1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include "bluetooth_ble_advertiser.h" 18 #include "bluetooth_ble_central_manager.h" 19 #include "bluetooth_host.h" 20 21 namespace OHOS { 22 namespace Bluetooth { 23 using namespace testing::ext; 24 25 class BleAdvertiseCallbackTest : public Bluetooth::BleAdvertiseCallback { 26 public: BleAdvertiseCallbackTest()27 BleAdvertiseCallbackTest(){}; ~BleAdvertiseCallbackTest()28 ~BleAdvertiseCallbackTest(){}; 29 30 private: OnStartResultEvent(int result,int advHandle)31 void OnStartResultEvent(int result, int advHandle) {} OnEnableResultEvent(int result,int advHandle)32 void OnEnableResultEvent(int result, int advHandle) {} OnDisableResultEvent(int result,int advHandle)33 void OnDisableResultEvent(int result, int advHandle) {} OnStopResultEvent(int result,int advHandle)34 void OnStopResultEvent(int result, int advHandle) {} OnSetAdvDataEvent(int result)35 void OnSetAdvDataEvent(int result) {} OnGetAdvHandleEvent(int result,int advHandle)36 void OnGetAdvHandleEvent(int result, int advHandle) {} 37 }; 38 39 class BleHostObserverTest : public Bluetooth::BluetoothHostObserver { 40 public: BleHostObserverTest()41 BleHostObserverTest(){}; ~BleHostObserverTest()42 ~BleHostObserverTest(){}; 43 44 private: 45 void OnStateChanged(const int transport, const int status); OnDiscoveryStateChanged(int status)46 void OnDiscoveryStateChanged(int status) 47 {} OnDiscoveryResult(const BluetoothRemoteDevice & device,int rssi,const std::string deviceName,int deviceClass)48 void OnDiscoveryResult( 49 const BluetoothRemoteDevice &device, int rssi, const std::string deviceName, int deviceClass) 50 {} OnPairRequested(const BluetoothRemoteDevice & device)51 void OnPairRequested(const BluetoothRemoteDevice &device) 52 {} OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)53 void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) 54 {} OnScanModeChanged(int mode)55 void OnScanModeChanged(int mode) 56 {} OnDeviceNameChanged(const std::string & device)57 void OnDeviceNameChanged(const std::string &device) 58 {} OnDeviceAddrChanged(const std::string & address)59 void OnDeviceAddrChanged(const std::string &address) 60 {} 61 }; 62 63 class BleCentralManagerCallbackTest : public Bluetooth::BleCentralManagerCallback { 64 public: BleCentralManagerCallbackTest()65 BleCentralManagerCallbackTest(){}; ~BleCentralManagerCallbackTest()66 ~BleCentralManagerCallbackTest(){}; 67 68 private: OnScanCallback(const Bluetooth::BleScanResult & result)69 void OnScanCallback(const Bluetooth::BleScanResult &result) 70 {} OnFoundOrLostCallback(const BleScanResult & result,uint8_t callbackType)71 void OnFoundOrLostCallback(const BleScanResult &result, uint8_t callbackType) 72 {} OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> & results)73 void OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> &results) 74 {} OnStartOrStopScanEvent(int resultCode,bool isStartScan)75 void OnStartOrStopScanEvent(int resultCode, bool isStartScan) 76 {} 77 }; 78 79 class BleTest : public testing::Test { 80 public: 81 BleTest(); 82 ~BleTest(); 83 84 Bluetooth::BluetoothHost *host_ = nullptr; 85 static BleTest *bleInstance_; 86 Bluetooth::BleAdvertiserSettings bleAdvertiserSettings_ {}; 87 BleCentralManagerCallbackTest bleCentralManagerCallbackTest_ {}; 88 BleAdvertiseCallbackTest bleAdvertiseCallbackTest_ {}; 89 std::shared_ptr<BleHostObserverTest> bleHostObserverTest_ = nullptr; 90 Bluetooth::BleScanSettings bleScanSettings_ {}; 91 92 static void SetUpTestCase(void); 93 static void TearDownTestCase(void); 94 void SetUp(); 95 void TearDown(); 96 97 void InitAdvertiseSettings(); 98 void InitScanSettings(); 99 bool HaveUuid(Bluetooth::BleAdvertiserData advData); 100 bool ManufacturerData(Bluetooth::BleAdvertiserData advData); 101 bool ServiceData(Bluetooth::BleAdvertiserData advData); 102 bool EnableBle(); 103 bool DisableBle(); 104 105 private: 106 bool isHaveUuid = false; 107 }; 108 } // namespace Bluetooth 109 } // namespace OHOS