mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-25 22:07:31 +00:00
commit
d101d9c491
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "auth_interface.h"
|
||||
@ -22,14 +22,22 @@
|
||||
#include "softbus_json_utils.h"
|
||||
#include "softbus_log.h"
|
||||
#include "softbus_protocol_def.h"
|
||||
#include "trans_channel_manager.h"
|
||||
#include "trans_udp_channel_manager.c"
|
||||
#include "trans_udp_negotiation.c"
|
||||
#include "trans_udp_negotiation_exchange.c"
|
||||
#include "trans_udp_channel_manager.h"
|
||||
#include "trans_udp_negotiation.h"
|
||||
#include "trans_udp_negotiation_exchange.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
#define INVALID_ID (-1)
|
||||
#define INVALID_SEQ (-1)
|
||||
#define INVALID_AUTH_ID (-2)
|
||||
|
||||
class TransUdpNegoTest : public testing::Test {
|
||||
public:
|
||||
TransUdpNegoTest()
|
||||
@ -50,6 +58,25 @@ void TransUdpNegoTest::SetUpTestCase(void)
|
||||
void TransUdpNegoTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
char* TestGetMsgInfo(void)
|
||||
{
|
||||
AppInfo info;
|
||||
info.udpChannelOptType = TYPE_UDP_CHANNEL_CLOSE;
|
||||
cJSON *requestMsg = cJSON_CreateObject();
|
||||
if (requestMsg == NULL) {
|
||||
cJSON_Delete(requestMsg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (TransPackRequestUdpInfo(requestMsg, &info) != SOFTBUS_OK) {
|
||||
cJSON_Delete(requestMsg);
|
||||
return NULL;
|
||||
}
|
||||
char *msgStr = cJSON_PrintUnformatted(requestMsg);
|
||||
cJSON_Delete(requestMsg);
|
||||
return msgStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TransUdpNegoTest001
|
||||
* @tc.desc: extern module active publish, stop session whitout start.
|
||||
@ -58,14 +85,14 @@ void TransUdpNegoTest::TearDownTestCase(void)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest001, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
int32_t errCode = 0;
|
||||
string msgStr = "ProcessMessage";
|
||||
ret = TransUnpackReplyErrInfo(NULL, NULL);
|
||||
int32_t ret = TransUnpackReplyErrInfo(NULL, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
cJSON *msg = cJSON_Parse((char *)msgStr.c_str());
|
||||
ret = TransUnpackReplyErrInfo(msg, &errCode);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
cJSON_Delete(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,10 +103,17 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest001, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest002, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
int32_t errCode = 0;
|
||||
ret = TransPackReplyErrInfo(NULL, errCode, NULL);
|
||||
string msgStr = "ProcessMessage";
|
||||
cJSON *msg = cJSON_Parse((char *)msgStr.c_str());
|
||||
const char* errDesc = "errDesc";
|
||||
|
||||
int32_t ret = TransPackReplyErrInfo(NULL, errCode, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
ret = TransPackReplyErrInfo(msg, errCode, errDesc);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
cJSON_Delete(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,17 +124,17 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest002, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest003, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
int64_t authId = 0;
|
||||
int64_t authId = AUTH_INVALID_ID;
|
||||
int64_t seq = 0;
|
||||
string msg = "ProcessMessage";
|
||||
cJSON *replyMsg = cJSON_Parse((char *)msg.c_str());
|
||||
|
||||
ret = sendUdpInfo(NULL, authId, seq);
|
||||
int32_t ret = sendUdpInfo(NULL, authId, seq);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
ret = sendUdpInfo(replyMsg, NULL, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
cJSON_Delete(replyMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,10 +145,9 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest003, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest004, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
int errCode = 0;
|
||||
int32_t errCode = 0;
|
||||
string errDesc = "ProcessMessage";
|
||||
ret = SendReplyErrInfo(errCode, NULL, NULL, NULL);
|
||||
int32_t ret = SendReplyErrInfo(errCode, NULL, NULL, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
ret = SendReplyErrInfo(errCode, (char *)errDesc.c_str(), NULL, NULL);
|
||||
@ -129,11 +162,17 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest004, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest005, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
int64_t authId = INVALID_ID;
|
||||
int64_t seq = INVALID_SEQ;
|
||||
AppInfo appInfo;
|
||||
(void)memset_s(&appInfo, sizeof(AppInfo), 0, sizeof(AppInfo));
|
||||
|
||||
appInfo.udpChannelOptType = TYPE_UDP_CHANNEL_CLOSE;
|
||||
ret = SendReplyUdpInfo(&appInfo, NULL, NULL);
|
||||
|
||||
int32_t ret = SendReplyUdpInfo(NULL, authId, seq);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
ret = SendReplyUdpInfo(&appInfo, NULL, seq);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
}
|
||||
|
||||
@ -145,15 +184,28 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest005, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest006, TestSize.Level1)
|
||||
{
|
||||
int errCode = 0;
|
||||
bool needClose = true;
|
||||
AppInfo info;
|
||||
(void)memset_s(&info, sizeof(AppInfo), 0, sizeof(AppInfo));
|
||||
info.udpChannelOptType = TYPE_UDP_CHANNEL_OPEN;
|
||||
ProcessAbnormalUdpChannelState(&info, errCode, needClose);
|
||||
(void)TransChannelInit();
|
||||
char* data = TestGetMsgInfo();
|
||||
cJSON *msg = cJSON_Parse(data);
|
||||
|
||||
info.udpChannelOptType = TYPE_UDP_CHANNEL_CLOSE;
|
||||
ProcessAbnormalUdpChannelState(&info, errCode, needClose);
|
||||
UdpChannelInfo *newChannel = (UdpChannelInfo*)SoftBusCalloc(sizeof(UdpChannelInfo));
|
||||
if (newChannel == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)memset_s(newChannel, sizeof(UdpChannelInfo), 0, sizeof(UdpChannelInfo));
|
||||
newChannel->seq = 1;
|
||||
int64_t authId = AUTH_INVALID_ID;
|
||||
|
||||
int32_t ret = TransAddUdpChannel(newChannel);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
TransOnExchangeUdpInfoReply(authId, INVALID_SEQ, msg);
|
||||
TransOnExchangeUdpInfoReply(INVALID_AUTH_ID, newChannel->seq, msg);
|
||||
TransOnExchangeUdpInfoReply(authId, newChannel->seq, msg);
|
||||
cJSON_Delete(msg);
|
||||
SoftBusFree(newChannel);
|
||||
TransChannelDeinit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,10 +216,26 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest006, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest007, TestSize.Level1)
|
||||
{
|
||||
int64_t seq = 0;
|
||||
string msgStr = "ProcessMessage";
|
||||
cJSON *msg = cJSON_Parse((char *)msgStr.c_str());
|
||||
TransOnExchangeUdpInfoReply(NULL, seq, msg);
|
||||
(void)TransChannelInit();
|
||||
char* data = TestGetMsgInfo();
|
||||
cJSON *msg = cJSON_Parse(data);
|
||||
|
||||
UdpChannelInfo *newChannel = (UdpChannelInfo*)SoftBusCalloc(sizeof(UdpChannelInfo));
|
||||
if (newChannel == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)memset_s(newChannel, sizeof(UdpChannelInfo), 0, sizeof(UdpChannelInfo));
|
||||
newChannel->seq = 1;
|
||||
int64_t authId = AUTH_INVALID_ID;
|
||||
|
||||
int32_t ret = TransAddUdpChannel(newChannel);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
TransOnExchangeUdpInfoRequest(authId, newChannel->seq, NULL);
|
||||
|
||||
cJSON_Delete(msg);
|
||||
SoftBusFree(newChannel);
|
||||
TransChannelDeinit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,7 +247,15 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest007, TestSize.Level1)
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest008, TestSize.Level1)
|
||||
{
|
||||
int64_t seq = 0;
|
||||
TransOnExchangeUdpInfoRequest(NULL, seq, NULL);
|
||||
UdpChannelInfo channel;
|
||||
(void)memset_s(&channel, sizeof(UdpChannelInfo), 0, sizeof(UdpChannelInfo));
|
||||
channel.info.udpChannelOptType = TYPE_UDP_CHANNEL_OPEN;
|
||||
int32_t ret = StartExchangeUdpInfo(&channel, NULL, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
channel.info.udpChannelOptType = TYPE_UDP_CHANNEL_CLOSE;
|
||||
ret = StartExchangeUdpInfo(&channel, NULL, seq);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,12 +266,22 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest008, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest009, TestSize.Level1)
|
||||
{
|
||||
int32_t ret;
|
||||
UdpChannelInfo channel;
|
||||
(void)memset_s(&channel, sizeof(UdpChannelInfo), 0, sizeof(UdpChannelInfo));
|
||||
channel.info.udpChannelOptType = TYPE_UDP_CHANNEL_OPEN;
|
||||
ret = StartExchangeUdpInfo(&channel, NULL, NULL);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
int64_t authId = AUTH_INVALID_ID;
|
||||
AuthTransData data;
|
||||
int32_t ret = memset_s(&data, sizeof(AuthTransData), 0, sizeof(AuthTransData));
|
||||
EXPECT_TRUE(ret == SOFTBUS_OK);
|
||||
|
||||
UdpModuleCb(authId, NULL);
|
||||
|
||||
data.data = NULL;
|
||||
UdpModuleCb(authId, &data);
|
||||
|
||||
data.data = (const uint8_t *)"data";
|
||||
data.len = 0;
|
||||
UdpModuleCb(authId, &data);
|
||||
|
||||
data.flag = 0;
|
||||
UdpModuleCb(authId, &data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,12 +292,10 @@ HWTEST_F(TransUdpNegoTest, TransUdpNegoTest009, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(TransUdpNegoTest, TransUdpNegoTest010, TestSize.Level1)
|
||||
{
|
||||
int64_t authId = 0;
|
||||
AuthTransData *data;
|
||||
(void)memset_s(&data, sizeof(AuthTransData), 0, sizeof(AuthTransData));
|
||||
UdpModuleCb(authId, NULL);
|
||||
IServerChannelCallBack *cb = TransServerGetChannelCb();
|
||||
int32_t ret = TransUdpChannelInit(cb);
|
||||
EXPECT_TRUE(ret != SOFTBUS_OK);
|
||||
|
||||
data->flag = SOFTBUS_OK;
|
||||
UdpModuleCb(authId, data);
|
||||
TransUdpChannelDeinit();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user