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