mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 08:49:59 +00:00
clear code check
Signed-off-by: xzh457 <xiaozihan4@h-partners.com> Change-Id: Idbc56790d10c94aa836abe0af3059a06521699b2
This commit is contained in:
parent
221a412dd2
commit
d44831ce9f
@ -48,7 +48,9 @@ def enable_option(file_name):
|
||||
line = str1[0] + '= false\n'
|
||||
file_data += line
|
||||
|
||||
with open(file_name, 'w') as gni_file:
|
||||
flags = os.O_WRONLY | os.O_CREAT
|
||||
modes = stat.S_IWUSR | stat.S_IRUSR
|
||||
with os.fdopen(os.open(file_name, flags, modes), 'w')as gni_file
|
||||
gni_file.write(file_data)
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DSOFTBUS_STATS(scene, extra) StatsEventInner(scene, __FUNCTION__, __LINE__, &extra)
|
||||
#define DSOFTBUS_STATS(scene, extra) StatsEventInner(scene, __FUNCTION__, __LINE__, &(extra))
|
||||
|
||||
/* For inner use only */
|
||||
void StatsEventInner(int32_t scene, const char *func, int32_t line, StatsEventExtra *extra);
|
||||
|
@ -22,10 +22,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TRANS_EVENT(scene, stage, extra) TransEventInner(scene, stage, __FUNCTION__, __LINE__, &extra)
|
||||
#define TRANS_ALARM(scene, type, extra) TransAlarmInner(scene, type, __FUNCTION__, __LINE__, &extra)
|
||||
#define TRANS_STATS(scene, extra) TransStatsInner(scene, __FUNCTION__, __LINE__, &extra)
|
||||
#define TRANS_AUDIT(scene, extra) TransAuditInner(scene, __FUNCTION__, __LINE__, &extra)
|
||||
#define TRANS_EVENT(scene, stage, extra) TransEventInner(scene, stage, __FUNCTION__, __LINE__, &(extra))
|
||||
#define TRANS_ALARM(scene, type, extra) TransAlarmInner(scene, type, __FUNCTION__, __LINE__, &(extra))
|
||||
#define TRANS_STATS(scene, extra) TransStatsInner(scene, __FUNCTION__, __LINE__, &(extra))
|
||||
#define TRANS_AUDIT(scene, extra) TransAuditInner(scene, __FUNCTION__, __LINE__, &(extra))
|
||||
|
||||
/* For inner use only */
|
||||
void TransEventInner(int32_t scene, int32_t stage, const char *func, int32_t line, TransEventExtra *extra);
|
||||
|
@ -671,7 +671,9 @@ int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &
|
||||
COMM_LOGE(COMM_SVC, "failed to read qos info");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_BUNDLENAME
|
||||
pid_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
|
||||
#endif
|
||||
if (param.sessionName == nullptr || param.peerSessionName == nullptr || param.peerDeviceId == nullptr ||
|
||||
param.groupId == nullptr) {
|
||||
retReply = SOFTBUS_INVALID_PARAM;
|
||||
@ -686,8 +688,6 @@ int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &
|
||||
goto EXIT;
|
||||
}
|
||||
#ifdef SUPPORT_BUNDLENAME
|
||||
pid_t callingUid;
|
||||
callingUid = OHOS::IPCSkeleton::GetCallingUid();
|
||||
if (CheckSessionName(param.sessionName, callingUid) != SOFTBUS_OK) {
|
||||
retReply = SOFTBUS_PERMISSION_DENIED;
|
||||
goto EXIT;
|
||||
|
@ -746,6 +746,7 @@ static void TransGetQosInfo(const SessionParam *param, QosInfo *qosInfo)
|
||||
break;
|
||||
case QOS_TYPE_RTT_LEVEL:
|
||||
qosInfo->rttLevel = (LaneRttLevel)((param->qos[i].value > 0) ? param->qos[i].value : 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -900,7 +900,7 @@ int32_t TransProxyPackAndSendData(
|
||||
}
|
||||
|
||||
uint32_t sliceNum = (dataInfo.outLen + (uint32_t)(SLICE_LEN - 1)) / (uint32_t)SLICE_LEN;
|
||||
for (int i = 0; i < sliceNum; i++) {
|
||||
for (uint32_t i = 0; i < sliceNum; i++) {
|
||||
uint32_t dataLen = (i == (sliceNum - 1U)) ? (dataInfo.outLen - i * SLICE_LEN) : SLICE_LEN;
|
||||
int32_t offset = (int32_t)(i * SLICE_LEN);
|
||||
|
||||
|
@ -67,6 +67,7 @@ void TransUdpNegoTest::SetUpTestCase(void)
|
||||
|
||||
void TransUdpNegoTest::TearDownTestCase(void)
|
||||
{
|
||||
AuthCommonDeinit();
|
||||
TransUdpChannelDeinit();
|
||||
LnnDeinitBusCenterEvent();
|
||||
}
|
||||
@ -394,6 +395,8 @@ HWTEST_F(TransUdpNegoTest, StartExchangeUdpInfo001, TestSize.Level1)
|
||||
EXPECT_EQ(ret, SOFTBUS_NOT_IMPLEMENT);
|
||||
|
||||
channel.info.udpChannelOptType = TYPE_UDP_CHANNEL_CLOSE;
|
||||
|
||||
(void)AuthCommonInit();
|
||||
ret = StartExchangeUdpInfo(&channel, authHandle, seq);
|
||||
EXPECT_EQ(ret, SOFTBUS_NOT_IMPLEMENT);
|
||||
}
|
||||
|
@ -120,6 +120,86 @@ static ISessionListener g_sessionlistener = {
|
||||
.OnMessageReceived = OnMessageReceived,
|
||||
};
|
||||
|
||||
static void TestGenerateCommParam(SessionParam *sessionParam)
|
||||
{
|
||||
sessionParam->sessionName = g_sessionName;
|
||||
sessionParam->peerSessionName = g_sessionName;
|
||||
sessionParam->peerDeviceId = g_deviceId;
|
||||
sessionParam->groupId = g_groupid;
|
||||
sessionParam->attr = &g_sessionAttr;
|
||||
}
|
||||
|
||||
static SessionInfo *TestGenerateSession(const SessionParam *param)
|
||||
{
|
||||
SessionInfo *session = (SessionInfo*)SoftBusCalloc(sizeof(SessionInfo));
|
||||
if (session == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcpy_s(session->info.peerSessionName, SESSION_NAME_SIZE_MAX, param->peerSessionName) != EOK ||
|
||||
strcpy_s(session->info.peerDeviceId, DEVICE_ID_SIZE_MAX, param->peerDeviceId) != EOK ||
|
||||
strcpy_s(session->info.groupId, GROUP_ID_SIZE_MAX, param->groupId) != EOK) {
|
||||
SoftBusFree(session);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
session->sessionId = TRANS_TEST_SESSION_ID;
|
||||
session->channelId = TRANS_TEST_CHANNEL_ID;
|
||||
session->channelType = CHANNEL_TYPE_BUTT;
|
||||
session->isServer = false;
|
||||
session->isEnable = false;
|
||||
session->routeType = ROUTE_TYPE_ALL;
|
||||
session->info.flag = TYPE_BYTES;
|
||||
session->isEncrypt = true;
|
||||
session->algorithm = TRANS_TEST_ALGORITHM;
|
||||
session->fileEncrypt = TRANS_TEST_FILE_ENCRYPT;
|
||||
session->crc = TRANS_TEST_CRC;
|
||||
session->sessionState = SESSION_STATE_INIT;
|
||||
return session;
|
||||
}
|
||||
|
||||
static int32_t AddSessionServerAndSession(const char *sessionName, int32_t channelType, bool isServer)
|
||||
{
|
||||
SessionParam *sessionParam = (SessionParam*)SoftBusCalloc(sizeof(SessionParam));
|
||||
if (sessionParam == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
TestGenerateCommParam(sessionParam);
|
||||
sessionParam->sessionName = sessionName;
|
||||
int32_t ret = ClientAddSessionServer(SEC_TYPE_PLAINTEXT, g_pkgName, sessionName, &g_sessionlistener);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
SessionInfo *session = TestGenerateSession(sessionParam);
|
||||
if (session == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
session->channelType = (ChannelType)channelType;
|
||||
session->isServer = isServer;
|
||||
ret = ClientAddNewSession(sessionName, session);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
int32_t sessionId = 0;
|
||||
ret = ClientGetSessionIdByChannelId(TRANS_TEST_CHANNEL_ID, channelType, &sessionId);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
SoftBusFree(sessionParam);
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
static void DeleteSessionServerAndSession(const char *sessionName, int32_t sessionId)
|
||||
{
|
||||
(void)ClientDeleteSession(sessionId);
|
||||
(void)ClientDeleteSessionServer(SEC_TYPE_PLAINTEXT, sessionName);
|
||||
}
|
||||
|
||||
static SessionInfo *GenerateSession(const SessionParam *param)
|
||||
{
|
||||
SessionInfo *session = (SessionInfo*)SoftBusMalloc(sizeof(SessionInfo));
|
||||
@ -256,4 +336,85 @@ HWTEST_F(TransClientSessionServiceTest, TransClientSessionServiceTest03, TestSiz
|
||||
SoftBusFree(sessionParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransClientSessionServiceTest04
|
||||
* @tc.desc: Transmission sdk session service get session option with different parameters.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(TransClientSessionServiceTest, TransClientSessionServiceTest04, TestSize.Level1)
|
||||
{
|
||||
uint32_t optionValue = 0;
|
||||
int ret = GetSessionOption(TRANS_TEST_SESSION_ID, SESSION_OPTION_BUTT,
|
||||
&optionValue, sizeof(optionValue));
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetSessionOption(TRANS_TEST_SESSION_ID, SESSION_OPTION_MAX_SENDBYTES_SIZE,
|
||||
NULL, sizeof(optionValue));
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetSessionOption(TRANS_TEST_SESSION_ID, SESSION_OPTION_MAX_SENDBYTES_SIZE,
|
||||
&optionValue, 0);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetSessionOption(TRANS_TEST_SESSION_ID, SESSION_OPTION_MAX_SENDBYTES_SIZE,
|
||||
&optionValue, sizeof(optionValue));
|
||||
EXPECT_EQ(ret, SOFTBUS_TRANS_SESSION_GET_CHANNEL_FAILED);
|
||||
int32_t sessionId = AddSessionServerAndSession(g_sessionName, CHANNEL_TYPE_TCP_DIRECT, false);
|
||||
ASSERT_GT(sessionId, 0);
|
||||
ret = GetSessionOption(sessionId, SESSION_OPTION_MAX_SENDBYTES_SIZE,
|
||||
&optionValue, sizeof(optionValue));
|
||||
EXPECT_EQ(ret, SOFTBUS_OK);
|
||||
DeleteSessionServerAndSession(g_sessionName, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransClientSessionServiceTest05
|
||||
* @tc.desc: Transmission sdk session service get peer device Id with different parameters.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(TransClientSessionServiceTest, TransClientSessionServiceTest05, TestSize.Level1)
|
||||
{
|
||||
char networkId[DEVICE_ID_SIZE_MAX] = {0};
|
||||
int ret = GetPeerDeviceId(TRANS_TEST_INVALID_SESSION_ID, networkId, DEVICE_ID_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerDeviceId(TRANS_TEST_SESSION_ID, NULL, DEVICE_ID_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerDeviceId(TRANS_TEST_SESSION_ID, networkId, SESSION_NAME_SIZE_MAX + 1);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerDeviceId(TRANS_TEST_SESSION_ID, networkId, DEVICE_ID_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND);
|
||||
int32_t sessionId = AddSessionServerAndSession(g_sessionName, CHANNEL_TYPE_BUTT, false);
|
||||
ASSERT_GT(sessionId, 0);
|
||||
ret = GetPeerDeviceId(sessionId, networkId, DEVICE_ID_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_OK);
|
||||
ret = strcmp(g_deviceId, networkId);
|
||||
EXPECT_EQ(ret, EOK);
|
||||
DeleteSessionServerAndSession(g_sessionName, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransClientSessionServiceTest06
|
||||
* @tc.desc: Transmission sdk session service get peer session name with different parameters.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(TransClientSessionServiceTest, TransClientSessionServiceTest06, TestSize.Level1)
|
||||
{
|
||||
char sessionName[SESSION_NAME_SIZE_MAX] = {0};
|
||||
int ret = GetPeerSessionName(TRANS_TEST_INVALID_SESSION_ID, sessionName, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerSessionName(TRANS_TEST_SESSION_ID, NULL, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerSessionName(TRANS_TEST_SESSION_ID, sessionName, SESSION_NAME_SIZE_MAX + 1);
|
||||
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
|
||||
ret = GetPeerSessionName(TRANS_TEST_SESSION_ID, sessionName, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_TRANS_SESSION_INFO_NOT_FOUND);
|
||||
int32_t sessionId = AddSessionServerAndSession(g_sessionName, CHANNEL_TYPE_BUTT, false);
|
||||
ASSERT_GT(sessionId, 0);
|
||||
ret = GetPeerSessionName(sessionId, sessionName, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(ret, SOFTBUS_OK);
|
||||
ret = strcmp(g_sessionName, sessionName);
|
||||
EXPECT_EQ(ret, EOK);
|
||||
DeleteSessionServerAndSession(g_sessionName, sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user