Fix:add ut

Signed-off-by: l30044017 <liuqiang254@huawei.com>
https://gitee.com/openharmony/communication_dsoftbus/issues/IB57TY
This commit is contained in:
l30044017 2024-11-18 21:01:14 +08:00
parent 8e5ca2ff5a
commit 201a238252
5 changed files with 31 additions and 3 deletions

View File

@ -384,12 +384,13 @@ static int32_t TransListCopy(ListNode *sessionServerList)
void TransOnLinkDown(const char *networkId, const char *uuid, const char *udid, const char *peerIp, int32_t type)
{
#define USER_SWITCH_OFFSET 10
if (networkId == NULL || g_sessionServerList == NULL) {
return;
}
int32_t routeType = (int32_t)GET_ROUTE_TYPE(type);
int32_t connType = (int32_t)GET_CONN_TYPE(type);
bool isUserSwitchEvent = (bool)((routeType >> 10) & 0xff);
bool isUserSwitchEvent = (bool)((type >> USER_SWITCH_OFFSET) & 0xff);
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
TRANS_LOGI(TRANS_CTRL,

View File

@ -1810,12 +1810,13 @@ static void TransNotifyOffLine(const LnnEventBasicInfo *info)
static void TransNotifyUserSwitch(const LnnEventBasicInfo *info)
{
#define USER_SWITCH_OFFSET 10
TRANS_CHECK_AND_RETURN_LOGE(info != NULL, TRANS_CTRL, "invalid Lnn info");
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
SoftBusUserSwitchState userSwitchState = (SoftBusUserSwitchState)event->status;
switch (userSwitchState) {
case SOFTBUS_USER_SWITCHED: {
TransOnLinkDown("", "", "", "", ROUTE_TYPE_ALL | 1 << 10);
TransOnLinkDown("", "", "", "", ROUTE_TYPE_ALL | 1 << USER_SWITCH_OFFSET);
break;
}
case SOFTBUS_USER_SWITCH_UNKNOWN:

View File

@ -367,4 +367,25 @@ HWTEST_F(SoftbusTransProxyChannelManagerTest, TransProxyFillChannelInfo004, Test
int32_t ret = TransProxyFillChannelInfo(&msg, &chan);
EXPECT_EQ(ret, SOFTBUS_TRANS_CHECK_ACL_FAILED);
}
/**
* @tc.name: TransNotifyUserSwitchTest001
* @tc.desc: client send file crc check sum, use normal parameter.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusTransProxyChannelManagerTest, TransNotifyUserSwitchTest001, TestSize.Level0)
{
LnnMonitorHbStateChangedEvent *info = (LnnMonitorHbStateChangedEvent *)SoftBusCalloc(
sizeof(LnnMonitorHbStateChangedEvent));
ASSERT_TRUE(info != nullptr);
info->basic.event = LNN_EVENT_BT_STATE_CHANGED;
info->status = SOFTBUS_USER_SWITCHED;
TransNotifyUserSwitch(nullptr);
const LnnEventBasicInfo *event = (const LnnEventBasicInfo *)info;
TransNotifyUserSwitch(event);
info->status = SOFTBUS_USER_SWITCH_UNKNOWN;
TransNotifyUserSwitch(event);
SoftBusFree(info);
}
} // namespace OHOS

View File

@ -88,7 +88,6 @@ void TransClientSessionManagerTest::TearDownTestCase(void)
ConnServerDeinit();
AuthDeinit();
BusCenterServerDeinit();
TransServerDeinit();
}
static int32_t OnSessionOpened(int32_t sessionId, int32_t result)
@ -1551,5 +1550,8 @@ HWTEST_F(TransClientSessionManagerTest, TransClientSessionManagerTest51, TestSiz
ret = ClientSignalSyncBind(1, 0);
EXPECT_EQ(ret, SOFTBUS_TRANS_SESSION_SERVER_NOINIT);
ClientTransOnUserSwitch();
TransServerDeinit();
ClientTransOnUserSwitch();
}
}

View File

@ -970,6 +970,9 @@ HWTEST_F(TransClientSessionTest, TransClientSessionTest27, TestSize.Level1)
{
ClientSessionServer *server = GetNewSessionServer(SEC_TYPE_PLAINTEXT, g_sessionName, g_pkgName, &g_sessionlistener);
ASSERT_TRUE(server != NULL);
ListNode destroyList;
DestroyAllClientSession(nullptr, &destroyList);
DestroyAllClientSession(server, nullptr);
SoftBusFree(server);
char sessionName[SESSION_NAME_SIZE_MAX + 2] = {0};
memset_s(sessionName, sizeof(sessionName), 'A', SESSION_NAME_SIZE_MAX + 1);