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: 31 void OnStartResultEvent(int result); 32 }; 33 34 class BleHostObserverTest : public Bluetooth::BluetoothHostObserver { 35 public: BleHostObserverTest()36 BleHostObserverTest(){}; ~BleHostObserverTest()37 ~BleHostObserverTest(){}; 38 39 private: 40 void OnStateChanged(const int transport, const int status); OnDiscoveryStateChanged(int status)41 void OnDiscoveryStateChanged(int status) 42 {} OnDiscoveryResult(const BluetoothRemoteDevice & device)43 void OnDiscoveryResult(const BluetoothRemoteDevice &device) 44 {} OnPairRequested(const BluetoothRemoteDevice & device)45 void OnPairRequested(const BluetoothRemoteDevice &device) 46 {} OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)47 void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) 48 {} OnScanModeChanged(int mode)49 void OnScanModeChanged(int mode) 50 {} OnDeviceNameChanged(const std::string & device)51 void OnDeviceNameChanged(const std::string &device) 52 {} OnDeviceAddrChanged(const std::string & address)53 void OnDeviceAddrChanged(const std::string &address) 54 {} 55 }; 56 57 class BleCentralManagerCallbackTest : public Bluetooth::BleCentralManagerCallback { 58 public: BleCentralManagerCallbackTest()59 BleCentralManagerCallbackTest(){}; ~BleCentralManagerCallbackTest()60 ~BleCentralManagerCallbackTest(){}; 61 62 private: OnScanCallback(const Bluetooth::BleScanResult & result)63 void OnScanCallback(const Bluetooth::BleScanResult &result) 64 {} OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> & results)65 void OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> &results) 66 {} OnStartOrStopScanEvent(int resultCode,bool isStartScan)67 void OnStartOrStopScanEvent(int resultCode, bool isStartScan) 68 {} 69 }; 70 71 class BleTest : public testing::Test { 72 public: 73 BleTest(); 74 ~BleTest(); 75 76 Bluetooth::BluetoothHost *host_ = nullptr; 77 static BleTest *bleInstance_; 78 Bluetooth::BleAdvertiserSettings bleAdvertiserSettings_ {}; 79 BleCentralManagerCallbackTest bleCentralManagerCallbackTest_ {}; 80 BleAdvertiseCallbackTest bleAdvertiseCallbackTest_ {}; 81 BleHostObserverTest bleHostObserverTest_ {}; 82 Bluetooth::BleScanSettings bleScanSettings_ {}; 83 84 static void SetUpTestCase(void); 85 static void TearDownTestCase(void); 86 void SetUp(); 87 void TearDown(); 88 89 void InitAdvertiseSettings(); 90 void InitScanSettings(); 91 bool HaveUuid(Bluetooth::BleAdvertiserData advData); 92 bool ManufacturerData(Bluetooth::BleAdvertiserData advData); 93 bool ServiceData(Bluetooth::BleAdvertiserData advData); 94 bool EnableBle(); 95 bool DisableBle(); 96 97 private: 98 bool isHaveUuid = false; 99 }; 100 } // namespace Bluetooth 101 } // namespace OHOS