2 // Copyright (C) 2015 Google, Inc.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at:
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 #include <base/macros.h>
20 #include <base/observer_list.h>
22 #include "service/hal/bluetooth_gatt_interface.h"
27 class FakeBluetoothGattInterface : public BluetoothGattInterface {
29 // Handles HAL Bluetooth API calls for testing. Test code can provide a fake
30 // or mock implementation of this and all calls will be routed to it.
33 virtual ~TestHandler() = default;
35 virtual bt_status_t RegisterClient(bt_uuid_t* app_uuid) = 0;
36 virtual bt_status_t UnregisterClient(int client_if) = 0;
39 // Constructs the fake with the given handler |handler|. Implementations can
40 // provide their own handlers or simply pass "nullptr" for the default
41 // behavior in which BT_STATUS_FAIL will be returned from all calls.
42 FakeBluetoothGattInterface(std::shared_ptr<TestHandler> handler);
43 ~FakeBluetoothGattInterface();
45 // The methods below can be used to notify observers with certain events and
47 void NotifyRegisterClientCallback(int status, int client_if,
48 const bt_uuid_t& app_uuid);
50 // BluetoothGattInterface overrides:
51 void AddClientObserver(ClientObserver* observer) override;
52 void RemoveClientObserver(ClientObserver* observer) override;
53 const btgatt_client_interface_t* GetClientHALInterface() const override;
56 base::ObserverList<ClientObserver> client_observers_;
57 std::shared_ptr<TestHandler> handler_;
59 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothGattInterface);
63 } // namespace bluetooth