增加传输测试用例

Signed-off-by: samuel.shi <shixintao1@huawei.com>
This commit is contained in:
samuel.shi 2022-11-26 14:24:13 +08:00 committed by shixintao
parent 58270b5dfd
commit a449419242
8 changed files with 1249 additions and 36 deletions

View File

@ -20,6 +20,10 @@
#include "softbus_app_info.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t NotifyNetworkingChannelOpened(int32_t channelId, const AppInfo *appInfo, unsigned char isServer);
void NotifyNetworkingChannelOpenFailed(int32_t channelId, const char *networkId);
@ -28,5 +32,8 @@ void NotifyNetworkingChannelClosed(int32_t channelId);
void NotifyNetworkingMsgReceived(int32_t channelId, const char *data, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -15,11 +15,16 @@
#ifndef SOFTBUS_PROXYCHANNEL_TRANSCEIVER_H
#define SOFTBUS_PROXYCHANNEL_TRANSCEIVER_H
#include "common_list.h"
#include "softbus_app_info.h"
#include "softbus_conn_interface.h"
#include "softbus_proxychannel_message.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
ListNode node;
uint32_t requestId;
@ -45,4 +50,8 @@ int32_t TransDecConnRefByConnId(uint32_t connId);
int32_t TransAddConnRefByConnId(uint32_t connId);
int32_t TransProxyGetConnInfoByConnId(uint32_t connId, ConnectOption *connInfo);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -20,6 +20,7 @@ dsoftbus_root_path = "//foundation/communication/dsoftbus"
dsoftbus_sdk_path = "//foundation/communication/dsoftbus/sdk"
dsoftbus_core_path = "//foundation/communication/dsoftbus/core"
ability_base_path = "//foundation/ability/ability_base"
dsoftbus_test_path = "//foundation/communication/dsoftbus/tests"
declare_args() {
softbus_adapter_common = "//foundation/communication/dsoftbus/adapter/common"

View File

@ -13,6 +13,8 @@
import("//build/test.gni")
import("//foundation/communication/dsoftbus/dsoftbus.gni")
import(
"//foundation/communication/dsoftbus/tests/core/transmission/common/mock/mock.gni")
module_output_path = "dsoftbus/transmission"
@ -22,14 +24,29 @@ ohos_unittest("TransProxyChannelCoreTest") {
include_dirs = [
"$softbus_adapter_common/include",
"$dsoftbus_root_path/core/adapter/bus_center/include",
"$dsoftbus_root_path/core/authentication/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/sync_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/message_handler/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/coap/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/transmission/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/include",
@ -40,39 +57,19 @@ ohos_unittest("TransProxyChannelCoreTest") {
"$dsoftbus_root_path/core/transmission/trans_channel/manager/include",
"$dsoftbus_root_path/core/transmission/pending_packet/include",
"//commonlibrary/c_utils/base/include",
"unittest/common/",
"$dsoftbus_root_path/core/authentication/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/sync_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/message_handler/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/coap/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/third_party/dfinder/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"//base/security/device_auth/interfaces/innerkits",
"//third_party/cJSON",
"$dsoftbus_root_path/core/adapter/bus_center/include",
"$dsoftbus_root_path/interfaces/kits/transport",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/transport",
"$dsoftbus_root_path/third_party/dfinder/include",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
"//base/security/device_auth/interfaces/innerkits",
"//commonlibrary/c_utils/base/include",
"//third_party/cJSON",
"unittest/common/",
]
deps = [
@ -94,7 +91,82 @@ ohos_unittest("TransProxyChannelCoreTest") {
}
}
ohos_unittest("TransProxyChannelCoreMockTest") {
module_out_path = module_output_path
sources = trans_comm_mock_src
sources += [
"trans_proxy_message_test.cpp",
"trans_proxy_network_test.cpp",
"trans_proxy_session_test.cpp",
"trans_proxy_transceiver_test.cpp",
]
include_dirs = trans_comm_mock_inc
include_dirs += [
"$softbus_adapter_common/include",
"$dsoftbus_root_path/core/adapter/bus_center/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/message_handler/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/p2p/interface",
"$dsoftbus_root_path/core/connection/p2p/common/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/transmission/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/common/include",
"$dsoftbus_root_path/core/transmission/trans_channel/proxy/include",
"$dsoftbus_root_path/core/transmission/interface",
"$dsoftbus_root_path/core/transmission/session/include",
"$dsoftbus_root_path/core/transmission/trans_channel/manager/include",
"$dsoftbus_root_path/core/transmission/pending_packet/include",
"$dsoftbus_root_path/interfaces/kits",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/transport",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
"//base/security/device_auth/interfaces/innerkits",
"//commonlibrary/c_utils/base/include",
"//third_party/cJSON",
"unittest/common/",
]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
} else {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
}
group("unittest") {
testonly = true
deps = [ ":TransProxyChannelCoreTest" ]
deps = [
":TransProxyChannelCoreMockTest",
":TransProxyChannelCoreTest",
]
}

View File

@ -0,0 +1,407 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "gtest/gtest.h"
#include "message_handler.h"
#include "softbus_adapter_mem.h"
#include "softbus_conn_manager.h"
#include "softbus_error_code.h"
#include "softbus_feature_config.h"
#include "softbus_json_utils.h"
#include "softbus_protocol_def.h"
#include "softbus_proxychannel_callback.h"
#include "softbus_proxychannel_manager.h"
#include "softbus_proxychannel_message.h"
#include "softbus_transmission_interface.h"
#include "trans_auth_mock.h"
#include "trans_common_mock.h"
#include "trans_conn_mock.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
class TransProxyMessageTest : public testing::Test {
public:
TransProxyMessageTest()
{}
~TransProxyMessageTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
void TransProxyMessageTest::SetUpTestCase(void)
{
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, GenerateRandomStr).WillRepeatedly(Return(SOFTBUS_OK));
SoftbusConfigInit();
ASSERT_EQ(SOFTBUS_OK, LooperInit());
ASSERT_EQ(SOFTBUS_OK, SoftBusTimerInit());
IServerChannelCallBack callBack;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnSetConnectCallback).WillRepeatedly(Return(SOFTBUS_OK));
ASSERT_EQ(SOFTBUS_OK, TransProxyManagerInit(&callBack));
}
void TransProxyMessageTest::TearDownTestCase(void)
{
TransProxyManagerDeinit();
}
void TestMessageAddProxyChannel(int32_t channelId, AppType appType, const char *identity, ProxyChannelStatus status)
{
TransCommInterfaceMock commMock;
TransAuthInterfaceMock authMock;
EXPECT_CALL(commMock, GenerateRandomStr)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(commMock, SoftBusGenerateRandomArray)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(authMock, AuthGetLatestIdByUuid)
.WillRepeatedly(Return(SOFTBUS_OK));
AppInfo appInfo;
ProxyChannelInfo *chan = (ProxyChannelInfo *)SoftBusCalloc(sizeof(ProxyChannelInfo));
ASSERT_TRUE(NULL != chan);
chan->authId = channelId;
chan->connId = channelId;
chan->myId = channelId;
chan->peerId = channelId;
chan->reqId = channelId;
chan->channelId = channelId;
chan->seq = channelId;
(void)strcpy_s(chan->identity, 33, identity);
chan->status = status;
appInfo.appType = appType;
int32_t ret = TransProxyCreateChanInfo(chan, chan->channelId, &appInfo);
ASSERT_TRUE(SOFTBUS_OK == ret);
}
int32_t TestGetUidAndPidSuccess(const char *sessionName, int32_t *uid, int32_t *pid)
{
(void)sessionName;
(void)uid;
(void)pid;
return SOFTBUS_OK;
}
int32_t TestGetUidAndPidFail(const char *sessionName, int32_t *uid, int32_t *pid)
{
(void)sessionName;
(void)uid;
(void)pid;
return SOFTBUS_ERR;
}
void TestCallbackSuccess(void)
{
IServerChannelCallBack cb;
cb.GetUidAndPidBySessionName = TestGetUidAndPidSuccess;
int32_t ret = TransProxySetCallBack(&cb);
ASSERT_EQ(SOFTBUS_OK, ret);
}
void TestCallbackFail(void)
{
IServerChannelCallBack cb;
cb.GetUidAndPidBySessionName = TestGetUidAndPidFail;
int32_t ret = TransProxySetCallBack(&cb);
ASSERT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyHandshakeErrMsgTest001
* @tc.desc: test pack or unpack handshake err message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyHandshakeErrMsgTest001, TestSize.Level1)
{
char* msg = TransProxyPackHandshakeErrMsg(SOFTBUS_ERR);
ASSERT_TRUE(NULL != msg);
int32_t ret = TransProxyUnPackHandshakeErrMsg(msg, NULL);
EXPECT_NE(SOFTBUS_OK, ret);
int32_t errCode = SOFTBUS_OK;
ret = TransProxyUnPackHandshakeErrMsg(msg, &errCode);
EXPECT_EQ(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyHandshakeAckMsgTest001
* @tc.desc: test pack or unpack handshake ack message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyHandshakeAckMsgTest001, TestSize.Level1)
{
int32_t ret = SOFTBUS_OK;
ProxyChannelInfo chan;
ProxyChannelInfo outChannel;
chan.appInfo.appType = APP_TYPE_NOT_CARE;
char *msg = TransProxyPackHandshakeAckMsg(&chan);
EXPECT_EQ(NULL, msg);
chan.appInfo.appType = APP_TYPE_NORMAL;
msg = TransProxyPackHandshakeAckMsg(&chan);
ASSERT_TRUE(NULL != msg);
cJSON_free(msg);
msg = NULL;
chan.appInfo.appType = APP_TYPE_AUTH;
chan.channelId = -1;
msg = TransProxyPackHandshakeAckMsg(&chan);
ASSERT_TRUE(NULL != msg);
ret = TransProxyUnpackHandshakeAckMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
chan.channelId = 44;
TestMessageAddProxyChannel(chan.channelId, APP_TYPE_AUTH, "44", PROXY_CHANNEL_STATUS_COMPLETED);
msg = TransProxyPackHandshakeAckMsg(&chan);
ASSERT_TRUE(NULL != msg);
outChannel.myId = chan.channelId;
printf("todo check why not ok?\n");
ret = TransProxyUnpackHandshakeAckMsg(msg, &outChannel);
//EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_NE(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyHandshakeMsgTest001
* @tc.desc: test pack or unpack handshake normal message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyHandshakeMsgTest001, TestSize.Level1)
{
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, SoftBusBase64Encode)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(commMock, SoftBusBase64Decode)
.WillOnce(Return(SOFTBUS_ERR))
.WillOnce(DoAll(SetArgPointee<2>(32), Return(SOFTBUS_ERR)))
.WillRepeatedly(DoAll(SetArgPointee<2>(32), Return(SOFTBUS_OK)));
int32_t ret = SOFTBUS_ERR;
ProxyChannelInfo info;
ProxyChannelInfo outChannel;
info.appInfo.appType = APP_TYPE_NORMAL;
char *msg = TransProxyPackHandshakeMsg(&info);
EXPECT_EQ(NULL, msg);
msg = TransProxyPackHandshakeMsg(&info);
ASSERT_TRUE(NULL != msg);
TestCallbackFail();
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
TestCallbackSuccess();
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_EQ(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyHandshakeMsgTest002
* @tc.desc: test pack or unpack handshake auth message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyHandshakeMsgTest002, TestSize.Level1)
{
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, GenerateRandomStr)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
ProxyChannelInfo info;
info.appInfo.appType = APP_TYPE_AUTH;
char *msg = TransProxyPackHandshakeMsg(&info);
EXPECT_EQ(NULL, msg);
msg = TransProxyPackHandshakeMsg(&info);
ASSERT_TRUE(NULL != msg);
ProxyChannelInfo outChannel;
TestCallbackFail();
int32_t ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
TestCallbackSuccess();
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_EQ(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyHandshakeMsgTest003
* @tc.desc: test pack or unpack handshake inner message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyHandshakeMsgTest003, TestSize.Level1)
{
int32_t len = 32;
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, SoftBusBase64Encode)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(commMock, SoftBusBase64Decode)
.WillOnce(Return(SOFTBUS_ERR))
.WillOnce(DoAll(SetArgPointee<2>(len), Return(SOFTBUS_ERR)))
.WillRepeatedly(DoAll(SetArgPointee<2>(len), Return(SOFTBUS_OK)));
ProxyChannelInfo info;
info.appInfo.appType = APP_TYPE_INNER;
char *msg = TransProxyPackHandshakeMsg(&info);
EXPECT_EQ(NULL, msg);
msg = TransProxyPackHandshakeMsg(&info);
ASSERT_TRUE(NULL != msg);
ProxyChannelInfo outChannel;
int32_t ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyUnpackHandshakeMsg(msg, &outChannel);
EXPECT_EQ(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyIdentityMsgTest001
* @tc.desc: test pack or unpack identity message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyIdentityMsgTest001, TestSize.Level1)
{
char identity[33] = "test identity";
char* msg = TransProxyPackIdentity(identity);
ASSERT_TRUE(NULL != msg);
int32_t ret = TransProxyUnpackIdentity(msg, identity, 33);
EXPECT_EQ(SOFTBUS_OK, ret);
cJSON_free(msg);
}
/**
* @tc.name: TransProxyPackMessageTest001
* @tc.desc: TransProxyPackMessageTest001, use the wrong parameter.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyPackMessageTest001, TestSize.Level1)
{
ProxyMessageHead msg;
int64_t authId = AUTH_INVALID_ID;
ProxyDataInfo dataInfo;
int32_t ret = TransProxyPackMessage(NULL, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPackMessage(&msg, authId, NULL);
EXPECT_NE(SOFTBUS_OK, ret);
dataInfo.inData = NULL;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
dataInfo.inData = 0;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
msg.cipher = 0;
msg.type = PROXYCHANNEL_MSG_TYPE_HANDSHAKE;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
dataInfo.inData = (uint8_t *)"1";
dataInfo.inLen = strlen((const char*)dataInfo.inData);
msg.cipher |= ENCRYPTED;
msg.type = PROXYCHANNEL_MSG_TYPE_NORMAL;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyPackMessageTest002
* @tc.desc: TransProxyPackMessageTest002, use normal param.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyMessageTest, TransProxyPackMessageTest002, TestSize.Level1)
{
ProxyMessageHead msg;
int64_t authId = AUTH_INVALID_ID;
ProxyDataInfo dataInfo;
int32_t ret = SOFTBUS_ERR;
TransAuthInterfaceMock authMock;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnGetHeadSize)
.WillRepeatedly(Return(sizeof(ConnPktHead)));
EXPECT_CALL(authMock, AuthGetEncryptSize)
.WillRepeatedly(Return(35));
EXPECT_CALL(authMock, AuthEncrypt)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
dataInfo.inData = (uint8_t *)"12345";
dataInfo.inLen = strlen((const char*)dataInfo.inData);
msg.cipher = 0;
msg.type = PROXYCHANNEL_MSG_TYPE_HANDSHAKE;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_EQ(SOFTBUS_OK, ret);
msg.cipher |= ENCRYPTED;
msg.type = PROXYCHANNEL_MSG_TYPE_NORMAL;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
authId = 1;
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPackMessage(&msg, authId, &dataInfo);
EXPECT_EQ(SOFTBUS_OK, ret);
}
} // namespace OHOS

View File

@ -0,0 +1,149 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "gtest/gtest.h"
#include "softbus_error_code.h"
#include "softbus_protocol_def.h"
#include "softbus_proxychannel_network.h"
#include "softbus_transmission_interface.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
class TransProxyNetworkTest : public testing::Test {
public:
TransProxyNetworkTest()
{}
~TransProxyNetworkTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
static int TestOnNetworkChannelOpened(int32_t channelId, const char *uuid, unsigned char isServer);
static void TestOnNetworkChannelOpenFailed(int32_t channelId, const char *uuid);
static void TestOnNetworkChannelClosed(int32_t channelId);
static void TestOnNetworkMessageReceived(int32_t channelId, const char *data, uint32_t len);
static void TestRegisterNetworkingChannelListener(void);
static bool m_channelOpenFailedFlag;
static bool m_channelClosedFlag;
static bool m_messageReceivedFlag;
};
bool TransProxyNetworkTest::m_channelClosedFlag = false;
bool TransProxyNetworkTest::m_channelOpenFailedFlag = false;
bool TransProxyNetworkTest::m_messageReceivedFlag = false;
void TransProxyNetworkTest::SetUpTestCase(void)
{
}
void TransProxyNetworkTest::TearDownTestCase(void)
{
}
int TransProxyNetworkTest::TestOnNetworkChannelOpened(int32_t channelId, const char *uuid, unsigned char isServer)
{
(void)channelId;
(void)uuid;
(void)isServer;
printf("test on networking channel opened.\n");
return SOFTBUS_OK;
}
void TransProxyNetworkTest::TestOnNetworkChannelOpenFailed(int32_t channelId, const char *uuid)
{
(void)channelId;
(void)uuid;
printf("test on network channel open failed.\n");
TransProxyNetworkTest::m_channelOpenFailedFlag = true;
}
void TransProxyNetworkTest::TestOnNetworkChannelClosed(int32_t channelId)
{
(void)channelId;
printf("test on networking channel closed.\n");
TransProxyNetworkTest::m_channelClosedFlag = true;
}
void TransProxyNetworkTest::TestOnNetworkMessageReceived(int32_t channelId, const char *data, uint32_t len)
{
(void)channelId;
(void)data;
(void)len;
printf("test on networking message received.\n");
TransProxyNetworkTest::m_messageReceivedFlag = true;
}
void TransProxyNetworkTest::TestRegisterNetworkingChannelListener(void)
{
INetworkingListener listener;
listener.onChannelClosed = TransProxyNetworkTest::TestOnNetworkChannelClosed;
listener.onChannelOpened = TransProxyNetworkTest::TestOnNetworkChannelOpened;
listener.onChannelOpenFailed = TransProxyNetworkTest::TestOnNetworkChannelOpenFailed;
listener.onMessageReceived = TransProxyNetworkTest::TestOnNetworkMessageReceived;
int32_t ret = TransRegisterNetworkingChannelListener(&listener);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransNoRegisterListenerTest001
* @tc.desc: test callback after no register networking channel listener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyNetworkTest, TransNoRegisterListenerTest001, TestSize.Level1)
{
int32_t ret = NotifyNetworkingChannelOpened(1, NULL, 0);
EXPECT_NE(SOFTBUS_OK, ret);
NotifyNetworkingChannelOpenFailed(1, NULL);
EXPECT_NE(true, TransProxyNetworkTest::m_channelOpenFailedFlag);
NotifyNetworkingChannelClosed(1);
EXPECT_NE(true, TransProxyNetworkTest::m_channelClosedFlag);
NotifyNetworkingMsgReceived(1, NULL, 0);
EXPECT_NE(true, TransProxyNetworkTest::m_messageReceivedFlag);
}
/**
* @tc.name: TransRegisterListenerTest001
* @tc.desc: test callback after register networking channel listener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyNetworkTest, TransRegisterListenerTest001, TestSize.Level1)
{
TransProxyNetworkTest::TestRegisterNetworkingChannelListener();
int32_t ret = NotifyNetworkingChannelOpened(1, NULL, 0);
EXPECT_EQ(SOFTBUS_OK, ret);
NotifyNetworkingChannelOpenFailed(1, NULL);
EXPECT_EQ(true, TransProxyNetworkTest::m_channelOpenFailedFlag);
NotifyNetworkingChannelClosed(1);
EXPECT_EQ(true, TransProxyNetworkTest::m_channelClosedFlag);
NotifyNetworkingMsgReceived(1, NULL, 0);
EXPECT_EQ(true, TransProxyNetworkTest::m_messageReceivedFlag);
}
} // namespace OHOS

View File

@ -0,0 +1,283 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "gtest/gtest.h"
#include "message_handler.h"
#include "session.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_error_code.h"
#include "softbus_feature_config.h"
#include "softbus_json_utils.h"
#include "softbus_log.h"
#include "softbus_protocol_def.h"
#include "softbus_proxychannel_session.h"
#include "softbus_proxychannel_manager.h"
#include "softbus_utils.h"
#include "trans_auth_mock.h"
#include "trans_conn_mock.h"
#include "trans_common_mock.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
typedef struct {
int32_t priority;
int32_t sliceNum;
int32_t sliceSeq;
int32_t reserved;
} TestSliceHead;
class TransProxySessionTest : public testing::Test {
public:
TransProxySessionTest()
{}
~TransProxySessionTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
int32_t TestSessionDataReceived(const char *pkgName, int32_t pid, int32_t channelId, int32_t channelType,
TransReceiveData* receiveData)
{
(void)pkgName;
(void)pid;
(void)channelId;
(void)channelType;
(void)receiveData;
return SOFTBUS_OK;
}
void TransProxySessionTest::SetUpTestCase(void)
{
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, GenerateRandomStr).WillRepeatedly(Return(SOFTBUS_OK));
SoftbusConfigInit();
ASSERT_EQ(SOFTBUS_OK, LooperInit());
ASSERT_EQ(SOFTBUS_OK, SoftBusTimerInit());
IServerChannelCallBack callBack;
callBack.OnDataReceived = TestSessionDataReceived;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnSetConnectCallback).WillRepeatedly(Return(SOFTBUS_OK));
ASSERT_EQ(SOFTBUS_OK, TransProxyManagerInit(&callBack));
}
void TransProxySessionTest::TearDownTestCase(void)
{
TransProxyManagerDeinit();
}
void TestAddProxyChannel(int32_t channelId, AppType appType, ProxyChannelStatus status)
{
TransCommInterfaceMock commMock;
TransAuthInterfaceMock authMock;
EXPECT_CALL(commMock, GenerateRandomStr)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(commMock, SoftBusGenerateRandomArray)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(authMock, AuthGetLatestIdByUuid)
.WillRepeatedly(Return(SOFTBUS_OK));
AppInfo appInfo;
ProxyChannelInfo *chan = (ProxyChannelInfo *)SoftBusCalloc(sizeof(ProxyChannelInfo));
ASSERT_TRUE(NULL != chan);
chan->authId = channelId;
chan->connId = channelId;
chan->myId = channelId;
chan->peerId = channelId;
chan->reqId = channelId;
chan->channelId = channelId;
chan->seq = channelId;
(void)strcpy_s(chan->identity, 33, std::to_string(channelId).c_str());
chan->status = status;
appInfo.appType = appType;
int32_t ret = TransProxyCreateChanInfo(chan, chan->channelId, &appInfo);
ASSERT_TRUE(SOFTBUS_OK == ret);
}
/**
* @tc.name: TransProxyPostSessionDataTest001
* @tc.desc: test proxy post session data.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransProxyPostSessionDataTest001, TestSize.Level1)
{
int32_t channelId = -1;
int32_t ret = SOFTBUS_ERR;
for (uint32_t flags = TRANS_SESSION_BYTES; flags <= TRANS_SESSION_FILE_ACK_RESPONSE_SENT; ++flags) {
ret = TransProxyPostSessionData(channelId, NULL, 0, (SessionPktType)flags);
EXPECT_NE(SOFTBUS_OK, ret);
}
const char *data = "test data";
uint32_t len = strlen(data);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyPostSessionDataTest002
* @tc.desc: test proxy post session data.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransProxyPostSessionDataTest002, TestSize.Level1)
{
int32_t channelId = 50;
int32_t ret = SOFTBUS_ERR;
TestAddProxyChannel(channelId, APP_TYPE_AUTH, PROXY_CHANNEL_STATUS_COMPLETED);
const char *data = "test data";
uint32_t len = strlen(data);
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnGetHeadSize)
.WillRepeatedly(Return(24));
EXPECT_CALL(connMock, ConnPostBytes)
.WillOnce(Return(SOFTBUS_ERR))
.WillOnce(Return(SOFTBUS_CONNECTION_ERR_SENDQUEUE_FULL))
.WillRepeatedly(Return(SOFTBUS_OK));
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_BYTES);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyPostSessionDataTest003
* @tc.desc: test proxy post session data.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransProxyPostSessionDataTest003, TestSize.Level1)
{
int32_t ret = SOFTBUS_OK;
int32_t channelId = 51;
TestAddProxyChannel(channelId, APP_TYPE_NORMAL, PROXY_CHANNEL_STATUS_COMPLETED);
const char *data = "test data";
uint32_t len = strlen(data);
TransConnInterfaceMock connMock;
TransCommInterfaceMock commMock;
EXPECT_CALL(connMock, ConnGetHeadSize)
.WillRepeatedly(Return(24));
EXPECT_CALL(connMock, ConnPostBytes)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(commMock, SoftBusEncryptDataWithSeq)
.WillOnce(Return(SOFTBUS_ERR))
.WillOnce(DoAll(SetArgPointee<4>(0), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_MESSAGE);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyPostSessionData(channelId, (const unsigned char *)data, len, TRANS_SESSION_BYTES);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransOnNormalMsgReceivedTest001
* @tc.desc: test proxy on normal msg received.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransOnNormalMsgReceivedTest001, TestSize.Level1)
{
const char *pkgName = "com.test.trans.proxysession";
int32_t pid = 0;
int32_t channelId = -1;
char buf[100] = {0};
TestSliceHead head;
uint32_t len = 10;
int32_t ret = TransOnNormalMsgReceived(pkgName, pid, channelId, NULL, len);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransOnNormalMsgReceived(pkgName, pid, channelId, buf, len);
EXPECT_NE(SOFTBUS_OK, ret);
head.priority = -1;
len += 50;
(void)memcpy_s(buf, 100, &head, sizeof(TestSliceHead));
ret = TransOnNormalMsgReceived(pkgName, pid, channelId, buf, len);
EXPECT_NE(SOFTBUS_OK, ret);
head.priority = 3;
(void)memcpy_s(buf, 100, &head, sizeof(TestSliceHead));
ret = TransOnNormalMsgReceived(pkgName, pid, channelId, buf, len);
EXPECT_NE(SOFTBUS_OK, ret);
head.priority = 2;
head.sliceNum = 2;
head.sliceSeq = 2;
(void)memcpy_s(buf, 100, &head, sizeof(TestSliceHead));
ret = TransOnNormalMsgReceived(pkgName, pid, channelId, buf, len);
EXPECT_NE(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransOnAuthMsgReceivedTest001
* @tc.desc: test proxy on auth msg received.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransOnAuthMsgReceivedTest001, TestSize.Level1)
{
const char *pkgName = "com.test.trans.proxysession";
int32_t pid = 0;
int32_t channelId = -1;
const char * data = "test data";
int32_t ret = TransOnAuthMsgReceived(pkgName, pid, channelId, NULL, 0);
EXPECT_NE(SOFTBUS_OK, ret);
uint32_t len = 70 * 1024;
ret = TransOnAuthMsgReceived(pkgName, pid, channelId, data, len);
EXPECT_NE(SOFTBUS_OK, ret);
len = 20;
ret = TransOnAuthMsgReceived(pkgName, pid, channelId, data, len);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyDelSliceProcessorByChannelIdTest001
* @tc.desc: test del slice processor by channelId.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxySessionTest, TransProxyDelSliceProcessorByChannelIdTest001, TestSize.Level1)
{
int32_t channelId = -1;
int32_t ret = TransProxyDelSliceProcessorByChannelId(channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
}
} // namespace OHOS

View File

@ -0,0 +1,285 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "gtest/gtest.h"
#include "message_handler.h"
#include "session.h"
#include "softbus_conn_manager.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_json_utils.h"
#include "softbus_log.h"
#include "softbus_protocol_def.h"
#include "softbus_proxychannel_manager.h"
#include "softbus_proxychannel_transceiver.h"
#include "softbus_utils.h"
#include "trans_auth_mock.h"
#include "trans_common_mock.h"
#include "trans_conn_mock.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
class TransProxyTransceiverTest : public testing::Test {
public:
TransProxyTransceiverTest()
{}
~TransProxyTransceiverTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
void TransProxyTransceiverTest::SetUpTestCase(void)
{
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, GenerateRandomStr).WillRepeatedly(Return(SOFTBUS_OK));
SoftbusConfigInit();
ASSERT_EQ(SOFTBUS_OK, LooperInit());
ASSERT_EQ(SOFTBUS_OK, SoftBusTimerInit());
IServerChannelCallBack callBack;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnSetConnectCallback).WillRepeatedly(Return(SOFTBUS_OK));
ASSERT_EQ(SOFTBUS_OK, TransProxyManagerInit(&callBack));
}
void TransProxyTransceiverTest::TearDownTestCase(void)
{
TransProxyManagerDeinit();
}
/**
* @tc.name: TransProxyOpenConnChannelTest001
* @tc.desc: test proxy open new conn channel.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyOpenConnChannelTest001, TestSize.Level1)
{
AppInfo appInfo;
appInfo.appType = APP_TYPE_NORMAL;
ConnectOption connInfo;
int32_t channelId = -1;
TransAuthInterfaceMock authMock;
TransConnInterfaceMock connMock;
TransCommInterfaceMock commMock;
EXPECT_CALL(commMock, GenerateRandomStr)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(authMock, AuthGetLatestIdByUuid)
.WillOnce(Return(AUTH_INVALID_ID))
.WillRepeatedly(Return(1));
EXPECT_CALL(commMock, SoftBusGenerateRandomArray)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnConnectDevice)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnGetNewRequestId)
.WillOnce(Return(1))
.WillOnce(Return(2))
.WillOnce(Return(3))
.WillOnce(Return(4))
.WillOnce(Return(5))
.WillRepeatedly(Return(6));
int32_t ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
appInfo.appType = APP_TYPE_AUTH;
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyOpenConnChannelTest002
* @tc.desc: test proxy open exist channel.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyOpenConnChannelTest002, TestSize.Level1)
{
ConnectionInfo tcpInfo;
tcpInfo.type = CONNECT_TCP;
ConnectionInfo brInfo;
tcpInfo.type = CONNECT_BR;
ConnectionInfo bleInfo;
tcpInfo.type = CONNECT_BLE;
TransAuthInterfaceMock authMock;
TransCommInterfaceMock commMock;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnGetConnectionInfo(_, _))
.WillOnce(DoAll(SetArgPointee<1>(tcpInfo), Return(SOFTBUS_ERR)))
.WillOnce(DoAll(SetArgPointee<1>(tcpInfo), Return(SOFTBUS_OK)))
.WillOnce(DoAll(SetArgPointee<1>(brInfo), Return(SOFTBUS_OK)))
.WillOnce(DoAll(SetArgPointee<1>(bleInfo), Return(SOFTBUS_OK)));
TransCreateConnByConnId(1);
TransCreateConnByConnId(2);
TransCreateConnByConnId(3);
TransCreateConnByConnId(4);
EXPECT_CALL(connMock, ConnGetNewRequestId)
.WillOnce(Return(10))
.WillOnce(Return(11))
.WillRepeatedly(Return(12));
EXPECT_CALL(commMock, GenerateRandomStr)
.WillRepeatedly( Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnGetHeadSize)
.WillRepeatedly(Return(24));
EXPECT_CALL(connMock, ConnPostBytes)
.WillRepeatedly(Return(SOFTBUS_OK));
AppInfo appInfo;
int32_t channelId = -1;
int32_t ret = SOFTBUS_ERR;
ConnectOption connInfo;
appInfo.appType = APP_TYPE_AUTH;
connInfo.type = CONNECT_TCP;
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
connInfo.type = CONNECT_BR;
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
connInfo.type = CONNECT_BLE;
ret = TransProxyOpenConnChannel(&appInfo, &connInfo, &channelId);
EXPECT_EQ(SOFTBUS_OK, ret);
sleep(1);
}
/**
* @tc.name: TransProxyCloseConnChannelTest001
* @tc.desc: test proxy close conn channel.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyCloseConnChannelTest001, TestSize.Level1)
{
ConnectionInfo tcpInfo;
tcpInfo.type = CONNECT_TCP;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnGetConnectionInfo(_, _))
.WillOnce(DoAll(SetArgPointee<1>(tcpInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(connMock, ConnDisconnectDevice)
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(connMock, ConnPostBytes)
.WillRepeatedly(Return(SOFTBUS_OK));
TransCreateConnByConnId(1);
int32_t ret = TransProxyCloseConnChannel(1);
EXPECT_EQ(SOFTBUS_OK, ret);
ret = TransProxyCloseConnChannel(1);
EXPECT_EQ(SOFTBUS_OK, ret);
ret = TransProxyCloseConnChannel(1);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyCloseConnChannelResetTest001
* @tc.desc: test proxy dec connInfo ref count.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyCloseConnChannelResetTest001, TestSize.Level1)
{
ConnectionInfo tcpInfo;
tcpInfo.type = CONNECT_TCP;
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnGetConnectionInfo(_, _))
.WillOnce(DoAll(SetArgPointee<1>(tcpInfo), Return(SOFTBUS_OK)));
EXPECT_CALL(connMock, ConnDisconnectDevice)
.WillRepeatedly(Return(SOFTBUS_OK));
TransCreateConnByConnId(2);
int32_t ret = TransProxyCloseConnChannelReset(2, false);
EXPECT_EQ(SOFTBUS_OK, ret);
ret = TransProxyCloseConnChannelReset(2, false);
EXPECT_EQ(SOFTBUS_OK, ret);
ret = TransProxyCloseConnChannelReset(2, true);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyGetConnInfoByConnIdTest001
* @tc.desc: test proxy get conn info by conn id.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyGetConnInfoByConnIdTest001, TestSize.Level1)
{
ConnectOption connOptInfo;
int32_t ret = TransProxyGetConnInfoByConnId(3, NULL);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyGetConnInfoByConnId(100, &connOptInfo);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyGetConnInfoByConnId(3, &connOptInfo);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: TransProxyTransSendMsgTest001
* @tc.desc: test proxy send message.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransProxyTransceiverTest, TransProxyTransSendMsgTest001, TestSize.Level1)
{
TransConnInterfaceMock connMock;
EXPECT_CALL(connMock, ConnPostBytes)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
uint32_t connectionId = 1;
uint8_t *buf = NULL;
uint32_t len = 1;
int32_t priority = 0;
int32_t pid = 0;
int32_t ret = TransProxyTransSendMsg(connectionId, buf, len, priority, pid);
EXPECT_NE(SOFTBUS_OK, ret);
ret = TransProxyTransSendMsg(connectionId, buf, len, priority, pid);
EXPECT_EQ(SOFTBUS_OK, ret);
}
} // namespace OHOS