Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_unittest.cc

Issue 2785383002: Update unit tests for BluetoothDevice::GetPrimaryServicesByUUID() etc. (Closed)
Patch Set: added TODO Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "device/bluetooth/bluetooth_gatt_service.h" 7 #include "device/bluetooth/bluetooth_gatt_service.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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID()); 166 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID());
167 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID()); 167 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID());
168 168
169 // GetCharacteristics & GetCharacteristic return the same object for the same 169 // GetCharacteristics & GetCharacteristic return the same object for the same
170 // ID: 170 // ID:
171 EXPECT_EQ(service->GetCharacteristics()[0], 171 EXPECT_EQ(service->GetCharacteristics()[0],
172 service->GetCharacteristic(char_id1)); 172 service->GetCharacteristic(char_id1));
173 EXPECT_EQ(service->GetCharacteristic(char_id1), 173 EXPECT_EQ(service->GetCharacteristic(char_id1),
174 service->GetCharacteristic(char_id1)); 174 service->GetCharacteristic(char_id1));
175 } 175 }
176
177 TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristicsByUUID) {
178 if (!PlatformSupportsLowEnergy()) {
179 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
180 return;
181 }
182 InitWithFakeAdapter();
183 StartLowEnergyDiscoverySession();
184 BluetoothDevice* device = SimulateLowEnergyDevice(3);
185 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
186 GetConnectErrorCallback(Call::NOT_EXPECTED));
187 SimulateGattConnection(device);
188 base::RunLoop().RunUntilIdle();
189
190 // Simulate two primary GATT services.
191 std::vector<std::string> services;
192 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
193 services.push_back("01010101-0101-1000-8000-00805f9b34fb");
194 SimulateGattServicesDiscovered(device, services);
195 base::RunLoop().RunUntilIdle();
196 BluetoothRemoteGattService* service1 = device->GetGattServices()[0];
197 BluetoothRemoteGattService* service2 = device->GetGattServices()[1];
198 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb";
199 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb";
200 SimulateGattCharacteristic(service1, characteristic_uuid1,
201 /* properties */ 0);
202 // 2 duplicate UUIDs creating 2 instances.
203 SimulateGattCharacteristic(service2, characteristic_uuid2,
204 /* properties */ 0);
205 SimulateGattCharacteristic(service2, characteristic_uuid2,
206 /* properties */ 0);
207
208 {
209 std::vector<BluetoothRemoteGattCharacteristic*> characteristics =
210 service1->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid1));
211 EXPECT_EQ(1u, characteristics.size());
212 EXPECT_EQ(characteristic_uuid1,
213 characteristics[0]->GetUUID().canonical_value());
214 }
215
216 {
217 std::vector<BluetoothRemoteGattCharacteristic*> characteristics =
218 service2->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid2));
219 EXPECT_EQ(2u, characteristics.size());
220 EXPECT_EQ(characteristic_uuid2,
221 characteristics[0]->GetUUID().canonical_value());
222 EXPECT_EQ(characteristic_uuid2,
223 characteristics[1]->GetUUID().canonical_value());
224 EXPECT_NE(characteristics[0]->GetIdentifier(),
225 characteristics[1]->GetIdentifier());
226 }
227
228 BluetoothUUID characteristic_uuid_not_exist_in_setup(
229 "33333333-0000-1000-8000-00805f9b34fb");
230 EXPECT_TRUE(
231 service1->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup)
232 .empty());
233 EXPECT_TRUE(
234 service2->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup)
235 .empty());
236 }
176 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 237 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
177 238
178 #if defined(OS_MACOSX) || defined(OS_WIN) 239 #if defined(OS_MACOSX) || defined(OS_WIN)
179 TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) { 240 TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) {
180 if (!PlatformSupportsLowEnergy()) { 241 if (!PlatformSupportsLowEnergy()) {
181 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 242 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
182 return; 243 return;
183 } 244 }
184 InitWithFakeAdapter(); 245 InitWithFakeAdapter();
185 StartLowEnergyDiscoverySession(); 246 StartLowEnergyDiscoverySession();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 std::string removed_service = service1->GetIdentifier(); 338 std::string removed_service = service1->GetIdentifier();
278 SimulateGattServiceRemoved(device->GetGattService(removed_service)); 339 SimulateGattServiceRemoved(device->GetGattService(removed_service));
279 EXPECT_EQ(1, observer.gatt_service_removed_count()); 340 EXPECT_EQ(1, observer.gatt_service_removed_count());
280 EXPECT_EQ(1u, device->GetGattServices().size()); 341 EXPECT_EQ(1u, device->GetGattServices().size());
281 EXPECT_FALSE(device->GetGattService(removed_service)); 342 EXPECT_FALSE(device->GetGattService(removed_service));
282 EXPECT_EQ(device->GetGattServices()[0], service2); 343 EXPECT_EQ(device->GetGattServices()[0], service2);
283 } 344 }
284 #endif // defined(OS_WIN) || defined(OS_MACOSX) 345 #endif // defined(OS_WIN) || defined(OS_MACOSX)
285 346
286 } // namespace device 347 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698