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 5c7f8e709b6413c62c892fe780e1653c8ede3466..a9a1094912db15bb6163ef3280bee3b8ce3399a0 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,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility005, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility005 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; MessageParcel reply; MessageOption option; @@ -184,6 +189,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility006, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility006 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); MessageParcel reply; @@ -203,6 +209,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility007, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility007 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(TEST_EXCEPTION_HIGH_SA_ID); @@ -223,6 +230,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility008, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility008 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -243,6 +251,7 @@ HWTEST_F(SystemAbilityMgrLoadTest, LoadSystemAbility009, TestSize.Level1) { DTEST_LOG << "LoadSystemAbility009 begin" << std::endl; sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); MessageParcel data; data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN); data.WriteInt32(DISTRIBUTED_SCHED_TEST_SO_ID); @@ -267,6 +276,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); @@ -299,6 +309,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 +326,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 +344,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 +363,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 +380,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 +719,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 +742,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 +764,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 +782,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 +800,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 +821,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 +843,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 +866,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 +893,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 +923,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 +950,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 +968,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 +987,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 9fcf2cbadf2c8fc74cdf7a810d075ec19f347ef2..153125a3cb281a1ebeaec7908e6fccc979731a22 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 @@ -187,6 +187,8 @@ void SystemAbilityMgrNewTest::TearDown() HWTEST_F(SystemAbilityMgrNewTest, GetLocalNodeId001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); string ret = saMgr->GetLocalNodeId(); EXPECT_EQ(ret, ""); } @@ -200,6 +202,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 +220,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 +238,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,7 +262,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityWithDevice001, TestSize.Level3 HWTEST_F(SystemAbilityMgrNewTest, GetSystemAbilityFromRemote001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; - InitSaMgr(saMgr); + EXPECT_TRUE(saMgr != nullptr); + saMgr->Init(); auto ability = saMgr->GetSystemAbilityFromRemote(TEST_EXCEPTION_LOW_SA_ID); EXPECT_EQ(ability, nullptr); } @@ -269,6 +276,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 +290,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 +307,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 +327,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 +343,7 @@ HWTEST_F(SystemAbilityMgrNewTest, GetDBinder001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); #ifdef SAMGR_ENABLE_DELAY_DBINDER saMgr->InitDbinderService(); @@ -338,6 +351,7 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted001, TestSize.Level3) sptr testAbility = new TestTransactionService(); saMgr->workHandler_ = nullptr; saMgr->NotifyRpcLoadCompleted("", 1, testAbility); + EXPECT_TRUE(saMgr != nullptr); } /** @@ -350,6 +364,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); @@ -364,12 +379,14 @@ HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted002, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, NotifyRpcLoadCompleted003, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); InitSaMgr(saMgr); #ifdef SAMGR_ENABLE_DELAY_DBINDER saMgr->InitDbinderService(); #endif sptr testAbility = new TestTransactionService(); saMgr->NotifyRpcLoadCompleted("", 1, testAbility); + EXPECT_TRUE(saMgr != nullptr); } /** @@ -383,7 +400,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); @@ -401,7 +419,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"); @@ -421,7 +440,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump003, 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"--ipc"); args.push_back(u"all"); @@ -440,7 +460,8 @@ HWTEST_F(SystemAbilityMgrNewTest, Dump004, 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"--ffrt"); args.push_back(u"99999"); @@ -458,6 +479,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"); @@ -474,6 +497,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); @@ -521,13 +545,14 @@ HWTEST_F(SystemAbilityMgrNewTest, GetCommonEventExtraIdList001, TestSize.Level3) HWTEST_F(SystemAbilityMgrNewTest, RemoveWhiteCommonEvent001, TestSize.Level3) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); saMgr->workHandler_ = make_shared("workHandler"); saMgr->CleanFfrt(); saMgr->collectManager_ = sptr(new DeviceStatusCollectManager()); saMgr->CleanFfrt(); saMgr->abilityStateScheduler_ = std::make_shared(); saMgr->CleanFfrt(); - InitSaMgr(saMgr); const std::u16string name; saMgr->NotifyRemoteSaDied(name); saMgr->RemoveWhiteCommonEvent(); @@ -543,6 +568,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); @@ -558,6 +584,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; @@ -587,6 +614,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; @@ -627,6 +655,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); @@ -642,6 +672,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); @@ -656,6 +687,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; @@ -672,6 +704,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; @@ -689,6 +722,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); @@ -702,6 +737,8 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcess001, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + saMgr->abilityStateScheduler_ = nullptr; int32_t systemAbilityId = 0; SystemProcessInfo systemProcessInfo; int32_t ret = saMgr->GetSystemProcessInfo(systemAbilityId, systemProcessInfo); @@ -716,6 +753,9 @@ HWTEST_F(SystemAbilityMgrNewTest, GetSystemProcessInfo003, TestSize.Level1) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); bool ret = saMgr->IsModuleUpdate(SAID); EXPECT_FALSE(ret); } @@ -728,6 +768,9 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate001, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); CommonSaProfile saprofile; saMgr->saProfileMap_[saprofile.saId] = saprofile; bool ret = saMgr->IsModuleUpdate(saprofile.saId); @@ -742,6 +785,9 @@ HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate002, TestSize.Level2) HWTEST_F(SystemAbilityMgrNewTest, IsModuleUpdate003, TestSize.Level2) { sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + InitSaMgr(saMgr); + saMgr->saProfileMap_.clear(); CommonSaProfile saprofile; saprofile.moduleUpdate = true; saMgr->saProfileMap_[saprofile.saId] = saprofile; @@ -758,6 +804,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; @@ -774,6 +821,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; @@ -798,6 +846,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; @@ -830,6 +879,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; @@ -846,6 +896,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; @@ -870,6 +921,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; @@ -905,6 +957,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; @@ -923,6 +977,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; @@ -942,6 +998,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; @@ -961,6 +1019,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; @@ -979,6 +1039,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); @@ -996,6 +1058,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; @@ -1018,6 +1082,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; @@ -1033,6 +1099,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; @@ -1049,6 +1117,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; @@ -1070,6 +1140,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"; @@ -1087,6 +1159,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; @@ -1109,6 +1183,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 7435edddc7fd1cd2ec858d4c3e3934b738f56dd9..bb43b9c57eb4ba33a278e763c70b3fbbdfc4bf97 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()