Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master

This commit is contained in:
chenbotong 2022-10-26 01:55:19 +00:00 committed by Gitee
commit 855ba50397
42 changed files with 2211 additions and 224 deletions

View File

@ -19,8 +19,7 @@ adapter_wifi_src = []
adapter_wifi_inc = [ "$softbus_adapter_wifi_path/include" ]
adapter_wifi_deps = []
if (defined(ohos_lite) || (defined(global_parts_info) &&
!defined(global_parts_info.communication_wifi))) {
if (defined(ohos_lite) || softbus_communication_wifi_feature == false) {
if (dsoftbus_feature_lnn_net) {
adapter_wifi_src += [
"$softbus_adapter_wifi_path/common/softbus_wifi_api_adapter_virtual.c",

View File

@ -102,6 +102,8 @@
"//foundation/communication/dsoftbus/tests/core/connection:fuzztest",
"//foundation/communication/dsoftbus/tests/core/discovery/manager:unittest",
"//foundation/communication/dsoftbus/tests/core/discovery/ble/dispatcher:unittest",
"//foundation/communication/dsoftbus/tests/core/discovery/ble/softbus_ble:unittest",
"//foundation/communication/dsoftbus/tests/core/discovery/coap/unittest:unittest",
"//foundation/communication/dsoftbus/tests/core/transmission/trans_channel/tcp_direct:unittest",
"//foundation/communication/dsoftbus/tests/core/transmission/trans_channel/auth_channel:unittest",
"//foundation/communication/dsoftbus/tests/core/transmission/trans_channel/proxy_channel:unittest",

View File

@ -51,7 +51,7 @@ typedef struct {
void SoftBusDumpShowHelp(int fd);
void SoftBusDumpErrInfo(int fd, const char *argv);
void SoftBusDumpSubModuleHelp(int fd, char *moduleName, ListNode *varList);
int32_t SoftBusAddDumpVarToList(char *dumpVar, SoftBusVarDumpCb cb, ListNode *subModoleVarList);
int32_t SoftBusAddDumpVarToList(const char *dumpVar, SoftBusVarDumpCb cb, ListNode *subModoleVarList);
void SoftBusReleaseDumpVar(ListNode *varList);
int32_t SoftBusRegHiDumperHandler(char *moduleName, char *helpInfo, DumpHandlerFunc handler);
int32_t SoftBusDumpDispatch(int fd, int32_t argc, const char **argv);

View File

@ -24,7 +24,7 @@ extern "C" {
#endif
int32_t SoftBusConnHiDumperInit(void);
int32_t SoftBusRegConnVarDump(char *dumpVar, SoftBusVarDumpCb cb);
int32_t SoftBusRegConnVarDump(const char *dumpVar, SoftBusVarDumpCb cb);
void SoftBusHiDumperConnDeInit(void);
#ifdef __cplusplus

View File

@ -71,7 +71,7 @@ void SoftBusDumpSubModuleHelp(int fd, char *moduleName, ListNode *varList)
SOFTBUS_DPRINTF(fd, " -l <item> Dump the item in %s module, item is nesessary\n", moduleName);
}
static SoftBusDumpVarNode *SoftBusCreateDumpVarNode(char *varName, SoftBusVarDumpCb cb)
static SoftBusDumpVarNode *SoftBusCreateDumpVarNode(const char *varName, SoftBusVarDumpCb cb)
{
SoftBusDumpVarNode *varNode = (SoftBusDumpVarNode *)SoftBusCalloc(sizeof(SoftBusDumpVarNode));
if (varNode == NULL) {
@ -89,7 +89,7 @@ static SoftBusDumpVarNode *SoftBusCreateDumpVarNode(char *varName, SoftBusVarDum
return varNode;
}
int32_t SoftBusAddDumpVarToList(char *dumpVar, SoftBusVarDumpCb cb, ListNode *varList)
int32_t SoftBusAddDumpVarToList(const char *dumpVar, SoftBusVarDumpCb cb, ListNode *varList)
{
if (strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegDiscDumpCb invalid param");
@ -206,7 +206,7 @@ int32_t SoftBusDumpDispatch(int fd, int32_t argc, const char **argv)
SoftBusDumpErrInfo(fd, argv[1]);
SoftBusDumpShowHelp(fd);
}
return SOFTBUS_OK;
}
@ -243,4 +243,3 @@ void SoftBusHiDumperModuleDeInit(void)
SoftBusHiDumperBusCenterDeInit();
SoftBusHiDumperReleaseHandler();
}

View File

@ -25,7 +25,7 @@
static LIST_HEAD(g_conn_var_list);
int32_t SoftBusRegConnVarDump(char *dumpVar, SoftBusVarDumpCb cb)
int32_t SoftBusRegConnVarDump(const char *dumpVar, SoftBusVarDumpCb cb)
{
if (strlen(dumpVar) >= SOFTBUS_DUMP_VAR_NAME_LEN || cb == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "SoftBusRegConnVarDump invalid param");

View File

@ -15,7 +15,7 @@
#include "softbus_errcode.h"
#include "softbus_hidumper_conn.h"
int32_t SoftBusRegConnVarDump(char *dumpVar, SoftBusVarDumpCb cb)
int32_t SoftBusRegConnVarDump(const char *dumpVar, SoftBusVarDumpCb cb)
{
(void)dumpVar;
(void)cb;

View File

@ -148,5 +148,5 @@ int SoftBusTransDumpHandler(int fd, int argc, const char **argv)
void SoftBusTransDumpHandlerInit(void)
{
InitTranHelpInfo();
SoftBusRegHiDumperHandler(MODULE_NAME_TRAN, g_transHelpInfo, SoftBusTransDumpHandler);
SoftBusRegHiDumperHandler((char*)MODULE_NAME_TRAN, g_transHelpInfo, SoftBusTransDumpHandler);
}

View File

@ -81,11 +81,6 @@ SoftBusEvtReportMsg g_bleDuration;
static int32_t InitDurationMsgDefault(SoftBusEvtReportMsg *msg)
{
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "dfx don't get rate duration msg");
return SOFTBUS_ERR;
}
if (msg->paramArray == NULL) {
msg->paramNum = SOFTBUS_EVT_PARAM_FOUR;
msg->paramArray = (SoftBusEvtParam *)SoftBusCalloc(sizeof(SoftBusEvtParam) * msg->paramNum);
@ -131,10 +126,6 @@ static int32_t InitDurationMsgDefault(SoftBusEvtReportMsg *msg)
static void RecoveryStatisticDuration(SoftBusEvtReportMsg *msg)
{
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "dfx don't get rate duration msg");
return;
}
msg->paramArray[EVT_INDEX_ZERO].paramValue.i32v = DEFAULT_INT_VALUE;
msg->paramArray[EVT_INDEX_ONE].paramValue.i32v = DEFAULT_INT_VALUE;
msg->paramArray[EVT_INDEX_TWO].paramValue.i32v = DEFAULT_INT_VALUE;
@ -144,15 +135,10 @@ static void RecoveryStatisticDuration(SoftBusEvtReportMsg *msg)
if (msg == &g_bleDuration) {
msg->paramArray[EVT_INDEX_THREE].paramValue.i32v = CONNECTION_ADDR_BLE;
}
return;
}
static int32_t InitRateOfSuccessMsgDefault(SoftBusEvtReportMsg *msg)
{
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "dfx don't get rate duration msg");
return SOFTBUS_ERR;
}
if (msg->paramArray == NULL) {
msg->paramNum = SOFTBUS_EVT_PARAM_FOUR;
msg->paramArray = (SoftBusEvtParam *)SoftBusCalloc(sizeof(SoftBusEvtParam) * msg->paramNum);
@ -200,10 +186,6 @@ static int32_t InitRateOfSuccessMsgDefault(SoftBusEvtReportMsg *msg)
static void RecoveryStatisticRateOfSuccessMsg(SoftBusEvtReportMsg *msg)
{
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "dfx don't get rate duration msg");
return;
}
msg->paramArray[EVT_INDEX_ZERO].paramValue.i32v = DEFAULT_INT_VALUE;
msg->paramArray[EVT_INDEX_ONE].paramValue.i32v = DEFAULT_INT_VALUE;
msg->paramArray[EVT_INDEX_TWO].paramValue.f = DEFAULT_FLOAT_VAULE;

View File

@ -82,7 +82,7 @@ typedef enum {
} BleConnectionLoopMsg;
static SoftBusHandler g_bleConnectAsyncHandler = {
.name = "g_bleConnectAsyncHandler"
.name = (char *)"g_bleConnectAsyncHandler"
};
typedef struct {
@ -131,7 +131,7 @@ static uint32_t AllocBleConnectionIdLocked()
static BleConnectionInfo* CreateBleConnectionNode(void)
{
BleConnectionInfo *newConnectionInfo = SoftBusCalloc(sizeof(BleConnectionInfo));
BleConnectionInfo *newConnectionInfo = (BleConnectionInfo *)SoftBusCalloc(sizeof(BleConnectionInfo));
if (newConnectionInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "[CreateBleConnectionNode malloc fail.]");
return NULL;
@ -299,7 +299,7 @@ static void BleDeviceConnected(const BleConnectionInfo *itemNode, uint32_t reque
static BleRequestInfo *CreateBleRequestInfo(uint32_t requestId, const ConnectResult *result)
{
BleRequestInfo *request = SoftBusCalloc(sizeof(BleRequestInfo));
BleRequestInfo *request = (BleRequestInfo *)SoftBusCalloc(sizeof(BleRequestInfo));
if (request == NULL) {
return NULL;
}
@ -435,7 +435,7 @@ static int32_t BleConnectDevice(const ConnectOption *option, uint32_t requestId,
}
if (UpdataBleConnectionUnsafe(option, clientId, requestId) != SOFTBUS_OK) {
SoftBusReportConnFaultEvt(SOFTBUS_HISYSEVT_CONN_MEDIUM_BLE, SOFTBUS_HISYSEVT_BLE_CONNECT_FAIL);
SoftbusRecordConnInfo(SOFTBUS_HISYSEVT_CONN_MEDIUM_BLE, SOFTBUS_EVT_CONN_FAIL, 0);
SoftbusRecordConnInfo(SOFTBUS_HISYSEVT_CONN_MEDIUM_BLE, SOFTBUS_EVT_CONN_FAIL, 0);
(void)SoftBusMutexUnlock(&g_connectionLock);
return SOFTBUS_ERR;
}
@ -465,7 +465,7 @@ static int32_t BlePostBytes(uint32_t connectionId, const char *data, int32_t len
(void)SoftBusMutexUnlock(&g_connectionLock);
return SOFTBUS_BLECONNECTION_GETCONNINFO_ERROR;
}
SendQueueNode *node = SoftBusCalloc(sizeof(SendQueueNode));
SendQueueNode *node = (SendQueueNode *)SoftBusCalloc(sizeof(SendQueueNode));
if (node == NULL) {
SoftBusFree((void *)data);
(void)SoftBusMutexUnlock(&g_connectionLock);
@ -507,7 +507,7 @@ static int32_t BlePostBytesInner(uint32_t connectionId, ConnPostData *data)
(void)SoftBusMutexUnlock(&g_connectionLock);
return SOFTBUS_BLECONNECTION_GETCONNINFO_ERROR;
}
SendQueueNode *node = SoftBusCalloc(sizeof(SendQueueNode));
SendQueueNode *node = (SendQueueNode *)SoftBusCalloc(sizeof(SendQueueNode));
if (node == NULL) {
(void)SoftBusMutexUnlock(&g_connectionLock);
return SOFTBUS_MALLOC_ERR;
@ -622,7 +622,7 @@ static void PackRequest(int32_t delta, uint32_t connectionId)
}
}
if (targetNode != NULL && refCount <= 0) {
SoftBusMessage *msg = SoftBusCalloc(sizeof(SoftBusMessage));
SoftBusMessage *msg = (SoftBusMessage *)SoftBusCalloc(sizeof(SoftBusMessage));
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "bleConnectionCreateLoopMsg SoftBusCalloc failed");
(void)SoftBusMutexUnlock(&g_connectionLock);
@ -635,7 +635,7 @@ static void PackRequest(int32_t delta, uint32_t connectionId)
targetNode->state = BLE_CONNECTION_STATE_CLOSING;
}
(void)SoftBusMutexUnlock(&g_connectionLock);
if (targetNode == NULL) {
return;
@ -1304,9 +1304,6 @@ static SoftBusBleTransCalback g_bleTransCallback = {
static void BleConnectionMsgHandler(SoftBusMessage *msg)
{
if (msg == NULL) {
return;
}
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, " 11ble gattc conn loop process msg type %d", msg->what);
switch (msg->what) {
case BLE_CONNECTION_DISCONNECT_OUT: {
@ -1339,10 +1336,6 @@ static void BleConnectionMsgHandler(SoftBusMessage *msg)
static int32_t BleConnectionRemoveMessageFunc(const SoftBusMessage *msg, void *args)
{
if (msg == NULL || args == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "BleConnectionRemoveMessageFunc invalid param");
return SOFTBUS_ERR;
}
uint64_t clientId = (uint64_t)(uintptr_t)args;
if ((msg->what == BLE_CONNECTION_DISCONNECT_OUT) && (msg->arg1 == clientId)) {
return SOFTBUS_OK;
@ -1352,7 +1345,7 @@ static int32_t BleConnectionRemoveMessageFunc(const SoftBusMessage *msg, void *a
static int BleConnLooperInit(void)
{
g_bleConnectAsyncHandler.name = "ble_conn_handler";
g_bleConnectAsyncHandler.name = (char *)"ble_conn_handler";
g_bleConnectAsyncHandler.HandleMessage = BleConnectionMsgHandler;
g_bleConnectAsyncHandler.looper = GetLooper(LOOP_TYPE_DEFAULT);
if (g_bleConnectAsyncHandler.looper == NULL ||

View File

@ -62,7 +62,7 @@ static pthread_mutex_t g_brConnLock;
static int32_t g_brMaxConnCount;
static SoftBusHandler g_brAsyncHandler = {
.name = "g_brAsyncHandler"
.name = (char *)"g_brAsyncHandler"
};
static int32_t ConnectDevice(const ConnectOption *option, uint32_t requestId, const ConnectResult *result);
@ -379,7 +379,7 @@ static void BrDisconnect(int32_t socketFd, int32_t value)
ReleaseConnectionRefByConnId(connectionId);
}
ConnectOption option = {0};
ConnectOption option;
option.type = CONNECT_BR;
option.brOption.sideType = CONN_SIDE_CLIENT;
if (strcpy_s(option.brOption.brMac, BT_MAC_LEN, connectionInfo.brInfo.brMac) != EOK) {
@ -732,7 +732,7 @@ static int32_t SendAck(const BrConnectionInfo *brConnInfo, uint32_t windows, uin
static void WaitAck(BrConnectionInfo *brConnInfo, uint64_t seq)
{
char *data = NULL;
int32_t ret = GetBrPendingPacket(brConnInfo->connectionId, seq, WAIT_ACK_TIMES, &data);
int32_t ret = GetBrPendingPacket(brConnInfo->connectionId, seq, WAIT_ACK_TIMES, (void **)&data);
if (ret == SOFTBUS_ALREADY_TRIGGERED) {
brConnInfo->ackTimeoutCount = 0;
if (brConnInfo->windows < MAX_WINDOWS) {
@ -1297,4 +1297,4 @@ ConnectFuncInterface *ConnInitBr(const ConnectCallback *callback)
pthread_mutex_init(&g_brConnLock, NULL);
g_connectCallback = (ConnectCallback *)callback;
return &g_brInterface;
}
}

View File

@ -13,14 +13,9 @@
* limitations under the License.
*/
#include "softbus_datahead_transform.h"
#include <fcntl.h>
#include <securec.h>
#include <sys/select.h>
#include <sys/types.h>
#include <unistd.h>
#include "softbus_adapter_errcode.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "softbus_adapter_socket.h"

View File

@ -28,7 +28,8 @@ p2p_connection_inc = [
"//foundation/communication/wifi/wifi/interfaces/kits/c",
]
if (dsoftbus_feature_conn_p2p == true) {
if (dsoftbus_feature_conn_p2p == true &&
softbus_communication_wifi_feature == true) {
p2p_connection_src += [
"$dsoftbus_root_path/core/connection/p2p/message/src/p2plink_message.c",
"$dsoftbus_root_path/core/connection/p2p/negotiation/src/p2plink_channel_freq.c",

View File

@ -62,7 +62,7 @@ static void P2pLinkNeoDataDispatch(int64_t authId, int64_t seq, const cJSON *msg
case CMD_REUSE_RESPONSE:
case CMD_REUSE:
case CMD_GC_WIFI_CONFIG_STATE_CHANGE:
P2pLinkControlMsgProc(authId, seq, cmdType, msg);
P2pLinkControlMsgProc(authId, seq, (P2pLinkCmdType)cmdType, msg);
break;
case CMD_REQUEST_INFO:
case CMD_RESPONSE_INFO:
@ -157,7 +157,7 @@ static void P2pLinkAuthChannelCloseProcess(P2pLoopMsg msgType, void *param)
static void P2pLinkAuthChannelClose(int64_t authId)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "P2pLinkAuthChannelClose authId: %" PRId64, authId);
int64_t *param = SoftBusMalloc(sizeof(int64_t));
int64_t *param = (int64_t *)SoftBusMalloc(sizeof(int64_t));
if (param == NULL) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "P2pLinkAuthChannelClose malloc failed");
return;

View File

@ -462,7 +462,7 @@ static void ProcessDisNonPacket(const unsigned char *advData, uint32_t advLen, c
InnerDeviceInfoAddtions addtions = {
.medium = BLE,
};
unsigned int tempCap = 0;
if (ProcessHwHashAccout(foundInfo)) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "same account");
@ -616,7 +616,7 @@ static int32_t GetConDeviceInfo(DeviceInfo *info)
if (DiscBleGetDeviceName(info->devName) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "Get deviceName failed");
}
info->devType = DiscBleGetDeviceType();
info->devType = (DeviceType)DiscBleGetDeviceType();
bool isSameAccount = false;
bool isWakeRemote = false;
for (uint32_t pos = 0; pos < CAPABILITY_MAX_BITNUM; pos++) {
@ -644,7 +644,7 @@ static int32_t GetNonDeviceInfo(DeviceInfo *info)
if (DiscBleGetDeviceName(info->devName) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "Get deviceName failed");
}
info->devType = DiscBleGetDeviceType();
info->devType = (DeviceType)DiscBleGetDeviceType();
uint32_t passiveCapBitMap[CAPABILITY_NUM] = {0};
if (MatchRecvMessage(g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap,
passiveCapBitMap, CAPABILITY_NUM) != SOFTBUS_OK) {
@ -655,7 +655,7 @@ static int32_t GetNonDeviceInfo(DeviceInfo *info)
info->capabilityBitmap[pos] =
g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].capBitMap[pos] | passiveCapBitMap[pos];
}
int32_t activeCnt = g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].rangingRefCnt;
int32_t passiveCnt = g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].rangingRefCnt;
info->range = activeCnt + passiveCnt;
@ -1015,7 +1015,7 @@ static int32_t RegisterCapability(DiscBleInfo *info, const DiscBleOption *option
continue;
}
if (info->capabilityData[pos] == NULL) {
info->capabilityData[pos] = SoftBusCalloc(CUST_DATA_MAX_LEN);
info->capabilityData[pos] = (unsigned char *)SoftBusCalloc(CUST_DATA_MAX_LEN);
if (info->capabilityData[pos] == NULL) {
return SOFTBUS_MALLOC_ERR;
}
@ -1078,7 +1078,7 @@ static int32_t UnregisterCapability(DiscBleInfo *info, DiscBleOption *option)
info->rangingRefCnt -= 1;
info->needUpdate = true;
}
return SOFTBUS_OK;
}
@ -1116,13 +1116,13 @@ static int32_t ProcessBleInfoManager(bool isStart, uint8_t publishFlags, uint8_t
return SOFTBUS_ERR;
}
}
uint32_t newCap = g_bleInfoManager[index].capBitMap[0];
int32_t newRangingRefCount = g_bleInfoManager[index].rangingRefCnt;
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "ble discovery request summary, action: (%d, %d, %d) cap: %d->%d, "
"ref ranging count: %d->%d", isStart, publishFlags, activeFlags, oldCap, newCap, oldRangingRefCount,
newRangingRefCount);
SoftBusMutexUnlock(&g_bleInfoLock);
return SOFTBUS_OK;
}
@ -1249,14 +1249,15 @@ static DiscoveryFuncInterface g_discBleFuncInterface = {
.StopScan = BleStopPassivePublish,
.StartAdvertise = BleStartActiveDiscovery,
.Subscribe = BleStartPassiveDiscovery,
.StopAdvertise = BleStopActiveDiscovery,
.Unsubscribe = BleStopPassiveDiscovery,
.StopAdvertise = BleStopActiveDiscovery,
.UpdateLocalDeviceInfo = BleUpdateLocalDeviceInfo
};
static DiscoveryBleDispatcherInterface g_discBleDispatcherInterface = {
.mediumInterface = &g_discBleFuncInterface,
.IsConcern = BleIsConcern
.IsConcern = BleIsConcern,
.mediumInterface = &g_discBleFuncInterface
};
static int32_t InitAdvertiser(void)
@ -1507,7 +1508,7 @@ static int32_t AddRecvMessage(const char *key, const uint32_t *capBitMap, bool n
RecvMessage *recvMsg = GetRecvMessage(key);
if (recvMsg == NULL) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "key is not exit");
recvMsg = SoftBusCalloc(sizeof(RecvMessage));
recvMsg = (RecvMessage *)SoftBusCalloc(sizeof(RecvMessage));
if (recvMsg == NULL) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "malloc recv msg failed");
SoftBusMutexUnlock(&g_recvMessageInfo.lock);
@ -1631,7 +1632,7 @@ static void DiscBleMsgHandler(SoftBusMessage *msg)
static int32_t DiscBleLooperInit(void)
{
g_discBleHandler.name = "ble_disc_handler";
g_discBleHandler.name = (char *)"ble_disc_handler";
g_discBleHandler.HandleMessage = DiscBleMsgHandler;
g_discBleHandler.looper = GetLooper(LOOP_TYPE_DEFAULT);
if (g_discBleHandler.looper == NULL) {
@ -1737,9 +1738,9 @@ DiscoveryBleDispatcherInterface *DiscSoftbusBleInit(DiscInnerCallback *discInner
goto EXIT;
}
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "DiscSoftbusBleInit success");
SoftBusRegDiscVarDump(BLE_INFO_MANAGER, &BleInfoDump);
SoftBusRegDiscVarDump(BlE_ADVERTISER, &BleAdvertiserDump);
SoftBusRegDiscVarDump(RECV_MESSAGE_INFO, &RecvMessageInfoDump);
SoftBusRegDiscVarDump((char *)BLE_INFO_MANAGER, &BleInfoDump);
SoftBusRegDiscVarDump((char *)BlE_ADVERTISER, &BleAdvertiserDump);
SoftBusRegDiscVarDump((char *)RECV_MESSAGE_INFO, &RecvMessageInfoDump);
return &g_discBleDispatcherInterface;
EXIT:

View File

@ -511,7 +511,7 @@ int32_t DiscNstackxInit(void)
DeinitLocalInfo();
return SOFTBUS_DISCOVER_COAP_INIT_FAIL;
}
SoftBusRegDiscVarDump(NSTACKX_LOCAL_DEV_INFO, &NstackxLocalDevInfoDump);
SoftBusRegDiscVarDump((char *)NSTACKX_LOCAL_DEV_INFO, &NstackxLocalDevInfoDump);
return SOFTBUS_OK;
}

View File

@ -30,6 +30,10 @@ int32_t TransClientProxy::OnClientPermissonChange(const char *pkgName, int32_t s
return SOFTBUS_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "write InterfaceToken failed!");
return SOFTBUS_ERR;
}
if (!data.WriteInt32(state)) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "write PermStateChangeType failed");
return SOFTBUS_ERR;

View File

@ -29,6 +29,21 @@ declare_args() {
"//foundation/communication/dsoftbus/adapter/default_config"
}
declare_args() {
dsoftbus_get_devicename = true
softbus_communication_wifi_feature = true
}
if (defined(global_parts_info) &&
!defined(global_parts_info.communication_wifi)) {
softbus_communication_wifi_feature = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.ability_ability_runtime)) {
dsoftbus_get_devicename = false
}
if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni")
if (ohos_kernel_type == "liteos_m") {

View File

@ -51,6 +51,7 @@ if (defined(ohos_lite)) {
sources = [
"dsoftbus_crypto_test.cpp",
"dsoftbus_other_test.cpp",
"softbus_dfx_test.cpp",
"softbus_socket_test.cpp",
"softbus_thread_test.cpp",
]

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 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 "gtest/gtest.h"
#include <securec.h>
#include "softbus_errcode.h"
#include "softbus_adapter_hisysevent.h"
using namespace testing::ext;
namespace OHOS {
class DsoftbusDfxTest : public testing::Test {
protected:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
/*
* @tc.name: HiSysEventParamDeInitTest001
* @tc.desc: paramType is SOFTBUS_EVT_PARAMTYPE_STRING
* @tc.type: FUNC
* @tc.require: 1
*/
HWTEST_F(DsoftbusDfxTest, HiSysEventParamDeInitTest001, TestSize.Level1)
{
SoftBusEvtParam evtParam;
strcpy_s(evtParam.paramName, sizeof(evtParam.paramName), "test");
evtParam.paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
strcpy_s(evtParam.paramValue.str, sizeof(evtParam.paramValue.str), "test");
SoftBusEvtReportMsg reportMsg;
reportMsg.paramArray = &evtParam;
reportMsg.paramNum = 1;
int32_t ret = SoftbusWriteHisEvt(&reportMsg);
EXPECT_EQ(SOFTBUS_OK, ret);
}
}

View File

@ -26,6 +26,7 @@ ohos_unittest("AuthTest") {
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/utils/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/message_handler/include",

View File

@ -34,12 +34,14 @@
#include "softbus_access_token_test.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "lnn_net_builder.h"
namespace OHOS {
using namespace testing::ext;
constexpr uint32_t TEST_DATA_LEN = 10;
constexpr uint32_t CRYPT_DATA_LEN = 200;
constexpr uint32_t P2P_MAC_LEN = 6;
constexpr uint32_t ENCRYPT_OVER_HEAD_LEN_TEST = 32;
class AuthTest : public testing::Test {
public:
@ -1338,4 +1340,408 @@ HWTEST_F(AuthTest, AUTH_START_LISTENING_Test_001, TestSize.Level1)
ret = AuthStartListening(AUTH_LINK_TYPE_P2P, ip, port);
EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
}
} // namespace OHOS
/*
* @tc.name: FIND_AUTH_REQUEST_BY_CONN_INFO_Test_001
* @tc.desc: Find Auth Request By Conn Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, FIND_AUTH_REQUEST_BY_CONN_INFO_Test_001, TestSize.Level1)
{
AuthConnInfo *authConnInfo = nullptr;
AuthRequest *request = nullptr;
AuthConnInfo authConnInfoValue;
AuthRequest requestValue;
(void)memset_s(&authConnInfoValue, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
(void)memset_s(&requestValue, sizeof(AuthRequest), 0, sizeof(AuthRequest));
int32_t ret = FindAuthRequestByConnInfo(authConnInfo, request);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = FindAuthRequestByConnInfo(&authConnInfoValue, request);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: CHECK_VERIFY_CALLBACK_Test_001
* @tc.desc: Check Verify Callback test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, CHECK_VERIFY_CALLBACK_Test_001, TestSize.Level1)
{
bool ret = CheckVerifyCallback(LnnGetVerifyCallback());
EXPECT_TRUE(ret == true);
ret = CheckVerifyCallback(nullptr);
EXPECT_TRUE(ret == false);
AuthVerifyCallback verifyCb = {
.onVerifyPassed = nullptr,
.onVerifyFailed = nullptr,
};
ret = CheckVerifyCallback(&verifyCb);
EXPECT_TRUE(ret == false);
}
static void OnConnOpenedTest(uint32_t requestId, int64_t authId)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "OnConnOpenedTest: requestId = %d, authId = %" PRId64 ".",
requestId, authId);
}
static void OnConnOpenFailedTest(uint32_t requestId, int32_t reason)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "OnConnOpenFailedTest: requestId = %d, reason = %d.",
requestId, reason);
}
/*
* @tc.name: CHECK_AUTH_CONN_CALLBACK_Test_001
* @tc.desc: Check Auth Conn Callback test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, CHECK_AUTH_CONN_CALLBACK_Test_001, TestSize.Level1)
{
AuthConnCallback cb = {
.onConnOpened = OnConnOpenedTest,
.onConnOpenFailed = OnConnOpenFailedTest,
};
AuthConnCallback connCb = {
.onConnOpened = nullptr,
.onConnOpenFailed = nullptr,
};
bool ret = CheckAuthConnCallback(nullptr);
EXPECT_TRUE(ret == false);
ret = CheckAuthConnCallback(&connCb);
EXPECT_TRUE(ret == false);
ret = CheckAuthConnCallback(&cb);
EXPECT_TRUE(ret == true);
}
/*
* @tc.name: AUTH_SESSION_START_AUTH_Test_001
* @tc.desc: Auth Session Start Auth test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_START_AUTH_Test_001, TestSize.Level1)
{
uint32_t requestId = 0;
uint64_t connId = 0;
AuthConnInfo *connInfo = nullptr;
int32_t ret = AuthSessionStartAuth(GenSeq(false), requestId, connId, connInfo, false);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_SESSION_PROCESS_DEV_ID_DATA_Test_001
* @tc.desc: Auth Session Process Dev Id Data test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_ID_DATA_Test_001,
TestSize.Level1)
{
int64_t authSeq = 0;
uint8_t *data = nullptr;
uint32_t len = 0;
int32_t ret = AuthSessionProcessDevIdData(authSeq, data, len);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_SESSION_SAVE_SESSION_KEY_Test_001
* @tc.desc: Auth Session Save Session Key test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_SAVE_SESSION_KEY_Test_001, TestSize.Level1)
{
int64_t authSeq = 0;
uint8_t *key = nullptr;
uint32_t len = 0;
int32_t ret = AuthSessionSaveSessionKey(authSeq, key, len);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_SESSION_PROCESS_DEV_INFO_DATA_Test_001
* @tc.desc: Auth Session Process Dev Info Data test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_INFO_DATA_Test_001, TestSize.Level1)
{
int64_t authSeq = 0;
const uint8_t *data = nullptr;
uint32_t len = 0;
int32_t ret = AuthSessionProcessDevInfoData(authSeq, data, len);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_SESSION_PROCESS_DEV_INFO_DATA_BY_CONN_ID_Test_001
* @tc.desc: Auth Session Process Dev Info Data By Conn Id test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_INFO_DATA_BY_CONN_ID_Test_001, TestSize.Level1)
{
int64_t connId = 0;
bool isServer = false;
const uint8_t *data = nullptr;
uint32_t len = 0;
int32_t ret = AuthSessionProcessDevInfoDataByConnId(connId, isServer, data, len);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONN_ID_Test_001
* @tc.desc: Auth Session Process Close Ack By Conn Id test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONN_ID_Test_001, TestSize.Level1)
{
int64_t connId = 0;
bool isServer = false;
const uint8_t *data = nullptr;
uint32_t len = 0;
int32_t ret = AuthSessionProcessCloseAckByConnId(connId, isServer, data, len);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: DUP_SESSION_KEY_LIST_Test_001
* @tc.desc: Dup Session Key List test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, DUP_SESSION_KEY_LIST_Test_001, TestSize.Level1)
{
SessionKeyList *srcList = nullptr;
SessionKeyList *dstList = nullptr;
int32_t ret = DupSessionKeyList(srcList, dstList);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: HAS_SESSION_KEY_Test_001
* @tc.desc: Has Session Key test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, HAS_SESSION_KEY_Test_001, TestSize.Level1)
{
SessionKeyList *list = nullptr;
int32_t ret = HasSessionKey(list);
EXPECT_TRUE(ret == false);
}
/*
* @tc.name: ADD_SESSION_KEY_Test_001
* @tc.desc: Add Session Key test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, ADD_SESSION_KEY_Test_001, TestSize.Level1)
{
SessionKeyList *list = nullptr;
int32_t index = 0;
SessionKey *key = nullptr;
SessionKey keyValue;
SessionKeyList listValue;
int32_t ret = AddSessionKey(list, index, key);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
(void)memset_s(&keyValue, sizeof(SessionKey), 0, sizeof(SessionKey));
(void)memset_s(&listValue, sizeof(SessionKeyList), 0, sizeof(SessionKeyList));
ListInit(&listValue);
ret = AddSessionKey(&listValue, index, &keyValue);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: ENCRYPT_DATA_Test_001
* @tc.desc: Encrypt Data test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, ENCRYPT_DATA_Test_001, TestSize.Level1)
{
SessionKeyList *list = nullptr;
SessionKeyList listValue;
(void)memset_s(&listValue, sizeof(SessionKeyList), 0, sizeof(SessionKeyList));
uint8_t indata[TEST_DATA_LEN] = "1234";
int32_t inLen = TEST_DATA_LEN;
uint8_t outData[TEST_DATA_LEN];
uint32_t outLen = TEST_DATA_LEN;
int32_t ret = EncryptData(list, indata, inLen, outData, &outLen);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: DECRYPT_DATA_Test_001
* @tc.desc: Decrypt Data test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, DECRYPT_DATA_Test_001, TestSize.Level1)
{
SessionKeyList *list = nullptr;
uint8_t indata[TEST_DATA_LEN] = "1234";
int32_t inLenValue = ENCRYPT_OVER_HEAD_LEN_TEST + 1;
uint8_t outData[TEST_DATA_LEN];
uint32_t outLen = TEST_DATA_LEN;
int32_t ret = DecryptData(list, indata, inLenValue, outData, &outLen);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: UNPACK_DEVICE_INFO_MESSAGE_Test_001
* @tc.desc: Unpack Device Info Message test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, UNPACK_DEVICE_INFO_MESSAGE_Test_001, TestSize.Level1)
{
const char *msg = "";
int32_t linkType = 1;
SoftBusVersion version = SOFTBUS_OLD_V1;
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
bool isMetaAuth = false;
int32_t ret = UnpackDeviceInfoMessage(msg, linkType, version, &nodeInfo, isMetaAuth);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
/*
* @tc.name: POST_DEVICE_ID_MESSAGE_Test_001
* @tc.desc: Post Device Id Message test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, POST_DEVICE_ID_MESSAGE_Test_001, TestSize.Level1)
{
AuthSessionInfo *info = nullptr;
AuthSessionInfo infoValue;
(void)memset_s(&infoValue, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
int32_t ret = PostDeviceIdMessage(GenSeq(false), info);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = PostDeviceIdMessage(GenSeq(false), &infoValue);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
/*
* @tc.name: PROCESS_DEVICE_ID_MESSAGE_Test_001
* @tc.desc: Process Device Id Message test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, PROCESS_DEVICE_ID_MESSAGE_Test_001, TestSize.Level1)
{
AuthSessionInfo *info = nullptr;
AuthSessionInfo infoValue;
(void)memset_s(&infoValue, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
uint8_t data[TEST_DATA_LEN] = "123";
int32_t ret = ProcessDeviceIdMessage(info, data, sizeof(data));
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = ProcessDeviceIdMessage(&infoValue, data, sizeof(data));
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
/*
* @tc.name: POST_VERIFY_DEVICE_MESSAGE_Test_001
* @tc.desc: Post Verify Device Message test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, POST_VERIFY_DEVICE_MESSAGE_Test_001, TestSize.Level1)
{
const AuthManager *auth = nullptr;
AuthManager authValue;
(void)memset_s(&authValue, sizeof(AuthManager), 0, sizeof(AuthManager));
int32_t ret = PostVerifyDeviceMessage(auth);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: SET_SOCKET_CALLBACK_Test_001
* @tc.desc: Set Socket Callback test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, SET_SOCKET_CALLBACK_Test_001, TestSize.Level1)
{
const SocketCallback *cb = nullptr;
int32_t ret = SetSocketCallback(cb);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: SOCKET_POST_BYTES_Test_001
* @tc.desc: Socket Post Bytes test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, SOCKET_POST_BYTES_Test_001, TestSize.Level1)
{
int32_t fd = 0;
const AuthDataHead *head = NULL;
const uint8_t *data = NULL;
int32_t ret = SocketPostBytes(fd, head, data);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
AuthDataHead headValue;
uint8_t dataValue[TEST_DATA_LEN] = "123";
(void)memset_s(&headValue, sizeof(AuthDataHead), 0, sizeof(AuthDataHead));
ret = SocketPostBytes(fd, &headValue, dataValue);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
/*
* @tc.name: SOCKET_GET_CONN_INFO_Test_001
* @tc.desc: Socket Get Conn Info test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, SOCKET_GET_CONN_INFO_Test_001, TestSize.Level1)
{
int32_t fd = 0;
AuthConnInfo *connInfo = NULL;
bool isServer = false;
int32_t ret = SocketGetConnInfo(fd, connInfo, &isServer);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
AuthConnInfo connInfoValue;
(void)memset_s(&connInfoValue, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
ret = SocketGetConnInfo(fd, &connInfoValue, &isServer);
EXPECT_TRUE(ret == SOFTBUS_ERR);
}
/*
* @tc.name: REG_AUTH_CHANNEL_LISTENER_Test_001
* @tc.desc: Reg Auth Channel Listener test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, REG_AUTH_CHANNEL_LISTENER_Test_001, TestSize.Level1)
{
int32_t module = MODULE_AUTH_CHANNEL;
const AuthChannelListener *listener = nullptr;
int32_t ret = RegAuthChannelListener(module, listener);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
}
/*
* @tc.name: AUTH_OPEN_CHANNEL_Test_001
* @tc.desc: Auth Open Channel test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(AuthTest, AUTH_OPEN_CHANNEL_Test_001, TestSize.Level1)
{
char *ip = nullptr;
char ipValue[32] = "0";
int32_t port = 22;
int32_t ret = AuthOpenChannel(ip, port);
EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
ret = AuthOpenChannel(ipValue, port);
EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
}
} // namespace OHOS

View File

@ -55,6 +55,7 @@ if (defined(ohos_lite)) {
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/dfx/hisysevent_adapter/include",
"$dsoftbus_root_path/core/common/dfx/hidumper_adapter",
]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",

View File

@ -113,6 +113,27 @@ HWTEST_F(LnnDfxTest, ReportBusCenterFaultEvtTest001, TestSize.Level0)
ASSERT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: ReportBusCenterFaultEvtTest002
* @tc.desc:
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnDfxTest, ReportBusCenterFaultEvtTest002, TestSize.Level1)
{
SoftBusEvtReportMsg msg;
memset_s(&msg, sizeof(msg), 0, sizeof(msg));
int32_t errorCode = SOFTBUS_NETWORK_AUTH_TCP_ERR;
ConnectionAddr addr;
addr.type = CONNECTION_ADDR_WLAN;
int32_t ret = CreateBusCenterFaultEvt(&msg, errorCode, &addr);
ASSERT_EQ(SOFTBUS_OK, ret);
ASSERT_NE(nullptr, msg.paramArray);
ret = ReportBusCenterFaultEvt(&msg);
ASSERT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: InitBusCenterDfxTest001
* @tc.desc: Verify InitBusCenterDfx function, use the normal parameter.
@ -273,6 +294,18 @@ HWTEST_F(LnnDfxTest, LnnDfxTest_SoftBusReportDiscStartupEvt_001, TestSize.Level1
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: LnnDfxTest_SoftBusReportDiscStartupEvt_002
* @tc.desc: packageName is null
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnDfxTest, LnnDfxTest_SoftBusReportDiscStartupEvt_002, TestSize.Level1)
{
int ret = SoftBusReportDiscStartupEvt(nullptr);
EXPECT_EQ(ret, SOFTBUS_ERR);
}
/**
* @tc.name: LnnDfxTest_SoftbusRecordDiscScanTimes_001
* @tc.desc: Error register timeout callback test.
@ -313,4 +346,17 @@ HWTEST_F(LnnDfxTest, LnnDfxTest_SoftbusRecordDiscFault_001, TestSize.Level1)
ret = SoftbusRecordDiscFault(SOFTBUS_HISYSEVT_DISC_MEDIUM_BLE, errCode);
EXPECT_EQ(SOFTBUS_OK, ret);
}
}; // namespace OHOS
/**
* @tc.name: LnnDfxTest_SoftbusRecordDiscFault_002
* @tc.desc: ErrCodeConvert,errCode == g_error_map[i].originErrCode
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LnnDfxTest, LnnDfxTest_SoftbusRecordDiscFault_002, TestSize.Level1)
{
int32_t errCode = SOFTBUS_DISCOVER_NOT_INIT;
int ret = SoftbusRecordDiscFault(SOFTBUS_HISYSEVT_DISC_MEDIUM_BLE, errCode);
EXPECT_EQ(ret, SOFTBUS_OK);
}
} // namespace OHOS

View File

@ -17,13 +17,8 @@
#include <gtest/gtest.h>
#include "softbus_error_code.h"
#include "softbus_adapter_mem.h"
#include "softbus_log.h"
#include "softbus_common.h"
#include "softbus_hisysevt_transreporter.h"
#include "securec.h"
#include "softbus_adapter_hisysevent.h"
#include "softbus_hisysevt_common.h"
#include "softbus_hidumper_trans.c"
using namespace std;
using namespace testing::ext;
@ -56,5 +51,19 @@ HWTEST_F(TransDfxTest, CreateTransFaultEvtTest001, TestSize.Level0)
int32_t errorCode = SOFTBUS_ACCESS_TOKEN_DENIED;
SoftbusReportTransErrorEvt(errorCode);
}
}; // namespace OHOS
/**
* @tc.name: SoftBusTransDumpHandler_001
* @tc.desc: Verify SoftBusTransDumpHandler function, use the normal parameter.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(TransDfxTest, SoftBusTransDumpHandler_001, TestSize.Level1)
{
int fd = 1;
int argc = 1;
const char* argv = "aaa";
int ret = SoftBusTransDumpHandler(fd, argc, &argv);
EXPECT_EQ(SOFTBUS_OK, ret);
}
} // namespace OHOS

View File

@ -15,9 +15,11 @@ group("unittest") {
testonly = true
deps = [
"ble:softbus_conn_ble_test",
"br:softbus_conn_br_manager_test",
"br:softbus_conn_br_test",
"common/unittest:softbus_conn_common_test",
"manager:softbus_conn_manager_test",
"p2p:softbus_connection_p2p_test",
"tcp:softbus_tcp_manager_test",
]
}

View File

@ -19,12 +19,21 @@ module_output_path = "dsoftbus/connection"
ohos_unittest("softbus_conn_ble_test") {
module_out_path = module_output_path
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$softbus_adapter_common/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$softbus_adapter_common/include",
"$softbus_adapter_common/net/bluetooth/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/manager",
"$dsoftbus_root_path/core/connection/tcp/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/ble/src",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"//third_party/googletest/googletest/include",
"//third_party/googletest/googletest/src",
"//third_party/bounds_checking_function/include",

View File

@ -14,7 +14,6 @@
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <gtest/gtest.h>
#include <securec.h>
@ -26,106 +25,66 @@
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_log.h"
#define TEST_BLE_MAC "11:22:33:44:55:66"
static unsigned int g_connId = 0;
static unsigned int g_secondConnId = 0;
#define WAIT_CONNECTION_COUNT 8
#define WAIT_CONNECTION_SLEEP_TIME 1
#include "softbus_ble_connection.c"
using namespace testing::ext;
namespace OHOS {
static uint32_t g_connId;
void ConnectedCB(unsigned int connectionId, const ConnectionInfo *info)
{
if (info->type == CONNECT_BLE) {
if (info->type == CONNECT_BLE) {
g_connId = connectionId;
}
return;
}
void DisConnectCB(unsigned int connectionId, const ConnectionInfo *info)
{
return;
}
void DataReceivedCB(unsigned int connectionId, ConnModule moduleId, int64_t seq, char *data, int len)
{
return;
}
void ConnectSuccessedCB(unsigned int requestId, unsigned int connectionId, const ConnectionInfo *info)
{
g_connId = connectionId;
return;
}
void SecondConnectSuccessedCB(unsigned int requestId, unsigned int connectionId, const ConnectionInfo *info)
{
g_secondConnId = connectionId;
return;
}
void ConnectFailedCB(unsigned int requestId, int reason)
{
return;
}
void DisConnectCB(unsigned int connectionId, const ConnectionInfo *info) {}
void DataReceivedCB(unsigned int connectionId, ConnModule moduleId, int64_t seq, char *data, int len) {}
class ConnectionBleTest : public testing::Test {
public:
ConnectionBleTest()
{}
~ConnectionBleTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static void SetUpTestCase();
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
void ConnectionBleTest::SetUpTestCase(void)
void ConnectionBleTest::SetUpTestCase()
{
SoftbusConfigInit();
ConnServerInit();
LooperInit();
BleConnLooperInit();
SoftBusMutexAttr attr;
attr.type = SOFTBUS_MUTEX_RECURSIVE;
SoftBusMutexInit(&g_connectionLock, &attr);
BleQueueInit();
}
void ConnectionBleTest::TearDownTestCase(void)
{}
void ConnectionBleTest::SetUp(void)
{}
void ConnectionBleTest::TearDown(void)
{}
/*
* @tc.name: testConnmanger001
* @tc.name: ManagerTest001
* @tc.desc: test ConnTypeIsSupport
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBleTest, testConnmanger001, TestSize.Level1)
HWTEST_F(ConnectionBleTest, ManagerTest001, TestSize.Level1)
{
int ret;
printf("testConnmanger001\r\n");
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest001");
ret = ConnTypeIsSupport(CONNECT_BLE);
EXPECT_EQ(SOFTBUS_OK, ret);
};
EXPECT_NE(ret, SOFTBUS_OK);
}
/*
* @tc.name: testConnmanger002
* @tc.name: ManagerTest002
* @tc.desc: test invalid param
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBleTest, testConnmanger002, TestSize.Level1)
HWTEST_F(ConnectionBleTest, ManagerTest002, TestSize.Level1)
{
printf("test begin testConnmanger002 \r\n");
int ret;
ret = ConnSetConnectCallback(static_cast<ConnModule>(0), nullptr);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest002");
int ret = ConnSetConnectCallback(static_cast<ConnModule>(0), nullptr);
ASSERT_TRUE(ret != SOFTBUS_OK);
ret = ConnConnectDevice(nullptr, 0, nullptr);
ASSERT_TRUE(ret != SOFTBUS_OK);
@ -139,105 +98,180 @@ HWTEST_F(ConnectionBleTest, testConnmanger002, TestSize.Level1)
ASSERT_TRUE(ret != SOFTBUS_OK);
ConnUnSetConnectCallback(static_cast<ConnModule>(0));
EXPECT_EQ(SOFTBUS_OK, SOFTBUS_OK);
};
}
/*
* @tc.name: testConnmanger003
* @tc.name: ManagerTest003
* @tc.desc: test set unset callback and post disconnect without connect
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBleTest, testConnmanger003, TestSize.Level1)
HWTEST_F(ConnectionBleTest, ManagerTest003, TestSize.Level1)
{
printf("test begin ConnManagerTest004 \r\n");
int ret;
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest003");
ConnectCallback connCb;
connCb.OnConnected = ConnectedCB;
connCb.OnDisconnected = DisConnectCB;
connCb.OnDataReceived = DataReceivedCB;
ret = ConnSetConnectCallback(MODULE_TRUST_ENGINE, &connCb);
int ret = ConnSetConnectCallback(MODULE_TRUST_ENGINE, &connCb);
EXPECT_EQ(SOFTBUS_OK, ret);
ConnUnSetConnectCallback(MODULE_TRUST_ENGINE);
g_connId = 0;
};
}
/*
* @tc.name: testConnmanger004
* @tc.name: ManagerTest004
* @tc.desc: Test start stop listening.
* @tc.in: Test module, Test number,Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The ConnStartLocalListening and ConnStopLocalListening operates normally.
*/
HWTEST_F(ConnectionBleTest, testConnmanger004, TestSize.Level1)
HWTEST_F(ConnectionBleTest, ManagerTest004, TestSize.Level1)
{
int ret;
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest004");
ConnectCallback connCb;
LocalListenerInfo info;
connCb.OnConnected = ConnectedCB;
connCb.OnDisconnected = DisConnectCB;
connCb.OnDataReceived = DataReceivedCB;
ret = ConnSetConnectCallback(MODULE_TRUST_ENGINE, &connCb);
EXPECT_EQ(SOFTBUS_OK, ret);
int ret = ConnSetConnectCallback(MODULE_TRUST_ENGINE, &connCb);
EXPECT_EQ(ret, SOFTBUS_OK);
LocalListenerInfo info;
info.type = CONNECT_BLE;
ret = ConnStartLocalListening(&info);
EXPECT_EQ(SOFTBUS_ERR, ret);
EXPECT_NE(ret, SOFTBUS_OK);
ret = ConnStopLocalListening(&info);
EXPECT_EQ(SOFTBUS_ERR, ret);
EXPECT_NE(ret, SOFTBUS_OK);
ConnUnSetConnectCallback(MODULE_TRUST_ENGINE);
g_connId = 0;
};
}
/*
* @tc.name: testConnmanger005
* @tc.name: ManagerTest005
* @tc.desc: Test ConnTypeIsSupport.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The ConnTypeIsSupport operates normally.
*/
HWTEST_F(ConnectionBleTest, testConnmanger005, TestSize.Level1)
HWTEST_F(ConnectionBleTest, ManagerTest005, TestSize.Level1)
{
int ret;
printf("testConnmanger016\r\n");
ret = ConnTypeIsSupport(CONNECT_P2P);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest005");
int ret = ConnTypeIsSupport(CONNECT_P2P);
EXPECT_EQ(SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT, ret);
};
/*
* @tc.name: testConnmanger006
* @tc.desc: Test ConnTypeIsSupport.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ConnTypeIsSupport operates normally.
*/
HWTEST_F(ConnectionBleTest, testConnmanger006, TestSize.Level1)
{
int ret;
printf("testConnmanger017\r\n");
ret = ConnTypeIsSupport(CONNECT_BR);
EXPECT_EQ(SOFTBUS_OK, ret);
};
/*
* @tc.name: testConnmanger007
* @tc.desc: Test ConnTypeIsSupport.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ConnTypeIsSupport operates normally.
*/
HWTEST_F(ConnectionBleTest, testConnmanger007, TestSize.Level1)
{
int ret;
printf("testConnmanger018\r\n");
ret = ConnTypeIsSupport(CONNECT_TCP);
EXPECT_EQ(SOFTBUS_OK, ret);
};
}
/*
* @tc.name: ManagerTest006
* @tc.desc: Test ConnTypeIsSupport.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ConnTypeIsSupport operates normally.
*/
HWTEST_F(ConnectionBleTest, ManagerTest006, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest006");
int ret = ConnTypeIsSupport(CONNECT_BR);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/*
* @tc.name: ManagerTest007
* @tc.desc: Test ConnTypeIsSupport.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ConnTypeIsSupport operates normally.
*/
HWTEST_F(ConnectionBleTest, ManagerTest007, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "ManagerTest007");
int ret = ConnTypeIsSupport(CONNECT_TCP);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/*
* @tc.name: PackRequest
* @tc.desc: test reference process is valid
* @tc.in: test module, test number, test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: NA
*/
HWTEST_F(ConnectionBleTest, PackRequest, TestSize.Level1)
{
BleConnectionInfo *info = CreateBleConnectionNode();
info->refCount = CONNECT_REF_INCRESE;
ListAdd(&g_connection_list, &info->node);
PackRequest(CONNECT_REF_DECRESE, info->connId);
EXPECT_EQ(info->state, BLE_CONNECTION_STATE_CLOSING);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: OnPackResponse
* @tc.desc: test reference process is valid
* @tc.in: test module, test number, test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: NA
*/
HWTEST_F(ConnectionBleTest, OnPackResponse, TestSize.Level1)
{
BleConnectionInfo *info = CreateBleConnectionNode();
info->state = BLE_CONNECTION_STATE_CLOSING;
ListAdd(&g_connection_list, &info->node);
OnPackResponse(CONNECT_REF_INCRESE, CONNECT_REF_INCRESE, info->connId);
EXPECT_EQ(info->state, BLE_CONNECTION_STATE_CONNECTED);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: BleConnectionMsgHandler
* @tc.desc: test message handle function
* @tc.in: test module, test number, test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: NA
*/
HWTEST_F(ConnectionBleTest, BleConnectionMsgHandler, TestSize.Level1)
{
SoftBusMessage *message = MallocMessage();
message->what = BLE_CONNECTION_DISCONNECT_OUT;
BleConnectionMsgHandler(message);
BleConnectionInfo *info = CreateBleConnectionNode();
info->state = BLE_CONNECTION_STATE_CLOSED;
ListAdd(&g_connection_list, &info->node);
message->arg1 = info->connId;
BleConnectionMsgHandler(message);
EXPECT_EQ(info->state, BLE_CONNECTION_STATE_CLOSED);
FreeMessage(message);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: BleConnectionRemoveMessageFunc
* @tc.desc: remove message function
* @tc.in: test module, test number, test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: NA
*/
HWTEST_F(ConnectionBleTest, BleConnectionRemoveMessageFunc, TestSize.Level1)
{
int64_t clientId = INT32_MAX;
SoftBusMessage *message = MallocMessage();
message->what = BLE_CONNECTION_DISCONNECT_OUT;
message->arg1 = clientId;
BleConnectionRemoveMessageFunc(message, &clientId);
}
}

View File

@ -15,21 +15,34 @@ import("//build/test.gni")
import("//foundation/communication/dsoftbus/dsoftbus.gni")
module_output_path = "dsoftbus/connection"
ohos_unittest("softbus_conn_br_test") {
module_out_path = module_output_path
config("softbus_connection_br_test_config") {
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/adapter/br/include",
"$softbus_adapter_common/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/manager",
"$dsoftbus_root_path/core/connection/tcp/include",
"$dsoftbus_root_path/core/connection/br/include",
"$dsoftbus_root_path/core/connection/br/src",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$softbus_adapter_common/net/bluetooth/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"//third_party/googletest/googletest/include",
"//third_party/googletest/googletest/src",
"//third_party/bounds_checking_function/include",
]
}
ohos_unittest("softbus_conn_br_test") {
module_out_path = module_output_path
public_configs = [ ":softbus_connection_br_test_config" ]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
@ -44,3 +57,21 @@ ohos_unittest("softbus_conn_br_test") {
]
sources = [ "connection_br_test.cpp" ]
}
ohos_unittest("softbus_conn_br_manager_test") {
module_out_path = module_output_path
public_configs = [ ":softbus_connection_br_test_config" ]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
sources = [ "connection_br_manager_test.cpp" ]
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (c) 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 <gtest/gtest.h>
#include "softbus_conn_interface.h"
#include "softbus_conn_manager.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_log.h"
#include "br_connection_manager.c"
using namespace testing::ext;
namespace OHOS {
class ConnectionBrManagerTest : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
/*
* @tc.name: HasDiffMacDeviceExit
* @tc.desc: br mac match
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrManagerTest, HasDiffMacDeviceExit, TestSize.Level1)
{
BrConnectionInfo *info = CreateBrconnectionNode(true);
char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
ListAdd(&g_connection_list, &info->node);
ConnectOption option;
int32_t ret = HasDiffMacDeviceExit(&option);
EXPECT_EQ(ret, true);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: GetBrConnStateByConnectionId
* @tc.desc: find by connection Id
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrManagerTest, GetBrConnStateByConnectionId, TestSize.Level1)
{
BrConnectionInfo *info = CreateBrconnectionNode(true);
info->state = BR_CONNECTION_STATE_CLOSED;
ListAdd(&g_connection_list, &info->node);
int32_t ret = GetBrConnStateByConnectionId(info->connectionId);
EXPECT_EQ(ret, BR_CONNECTION_STATE_CLOSED);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: BrClosingByConnOption
* @tc.desc: br mac match
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrManagerTest, BrClosingByConnOption, TestSize.Level1)
{
char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
BrConnectionInfo *info = CreateBrconnectionNode(true);
memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
info->state = BR_CONNECTION_STATE_CLOSED;
ListAdd(&g_connection_list, &info->node);
ConnectOption option;
memcpy_s(option.brOption.brMac, sizeof(option.brOption.brMac), mac, sizeof(mac));
int32_t socketFd;
int32_t sideType;
int32_t ret = BrClosingByConnOption(&option, &socketFd, &sideType);
EXPECT_EQ(ret, SOFTBUS_OK);
ListDelete(&info->node);
SoftBusFree(info);
}
/*
* @tc.name: BrCheckActiveConnection
* @tc.desc: br mac match and state
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrManagerTest, BrCheckActiveConnection, TestSize.Level1)
{
char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
BrConnectionInfo *info = CreateBrconnectionNode(true);
memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
info->state = BR_CONNECTION_STATE_CONNECTED;
ListAdd(&g_connection_list, &info->node);
ConnectOption option;
memcpy_s(option.brOption.brMac, sizeof(option.brOption.brMac), mac, sizeof(mac));
int32_t ret = BrCheckActiveConnection(&option);
EXPECT_EQ(ret, SOFTBUS_OK);
ListDelete(&info->node);
SoftBusFree(info);
}
}

View File

@ -26,6 +26,7 @@
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_log.h"
#include "br_connection.c"
static const uint32_t CONN_HEAD_SIZE = 24;
#define TEST_BR_MAC "24:DA:33:6A:06:EC"
@ -108,6 +109,12 @@ void ConnectionBrTest::SetUp(void)
void ConnectionBrTest::TearDown(void)
{}
int32_t GetBrConnStateByConnectionId(uint32_t connectId)
{
(void)connectId;
return BR_CONNECTION_STATE_CLOSED;
}
/*
* @tc.name: testConnmanger001
* @tc.desc: test ConnTypeIsSupport
@ -510,4 +517,32 @@ HWTEST_F(ConnectionBrTest, testConnmanger010, TestSize.Level1)
}
ConnUnSetConnectCallback(MODULE_TRUST_ENGINE);
};
/*
* @tc.name: PostBytesInner
* @tc.desc: connect state != BR_CONNECTION_STATE_CLOSING && state != BR_CONNECTION_STATE_CONNECTED
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrTest, PostBytesInner, TestSize.Level1)
{
uint32_t len = 16;
char *data = (char *) SoftBusMalloc(len);
int32_t ret = PostBytesInner(0, 0, data, len);
EXPECT_EQ(ret, SOFTBUS_BRCONNECTION_POSTBYTES_ERROR);
}
/*
* @tc.name: PostBytes
* @tc.desc: connect state != BR_CONNECTION_STATE_CONNECTED
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionBrTest, PostBytes, TestSize.Level1)
{
uint32_t len = 16;
char *data = (char *) SoftBusMalloc(len);
int32_t ret = PostBytesInner(0, 0, data, len);
EXPECT_EQ(ret, SOFTBUS_BRCONNECTION_POSTBYTES_ERROR);
}
}

View File

@ -1759,4 +1759,63 @@ HWTEST_F(SoftbusCommonTest, testSocket002, TestSize.Level1)
ret = ConnGetPeerSocketAddr(TEST_FD, &g_socketAddr);
EXPECT_EQ(SOFTBUS_ERR, ret);
};
/*
* @tc.name: testConnSetTcpUserTimeOut001
* @tc.desc: Test ConnSetTcpUserTimeOut param is invalid
* @tc.in: test module, test number,test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ThreadPoolDestroy operates normally.
*/
HWTEST_F(SoftbusCommonTest, testConnSetTcpUserTimeOut001, TestSize.Level1)
{
int32_t fd = -1;
uint32_t millSec= 1;
int ret = ConnSetTcpUserTimeOut(fd, millSec);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
/*
* @tc.name: testConnSetTcpUserTimeOut002
* @tc.desc: Test ConnSetTcpUserTimeOut param is invalid
* @tc.in: test module, test number,test levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require: The ThreadPoolDestroy operates normally.
*/
HWTEST_F(SoftbusCommonTest, testConnSetTcpUserTimeOut002, TestSize.Level1)
{
int32_t fd = 1;
uint32_t millSec= 321;
int ret = ConnSetTcpUserTimeOut(fd, millSec);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
/*
* @tc.name: testSocket003
* @tc.desc: test ConnGetPeerSocketAddr param is invalid
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusCommonTest, testSocket003, TestSize.Level1)
{
int ret;
SocketAddr socketAddr;
ret = ConnGetPeerSocketAddr(INVALID_FD, &socketAddr);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
/*
* @tc.name: testSocket004
* @tc.desc: test ConnGetLocalSocketPort port
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusCommonTest, testSocket004, TestSize.Level1)
{
int ret;
ret = ConnGetLocalSocketPort(INVALID_FD);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
}

View File

@ -0,0 +1,82 @@
# Copyright (c) 2021 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.
import("//build/test.gni")
import("//foundation/communication/dsoftbus/dsoftbus.gni")
module_output_path = "dsoftbus/connection"
ohos_unittest("softbus_connection_p2p_test") {
module_out_path = module_output_path
if (dsoftbus_feature_conn_br == true) {
defines = [ "connection_enable_br_test" ]
} else {
defines = []
}
if (dsoftbus_feature_conn_ble == true) {
defines += [ "connection_enable_ble_test" ]
}
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$softbus_adapter_common/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/manager",
"$dsoftbus_root_path/core/connection/p2p/manager/include",
"$dsoftbus_root_path/core/connection/p2p/interface",
"$dsoftbus_root_path/core/connection/p2p/common/include",
"$dsoftbus_root_path/core/connection/tcp/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$softbus_adapter_common/include",
"$softbus_adapter_common/net/bluetooth/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/manager",
"$dsoftbus_root_path/core/connection/tcp/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/connection/p2p/message/src",
"$dsoftbus_root_path/core/connection/p2p/message/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/connection/p2p/adapter",
"$dsoftbus_root_path/core/connection/p2p/negotiation/include",
"//third_party/googletest/googletest/include",
"//third_party/googletest/googletest/src",
"//third_party/bounds_checking_function/include",
]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
"$dsoftbus_root_path/core/frame:softbus_server",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
sources = [ "connection_p2p_test.cpp" ]
}

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2021 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 <cstring>
#include <gtest/gtest.h>
#include <securec.h>
#include "p2plink_manager.h"
#include "softbus_log.h"
#include "p2plink_interface.h"
#include "p2plink_message.c"
using namespace testing::ext;
namespace OHOS {
class ConnectionP2PFuncTest : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
/*
* @tc.name: testP2pLinkLoopDisconnectDev001
* @tc.desc: arg is NULL
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionP2PFuncTest, testP2pLinkLoopDisconnectDev001, TestSize.Level1)
{
P2pLinkLoopDisconnectDev(P2PLOOP_P2PAUTHCHAN_OK, nullptr);
EXPECT_EQ(true, true);
}
/*
* @tc.name: testP2pLinkLoopDisconnectDev002
* @tc.desc: test ConnTypeIsSupport
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionP2PFuncTest, testP2pLinkLoopDisconnectDev002, TestSize.Level1)
{
P2pLinkDisconnectInfo info = {
.authId = 11,
.peerMac = "abc",
.pid = 11,
};
P2pLinkLoopDisconnectDev(P2PLOOP_P2PAUTHCHAN_OK, &info);
EXPECT_EQ(true, true);
}
/*
* @tc.name: testP2pLinkNeoDataProcess001
* @tc.desc: param is NULL
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionP2PFuncTest, testP2pLinkNeoDataProcess001, TestSize.Level1)
{
P2pLinkNeoDataProcess(P2PLOOP_P2PAUTHCHAN_OK, nullptr);
EXPECT_EQ(true, true);
}
/*
* @tc.name: testP2pLinkNegoDataRecv001
* @tc.desc: param is NULL
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionP2PFuncTest, testP2pLinkNegoDataRecv001, TestSize.Level1)
{
int64_t authId = 11;
AuthTransData *data = nullptr;
P2pLinkNegoDataRecv(authId, data);
EXPECT_EQ(true, true);
}
/*
* @tc.name: testP2pLinkSendMessage001
* @tc.desc: param is NULL
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ConnectionP2PFuncTest, testP2pLinkSendMessage001, TestSize.Level1)
{
char data[] = "data";
int ret = P2pLinkSendMessage(11, data, strlen(data));
EXPECT_EQ(ret, SOFTBUS_ERR);
}
} // namespace OHOS

View File

@ -897,7 +897,7 @@ HWTEST_F(SoftbusTcpManagerTest, testTcpManager023, TestSize.Level1)
.protocol = LNN_PROTOCOL_IP
}
};
int fd = tcp->OpenClientSocket(&option, "127.0.0.1", true);
int tos = 1;
int ret = SetIpTos(fd, tos);
@ -1592,4 +1592,16 @@ HWTEST_F(SoftbusTcpManagerTest, testTcpManager047, TestSize.Level1)
int fd = tcp->OpenServerSocket(&info);
EXPECT_EQ(ConnSetTcpKeepAlive(fd, 100), SOFTBUS_OK);
};
/*
* @tc.name: testTcpDisconnectDeviceNow001
* @tc.desc: test TcpDisconnectDeviceNow invaild parma
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusTcpManagerTest, testTcpDisconnectDeviceNow001, TestSize.Level1)
{
int ret = TcpDisconnectDeviceNow(nullptr);
EXPECT_EQ(ret, SOFTBUS_ERR);
}
}

View File

@ -23,15 +23,18 @@ ohos_unittest("DiscoveryBleDispatcherTest") {
sources = [ "disc_ble_dispatcher_test.cpp" ]
include_dirs = [
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/core/discovery/ble/dispatcher/include",
"//foundation/communication/dsoftbus/core/discovery/manager/include",
"//foundation/communication/dsoftbus/core/discovery/interface",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/discovery/ble/dispatcher/include",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
]
deps = [
"//foundation/communication/dsoftbus/components/nstackx/nstackx_ctrl:nstackx_ctrl",
"//foundation/communication/dsoftbus/core/frame:softbus_server",
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/components/nstackx/nstackx_ctrl:nstackx_ctrl",
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
"//third_party/googletest:gtest_main",
]

View File

@ -18,6 +18,7 @@
#include "disc_ble_dispatcher.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
using namespace testing::ext;
@ -241,6 +242,23 @@ static int32_t StopAdvertiseB(const SubscribeOption *option)
return SOFTBUS_ERR;
}
static PublishOption g_pOption0 = {
.freq = 1,
.capabilityBitmap = {0},
.capabilityData = nullptr,
.dataLen = 0,
.ranging = true
};
static SubscribeOption g_sOption0 = {
.freq = 1,
.isSameAccount = true,
.isWakeRemote = false,
.capabilityBitmap = {0},
.capabilityData = nullptr,
.dataLen = 0
};
static PublishOption g_pOption1 = {
.freq = 1,
.capabilityBitmap = {1},
@ -706,5 +724,61 @@ HWTEST_F(DiscoveryBleDispatcherTest, testUpdateLocalDeviceInfo001, TestSize.Leve
interface->UpdateLocalDeviceInfo(type);
afterFunCntA = g_interfaceFunCntA.updateLocalDeviceInfoCntA;
EXPECT_EQ(beforeFunCntA+1, afterFunCntA);
};
}
/*
* @tc.name: BleDispatchPublishOption001
* @tc.desc: test dispatcher
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscoveryBleDispatcherTest, BleDispatchPublishOption001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "BleDispatchPublishOption001");
DiscoveryFuncInterface *interface = DiscBleInitForTest(&a, &b);
int32_t ret = interface->Publish(&g_pOption0);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
/*
* @tc.name: BleDispatchSubscribeOption001
* @tc.desc: test dispatcher
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscoveryBleDispatcherTest, BleDispatchSubscribeOption001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "BleDispatchSubscribeOption001");
DiscoveryFuncInterface *interface = DiscBleInitForTest(&a, &b);
int32_t ret = interface->StartAdvertise(&g_sOption0);
EXPECT_EQ(SOFTBUS_ERR, ret);
}
/*
* @tc.name: DiscBleInit001
* @tc.desc: test dispatcher
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscoveryBleDispatcherTest, DiscBleInit001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "DiscBleInit001");
DiscoveryFuncInterface *interface = DiscBleInit(nullptr);
EXPECT_EQ(interface, nullptr);
}
/*
* @tc.name: DiscBleInit002
* @tc.desc: test dispatcher
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscoveryBleDispatcherTest, DiscBleInit002, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "DiscBleInit002");
DiscInnerCallback g_discMgrMediumCb;
g_discMgrMediumCb.OnDeviceFound = nullptr;
DiscoveryFuncInterface *interface = DiscBleInit(&g_discMgrMediumCb);
EXPECT_EQ(interface, nullptr);
}
}

View File

@ -0,0 +1,75 @@
# Copyright (c) 2021 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.
import("//build/lite/config/component/lite_component.gni")
import("//build/ohos.gni")
import("//build/test.gni")
import("//foundation/communication/dsoftbus/dsoftbus.gni")
module_output_path = "dsoftbus/discovery"
ohos_unittest("SoftBusDiscBleTest") {
module_out_path = module_output_path
sources = [ "disc_ble_softbus_test.cpp" ]
include_dirs = [
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/core/discovery/ble/dispatcher/include",
"//foundation/communication/dsoftbus/core/discovery/manager/include",
"//foundation/communication/dsoftbus/core/discovery/interface",
"//foundation/communication/dsoftbus/core/discovery/ble/softbus_ble/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$softbus_adapter_common/include",
"$softbus_adapter_common/net/bluetooth/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/manager",
"$dsoftbus_root_path/core/connection/tcp/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/ble/src",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/ble/softbus_ble/include",
"$dsoftbus_root_path/core/discovery/ble/softbus_ble/src",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/adapter/bus_center/include",
]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/frame:softbus_server",
"//foundation/communication/dsoftbus/components/nstackx/nstackx_ctrl:nstackx_ctrl",
"//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 = [ ":SoftBusDiscBleTest" ]
}

View File

@ -0,0 +1,729 @@
/*
* Copyright (c) 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 <cmath>
#include <gtest/gtest.h>
#include "disc_ble.c"
#include "softbus_errcode.h"
#include "message_handler.h"
using namespace testing::ext;
namespace OHOS {
class SoftBusDiscBleTest : public testing::Test {
public:
void SetUp() override {}
void TearDown() override {}
};
static int g_info = 0;
static bool g_softbusBtState = BLE_ENABLE;
static InnerDeviceInfoAddtions addtionsTest;
static void TestOnDeviceFound(const DeviceInfo *device, const InnerDeviceInfoAddtions *addtions)
{
addtionsTest.medium = addtions->medium;
}
static DiscInnerCallback g_discInnerCallback = {
.OnDeviceFound = TestOnDeviceFound,
};
int SoftBusGetBtState()
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "Get, GXY, BT, STATE");
if (g_softbusBtState) {
return BLE_ENABLE;
}
return BLE_DISABLE;
}
int32_t GetDeviceInfo(DeviceInfo *info)
{
(void)info;
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetDeviceInfo, START");
if (g_info == 0) {
return 0;
}
return -1;
}
int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data)
{
(void)data;
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, SoftBusSetAdvData, START");
if (advId == 1 || advId == 2) {
return SOFTBUS_OK;
}
return SOFTBUS_ERR;
}
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param)
{
(void)param;
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, SoftBusBleAdvParams, START");
if (advId == 2) {
return SOFTBUS_OK;
}
return SOFTBUS_ERR;
}
/*
* @tc.name: DeConvertBitMap001
* @tc.desc: test DeConvertBitMap
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, DeConvertBitMap001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, DeConvertBitMap001, Start");
uint32_t tempCap = 0;
int32_t capabilityBitmapNum = 1;
uint32_t capabilityBitmap[DISC_MAX_CAPABILITY_NUM] = { 0x10 };
DeConvertBitMap(&tempCap, capabilityBitmap, capabilityBitmapNum);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, DeConvertBitMap001, End");
}
/*
* @tc.name: ResetInfoUpdate001
* @tc.desc: test ResetInfoUpdate
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ResetInfoUpdate001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ResetInfoUpdate001, Start");
int32_t adv = NON_ADV_ID;
ResetInfoUpdate(adv);
adv = CON_ADV_ID;
ResetInfoUpdate(adv);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ResetInfoUpdate001, End");
}
/*
* @tc.name: GetNeedUpdateAdvertiser001
* @tc.desc: test GetNeedUpdateAdvertiser
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetNeedUpdateAdvertiser001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetNeedUpdateAdvertiser001, Start");
int32_t adv = NON_ADV_ID;
ResetInfoUpdate(adv);
int ret = GetNeedUpdateAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_OK);
adv = CON_ADV_ID;
ResetInfoUpdate(CON_ADV_ID);
ret = GetNeedUpdateAdvertiser(CON_ADV_ID);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetNeedUpdateAdvertiser001, End");
}
/*
* @tc.name: BleAdvEnableCallback001
* @tc.desc: test BleAdvEnableCallback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleAdvEnableCallback001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvEnableCallback001, Start");
int32_t adv = NON_ADV_ID;
int status = SOFTBUS_BT_STATUS_SUCCESS;
BleAdvEnableCallback(adv, status);
adv = NUM_ADVERTISER;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvEnableCallback(adv, status);
adv = NON_ADV_ID;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvEnableCallback(adv, status);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvEnableCallback001, End");
}
/*
* @tc.name: BleAdvDisableCallback001
* @tc.desc: test BleAdvDisableCallback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleAdvDisableCallback001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvDisableCallback001, Start");
int32_t adv = NON_ADV_ID;
int status = SOFTBUS_BT_STATUS_SUCCESS;
BleAdvDisableCallback(adv, status);
adv = NUM_ADVERTISER;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvDisableCallback(adv, status);
adv = NON_ADV_ID;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvDisableCallback(adv, status);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvDisableCallback001, End");
}
/*
* @tc.name: BleAdvDataCallback001
* @tc.desc: test BleAdvDataCallback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleAdvDataCallback001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvDataCallback001, Start");
int32_t adv = NON_ADV_ID;
int status = SOFTBUS_BT_STATUS_SUCCESS;
BleAdvDataCallback(adv, status);
adv = NUM_ADVERTISER;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvDataCallback(adv, status);
adv = NON_ADV_ID;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvDataCallback(adv, status);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvDataCallback001, End");
}
/*
* @tc.name: BleAdvUpdateCallback001
* @tc.desc: test BleAdvUpdateCallback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleAdvUpdateCallback001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvUpdateCallback001, Start");
int32_t adv = NON_ADV_ID;
int status = SOFTBUS_BT_STATUS_SUCCESS;
BleAdvUpdateCallback(adv, status);
adv = NUM_ADVERTISER;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvUpdateCallback(adv, status);
adv = NON_ADV_ID;
status = SOFTBUS_BT_STATUS_BUSY;
BleAdvUpdateCallback(adv, status);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleAdvUpdateCallback001, End");
}
/*
* @tc.name: CheckScanner001
* @tc.desc: test CheckScanner
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, CheckScanner001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, CheckScanner001, Start");
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x0;
bool ret = CheckScanner();
EXPECT_EQ(ret, false);
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x1;
ret = CheckScanner();
EXPECT_EQ(ret, true);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, CheckScanner001, End");
}
/*
* @tc.name: ScanFilter001
* @tc.desc: test ScanFilter
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ScanFilter001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ScanFilter001, Start");
int32_t ret = ScanFilter(nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
unsigned char advDataTest[INT32_MAX_BIT_NUM];
unsigned char advLenTest = sizeof(advDataTest);
SoftBusBleScanResult scanResultDataTest{
.dataStatus = SOFTBUS_BLE_DATA_COMPLETE,
.advLen = advLenTest,
.advData = advDataTest,
};
scanResultDataTest.dataStatus = SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME;
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
scanResultDataTest.dataStatus = SOFTBUS_BLE_DATA_COMPLETE;
scanResultDataTest.advData[POS_UUID] = (unsigned char) BYTE_MASK;
scanResultDataTest.advData[POS_UUID + 1] = (unsigned char) ((BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK);
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
scanResultDataTest.advData[POS_UUID] = (unsigned char) (BLE_UUID & BYTE_MASK);
scanResultDataTest.advData[POS_UUID + 1] = (unsigned char) BYTE_MASK;
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
scanResultDataTest.advData[POS_UUID] = (unsigned char) BYTE_MASK;
scanResultDataTest.advData[POS_UUID + 1] = (unsigned char) BYTE_MASK;
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
scanResultDataTest.advData[POS_UUID] = (unsigned char) (BLE_UUID & BYTE_MASK);
scanResultDataTest.advData[POS_UUID + 1] = (unsigned char) ((BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK);
scanResultDataTest.advData[POS_VERSION + ADV_HEAD_LEN] = BLE_VERSION;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x0;
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x1;
ret = ScanFilter(&scanResultDataTest);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ScanFilter001, End");
}
/*
* @tc.name: ProcessDisConPacket001
* @tc.desc: test ProcessDisConPacket
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ProcessDisConPacket001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDisConPacket001, Start");
DeviceInfo foundInfoTest;
uint8_t advDataTest[100];
uint8_t advLenTest = sizeof(advDataTest);
ProcessDisConPacket(nullptr, advLenTest, &foundInfoTest);
foundInfoTest.capabilityBitmap[0] = 0x0;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x0;
ProcessDisConPacket(advDataTest, advLenTest, &foundInfoTest);
foundInfoTest.capabilityBitmap[0] = 0x1;
advDataTest[POS_CAPABLITY + ADV_HEAD_LEN] = 0x1;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x1;
ProcessDisConPacket(advDataTest, advLenTest, &foundInfoTest);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDisConPacket001, End");
}
/*
* @tc.name: ProcessHwHashAccout001
* @tc.desc: test ProcessHwHashAccout
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ProcessHwHashAccout001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessHwHashAccout001, Start");
uint32_t pos = 1;
DeviceInfo foundInfoTest;
foundInfoTest.capabilityBitmap[0] = 1 << pos;
foundInfoTest.capabilityBitmap[1] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isSameAccount[pos] = false;
bool ret = ProcessHwHashAccout(&foundInfoTest);
EXPECT_EQ(ret, true);
foundInfoTest.capabilityBitmap[0] = 1 << pos;
foundInfoTest.capabilityBitmap[1] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isSameAccount[pos] = true;
ret = ProcessHwHashAccout(&foundInfoTest);
EXPECT_EQ(ret, false);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessHwHashAccout001, End");
}
/*
* @tc.name: RangeDevice001
* @tc.desc: test RangeDevice
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, RangeDevice001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, RangeDevice001, Start");
static constexpr double DB_BASE = 10.0;
static constexpr double DB_COEFFICIENT = 20.0;
DeviceInfo foundInfoTest;
const char rssiTest = 's';
int8_t powerTest = SOFTBUS_ILLEGAL_BLE_POWER;
RangeDevice(&foundInfoTest, rssiTest, powerTest);
EXPECT_EQ(foundInfoTest.range, -1);
powerTest = 10;
foundInfoTest.devId[0] = 's';
RangeDevice(&foundInfoTest, rssiTest, powerTest);
EXPECT_EQ(foundInfoTest.range, (int32_t)pow(DB_BASE, rssiTest * -1 / DB_COEFFICIENT));
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, RangeDevice001, End");
}
/*
* @tc.name: ProcessDisNonPacket001
* @tc.desc: test ProcessDisNonPacket
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ProcessDisNonPacket001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDisNonPacket001, Start");
uint8_t advDataTest[100];
uint8_t advLenTest = sizeof(advDataTest);
const char rssiTest = 's';
DeviceInfo foundInfoTest;
ProcessDisNonPacket(nullptr, advLenTest, rssiTest, &foundInfoTest);
foundInfoTest.capabilityBitmap[0] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
ProcessDisNonPacket(advDataTest, advLenTest, rssiTest, &foundInfoTest);
g_discBleInnerCb = &g_discInnerCallback;
ListInit(&g_recvMessageInfo.node);
uint32_t pos = 0;
foundInfoTest.capabilityBitmap[0] = 1 << pos;
foundInfoTest.capabilityBitmap[1] = 0x0;
advDataTest[POS_CAPABLITY + ADV_HEAD_LEN] = 1 << pos;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isSameAccount[pos] = false;
ProcessDisNonPacket(advDataTest, advLenTest, rssiTest, &foundInfoTest);
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isSameAccount[pos] = true;
ProcessDisNonPacket(advDataTest, advLenTest, rssiTest, &foundInfoTest);
EXPECT_EQ(addtionsTest.medium, BLE);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDisNonPacket001, End");
}
/*
* @tc.name: BleScanResultCallback001
* @tc.desc: test BleScanResultCallback
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleScanResultCallback001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleScanResultCallback001, Start");
int listenerIdTest = 1;
BleScanResultCallback(listenerIdTest, nullptr);
uint8_t advDataTest[INT32_MAX_BIT_NUM];
uint8_t advLenTest = sizeof(advDataTest);
SoftBusBleScanResult scanResultDataTest = {
.dataStatus = SOFTBUS_BLE_DATA_COMPLETE,
.advLen = advLenTest,
.advData = advDataTest,
};
scanResultDataTest.dataStatus = SOFTBUS_BLE_DATA_COMPLETE;
scanResultDataTest.advData[POS_UUID] = (unsigned char) (BLE_UUID & BYTE_MASK);
scanResultDataTest.advData[POS_UUID + 1] = (unsigned char) ((BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK);
scanResultDataTest.advData[POS_VERSION + ADV_HEAD_LEN] = BLE_VERSION;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x1;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x1;
BleScanResultCallback(listenerIdTest, &scanResultDataTest);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleScanResultCallback001, End");
}
/*
* @tc.name: BleOnStateChanged001
* @tc.desc: test BleOnStateChanged
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BleOnStateChanged001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleOnStateChanged001, Start");
LooperInit();
DiscBleLooperInit();
int listenerIdTest = 1;
BleOnStateChanged(listenerIdTest, SOFTBUS_BT_STATE_TURN_ON);
BleOnStateChanged(listenerIdTest, SOFTBUS_BT_STATE_TURN_OFF);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BleOnStateChanged001, End");
}
/*
* @tc.name: GetWakeRemote001
* @tc.desc: test GetWakeRemote
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetWakeRemote001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetWakeRemote001, Start");
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isWakeRemote[0] = true;
GetWakeRemote();
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isWakeRemote[0] = false;
GetWakeRemote();
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetWakeRemote001, End");
}
/*
* @tc.name: GetConDeviceInfo001
* @tc.desc: test GetConDeviceInfo
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetConDeviceInfo001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetConDeviceInfo001, Start");
int32_t ret = GetConDeviceInfo(nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x0;
DeviceInfo foundInfoTest;
ret = GetConDeviceInfo(&foundInfoTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
ret = GetConDeviceInfo(&foundInfoTest);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetConDeviceInfo001, End");
}
/*
* @tc.name: ProcessDistributePacket001
* @tc.desc: test ProcessDistributePacket
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, ProcessDistributePacket001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDistributePacket001, Start");
uint8_t advDataTest[INT32_MAX_BIT_NUM];
uint8_t advLenTest = sizeof(advDataTest);
SoftBusBleScanResult scanResultDataTest = {
.dataStatus = SOFTBUS_BLE_DATA_COMPLETE,
.advLen = advLenTest,
.advData = advDataTest,
};
ProcessDistributePacket(&scanResultDataTest);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, ProcessDistributePacket001, End");
}
/*
* @tc.name: GetNonDeviceInfo001
* @tc.desc: test GetNonDeviceInfo
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetNonDeviceInfo001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetNonDeviceInfo001, Start");
int32_t ret = GetNonDeviceInfo(nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
DeviceInfo foundInfoTest;
g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].capBitMap[0] = 0x0;
ret = GetNonDeviceInfo(&foundInfoTest);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].capBitMap[0] = 0x1;
ret = GetNonDeviceInfo(&foundInfoTest);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetNonDeviceInfo001, End");
}
/*
* @tc.name: BuildBleConfigAdvData001
* @tc.desc: test BuildBleConfigAdvData
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, BuildBleConfigAdvData001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BuildBleConfigAdvData001, Start");
int32_t ret = BuildBleConfigAdvData(nullptr, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
SoftBusBleAdvData advDataTest {};
BoardcastData broadcastDataTest {};
broadcastDataTest.dataLen = ADV_DATA_MAX_LEN;
ret = BuildBleConfigAdvData(&advDataTest, &broadcastDataTest);
EXPECT_EQ(advDataTest.scanRspData[POS_RSP_TYPE], RSP_TYPE);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, BuildBleConfigAdvData001, End");
}
/*
* @tc.name: AssembleNonOptionalTlv001
* @tc.desc: test AssembleNonOptionalTlv
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, AssembleNonOptionalTlv001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, AssembleNonOptionalTlv001, Start");
DeviceInfo infoTest;
infoTest.range = 1;
BoardcastData broadcastDataTest {};
AssembleNonOptionalTlv(&infoTest, &broadcastDataTest);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, AssembleNonOptionalTlv001, End");
}
/*
* @tc.name: GetBroadcastData001
* @tc.desc: test GetBroadcastData
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetBroadcastData001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetBroadcastData001, Start");
int32_t ret = GetBroadcastData(nullptr, NUM_ADVERTISER, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
int32_t advId = CON_ADV_ID;
DeviceInfo infoTest {};
BoardcastData broadcastDataTest {};
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].isWakeRemote[0] = true;
ret = GetBroadcastData(&infoTest, advId, &broadcastDataTest);
EXPECT_EQ(ret, SOFTBUS_OK);
advId = NON_ADV_ID;
ret = GetBroadcastData(&infoTest, advId, &broadcastDataTest);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetBroadcastData001, End");
}
/*
* @tc.name: StartAdvertiser001
* @tc.desc: test StartAdvertiser
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, StartAdvertiser001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, StartAdvertiser001, Start");
InitAdvertiser();
int32_t adv = NON_ADV_ID;
g_bleAdvertiser[adv].isAdvertising = true;
g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].needUpdate = true;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].needUpdate = true;
int32_t ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleAdvertiser[adv].isAdvertising = true;
g_bleInfoManager[BLE_PUBLISH | BLE_ACTIVE].needUpdate = false;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].needUpdate = false;
ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleAdvertiser[adv].isAdvertising = false;
g_info = -1;
g_bleAdvertiser[adv].GetDeviceInfo = GetDeviceInfo;
g_bleAdvertiser[adv].advId = 0;
ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_OK);
g_info = 0;
ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleAdvertiser[adv].advId = 1;
ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_ERR);
g_bleAdvertiser[adv].advId = 2;
ret = StartAdvertiser(adv);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, StartAdvertiser001, End");
}
/*
* @tc.name: GetScannerParam001
* @tc.desc: test GetScannerParam
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, GetScannerParam001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetScannerParam001, Start");
constexpr int32_t FREQ = -1;
int32_t ret = GetScannerParam(FREQ, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, GetScannerParam001, End");
}
/*
* @tc.name: StartScaner001
* @tc.desc: test StartScaner
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, StartScaner001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, StartScaner001, Start");
for (uint32_t pos = 0; pos < CAPABILITY_MAX_BITNUM; pos++) {
for (uint32_t index = 0; index < BLE_INFO_COUNT; index++) {
g_bleInfoManager[index].freq[pos] = 0;
}
}
StartScaner();
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_SUBSCRIBE | BLE_PASSIVE].capBitMap[0] = 0x0;
g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0] = 0x0;
StartScaner();
g_bleInfoManager[BLE_SUBSCRIBE | BLE_ACTIVE].capBitMap[0] = 0x1;
g_isScanning = false;
StartScaner();
g_bleInfoManager[0].freq[0] = FREQ_BUTT;
StartScaner();
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, StartScaner001, End");
}
/*
* @tc.name: RegisterCapability001
* @tc.desc: test RegisterCapability
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusDiscBleTest, RegisterCapability001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, RegisterCapability001, Start");
uint8_t *capabilityDate = (uint8_t *)SoftBusMalloc(sizeof(uint8_t));
capabilityDate[0] = 'a';
SubscribeOption subscribeOption = {};
PublishOption publishOption = {
.ranging = true,
};
DiscBleInfo infoTest = {};
DiscBleOption optionTest = {
.publishOption = &publishOption,
.subscribeOption = &subscribeOption,
};
int32_t ret = RegisterCapability(nullptr, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = RegisterCapability(nullptr, &optionTest);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = RegisterCapability(&infoTest, nullptr);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
RegisterCapability(&infoTest, &optionTest);
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "SoftBusDiscBleTest, RegisterCapability001, End");
}
}

View File

@ -0,0 +1,63 @@
# Copyright (c) 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.
import("//build/lite/config/component/lite_component.gni")
import("//build/ohos.gni")
import("//build/test.gni")
import("//foundation/communication/dsoftbus/dsoftbus.gni")
module_output_path = "dsoftbus/discovery"
ohos_unittest("DiscoveryCoapDiscNstackxAdapterTest") {
module_out_path = module_output_path
sources = [ "disc_nstackx_adapter_test.cpp" ]
include_dirs = [
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/core/discovery/ble/dispatcher/include",
"//foundation/communication/dsoftbus/core/discovery/manager/include",
"//foundation/communication/dsoftbus/core/discovery/interface",
"//foundation/communication/dsoftbus/core/discovery/coap/include",
"//foundation/communication/dsoftbus/core/discovery/coap/src",
"//foundation/communication/dsoftbus/core/bus_center/interface",
"//foundation/communication/dsoftbus/core/bus_center/lnn/lane_hub/lane_manager/include",
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/adapter/default_config/spec_config",
"//foundation/communication/dsoftbus//core/common/dfx/hidumper_adapter/include",
"//third_party/cJSON",
]
deps = [
"//foundation/communication/dsoftbus/components/nstackx/nstackx_ctrl:nstackx_ctrl",
"//foundation/communication/dsoftbus/core/common:softbus_utils",
"//foundation/communication/dsoftbus/core/frame:softbus_server",
"//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 = [ ":DiscoveryCoapDiscNstackxAdapterTest" ]
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 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 <gtest/gtest.h>
#include <unistd.h>
#include "disc_nstackx_adapter.c"
using namespace testing::ext;
namespace OHOS {
class DiscNstackxAdapterTest : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
};
/*
* @tc.name: testParseServiceData001
* @tc.desc: test ParseServiceData
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscNstackxAdapterTest, testParseServiceData001, TestSize.Level1)
{
cJSON *jsonObject = cJSON_CreateObject();
bool ret = AddStringToJsonObject(jsonObject, JSON_SERVICE_DATA, "port:-10");
EXPECT_EQ(ret, true);
if (!ret) {
cJSON_Delete(jsonObject);
return;
}
DeviceInfo deviceInfo;
ParseServiceData(jsonObject, &deviceInfo);
cJSON_Delete(jsonObject);
}
}

View File

@ -79,7 +79,6 @@ static void TestDeviceFound(const DeviceInfo *device)
if (strcmp(g_addr1.info.ble.bleMac, g_addr.info.ble.bleMac) != 0) {
strcpy_s(g_addr1.info.ble.bleMac, BT_MAC_LEN, g_addr.info.ble.bleMac);
printf("[client]TestDeviceFound\r\n");
printf("account = %s\r\n", device->hwAccountHash);
g_state = true;
}
}
@ -234,4 +233,4 @@ HWTEST_F(DiscAccountTest, PublishServiceTest001, TestSize.Level0)
EXPECT_TRUE(ret == 0);
Wait();
};
}
}