!1061 UT修复与补充

Merge pull request !1061 from frank_bing/master
This commit is contained in:
openharmony_ci 2024-04-25 05:05:36 +00:00 committed by Gitee
commit 74ef4d381d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 178 additions and 6 deletions

View File

@ -1310,3 +1310,13 @@ HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest004, TestSize.Level1)
object->ReleaseDatabusProto();
ASSERT_TRUE(object->handle_ != 0);
}
HWTEST_F(IPCObjectProxyTest, GetStrongRefCountForStubTest001, TestSize.Level1)
{
sptr<IPCObjectProxy> 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);
}

View File

@ -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

View File

@ -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<char *>(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<ssize_t>(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<DeviceLock> 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);
}

View File

@ -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 = 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> dBinderService ;
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::shared_ptr<RpcSystemAbilityCallback> 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> dBinderService ;
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::shared_ptr<RpcSystemAbilityCallback> 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> dBinderService;
sptr<DBinderService> dBinderService = DBinderService::GetInstance();
std::shared_ptr<RpcSystemAbilityCallback> 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 = DBinderService::GetInstance();
std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
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