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 "device/bluetooth/bluetooth_gatt_service.h" | 5 #include "device/bluetooth/bluetooth_gatt_service.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
9 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 9 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // GetCharacteristics & GetCharacteristic return the same object for the same | 161 // GetCharacteristics & GetCharacteristic return the same object for the same |
162 // ID: | 162 // ID: |
163 EXPECT_EQ(service->GetCharacteristics()[0], | 163 EXPECT_EQ(service->GetCharacteristics()[0], |
164 service->GetCharacteristic(char_id1)); | 164 service->GetCharacteristic(char_id1)); |
165 EXPECT_EQ(service->GetCharacteristic(char_id1), | 165 EXPECT_EQ(service->GetCharacteristic(char_id1), |
166 service->GetCharacteristic(char_id1)); | 166 service->GetCharacteristic(char_id1)); |
167 } | 167 } |
168 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 168 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
169 | 169 |
170 #if defined(OS_MACOSX) || defined(OS_WIN) | 170 #if defined(OS_MACOSX) || defined(OS_WIN) |
171 TEST_F(BluetoothRemoteGattServiceTest, | 171 TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) { |
172 GetCharacteristic_CharacteristicRemoved) { | |
173 if (!PlatformSupportsLowEnergy()) { | 172 if (!PlatformSupportsLowEnergy()) { |
174 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 173 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
175 return; | 174 return; |
176 } | 175 } |
177 InitWithFakeAdapter(); | 176 InitWithFakeAdapter(); |
178 StartLowEnergyDiscoverySession(); | 177 StartLowEnergyDiscoverySession(); |
179 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 178 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
180 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 179 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
181 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 180 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
182 SimulateGattConnection(device); | 181 SimulateGattConnection(device); |
183 | 182 |
184 TestBluetoothAdapterObserver observer(adapter_); | 183 TestBluetoothAdapterObserver observer(adapter_); |
185 | 184 |
186 // Simulate a service, with several Characteristics: | 185 // Simulate a service, with several Characteristics: |
187 std::vector<std::string> services; | 186 std::vector<std::string> services; |
188 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 187 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
189 SimulateGattServicesDiscovered(device, services); | 188 SimulateGattServicesDiscovered(device, services); |
190 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 189 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
191 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; | 190 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; |
192 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; | 191 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; |
193 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. | 192 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. |
194 std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; | 193 std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; |
195 SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); | 194 SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); |
196 SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); | 195 SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); |
197 SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); | 196 SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); |
198 SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); | 197 SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); |
| 198 #if !defined(OS_WIN) |
| 199 // TODO(620895) GattCharacteristicAdded has to be implemented for Windows. |
| 200 EXPECT_EQ(4, observer.gatt_characteristic_added_count()); |
| 201 #endif // !defined(OS_WIN) |
199 | 202 |
200 // Simulate remove of characteristics one by one. | 203 // Simulate remove of characteristics one by one. |
201 EXPECT_EQ(4u, service->GetCharacteristics().size()); | 204 EXPECT_EQ(4u, service->GetCharacteristics().size()); |
202 std::string removed_char = service->GetCharacteristics()[0]->GetIdentifier(); | 205 std::string removed_char = service->GetCharacteristics()[0]->GetIdentifier(); |
203 SimulateGattCharacteristicRemoved(service, | 206 SimulateGattCharacteristicRemoved(service, |
204 service->GetCharacteristic(removed_char)); | 207 service->GetCharacteristic(removed_char)); |
205 EXPECT_EQ(1, observer.gatt_characteristic_removed_count()); | 208 EXPECT_EQ(1, observer.gatt_characteristic_removed_count()); |
206 EXPECT_FALSE(service->GetCharacteristic(removed_char)); | 209 EXPECT_FALSE(service->GetCharacteristic(removed_char)); |
207 EXPECT_EQ(3u, service->GetCharacteristics().size()); | 210 EXPECT_EQ(3u, service->GetCharacteristics().size()); |
208 removed_char = service->GetCharacteristics()[0]->GetIdentifier(); | 211 removed_char = service->GetCharacteristics()[0]->GetIdentifier(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 std::string removed_service = service1->GetIdentifier(); | 266 std::string removed_service = service1->GetIdentifier(); |
264 SimulateGattServiceRemoved(device->GetGattService(removed_service)); | 267 SimulateGattServiceRemoved(device->GetGattService(removed_service)); |
265 EXPECT_EQ(1, observer.gatt_service_removed_count()); | 268 EXPECT_EQ(1, observer.gatt_service_removed_count()); |
266 EXPECT_EQ(1u, device->GetGattServices().size()); | 269 EXPECT_EQ(1u, device->GetGattServices().size()); |
267 EXPECT_FALSE(device->GetGattService(removed_service)); | 270 EXPECT_FALSE(device->GetGattService(removed_service)); |
268 EXPECT_EQ(device->GetGattServices()[0], service2); | 271 EXPECT_EQ(device->GetGattServices()[0], service2); |
269 } | 272 } |
270 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 273 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
271 | 274 |
272 } // namespace device | 275 } // namespace device |
OLD | NEW |