119e95205Sopenharmony_ci/*
219e95205Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
419e95205Sopenharmony_ci * you may not use this file except in compliance with the License.
519e95205Sopenharmony_ci * You may obtain a copy of the License at
619e95205Sopenharmony_ci *
719e95205Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
819e95205Sopenharmony_ci *
919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and
1319e95205Sopenharmony_ci * limitations under the License.
1419e95205Sopenharmony_ci */
1519e95205Sopenharmony_ci
1619e95205Sopenharmony_ci#include <gtest/gtest.h>
1719e95205Sopenharmony_ci#include "bluetooth_ble_advertiser.h"
1819e95205Sopenharmony_ci#include "bluetooth_ble_central_manager.h"
1919e95205Sopenharmony_ci#include "bluetooth_host.h"
2019e95205Sopenharmony_ci
2119e95205Sopenharmony_cinamespace OHOS {
2219e95205Sopenharmony_cinamespace Bluetooth {
2319e95205Sopenharmony_ciusing namespace testing::ext;
2419e95205Sopenharmony_ci
2519e95205Sopenharmony_ciclass BleAdvertiseCallbackTest : public Bluetooth::BleAdvertiseCallback {
2619e95205Sopenharmony_cipublic:
2719e95205Sopenharmony_ci    BleAdvertiseCallbackTest(){};
2819e95205Sopenharmony_ci    ~BleAdvertiseCallbackTest(){};
2919e95205Sopenharmony_ci
3019e95205Sopenharmony_ciprivate:
3119e95205Sopenharmony_ci    void OnStartResultEvent(int result, int advHandle) {}
3219e95205Sopenharmony_ci    void OnEnableResultEvent(int result, int advHandle) {}
3319e95205Sopenharmony_ci    void OnDisableResultEvent(int result, int advHandle) {}
3419e95205Sopenharmony_ci    void OnStopResultEvent(int result, int advHandle) {}
3519e95205Sopenharmony_ci    void OnSetAdvDataEvent(int result) {}
3619e95205Sopenharmony_ci    void OnGetAdvHandleEvent(int result, int advHandle) {}
3719e95205Sopenharmony_ci};
3819e95205Sopenharmony_ci
3919e95205Sopenharmony_ciclass BleHostObserverTest : public Bluetooth::BluetoothHostObserver {
4019e95205Sopenharmony_cipublic:
4119e95205Sopenharmony_ci    BleHostObserverTest(){};
4219e95205Sopenharmony_ci    ~BleHostObserverTest(){};
4319e95205Sopenharmony_ci
4419e95205Sopenharmony_ciprivate:
4519e95205Sopenharmony_ci    void OnStateChanged(const int transport, const int status);
4619e95205Sopenharmony_ci    void OnDiscoveryStateChanged(int status)
4719e95205Sopenharmony_ci    {}
4819e95205Sopenharmony_ci    void OnDiscoveryResult(
4919e95205Sopenharmony_ci        const BluetoothRemoteDevice &device, int rssi, const std::string deviceName, int deviceClass)
5019e95205Sopenharmony_ci    {}
5119e95205Sopenharmony_ci    void OnPairRequested(const BluetoothRemoteDevice &device)
5219e95205Sopenharmony_ci    {}
5319e95205Sopenharmony_ci    void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number)
5419e95205Sopenharmony_ci    {}
5519e95205Sopenharmony_ci    void OnScanModeChanged(int mode)
5619e95205Sopenharmony_ci    {}
5719e95205Sopenharmony_ci    void OnDeviceNameChanged(const std::string &device)
5819e95205Sopenharmony_ci    {}
5919e95205Sopenharmony_ci    void OnDeviceAddrChanged(const std::string &address)
6019e95205Sopenharmony_ci    {}
6119e95205Sopenharmony_ci};
6219e95205Sopenharmony_ci
6319e95205Sopenharmony_ciclass BleCentralManagerCallbackTest : public Bluetooth::BleCentralManagerCallback {
6419e95205Sopenharmony_cipublic:
6519e95205Sopenharmony_ci    BleCentralManagerCallbackTest(){};
6619e95205Sopenharmony_ci    ~BleCentralManagerCallbackTest(){};
6719e95205Sopenharmony_ci
6819e95205Sopenharmony_ciprivate:
6919e95205Sopenharmony_ci    void OnScanCallback(const Bluetooth::BleScanResult &result)
7019e95205Sopenharmony_ci    {}
7119e95205Sopenharmony_ci    void OnFoundOrLostCallback(const BleScanResult &result, uint8_t callbackType)
7219e95205Sopenharmony_ci    {}
7319e95205Sopenharmony_ci    void OnBleBatchScanResultsEvent(const std::vector<Bluetooth::BleScanResult> &results)
7419e95205Sopenharmony_ci    {}
7519e95205Sopenharmony_ci    void OnStartOrStopScanEvent(int resultCode, bool isStartScan)
7619e95205Sopenharmony_ci    {}
7719e95205Sopenharmony_ci};
7819e95205Sopenharmony_ci
7919e95205Sopenharmony_ciclass BleTest : public testing::Test {
8019e95205Sopenharmony_cipublic:
8119e95205Sopenharmony_ci    BleTest();
8219e95205Sopenharmony_ci    ~BleTest();
8319e95205Sopenharmony_ci
8419e95205Sopenharmony_ci    Bluetooth::BluetoothHost *host_ = nullptr;
8519e95205Sopenharmony_ci    static BleTest *bleInstance_;
8619e95205Sopenharmony_ci    Bluetooth::BleAdvertiserSettings bleAdvertiserSettings_ {};
8719e95205Sopenharmony_ci    BleCentralManagerCallbackTest bleCentralManagerCallbackTest_ {};
8819e95205Sopenharmony_ci    BleAdvertiseCallbackTest bleAdvertiseCallbackTest_ {};
8919e95205Sopenharmony_ci    std::shared_ptr<BleHostObserverTest> bleHostObserverTest_ = nullptr;
9019e95205Sopenharmony_ci    Bluetooth::BleScanSettings bleScanSettings_ {};
9119e95205Sopenharmony_ci
9219e95205Sopenharmony_ci    static void SetUpTestCase(void);
9319e95205Sopenharmony_ci    static void TearDownTestCase(void);
9419e95205Sopenharmony_ci    void SetUp();
9519e95205Sopenharmony_ci    void TearDown();
9619e95205Sopenharmony_ci
9719e95205Sopenharmony_ci    void InitAdvertiseSettings();
9819e95205Sopenharmony_ci    void InitScanSettings();
9919e95205Sopenharmony_ci    bool HaveUuid(Bluetooth::BleAdvertiserData advData);
10019e95205Sopenharmony_ci    bool ManufacturerData(Bluetooth::BleAdvertiserData advData);
10119e95205Sopenharmony_ci    bool ServiceData(Bluetooth::BleAdvertiserData advData);
10219e95205Sopenharmony_ci    bool EnableBle();
10319e95205Sopenharmony_ci    bool DisableBle();
10419e95205Sopenharmony_ci
10519e95205Sopenharmony_ciprivate:
10619e95205Sopenharmony_ci    bool isHaveUuid = false;
10719e95205Sopenharmony_ci};
10819e95205Sopenharmony_ci}  // namespace Bluetooth
10919e95205Sopenharmony_ci}  // namespace OHOS