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

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

Issue 1950033002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@servicescan_cleanup
Patch Set: Fixing the build Created 4 years, 6 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 "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"
11 11
12 #if defined(OS_ANDROID) 12 #if defined(OS_ANDROID)
13 #include "device/bluetooth/test/bluetooth_test_android.h" 13 #include "device/bluetooth/test/bluetooth_test_android.h"
14 #elif defined(OS_MACOSX) 14 #elif defined(OS_MACOSX)
15 #include "device/bluetooth/test/bluetooth_test_mac.h" 15 #include "device/bluetooth/test/bluetooth_test_mac.h"
16 #elif defined(OS_WIN) 16 #elif defined(OS_WIN)
17 #include "device/bluetooth/test/bluetooth_test_win.h" 17 #include "device/bluetooth/test/bluetooth_test_win.h"
18 #endif 18 #endif
19 19
20 namespace device { 20 namespace device {
21 21
22 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 22 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
23 class BluetoothRemoteGattServiceTest : public BluetoothTest {}; 23 class BluetoothRemoteGattServiceTest : public BluetoothTest {};
24 #endif 24 #endif
25 25
26 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) 26 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
27 TEST_F(BluetoothRemoteGattServiceTest, GetIdentifier) { 27 TEST_F(BluetoothRemoteGattServiceTest, GetIdentifier) {
28 if (!PlatformSupportsLowEnergy()) { 28 if (!PlatformSupportsLowEnergy()) {
29 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 29 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
30 return; 30 return;
31 } 31 }
32 InitWithFakeAdapter(); 32 InitWithFakeAdapter();
33 StartLowEnergyDiscoverySession(); 33 StartLowEnergyDiscoverySession();
34 // 2 devices to verify unique IDs across them. 34 // 2 devices to verify unique IDs across them.
35 BluetoothDevice* device1 = SimulateLowEnergyDevice(3); 35 BluetoothDevice* device1 = SimulateLowEnergyDevice(3);
36 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); 36 BluetoothDevice* device2 = SimulateLowEnergyDevice(4);
(...skipping 19 matching lines...) Expand all
56 // All IDs are unique, even though they have the same UUID. 56 // All IDs are unique, even though they have the same UUID.
57 EXPECT_NE(service1->GetIdentifier(), service2->GetIdentifier()); 57 EXPECT_NE(service1->GetIdentifier(), service2->GetIdentifier());
58 EXPECT_NE(service1->GetIdentifier(), service3->GetIdentifier()); 58 EXPECT_NE(service1->GetIdentifier(), service3->GetIdentifier());
59 EXPECT_NE(service1->GetIdentifier(), service4->GetIdentifier()); 59 EXPECT_NE(service1->GetIdentifier(), service4->GetIdentifier());
60 60
61 EXPECT_NE(service2->GetIdentifier(), service3->GetIdentifier()); 61 EXPECT_NE(service2->GetIdentifier(), service3->GetIdentifier());
62 EXPECT_NE(service2->GetIdentifier(), service4->GetIdentifier()); 62 EXPECT_NE(service2->GetIdentifier(), service4->GetIdentifier());
63 63
64 EXPECT_NE(service3->GetIdentifier(), service4->GetIdentifier()); 64 EXPECT_NE(service3->GetIdentifier(), service4->GetIdentifier());
65 } 65 }
66 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) 66 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
67 67
68 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) 68 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
69 TEST_F(BluetoothRemoteGattServiceTest, GetUUID) { 69 TEST_F(BluetoothRemoteGattServiceTest, GetUUID) {
70 if (!PlatformSupportsLowEnergy()) { 70 if (!PlatformSupportsLowEnergy()) {
71 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 71 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
72 return; 72 return;
73 } 73 }
74 InitWithFakeAdapter(); 74 InitWithFakeAdapter();
75 StartLowEnergyDiscoverySession(); 75 StartLowEnergyDiscoverySession();
76 BluetoothDevice* device = SimulateLowEnergyDevice(3); 76 BluetoothDevice* device = SimulateLowEnergyDevice(3);
77 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 77 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
78 GetConnectErrorCallback(Call::NOT_EXPECTED)); 78 GetConnectErrorCallback(Call::NOT_EXPECTED));
79 SimulateGattConnection(device); 79 SimulateGattConnection(device);
80 80
81 // Create multiple instances with the same UUID. 81 // Create multiple instances with the same UUID.
82 BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); 82 BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb");
83 std::vector<std::string> services; 83 std::vector<std::string> services;
84 services.push_back(uuid.canonical_value()); 84 services.push_back(uuid.canonical_value());
85 services.push_back(uuid.canonical_value()); 85 services.push_back(uuid.canonical_value());
86 SimulateGattServicesDiscovered(device, services); 86 SimulateGattServicesDiscovered(device, services);
87 87
88 // Each has the same UUID. 88 // Each has the same UUID.
89 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); 89 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID());
90 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); 90 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID());
91 } 91 }
92 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) 92 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
93 93
94 #if defined(OS_ANDROID) || defined(OS_WIN) 94 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
95 TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) { 95 TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) {
96 if (!PlatformSupportsLowEnergy()) { 96 if (!PlatformSupportsLowEnergy()) {
97 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 97 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
98 return; 98 return;
99 } 99 }
100 InitWithFakeAdapter(); 100 InitWithFakeAdapter();
101 StartLowEnergyDiscoverySession(); 101 StartLowEnergyDiscoverySession();
102 BluetoothDevice* device = SimulateLowEnergyDevice(3); 102 BluetoothDevice* device = SimulateLowEnergyDevice(3);
103 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 103 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
104 GetConnectErrorCallback(Call::NOT_EXPECTED)); 104 GetConnectErrorCallback(Call::NOT_EXPECTED));
105 SimulateGattConnection(device); 105 SimulateGattConnection(device);
106 106
107 // Simulate a service, with no Characteristics: 107 // Simulate a service, with no Characteristics:
108 std::vector<std::string> services; 108 std::vector<std::string> services;
109 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 109 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
110 SimulateGattServicesDiscovered(device, services); 110 SimulateGattServicesDiscovered(device, services);
111 BluetoothRemoteGattService* service = device->GetGattServices()[0]; 111 BluetoothRemoteGattService* service = device->GetGattServices()[0];
112 112
113 EXPECT_EQ(0u, service->GetCharacteristics().size()); 113 EXPECT_EQ(0u, service->GetCharacteristics().size());
114 } 114 }
115 #endif // defined(OS_ANDROID) || defined(OS_WIN) 115 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
116 116
117 #if defined(OS_ANDROID) || defined(OS_WIN) 117 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
118 TEST_F(BluetoothRemoteGattServiceTest, 118 TEST_F(BluetoothRemoteGattServiceTest,
119 GetCharacteristics_and_GetCharacteristic) { 119 GetCharacteristics_and_GetCharacteristic) {
120 if (!PlatformSupportsLowEnergy()) {
121 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
122 return;
123 }
120 InitWithFakeAdapter(); 124 InitWithFakeAdapter();
121 StartLowEnergyDiscoverySession(); 125 StartLowEnergyDiscoverySession();
122 BluetoothDevice* device = SimulateLowEnergyDevice(3); 126 BluetoothDevice* device = SimulateLowEnergyDevice(3);
123 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 127 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
124 GetConnectErrorCallback(Call::NOT_EXPECTED)); 128 GetConnectErrorCallback(Call::NOT_EXPECTED));
125 SimulateGattConnection(device); 129 SimulateGattConnection(device);
126 130
127 // Simulate a service, with several Characteristics: 131 // Simulate a service, with several Characteristics:
128 std::vector<std::string> services; 132 std::vector<std::string> services;
129 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 133 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
(...skipping 24 matching lines...) Expand all
154 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID()); 158 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID());
155 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID()); 159 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID());
156 160
157 // GetCharacteristics & GetCharacteristic return the same object for the same 161 // GetCharacteristics & GetCharacteristic return the same object for the same
158 // ID: 162 // ID:
159 EXPECT_EQ(service->GetCharacteristics()[0], 163 EXPECT_EQ(service->GetCharacteristics()[0],
160 service->GetCharacteristic(char_id1)); 164 service->GetCharacteristic(char_id1));
161 EXPECT_EQ(service->GetCharacteristic(char_id1), 165 EXPECT_EQ(service->GetCharacteristic(char_id1),
162 service->GetCharacteristic(char_id1)); 166 service->GetCharacteristic(char_id1));
163 } 167 }
164 #endif // defined(OS_ANDROID) || defined(OS_WIN) 168 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
165 169
166 #if defined(OS_WIN) 170 #if defined(OS_MACOSX) || defined(OS_WIN)
167 TEST_F(BluetoothRemoteGattServiceTest, 171 TEST_F(BluetoothRemoteGattServiceTest,
168 GetCharacteristic_CharacteristicRemoved) { 172 GetCharacteristic_CharacteristicRemoved) {
173 if (!PlatformSupportsLowEnergy()) {
174 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
175 return;
176 }
169 InitWithFakeAdapter(); 177 InitWithFakeAdapter();
170 StartLowEnergyDiscoverySession(); 178 StartLowEnergyDiscoverySession();
171 BluetoothDevice* device = SimulateLowEnergyDevice(3); 179 BluetoothDevice* device = SimulateLowEnergyDevice(3);
172 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 180 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
173 GetConnectErrorCallback(Call::NOT_EXPECTED)); 181 GetConnectErrorCallback(Call::NOT_EXPECTED));
174 SimulateGattConnection(device); 182 SimulateGattConnection(device);
175 183
176 TestBluetoothAdapterObserver observer(adapter_); 184 TestBluetoothAdapterObserver observer(adapter_);
177 185
178 // Simulate a service, with several Characteristics: 186 // Simulate a service, with several Characteristics:
(...skipping 30 matching lines...) Expand all
209 EXPECT_EQ(3, observer.gatt_characteristic_removed_count()); 217 EXPECT_EQ(3, observer.gatt_characteristic_removed_count());
210 EXPECT_FALSE(service->GetCharacteristic(removed_char)); 218 EXPECT_FALSE(service->GetCharacteristic(removed_char));
211 EXPECT_EQ(1u, service->GetCharacteristics().size()); 219 EXPECT_EQ(1u, service->GetCharacteristics().size());
212 removed_char = service->GetCharacteristics()[0]->GetIdentifier(); 220 removed_char = service->GetCharacteristics()[0]->GetIdentifier();
213 SimulateGattCharacteristicRemoved(service, 221 SimulateGattCharacteristicRemoved(service,
214 service->GetCharacteristic(removed_char)); 222 service->GetCharacteristic(removed_char));
215 EXPECT_EQ(4, observer.gatt_characteristic_removed_count()); 223 EXPECT_EQ(4, observer.gatt_characteristic_removed_count());
216 EXPECT_FALSE(service->GetCharacteristic(removed_char)); 224 EXPECT_FALSE(service->GetCharacteristic(removed_char));
217 EXPECT_EQ(0u, service->GetCharacteristics().size()); 225 EXPECT_EQ(0u, service->GetCharacteristics().size());
218 226
227 #if defined(OS_MACOSX)
228 // SimulateGattServicesDiscovered
229 // 4 * SimulateGattCharacteristic
230 // 4 * SimulateGattCharacteristicRemoved
231 EXPECT_EQ(9, observer.gatt_service_changed_count());
232 #else // defined(OS_MACOSX)
219 EXPECT_EQ(4, observer.gatt_service_changed_count()); 233 EXPECT_EQ(4, observer.gatt_service_changed_count());
234 #endif // defined(OS_MACOSX)
220 } 235 }
221 #endif // defined(OS_WIN) 236 #endif // defined(OS_MACOSX) || defined(OS_WIN)
222 237
223 #if defined(OS_WIN) || defined(OS_MACOSX) 238 #if defined(OS_WIN) || defined(OS_MACOSX)
224 TEST_F(BluetoothRemoteGattServiceTest, SimulateGattServiceRemove) { 239 TEST_F(BluetoothRemoteGattServiceTest, SimulateGattServiceRemove) {
225 if (!PlatformSupportsLowEnergy()) { 240 if (!PlatformSupportsLowEnergy()) {
226 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 241 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
227 return; 242 return;
228 } 243 }
229 InitWithFakeAdapter(); 244 InitWithFakeAdapter();
230 StartLowEnergyDiscoverySession(); 245 StartLowEnergyDiscoverySession();
231 BluetoothDevice* device = SimulateLowEnergyDevice(3); 246 BluetoothDevice* device = SimulateLowEnergyDevice(3);
(...skipping 16 matching lines...) Expand all
248 std::string removed_service = service1->GetIdentifier(); 263 std::string removed_service = service1->GetIdentifier();
249 SimulateGattServiceRemoved(device->GetGattService(removed_service)); 264 SimulateGattServiceRemoved(device->GetGattService(removed_service));
250 EXPECT_EQ(1, observer.gatt_service_removed_count()); 265 EXPECT_EQ(1, observer.gatt_service_removed_count());
251 EXPECT_EQ(1u, device->GetGattServices().size()); 266 EXPECT_EQ(1u, device->GetGattServices().size());
252 EXPECT_FALSE(device->GetGattService(removed_service)); 267 EXPECT_FALSE(device->GetGattService(removed_service));
253 EXPECT_EQ(device->GetGattServices()[0], service2); 268 EXPECT_EQ(device->GetGattServices()[0], service2);
254 } 269 }
255 #endif // defined(OS_WIN) || defined(OS_MACOSX) 270 #endif // defined(OS_WIN) || defined(OS_MACOSX)
256 271
257 } // namespace device 272 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_mac.mm ('k') | device/bluetooth/test/bluetooth_test_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698