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

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

Issue 2798193002: Use test UUIDs for device bluetooth unit tests (Closed)
Patch Set: use test UUIDs for device bluetooth unit tests 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 6 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
7 #include "device/bluetooth/bluetooth_remote_gatt_service.h" 7 #include "device/bluetooth/bluetooth_remote_gatt_service.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #if defined(OS_ANDROID) 10 #if defined(OS_ANDROID)
(...skipping 11 matching lines...) Expand all
22 // descriptor1_, & descriptor2_. 22 // descriptor1_, & descriptor2_.
23 void FakeDescriptorBoilerplate() { 23 void FakeDescriptorBoilerplate() {
24 InitWithFakeAdapter(); 24 InitWithFakeAdapter();
25 StartLowEnergyDiscoverySession(); 25 StartLowEnergyDiscoverySession();
26 device_ = SimulateLowEnergyDevice(3); 26 device_ = SimulateLowEnergyDevice(3);
27 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 27 device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
28 GetConnectErrorCallback(Call::NOT_EXPECTED)); 28 GetConnectErrorCallback(Call::NOT_EXPECTED));
29 SimulateGattConnection(device_); 29 SimulateGattConnection(device_);
30 base::RunLoop().RunUntilIdle(); 30 base::RunLoop().RunUntilIdle();
31 std::vector<std::string> services; 31 std::vector<std::string> services;
32 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); 32 services.push_back(kTestUUIDGenericAccess);
33 services.push_back(uuid);
34 SimulateGattServicesDiscovered(device_, services); 33 SimulateGattServicesDiscovered(device_, services);
35 base::RunLoop().RunUntilIdle(); 34 base::RunLoop().RunUntilIdle();
36 ASSERT_EQ(1u, device_->GetGattServices().size()); 35 ASSERT_EQ(1u, device_->GetGattServices().size());
37 service_ = device_->GetGattServices()[0]; 36 service_ = device_->GetGattServices()[0];
38 SimulateGattCharacteristic(service_, uuid, 0); 37 SimulateGattCharacteristic(service_, kTestUUIDDeviceName, 0);
39 ASSERT_EQ(1u, service_->GetCharacteristics().size()); 38 ASSERT_EQ(1u, service_->GetCharacteristics().size());
40 characteristic_ = service_->GetCharacteristics()[0]; 39 characteristic_ = service_->GetCharacteristics()[0];
41 SimulateGattDescriptor(characteristic_, 40 SimulateGattDescriptor(characteristic_,
42 "00000001-0000-1000-8000-00805f9b34fb"); 41 kTestUUIDCharacteristicUserDescription);
43 SimulateGattDescriptor(characteristic_, 42 SimulateGattDescriptor(characteristic_,
44 "00000002-0000-1000-8000-00805f9b34fb"); 43 kTestUUIDClientCharacteristicConfiguration);
45 ASSERT_EQ(2u, characteristic_->GetDescriptors().size()); 44 ASSERT_EQ(2u, characteristic_->GetDescriptors().size());
46 descriptor1_ = characteristic_->GetDescriptors()[0]; 45 descriptor1_ = characteristic_->GetDescriptors()[0];
47 descriptor2_ = characteristic_->GetDescriptors()[1]; 46 descriptor2_ = characteristic_->GetDescriptors()[1];
48 ResetEventCounts(); 47 ResetEventCounts();
49 } 48 }
50 49
51 BluetoothDevice* device_ = nullptr; 50 BluetoothDevice* device_ = nullptr;
52 BluetoothRemoteGattService* service_ = nullptr; 51 BluetoothRemoteGattService* service_ = nullptr;
53 BluetoothRemoteGattCharacteristic* characteristic_ = nullptr; 52 BluetoothRemoteGattCharacteristic* characteristic_ = nullptr;
54 BluetoothRemoteGattDescriptor* descriptor1_ = nullptr; 53 BluetoothRemoteGattDescriptor* descriptor1_ = nullptr;
(...skipping 17 matching lines...) Expand all
72 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 71 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
73 GetConnectErrorCallback(Call::NOT_EXPECTED)); 72 GetConnectErrorCallback(Call::NOT_EXPECTED));
74 SimulateGattConnection(device1); 73 SimulateGattConnection(device1);
75 SimulateGattConnection(device2); 74 SimulateGattConnection(device2);
76 base::RunLoop().RunUntilIdle(); 75 base::RunLoop().RunUntilIdle();
77 76
78 // 3 services (all with same UUID). 77 // 3 services (all with same UUID).
79 // 1 on the first device (to test characteristic instances across devices). 78 // 1 on the first device (to test characteristic instances across devices).
80 // 2 on the second device (to test same device, multiple service instances). 79 // 2 on the second device (to test same device, multiple service instances).
81 std::vector<std::string> services; 80 std::vector<std::string> services;
82 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; 81 services.push_back(kTestUUIDGenericAccess);
83 services.push_back(uuid);
84 SimulateGattServicesDiscovered(device1, services); 82 SimulateGattServicesDiscovered(device1, services);
85 base::RunLoop().RunUntilIdle(); 83 base::RunLoop().RunUntilIdle();
86 services.push_back(uuid); 84 services.push_back(kTestUUIDGenericAccess);
87 SimulateGattServicesDiscovered(device2, services); 85 SimulateGattServicesDiscovered(device2, services);
88 base::RunLoop().RunUntilIdle(); 86 base::RunLoop().RunUntilIdle();
89 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; 87 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0];
90 BluetoothRemoteGattService* service2 = device2->GetGattServices()[0]; 88 BluetoothRemoteGattService* service2 = device2->GetGattServices()[0];
91 BluetoothRemoteGattService* service3 = device2->GetGattServices()[1]; 89 BluetoothRemoteGattService* service3 = device2->GetGattServices()[1];
92 // 6 characteristics (same UUID), 2 on each service. 90 // 6 characteristics (same UUID), 2 on each service.
93 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 91 SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
94 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); 92 SimulateGattCharacteristic(service1, kTestUUIDDeviceName, /* properties */ 0);
95 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 93 SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
96 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); 94 SimulateGattCharacteristic(service2, kTestUUIDDeviceName, /* properties */ 0);
97 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 95 SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
98 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); 96 SimulateGattCharacteristic(service3, kTestUUIDDeviceName, /* properties */ 0);
99 BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0]; 97 BluetoothRemoteGattCharacteristic* char1 = service1->GetCharacteristics()[0];
100 BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1]; 98 BluetoothRemoteGattCharacteristic* char2 = service1->GetCharacteristics()[1];
101 BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0]; 99 BluetoothRemoteGattCharacteristic* char3 = service2->GetCharacteristics()[0];
102 BluetoothRemoteGattCharacteristic* char4 = service2->GetCharacteristics()[1]; 100 BluetoothRemoteGattCharacteristic* char4 = service2->GetCharacteristics()[1];
103 BluetoothRemoteGattCharacteristic* char5 = service3->GetCharacteristics()[0]; 101 BluetoothRemoteGattCharacteristic* char5 = service3->GetCharacteristics()[0];
104 BluetoothRemoteGattCharacteristic* char6 = service3->GetCharacteristics()[1]; 102 BluetoothRemoteGattCharacteristic* char6 = service3->GetCharacteristics()[1];
105 // 6 descriptors (same UUID), 1 on each characteristic 103 // 6 descriptors (same UUID), 1 on each characteristic
106 // TODO(576900) Test multiple descriptors with same UUID on one 104 // TODO(576900) Test multiple descriptors with same UUID on one
107 // characteristic. 105 // characteristic.
108 SimulateGattDescriptor(char1, uuid); 106 SimulateGattDescriptor(char1, kTestUUIDCharacteristicUserDescription);
109 SimulateGattDescriptor(char2, uuid); 107 SimulateGattDescriptor(char2, kTestUUIDCharacteristicUserDescription);
110 SimulateGattDescriptor(char3, uuid); 108 SimulateGattDescriptor(char3, kTestUUIDCharacteristicUserDescription);
111 SimulateGattDescriptor(char4, uuid); 109 SimulateGattDescriptor(char4, kTestUUIDCharacteristicUserDescription);
112 SimulateGattDescriptor(char5, uuid); 110 SimulateGattDescriptor(char5, kTestUUIDCharacteristicUserDescription);
113 SimulateGattDescriptor(char6, uuid); 111 SimulateGattDescriptor(char6, kTestUUIDCharacteristicUserDescription);
114 BluetoothRemoteGattDescriptor* desc1 = char1->GetDescriptors()[0]; 112 BluetoothRemoteGattDescriptor* desc1 = char1->GetDescriptors()[0];
115 BluetoothRemoteGattDescriptor* desc2 = char2->GetDescriptors()[0]; 113 BluetoothRemoteGattDescriptor* desc2 = char2->GetDescriptors()[0];
116 BluetoothRemoteGattDescriptor* desc3 = char3->GetDescriptors()[0]; 114 BluetoothRemoteGattDescriptor* desc3 = char3->GetDescriptors()[0];
117 BluetoothRemoteGattDescriptor* desc4 = char4->GetDescriptors()[0]; 115 BluetoothRemoteGattDescriptor* desc4 = char4->GetDescriptors()[0];
118 BluetoothRemoteGattDescriptor* desc5 = char5->GetDescriptors()[0]; 116 BluetoothRemoteGattDescriptor* desc5 = char5->GetDescriptors()[0];
119 BluetoothRemoteGattDescriptor* desc6 = char6->GetDescriptors()[0]; 117 BluetoothRemoteGattDescriptor* desc6 = char6->GetDescriptors()[0];
120 118
121 // All IDs are unique. 119 // All IDs are unique.
122 EXPECT_NE(desc1->GetIdentifier(), desc2->GetIdentifier()); 120 EXPECT_NE(desc1->GetIdentifier(), desc2->GetIdentifier());
123 EXPECT_NE(desc1->GetIdentifier(), desc3->GetIdentifier()); 121 EXPECT_NE(desc1->GetIdentifier(), desc3->GetIdentifier());
(...skipping 23 matching lines...) Expand all
147 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 145 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
148 return; 146 return;
149 } 147 }
150 InitWithFakeAdapter(); 148 InitWithFakeAdapter();
151 StartLowEnergyDiscoverySession(); 149 StartLowEnergyDiscoverySession();
152 BluetoothDevice* device = SimulateLowEnergyDevice(3); 150 BluetoothDevice* device = SimulateLowEnergyDevice(3);
153 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 151 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
154 GetConnectErrorCallback(Call::NOT_EXPECTED)); 152 GetConnectErrorCallback(Call::NOT_EXPECTED));
155 SimulateGattConnection(device); 153 SimulateGattConnection(device);
156 std::vector<std::string> services; 154 std::vector<std::string> services;
157 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 155 services.push_back(kTestUUIDGenericAccess);
158 SimulateGattServicesDiscovered(device, services); 156 SimulateGattServicesDiscovered(device, services);
159 base::RunLoop().RunUntilIdle(); 157 base::RunLoop().RunUntilIdle();
160 ASSERT_EQ(1u, device->GetGattServices().size()); 158 ASSERT_EQ(1u, device->GetGattServices().size());
161 BluetoothRemoteGattService* service = device->GetGattServices()[0]; 159 BluetoothRemoteGattService* service = device->GetGattServices()[0];
162 160
163 SimulateGattCharacteristic(service, "00000000-0000-1000-8000-00805f9b34fb", 161 SimulateGattCharacteristic(service, kTestUUIDDeviceName,
164 /* properties */ 0); 162 /* properties */ 0);
165 ASSERT_EQ(1u, service->GetCharacteristics().size()); 163 ASSERT_EQ(1u, service->GetCharacteristics().size());
166 BluetoothRemoteGattCharacteristic* characteristic = 164 BluetoothRemoteGattCharacteristic* characteristic =
167 service->GetCharacteristics()[0]; 165 service->GetCharacteristics()[0];
168 166
169 // Create 2 descriptors. 167 // Create 2 descriptors.
170 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); 168 BluetoothUUID uuid1(kTestUUIDCharacteristicUserDescription);
171 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); 169 BluetoothUUID uuid2(kTestUUIDClientCharacteristicConfiguration);
172 BluetoothUUID uuid1(uuid_str1); 170 SimulateGattDescriptor(characteristic,
173 BluetoothUUID uuid2(uuid_str2); 171 kTestUUIDCharacteristicUserDescription);
174 SimulateGattDescriptor(characteristic, uuid_str1); 172 SimulateGattDescriptor(characteristic,
175 SimulateGattDescriptor(characteristic, uuid_str2); 173 kTestUUIDClientCharacteristicConfiguration);
176 ASSERT_EQ(2u, characteristic->GetDescriptors().size()); 174 ASSERT_EQ(2u, characteristic->GetDescriptors().size());
177 BluetoothRemoteGattDescriptor* descriptor1 = 175 BluetoothRemoteGattDescriptor* descriptor1 =
178 characteristic->GetDescriptors()[0]; 176 characteristic->GetDescriptors()[0];
179 BluetoothRemoteGattDescriptor* descriptor2 = 177 BluetoothRemoteGattDescriptor* descriptor2 =
180 characteristic->GetDescriptors()[1]; 178 characteristic->GetDescriptors()[1];
181 179
182 // Swap as needed to have descriptor1 be the one with uuid1. 180 // Swap as needed to have descriptor1 be the one with uuid1.
183 if (descriptor2->GetUUID() == uuid1) 181 if (descriptor2->GetUUID() == uuid1)
184 std::swap(descriptor1, descriptor2); 182 std::swap(descriptor1, descriptor2);
185 183
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED), 681 std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED),
684 // TODO(crbug.com/621901): Expect an error. 682 // TODO(crbug.com/621901): Expect an error.
685 GetGattErrorCallback(Call::NOT_EXPECTED)); 683 GetGattErrorCallback(Call::NOT_EXPECTED));
686 684
687 base::RunLoop().RunUntilIdle(); 685 base::RunLoop().RunUntilIdle();
688 // TODO(crbug.com/621901): Test that an error was returned. 686 // TODO(crbug.com/621901): Test that an error was returned.
689 } 687 }
690 #endif // defined(OS_ANDROID) 688 #endif // defined(OS_ANDROID)
691 689
692 } // namespace device 690 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698