diff --git a/ipc/native/test/unittest/common/ipc_object_proxy_unittest.cpp b/ipc/native/test/unittest/common/ipc_object_proxy_unittest.cpp index f4958558..27cc9ebe 100644 --- a/ipc/native/test/unittest/common/ipc_object_proxy_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_object_proxy_unittest.cpp @@ -1310,3 +1310,13 @@ HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest004, TestSize.Level1) object->ReleaseDatabusProto(); ASSERT_TRUE(object->handle_ != 0); } + +HWTEST_F(IPCObjectProxyTest, GetStrongRefCountForStubTest001, TestSize.Level1) +{ + sptr object = new IPCObjectProxy( + 1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE); + + object->proto_ = IRemoteObject::IF_PROT_DEFAULT; + uint32_t count = object->GetStrongRefCountForStub(); + ASSERT_TRUE(count == 0); +} \ No newline at end of file diff --git a/services/dbinder/test/unittest/dbinder_death_recipient_unittest.cpp b/services/dbinder/test/unittest/dbinder_death_recipient_unittest.cpp index ba8204cb..0fc49f66 100644 --- a/services/dbinder/test/unittest/dbinder_death_recipient_unittest.cpp +++ b/services/dbinder/test/unittest/dbinder_death_recipient_unittest.cpp @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "rpc_log.h" #include "log_tags.h" -#include "session_impl.h" #define private public #include "dbinder_death_recipient.h" #undef private diff --git a/services/dbinder/test/unittest/dbinder_remote_listener_unittest.cpp b/services/dbinder/test/unittest/dbinder_remote_listener_unittest.cpp index 304c4386..3da9ac15 100644 --- a/services/dbinder/test/unittest/dbinder_remote_listener_unittest.cpp +++ b/services/dbinder/test/unittest/dbinder_remote_listener_unittest.cpp @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "rpc_log.h" #include "log_tags.h" -#include "session_impl.h" #define private public #include "dbinder_remote_listener.h" #undef private @@ -32,6 +31,7 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + const std::string NETWORKID_TEST = "123456789"; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "DBinderRemoteListenerUnitTest" }; }; @@ -49,3 +49,140 @@ HWTEST_F(DBinderRemoteListenerUnitTest, CreateClientSocket_001, TestSize.Level1) std::string networkId = ""; EXPECT_EQ(dBinderRemoteListener.CreateClientSocket(networkId), SOCKET_ID_INVALID); } + +HWTEST_F(DBinderRemoteListenerUnitTest, ServerOnBind_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + int32_t socketId = 1; + PeerSocketInfo info = { + .networkId = const_cast(NETWORKID_TEST.c_str()), + }; + + dBinderRemoteListener.ServerOnBind(socketId, info); + EXPECT_NE(dBinderRemoteListener.serverSocketInfos_.size(), 0); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, ServerOnShutdown_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + std::string networkId = "networkId"; + int32_t socketId = 1; + dBinderRemoteListener.clientSocketInfos_[networkId] = socketId; + dBinderRemoteListener.ServerOnShutdown(socketId, SHUTDOWN_REASON_PEER); + EXPECT_EQ(dBinderRemoteListener.serverSocketInfos_.size(), 0); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const char* data = nullptr; + auto len = sizeof(struct DHandleEntryTxRx); + int32_t socketId = 1; + dBinderRemoteListener.OnBytesReceived(socketId, data, len); + EXPECT_EQ(data, nullptr); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_002, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const char *data = "testdatas"; + ssize_t len = 0; + int32_t socketId = 1; + dBinderRemoteListener.OnBytesReceived(socketId, data, len); + EXPECT_EQ(len < static_cast(sizeof(struct DHandleEntryTxRx)), true); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, onbytesreceived_003, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + auto len = sizeof(struct DHandleEntryTxRx); + dBinderRemoteListener.OnBytesReceived(1, nullptr, len); + EXPECT_EQ(dBinderRemoteListener.listenSocketId_, SOCKET_ID_INVALID); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, senddatatoremote_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = "testdeviceid"; + EXPECT_EQ(dBinderRemoteListener.SendDataToRemote(deviceId, nullptr), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, senddatatoremote_002, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = ""; + DHandleEntryTxRx message; + message.head.len = sizeof(DHandleEntryTxRx); + EXPECT_EQ(dBinderRemoteListener.SendDataToRemote(deviceId, &message), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, senddatatoremote_003, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = "123"; + DHandleEntryTxRx message; + message.head.len = sizeof(DHandleEntryTxRx); + EXPECT_EQ(dBinderRemoteListener.SendDataToRemote(deviceId, &message), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, startlistener_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + EXPECT_EQ(dBinderRemoteListener.StartListener(), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, StopListener_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + EXPECT_EQ(dBinderRemoteListener.StopListener(), true); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, closedatabussession_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = ""; + EXPECT_EQ(dBinderRemoteListener.ShutdownSocket(deviceId), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, QueryOrNewDeviceLock_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = ""; + dBinderRemoteListener.QueryOrNewDeviceLock(deviceId); + const std::string deviceId1 = "123456"; + std::shared_ptr lockInfo = nullptr; + lockInfo = dBinderRemoteListener.QueryOrNewDeviceLock(deviceId1); + EXPECT_TRUE(lockInfo != nullptr); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = ""; + EXPECT_EQ(dBinderRemoteListener.SendDataReply(deviceId, nullptr), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_002, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = ""; + DHandleEntryTxRx message; + message.deviceIdInfo.fromDeviceId[0] = 't'; + EXPECT_EQ(dBinderRemoteListener.SendDataReply(deviceId, &message), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, SendDataReply_003, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string deviceId = "12345"; + DHandleEntryTxRx message; + message.deviceIdInfo.fromDeviceId[0] = 't'; + EXPECT_EQ(dBinderRemoteListener.SendDataReply(deviceId, &message), false); +} + +HWTEST_F(DBinderRemoteListenerUnitTest, OpenSoftbusSession_001, TestSize.Level1) +{ + DBinderRemoteListener dBinderRemoteListener; + const std::string peerDeviceId = "12345"; + EXPECT_EQ(dBinderRemoteListener.CreateClientSocket(peerDeviceId), SOCKET_ID_INVALID); +} diff --git a/services/dbinder/test/unittest/dbinder_service_unittest.cpp b/services/dbinder/test/unittest/dbinder_service_unittest.cpp index 36ec1648..30a165c7 100755 --- a/services/dbinder/test/unittest/dbinder_service_unittest.cpp +++ b/services/dbinder/test/unittest/dbinder_service_unittest.cpp @@ -24,7 +24,6 @@ #include "rpc_log.h" #include "log_tags.h" #include "string_ex.h" -#include "session_impl.h" using namespace testing::ext; using namespace OHOS; @@ -67,6 +66,18 @@ public: } }; +/* + * @tc.name: ProcessOnSessionClosed001 + * @tc.desc: Verify the ProcessOnSessionClosed function + * @tc.type: FUNC + */ +HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1) +{ + sptr dBinderService = DBinderService::GetInstance(); + std::string networkId = "1234567890"; + EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true); +} + /** * @tc.name: StartDBinderService001 * @tc.desc: Verify the StartDBinderService function @@ -74,7 +85,7 @@ public: */ HWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1) { - sptr dBinderService ; + sptr dBinderService = DBinderService::GetInstance(); std::shared_ptr callbackImpl = nullptr; bool res = dBinderService->StartDBinderService(callbackImpl); EXPECT_EQ(res, false); @@ -87,7 +98,7 @@ HWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1) */ HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1) { - sptr dBinderService ; + sptr dBinderService = DBinderService::GetInstance(); std::shared_ptr callbackImpl = nullptr; DBinderService::mainThreadCreated_ = true; bool res = dBinderService->StartDBinderService(callbackImpl); @@ -101,7 +112,7 @@ HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1) */ HWTEST_F(DBinderServiceUnitTest, StartDBinderService003, TestSize.Level1) { - sptr dBinderService; + sptr dBinderService = DBinderService::GetInstance(); std::shared_ptr callbackImpl = nullptr; DBinderService::mainThreadCreated_ = false; dBinderService->remoteListener_ = nullptr; @@ -999,6 +1010,21 @@ HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest002, TestSize. &objectProxy, &replyMessage, remoteDeviceId, pid, uid, tokenId), DBinderErrorCode::SESSION_NAME_NOT_FOUND); } +/* + * @tc.name: ProcessOnSessionClosedTest002 + * @tc.desc: Verify the ProcessOnSessionClosed function + * @tc.type: FUNC + */ +HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosedTest002, TestSize.Level1) +{ + sptr dBinderService = DBinderService::GetInstance(); + std::shared_ptr threadLockInfo = std::make_shared(); + uint32_t seqNumber = 10; + std::string networkId = "networkId"; + dBinderService->AttachThreadLockInfo(seqNumber, networkId, threadLockInfo); + EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true); +} + /** * @tc.name: FindDBinderStub001 * @tc.desc: Verify the FindDBinderStub function