#ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_
#define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/test/test_simple_task_runner.h"
#include "device/bluetooth/test/bluetooth_test.h"
#if __OBJC__
@class MockCBDescriptor;
@class MockCBCharacteristic;
@class MockCBPeripheral;
#endif
namespace device {
class BluetoothLowEnergyAdapterApple;
class BluetoothTestMac : public BluetoothTestBase {
public:
static const char kTestPeripheralUUID1[];
static const char kTestPeripheralUUID2[];
BluetoothTestMac();
~BluetoothTestMac() override;
void SetUp() override;
bool PlatformSupportsLowEnergy() override;
void InitWithDefaultAdapter() override;
void InitWithoutDefaultAdapter() override;
void InitWithFakeAdapter() override;
void ResetEventCounts() override;
void SimulateAdapterPoweredOff() override;
BluetoothDevice* SimulateLowEnergyDevice(int device_ordinal) override;
void SimulateConnectedLowEnergyDevice(
ConnectedDeviceType device_ordinal) override;
void SimulateGattConnection(BluetoothDevice* device) override;
void SimulateGattConnectionError(
BluetoothDevice* device,
BluetoothDevice::ConnectErrorCode errorCode) override;
void SimulateGattDisconnection(BluetoothDevice* device) override;
void SimulateGattDisconnectionError(BluetoothDevice* device) override;
void SimulateGattServicesDiscovered(
BluetoothDevice* device,
const std::vector<std::string>& uuids,
const std::vector<std::string>& blocked_uuids = {}) override;
void SimulateGattServicesChanged(BluetoothDevice* device) override;
void SimulateGattServiceRemoved(BluetoothRemoteGattService* service) override;
void SimulateGattCharacteristic(BluetoothRemoteGattService* service,
const std::string& uuid,
int properties) override;
void SimulateGattCharacteristicRead(
BluetoothRemoteGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
void SimulateGattCharacteristicReadError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode) override;
void SimulateGattCharacteristicWrite(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattCharacteristicWriteError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattDescriptor(BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) override;
void SimulateGattNotifySessionStarted(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattNotifySessionStartError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattNotifySessionStopped(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattNotifySessionStopError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattCharacteristicChanged(
BluetoothRemoteGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
void SimulateGattCharacteristicRemoved(
BluetoothRemoteGattService* service,
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattDescriptorRead(BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value) override;
void SimulateGattDescriptorReadError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattDescriptorWrite(
BluetoothRemoteGattDescriptor* descriptor) override;
void SimulateGattDescriptorWriteError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattDescriptorUpdateError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothGattService::GattErrorCode error_code) override;
void ExpectedChangeNotifyValueAttempts(int attempts) override;
void ExpectedNotifyValue(NotifyValueState expected_value_state) override;
void SimulateDidDiscoverServicesMac(BluetoothDevice* device);
void SimulateDidDiscoverServicesMacWithError(BluetoothDevice* device);
void SimulateDidDiscoverCharacteristicsMac(
BluetoothRemoteGattService* service);
void SimulateDidDiscoverCharacteristicsWithErrorMac(
BluetoothRemoteGattService* service);
void SimulateDidDiscoverDescriptorsMac(
BluetoothRemoteGattCharacteristic* characteristic);
void SimulateDidDiscoverDescriptorsWithErrorMac(
BluetoothRemoteGattCharacteristic* characteristic);
void SimulateGattDescriptorReadNSDataMac(
BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value);
void SimulateGattDescriptorReadNSStringMac(
BluetoothRemoteGattDescriptor* descriptor,
const std::string& value);
void SimulateGattDescriptorReadNSNumberMac(
BluetoothRemoteGattDescriptor* descriptor,
short value);
#if !BUILDFLAG(IS_IOS)
void SetMockControllerPowerState(int powered);
#endif
void AddServicesToDeviceMac(BluetoothDevice* device,
const std::vector<std::string>& uuids);
void AddCharacteristicToServiceMac(BluetoothRemoteGattService* service,
const std::string& characteristic_uuid,
int properties);
void AddDescriptorToCharacteristicMac(
BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid);
void OnFakeBluetoothDeviceConnectGattCalled();
void OnFakeBluetoothGattDisconnect();
void OnFakeBluetoothServiceDiscovery();
void OnFakeBluetoothCharacteristicDiscovery();
void OnFakeBluetoothCharacteristicReadValue();
void OnFakeBluetoothCharacteristicWriteValue(std::vector<uint8_t> value);
void OnFakeBluetoothGattSetCharacteristicNotification(bool notify_value);
void OnFakeBluetoothDescriptorReadValue();
void OnFakeBluetoothDescriptorWriteValue(std::vector<uint8_t> value);
BluetoothDevice::UUIDSet RetrieveConnectedPeripheralServiceUUIDs();
void ResetRetrieveConnectedPeripheralServiceUUIDs();
protected:
class ScopedMockCentralManager;
#if __OBJC__
MockCBPeripheral* GetMockCBPeripheral(BluetoothDevice* device) const;
MockCBPeripheral* GetMockCBPeripheral(
BluetoothRemoteGattService* service) const;
MockCBPeripheral* GetMockCBPeripheral(
BluetoothRemoteGattCharacteristic* characteristic) const;
MockCBPeripheral* GetMockCBPeripheral(
BluetoothRemoteGattDescriptor* descriptor) const;
MockCBCharacteristic* GetCBMockCharacteristic(
BluetoothRemoteGattCharacteristic* characteristic) const;
MockCBDescriptor* GetCBMockDescriptor(
BluetoothRemoteGattDescriptor* descriptor) const;
#endif
std::string FindCBUUIDForHashTarget();
raw_ptr<BluetoothLowEnergyAdapterApple, DanglingUntriaged>
adapter_low_energy_ = nullptr;
std::unique_ptr<ScopedMockCentralManager> mock_central_manager_;
bool last_notify_value_ = false;
int gatt_characteristic_discovery_attempts_ = 0;
};
using BluetoothTest = BluetoothTestMac;
}
#endif