mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 16:59:54 +00:00
commit
916f8eaa1f
@ -248,43 +248,32 @@ ohos_unittest("TransTcpDirectMessageTest") {
|
||||
|
||||
ohos_unittest("TransTcpDirectMessageAppendTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/trans_tcp_direct_message_append_test.cpp" ]
|
||||
sources = [
|
||||
"unittest/mock/trans_tcp_direct_message_test_mock.cpp",
|
||||
"unittest/trans_tcp_direct_message_append_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$softbus_adapter_common/include",
|
||||
|
||||
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
||||
"$dsoftbus_root_path/core/adapter/transmission/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_builder/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/connection/wifi_direct",
|
||||
|
||||
"$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/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||
"$dsoftbus_root_path/core/frame/common/include",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/include",
|
||||
"$dsoftbus_root_path/interfaces/kits",
|
||||
"$dsoftbus_root_path/interfaces/kits/bus_center",
|
||||
"$dsoftbus_root_path/interfaces/kits/common",
|
||||
"$dsoftbus_root_path/interfaces/kits/transport",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/src",
|
||||
"$dsoftbus_root_path/tests/core/transmission/trans_channel/tcp_direct/unittest/mock",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/manager/include",
|
||||
"$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/bus_center/lnn/net_builder/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/include",
|
||||
"$dsoftbus_root_path/core/bus_center/interface",
|
||||
"$dsoftbus_root_path/core/bus_center/interface",
|
||||
"$dsoftbus_root_path/core/connection/wifi_direct",
|
||||
"$dsoftbus_root_path/core/discovery/manager/include",
|
||||
"$dsoftbus_root_path/core/discovery/interface",
|
||||
"$dsoftbus_root_path/core/adapter/transmission/include",
|
||||
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
||||
"$dsoftbus_root_path/core/authentication/interface",
|
||||
"$dsoftbus_root_path/core/common/security/permission/include",
|
||||
|
||||
"//base/security/device_auth/interfaces/inner_api",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
@ -292,16 +281,10 @@ ohos_unittest("TransTcpDirectMessageAppendTest") {
|
||||
"unittest/common/",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/include",
|
||||
"$dsoftbus_root_path/core/frame/common/include",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/include",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/src",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/common:softbus_utils",
|
||||
"$dsoftbus_root_path/core/frame:softbus_server",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
|
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "trans_tcp_direct_message_test_mock.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
void *g_transTcpDirectMessageInterface;
|
||||
TransTcpDirectMessageInterfaceMock::TransTcpDirectMessageInterfaceMock()
|
||||
{
|
||||
g_transTcpDirectMessageInterface = reinterpret_cast<void *>(this);
|
||||
}
|
||||
|
||||
TransTcpDirectMessageInterfaceMock::~TransTcpDirectMessageInterfaceMock()
|
||||
{
|
||||
g_transTcpDirectMessageInterface = nullptr;
|
||||
}
|
||||
|
||||
static TransTcpDirectMessageInterface *GetTransTcpDirectMessageInterface()
|
||||
{
|
||||
return reinterpret_cast<TransTcpDirectMessageInterface *>(g_transTcpDirectMessageInterface);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
SoftBusList *CreateSoftBusList()
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->CreateSoftBusList();
|
||||
}
|
||||
|
||||
int64_t GetAuthIdByChanId(int32_t channelId)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->GetAuthIdByChanId(channelId);
|
||||
}
|
||||
|
||||
int32_t AuthEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData,
|
||||
uint32_t *outLen)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->AuthEncrypt(authId, inData, inLen, outData, outLen);
|
||||
}
|
||||
|
||||
SessionConn *GetSessionConnById(int32_t channelId, SessionConn *conn)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->GetSessionConnById(channelId, conn);
|
||||
}
|
||||
|
||||
ssize_t ConnSendSocketData(int32_t fd, const char *buf, size_t len, int32_t timeout)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->ConnSendSocketData(fd, buf, len, timeout);
|
||||
}
|
||||
|
||||
ssize_t ConnRecvSocketData(int32_t fd, char *buf, size_t len, int32_t timeout)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->ConnRecvSocketData(fd, buf, len, timeout);
|
||||
}
|
||||
|
||||
int32_t TransTdcOnChannelOpenFailed(const char *pkgName, int32_t pid, int32_t channelId, int32_t errCode)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->TransTdcOnChannelOpenFailed(pkgName, pid, channelId, errCode);
|
||||
}
|
||||
|
||||
int32_t TransTdcGetPkgName(const char *sessionName, char *pkgName, uint16_t len)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->TransTdcGetPkgName(sessionName, pkgName, len);
|
||||
}
|
||||
|
||||
int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->LnnGetLocalStrInfo(key, info, len);
|
||||
}
|
||||
|
||||
int32_t GetLocalIpByRemoteIp(const char *remoteIp, char *localIp, int32_t localIpSize)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->GetLocalIpByRemoteIp(remoteIp, localIp, localIpSize);
|
||||
}
|
||||
|
||||
char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->TransTdcPackFastData(appInfo, outLen);
|
||||
}
|
||||
|
||||
int32_t UnpackReplyErrCode(const cJSON *msg, int32_t *errCode)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->UnpackReplyErrCode(msg, errCode);
|
||||
}
|
||||
|
||||
int UnpackReply(const cJSON *msg, AppInfo *appInfo, uint16_t *fastDataSize)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->UnpackReply(msg, appInfo, fastDataSize);
|
||||
}
|
||||
|
||||
int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->SoftbusGetConfig(type, val, len);
|
||||
}
|
||||
|
||||
int32_t SetAppInfoById(int32_t channelId, const AppInfo *appInfo)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->SetAppInfoById(channelId, appInfo);
|
||||
}
|
||||
|
||||
char *PackError(int errCode, const char *errDesc)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->PackError(errCode, errDesc);
|
||||
}
|
||||
|
||||
int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->AuthGetDeviceUuid(authId, uuid, size);
|
||||
}
|
||||
|
||||
int32_t UnpackRequest(const cJSON *msg, AppInfo *appInfo)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->UnpackRequest(msg, appInfo);
|
||||
}
|
||||
|
||||
int32_t GetAppInfoById(int32_t channelId, AppInfo *appInfo)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->GetAppInfoById(channelId, appInfo);
|
||||
}
|
||||
|
||||
int32_t GetRemoteUuidByIp(const char *remoteIp, char *localIp, int32_t localIpSize)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->GetRemoteUuidByIp(remoteIp, localIp, localIpSize);
|
||||
}
|
||||
|
||||
int32_t SetAuthIdByChanId(int32_t channelId, int64_t authId)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->SetAuthIdByChanId(channelId, authId);
|
||||
}
|
||||
|
||||
int32_t AuthDecrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData, uint32_t *outLen)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->AuthDecrypt(authId, inData, inLen, outData, outLen);
|
||||
}
|
||||
|
||||
cJSON* cJSON_Parse(const char *value)
|
||||
{
|
||||
return GetTransTcpDirectMessageInterface()->cJSON_Parse(value);
|
||||
}
|
||||
|
||||
static struct WifiDirectManager g_manager = {
|
||||
.getLocalIpByRemoteIp = GetLocalIpByRemoteIp,
|
||||
.getRemoteUuidByIp = GetRemoteUuidByIp,
|
||||
};
|
||||
|
||||
struct WifiDirectManager* GetWifiDirectManager(void)
|
||||
{
|
||||
return &g_manager;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#ifndef TRANS_TCP_DIRECT_MESSAGE_TEST_MOCK_H
|
||||
#define TRANS_TCP_DIRECT_MESSAGE_TEST_MOCK_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "auth_interface.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "softbus_feature_config.h"
|
||||
#include "softbus_message_open_channel.h"
|
||||
#include "softbus_socket.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "trans_tcp_direct_callback.h"
|
||||
#include "trans_tcp_direct_sessionconn.h"
|
||||
#include "wifi_direct_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
class TransTcpDirectMessageInterface {
|
||||
public:
|
||||
TransTcpDirectMessageInterface() {};
|
||||
virtual ~TransTcpDirectMessageInterface() {};
|
||||
virtual SoftBusList *CreateSoftBusList() = 0;
|
||||
virtual int64_t GetAuthIdByChanId(int32_t channelId) = 0;
|
||||
virtual int32_t AuthEncrypt(int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData,
|
||||
uint32_t *outLen) = 0;
|
||||
virtual SessionConn *GetSessionConnById(int32_t channelId, SessionConn *conn) = 0;
|
||||
virtual ssize_t ConnSendSocketData(int32_t fd, const char *buf, size_t len, int32_t timeout) = 0;
|
||||
virtual ssize_t ConnRecvSocketData(int32_t fd, char *buf, size_t len, int32_t timeout) = 0;
|
||||
virtual int32_t TransTdcOnChannelOpenFailed(const char *pkgName,
|
||||
int32_t pid, int32_t channelId, int32_t errCode) = 0;
|
||||
virtual int32_t TransTdcGetPkgName(const char *sessionName, char *pkgName, uint16_t len) = 0;
|
||||
virtual int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len) = 0;
|
||||
virtual int32_t GetLocalIpByRemoteIp(const char *remoteIp, char *localIp, int32_t localIpSize) = 0;
|
||||
virtual char *TransTdcPackFastData(const AppInfo *appInfo, uint32_t *outLen) = 0;
|
||||
virtual int32_t UnpackReplyErrCode(const cJSON *msg, int32_t *errCode) = 0;
|
||||
virtual int UnpackReply(const cJSON *msg, AppInfo *appInfo, uint16_t *fastDataSize) = 0;
|
||||
virtual int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len) = 0;
|
||||
virtual int32_t SetAppInfoById(int32_t channelId, const AppInfo *appInfo) = 0;
|
||||
virtual char *PackError(int errCode, const char *errDesc) = 0;
|
||||
virtual int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size) = 0;
|
||||
virtual int32_t UnpackRequest(const cJSON *msg, AppInfo *appInfo) = 0;
|
||||
virtual int32_t GetAppInfoById(int32_t channelId, AppInfo *appInfo) = 0;
|
||||
virtual int32_t GetRemoteUuidByIp(const char *remoteIp, char *localIp, int32_t localIpSize) = 0;
|
||||
virtual cJSON* cJSON_Parse(const char *value) = 0;
|
||||
virtual int32_t SetAuthIdByChanId(int32_t channelId, int64_t authId) = 0;
|
||||
virtual int32_t AuthDecrypt(int64_t authId, const uint8_t *inData,
|
||||
uint32_t inLen, uint8_t *outData, uint32_t *outLen) = 0;
|
||||
};
|
||||
|
||||
class TransTcpDirectMessageInterfaceMock : public TransTcpDirectMessageInterface {
|
||||
public:
|
||||
TransTcpDirectMessageInterfaceMock();
|
||||
~TransTcpDirectMessageInterfaceMock() override;
|
||||
MOCK_METHOD0(CreateSoftBusList, SoftBusList * ());
|
||||
MOCK_METHOD1(GetAuthIdByChanId, int64_t (int32_t channelId));
|
||||
MOCK_METHOD5(AuthEncrypt, int32_t (int64_t authId, const uint8_t *inData, uint32_t inLen, uint8_t *outData,
|
||||
uint32_t *outLen));
|
||||
MOCK_METHOD2(GetSessionConnById, SessionConn * (int32_t channelId, SessionConn *conn));
|
||||
MOCK_METHOD4(ConnSendSocketData, ssize_t (int32_t fd, const char *buf, size_t len, int32_t timeout));
|
||||
MOCK_METHOD4(ConnRecvSocketData, ssize_t (int32_t fd, char *buf, size_t len, int32_t timeout));
|
||||
MOCK_METHOD4(TransTdcOnChannelOpenFailed, int32_t (const char *pkgName,
|
||||
int32_t pid, int32_t channelId, int32_t errCode));
|
||||
MOCK_METHOD3(TransTdcGetPkgName, int32_t (const char *sessionName, char *pkgName, uint16_t len));
|
||||
MOCK_METHOD3(LnnGetLocalStrInfo, int32_t (InfoKey key, char *info, uint32_t len));
|
||||
MOCK_METHOD3(GetLocalIpByRemoteIp, int32_t (const char *remoteIp, char *localIp, int32_t localIpSize));
|
||||
MOCK_METHOD2(TransTdcPackFastData, char * (const AppInfo *appInfo, uint32_t *outLen));
|
||||
MOCK_METHOD2(UnpackReplyErrCode, int32_t (const cJSON *msg, int32_t *errCode));
|
||||
MOCK_METHOD3(UnpackReply, int (const cJSON *msg, AppInfo *appInfo, uint16_t *fastDataSize));
|
||||
MOCK_METHOD3(SoftbusGetConfig, int (ConfigType type, unsigned char *val, uint32_t len));
|
||||
MOCK_METHOD2(SetAppInfoById, int32_t (int32_t channelId, const AppInfo *appInfo));
|
||||
MOCK_METHOD2(PackError, char * (int errCode, const char *errDesc));
|
||||
MOCK_METHOD3(AuthGetDeviceUuid, int32_t (int64_t authId, char *uuid, uint16_t size));
|
||||
MOCK_METHOD2(UnpackRequest, int32_t (const cJSON *msg, AppInfo *appInfo));
|
||||
MOCK_METHOD2(GetAppInfoById, int32_t (int32_t channelId, AppInfo *appInfo));
|
||||
MOCK_METHOD3(GetRemoteUuidByIp, int32_t (const char *remoteIp, char *localIp, int32_t localIpSize));
|
||||
MOCK_METHOD1(cJSON_Parse, cJSON * (const char *value));
|
||||
MOCK_METHOD2(SetAuthIdByChanId, int32_t (int32_t channelId, int64_t authId));
|
||||
MOCK_METHOD5(AuthDecrypt, int32_t (int64_t authId, const uint8_t *inData,
|
||||
uint32_t inLen, uint8_t *outData, uint32_t *outLen));
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // TRANS_TCP_DIRECT_MESSAGE_TEST_MOCK_H
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user