1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #define LOG_TAG "ObjectManagerMockTest" 17 #include <gmock/gmock.h> 18 #include <ipc_skeleton.h> 19 20 #include "device_manager_adapter_mock.h" 21 #include "device_matrix_mock.h" 22 #include "gtest/gtest.h" 23 #include "mock/access_token_mock.h" 24 #include "mock/account_delegate_mock.h" 25 #include "mock/distributed_file_daemon_manager_mock.h" 26 #include "mock/meta_data_manager_mock.h" 27 #include "object_manager.h" 28 #include "object_service_impl.h" 29 30 31 using namespace OHOS::DistributedObject; 32 using namespace OHOS::DistributedData; 33 using namespace OHOS::Storage::DistributedFile; 34 using namespace OHOS::Security::AccessToken; 35 using namespace testing::ext; 36 using namespace testing; 37 using AssetValue = OHOS::CommonType::AssetValue; 38 using DeviceInfo = OHOS::AppDistributedKv::DeviceInfo; 39 using OnComplete = OHOS::DistributedData::MetaDataManager::OnComplete; 40 41 namespace OHOS::Test { 42 namespace DistributedDataTest { 43 class ObjectManagerMockTest : public testing::Test { 44 public: SetUpTestCase(void)45 static void SetUpTestCase(void) 46 { 47 metaDataManagerMock = std::make_shared<MetaDataManagerMock>(); 48 BMetaDataManager::metaDataManager = metaDataManagerMock; 49 metaDataMock = std::make_shared<MetaDataMock<StoreMetaData>>(); 50 BMetaData<StoreMetaData>::metaDataManager = metaDataMock; 51 devMgrAdapterMock = std::make_shared<DeviceManagerAdapterMock>(); 52 BDeviceManagerAdapter::deviceManagerAdapter = devMgrAdapterMock; 53 deviceMatrixMock = std::make_shared<DeviceMatrixMock>(); 54 BDeviceMatrix::deviceMatrix = deviceMatrixMock; 55 fileDaemonMgrMock = std::make_shared<DistributedFileDaemonManagerMock>(); 56 BDistributedFileDaemonManager::fileDaemonManger_ = fileDaemonMgrMock; 57 accountDelegateMock = new (std::nothrow) AccountDelegateMock(); 58 if (accountDelegateMock != nullptr) { 59 AccountDelegate::instance_ = nullptr; 60 AccountDelegate::RegisterAccountInstance(accountDelegateMock); 61 } 62 accTokenMock = std::make_shared<AccessTokenKitMock>(); 63 BAccessTokenKit::accessTokenkit = accTokenMock; 64 } TearDownTestCase(void)65 static void TearDownTestCase(void) 66 { 67 metaDataManagerMock = nullptr; 68 BMetaDataManager::metaDataManager = nullptr; 69 metaDataMock = nullptr; 70 BMetaData<StoreMetaData>::metaDataManager = nullptr; 71 devMgrAdapterMock = nullptr; 72 BDeviceManagerAdapter::deviceManagerAdapter = nullptr; 73 deviceMatrixMock = nullptr; 74 BDeviceMatrix::deviceMatrix = nullptr; 75 fileDaemonMgrMock = nullptr; 76 BDistributedFileDaemonManager::fileDaemonManger_ = nullptr; 77 if (accountDelegateMock != nullptr) { 78 delete accountDelegateMock; 79 accountDelegateMock = nullptr; 80 } 81 accTokenMock = nullptr; 82 BAccessTokenKit::accessTokenkit = nullptr; 83 } 84 85 static inline std::shared_ptr<MetaDataManagerMock> metaDataManagerMock = nullptr; 86 static inline std::shared_ptr<MetaDataMock<StoreMetaData>> metaDataMock = nullptr; 87 static inline std::shared_ptr<DeviceManagerAdapterMock> devMgrAdapterMock = nullptr; 88 static inline std::shared_ptr<DeviceMatrixMock> deviceMatrixMock = nullptr; 89 static inline std::shared_ptr<DistributedFileDaemonManagerMock> fileDaemonMgrMock = nullptr; 90 static inline AccountDelegateMock *accountDelegateMock = nullptr; 91 static inline std::shared_ptr<AccessTokenKitMock> accTokenMock = nullptr; SetUp()92 void SetUp() {}; TearDown()93 void TearDown() {}; 94 95 protected: 96 std::string sessionId_ = "123"; 97 OHOS::ObjectStore::AssetBindInfo assetBindInfo_; 98 AssetValue assetValue_; 99 }; 100 101 /** 102 * @tc.name: IsNeedMetaSync001 103 * @tc.desc: Test IsNeedMetaSync when LoadMeta fails for CapMetaData. 104 * @tc.type: FUNC 105 * @tc.require: 106 */ 107 HWTEST_F(ObjectManagerMockTest, IsNeedMetaSync001, TestSize.Level0) 108 { 109 EXPECT_CALL(*fileDaemonMgrMock, RegisterAssetCallback(_)).WillOnce(testing::Return(0)); 110 auto &manager = ObjectStoreManager::GetInstance(); 111 StoreMetaData meta; 112 meta.deviceId = "test_device_id"; 113 meta.user = "0"; 114 meta.storeId = "distributedObject_"; 115 meta.bundleName = "test_bundle"; 116 std::vector<std::string> uuids = { "test_uuid" }; 117 118 EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)).WillOnce(testing::Return(false)); 119 bool isNeedSync = manager.IsNeedMetaSync(meta, uuids); 120 EXPECT_EQ(isNeedSync, true); 121 EXPECT_CALL(*metaDataManagerMock, LoadMeta(testing::_, testing::_, testing::_)) 122 .WillOnce(testing::Return(true)) 123 .WillOnce(testing::Return(false)); 124 isNeedSync = manager.IsNeedMetaSync(meta, uuids); 125 EXPECT_EQ(isNeedSync, true); 126 } 127 128 /** 129 * @tc.name: IsNeedMetaSync002 130 * @tc.desc: Test IsNeedMetaSync when LoadMeta fails for StoreMetaData. 131 * @tc.type: FUNC 132 * @tc.require: 133 */ 134 HWTEST_F(ObjectManagerMockTest, IsNeedMetaSync002, TestSize.Level0) 135 { 136 auto &manager = ObjectStoreManager::GetInstance(); 137 StoreMetaData meta; 138 meta.deviceId = "test_device_id"; 139 meta.user = "0"; 140 meta.storeId = "distributedObject_"; 141 meta.bundleName = "test_bundle"; 142 std::vector<std::string> uuids = { "test_uuid" }; 143 144 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)).WillRepeatedly(Return((true))); 145 EXPECT_CALL(*deviceMatrixMock, GetRemoteMask(_, _)) 146 .WillRepeatedly(Return(std::make_pair(true, DeviceMatrix::META_STORE_MASK))); 147 148 bool result = manager.IsNeedMetaSync(meta, uuids); 149 EXPECT_EQ(result, true); 150 } 151 152 /** 153 * @tc.name: IsNeedMetaSync003 154 * @tc.desc: Test IsNeedMetaSync when LoadMeta fails for StoreMetaData. 155 * @tc.type: FUNC 156 * @tc.require: 157 */ 158 HWTEST_F(ObjectManagerMockTest, IsNeedMetaSync003, TestSize.Level0) 159 { 160 auto &manager = ObjectStoreManager::GetInstance(); 161 StoreMetaData meta; 162 meta.deviceId = "test_device_id"; 163 meta.user = "0"; 164 meta.storeId = "distributedObject_"; 165 meta.bundleName = "test_bundle"; 166 std::vector<std::string> uuids = { "test_uuid" }; 167 168 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)).WillRepeatedly(Return(true)); 169 EXPECT_CALL(*deviceMatrixMock, GetRemoteMask(_, _)).WillOnce(Return(std::make_pair(true, 0))); 170 EXPECT_CALL(*deviceMatrixMock, GetMask(_, _)).WillOnce(Return(std::make_pair(true, DeviceMatrix::META_STORE_MASK))); 171 172 bool result = manager.IsNeedMetaSync(meta, uuids); 173 EXPECT_EQ(result, true); 174 175 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)).WillRepeatedly(Return(true)); 176 177 EXPECT_CALL(*deviceMatrixMock, GetRemoteMask(_, _)).WillOnce(Return(std::make_pair(true, 0))); 178 179 EXPECT_CALL(*deviceMatrixMock, GetMask(_, _)).WillOnce(Return(std::make_pair(true, 0))); 180 181 result = manager.IsNeedMetaSync(meta, uuids); 182 EXPECT_EQ(result, false); 183 } 184 185 /** 186 * @tc.name: SyncOnStore001 187 * @tc.desc: Test SyncOnStore 188 * @tc.type: FUNC 189 * @tc.require: 190 */ 191 HWTEST_F(ObjectManagerMockTest, SyncOnStore001, TestSize.Level0) 192 { 193 // 2 means that the GetUserByToken interface will be called twice 194 EXPECT_CALL(*accountDelegateMock, GetUserByToken(_)).Times(2).WillRepeatedly(Return(0)); 195 auto &manager = ObjectStoreManager::GetInstance(); 196 std::function<void(const std::map<std::string, int32_t> &results)> func; __anon46c8bb2b0102(const std::map<std::string, int32_t> &results) 197 func = [](const std::map<std::string, int32_t> &results) { return results; }; 198 std::string prefix = "ObjectManagerTest"; 199 StoreMetaData meta; 200 meta.deviceId = "test_device_id"; 201 meta.user = "0"; 202 meta.storeId = "distributedObject_"; 203 meta.bundleName = "test_bundle"; 204 std::vector<std::string> uuids = { "test_uuid" }; 205 206 // local device 207 { 208 std::vector<std::string> localDeviceList = { "local" }; 209 auto result = manager.SyncOnStore(prefix, localDeviceList, func); 210 EXPECT_EQ(result, OBJECT_SUCCESS); 211 } 212 213 // remote device. IsNeedMetaSync: true; Sync: true 214 { 215 std::vector<std::string> remoteDeviceList = { "remote_device_1" }; 216 EXPECT_CALL(*devMgrAdapterMock, GetUuidByNetworkId(_)).WillRepeatedly(Return("mock_uuid")); 217 EXPECT_CALL(*devMgrAdapterMock, ToUUID(testing::A<const std::vector<std::string> &>())) 218 .WillOnce(Return(std::vector<std::string>{ "mock_uuid_1" })); 219 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)).WillOnce(testing::Return(false)); 220 EXPECT_CALL(*metaDataManagerMock, Sync(_, _, _, _)).WillOnce(testing::Return(true)); 221 auto result = manager.SyncOnStore(prefix, remoteDeviceList, func); 222 EXPECT_EQ(result, OBJECT_SUCCESS); 223 } 224 225 // remote device. IsNeedMetaSync: false 226 { 227 std::vector<std::string> remoteDeviceList = { "remote_device_1" }; 228 EXPECT_CALL(*devMgrAdapterMock, GetUuidByNetworkId(_)).WillRepeatedly(Return("mock_uuid")); 229 EXPECT_CALL(*devMgrAdapterMock, ToUUID(testing::A<const std::vector<std::string> &>())) 230 .WillOnce(Return(std::vector<std::string>{ "mock_uuid_1" })); 231 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) 232 .WillOnce(testing::Return(true)) 233 .WillOnce(testing::Return(true)); 234 EXPECT_CALL(*deviceMatrixMock, GetRemoteMask(_, _)).WillOnce(Return(std::make_pair(true, 0))); 235 EXPECT_CALL(*deviceMatrixMock, GetMask(_, _)).WillOnce(Return(std::make_pair(true, 0))); 236 auto result = manager.SyncOnStore(prefix, remoteDeviceList, func); 237 EXPECT_EQ(result, E_DB_ERROR); 238 } 239 } 240 241 /** 242 * @tc.name: GetCurrentUser001 243 * @tc.desc: Test the scenario where the QueryUsers return false in the GetCurrentUser function. 244 * @tc.type: FUNC 245 * @tc.require: 246 * @tc.author: 247 */ 248 HWTEST_F(ObjectManagerMockTest, GetCurrentUser001, TestSize.Level1) 249 { 250 auto &manager = ObjectStoreManager::GetInstance(); 251 std::vector<int> users; 252 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(false))); 253 auto result = manager.GetCurrentUser(); 254 EXPECT_EQ(result, ""); 255 } 256 257 /** 258 * @tc.name: GetCurrentUser002 259 * @tc.desc: Test the scenario where the QueryUsers users empty in the GetCurrentUser function. 260 * @tc.type: FUNC 261 * @tc.require: 262 * @tc.author: 263 */ 264 HWTEST_F(ObjectManagerMockTest, GetCurrentUser002, TestSize.Level1) 265 { 266 auto &manager = ObjectStoreManager::GetInstance(); 267 std::vector<int> users; 268 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)) 269 .Times(1) 270 .WillOnce( __anon46c8bb2b0202(std::vector<int> &users) 271 DoAll(SetArgReferee<0>(users), Invoke([](std::vector<int> &users) { users.clear(); }), Return(true))); 272 auto result = manager.GetCurrentUser(); 273 EXPECT_EQ(result, ""); 274 } 275 276 /** 277 * @tc.name: GetCurrentUser003 278 * @tc.desc: Test the scenario where the QueryUsers return true in the GetCurrentUser function. 279 * @tc.type: FUNC 280 * @tc.require: 281 * @tc.author: 282 */ 283 HWTEST_F(ObjectManagerMockTest, GetCurrentUser003, TestSize.Level1) 284 { 285 auto &manager = ObjectStoreManager::GetInstance(); 286 std::vector<int> users = { 0, 1 }; 287 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(true))); 288 auto result = manager.GetCurrentUser(); 289 EXPECT_EQ(result, std::to_string(users[0])); 290 } 291 292 /** 293 * @tc.name: WaitAssets001 294 * @tc.desc: WaitAssets test. 295 * @tc.type: FUNC 296 */ 297 HWTEST_F(ObjectManagerMockTest, WaitAssets001, TestSize.Level1) 298 { 299 auto &manager = ObjectStoreManager::GetInstance(); 300 std::string objectKey = "objectKey"; 301 ObjectStoreManager::SaveInfo info; 302 std::map<std::string, ObjectRecord> data; 303 auto ret = manager.WaitAssets(objectKey, info, data); 304 EXPECT_EQ(ret, DistributedObject::OBJECT_INNER_ERROR); 305 } 306 307 /** 308 * @tc.name: NotifyAssetsReady001 309 * @tc.desc: NotifyAssetsReady test. 310 * @tc.type: FUNC 311 */ 312 HWTEST_F(ObjectManagerMockTest, NotifyAssetsReady001, TestSize.Level1) 313 { 314 auto &manager = ObjectStoreManager::GetInstance(); 315 std::string objectKey = "objectKey"; 316 std::string bundleName = "bundleName"; 317 std::string srcNetworkId = "srcNetworkId"; 318 manager.NotifyAssetsReady(objectKey, bundleName, srcNetworkId); 319 EXPECT_EQ(manager.executors_, nullptr); 320 } 321 322 /** 323 * @tc.name: DoNotifyAssetsReady001 324 * @tc.desc: DoNotifyAssetsReady test. 325 * @tc.type: FUNC 326 */ 327 HWTEST_F(ObjectManagerMockTest, DoNotifyAssetsReady001, TestSize.Level1) 328 { 329 auto &manager = ObjectStoreManager::GetInstance(); 330 uint32_t tokenId = 0; 331 ObjectStoreManager::CallbackInfo info; 332 std::string objectKey = "objectKey"; 333 bool isReady = true; 334 manager.DoNotifyAssetsReady(tokenId, info, objectKey, isReady); 335 EXPECT_EQ(manager.executors_, nullptr); 336 } 337 338 /** 339 * @tc.name: DoNotifyWaitAssetTimeout001 340 * @tc.desc: DoNotifyWaitAssetTimeout test. 341 * @tc.type: FUNC 342 */ 343 HWTEST_F(ObjectManagerMockTest, DoNotifyWaitAssetTimeout001, TestSize.Level1) 344 { 345 auto &manager = ObjectStoreManager::GetInstance(); 346 std::string objectKey = "objectKey"; 347 manager.DoNotifyWaitAssetTimeout(objectKey); 348 EXPECT_EQ(manager.executors_, nullptr); 349 } 350 351 /** 352 * @tc.name: FlushClosedStore001 353 * @tc.desc: FlushClosedStore test. 354 * @tc.type: FUNC 355 */ 356 HWTEST_F(ObjectManagerMockTest, FlushClosedStore001, TestSize.Level1) 357 { 358 auto &manager = ObjectStoreManager::GetInstance(); 359 manager.FlushClosedStore(); 360 EXPECT_EQ(manager.executors_, nullptr); 361 } 362 363 /** 364 * @tc.name: CloseAfterMinute001 365 * @tc.desc: CloseAfterMinute test. 366 * @tc.type: FUNC 367 */ 368 HWTEST_F(ObjectManagerMockTest, CloseAfterMinute001, TestSize.Level1) 369 { 370 auto &manager = ObjectStoreManager::GetInstance(); 371 manager.CloseAfterMinute(); 372 EXPECT_EQ(manager.executors_, nullptr); 373 } 374 375 /** 376 * @tc.name: UnRegisterAssetsLister001 377 * @tc.desc: UnRegisterAssetsLister test. 378 * @tc.type: FUNC 379 */ 380 HWTEST_F(ObjectManagerMockTest, UnRegisterAssetsLister001, TestSize.Level1) 381 { 382 auto &manager = ObjectStoreManager::GetInstance(); 383 manager.objectAssetsRecvListener_ = nullptr; 384 auto ret = manager.UnRegisterAssetsLister(); 385 EXPECT_EQ(ret, true); 386 EXPECT_CALL(*fileDaemonMgrMock, RegisterAssetCallback(_)).WillOnce(testing::Return(0)); 387 manager.RegisterAssetsLister(); 388 EXPECT_CALL(*fileDaemonMgrMock, UnRegisterAssetCallback(_)).WillOnce(testing::Return(-1)); 389 ret = manager.UnRegisterAssetsLister(); 390 EXPECT_EQ(ret, false); 391 EXPECT_CALL(*fileDaemonMgrMock, UnRegisterAssetCallback(_)).WillOnce(testing::Return(0)); 392 ret = manager.UnRegisterAssetsLister(); 393 EXPECT_EQ(ret, true); 394 } 395 396 /** 397 * @tc.name: InitUserMeta001 398 * @tc.desc: Test the scenario where the QueryUsers return false in the GetCurrentUser function. 399 * @tc.type: FUNC 400 */ 401 HWTEST_F(ObjectManagerMockTest, InitUserMeta001, TestSize.Level1) 402 { 403 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) 404 .WillOnce(testing::Return(false)); 405 auto &manager = ObjectStoreManager::GetInstance(); 406 std::vector<int> users; 407 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(false))); 408 auto status = manager.InitUserMeta(); 409 EXPECT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); 410 } 411 412 /** 413 * @tc.name: InitUserMeta002 414 * @tc.desc: Test the scenario where the QueryUsers users empty in the GetCurrentUser function. 415 * @tc.type: FUNC 416 */ 417 HWTEST_F(ObjectManagerMockTest, InitUserMeta002, TestSize.Level1) 418 { 419 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) 420 .WillOnce(testing::Return(false)); 421 auto &manager = ObjectStoreManager::GetInstance(); 422 std::vector<int> users; 423 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)) 424 .Times(1) 425 .WillOnce( __anon46c8bb2b0302(std::vector<int> &users) 426 DoAll(SetArgReferee<0>(users), Invoke([](std::vector<int> &users) { users.clear(); }), Return(true))); 427 auto status = manager.InitUserMeta(); 428 EXPECT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); 429 } 430 431 /** 432 * @tc.name: InitUserMeta003 433 * @tc.desc: Test the scenario where the QueryUsers return true in the GetCurrentUser function. 434 * @tc.type: FUNC 435 */ 436 HWTEST_F(ObjectManagerMockTest, InitUserMeta003, TestSize.Level1) 437 { 438 EXPECT_CALL(*metaDataManagerMock, LoadMeta(_, _, _)) 439 .WillOnce(testing::Return(false)); 440 DeviceInfo devInfo = { .uuid = "666" }; 441 EXPECT_CALL(*devMgrAdapterMock, GetLocalDevice()).WillOnce(Return(devInfo)); 442 auto &manager = ObjectStoreManager::GetInstance(); 443 std::vector<int> users = { 0, 1 }; 444 EXPECT_CALL(*accountDelegateMock, QueryUsers(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(users), Return(true))); 445 auto status = manager.InitUserMeta(); 446 EXPECT_EQ(status, DistributedObject::OBJECT_INNER_ERROR); 447 } 448 449 /** 450 * @tc.name: BindAsset001 451 * @tc.desc: Test BindAsset function when GetTokenTypeFlag is not TOKEN_HAP. 452 * @tc.type: FUNC 453 */ 454 HWTEST_F(ObjectManagerMockTest, BindAsset001, TestSize.Level1) 455 { 456 auto &manager = ObjectStoreManager::GetInstance(); 457 std::string bundleName = "BindAsset"; 458 uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); 459 EXPECT_CALL(*accTokenMock, GetTokenTypeFlag(_)) 460 .Times(1) 461 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE)); 462 auto result = manager.BindAsset(tokenId, bundleName, sessionId_, assetValue_, assetBindInfo_); 463 EXPECT_EQ(result, DistributedObject::OBJECT_DBSTATUS_ERROR); 464 } 465 466 /** 467 * @tc.name: BindAsset002 468 * @tc.desc: Test BindAsset function when GetTokenTypeFlag is TOKEN_HAP. 469 * @tc.type: FUNC 470 */ 471 HWTEST_F(ObjectManagerMockTest, BindAsset002, TestSize.Level1) 472 { 473 auto &manager = ObjectStoreManager::GetInstance(); 474 std::string bundleName = "BindAsset"; 475 uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); 476 EXPECT_CALL(*accTokenMock, GetTokenTypeFlag(_)) 477 .Times(1) 478 .WillOnce(Return(ATokenTypeEnum::TOKEN_HAP)); 479 EXPECT_CALL(*accTokenMock, GetHapTokenInfo(_, _)) 480 .Times(1) 481 .WillOnce(Return(0)); 482 auto result = manager.BindAsset(tokenId, bundleName, sessionId_, assetValue_, assetBindInfo_); 483 EXPECT_EQ(result, DistributedObject::OBJECT_SUCCESS); 484 } 485 486 /** 487 * @tc.name: IsContinue001 488 * @tc.desc: Test IsContinue function when GetTokenTypeFlag is not TOKEN_HAP. 489 * @tc.type: FUNC 490 */ 491 HWTEST_F(ObjectManagerMockTest, IsContinue001, TestSize.Level1) 492 { 493 std::shared_ptr<ObjectServiceImpl> objectServiceImpl = std::make_shared<ObjectServiceImpl>(); 494 bool isContinue = false; 495 EXPECT_CALL(*fileDaemonMgrMock, UnRegisterAssetCallback(_)).WillRepeatedly(testing::Return(0)); 496 EXPECT_CALL(*accTokenMock, GetTokenTypeFlag(_)) 497 .Times(1) 498 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE)); 499 auto ret = objectServiceImpl->IsContinue(isContinue); 500 EXPECT_EQ(ret, DistributedObject::OBJECT_INNER_ERROR); 501 } 502 503 /** 504 * @tc.name: IsContinue002 505 * @tc.desc: Test IsContinue function when GetTokenTypeFlag is TOKEN_HAP. 506 * @tc.type: FUNC 507 */ 508 HWTEST_F(ObjectManagerMockTest, IsContinue002, TestSize.Level1) 509 { 510 std::shared_ptr<ObjectServiceImpl> objectServiceImpl = std::make_shared<ObjectServiceImpl>(); 511 bool isContinue = false; 512 EXPECT_CALL(*accTokenMock, GetTokenTypeFlag(_)) 513 .Times(2) 514 .WillRepeatedly(Return(ATokenTypeEnum::TOKEN_HAP)); 515 EXPECT_CALL(*accTokenMock, GetHapTokenInfo(_, _)) 516 .Times(1) 517 .WillOnce(Return(0)); 518 auto ret = objectServiceImpl->IsContinue(isContinue); 519 EXPECT_EQ(ret, DistributedObject::OBJECT_SUCCESS); 520 } 521 }; // namespace DistributedDataTest 522 } // namespace OHOS::Test