mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 08:49:59 +00:00
fix:delete redundant code and fix ut
Signed-off-by: kevin <liufeihu@huawei.com>
This commit is contained in:
parent
8d6a515bfc
commit
b8e08ca425
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,6 @@
|
||||
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gap.h"
|
||||
#include "c_header/ohos_bt_gatt.h"
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_ADAPTER_BLE_GATT_H
|
||||
#define SOFTBUS_ADAPTER_BLE_GATT_H
|
||||
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// max adv and scan limit
|
||||
#define ADV_MAX_NUM 16
|
||||
#define SCAN_MAX_NUM 16
|
||||
|
||||
// Bluetooth scan duty cycle, unit: ms
|
||||
#define SOFTBUS_BLE_SCAN_INTERVAL_P2 3000
|
||||
#define SOFTBUS_BLE_SCAN_INTERVAL_P10 600
|
||||
#define SOFTBUS_BLE_SCAN_INTERVAL_P25 240
|
||||
#define SOFTBUS_BLE_SCAN_INTERVAL_P100 1000
|
||||
#define SOFTBUS_BLE_SCAN_WINDOW_P2 60
|
||||
#define SOFTBUS_BLE_SCAN_WINDOW_P10 60
|
||||
#define SOFTBUS_BLE_SCAN_WINDOW_P25 60
|
||||
#define SOFTBUS_BLE_SCAN_WINDOW_P100 1000
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
|
||||
SOFTBUS_BLE_EVT_CONNECTABLE = 0x01,
|
||||
SOFTBUS_BLE_EVT_SCANNABLE = 0x02,
|
||||
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
|
||||
SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05,
|
||||
SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED = 0x06,
|
||||
SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10,
|
||||
SOFTBUS_BLE_EVT_LEGACY_SCANNABLE = 0x12,
|
||||
SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE = 0x13,
|
||||
SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15,
|
||||
SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A,
|
||||
SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B
|
||||
} SoftBusBleScanResultEvtType;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS = 0x00,
|
||||
SOFTBUS_BLE_RANDOM_DEVICE_ADDRESS = 0x01,
|
||||
SOFTBUS_BLE_PUBLIC_IDENTITY_ADDRESS = 0x02,
|
||||
SOFTBUS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03,
|
||||
SOFTBUS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE,
|
||||
SOFTBUS_BLE_NO_ADDRESS = 0xFF,
|
||||
} SoftBusBleScanResultAddrType;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_SCAN_TYPE_PASSIVE = 0x00,
|
||||
SOFTBUS_BLE_SCAN_TYPE_ACTIVE,
|
||||
} SoftBusBleScanType;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_SCAN_PHY_NO_PACKET = 0x00,
|
||||
SOFTBUS_BLE_SCAN_PHY_1M = 0x01,
|
||||
SOFTBUS_BLE_SCAN_PHY_2M = 0x02,
|
||||
SOFTBUS_BLE_SCAN_PHY_CODED = 0x03
|
||||
} SoftBusBleScanResultPhyType;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00,
|
||||
SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST,
|
||||
SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA,
|
||||
SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA
|
||||
} SoftBusBleScanFilterPolicy;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_ADV_IND = 0x00,
|
||||
SOFTBUS_BLE_ADV_DIRECT_IND_HIGH = 0x01,
|
||||
SOFTBUS_BLE_ADV_SCAN_IND = 0x02,
|
||||
SOFTBUS_BLE_ADV_NONCONN_IND = 0x03,
|
||||
SOFTBUS_BLE_ADV_DIRECT_IND_LOW = 0x04,
|
||||
} SoftBusBleAdvType;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
|
||||
SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01,
|
||||
SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02,
|
||||
SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03,
|
||||
} SoftBusBleAdvFilter;
|
||||
|
||||
typedef struct {
|
||||
unsigned short scanInterval;
|
||||
unsigned short scanWindow;
|
||||
unsigned char scanType;
|
||||
unsigned char scanPhy;
|
||||
unsigned char scanFilterPolicy;
|
||||
} SoftBusBleScanParams;
|
||||
|
||||
typedef struct {
|
||||
char *address;
|
||||
char *deviceName;
|
||||
unsigned int serviceUuidLength;
|
||||
unsigned char *serviceUuid;
|
||||
unsigned char *serviceUuidMask;
|
||||
unsigned int serviceDataLength;
|
||||
unsigned char *serviceData;
|
||||
unsigned char *serviceDataMask;
|
||||
unsigned int manufactureDataLength;
|
||||
unsigned char *manufactureData;
|
||||
unsigned char *manufactureDataMask;
|
||||
unsigned short manufactureId;
|
||||
} SoftBusBleScanFilter;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_DATA_COMPLETE = 0x00,
|
||||
SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01,
|
||||
SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED = 0x02,
|
||||
} SoftBusScanResultDataStatus;
|
||||
|
||||
typedef struct {
|
||||
unsigned char eventType;
|
||||
unsigned char dataStatus;
|
||||
unsigned char addrType;
|
||||
SoftBusBtAddr addr;
|
||||
unsigned char primaryPhy;
|
||||
unsigned char secondaryPhy;
|
||||
unsigned char advSid;
|
||||
char txPower;
|
||||
char rssi;
|
||||
unsigned short periodicAdvInterval;
|
||||
unsigned char directAddrType;
|
||||
SoftBusBtAddr directAddr;
|
||||
unsigned char advLen;
|
||||
unsigned char *advData;
|
||||
char *deviceName;
|
||||
unsigned char rspDataLen;
|
||||
unsigned char *rspData;
|
||||
} SoftBusBleScanResult;
|
||||
|
||||
typedef struct {
|
||||
void (*OnScanStart)(int listenerId, int status);
|
||||
void (*OnScanStop)(int listenerId, int status);
|
||||
void (*OnScanResult)(int listenerId, const SoftBusBleScanResult *scanResultdata);
|
||||
void (*OnScanStateChanged)(int32_t resultCode, bool isStartScan);
|
||||
} SoftBusScanListener;
|
||||
|
||||
typedef struct {
|
||||
int minInterval;
|
||||
int maxInterval;
|
||||
unsigned char advType;
|
||||
unsigned char ownAddrType;
|
||||
unsigned char peerAddrType;
|
||||
SoftBusBtAddr peerAddr;
|
||||
int channelMap;
|
||||
unsigned char advFilterPolicy;
|
||||
int8_t txPower;
|
||||
int duration;
|
||||
} SoftBusBleAdvParams;
|
||||
|
||||
typedef struct {
|
||||
void (*AdvEnableCallback)(int advId, int status);
|
||||
void (*AdvDisableCallback)(int advId, int status);
|
||||
void (*AdvDataCallback)(int advId, int status);
|
||||
void (*AdvUpdateCallback)(int advId, int status);
|
||||
void (*LpDeviceInfoCallback)(SoftBusBtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize);
|
||||
} SoftBusAdvCallback;
|
||||
|
||||
int BleGattLockInit(void);
|
||||
|
||||
int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan);
|
||||
|
||||
int SoftBusRemoveScanListener(int listenerId);
|
||||
|
||||
int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize);
|
||||
|
||||
int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param);
|
||||
|
||||
int SoftBusStopScan(int listenerId, int scannerId);
|
||||
|
||||
int SoftBusStopScanImmediately(int listenerId, int scannerId);
|
||||
|
||||
int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan);
|
||||
|
||||
int SoftBusReleaseAdvChannel(int advId);
|
||||
|
||||
int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data);
|
||||
|
||||
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param);
|
||||
|
||||
int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
|
||||
int (*startAdvEx)(int *, const SoftBusBleAdvParams *, const SoftBusBleAdvData *));
|
||||
|
||||
int SoftBusStopAdv(int advId);
|
||||
|
||||
int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param);
|
||||
|
||||
int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data);
|
||||
|
||||
bool SoftBusIsLpDeviceAvailable(void);
|
||||
|
||||
bool SoftBusSetAdvFilterParam(int advHandle, int advId, SoftBusBleAdvParams *advParam,
|
||||
int listenerId, SoftBusBleScanParams *scanParam);
|
||||
|
||||
int32_t SoftBusGetAdvHandle(int32_t advId, int32_t *advHandle);
|
||||
|
||||
int32_t SoftBusEnableSyncDataToLpDevice(void);
|
||||
|
||||
int32_t SoftBusDisableSyncDataToLpDevice(void);
|
||||
|
||||
int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId);
|
||||
|
||||
int32_t SoftBusSetScanReportChannelToLpDevice(int32_t scannerId, bool enable);
|
||||
|
||||
int32_t SoftBusSetLpDeviceParam(int duration, int maxExtAdvEvents, int window,
|
||||
int interval, int advHandle);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* SOFTBUS_ADAPTER_BLE_GATT_H */
|
@ -23,7 +23,6 @@ adapter_ble_inc = [
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/adapter/ble/include",
|
||||
]
|
||||
adapter_ble_src = [
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_client.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/adapter_bt_utils.c",
|
||||
|
@ -34,9 +34,9 @@
|
||||
#include "lnn_net_builder.h"
|
||||
#include "lnn_ohos_account.h"
|
||||
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_broadcast_type.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_hisysevt_bus_center.h"
|
||||
@ -333,12 +333,12 @@ static void HbChangeMediumParamByState(SoftBusScreenState state)
|
||||
};
|
||||
switch (state) {
|
||||
case SOFTBUS_SCREEN_ON:
|
||||
param.info.ble.scanInterval = SOFTBUS_BLE_SCAN_INTERVAL_P10;
|
||||
param.info.ble.scanWindow = SOFTBUS_BLE_SCAN_WINDOW_P10;
|
||||
param.info.ble.scanInterval = SOFTBUS_BC_SCAN_INTERVAL_P10;
|
||||
param.info.ble.scanWindow = SOFTBUS_BC_SCAN_WINDOW_P10;
|
||||
break;
|
||||
case SOFTBUS_SCREEN_OFF:
|
||||
param.info.ble.scanInterval = SOFTBUS_BLE_SCAN_INTERVAL_P2;
|
||||
param.info.ble.scanWindow = SOFTBUS_BLE_SCAN_WINDOW_P2;
|
||||
param.info.ble.scanInterval = SOFTBUS_BC_SCAN_INTERVAL_P2;
|
||||
param.info.ble.scanWindow = SOFTBUS_BC_SCAN_WINDOW_P2;
|
||||
break;
|
||||
default:
|
||||
LNN_LOGD(LNN_HEART_BEAT, "ctrl reset ble scan medium param get invalid state");
|
||||
|
@ -74,6 +74,7 @@ if (dsoftbus_feature_lnn_net) {
|
||||
if (dsoftbus_feature_lnn_heartbeat) {
|
||||
bus_center_hub_inc += [
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/interface",
|
||||
"$dsoftbus_core_path/core/adapter/bus_center/include",
|
||||
"$dsoftbus_core_path/core/authentication/interface",
|
||||
"$dsoftbus_core_path/connection/p2p/interface",
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "lnn_ohos_account.h"
|
||||
#include "message_handler.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_crypto.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
@ -318,7 +317,7 @@ static int32_t ScanFilter(const BroadcastReportInfo *reportInfo)
|
||||
uint32_t advLen = reportInfo->packet.bcData.payloadLen;
|
||||
uint8_t *advData = reportInfo->packet.bcData.payload;
|
||||
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->dataStatus == SOFTBUS_BLE_DATA_COMPLETE, SOFTBUS_ERR, DISC_BLE,
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(reportInfo->dataStatus == SOFTBUS_BC_DATA_COMPLETE, SOFTBUS_ERR, DISC_BLE,
|
||||
"dataStatus is invalid. dataStatus=%{public}u", reportInfo->dataStatus);
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advData != NULL, SOFTBUS_ERR, DISC_BLE, "advData is null");
|
||||
DISC_CHECK_AND_RETURN_RET_LOGE(advLen >= POS_TLV, SOFTBUS_ERR, DISC_BLE,
|
||||
@ -1762,7 +1761,7 @@ DiscoveryBleDispatcherInterface *DiscSoftBusBleInit(DiscInnerCallback *callback)
|
||||
g_discBleInnerCb = callback;
|
||||
|
||||
if (SoftBusMutexInit(&g_recvMessageInfo.lock, NULL) != SOFTBUS_OK ||
|
||||
SoftBusMutexInit(&g_bleInfoLock, NULL) != SOFTBUS_OK || BleGattLockInit() != SOFTBUS_OK) {
|
||||
SoftBusMutexInit(&g_bleInfoLock, NULL) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_INIT, "init ble lock failed");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -45,16 +45,6 @@ if (!defined(ohos_lite)) {
|
||||
bt_test_external_deps += [ "bluetooth:btframework" ]
|
||||
}
|
||||
|
||||
ohos_unittest("AdapterBleGattTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = bt_test_sources
|
||||
sources += [ "softbus_adapter_ble_gatt_test.cpp" ]
|
||||
|
||||
include_dirs = bt_test_inc
|
||||
deps = bt_test_deps
|
||||
external_deps = bt_test_external_deps
|
||||
}
|
||||
|
||||
ohos_unittest("AdapterBleGattServerTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = bt_test_sources
|
||||
@ -103,7 +93,6 @@ if (!defined(ohos_lite)) {
|
||||
deps += [
|
||||
# ":AdapterBleGattClientTest",
|
||||
# ":AdapterBleGattServerTest",
|
||||
# ":AdapterBleGattTest",
|
||||
# ":AdapterBtCommonTest",
|
||||
# ":AdapterBtUtilsTest",
|
||||
]
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_ble_gatt_client.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
|
@ -1,620 +0,0 @@
|
||||
/*
|
||||
* 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 "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "c_header/ohos_bt_gatt.h"
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "conn_log.h"
|
||||
#include "assert_helper.h"
|
||||
#include "bluetooth_mock.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using ::testing::AtMost;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
class ScanResultCtx : public RecordCtx {
|
||||
public:
|
||||
explicit ScanResultCtx(const char *identifier);
|
||||
~ScanResultCtx();
|
||||
bool Update(int id, const SoftBusBleScanResult *scanResult);
|
||||
testing::AssertionResult Expect(int id, const SoftBusBleScanResult *scanResult);
|
||||
private:
|
||||
SoftBusBleScanResult scanResult;
|
||||
void Reset();
|
||||
};
|
||||
|
||||
class AdapterBleGattTest : public testing::Test {
|
||||
public:
|
||||
static StRecordCtx scanStartCtx;
|
||||
static StRecordCtx scanStopCtx;
|
||||
static ScanResultCtx scanResultCtx;
|
||||
|
||||
static StRecordCtx advEnableCtx;
|
||||
static StRecordCtx advDisableCtx;
|
||||
static StRecordCtx advDataCtx;
|
||||
static StRecordCtx advUpdateCtx;
|
||||
// btInnerAdvId 模拟蓝牙生成的广播id
|
||||
static int btInnerAdvId;
|
||||
|
||||
static void SetUpTestCase(void);
|
||||
};
|
||||
|
||||
StRecordCtx AdapterBleGattTest::scanStartCtx("OnScanStart");
|
||||
StRecordCtx AdapterBleGattTest::scanStopCtx("OnScanStop");
|
||||
ScanResultCtx AdapterBleGattTest::scanResultCtx("OnScanResult");
|
||||
|
||||
StRecordCtx AdapterBleGattTest::advEnableCtx("AdvEnableCallback");
|
||||
StRecordCtx AdapterBleGattTest::advDisableCtx("AdvDisableCallback");
|
||||
StRecordCtx AdapterBleGattTest::advDataCtx("AdvDataCallback");
|
||||
StRecordCtx AdapterBleGattTest::advUpdateCtx("AdvUpdateCallback");
|
||||
int AdapterBleGattTest::btInnerAdvId = -1;
|
||||
|
||||
void AdapterBleGattTest::SetUpTestCase()
|
||||
{
|
||||
BleGattLockInit();
|
||||
}
|
||||
|
||||
static void StubOnScanStart(int listenerId, int status)
|
||||
{
|
||||
AdapterBleGattTest::scanStartCtx.Update(listenerId, status);
|
||||
}
|
||||
|
||||
static void StubOnScanStop(int listenerId, int status)
|
||||
{
|
||||
AdapterBleGattTest::scanStopCtx.Update(listenerId, status);
|
||||
}
|
||||
|
||||
static void StubOnScanResult(int listenerId, const SoftBusBleScanResult *scanResultdata)
|
||||
{
|
||||
AdapterBleGattTest::scanResultCtx.Update(listenerId, scanResultdata);
|
||||
}
|
||||
|
||||
SoftBusScanListener *GetStubScanListener()
|
||||
{
|
||||
static SoftBusScanListener listener = {
|
||||
.OnScanStart = StubOnScanStart,
|
||||
.OnScanStop = StubOnScanStop,
|
||||
.OnScanResult = StubOnScanResult,
|
||||
.OnScanStateChanged = NULL
|
||||
};
|
||||
return &listener;
|
||||
}
|
||||
|
||||
static void StubAdvEnableCallback(int advId, int status)
|
||||
{
|
||||
AdapterBleGattTest::advEnableCtx.Update(advId, status);
|
||||
}
|
||||
|
||||
static void StubAdvDisableCallback(int advId, int status)
|
||||
{
|
||||
AdapterBleGattTest::advDisableCtx.Update(advId, status);
|
||||
}
|
||||
|
||||
static void StubAdvDataCallback(int advId, int status)
|
||||
{
|
||||
AdapterBleGattTest::advDataCtx.Update(advId, status);
|
||||
}
|
||||
|
||||
static void StubAdvUpdateCallback(int advId, int status)
|
||||
{
|
||||
AdapterBleGattTest::advUpdateCtx.Update(advId, status);
|
||||
}
|
||||
|
||||
// Notice:考虑到BleStartAdvEx的回调需要异步触发,实现会导致专注点不在用来本身。这里不手动mock,
|
||||
// !!!IMPORANT: 一定需要手动触发成功回调,否则回导致adapter状态异常!!!
|
||||
static int ActionSuccessBleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advParam)
|
||||
{
|
||||
static int advIdGenerator = 0;
|
||||
*advId = advIdGenerator++;
|
||||
AdapterBleGattTest::btInnerAdvId = *advId;
|
||||
return OHOS_BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static int ActionSuccessBleStopAdv(int advId)
|
||||
{
|
||||
MockBluetooth::btGattCallback->advDisableCb(advId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
return OHOS_BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SoftBusAdvCallback *GetStubAdvCallback()
|
||||
{
|
||||
static SoftBusAdvCallback callback = {.AdvEnableCallback = StubAdvEnableCallback,
|
||||
.AdvDisableCallback = StubAdvDisableCallback,
|
||||
.AdvDataCallback = StubAdvDataCallback,
|
||||
.AdvUpdateCallback = StubAdvUpdateCallback,
|
||||
.LpDeviceInfoCallback = NULL};
|
||||
return &callback;
|
||||
}
|
||||
|
||||
static testing::AssertionResult PrepareScanListener(MockBluetooth &mocker, int *outId, int *scannerId)
|
||||
{
|
||||
auto id = SoftBusAddScanListener(GetStubScanListener(), scannerId, false);
|
||||
if (id == SOFTBUS_ERR) {
|
||||
return testing::AssertionFailure() << "SoftBusAddScanListener failed";
|
||||
}
|
||||
if (MockBluetooth::btGattCallback == nullptr) {
|
||||
return testing::AssertionFailure() << "BleGattRegisterCallbacks is not invoke";
|
||||
}
|
||||
*outId = id;
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
static testing::AssertionResult PrepareAdvCallback(MockBluetooth &mocker, int *outId, int *scannerId)
|
||||
{
|
||||
EXPECT_CALL(mocker, BleStartAdvEx).WillRepeatedly(ActionSuccessBleStartAdvEx);
|
||||
EXPECT_CALL(mocker, BleStopAdv).WillRepeatedly(ActionSuccessBleStopAdv);
|
||||
auto id = SoftBusGetAdvChannel(GetStubAdvCallback(), scannerId, false);
|
||||
if (id == SOFTBUS_ERR) {
|
||||
return testing::AssertionFailure() << "GetStubAdvCallback failed";
|
||||
}
|
||||
if (MockBluetooth::btGattCallback == nullptr) {
|
||||
return testing::AssertionFailure() << "BleGattRegisterCallbacks is not invoke";
|
||||
}
|
||||
*outId = id;
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
static SoftBusBleScanFilter *CreateScanFilter()
|
||||
{
|
||||
unsigned char serviceData[] = {0xE, 0xE, 0xF, 0xF, 0x04, 0x05};
|
||||
int len = sizeof(serviceData);
|
||||
|
||||
SoftBusBleScanFilter *filter = (SoftBusBleScanFilter *)SoftBusCalloc(sizeof(SoftBusBleScanFilter));
|
||||
unsigned char *serviceDataPtr = (unsigned char *)SoftBusCalloc(len);
|
||||
unsigned char *serviceDataMaskPtr = (unsigned char *)SoftBusCalloc(len);
|
||||
if (filter == nullptr || serviceDataPtr == nullptr || serviceDataMaskPtr == nullptr) {
|
||||
goto EXIT;
|
||||
}
|
||||
if (memcpy_s(serviceDataPtr, len, serviceData, len) != EOK) {
|
||||
goto EXIT;
|
||||
}
|
||||
if (memset_s(serviceDataMaskPtr, len, 0xFF, len) != EOK) {
|
||||
goto EXIT;
|
||||
}
|
||||
filter->serviceData = serviceDataPtr;
|
||||
filter->serviceDataMask = serviceDataMaskPtr;
|
||||
filter->serviceDataLength = len;
|
||||
return filter;
|
||||
EXIT:
|
||||
SoftBusFree(filter);
|
||||
SoftBusFree(serviceDataPtr);
|
||||
SoftBusFree(serviceDataMaskPtr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_SoftBusAddScanListener
|
||||
* @tc.desc: test add scan listener
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusAddScanListener, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int scannerId = -1;
|
||||
ASSERT_EQ(SoftBusAddScanListener(nullptr, &scannerId, false), SOFTBUS_ERR);
|
||||
|
||||
int scanListerIds[SCAN_MAX_NUM];
|
||||
for (size_t i = 0; i < SCAN_MAX_NUM; i++) {
|
||||
scanListerIds[i] = SoftBusAddScanListener(GetStubScanListener(), &scannerId, false);
|
||||
ASSERT_NE(scanListerIds[i], SOFTBUS_ERR);
|
||||
}
|
||||
|
||||
ASSERT_EQ(SoftBusAddScanListener(GetStubScanListener(), &scannerId, false), SOFTBUS_ERR);
|
||||
|
||||
for (size_t i = 0; i < SCAN_MAX_NUM; i++) {
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(scanListerIds[i]), SOFTBUS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_SoftBusRemoveScanListener
|
||||
* @tc.desc: test remove scan listener
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusRemoveScanListener, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(-1), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(SCAN_MAX_NUM), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(listenerId), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_SoftBusSetScanFilter
|
||||
* @tc.desc: test set scan filter
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusSetScanFilter, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
ASSERT_NE(filter, nullptr);
|
||||
|
||||
ASSERT_EQ(SoftBusSetScanFilter(listenerId, nullptr, 0), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusSetScanFilter(listenerId, filter, 0), SOFTBUS_INVALID_PARAM);
|
||||
|
||||
// not exist scaner
|
||||
ASSERT_EQ(SoftBusSetScanFilter(SCAN_MAX_NUM - 1, filter, 1), SOFTBUS_ERR);
|
||||
ASSERT_EQ(SoftBusSetScanFilter(listenerId, filter, 1), SOFTBUS_OK);
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(listenerId), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_ScanLifecycle
|
||||
* @tc.desc: test complete scan life cycle
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, ScanLifecycle, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
ASSERT_NE(filter, nullptr);
|
||||
auto ret = SoftBusSetScanFilter(listenerId, filter, 1);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
|
||||
SoftBusBleScanParams scanParam = {
|
||||
.scanInterval = 60,
|
||||
.scanWindow = 600,
|
||||
.scanType = 1,
|
||||
.scanPhy = 1,
|
||||
.scanFilterPolicy = 0,
|
||||
};
|
||||
|
||||
EXPECT_CALL(mocker, BleStartScanEx).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStartScan(listenerId, scannerId, &scanParam);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStartCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
const unsigned char scanDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00,
|
||||
0x04, 0x00, 0x18, 0x33, 0x39, 0x36, 0x62, 0x33, 0x61, 0x33, 0x31, 0x21, 0x00, 0x02, 0x0A, 0xEF, 0x03, 0xFF,
|
||||
0x7D, 0x02};
|
||||
BtScanResultData mockScanResult = {0};
|
||||
mockScanResult.advLen = sizeof(scanDataExample);
|
||||
mockScanResult.advData = (unsigned char *)scanDataExample;
|
||||
|
||||
|
||||
SoftBusBleScanResult expectScanResult = {0};
|
||||
expectScanResult.advLen = sizeof(scanDataExample);
|
||||
expectScanResult.advData = (unsigned char *)scanDataExample;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
EXPECT_CALL(mocker, BleStopScan).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStopScan(listenerId, scannerId);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStopCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(listenerId), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_SoftBusStopScanImmediately
|
||||
* @tc.desc: test stop ble scan immediately
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusStopScanImmediately, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
ASSERT_NE(filter, nullptr);
|
||||
auto ret = SoftBusSetScanFilter(listenerId, filter, 1);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
|
||||
SoftBusBleScanParams scanParam = {
|
||||
.scanInterval = 60,
|
||||
.scanWindow = 600,
|
||||
.scanType = 1,
|
||||
.scanPhy = 1,
|
||||
.scanFilterPolicy = 0,
|
||||
};
|
||||
|
||||
EXPECT_CALL(mocker, BleStartScanEx).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStartScan(listenerId, scannerId, &scanParam);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStartCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
const unsigned char scanDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00,
|
||||
0x04, 0x00, 0x18, 0x33, 0x39, 0x36, 0x62, 0x33, 0x61, 0x33, 0x31, 0x21, 0x00, 0x02, 0x0A, 0xEF, 0x03, 0xFF,
|
||||
0x7D, 0x02};
|
||||
BtScanResultData mockScanResult = {0};
|
||||
mockScanResult.advLen = sizeof(scanDataExample);
|
||||
mockScanResult.advData = (unsigned char *)scanDataExample;
|
||||
|
||||
SoftBusBleScanResult expectScanResult = {0};
|
||||
expectScanResult.advLen = sizeof(scanDataExample);
|
||||
expectScanResult.advData = (unsigned char *)scanDataExample;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
EXPECT_CALL(mocker, BleStopScan).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStopScanImmediately(listenerId, scannerId);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStopCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(listenerId), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_ScanResultCb
|
||||
* @tc.desc: test scan result callback
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
ASSERT_NE(filter, nullptr);
|
||||
auto ret = SoftBusSetScanFilter(listenerId, filter, 1);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
|
||||
SoftBusBleScanParams scanParam = {
|
||||
.scanInterval = 60,
|
||||
.scanWindow = 600,
|
||||
.scanType = 1,
|
||||
.scanPhy = 1,
|
||||
.scanFilterPolicy = 0,
|
||||
};
|
||||
EXPECT_CALL(mocker, BleStartScanEx).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, scannerId, nullptr), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, scannerId, &scanParam), SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStartCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
const unsigned char scanDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00,
|
||||
0x04, 0x00, 0x18, 0x33, 0x39, 0x36, 0x62, 0x33, 0x61, 0x33, 0x31, 0x21, 0x00, 0x02, 0x0A, 0xEF, 0x03, 0xFF,
|
||||
0x7D, 0x02};
|
||||
SoftBusBleScanResult expectScanResult = {0};
|
||||
expectScanResult.advLen = sizeof(scanDataExample);
|
||||
expectScanResult.advData = (unsigned char *)scanDataExample;
|
||||
BtScanResultData mockScanResult = {0};
|
||||
mockScanResult.advLen = sizeof(scanDataExample);
|
||||
mockScanResult.advData = (unsigned char *)scanDataExample;
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
mockScanResult.dataStatus = OHOS_BLE_DATA_COMPLETE;
|
||||
mockScanResult.addrType = OHOS_BLE_PUBLIC_DEVICE_ADDRESS;
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
|
||||
mockScanResult.directAddrType = OHOS_BLE_PUBLIC_DEVICE_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
|
||||
mockScanResult.dataStatus = OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME;
|
||||
mockScanResult.addrType = OHOS_BLE_RANDOM_DEVICE_ADDRESS;
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_1M;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_1M;
|
||||
mockScanResult.directAddrType = OHOS_BLE_RANDOM_DEVICE_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_CONNECTABLE;
|
||||
mockScanResult.dataStatus = OHOS_BLE_DATA_INCOMPLETE_TRUNCATED;
|
||||
mockScanResult.addrType = OHOS_BLE_PUBLIC_IDENTITY_ADDRESS;
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_2M;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_2M;
|
||||
mockScanResult.directAddrType = OHOS_BLE_PUBLIC_IDENTITY_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_CONNECTABLE_DIRECTED;
|
||||
mockScanResult.dataStatus = UINT8_MAX;
|
||||
mockScanResult.addrType = OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS;
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_CODED;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_CODED;
|
||||
mockScanResult.directAddrType = OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_SCANNABLE;
|
||||
mockScanResult.addrType = OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
|
||||
mockScanResult.primaryPhy = UINT8_MAX;
|
||||
mockScanResult.secondaryPhy = UINT8_MAX;
|
||||
mockScanResult.directAddrType = OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_SCANNABLE_DIRECTED;
|
||||
mockScanResult.addrType = OHOS_BLE_NO_ADDRESS;
|
||||
mockScanResult.directAddrType = OHOS_BLE_NO_ADDRESS;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE;
|
||||
mockScanResult.addrType = UINT8_MAX;
|
||||
mockScanResult.directAddrType = UINT8_MAX;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCANNABLE;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_CONNECTABLE;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = UINT8_MAX;
|
||||
ASSERT_FALSE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_AdvertiseLifecycle
|
||||
* @tc.desc: test complete Advertisement life cycle
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, AdvertiseLifecycle, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int advId = 0;
|
||||
int scannerId = -1;
|
||||
auto result = PrepareAdvCallback(mocker, &advId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
const char advDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00, 0x04, 0x00,
|
||||
0x18, 0x33, 0x39, 0x36, 0x62, 0x33, 0x61, 0x33, 0x31, 0x21, 0x00, 0x02, 0x0A, 0xEF};
|
||||
const unsigned char scanRspDataExample[] = {0x03, 0xFF, 0x7D, 0x02};
|
||||
SoftBusBleAdvData data = {.advLength = sizeof(advDataExample),
|
||||
.advData = (uint8_t *)advDataExample,
|
||||
.scanRspLength = sizeof(scanRspDataExample),
|
||||
.scanRspData = (uint8_t *)scanRspDataExample};
|
||||
ASSERT_EQ(SoftBusSetAdvData(advId, &data), SOFTBUS_OK);
|
||||
ASSERT_TRUE(advDataCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
SoftBusBleAdvParams params = {0};
|
||||
ASSERT_EQ(SoftBusStartAdv(advId, ¶ms), SOFTBUS_OK);
|
||||
ASSERT_FALSE(advEnableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
// 模拟蓝牙广播成功回调, 广播成功会被再次回调, adapter状态才能恢复正常
|
||||
MockBluetooth::btGattCallback->advEnableCb(btInnerAdvId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
ASSERT_TRUE(advEnableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
MockBluetooth::btGattCallback->advDataCb(btInnerAdvId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
ASSERT_TRUE(advDataCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
ASSERT_EQ(SoftBusUpdateAdv(advId, nullptr, ¶ms), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusUpdateAdv(advId, &data, nullptr), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusUpdateAdv(advId, &data, ¶ms), SOFTBUS_OK);
|
||||
ASSERT_FALSE(advEnableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
ASSERT_TRUE(advDisableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
// 模拟蓝牙广播成功回调, 广播成功会被再次回调, adapter状态才能恢复正常
|
||||
MockBluetooth::btGattCallback->advEnableCb(btInnerAdvId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
ASSERT_TRUE(advEnableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
MockBluetooth::btGattCallback->advUpdateCb(btInnerAdvId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
ASSERT_TRUE(advUpdateCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
MockBluetooth::btGattCallback->securityRespondCb(nullptr);
|
||||
|
||||
ASSERT_EQ(SoftBusStopAdv(advId), SOFTBUS_OK);
|
||||
ASSERT_TRUE(advDisableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(advId), SOFTBUS_OK);
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(advId), SOFTBUS_ERR);
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(-1), SOFTBUS_ERR);
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(ADV_MAX_NUM), SOFTBUS_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AdapterBleGattTest_SoftBusGetAdvChannel
|
||||
* @tc.desc: test get adv channel
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NONE
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusGetAdvChannel, TestSize.Level3)
|
||||
{
|
||||
int scannerId = -1;
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(nullptr, &scannerId, false), SOFTBUS_INVALID_PARAM);
|
||||
MockBluetooth mocker;
|
||||
int advIds[ADV_MAX_NUM];
|
||||
for (size_t i = 0; i < ADV_MAX_NUM; i++) {
|
||||
advIds[i] = SoftBusGetAdvChannel(GetStubAdvCallback(), &scannerId, false);
|
||||
ASSERT_NE(advIds[i], SOFTBUS_ERR);
|
||||
}
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(GetStubAdvCallback(), &scannerId, false), SOFTBUS_ERR);
|
||||
for (size_t i = 0; i < ADV_MAX_NUM; i++) {
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(advIds[i]), SOFTBUS_OK);
|
||||
}
|
||||
}
|
||||
|
||||
ScanResultCtx::ScanResultCtx(const char *identifier) : RecordCtx(identifier)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
ScanResultCtx::~ScanResultCtx()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void ScanResultCtx::Reset()
|
||||
{
|
||||
SoftBusFree(scanResult.advData);
|
||||
scanResult.advData = nullptr;
|
||||
memset_s(&scanResult, sizeof(SoftBusBtAddr), 0, sizeof(SoftBusBtAddr));
|
||||
}
|
||||
|
||||
bool ScanResultCtx::Update(int id, const SoftBusBleScanResult *scanResult)
|
||||
{
|
||||
if (!RecordCtx::Update(id)) {
|
||||
return false;
|
||||
}
|
||||
this->scanResult = *scanResult;
|
||||
unsigned char *cpyAdvData = (unsigned char *)SoftBusCalloc(this->scanResult.advLen);
|
||||
if (cpyAdvData == nullptr) {
|
||||
CONN_LOGE(CONN_BLE, "malloc failed in OnScanResult, can not save ctx, id=%{public}d", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(cpyAdvData, this->scanResult.advLen, scanResult->advData, scanResult->advLen) != EOK) {
|
||||
CONN_LOGE(CONN_BLE, "malloc failed in OnScanResult, can not save ctx, id=%{public}d", id);
|
||||
SoftBusFree(cpyAdvData);
|
||||
return false;
|
||||
}
|
||||
this->scanResult.advData = cpyAdvData;
|
||||
return true;
|
||||
}
|
||||
|
||||
testing::AssertionResult ScanResultCtx::Expect(int id, const SoftBusBleScanResult *scanResultParam)
|
||||
{
|
||||
auto result = RecordCtx::Expect(id);
|
||||
if (!result) {
|
||||
goto ClEANUP;
|
||||
}
|
||||
|
||||
if (this->scanResult.advLen == scanResultParam->advLen &&
|
||||
memcmp(this->scanResult.advData, scanResultParam->advData, scanResultParam->advLen) == 0) {
|
||||
result = testing::AssertionSuccess();
|
||||
goto ClEANUP;
|
||||
}
|
||||
result = testing::AssertionFailure() << identifier << " is call by unexpectedly scan result.";
|
||||
ClEANUP:
|
||||
Reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace OHOS
|
@ -1669,6 +1669,7 @@ if (!defined(ohos_lite) && enhanced_test) {
|
||||
"$dsoftbus_root_path/core/bus_center/service/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
|
||||
"$dsoftbus_root_path/adapter/common/net/bluetooth/broadcast/interface",
|
||||
]
|
||||
include_dirs += bus_center_decision_center_inc
|
||||
|
||||
|
@ -138,13 +138,12 @@ HWTEST_F(DiscDistributedBleTest, TestScanFilter001, TestSize.Level1)
|
||||
|
||||
BroadcastReportInfo reportInfo = {0};
|
||||
|
||||
// when not reportInfo->dataStatus == SOFTBUS_BLE_DATA_COMPLETE
|
||||
reportInfo.dataStatus = SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME;
|
||||
reportInfo.dataStatus = SOFTBUS_BC_DATA_INCOMPLETE_MORE_TO_COME;
|
||||
int32_t ret = ScanFilter(&reportInfo);
|
||||
EXPECT_NE(ret, SOFTBUS_OK);
|
||||
|
||||
// when not advData != NULL
|
||||
reportInfo.dataStatus = SOFTBUS_BLE_DATA_COMPLETE;
|
||||
reportInfo.dataStatus = SOFTBUS_BC_DATA_COMPLETE;
|
||||
ret = ScanFilter(&reportInfo);
|
||||
EXPECT_NE(ret, SOFTBUS_OK);
|
||||
|
||||
@ -184,7 +183,7 @@ HWTEST_F(DiscDistributedBleTest, TestScanFilter002, TestSize.Level1)
|
||||
|
||||
uint8_t payload[POS_TLV] = {0};
|
||||
BroadcastReportInfo reportInfo = {
|
||||
.dataStatus = SOFTBUS_BLE_DATA_COMPLETE,
|
||||
.dataStatus = SOFTBUS_BC_DATA_COMPLETE,
|
||||
.packet = {
|
||||
.bcData = {
|
||||
.payload = &payload[0],
|
||||
@ -244,7 +243,7 @@ HWTEST_F(DiscDistributedBleTest, TestScanFilter003, TestSize.Level1)
|
||||
|
||||
uint8_t payload[POS_TLV] = {0};
|
||||
BroadcastReportInfo reportInfo = {
|
||||
.dataStatus = SOFTBUS_BLE_DATA_COMPLETE,
|
||||
.dataStatus = SOFTBUS_BC_DATA_COMPLETE,
|
||||
.packet = {
|
||||
.bcData = {
|
||||
.payload = &payload[0],
|
||||
@ -471,7 +470,7 @@ HWTEST_F(DiscDistributedBleTest, TestStopScaner001, TestSize.Level1)
|
||||
EXPECT_EQ(ret, SOFTBUS_OK);
|
||||
|
||||
g_isScanning = true;
|
||||
g_bleListener.scanListenerId = SCAN_MAX_NUM;
|
||||
g_bleListener.scanListenerId = SCAN_NUM_MAX;
|
||||
ret = StopScaner();
|
||||
EXPECT_NE(ret, SOFTBUS_OK);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,11 +25,6 @@ using testing::_;
|
||||
using testing::NotNull;
|
||||
|
||||
/* implement related global function of BLE */
|
||||
int BleGattLockInit()
|
||||
{
|
||||
return BleMock::GetMock()->BleGattLockInit();
|
||||
}
|
||||
|
||||
int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusAddBtStateListener(listener);
|
||||
@ -127,11 +122,6 @@ BleMock::~BleMock()
|
||||
mock.store(nullptr);
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfBleGattLockInit()
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfInitBroadcastMgr()
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
@ -476,7 +466,6 @@ bool BleMock::IsDeInitSuccess()
|
||||
|
||||
void BleMock::SetupSuccessStub()
|
||||
{
|
||||
EXPECT_CALL(*this, BleGattLockInit).WillRepeatedly(BleMock::ActionOfBleGattLockInit);
|
||||
EXPECT_CALL(*this, InitBroadcastMgr).WillRepeatedly(BleMock::ActionOfInitBroadcastMgr);
|
||||
EXPECT_CALL(*this, DeInitBroadcastMgr).WillRepeatedly(BleMock::ActionOfDeInitBroadcastMgr);
|
||||
EXPECT_CALL(*this, SoftBusGetBtState).WillRepeatedly(BleMock::ActionOfGetBtState);
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <gmock/gmock.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_ble_gatt_client.h"
|
||||
#include "softbus_adapter_ble_gatt_server.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
@ -30,7 +29,6 @@
|
||||
|
||||
class BleInterface {
|
||||
public:
|
||||
virtual int BleGattLockInit() = 0;
|
||||
virtual int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener) = 0;
|
||||
virtual int SoftBusRemoveBtStateListener(int listenerId) = 0;
|
||||
|
||||
@ -68,7 +66,6 @@ public:
|
||||
BleMock();
|
||||
~BleMock();
|
||||
|
||||
MOCK_METHOD(int, BleGattLockInit, (), (override));
|
||||
MOCK_METHOD(int, SoftBusAddBtStateListener, (const SoftBusBtStateListener *listener), (override));
|
||||
MOCK_METHOD(int, SoftBusRemoveBtStateListener, (int listenerId), (override));
|
||||
MOCK_METHOD(int32_t, InitBroadcastMgr, (), (override));
|
||||
@ -98,7 +95,6 @@ public:
|
||||
bool GetAsyncAdvertiseResult();
|
||||
bool IsScanning();
|
||||
|
||||
static int32_t ActionOfBleGattLockInit();
|
||||
static int32_t ActionOfAddBtStateListener(const SoftBusBtStateListener *listener);
|
||||
static int32_t ActionOfRemoveBtStateListener(int listenerId);
|
||||
static int32_t ActionOfInitBroadcastMgr();
|
||||
|
Loading…
Reference in New Issue
Block a user