AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockBluetoothDevice.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_BLUETOOTH_MOCKBLUETOOTHDEVICE_H_
16 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_BLUETOOTH_MOCKBLUETOOTHDEVICE_H_
17 
18 #include <unordered_map>
19 #include <vector>
20 
21 #include <gmock/gmock.h>
22 
25 
26 namespace alexaClientSDK {
27 namespace avsCommon {
28 namespace sdkInterfaces {
29 namespace bluetooth {
30 namespace test {
31 
32 using namespace ::testing;
33 
34 static constexpr std::size_t PAIRING_PIN_LENGTH_MIN = 4;
35 static constexpr std::size_t PAIRING_PIN_LENGTH_MAX = 16;
36 
43 public:
44  std::string getMac() const override;
45  std::string getFriendlyName() const override;
46  DeviceState getDeviceState() override;
48  bool isPaired() override;
49  std::future<bool> pair() override;
50  std::future<bool> unpair() override;
51  bool isConnected() override;
52  std::future<bool> connect() override;
53  std::future<bool> disconnect() override;
54  bool setPairingPin(const std::string& pin) override;
55  std::vector<std::shared_ptr<services::SDPRecordInterface>> getSupportedServices() override;
56  std::shared_ptr<services::BluetoothServiceInterface> getService(std::string uuid) override;
58  bool toggleServiceConnection(bool enabled, std::shared_ptr<services::BluetoothServiceInterface> service) override;
59 
62  const std::string& mac,
63  const std::string friendlyName,
64  MetaData metaData,
65  std::vector<std::shared_ptr<services::BluetoothServiceInterface>> supportedServices);
66 
67 protected:
69  bool m_isPaired;
79  std::unordered_map<std::string, std::shared_ptr<services::BluetoothServiceInterface>> m_supportedServices;
82 };
83 
85  return m_mac;
86 }
87 
89  return m_friendlyName;
90 }
91 
93  return m_deviceState;
94 }
95 
97  return m_metaData;
98 }
99 
101  return m_isPaired;
102 }
103 
104 inline std::future<bool> MockBluetoothDevice::pair() {
105  std::promise<bool> pairPromise;
106  pairPromise.set_value(true);
107  m_isPaired = true;
109  return pairPromise.get_future();
110 }
111 
112 inline std::future<bool> MockBluetoothDevice::unpair() {
113  std::promise<bool> pairPromise;
114  pairPromise.set_value(true);
115  m_isPaired = false;
117  return pairPromise.get_future();
118 }
119 
121  return m_isConnected;
122 }
123 
124 inline std::future<bool> MockBluetoothDevice::connect() {
125  std::promise<bool> connectionPromise;
126  connectionPromise.set_value(true);
127  m_isConnected = true;
129  return connectionPromise.get_future();
130 }
131 
132 inline std::future<bool> MockBluetoothDevice::disconnect() {
133  std::promise<bool> connectionPromise;
134  connectionPromise.set_value(true);
135  m_isConnected = false;
137  return connectionPromise.get_future();
138 }
139 
141  if (pin.length() < PAIRING_PIN_LENGTH_MIN || pin.length() > PAIRING_PIN_LENGTH_MAX) {
142  return false;
143  }
144  return true;
145 }
146 
147 inline std::vector<std::shared_ptr<services::SDPRecordInterface>> MockBluetoothDevice::getSupportedServices() {
148  std::vector<std::shared_ptr<services::SDPRecordInterface>> services;
149  for (auto service : m_supportedServices) {
150  services.push_back(service.second->getRecord());
151  }
152  return services;
153 }
154 
155 inline std::shared_ptr<services::BluetoothServiceInterface> MockBluetoothDevice::getService(std::string uuid) {
156  auto serviceIt = m_supportedServices.find(uuid);
157  if (serviceIt != m_supportedServices.end()) {
158  return serviceIt->second;
159  }
160  return nullptr;
161 }
162 
165 }
166 
168  bool enabled,
169  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::bluetooth::services::BluetoothServiceInterface> service) {
170  // No-op.
171  return false;
172 }
173 
175  const std::string& mac,
176  const std::string friendlyName,
178  std::vector<std::shared_ptr<services::BluetoothServiceInterface>> supportedServices) :
179  m_mac{mac},
180  m_friendlyName{friendlyName},
181  m_metaData{metaData} {
182  m_isPaired = false;
183  m_isConnected = false;
185  for (unsigned int i = 0; i < supportedServices.size(); ++i) {
186  auto service = supportedServices[i];
187  m_supportedServices.insert({service->getRecord()->getUuid(), service});
188  }
189 }
190 
191 } // namespace test
192 } // namespace bluetooth
193 } // namespace sdkInterfaces
194 } // namespace avsCommon
195 } // namespace alexaClientSDK
196 
197 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_TEST_AVSCOMMON_SDKINTERFACES_BLUETOOTH_MOCKBLUETOOTHDEVICE_H_
static constexpr std::size_t PAIRING_PIN_LENGTH_MIN
Definition: MockBluetoothDevice.h:34
Definition: gmock-actions.h:53
const std::string m_mac
Represent the Bluetooth device mac address.
Definition: MockBluetoothDevice.h:73
const std::string m_friendlyName
Represent the Bluetooth device friendly name.
Definition: MockBluetoothDevice.h:75
std::future< bool > pair() override
Definition: MockBluetoothDevice.h:104
std::string getFriendlyName() const override
Definition: MockBluetoothDevice.h:88
std::future< bool > disconnect() override
Definition: MockBluetoothDevice.h:132
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
utils::bluetooth::MediaStreamingState getStreamingState() override
Definition: MockBluetoothDevice.h:163
MediaStreamingState
An Enum representing the current state of the stream.
Definition: MediaStreamingState.h:25
std::future< bool > unpair() override
Definition: MockBluetoothDevice.h:112
bool isPaired() override
Definition: MockBluetoothDevice.h:100
std::string getMac() const override
Definition: MockBluetoothDevice.h:84
std::unordered_map< std::string, std::shared_ptr< services::BluetoothServiceInterface > > m_supportedServices
Represent the Bluetooth device supported Services.
Definition: MockBluetoothDevice.h:79
MockBluetoothDevice::MetaData m_metaData
Represent the Bluetooth device meta data.
Definition: MockBluetoothDevice.h:77
MockBluetoothDevice::MetaData getDeviceMetaData() override
Definition: MockBluetoothDevice.h:96
Represents a Bluetooth Device.
Definition: BluetoothDeviceInterface.h:100
MockBluetoothDevice(const std::string &mac, const std::string friendlyName, MetaData metaData, std::vector< std::shared_ptr< services::BluetoothServiceInterface >> supportedServices)
Constructor.
Definition: MockBluetoothDevice.h:174
bool setPairingPin(const std::string &pin) override
Definition: MockBluetoothDevice.h:140
bool isConnected() override
Definition: MockBluetoothDevice.h:120
DeviceState m_deviceState
Represent the Bluetooth device state.
Definition: MockBluetoothDevice.h:81
bool toggleServiceConnection(bool enabled, std::shared_ptr< services::BluetoothServiceInterface > service) override
Definition: MockBluetoothDevice.h:167
std::vector< std::shared_ptr< services::SDPRecordInterface > > getSupportedServices() override
Definition: MockBluetoothDevice.h:147
std::future< bool > connect() override
Definition: MockBluetoothDevice.h:124
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
DeviceState
Definition: BluetoothDeviceInterface.h:48
static constexpr std::size_t PAIRING_PIN_LENGTH_MAX
Definition: MockBluetoothDevice.h:35
bool m_isPaired
Represent the pair status.
Definition: MockBluetoothDevice.h:69
DeviceState getDeviceState() override
Definition: MockBluetoothDevice.h:92
std::shared_ptr< services::BluetoothServiceInterface > getService(std::string uuid) override
Definition: MockBluetoothDevice.h:155
bool m_isConnected
Represent the connection status.
Definition: MockBluetoothDevice.h:71

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0