From be9ef8802e0413b0424a3e433c1ea58bfc5bf876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Sat, 2 Nov 2024 10:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../src/distributed_sched_utils_test.cpp | 16 + services/dtbschedmgr/test/BUILD.gn | 5 +- .../continue/dsched_continue_state_test.cpp | 408 +++++++++++++++++- .../continue/dsched_continue_state_test.h | 2 + .../continue_scene_session_handler_test.cpp | 18 + .../unittest/distributed_sched_stub_test.cpp | 69 +++ .../mission/dms_mission_manager_test.cpp | 2 +- .../unittest/mission/dsched_sync_e2e_test.cpp | 89 ++++ .../dsched_all_connect_manager_test.cpp | 155 +++++++ .../softbus_transport_test.cpp | 17 +- 10 files changed, 777 insertions(+), 4 deletions(-) create mode 100644 services/dtbschedmgr/test/unittest/softbus_adapter/dsched_all_connect_manager_test.cpp diff --git a/common/test/unittest/src/distributed_sched_utils_test.cpp b/common/test/unittest/src/distributed_sched_utils_test.cpp index edbf5757..b86dd643 100644 --- a/common/test/unittest/src/distributed_sched_utils_test.cpp +++ b/common/test/unittest/src/distributed_sched_utils_test.cpp @@ -90,6 +90,22 @@ HWTEST_F(DistributedSchedUtilsTest, IsValidPath_002, TestSize.Level1) EXPECT_FALSE(realFilePath.empty()); } +/** + * @tc.name: IsValidPath_003 + * @tc.desc: File path is invalid + * @tc.type: FUNC + * @tc.require: I5WKCK + */ +HWTEST_F(DistributedSchedUtilsTest, IsValidPath_003, TestSize.Level1) +{ + std::string inFilePath = ""; + std::string realFilePath = ""; + EXPECT_FALSE(IsValidPath(inFilePath, realFilePath)); + + inFilePath = "/data/123_test.json"; + EXPECT_FALSE(IsValidPath(inFilePath, realFilePath)); +} + /** * @tc.name: CheckBundleContinueConfig_001 * @tc.desc: Check bundle continue config when existing config file diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index 02b66aee..727bed8a 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -498,7 +498,10 @@ ohos_unittest("bundlemanagerinternaltest") { ohos_unittest("softbusadaptertest") { module_out_path = module_output_path cflags = [ "-Dprivate=public" ] - sources = [ "unittest/softbus_adapter/softbus_transport_test.cpp" ] + sources = [ + "unittest/softbus_adapter/dsched_all_connect_manager_test.cpp", + "unittest/softbus_adapter/softbus_transport_test.cpp", + ] if (!dmsfwk_softbus_adapter_common) { sources += [ diff --git a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp index 3994ab36..5f5f3daf 100644 --- a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp +++ b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.cpp @@ -32,12 +32,16 @@ namespace { void DSchedContinueDataStateTest::SetUpTestCase() { mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)); + mockStateTest_ = std::make_shared(); + DmsMgrDeviceInfoStore::dmsStore = mockStateTest_; DTEST_LOG << "DSchedContinueDataStateTest::SetUpTestCase" << std::endl; } void DSchedContinueDataStateTest::TearDownTestCase() { (void)remove(BASEDIR.c_str()); + DmsMgrDeviceInfoStore::dmsStore = nullptr; + mockStateTest_ = nullptr; DTEST_LOG << "DSchedContinueDataStateTest::TearDownTestCase" << std::endl; } @@ -477,9 +481,31 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueDataTask001, TestSize.Level3 ret = dataStateTest_->DoContinueDataTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = dataStateTest_->DoContinueDataTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueDataTask001 end" << std::endl; } + /** + * @tc.name: SinkDoContinueDataTask002 + * @tc.desc: DoContinueDataTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueDataTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueDataTask002 begin" << std::endl; + ASSERT_NE(dataStateTest_, nullptr); + auto data = std::make_shared(); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_DATA_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + EXPECT_CALL(*mockStateTest_, GetLocalDeviceId(_)).WillOnce(Return(true)); + int32_t ret = dataStateTest_->DoContinueDataTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueDataTask002 end" << std::endl; +} + /** * @tc.name: SinkDoContinueEndTask001 * @tc.desc: DoContinueEndTask @@ -502,9 +528,30 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueEndTask001, TestSize.Level3) ret = dataStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = dataStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueEndTask001 end" << std::endl; } + /** + * @tc.name: SinkDoContinueEndTask002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueEndTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueEndTask002 begin" << std::endl; + ASSERT_NE(dataStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = dataStateTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueEndTask002 end" << std::endl; +} + /** * @tc.name: SinkDoContinueErrorTask001 * @tc.desc: DoContinueErrorTask @@ -527,9 +574,30 @@ HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueErrorTask001, TestSize.Level ret = dataStateTest_->DoContinueErrorTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = dataStateTest_->DoContinueErrorTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueErrorTask001 end" << std::endl; } + /** + * @tc.name: SinkDoContinueErrorTask002 + * @tc.desc: DoContinueErrorTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueDataStateTest, SinkDoContinueErrorTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueErrorTask002 begin" << std::endl; + ASSERT_NE(dataStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = dataStateTest_->DoContinueErrorTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueDataStateTest SinkDoContinueErrorTask002 end" << std::endl; +} + /** * @tc.name: TestSinkExecute001 * @tc.desc: Execute @@ -571,6 +639,9 @@ HWTEST_F(DSchedContinueSinkEndStateTest, TestSinkExecute002, TestSize.Level3) }; int32_t ret = sinkEndStateTest_->Execute(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_NE(ret, ERR_OK); + + ret = sinkEndStateTest_->Execute(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkExecute002 end" << std::endl; } @@ -607,9 +678,33 @@ HWTEST_F(DSchedContinueSinkEndStateTest, TestSinkDoContinueEndTask001, TestSize. }; int32_t ret = sinkEndStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_NE(ret, ERR_OK); + + sinkEndStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_NE(ret, ERR_OK); + + std::shared_ptr dContinue = CreateObject(); + sinkEndStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_NE(ret, ERR_OK); DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkDoContinueEndTask001 end" << std::endl; } +/** + * @tc.name: TestSinkDoContinueEndTask002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSinkEndStateTest, TestSinkDoContinueEndTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkDoContinueEndTask002 begin" << std::endl; + ASSERT_NE(sinkEndStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = sinkEndStateTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSinkEndStateTest TestSinkDoContinueEndTask002 end" << std::endl; +} + /** * @tc.name: SinkExecuteTest_001 * @tc.desc: Execute @@ -629,6 +724,9 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkExecuteTest_001, TestSize.Level3) }; int32_t ret = sinkStartStateTest_->Execute(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_EQ(ret, CONTINUE_STATE_MACHINE_INVALID_STATE); + + ret = sinkStartStateTest_->Execute(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkStartStateTest SinkExecuteTest_001 end" << std::endl; } @@ -688,6 +786,15 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinuePullReqTaskTest_001, Te int32_t ret = sinkStartStateTest_->DoContinuePullReqTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = sinkStartStateTest_->DoContinuePullReqTask(nullptr, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkStartStateTest_->DoContinuePullReqTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkStartStateTest SinkDoContinuePullReqTaskTest_001 end" << std::endl; } @@ -711,6 +818,15 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueAbilityTaskTest_001, Te int32_t ret = sinkStartStateTest_->DoContinueAbilityTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = sinkStartStateTest_->DoContinueAbilityTask(nullptr, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkStartStateTest_->DoContinueAbilityTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkStartStateTest SinkDoContinueAbilityTaskTest_001 end" << std::endl; } @@ -734,6 +850,15 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueEndTaskTest_001, TestSi int32_t ret = sinkStartStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = sinkStartStateTest_->DoContinueEndTask(nullptr, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkStartStateTest_->DoContinueEndTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkStartStateTest SinkDoContinueEndTaskTest_001 end" << std::endl; } @@ -756,6 +881,15 @@ HWTEST_F(DSchedContinueSinkStartStateTest, SinkDoContinueErrorTask001, TestSize. }; int32_t ret = sinkStartStateTest_->DoContinueErrorTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_NE(ret, ERR_OK); + + ret = sinkStartStateTest_->DoContinueErrorTask(nullptr, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkStartStateTest_->DoContinueErrorTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkStartStateTest SinkDoContinueErrorTask001 end" << std::endl; } @@ -844,9 +978,30 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoNotifyCompleteTask001, TestSi ret = sinkWaitEndTest_->DoNotifyCompleteTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkWaitEndTest_->DoNotifyCompleteTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoNotifyCompleteTask001 end" << std::endl; } + /** + * @tc.name: SinkDoNotifyCompleteTask002 + * @tc.desc: DoNotifyCompleteTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoNotifyCompleteTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoNotifyCompleteTask002 begin" << std::endl; + ASSERT_NE(sinkWaitEndTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = sinkWaitEndTest_->DoNotifyCompleteTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoNotifyCompleteTask002 end" << std::endl; +} + /** * @tc.name: SinkDoContinueEndTask001 * @tc.desc: DoContinueEndTask @@ -870,9 +1025,30 @@ HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoContinueEndTask001, TestSize. ret = sinkWaitEndTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = sinkWaitEndTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoContinueEndTask001 end" << std::endl; } + /** + * @tc.name: SinkDoContinueEndTask002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSinkWaitEndStateTest, SinkDoContinueEndTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoContinueEndTask002 begin" << std::endl; + ASSERT_NE(sinkWaitEndTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = sinkWaitEndTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSinkWaitEndStateTest SinkDoContinueEndTask002 end" << std::endl; +} + /** * @tc.name: SrcExecuteTest001 * @tc.desc: Execute @@ -956,9 +1132,30 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueSendTask001, TestSize.Leve ret = abilityStateTest_->DoContinueSendTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = abilityStateTest_->DoContinueSendTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueSendTask001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueSendTask002 + * @tc.desc: DoContinueSendTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueSendTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueSendTask002 begin" << std::endl; + ASSERT_NE(abilityStateTest_, nullptr); + auto data = std::make_shared(); + auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_SEND_DATA_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = abilityStateTest_->DoContinueSendTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueSendTask002 end" << std::endl; +} + /** * @tc.name: SrcDoContinueEndTask001 * @tc.desc: DoContinueEndTask @@ -981,9 +1178,30 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueEndTask001, TestSize.Level ret = abilityStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = abilityStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueEndTask001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueErrorTask002 + * @tc.desc: DoContinueErrorTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueErrorTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueErrorTask002 begin" << std::endl; + ASSERT_NE(abilityStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = abilityStateTest_->DoContinueErrorTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueErrorTask002 end" << std::endl; +} + /** * @tc.name: SrcDoContinueErrorTask001 * @tc.desc: DoContinueErrorTask @@ -1006,9 +1224,30 @@ HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueErrorTask001, TestSize.Lev ret = abilityStateTest_->DoContinueErrorTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = abilityStateTest_->DoContinueErrorTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueErrorTask001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueEndTask002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueAbilityStateTest, SrcDoContinueEndTask002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueEndTask002 begin" << std::endl; + ASSERT_NE(abilityStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = abilityStateTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueAbilityStateTest SrcDoContinueEndTask002 end" << std::endl; +} + /** * @tc.name: SrcExecuteTest001 * @tc.desc: Execute @@ -1092,9 +1331,30 @@ HWTEST_F(DSchedContinueEndStateTest, SrcDoContinueEndTaskTest001, TestSize.Level ret = srcEndStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = srcEndStateTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueEndStateTest SrcDoContinueEndTaskTest001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueEndTaskTest002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueEndStateTest, SrcDoContinueEndTaskTest002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueEndStateTest SrcDoContinueEndTaskTest002 begin" << std::endl; + ASSERT_NE(srcEndStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcEndStateTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueEndStateTest SrcDoContinueEndTaskTest002 end" << std::endl; +} + /** * @tc.name: SrcExecuteTest_001 * @tc.desc: Execute @@ -1182,6 +1442,60 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinuePushReqTaskTest_001, T DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_001 end" << std::endl; } + /** + * @tc.name: SrcDoContinuePushReqTaskTest_002 + * @tc.desc: DoContinuePushReqTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinuePushReqTaskTest_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_002 begin" << std::endl; + ASSERT_NE(srcStartStateTest_, nullptr); + AppExecFwk::InnerEvent *event = new AppExecFwk::InnerEvent(); + ASSERT_NE(event, nullptr); + event->innerEventId_ = static_cast(-1); + auto destructor = [](AppExecFwk::InnerEvent *event) { + if (event != nullptr) { + delete event; + } + }; + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcStartStateTest_->DoContinuePushReqTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = srcStartStateTest_->DoContinueErrorTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = srcStartStateTest_->DoContinueAbilityTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = srcStartStateTest_->DoContinueEndTask(dContinue, + AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_002 end" << std::endl; +} + + /** + * @tc.name: SrcDoContinuePushReqTaskTest_003 + * @tc.desc: DoContinuePushReqTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinuePushReqTaskTest_003, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_003 begin" << std::endl; + ASSERT_NE(srcStartStateTest_, nullptr); + AAFwk::WantParams wantParams; + auto wantParamsPtr = std::make_shared(wantParams); + auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_REQ_PUSH_EVENT, wantParamsPtr, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcStartStateTest_->DoContinuePushReqTask(dContinue, event); + EXPECT_NE(ret, ERR_OK); + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinuePushReqTaskTest_003 end" << std::endl; +} + /** * @tc.name: SrcDoContinueAbilityTaskTest_001 * @tc.desc: DoContinueAbilityTask @@ -1208,6 +1522,23 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueAbilityTaskTest_001, T DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueAbilityTaskTest_001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueAbilityTaskTest_002 + * @tc.desc: DoContinueAbilityTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueAbilityTaskTest_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueAbilityTaskTest_002 begin" << std::endl; + ASSERT_NE(srcStartStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSHCED_CONTINUE_ABILITY_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcStartStateTest_->DoContinueAbilityTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueAbilityTaskTest_002 end" << std::endl; +} + /** * @tc.name: SrcDoContinueEndTaskTest_001 * @tc.desc: DoContinueEndTask @@ -1234,6 +1565,23 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueEndTaskTest_001, TestS DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueEndTaskTest_001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueEndTaskTest_002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueEndTaskTest_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueEndTaskTest_002 begin" << std::endl; + ASSERT_NE(srcStartStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcStartStateTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueEndTaskTest_002 end" << std::endl; +} + /** * @tc.name: SrcDoContinueErrorTask001 * @tc.desc: DoContinueErrorTask @@ -1254,11 +1602,28 @@ HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueErrorTask001, TestSize int32_t ret = srcStartStateTest_->DoContinueErrorTask(nullptr, AppExecFwk::InnerEvent::Pointer(event, destructor)); EXPECT_NE(ret, ERR_OK); - ret = srcStartStateTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + ret = srcStartStateTest_->DoContinueErrorTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueErrorTask001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueErrorTaskTest_002 + * @tc.desc: DoContinueErrorTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueSourceStartStateTest, SrcDoContinueErrorTaskTest_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueErrorTaskTest_002 begin" << std::endl; + ASSERT_NE(srcStartStateTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcStartStateTest_->DoContinueErrorTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueSourceStartStateTest SrcDoContinueErrorTaskTest_002 end" << std::endl; +} + /** * @tc.name: SrcExecute_001 * @tc.desc: Execute @@ -1343,9 +1708,30 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoNotifyCompleteTask_001, TestSize.L ret = srcWaitEndTest_->DoNotifyCompleteTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = srcWaitEndTest_->DoNotifyCompleteTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoNotifyCompleteTask_001 end" << std::endl; } + /** + * @tc.name: SrcDoNotifyCompleteTask_002 + * @tc.desc: DoNotifyCompleteTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoNotifyCompleteTask_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoNotifyCompleteTask_002 begin" << std::endl; + ASSERT_NE(srcWaitEndTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_COMPLETE_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcWaitEndTest_->DoNotifyCompleteTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoNotifyCompleteTask_002 end" << std::endl; +} + /** * @tc.name: SrcDoContinueEndTask_001 * @tc.desc: DoContinueEndTask @@ -1369,9 +1755,29 @@ HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoContinueEndTask_001, TestSize.Leve ret = srcWaitEndTest_->DoContinueEndTask(nullptr, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + std::shared_ptr dContinue = CreateObject(); + ret = srcWaitEndTest_->DoContinueEndTask(dContinue, AppExecFwk::InnerEvent::Pointer(nullptr, nullptr)); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoContinueEndTask_001 end" << std::endl; } + /** + * @tc.name: SrcDoContinueEndTask_002 + * @tc.desc: DoContinueEndTask + * @tc.type: FUNC + */ +HWTEST_F(DSchedContinueWaitEndStateTest, SrcDoContinueEndTask_002, TestSize.Level3) +{ + DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoContinueEndTask_002 begin" << std::endl; + ASSERT_NE(srcWaitEndTest_, nullptr); + auto data = std::make_shared(1); + auto event = AppExecFwk::InnerEvent::Get(DSCHED_CONTINUE_END_EVENT, data, 0); + std::shared_ptr dContinue = CreateObject(); + int32_t ret = srcWaitEndTest_->DoContinueEndTask(dContinue, event); + EXPECT_NE(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedContinueWaitEndStateTest SrcDoContinueEndTask_002 end" << std::endl; +} /** * @tc.name: Execute_001 diff --git a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.h b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.h index a7765d7d..eb4fe1cf 100644 --- a/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.h +++ b/services/dtbschedmgr/test/unittest/continue/dsched_continue_state_test.h @@ -27,6 +27,7 @@ #include "dsched_continue_source_start_state.h" #include "dsched_continue_source_wait_end_state.h" #include "dsched_continue_state_machine.h" +#include "mock_dtbschedmgr_device_info.h" namespace OHOS { namespace DistributedSchedule { @@ -39,6 +40,7 @@ public: void TearDown(); std::shared_ptr CreateObject(); std::shared_ptr dataStateTest_; + static inline std::shared_ptr mockStateTest_ = nullptr; }; class DSchedContinueSinkEndStateTest : public testing::Test { diff --git a/services/dtbschedmgr/test/unittest/continue_scene_session_handler_test.cpp b/services/dtbschedmgr/test/unittest/continue_scene_session_handler_test.cpp index 1b5536dd..b5d2866e 100644 --- a/services/dtbschedmgr/test/unittest/continue_scene_session_handler_test.cpp +++ b/services/dtbschedmgr/test/unittest/continue_scene_session_handler_test.cpp @@ -13,7 +13,9 @@ * limitations under the License. */ +#define private public #include "continue_scene_session_handler_test.h" +#undef private #include "dtbschedmgr_log.h" #include "test_log.h" @@ -90,6 +92,22 @@ HWTEST_F(ContinueSceneSessionHandlerTest, GetPersistentId_001, TestSize.Level3) DTEST_LOG << "ContinueSceneSessionHandlerTest GetPersistentId_001 end" << std::endl; } +/** + * @tc.name: GetPersistentId_002 + * @tc.desc: get persistentId by continueSessionId + * @tc.type: FUNC + * @tc.require: SR20240116512594 + */ +HWTEST_F(ContinueSceneSessionHandlerTest, GetPersistentId_002, TestSize.Level3) +{ + DTEST_LOG << "ContinueSceneSessionHandlerTest GetPersistentId_002 begin" << std::endl; + int32_t persistentId; + ContinueSceneSessionHandler::GetInstance().continueSessionId_.clear(); + int32_t err = ContinueSceneSessionHandler::GetInstance().GetPersistentId(persistentId); + EXPECT_EQ(INVALID_PARAMETERS_ERR, err); + DTEST_LOG << "ContinueSceneSessionHandlerTest GetPersistentId_002 end" << std::endl; +} + /** * @tc.name: ClearContinueSessionId_001 * @tc.desc: clear continueSessionId test diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp index 4d6d6d22..ef08cee3 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_stub_test.cpp @@ -2213,5 +2213,74 @@ HWTEST_F(DistributedSchedStubTest, StopRemoteExtensionAbilityInner_002, TestSize EXPECT_EQ(result, ERR_NONE); DTEST_LOG << "DistributedSchedStubTest StopRemoteExtensionAbilityInner_002 end" << std::endl; } + +/** + * @tc.name: IsRemoteInstall_001 + * @tc.desc: check IsRemoteInstall + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, IsRemoteInstall_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest IsRemoteInstall_001 begin" << std::endl; + std::string networkId = "networkId"; + std::string bundleName = "bundleName"; + bool result = DistributedSchedService::GetInstance().IsRemoteInstall(networkId, bundleName); + EXPECT_EQ(result, false); + DTEST_LOG << "DistributedSchedStubTest IsRemoteInstall_001 end" << std::endl; +} + +/** + * @tc.name: RegisterOffListenerInner_001 + * @tc.desc: check RegisterOffListenerInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, RegisterOffListenerInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest RegisterOffListenerInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t ret = DistributedSchedService::GetInstance().RegisterOffListenerInner(data, reply); + EXPECT_EQ(ret, ERR_FLATTEN_OBJECT); + + data.WriteString("type"); + ret = DistributedSchedService::GetInstance().RegisterOffListenerInner(data, reply); + EXPECT_EQ(ret, ERR_FLATTEN_OBJECT); + + data.WriteString("type"); + sptr onListener(new DistributedSchedService()); + data.WriteRemoteObject(onListener); + ret = DistributedSchedService::GetInstance().RegisterOffListenerInner(data, reply); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedStubTest RegisterOffListenerInner_001 end" << std::endl; +} + +/** + * @tc.name: IsUsingQos_001 + * @tc.desc: check IsUsingQos + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, IsUsingQos_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest IsUsingQos_001 begin" << std::endl; + std::string remoteDeviceId = "remoteDeviceId"; + bool result = DistributedSchedService::GetInstance().IsUsingQos(remoteDeviceId); + EXPECT_EQ(result, true); + DTEST_LOG << "DistributedSchedStubTest IsUsingQos_001 end" << std::endl; +} + +/** + * @tc.name: NotifyDSchedEventResultFromRemoteInner_001 + * @tc.desc: check NotifyDSchedEventResultFromRemoteInner + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedStubTest, NotifyDSchedEventResultFromRemoteInner_001, TestSize.Level1) +{ + DTEST_LOG << "DistributedSchedStubTest NotifyDSchedEventResultFromRemoteInner_001 begin" << std::endl; + MessageParcel data; + MessageParcel reply; + int32_t result = DistributedSchedService::GetInstance().NotifyDSchedEventResultFromRemoteInner(data, reply); + EXPECT_NE(result, ERR_NULL_OBJECT); + DTEST_LOG << "DistributedSchedStubTest NotifyDSchedEventResultFromRemoteInner_001 end" << std::endl; +} } } \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp index 71e7d062..722b6eee 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp @@ -1384,7 +1384,7 @@ HWTEST_F(DMSMissionManagerTest, testMissionSnapshotChanged001, TestSize.Level3) DistributedSchedMissionManager::GetInstance().NotifyDmsProxyProcessDied(); std::vector missionInfos; DistributedSchedMissionManager::GetInstance().InitAllSnapshots(missionInfos); - EXPECT_CALL(*mockDmsAdapter, GetLocalMissionSnapshotInfo(_, _, _)).WillOnce(Return(true)); + EXPECT_CALL(*mockDmsAdapter, GetLocalMissionSnapshotInfo(_, _, _)).WillOnce(Return(1)).WillOnce(Return(1)); auto ret = DistributedSchedMissionManager::GetInstance().MissionSnapshotChanged(NUM_MISSIONS); EXPECT_NE(ret, ERR_NONE); DTEST_LOG << "testMissionSnapshotChanged001 end" << std::endl; diff --git a/services/dtbschedmgr/test/unittest/mission/dsched_sync_e2e_test.cpp b/services/dtbschedmgr/test/unittest/mission/dsched_sync_e2e_test.cpp index 72427d43..9376ab66 100644 --- a/services/dtbschedmgr/test/unittest/mission/dsched_sync_e2e_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dsched_sync_e2e_test.cpp @@ -80,6 +80,7 @@ HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_001, TestSize.Level1) auto dmsKvSyncE2E = GetDmsKvSyncE2E(); EXPECT_NE(dmsKvSyncE2E, nullptr); if (dmsKvSyncE2E != nullptr) { + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear(); bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData(); EXPECT_EQ(ret, false); } @@ -105,6 +106,28 @@ HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_002, TestSize.Level1) DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_002 end" << std::endl; } +/** + * @tc.name: PushAndPullDataTest_003 + * @tc.desc: test insert DmsKvSyncE2E + * @tc.type: FUNC + */ +HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_003, TestSize.Level1) +{ + DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_003 start" << std::endl; + ASSERT_NE(dmsKvSyncE2E_, nullptr); + auto dmsKvSyncE2E = GetDmsKvSyncE2E(); + EXPECT_NE(dmsKvSyncE2E, nullptr); + if (dmsKvSyncE2E != nullptr) { + auto deviceInfo = std::make_shared("", 0, ""); + auto deviceInfo1 = std::make_shared("", 1, ""); + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_["deviceInfo"] = deviceInfo; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_["deviceInfo1"] = deviceInfo1; + bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData(); + EXPECT_EQ(ret, false); + } + DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_003 end" << std::endl; +} + /** * @tc.name: SetDeviceCfgTest_001 * @tc.desc: test insert DmsKvSyncE2E @@ -259,6 +282,34 @@ HWTEST_F(DmsKvSyncE2ETest, CheckBundleContinueConfigTest_001, TestSize.Level1) DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_001 end" << std::endl; } +/** + * @tc.name: CheckBundleContinueConfigTest_002 + * @tc.desc: test insert DmsKvSyncE2E + * @tc.type: FUNC + */ +HWTEST_F(DmsKvSyncE2ETest, CheckBundleContinueConfigTest_002, TestSize.Level1) +{ + DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_002 start" << std::endl; + ASSERT_NE(dmsKvSyncE2E_, nullptr); + auto dmsKvSyncE2E = GetDmsKvSyncE2E(); + EXPECT_NE(dmsKvSyncE2E, nullptr); + if (dmsKvSyncE2E != nullptr) { + const std::string bundleName = "123"; + dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = true; + dmsKvSyncE2E_->GetInstance()->whiteList_.clear(); + bool ret = dmsKvSyncE2E_->GetInstance()->CheckBundleContinueConfig(bundleName); + EXPECT_EQ(ret, false); + + dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = true; + dmsKvSyncE2E_->GetInstance()->whiteList_.clear(); + dmsKvSyncE2E_->GetInstance()->whiteList_.push_back(bundleName); + dmsKvSyncE2E_->GetInstance()->whiteList_.push_back(bundleName); + ret = dmsKvSyncE2E_->GetInstance()->CheckBundleContinueConfig(bundleName); + EXPECT_EQ(ret, true); + } + DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_002 end" << std::endl; +} + /** * @tc.name: IsValidPath_001 * @tc.desc: test IsValidPath @@ -282,5 +333,43 @@ HWTEST_F(DmsKvSyncE2ETest, IsValidPath_001, TestSize.Level1) } DTEST_LOG << "DmsKvSyncE2ETest IsValidPath_001 end" << std::endl; } + +/** + * @tc.name: UpdateWhiteListTest_001 + * @tc.desc: test UpdateWhiteList + * @tc.type: FUNC + */ +HWTEST_F(DmsKvSyncE2ETest, UpdateWhiteListTest_001, TestSize.Level1) +{ + DTEST_LOG << "DmsKvSyncE2ETest UpdateWhiteListTest_001 start" << std::endl; + ASSERT_NE(dmsKvSyncE2E_, nullptr); + auto dmsKvSyncE2E = GetDmsKvSyncE2E(); + EXPECT_NE(dmsKvSyncE2E, nullptr); + if (dmsKvSyncE2E != nullptr) { + const std::string cfgJsonStr = "cfgJsonStr"; + bool ret = dmsKvSyncE2E_->GetInstance()->UpdateWhiteList(cfgJsonStr); + EXPECT_EQ(ret, false); + } + DTEST_LOG << "DmsKvSyncE2ETest UpdateWhiteListTest_001 end" << std::endl; +} + +/** + * @tc.name: CheckKvStoreTest_001 + * @tc.desc: test CheckKvStore + * @tc.type: FUNC + */ +HWTEST_F(DmsKvSyncE2ETest, CheckKvStoreTest_001, TestSize.Level1) +{ + DTEST_LOG << "DmsKvSyncE2ETest CheckKvStoreTest_001 start" << std::endl; + ASSERT_NE(dmsKvSyncE2E_, nullptr); + auto dmsKvSyncE2E = GetDmsKvSyncE2E(); + EXPECT_NE(dmsKvSyncE2E, nullptr); + if (dmsKvSyncE2E != nullptr) { + dmsKvSyncE2E_->GetInstance()->kvStorePtr_ = nullptr; + bool ret = dmsKvSyncE2E_->GetInstance()->CheckKvStore(); + EXPECT_EQ(ret, true); + } + DTEST_LOG << "DmsKvSyncE2ETest CheckKvStoreTest_001 end" << std::endl; +} } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/test/unittest/softbus_adapter/dsched_all_connect_manager_test.cpp b/services/dtbschedmgr/test/unittest/softbus_adapter/dsched_all_connect_manager_test.cpp new file mode 100644 index 00000000..82c4b484 --- /dev/null +++ b/services/dtbschedmgr/test/unittest/softbus_adapter/dsched_all_connect_manager_test.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" + +#include "softbus_adapter/allconnectmgr/dsched_all_connect_manager.h" +#include "test_log.h" +#include "dtbschedmgr_log.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedSchedule { +class DSchedAllConnectManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void DSchedAllConnectManagerTest::SetUpTestCase() +{ +} + +void DSchedAllConnectManagerTest::TearDownTestCase() +{ +} + +void DSchedAllConnectManagerTest::SetUp() +{ +} + +void DSchedAllConnectManagerTest::TearDown() +{ +} + +/** + * @tc.name: RegistLifecycleCallback001 + * @tc.desc: call RegistLifecycleCallback + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, RegistLifecycleCallback001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest RegistLifecycleCallback001 start" << std::endl; + DSchedAllConnectManager::GetInstance().allConnectMgrApi_. + ServiceCollaborationManager_RegisterLifecycleCallback = nullptr; + int32_t ret = DSchedAllConnectManager::GetInstance().RegistLifecycleCallback(); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedAllConnectManagerTest RegistLifecycleCallback001 end" << std::endl; +} + +/** + * @tc.name: UnregistLifecycleCallback001 + * @tc.desc: call UnregistLifecycleCallback + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, UnregistLifecycleCallback001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest UnregistLifecycleCallback001 start" << std::endl; + DSchedAllConnectManager::GetInstance().allConnectMgrApi_. + ServiceCollaborationManager_UnRegisterLifecycleCallback = nullptr; + int32_t ret = DSchedAllConnectManager::GetInstance().UnregistLifecycleCallback(); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + DTEST_LOG << "DSchedAllConnectManagerTest UnregistLifecycleCallback001 end" << std::endl; +} + +/** + * @tc.name: ApplyAdvanceResource001 + * @tc.desc: call ApplyAdvanceResource + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, ApplyAdvanceResource001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest ApplyAdvanceResource001 start" << std::endl; + std::string peerNetworkId = "peerNetworkId"; + ServiceCollaborationManager_ResourceRequestInfoSets reqInfoSets; + DSchedAllConnectManager::GetInstance().allConnectMgrApi_. + ServiceCollaborationManager_ApplyAdvancedResource = nullptr; + int32_t ret = DSchedAllConnectManager::GetInstance().ApplyAdvanceResource(peerNetworkId, reqInfoSets); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DSchedAllConnectManagerTest ApplyAdvanceResource001 end" << std::endl; +} + +/** + * @tc.name: WaitAllConnectApplyCb001 + * @tc.desc: call WaitAllConnectApplyCb + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, WaitAllConnectApplyCb001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest WaitAllConnectApplyCb001 start" << std::endl; + std::string peerNetworkId = "peerNetworkId1"; + DSchedAllConnectManager::GetInstance().peerConnectDecision_.clear(); + DSchedAllConnectManager::GetInstance().peerConnectDecision_["peerNetworkId"] = true; + int32_t ret = DSchedAllConnectManager::GetInstance().WaitAllConnectApplyCb(peerNetworkId); + EXPECT_EQ(ret, DMS_CONNECT_APPLY_TIMEOUT_FAILED); + + peerNetworkId = "peerNetworkId"; + ret = DSchedAllConnectManager::GetInstance().WaitAllConnectApplyCb(peerNetworkId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DSchedAllConnectManagerTest WaitAllConnectApplyCb001 end" << std::endl; +} + +/** + * @tc.name: OnStop001 + * @tc.desc: call OnStop + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, OnStop001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest OnStop001 start" << std::endl; + std::string peerNetworkId = "peerNetworkId"; + int32_t ret = DSchedAllConnectManager::GetInstance().OnStop(peerNetworkId.c_str()); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DSchedAllConnectManagerTest OnStop001 end" << std::endl; +} + +/** + * @tc.name: ApplyResult001 + * @tc.desc: call ApplyResult + * @tc.type: FUNC + */ +HWTEST_F(DSchedAllConnectManagerTest, ApplyResult001, TestSize.Level3) +{ + DTEST_LOG << "DSchedAllConnectManagerTest ApplyResult001 start" << std::endl; + int32_t errorcode = 0; + int32_t result = 0; + std::string reason = "reason"; + while (!DSchedAllConnectManager::GetInstance().peerConnectCbQueue_.empty()) { + DSchedAllConnectManager::GetInstance().peerConnectCbQueue_.pop(); + } + int32_t ret = DSchedAllConnectManager::GetInstance().ApplyResult(errorcode, result, reason.c_str()); + EXPECT_EQ(ret, ERR_OK); + + DSchedAllConnectManager::GetInstance().peerConnectCbQueue_.push(reason); + ret = DSchedAllConnectManager::GetInstance().ApplyResult(errorcode, result, reason.c_str()); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DSchedAllConnectManagerTest ApplyResult001 end" << std::endl; +} +} // namespace DistributedSchedule +} // namespace OHOS diff --git a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp index 7eb2cab7..e383ba19 100644 --- a/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp +++ b/services/dtbschedmgr/test/unittest/softbus_adapter/softbus_transport_test.cpp @@ -29,6 +29,7 @@ constexpr uint16_t SIZE_4 = 4; constexpr uint32_t SIZE_6 = 6; constexpr size_t OFFSET_1 = 1; constexpr size_t OFFSET_2 = 2; +constexpr size_t OFFSET_3 = 3; constexpr int32_t COUNT = 2; constexpr int32_t SESSIONID = 0; constexpr uint32_t SEQ_1 = 3; @@ -207,11 +208,25 @@ HWTEST_F(DSchedDataBufferTest, SetRange_002, TestSize.Level3) { DTEST_LOG << "DSchedDataBufferTest SetRange_002 begin" << std::endl; ASSERT_NE(dataBufferTest_, nullptr); - int32_t ret = dataBufferTest_->SetRange(OFFSET_1, SIZE_2); + int32_t ret = dataBufferTest_->SetRange(OFFSET_3, SIZE_1); EXPECT_EQ(ret, -1); DTEST_LOG << "DSchedDataBufferTest SetRange_002 end" << std::endl; } +/** + * @tc.name: SetRange_003 + * @tc.desc: call SetRange + * @tc.type: FUNC + */ +HWTEST_F(DSchedDataBufferTest, SetRange_003, TestSize.Level3) +{ + DTEST_LOG << "DSchedDataBufferTest SetRange_002 begin" << std::endl; + ASSERT_NE(dataBufferTest_, nullptr); + int32_t ret = dataBufferTest_->SetRange(OFFSET_2, 0); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DSchedDataBufferTest SetRange_003 end" << std::endl; +} + /** * @tc.name: OnDisconnect_001 * @tc.desc: call OnDisconnect