fix: ut coverage

Signed-off-by: 居凯 <shun0304@126.com>
Change-Id: I66e84d0b91d8067c2c8bf8cac37f734b49a9a0f2
This commit is contained in:
居凯 2024-11-15 11:51:27 +08:00
parent 9d50f17cf5
commit 0a15c280f1

View File

@ -51,6 +51,12 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestCheckAndCopyStr, TestSize.Level0)
EXPECT_EQ(SoftBusManager::GetInstance().CheckAndCopyStr(dest, destLen, src), false);
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnBind_001, TestSize.Level0)
{
PeerSocketInfo info;
EXPECT_NO_THROW(SoftBusManager::GetInstance().OnBind(-2, info));
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestSocketUnInit_001, TestSize.Level0)
{
EXPECT_NO_THROW({
@ -88,6 +94,13 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestUnRegistSoftBusListener, TestSize
});
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestDeleteSocket, TestSize.Level0)
{
EXPECT_NO_THROW({
SoftBusManager::GetInstance().DeleteSocket(600);
});
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestServiceSocketListen, TestSize.Level0)
{
int32_t socketId = 100;
@ -96,6 +109,10 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestServiceSocketListen, TestSize.Lev
std::shared_ptr<BaseSocket> serverSocket = SocketFactory::CreateServerSocket(socketId);
int ret = SoftBusManager::GetInstance().ServiceSocketListen(socketId);
EXPECT_EQ(ret, LISTEN_SOCKET_FAILED);
PeerSocketInfo info;
EXPECT_NO_THROW(SoftBusManager::GetInstance().OnBind(socketId, info));
SoftBusManager::GetInstance().AddSocket(socketId, serverSocket);
SoftBusManager::GetInstance().SetServerSocket(serverSocket);
@ -110,9 +127,19 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestServiceSocketListen, TestSize.Lev
SoftBusManager::GetInstance().AddSocket(clientSocketId, clientSocket);
RemoteConnectListenerManager::GetInstance().OnConnectionUp(connectionName);
const std::string srcEndPoint = "123";
const std::string destEndPoint = "456";
const std::shared_ptr<Attributes> attributes = Common::MakeShared<Attributes>();
ASSERT_NE(attributes, nullptr);
MsgCallback callback;
EXPECT_EQ(SoftBusManager::GetInstance().SendMessage(connectionName, srcEndPoint, destEndPoint, attributes,
callback), 2);
EXPECT_EQ(SoftBusManager::GetInstance().DoCloseConnection(connectionName), SUCCESS);
SoftBusManager::GetInstance().ServiceSocketUnInit();
SoftBusManager::GetInstance().UnRegistSoftBusListener();
SoftBusManager::GetInstance().DeleteSocket(socketId);
SoftBusManager::GetInstance().DeleteSocket(clientSocketId);
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOpenConnection, TestSize.Level0)
@ -124,15 +151,56 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOpenConnection, TestSize.Level0)
EXPECT_EQ(SoftBusManager::GetInstance().DoCloseConnection(connectionName), GENERAL_ERROR);
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnServerBytes_001, TestSize.Level0)
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestServiceSocketUnInit_003, TestSize.Level0)
{
int32_t socketId = 100;
int32_t clientSocketId = 200;
const std::string connectionName = "testConnection";
const std::string networkId = "networkId";
SoftBusManager::GetInstance().ServiceSocketInit();
std::shared_ptr<BaseSocket> serverSocket = SocketFactory::CreateServerSocket(socketId);
std::shared_ptr<BaseSocket> clientSocket = SocketFactory::CreateClientSocket(clientSocketId,
connectionName, networkId);
SoftBusManager::GetInstance().AddSocket(socketId, serverSocket);
SoftBusManager::GetInstance().AddSocket(clientSocketId, clientSocket);
SoftBusManager::GetInstance().SetServerSocket(serverSocket);
auto findSocket = SoftBusManager::GetInstance().FindSocketBySocketId(socketId);
EXPECT_NE(findSocket, nullptr);
SoftBusManager::GetInstance().ServiceSocketUnInit();
SoftBusManager::GetInstance().DeleteSocket(socketId);
SoftBusManager::GetInstance().DeleteSocket(clientSocketId);
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnServerBytes_001, TestSize.Level0)
{
const void *data = new char[10];
uint32_t dataLen = 3;
int32_t socketId = 100;
int32_t clientSocketId = 200;
const std::string connectionName = "testConnection";
const std::string networkId = "networkId";
std::shared_ptr<BaseSocket> serverSocket = SocketFactory::CreateServerSocket(socketId);
std::shared_ptr<BaseSocket> clientSocket = SocketFactory::CreateClientSocket(clientSocketId,
connectionName, networkId);
SoftBusManager::GetInstance().AddSocket(socketId, serverSocket);
SoftBusManager::GetInstance().AddSocket(clientSocketId, clientSocket);
SoftBusManager::GetInstance().SetServerSocket(serverSocket);
EXPECT_NO_THROW({
SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen);
SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen);
});
SoftBusManager::GetInstance().ServiceSocketUnInit();
SoftBusManager::GetInstance().DeleteSocket(socketId);
SoftBusManager::GetInstance().DeleteSocket(clientSocketId);
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnShutdown_001, TestSize.Level0)
{
ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN;
EXPECT_NO_THROW(SoftBusManager::GetInstance().OnShutdown(-2, reason));
SoftBusManager::GetInstance().ClearServerSocket();
EXPECT_NO_THROW(SoftBusManager::GetInstance().OnShutdown(600, reason));
}
HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnServerBytes_002, TestSize.Level0)