diff --git a/services/softbusadapter/test/unittest/include/softbus_adapter_test.h b/services/softbusadapter/test/unittest/include/softbus_adapter_test.h index 10b0cc7521ad2a78a5b1211e751391f8a3aaf6fc..134b103b3d71a2e141c6d018483579444b9d2cf6 100644 --- a/services/softbusadapter/test/unittest/include/softbus_adapter_test.h +++ b/services/softbusadapter/test/unittest/include/softbus_adapter_test.h @@ -22,6 +22,7 @@ #include "softbus_bus_center.h" #include "softbus_common.h" +#include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_util.h" #define private public diff --git a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp index d696f7050f3710082f64ae7f413b6d5c0e6ad68e..f8a389f3523c5d622b7e780acf9199078d33f0f0 100644 --- a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp +++ b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp @@ -36,11 +36,13 @@ void SoftbusAdapterTest::TearDown(void) {} HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_001, TestSize.Level1) { std::shared_ptr listener = nullptr; - std::string sessionName; - std::string peerDevId; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; int32_t actual = softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId); + EXPECT_EQ(DH_SUCCESS, actual); + actual = softbusAdapter.UnRegisterSoftbusListener(sessionName, peerDevId); EXPECT_EQ(DH_SUCCESS, actual); } @@ -53,12 +55,13 @@ HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_001, TestSize.Level1) HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_002, TestSize.Level1) { std::shared_ptr listener = nullptr; - std::string sessionName = "hello"; - std::string peerDevId = "world"; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; - softbusAdapter.mapListeners_["hello_world"] = listener; int32_t actual = softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId); + EXPECT_EQ(DH_SUCCESS, actual); + actual = softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId); EXPECT_EQ(ERR_DH_SCREEN_ADAPTER_REGISTER_SOFTBUS_LISTENER_FAIL, actual); } @@ -70,8 +73,8 @@ HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_002, TestSize.Level1) */ HWTEST_F(SoftbusAdapterTest, UnRegisterSoftbusListener_001, TestSize.Level1) { - std::string sessionName = "hello"; - std::string peerDevId = "world"; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; int32_t actual = softbusAdapter.UnRegisterSoftbusListener(sessionName, peerDevId); @@ -86,14 +89,18 @@ HWTEST_F(SoftbusAdapterTest, UnRegisterSoftbusListener_001, TestSize.Level1) */ HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1) { - std::string pkgname = "hello"; - std::string sessionName = "world"; - std::string peerDevId = "world"; + std::string pkgname = PKG_NAME; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; - softbusAdapter.mapSessionSet_[sessionName].insert(peerDevId); int32_t actual = softbusAdapter.CreateSoftbusSessionServer(pkgname, sessionName, peerDevId); + EXPECT_EQ(DH_SUCCESS, actual); + actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId); EXPECT_EQ(DH_SUCCESS, actual); + + actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId); + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, actual); } /** @@ -104,33 +111,15 @@ HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1) */ HWTEST_F(SoftbusAdapterTest, RemoveSoftbusSessionServer_001, TestSize.Level1) { - std::string pkgname = "hello"; - std::string sessionName = "world"; - std::string peerDevId = "world"; + std::string pkgname = PKG_NAME; + std::string sessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; int32_t actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId); EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, actual); } -/** - * @tc.name: RemoveSoftbusSessionServer_002 - * @tc.desc: Verify the RemoveSoftbusSessionServer function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(SoftbusAdapterTest, RemoveSoftbusSessionServer_002, TestSize.Level1) -{ - std::string pkgname = "hello"; - std::string sessionName = "world"; - std::string peerDevId = "world"; - - softbusAdapter.mapSessionSet_[sessionName].insert(peerDevId); - int32_t actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId); - - EXPECT_EQ(DH_SUCCESS, actual); -} - /** * @tc.name: OpenSoftbusSession_001 * @tc.desc: Verify the OpenSoftbusSession function. @@ -140,8 +129,8 @@ HWTEST_F(SoftbusAdapterTest, RemoveSoftbusSessionServer_002, TestSize.Level1) HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_001, TestSize.Level1) { std::string mySessionName = DATA_SESSION_NAME; - std::string peerSessionName = "world"; - std::string peerDevId = "world"; + std::string peerSessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; int32_t actual = softbusAdapter.OpenSoftbusSession(mySessionName, peerSessionName, peerDevId); @@ -156,9 +145,9 @@ HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_001, TestSize.Level1) */ HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_002, TestSize.Level1) { - std::string mySessionName = "hello"; - std::string peerSessionName = "world"; - std::string peerDevId = "world"; + std::string mySessionName = DATA_SESSION_NAME; + std::string peerSessionName = DATA_SESSION_NAME; + std::string peerDevId = "testDevId"; int32_t actual = softbusAdapter.OpenSoftbusSession(mySessionName, peerSessionName, peerDevId);