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

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

Issue 2785383002: Update unit tests for BluetoothDevice::GetPrimaryServicesByUUID() etc. (Closed)
Patch Set: address more comments 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);
ortuno 2017/04/04 22:14:12 SimulateGattServicesDiscovered( device, std::vec
juncai 2017/04/05 00:36:46 The added code is the same as the following in the
ortuno 2017/04/05 00:53:10 tldr; follow up sounds good! I would love to alwa
juncai 2017/04/05 19:01:23 I will submit a CL to do that.
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";
ortuno 2017/04/04 22:14:12 Add standard UUIDs to the list of test UUIDs and u
juncai 2017/04/05 00:36:46 ditto. Same as: https://cs.chromium.org/chromium/
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 std::vector<BluetoothRemoteGattCharacteristic*> characteristics1 =
ortuno 2017/04/04 22:14:12 Consider using brackets to avoid characteristics1,
juncai 2017/04/05 00:36:46 Done.
209 service1->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid1));
210 EXPECT_EQ(1u, characteristics1.size());
211 EXPECT_EQ(characteristic_uuid1, characteristics1[0]->GetUUID().value());
ortuno 2017/04/04 22:14:12 Use canonical_value here and elsewhere. value() de
juncai 2017/04/05 00:36:46 Done.
212
213 std::vector<BluetoothRemoteGattCharacteristic*> characteristics2 =
214 service2->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid2));
215 EXPECT_EQ(2u, characteristics2.size());
216 EXPECT_EQ(characteristic_uuid2, characteristics2[0]->GetUUID().value());
217 EXPECT_EQ(characteristic_uuid2, characteristics2[1]->GetUUID().value());
218 EXPECT_NE(characteristics2[0]->GetIdentifier(),
219 characteristics2[1]->GetIdentifier());
220
221 BluetoothUUID characteristic_uuid_not_exist_in_setup(
222 "33333333-0000-1000-8000-00805f9b34fb");
223 EXPECT_TRUE(
224 service1->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup)
225 .empty());
226 EXPECT_TRUE(
227 service2->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup)
228 .empty());
229 }
176 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 230 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
177 231
178 #if defined(OS_MACOSX) || defined(OS_WIN) 232 #if defined(OS_MACOSX) || defined(OS_WIN)
179 TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) { 233 TEST_F(BluetoothRemoteGattServiceTest, GattCharacteristics_ObserversCalls) {
180 if (!PlatformSupportsLowEnergy()) { 234 if (!PlatformSupportsLowEnergy()) {
181 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 235 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
182 return; 236 return;
183 } 237 }
184 InitWithFakeAdapter(); 238 InitWithFakeAdapter();
185 StartLowEnergyDiscoverySession(); 239 StartLowEnergyDiscoverySession();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 std::string removed_service = service1->GetIdentifier(); 331 std::string removed_service = service1->GetIdentifier();
278 SimulateGattServiceRemoved(device->GetGattService(removed_service)); 332 SimulateGattServiceRemoved(device->GetGattService(removed_service));
279 EXPECT_EQ(1, observer.gatt_service_removed_count()); 333 EXPECT_EQ(1, observer.gatt_service_removed_count());
280 EXPECT_EQ(1u, device->GetGattServices().size()); 334 EXPECT_EQ(1u, device->GetGattServices().size());
281 EXPECT_FALSE(device->GetGattService(removed_service)); 335 EXPECT_FALSE(device->GetGattService(removed_service));
282 EXPECT_EQ(device->GetGattServices()[0], service2); 336 EXPECT_EQ(device->GetGattServices()[0], service2);
283 } 337 }
284 #endif // defined(OS_WIN) || defined(OS_MACOSX) 338 #endif // defined(OS_WIN) || defined(OS_MACOSX)
285 339
286 } // namespace device 340 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698