Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/run_loop.h" | |
| 6 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | |
| 7 #include "device/bluetooth/bluetooth_gatt_service.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 #if defined(OS_ANDROID) | |
| 11 #include "device/bluetooth/test/bluetooth_test_android.h" | |
| 12 #elif defined(OS_MACOSX) | |
| 13 #include "device/bluetooth/test/bluetooth_test_mac.h" | |
| 14 #endif | |
| 15 | |
| 16 namespace device { | |
| 17 | |
| 18 #if defined(OS_ANDROID) || defined(OS_MACOSX) | |
| 19 class BluetoothGattDescriptorTest : public BluetoothTest {}; | |
| 20 #endif | |
| 21 | |
| 22 #if defined(OS_ANDROID) | |
| 23 TEST_F(BluetoothGattDescriptorTest, GetIdentifier) { | |
| 24 InitWithFakeAdapter(); | |
| 25 StartLowEnergyDiscoverySession(); | |
| 26 // 2 devices to verify unique IDs across them. | |
|
Jeffrey Yasskin
2016/01/12 21:53:54
s/verify unique IDs across them/verify that descri
scheib
2016/01/12 23:16:55
Done.
| |
| 27 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3); | |
| 28 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4); | |
| 29 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 30 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 31 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 32 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 33 SimulateGattConnection(device1); | |
| 34 SimulateGattConnection(device2); | |
| 35 | |
| 36 // 3 services (all with same UUID). | |
| 37 // 1 on the first device (to test characteristic instances across devices). | |
| 38 // 2 on the second device (to test same device, multiple service instances). | |
| 39 std::vector<std::string> services; | |
| 40 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; | |
| 41 services.push_back(uuid); | |
| 42 SimulateGattServicesDiscovered(device1, services); | |
| 43 services.push_back(uuid); | |
| 44 SimulateGattServicesDiscovered(device2, services); | |
| 45 BluetoothGattService* service1 = device1->GetGattServices()[0]; | |
| 46 BluetoothGattService* service2 = device2->GetGattServices()[0]; | |
| 47 BluetoothGattService* service3 = device2->GetGattServices()[1]; | |
| 48 // 6 characteristics (same UUID), 2 on each service. | |
| 49 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); | |
| 50 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); | |
| 51 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); | |
| 52 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); | |
| 53 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); | |
| 54 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); | |
| 55 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; | |
| 56 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; | |
| 57 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; | |
| 58 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1]; | |
| 59 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0]; | |
| 60 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1]; | |
| 61 // 6 descriptors (same UUID), 1 on each characteristic | |
|
Jeffrey Yasskin
2016/01/12 21:53:54
The Characteristic Presentation Format descriptor
scheib
2016/01/12 23:16:55
TODOs added to code. Though Android doesn't provid
| |
| 62 SimulateGattDescriptor(char1, uuid); | |
| 63 SimulateGattDescriptor(char2, uuid); | |
| 64 SimulateGattDescriptor(char3, uuid); | |
| 65 SimulateGattDescriptor(char4, uuid); | |
| 66 SimulateGattDescriptor(char5, uuid); | |
| 67 SimulateGattDescriptor(char6, uuid); | |
| 68 BluetoothGattDescriptor* desc1 = char1->GetDescriptors()[0]; | |
| 69 BluetoothGattDescriptor* desc2 = char2->GetDescriptors()[0]; | |
| 70 BluetoothGattDescriptor* desc3 = char3->GetDescriptors()[0]; | |
| 71 BluetoothGattDescriptor* desc4 = char4->GetDescriptors()[0]; | |
| 72 BluetoothGattDescriptor* desc5 = char5->GetDescriptors()[0]; | |
| 73 BluetoothGattDescriptor* desc6 = char6->GetDescriptors()[0]; | |
| 74 | |
| 75 // All IDs are unique. | |
| 76 EXPECT_NE(desc1->GetIdentifier(), desc2->GetIdentifier()); | |
| 77 EXPECT_NE(desc1->GetIdentifier(), desc3->GetIdentifier()); | |
| 78 EXPECT_NE(desc1->GetIdentifier(), desc4->GetIdentifier()); | |
| 79 EXPECT_NE(desc1->GetIdentifier(), desc5->GetIdentifier()); | |
| 80 EXPECT_NE(desc1->GetIdentifier(), desc6->GetIdentifier()); | |
| 81 | |
| 82 EXPECT_NE(desc2->GetIdentifier(), desc3->GetIdentifier()); | |
| 83 EXPECT_NE(desc2->GetIdentifier(), desc4->GetIdentifier()); | |
| 84 EXPECT_NE(desc2->GetIdentifier(), desc5->GetIdentifier()); | |
| 85 EXPECT_NE(desc2->GetIdentifier(), desc6->GetIdentifier()); | |
| 86 | |
| 87 EXPECT_NE(desc3->GetIdentifier(), desc4->GetIdentifier()); | |
| 88 EXPECT_NE(desc3->GetIdentifier(), desc5->GetIdentifier()); | |
| 89 EXPECT_NE(desc3->GetIdentifier(), desc6->GetIdentifier()); | |
| 90 | |
| 91 EXPECT_NE(desc4->GetIdentifier(), desc5->GetIdentifier()); | |
| 92 EXPECT_NE(desc4->GetIdentifier(), desc6->GetIdentifier()); | |
| 93 | |
| 94 EXPECT_NE(desc5->GetIdentifier(), desc6->GetIdentifier()); | |
| 95 } | |
| 96 #endif // defined(OS_ANDROID) | |
| 97 | |
| 98 #if defined(OS_ANDROID) | |
| 99 TEST_F(BluetoothGattDescriptorTest, GetUUID) { | |
| 100 InitWithFakeAdapter(); | |
| 101 StartLowEnergyDiscoverySession(); | |
| 102 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | |
| 103 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | |
| 104 GetConnectErrorCallback(Call::NOT_EXPECTED)); | |
| 105 SimulateGattConnection(device); | |
| 106 std::vector<std::string> services; | |
| 107 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | |
| 108 SimulateGattServicesDiscovered(device, services); | |
| 109 ASSERT_EQ(1u, device->GetGattServices().size()); | |
| 110 BluetoothGattService* service = device->GetGattServices()[0]; | |
| 111 | |
| 112 SimulateGattCharacteristic(service, "00000000-0000-1000-8000-00805f9b34fb", | |
| 113 /* properties */ 0); | |
| 114 ASSERT_EQ(1u, service->GetCharacteristics().size()); | |
| 115 BluetoothGattCharacteristic* characteristic = | |
| 116 service->GetCharacteristics()[0]; | |
| 117 | |
| 118 // Create 2 descriptors. | |
| 119 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); | |
| 120 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); | |
| 121 BluetoothUUID uuid1(uuid_str1); | |
| 122 BluetoothUUID uuid2(uuid_str2); | |
| 123 SimulateGattDescriptor(characteristic, uuid_str1); | |
| 124 SimulateGattDescriptor(characteristic, uuid_str2); | |
| 125 ASSERT_EQ(2u, characteristic->GetDescriptors().size()); | |
| 126 BluetoothGattDescriptor* descriptor1 = characteristic->GetDescriptors()[0]; | |
| 127 BluetoothGattDescriptor* descriptor2 = characteristic->GetDescriptors()[1]; | |
| 128 | |
| 129 // Swap as needed to have descriptor1 be the one with uuid1. | |
| 130 if (descriptor2->GetUUID() == uuid1) | |
| 131 std::swap(descriptor1, descriptor2); | |
| 132 | |
| 133 EXPECT_EQ(uuid1, descriptor1->GetUUID()); | |
| 134 EXPECT_EQ(uuid2, descriptor2->GetUUID()); | |
| 135 } | |
| 136 #endif // defined(OS_ANDROID) | |
| 137 | |
| 138 } // namespace device | |
| OLD | NEW |