diff --git a/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp b/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp index 43d7649d2fc1a9a360c3cef12601fa1e7ed7f282..1cff02990685d7623a0bfe967d47b2a46b6b8b32 100644 --- a/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp +++ b/services/samgr/native/test/unittest/src/device_timed_collect_test.cpp @@ -825,6 +825,7 @@ HWTEST_F(DeviceTimedCollectTest, ProcessPersistenceTimedTask002, TestSize.Level3 } #endif +#ifdef PREFERENCES_ENABLE HWTEST_F(DeviceTimedCollectTest, ProcessPersistenceLoopTask001, TestSize.Level3) { DTEST_LOG << " ProcessPersistenceLoopTask001 begin" << std::endl; @@ -862,6 +863,7 @@ HWTEST_F(DeviceTimedCollectTest, PostNonPersistenceLoopTaskLocked001, TestSize.L EXPECT_TRUE(deviceTimedCollect->nonPersitenceLoopTasks_.empty()); DTEST_LOG << " PostNonPersistenceLoopTaskLocked001 end" << std::endl; } +#endif #ifdef PREFERENCES_ENABLE HWTEST_F(DeviceTimedCollectTest, PostPersistenceDelayTaskd001, TestSize.Level3) diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp index 1cd777e8ad3d48a43ca9e3867bac196e5ab8dcb7..5359810e4416952791313f2716754079559b571f 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_load_test.cpp @@ -102,6 +102,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility001, TestSize.Level0) DTEST_LOG << "LoadSystemAbility001 begin" << std::endl; int32_t systemAbilityId = TEST_EXCEPTION_LOW_SA_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -118,6 +119,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility002, TestSize.Level0) DTEST_LOG << "LoadSystemAbility002 begin" << std::endl; int32_t systemAbilityId = TEST_EXCEPTION_HIGH_SA_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -134,6 +136,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility003, TestSize.Level0) DTEST_LOG << "LoadSystemAbility003 begin" << std::endl; int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_SO_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, nullptr); EXPECT_TRUE(result != ERR_OK); @@ -150,6 +153,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility004, TestSize.Level0) DTEST_LOG << "LoadSystemAbility004 begin" << std::endl; int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_SO_ID; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); int32_t result = saMgr->LoadSystemAbility(systemAbilityId, callback); @@ -166,6 +170,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility005, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility005 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; MessageOption option; @@ -184,6 +190,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility006, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility006 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); MessageParcel reply; @@ -203,6 +211,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility007, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility007 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(TEST_EXCEPTION_HIGH_SA_ID); @@ -223,6 +233,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility008, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility008 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -243,6 +255,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility009, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility009 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -267,6 +281,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility010, TestSize.Level3) DTEST_LOG << "LoadSystemAbility010 begin" << std::endl; sptr saMgr = new SystemAbilityManager; InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); sptr callback = new SystemAbilityLoadCallbackMock(); int32_t ret = saMgr->LoadSystemAbility(SAID, callback); EXPECT_EQ(ret, PROFILE_NOT_EXIST); @@ -283,6 +298,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility011, TestSize.Level3) { DTEST_LOG << "LoadSystemAbility011 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); int32_t ret = saMgr->LoadSystemAbility(-1, callback); @@ -299,6 +315,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess001, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, nullptr); @@ -315,7 +332,8 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess002, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; - saMgr->Init(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, callback); EXPECT_TRUE(callback->GetSystemAbilityId() == DISTRIBUTED_SCHED_TEST_SO_ID); @@ -332,6 +350,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess003, TestSize.Level { DTEST_LOG << "OnLoadSystemAbilitySuccess003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); sptr remoteObject = new TestTransactionService(); @@ -350,6 +369,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, OnLoadSystemAbilitySuccess004, TestSize.Level { DTEST_LOG << " OnLoadSystemAbilitySuccess004 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr callback = new SystemAbilityLoadCallbackMock(); saMgr->NotifySystemAbilityLoaded(DISTRIBUTED_SCHED_TEST_SO_ID, nullptr, nullptr); @@ -366,6 +386,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, ReportLoadSAOverflow001, TestSize.Level1) { DTEST_LOG << "ReportLoadSAOverflow001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + ASSERT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); for (int i = 0; i < OVERFLOW_TIME; ++i) { sptr callback = new SystemAbilityLoadCallbackMock(); @@ -704,6 +725,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadSystemAbility002, TestSize.Level3) { DTEST_LOG << "UnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = 1; CommonSaProfile saProfile; @@ -726,6 +748,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadSystemAbility003, TestSize.Level3) DTEST_LOG << " UnloadSystemAbility003 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"memmgrservice"; @@ -747,6 +770,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility001, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; int32_t ret = saMgr->CancelUnloadSystemAbility(systemAbilityId); @@ -764,6 +788,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility002, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = 1; int32_t ret = saMgr->CancelUnloadSystemAbility(systemAbilityId); @@ -781,6 +806,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility003, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saMgr->saProfileMap_[1] = saProfile; @@ -801,6 +827,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility004, TestSize.Level3 DTEST_LOG << " CancelUnloadSystemAbility004 begin" << std::endl; SamMockPermission::MockProcess("mockProcess"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"mockProcess"; @@ -822,6 +849,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility005, TestSize.Level3 DTEST_LOG << " CancelUnloadSystemAbility005 begin" << std::endl; SamMockPermission::MockProcess("mockProcess"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); CommonSaProfile saProfile; saProfile.process = u"mockProcess"; @@ -844,6 +872,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, CancelUnloadSystemAbility006, TestSize.Level3 { DTEST_LOG << " CancelUnloadSystemAbility006 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); Security::AccessToken::NativeTokenInfo nativeTokenInfo; @@ -870,6 +899,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, DoUnloadSystemAbility001, TestSize.Level3) { DTEST_LOG << "DoUnloadSystemAbility001 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); std::u16string procName = u"foundation"; int32_t said = 401; @@ -899,6 +929,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, DoUnloadSystemAbility002, TestSize.Level3) { DTEST_LOG << "DoUnloadSystemAbility002 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); ISystemAbilityManager::SAExtraProp saExtraProp(false, 0, u"", u""); int32_t systemAbilityId = DISTRIBUTED_SCHED_TEST_TT_ID; @@ -925,6 +956,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility001, TestSize.Level DTEST_LOG << "UnloadAllIdleSystemAbility001 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t ret = saMgr->UnloadAllIdleSystemAbility(); EXPECT_EQ(ret, ERR_OK); @@ -942,6 +974,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility002, TestSize.Level DTEST_LOG << "UnloadAllIdleSystemAbility002 begin" << std::endl; SamMockPermission::MockProcess("memmgrservice"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->abilityStateScheduler_ = nullptr; int32_t ret = saMgr->UnloadAllIdleSystemAbility(); @@ -960,6 +993,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, UnloadAllIdleSystemAbility003, TestSize.Level { DTEST_LOG << "UnloadAllIdleSystemAbility003 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t ret = saMgr->UnloadAllIdleSystemAbility(); EXPECT_EQ(ret, ERR_PERMISSION_DENIED); diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp index 7153d541c87541540f8f452c236508889c986c79..09fe52aec1ade4bded332da71348a1d7bbe05e22 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_new_test.cpp @@ -200,6 +200,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetLocalNodeId001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, ReportGetSAPeriodically001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); uint64_t pid_said = 123; int32_t count = 1; saMgr->saFrequencyMap_[pid_said] = count; @@ -216,6 +218,7 @@ HWTEST_F(SystemAbilityMgrNewTest, StartDynamicSystemProcess001, TestSize.Level3) { cout << "begin StartDynamicSystemProcess001 "<< endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); std::u16string invalidProcess = u"1234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456"; @@ -233,6 +236,7 @@ HWTEST_F(SystemAbilityMgrNewTest, StartDynamicSystemProcess001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityWithDevice001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); std::string deviceId = ""; auto ability = saMgr->GetSystemAbility(TEST_EXCEPTION_LOW_SA_ID, deviceId); @@ -256,6 +260,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityWithDevice001, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); auto ability = saMgr->GetSystemAbilityFromRemote(TEST_EXCEPTION_LOW_SA_ID); EXPECT_EQ(ability, nullptr); @@ -269,6 +274,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote001, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote002, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); auto ability = saMgr->GetSystemAbilityFromRemote(TEST_SYSTEM_ABILITY1); EXPECT_EQ(ability, nullptr); @@ -282,6 +288,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote002, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote003, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); SAInfo saInfo; saMgr->abilityMap_[1] = saInfo; @@ -298,6 +305,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote003, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote004, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); SAInfo saInfo; saInfo.isDistributed = true; @@ -317,6 +325,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote004, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetDBinder001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); sptr result = saMgr->GetDBinder(); EXPECT_TRUE(result == nullptr); } @@ -331,6 +341,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetDBinder001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->InitDbinderService(); sptr testAbility = new TestTransactionService(); @@ -348,6 +359,7 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted002, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr testAbility = new TestTransactionService(); saMgr->NotifyRpcLoadCompleted("", 1, testAbility); @@ -362,6 +374,7 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted002, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted003, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->InitDbinderService(); sptr testAbility = new TestTransactionService(); @@ -379,7 +392,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump001, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; args.push_back(u"test_name"); int32_t result = saMgr->Dump(1, args); @@ -397,7 +411,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump002, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; - saMgr->abilityStateScheduler_ = std::make_shared(); + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); vector args; vector argsWithStr8; args.push_back(u"test_name"); @@ -417,6 +432,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump003, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->abilityStateScheduler_ = std::make_shared(); vector args; args.push_back(u"--ipc"); @@ -436,6 +453,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump004, TestSize.Level3) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->abilityStateScheduler_ = std::make_shared(); vector args; args.push_back(u"--ffrt"); @@ -454,6 +473,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump004, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, AddSamgrToAbilityMap001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->AddSamgrToAbilityMap(); vector args; args.push_back(u"test_name"); @@ -470,6 +491,7 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSamgrToAbilityMap001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, GetCommonEventExtraIdList001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); sptr commonEventCollect = new CommonEventCollect(saMgr->collectManager_); commonEventCollect->workHandler_ = std::make_shared(commonEventCollect); @@ -517,6 +539,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetCommonEventExtraIdList001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, RemoveWhiteCommonEvent001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); saMgr->workHandler_ = make_shared("workHandler"); saMgr->CleanFfrt(); saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); @@ -539,6 +562,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RemoveWhiteCommonEvent001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, SetFfrt001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); saMgr->SetFfrt(); EXPECT_NE(saMgr->collectManager_, nullptr); @@ -554,6 +578,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList001, TestSize.Lev { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -583,6 +608,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList002, TestSize.Lev { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -623,6 +649,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetRunningSaExtensionInfoList002, TestSize.Lev HWTEST_F(SystemAbilityMgrNewTest, CheckSystemAbility006, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t systemAbilityId = -1; bool isExist; sptr ret = saMgr->CheckSystemAbility(systemAbilityId, isExist); @@ -638,6 +666,7 @@ HWTEST_F(SystemAbilityMgrNewTest, CheckSystemAbility006, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, RemoveSystemAbility005, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const sptr ability = nullptr; int32_t ret = saMgr->RemoveSystemAbility(ability); @@ -652,6 +681,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RemoveSystemAbility005, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility006, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; const sptr ability; @@ -668,6 +698,7 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility006, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility007, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); int32_t systemAbilityId = -1; const sptr ability; @@ -685,6 +716,8 @@ HWTEST_F(SystemAbilityMgrNewTest, AddSystemAbility007, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcess001, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); std::u16string procName; sptr ret = saMgr->GetSystemProcess(procName); EXPECT_EQ(ret, nullptr); @@ -698,6 +731,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcess001, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t systemAbilityId = 0; SystemProcessInfo systemProcessInfo; int32_t ret = saMgr->GetSystemProcessInfo(systemAbilityId, systemProcessInfo); @@ -712,6 +747,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); bool ret = saMgr->IsModuleUpdate(SAID); EXPECT_FALSE(ret); } @@ -724,6 +761,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); CommonSaProfile saprofile; saMgr->saProfileMap_[saprofile.saId] = saprofile; bool ret = saMgr->IsModuleUpdate(saprofile.saId); @@ -738,6 +777,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate003, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); CommonSaProfile saprofile; saprofile.moduleUpdate = true; saMgr->saProfileMap_[saprofile.saId] = saprofile; @@ -754,6 +795,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner001, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -770,6 +812,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner002, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -794,6 +837,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionSaIdsInner003, TestSize.Level3) { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -826,6 +870,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner001, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -842,6 +887,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner002, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); MessageParcel data; MessageParcel reply; @@ -866,6 +912,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetExtensionRunningSaListInner003, TestSize.Le { DTEST_LOG << __func__ << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); const int32_t maxLoop = 4; map saProfileMapTmp; @@ -901,6 +948,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc001, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -919,6 +968,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc002, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -938,6 +989,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc003, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -957,6 +1010,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc004, TestSize.Level2) { SamMockPermission::MockProcess("hidumper_service"); sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = -1; int32_t fd = 1; std::vector args; @@ -975,6 +1030,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpProc004, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START - 1; int32_t fd = 1; bool ret = saMgr->IpcStatSamgrProc(fd, cmd); @@ -992,6 +1049,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc002, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t dmd = IPC_STAT_CMD_STOP; int32_t emd = IPC_STAT_CMD_GET; @@ -1014,6 +1073,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcStatSamgrProc002, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpAllProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t fd = 1; bool ret = true; @@ -1029,6 +1090,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpAllProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSamgrProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = 4; int32_t fd = 1; bool ret = true; @@ -1045,6 +1108,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSamgrProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSingleProcess001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); int32_t cmd = IPC_STAT_CMD_START; int32_t fd = 1; bool ret = true; @@ -1066,6 +1131,8 @@ HWTEST_F(SystemAbilityMgrNewTest, IpcDumpSingleProcess001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, DoLoadForPerf001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->abilityStateScheduler_ = std::make_shared(); CommonSaProfile saProfile; saProfile.process = u"memmgrservice"; @@ -1083,6 +1150,8 @@ HWTEST_F(SystemAbilityMgrNewTest, DoLoadForPerf001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsDistributedSystemAbility001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); bool res = saMgr->IsDistributedSystemAbility(-1); EXPECT_FALSE(res); CommonSaProfile saProfile; @@ -1104,6 +1173,7 @@ HWTEST_F(SystemAbilityMgrNewTest, RegisterDistribute001, TestSize.Level2) DTEST_LOG<<"RegisterDistribute001 BEGIN"< saMgr = new SystemAbilityManager(); EXPECT_FALSE(saMgr == nullptr); + InitSaMgr(saMgr); saMgr->Init(); saMgr->isDbinderServiceInit_ = false; saMgr->distributedSaList_.push_back(softBusServerSaID); diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp index 076df88fbe62ba66ba62a0db274eb295bf5a69f6..04cc15df61941c46682a597774e64a7b3c37d1df 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_load_test.cpp @@ -41,6 +41,17 @@ const string DEFAULT_LOAD_NAME = "loadevent"; constexpr uint32_t SAID = 1499; constexpr int64_t DEFAULT_EVENTID = 0; constexpr int32_t INVALID_SAID = -1; +void InitSaMgr(sptr& saMgr) +{ + saMgr->abilityDeath_ = sptr(new AbilityDeathRecipient()); + saMgr->systemProcessDeath_ = sptr(new SystemProcessDeathRecipient()); + saMgr->abilityStatusDeath_ = sptr(new AbilityStatusDeathRecipient()); + saMgr->abilityCallbackDeath_ = sptr(new AbilityCallbackDeathRecipient()); + saMgr->remoteCallbackDeath_ = sptr(new RemoteCallbackDeathRecipient()); + saMgr->workHandler_ = make_shared("workHandler"); + saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); + saMgr->abilityStateScheduler_ = std::make_shared(); +} } void SystemAbilityMgrStubLoadTest::SetUpTestCase() diff --git a/services/samgr/native/test/unittest/src/system_ability_state_scheduler_proc_test.cpp b/services/samgr/native/test/unittest/src/system_ability_state_scheduler_proc_test.cpp index 67b7555a9d63bdf7a636ba07f5a4b04b5cc4f54a..c55ace60605e0e9b20676ccbc0c60dd7f4cd97ab 100644 --- a/services/samgr/native/test/unittest/src/system_ability_state_scheduler_proc_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_state_scheduler_proc_test.cpp @@ -39,6 +39,17 @@ constexpr int32_t STATENUMS = 1; const std::u16string process = u"test"; const std::u16string process_invalid = u"test_invalid"; const std::string LOCAL_DEVICE = "local"; +void InitSaMgr(sptr& saMgr) +{ + saMgr->abilityDeath_ = sptr(new AbilityDeathRecipient()); + saMgr->systemProcessDeath_ = sptr(new SystemProcessDeathRecipient()); + saMgr->abilityStatusDeath_ = sptr(new AbilityStatusDeathRecipient()); + saMgr->abilityCallbackDeath_ = sptr(new AbilityCallbackDeathRecipient()); + saMgr->remoteCallbackDeath_ = sptr(new RemoteCallbackDeathRecipient()); + saMgr->workHandler_ = make_shared("workHandler"); + saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); + saMgr->abilityStateScheduler_ = std::make_shared(); +} } void SystemAbilityStateSchedulerProcTest::SetUpTestCase()