OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_EQ(expected_byte1, last_write_value_[1]); | 129 EXPECT_EQ(expected_byte1, last_write_value_[1]); |
130 } | 130 } |
131 | 131 |
132 BluetoothDevice* device_ = nullptr; | 132 BluetoothDevice* device_ = nullptr; |
133 BluetoothRemoteGattService* service_ = nullptr; | 133 BluetoothRemoteGattService* service_ = nullptr; |
134 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; | 134 BluetoothRemoteGattCharacteristic* characteristic1_ = nullptr; |
135 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; | 135 BluetoothRemoteGattCharacteristic* characteristic2_ = nullptr; |
136 }; | 136 }; |
137 #endif | 137 #endif |
138 | 138 |
139 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 139 #if defined(OS_ANDROID) || defined(OS_WIN) |
140 TEST_F(BluetoothRemoteGattCharacteristicTest, GetIdentifier) { | 140 TEST_F(BluetoothRemoteGattCharacteristicTest, GetIdentifier) { |
141 if (!PlatformSupportsLowEnergy()) { | |
142 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
143 return; | |
144 } | |
145 InitWithFakeAdapter(); | 141 InitWithFakeAdapter(); |
146 StartLowEnergyDiscoverySession(); | 142 StartLowEnergyDiscoverySession(); |
147 // 2 devices to verify unique IDs across them. | 143 // 2 devices to verify unique IDs across them. |
148 BluetoothDevice* device1 = SimulateLowEnergyDevice(3); | 144 BluetoothDevice* device1 = SimulateLowEnergyDevice(3); |
149 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); | 145 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); |
150 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 146 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
151 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 147 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
152 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 148 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
153 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 149 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
154 SimulateGattConnection(device1); | 150 SimulateGattConnection(device1); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 190 |
195 EXPECT_NE(char3->GetIdentifier(), char4->GetIdentifier()); | 191 EXPECT_NE(char3->GetIdentifier(), char4->GetIdentifier()); |
196 EXPECT_NE(char3->GetIdentifier(), char5->GetIdentifier()); | 192 EXPECT_NE(char3->GetIdentifier(), char5->GetIdentifier()); |
197 EXPECT_NE(char3->GetIdentifier(), char6->GetIdentifier()); | 193 EXPECT_NE(char3->GetIdentifier(), char6->GetIdentifier()); |
198 | 194 |
199 EXPECT_NE(char4->GetIdentifier(), char5->GetIdentifier()); | 195 EXPECT_NE(char4->GetIdentifier(), char5->GetIdentifier()); |
200 EXPECT_NE(char4->GetIdentifier(), char6->GetIdentifier()); | 196 EXPECT_NE(char4->GetIdentifier(), char6->GetIdentifier()); |
201 | 197 |
202 EXPECT_NE(char5->GetIdentifier(), char6->GetIdentifier()); | 198 EXPECT_NE(char5->GetIdentifier(), char6->GetIdentifier()); |
203 } | 199 } |
204 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 200 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
205 | 201 |
206 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 202 #if defined(OS_ANDROID) || defined(OS_WIN) |
207 TEST_F(BluetoothRemoteGattCharacteristicTest, GetUUID) { | 203 TEST_F(BluetoothRemoteGattCharacteristicTest, GetUUID) { |
208 if (!PlatformSupportsLowEnergy()) { | |
209 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
210 return; | |
211 } | |
212 InitWithFakeAdapter(); | 204 InitWithFakeAdapter(); |
213 StartLowEnergyDiscoverySession(); | 205 StartLowEnergyDiscoverySession(); |
214 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 206 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
215 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 207 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
216 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 208 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
217 SimulateGattConnection(device); | 209 SimulateGattConnection(device); |
218 std::vector<std::string> services; | 210 std::vector<std::string> services; |
219 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 211 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
220 SimulateGattServicesDiscovered(device, services); | 212 SimulateGattServicesDiscovered(device, services); |
221 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 213 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
(...skipping 14 matching lines...) Expand all Loading... |
236 if (char2->GetUUID() == uuid1) { | 228 if (char2->GetUUID() == uuid1) { |
237 std::swap(char1, char2); | 229 std::swap(char1, char2); |
238 } else if (char3->GetUUID() == uuid1) { | 230 } else if (char3->GetUUID() == uuid1) { |
239 std::swap(char1, char3); | 231 std::swap(char1, char3); |
240 } | 232 } |
241 | 233 |
242 EXPECT_EQ(uuid1, char1->GetUUID()); | 234 EXPECT_EQ(uuid1, char1->GetUUID()); |
243 EXPECT_EQ(uuid2, char2->GetUUID()); | 235 EXPECT_EQ(uuid2, char2->GetUUID()); |
244 EXPECT_EQ(uuid2, char3->GetUUID()); | 236 EXPECT_EQ(uuid2, char3->GetUUID()); |
245 } | 237 } |
246 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 238 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
247 | 239 |
248 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 240 #if defined(OS_ANDROID) || defined(OS_WIN) |
249 TEST_F(BluetoothRemoteGattCharacteristicTest, GetProperties) { | 241 TEST_F(BluetoothRemoteGattCharacteristicTest, GetProperties) { |
250 if (!PlatformSupportsLowEnergy()) { | |
251 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
252 return; | |
253 } | |
254 InitWithFakeAdapter(); | 242 InitWithFakeAdapter(); |
255 StartLowEnergyDiscoverySession(); | 243 StartLowEnergyDiscoverySession(); |
256 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 244 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
257 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 245 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
258 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 246 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
259 SimulateGattConnection(device); | 247 SimulateGattConnection(device); |
260 std::vector<std::string> services; | 248 std::vector<std::string> services; |
261 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); | 249 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); |
262 services.push_back(uuid); | 250 services.push_back(uuid); |
263 SimulateGattServicesDiscovered(device, services); | 251 SimulateGattServicesDiscovered(device, services); |
264 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 252 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
265 | 253 |
266 // Create two characteristics with different properties: | 254 // Create two characteristics with different properties: |
267 SimulateGattCharacteristic(service, uuid, /* properties */ 0); | 255 SimulateGattCharacteristic(service, uuid, /* properties */ 0); |
268 SimulateGattCharacteristic(service, uuid, /* properties */ 7); | 256 SimulateGattCharacteristic(service, uuid, /* properties */ 7); |
269 | 257 |
270 // Read the properties. Because ordering is unknown swap as necessary. | 258 // Read the properties. Because ordering is unknown swap as necessary. |
271 int properties1 = service->GetCharacteristics()[0]->GetProperties(); | 259 int properties1 = service->GetCharacteristics()[0]->GetProperties(); |
272 int properties2 = service->GetCharacteristics()[1]->GetProperties(); | 260 int properties2 = service->GetCharacteristics()[1]->GetProperties(); |
273 if (properties2 == 0) | 261 if (properties2 == 0) |
274 std::swap(properties1, properties2); | 262 std::swap(properties1, properties2); |
275 EXPECT_EQ(0, properties1); | 263 EXPECT_EQ(0, properties1); |
276 EXPECT_EQ(7, properties2); | 264 EXPECT_EQ(7, properties2); |
277 } | 265 } |
278 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 266 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
279 | 267 |
280 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 268 #if defined(OS_ANDROID) || defined(OS_WIN) |
281 // Tests GetService. | 269 // Tests GetService. |
282 TEST_F(BluetoothRemoteGattCharacteristicTest, GetService) { | 270 TEST_F(BluetoothRemoteGattCharacteristicTest, GetService) { |
283 if (!PlatformSupportsLowEnergy()) { | |
284 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | |
285 return; | |
286 } | |
287 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 271 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
288 | 272 |
289 EXPECT_EQ(service_, characteristic1_->GetService()); | 273 EXPECT_EQ(service_, characteristic1_->GetService()); |
290 EXPECT_EQ(service_, characteristic2_->GetService()); | 274 EXPECT_EQ(service_, characteristic2_->GetService()); |
291 } | 275 } |
292 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 276 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
293 | 277 |
294 #if defined(OS_ANDROID) || defined(OS_WIN) | 278 #if defined(OS_ANDROID) || defined(OS_WIN) |
295 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. | 279 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. |
296 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { | 280 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { |
297 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
298 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | 282 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
299 | 283 |
300 characteristic1_->ReadRemoteCharacteristic( | 284 characteristic1_->ReadRemoteCharacteristic( |
301 GetReadValueCallback(Call::EXPECTED), | 285 GetReadValueCallback(Call::EXPECTED), |
302 GetGattErrorCallback(Call::NOT_EXPECTED)); | 286 GetGattErrorCallback(Call::NOT_EXPECTED)); |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 1224 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
1241 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 1225 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
1242 | 1226 |
1243 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 1227 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
1244 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 1228 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
1245 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 1229 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
1246 } | 1230 } |
1247 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1231 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
1248 | 1232 |
1249 } // namespace device | 1233 } // namespace device |
OLD | NEW |