• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)48     void OnDiscoveryResult(const BluetoothRemoteDevice &device)
49     {}
OnPairRequested(const BluetoothRemoteDevice & device)50     void OnPairRequested(const BluetoothRemoteDevice &device)
51     {}
OnPairConfirmed(const BluetoothRemoteDevice & device,int reqType,int number)52     void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number)
53     {}
OnScanModeChanged(int mode)54     void OnScanModeChanged(int mode)
55     {}
OnDeviceNameChanged(const std::string & device)56     void OnDeviceNameChanged(const std::string &device)
57     {}
OnDeviceAddrChanged(const std::string & address)58     void OnDeviceAddrChanged(const std::string &address)
59     {}
60 };
61 
62 class BleCentralManagerCallbackTest : public Bluetooth::BleCentralManagerCallback {
63 public:
BleCentralManagerCallbackTest()64     BleCentralManagerCallbackTest(){};
~BleCentralManagerCallbackTest()65     ~BleCentralManagerCallbackTest(){};
66 
67 private:
OnScanCallback(const Bluetooth::BleScanResult & result)68     void OnScanCallback(const Bluetooth::BleScanResult &result)
69     {}
OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> & results)70     void OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> &results)
71     {}
OnStartOrStopScanEvent(int resultCode,bool isStartScan)72     void OnStartOrStopScanEvent(int resultCode, bool isStartScan)
73     {}
74 };
75 
76 class BleTest : public testing::Test {
77 public:
78     BleTest();
79     ~BleTest();
80 
81     Bluetooth::BluetoothHost *host_ = nullptr;
82     static BleTest *bleInstance_;
83     Bluetooth::BleAdvertiserSettings bleAdvertiserSettings_ {};
84     BleCentralManagerCallbackTest bleCentralManagerCallbackTest_ {};
85     BleAdvertiseCallbackTest bleAdvertiseCallbackTest_ {};
86     std::shared_ptr<BleHostObserverTest> bleHostObserverTest_ = nullptr;
87     Bluetooth::BleScanSettings bleScanSettings_ {};
88 
89     static void SetUpTestCase(void);
90     static void TearDownTestCase(void);
91     void SetUp();
92     void TearDown();
93 
94     void InitAdvertiseSettings();
95     void InitScanSettings();
96     bool HaveUuid(Bluetooth::BleAdvertiserData advData);
97     bool ManufacturerData(Bluetooth::BleAdvertiserData advData);
98     bool ServiceData(Bluetooth::BleAdvertiserData advData);
99     bool EnableBle();
100     bool DisableBle();
101 
102 private:
103     bool isHaveUuid = false;
104 };
105 }  // namespace Bluetooth
106 }  // namespace OHOS