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

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

Issue 2798193002: Use test UUIDs for device bluetooth unit tests (Closed)
Patch Set: address 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 20 matching lines...) Expand all
31 // |properties| will be used for each characteristic. 31 // |properties| will be used for each characteristic.
32 void FakeCharacteristicBoilerplate(int properties = 0) { 32 void FakeCharacteristicBoilerplate(int properties = 0) {
33 InitWithFakeAdapter(); 33 InitWithFakeAdapter();
34 StartLowEnergyDiscoverySession(); 34 StartLowEnergyDiscoverySession();
35 device_ = SimulateLowEnergyDevice(3); 35 device_ = SimulateLowEnergyDevice(3);
36 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 36 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
37 GetConnectErrorCallback(Call::NOT_EXPECTED)); 37 GetConnectErrorCallback(Call::NOT_EXPECTED));
38 SimulateGattConnection(device_); 38 SimulateGattConnection(device_);
39 base::RunLoop().RunUntilIdle(); 39 base::RunLoop().RunUntilIdle();
40 40
41 std::vector<std::string> services; 41 SimulateGattServicesDiscovered(
42 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); 42 device_, std::vector<std::string>({kTestUUIDGenericAccess}));
43 services.push_back(uuid);
44 SimulateGattServicesDiscovered(device_, services);
45 base::RunLoop().RunUntilIdle(); 43 base::RunLoop().RunUntilIdle();
46 ASSERT_EQ(1u, device_->GetGattServices().size()); 44 ASSERT_EQ(1u, device_->GetGattServices().size());
47 service_ = device_->GetGattServices()[0]; 45 service_ = device_->GetGattServices()[0];
48 SimulateGattCharacteristic(service_, uuid, properties); 46 SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties);
49 SimulateGattCharacteristic(service_, uuid, properties); 47 SimulateGattCharacteristic(service_, kTestUUIDDeviceName, properties);
50 ASSERT_EQ(2u, service_->GetCharacteristics().size()); 48 ASSERT_EQ(2u, service_->GetCharacteristics().size());
51 characteristic1_ = service_->GetCharacteristics()[0]; 49 characteristic1_ = service_->GetCharacteristics()[0];
52 characteristic2_ = service_->GetCharacteristics()[1]; 50 characteristic2_ = service_->GetCharacteristics()[1];
53 ResetEventCounts(); 51 ResetEventCounts();
54 } 52 }
55 53
56 enum class StartNotifySetupError { 54 enum class StartNotifySetupError {
57 CHARACTERISTIC_PROPERTIES, 55 CHARACTERISTIC_PROPERTIES,
58 CONFIG_DESCRIPTOR_MISSING, 56 CONFIG_DESCRIPTOR_MISSING,
59 CONFIG_DESCRIPTOR_DUPLICATE, 57 CONFIG_DESCRIPTOR_DUPLICATE,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 GetConnectErrorCallback(Call::NOT_EXPECTED)); 150 GetConnectErrorCallback(Call::NOT_EXPECTED));
153 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 151 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
154 GetConnectErrorCallback(Call::NOT_EXPECTED)); 152 GetConnectErrorCallback(Call::NOT_EXPECTED));
155 SimulateGattConnection(device1); 153 SimulateGattConnection(device1);
156 SimulateGattConnection(device2); 154 SimulateGattConnection(device2);
157 base::RunLoop().RunUntilIdle(); 155 base::RunLoop().RunUntilIdle();
158 156
159 // 3 services (all with same UUID). 157 // 3 services (all with same UUID).
160 // 1 on the first device (to test characteristic instances across devices). 158 // 1 on the first device (to test characteristic instances across devices).
161 // 2 on the second device (to test same device, multiple service instances). 159 // 2 on the second device (to test same device, multiple service instances).
162 std::vector<std::string> services; 160 SimulateGattServicesDiscovered(
163 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; 161 device1, std::vector<std::string>({kTestUUIDGenericAccess}));
164 services.push_back(uuid);
165 SimulateGattServicesDiscovered(device1, services);
166 base::RunLoop().RunUntilIdle(); 162 base::RunLoop().RunUntilIdle();
167 services.push_back(uuid); 163 SimulateGattServicesDiscovered(
168 SimulateGattServicesDiscovered(device2, services); 164 device2, std::vector<std::string>(
165 {kTestUUIDGenericAccess, kTestUUIDGenericAccess}));
169 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
170 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; 167 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
171 BluetoothRemoteGattService* service2 = device2->GetGattServices()[0]; 168 BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
172 BluetoothRemoteGattService* service3 = device2->GetGattServices()[1]; 169 BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
173 // 6 characteristics (same UUID), 2 on each service. 170 // 6 characteristics (same UUID), 2 on each service.
174 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 171 SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
175 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 172 SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
176 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 173 SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
177 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 174 SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
178 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 175 SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
179 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 176 SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
180 BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0]; 177 BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
181 BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1]; 178 BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
182 BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0]; 179 BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
183 BluetoothRemoteGattCharacteristic* char4 = service2->GetCharacteristics()[1]; 180 BluetoothRemoteGattCharacteristic* char4 = service2->GetCharacteristics()[1];
184 BluetoothRemoteGattCharacteristic* char5 = service3->GetCharacteristics()[0]; 181 BluetoothRemoteGattCharacteristic* char5 = service3->GetCharacteristics()[0];
185 BluetoothRemoteGattCharacteristic* char6 = service3->GetCharacteristics()[1]; 182 BluetoothRemoteGattCharacteristic* char6 = service3->GetCharacteristics()[1];
186 183
187 // All IDs are unique, even though they have the same UUID. 184 // All IDs are unique, even though they have the same UUID.
188 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier()); 185 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier());
189 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier()); 186 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier());
(...skipping 23 matching lines...) Expand all
213 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 210 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
214 return; 211 return;
215 } 212 }
216 InitWithFakeAdapter(); 213 InitWithFakeAdapter();
217 StartLowEnergyDiscoverySession(); 214 StartLowEnergyDiscoverySession();
218 BluetoothDevice* device = SimulateLowEnergyDevice(3); 215 BluetoothDevice* device = SimulateLowEnergyDevice(3);
219 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 216 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
220 GetConnectErrorCallback(Call::NOT_EXPECTED)); 217 GetConnectErrorCallback(Call::NOT_EXPECTED));
221 SimulateGattConnection(device); 218 SimulateGattConnection(device);
222 base::RunLoop().RunUntilIdle(); 219 base::RunLoop().RunUntilIdle();
223 std::vector<std::string> services; 220 SimulateGattServicesDiscovered(
224 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 221 device, std::vector<std::string>({kTestUUIDGenericAccess}));
225 SimulateGattServicesDiscovered(device, services);
226 base::RunLoop().RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
227 BluetoothRemoteGattService* service = device->GetGattServices()[0]; 223 BluetoothRemoteGattService* service = device->GetGattServices()[0];
228 224
229 // Create 3 characteristics. Two of them are duplicates. 225 // Create 3 characteristics. Two of them are duplicates.
230 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); 226 BluetoothUUID uuid1(kTestUUIDDeviceName);
231 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); 227 BluetoothUUID uuid2(kTestUUIDAppearance);
232 BluetoothUUID uuid1(uuid_str1); 228 SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
233 BluetoothUUID uuid2(uuid_str2); 229 SimulateGattCharacteristic(service, kTestUUIDAppearance, /* properties */ 0);
234 SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0); 230 SimulateGattCharacteristic(service, kTestUUIDAppearance, /* properties */ 0);
235 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
236 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0);
237 BluetoothRemoteGattCharacteristic* char1 = service->GetCharacteristics()[0]; 231 BluetoothRemoteGattCharacteristic* char1 = service->GetCharacteristics()[0];
238 BluetoothRemoteGattCharacteristic* char2 = service->GetCharacteristics()[1]; 232 BluetoothRemoteGattCharacteristic* char2 = service->GetCharacteristics()[1];
239 BluetoothRemoteGattCharacteristic* char3 = service->GetCharacteristics()[2]; 233 BluetoothRemoteGattCharacteristic* char3 = service->GetCharacteristics()[2];
240 234
241 // Swap as needed to have char1 point to the the characteristic with uuid1. 235 // Swap as needed to have char1 point to the the characteristic with uuid1.
242 if (char2->GetUUID() == uuid1) { 236 if (char2->GetUUID() == uuid1) {
243 std::swap(char1, char2); 237 std::swap(char1, char2);
244 } else if (char3->GetUUID() == uuid1) { 238 } else if (char3->GetUUID() == uuid1) {
245 std::swap(char1, char3); 239 std::swap(char1, char3);
246 } 240 }
(...skipping 10 matching lines...) Expand all
257 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 251 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
258 return; 252 return;
259 } 253 }
260 InitWithFakeAdapter(); 254 InitWithFakeAdapter();
261 StartLowEnergyDiscoverySession(); 255 StartLowEnergyDiscoverySession();
262 BluetoothDevice* device = SimulateLowEnergyDevice(3); 256 BluetoothDevice* device = SimulateLowEnergyDevice(3);
263 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 257 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
264 GetConnectErrorCallback(Call::NOT_EXPECTED)); 258 GetConnectErrorCallback(Call::NOT_EXPECTED));
265 SimulateGattConnection(device); 259 SimulateGattConnection(device);
266 base::RunLoop().RunUntilIdle(); 260 base::RunLoop().RunUntilIdle();
267 std::vector<std::string> services; 261 SimulateGattServicesDiscovered(
268 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); 262 device, std::vector<std::string>({kTestUUIDGenericAccess}));
269 services.push_back(uuid);
270 SimulateGattServicesDiscovered(device, services);
271 base::RunLoop().RunUntilIdle(); 263 base::RunLoop().RunUntilIdle();
272 BluetoothRemoteGattService* service = device->GetGattServices()[0]; 264 BluetoothRemoteGattService* service = device->GetGattServices()[0];
273 265
274 // Create two characteristics with different properties: 266 // Create two characteristics with different properties:
275 SimulateGattCharacteristic(service, uuid, /* properties */ 0); 267 SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0);
276 SimulateGattCharacteristic(service, uuid, /* properties */ 7); 268 SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 7);
277 269
278 // Read the properties. Because ordering is unknown swap as necessary. 270 // Read the properties. Because ordering is unknown swap as necessary.
279 int properties1 = service->GetCharacteristics()[0]->GetProperties(); 271 int properties1 = service->GetCharacteristics()[0]->GetProperties();
280 int properties2 = service->GetCharacteristics()[1]->GetProperties(); 272 int properties2 = service->GetCharacteristics()[1]->GetProperties();
281 if (properties2 == 0) 273 if (properties2 == 0)
282 std::swap(properties1, properties2); 274 std::swap(properties1, properties2);
283 EXPECT_EQ(0, properties1); 275 EXPECT_EQ(0, properties1);
284 EXPECT_EQ(7, properties2); 276 EXPECT_EQ(7, properties2);
285 } 277 }
286 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 278 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
(...skipping 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); 2193 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size());
2202 } 2194 }
2203 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2195 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2204 2196
2205 #if defined(OS_ANDROID) || defined(OS_WIN) 2197 #if defined(OS_ANDROID) || defined(OS_WIN)
2206 TEST_F(BluetoothRemoteGattCharacteristicTest, 2198 TEST_F(BluetoothRemoteGattCharacteristicTest,
2207 GetDescriptors_and_GetDescriptor) { 2199 GetDescriptors_and_GetDescriptor) {
2208 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 2200 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
2209 2201
2210 // Add several Descriptors: 2202 // Add several Descriptors:
2211 BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb"); 2203 BluetoothUUID uuid1(kTestUUIDCharacteristicUserDescription);
2212 BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb"); 2204 BluetoothUUID uuid2(kTestUUIDClientCharacteristicConfiguration);
2213 BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb"); 2205 BluetoothUUID uuid3(kTestUUIDServerCharacteristicConfiguration);
2214 BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb"); 2206 BluetoothUUID uuid4(kTestUUIDCharacteristicPresentationFormat);
2215 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value()); 2207 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value());
2216 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value()); 2208 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value());
2217 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value()); 2209 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value());
2218 SimulateGattDescriptor(characteristic2_, uuid4.canonical_value()); 2210 SimulateGattDescriptor(characteristic2_, uuid4.canonical_value());
2219 2211
2220 // Verify that GetDescriptor can retrieve descriptors again by ID, 2212 // Verify that GetDescriptor can retrieve descriptors again by ID,
2221 // and that the same Descriptor is returned when searched by ID. 2213 // and that the same Descriptor is returned when searched by ID.
2222 EXPECT_EQ(2u, characteristic1_->GetDescriptors().size()); 2214 EXPECT_EQ(2u, characteristic1_->GetDescriptors().size());
2223 EXPECT_EQ(2u, characteristic2_->GetDescriptors().size()); 2215 EXPECT_EQ(2u, characteristic2_->GetDescriptors().size());
2224 std::string c1_id1 = characteristic1_->GetDescriptors()[0]->GetIdentifier(); 2216 std::string c1_id1 = characteristic1_->GetDescriptors()[0]->GetIdentifier();
(...skipping 21 matching lines...) Expand all
2246 // ... but not uuid 3 2238 // ... but not uuid 3
2247 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); 2239 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3);
2248 } 2240 }
2249 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2241 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2250 2242
2251 #if defined(OS_ANDROID) || defined(OS_WIN) 2243 #if defined(OS_ANDROID) || defined(OS_WIN)
2252 TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) { 2244 TEST_F(BluetoothRemoteGattCharacteristicTest, GetDescriptorsByUUID) {
2253 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 2245 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
2254 2246
2255 // Add several Descriptors: 2247 // Add several Descriptors:
2256 BluetoothUUID id1("11111111-0000-1000-8000-00805f9b34fb"); 2248 BluetoothUUID id1(kTestUUIDCharacteristicUserDescription);
2257 BluetoothUUID id2("22222222-0000-1000-8000-00805f9b34fb"); 2249 BluetoothUUID id2(kTestUUIDClientCharacteristicConfiguration);
2258 BluetoothUUID id3("33333333-0000-1000-8000-00805f9b34fb"); 2250 BluetoothUUID id3(kTestUUIDServerCharacteristicConfiguration);
2259 SimulateGattDescriptor(characteristic1_, id1.canonical_value()); 2251 SimulateGattDescriptor(characteristic1_, id1.canonical_value());
2260 SimulateGattDescriptor(characteristic1_, id2.canonical_value()); 2252 SimulateGattDescriptor(characteristic1_, id2.canonical_value());
2261 SimulateGattDescriptor(characteristic2_, id3.canonical_value()); 2253 SimulateGattDescriptor(characteristic2_, id3.canonical_value());
2262 SimulateGattDescriptor(characteristic2_, id3.canonical_value()); 2254 SimulateGattDescriptor(characteristic2_, id3.canonical_value());
2263 2255
2264 EXPECT_NE(characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetIdentifier(), 2256 EXPECT_NE(characteristic2_->GetDescriptorsByUUID(id3).at(0)->GetIdentifier(),
2265 characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetIdentifier()); 2257 characteristic2_->GetDescriptorsByUUID(id3).at(1)->GetIdentifier());
2266 2258
2267 EXPECT_EQ(id1, characteristic1_->GetDescriptorsByUUID(id1).at(0)->GetUUID()); 2259 EXPECT_EQ(id1, characteristic1_->GetDescriptorsByUUID(id1).at(0)->GetUUID());
2268 EXPECT_EQ(id2, characteristic1_->GetDescriptorsByUUID(id2).at(0)->GetUUID()); 2260 EXPECT_EQ(id2, characteristic1_->GetDescriptorsByUUID(id2).at(0)->GetUUID());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 2384 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2393 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY)); 2385 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY));
2394 2386
2395 SimulateGattDisconnection(device_); 2387 SimulateGattDisconnection(device_);
2396 // Don't run the disconnect task. 2388 // Don't run the disconnect task.
2397 notify_sessions_.clear(); 2389 notify_sessions_.clear();
2398 base::RunLoop().RunUntilIdle(); 2390 base::RunLoop().RunUntilIdle();
2399 } 2391 }
2400 #endif 2392 #endif
2401 } // namespace device 2393 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_unittest.cc ('k') | device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698