| OLD | NEW |
| 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_characteristic.h" | 5 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 6 | 6 |
| 7 #include "device/bluetooth/bluetooth_gatt_service.h" | 7 #include "device/bluetooth/bluetooth_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 28 matching lines...) Expand all Loading... |
| 39 std::vector<std::string> services; | 39 std::vector<std::string> services; |
| 40 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; | 40 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; |
| 41 services.push_back(uuid); | 41 services.push_back(uuid); |
| 42 SimulateGattServicesDiscovered(device1, services); | 42 SimulateGattServicesDiscovered(device1, services); |
| 43 services.push_back(uuid); | 43 services.push_back(uuid); |
| 44 SimulateGattServicesDiscovered(device2, services); | 44 SimulateGattServicesDiscovered(device2, services); |
| 45 BluetoothGattService* service1 = device1->GetGattServices()[0]; | 45 BluetoothGattService* service1 = device1->GetGattServices()[0]; |
| 46 BluetoothGattService* service2 = device2->GetGattServices()[0]; | 46 BluetoothGattService* service2 = device2->GetGattServices()[0]; |
| 47 BluetoothGattService* service3 = device2->GetGattServices()[1]; | 47 BluetoothGattService* service3 = device2->GetGattServices()[1]; |
| 48 // 6 characteristics (same UUID), 2 on each service. | 48 // 6 characteristics (same UUID), 2 on each service. |
| 49 SimulateGattCharacteristic(service1, uuid); | 49 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); |
| 50 SimulateGattCharacteristic(service1, uuid); | 50 SimulateGattCharacteristic(service1, uuid, /* properties */ 0); |
| 51 SimulateGattCharacteristic(service2, uuid); | 51 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); |
| 52 SimulateGattCharacteristic(service2, uuid); | 52 SimulateGattCharacteristic(service2, uuid, /* properties */ 0); |
| 53 SimulateGattCharacteristic(service3, uuid); | 53 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); |
| 54 SimulateGattCharacteristic(service3, uuid); | 54 SimulateGattCharacteristic(service3, uuid, /* properties */ 0); |
| 55 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; | 55 BluetoothGattCharacteristic* char1 = service1->GetCharacteristics()[0]; |
| 56 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; | 56 BluetoothGattCharacteristic* char2 = service1->GetCharacteristics()[1]; |
| 57 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; | 57 BluetoothGattCharacteristic* char3 = service2->GetCharacteristics()[0]; |
| 58 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1]; | 58 BluetoothGattCharacteristic* char4 = service2->GetCharacteristics()[1]; |
| 59 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0]; | 59 BluetoothGattCharacteristic* char5 = service3->GetCharacteristics()[0]; |
| 60 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1]; | 60 BluetoothGattCharacteristic* char6 = service3->GetCharacteristics()[1]; |
| 61 | 61 |
| 62 // All IDs are unique, even though they have the same UUID. | 62 // All IDs are unique, even though they have the same UUID. |
| 63 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier()); | 63 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier()); |
| 64 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier()); | 64 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 std::vector<std::string> services; | 93 std::vector<std::string> services; |
| 94 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 94 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
| 95 SimulateGattServicesDiscovered(device, services); | 95 SimulateGattServicesDiscovered(device, services); |
| 96 BluetoothGattService* service = device->GetGattServices()[0]; | 96 BluetoothGattService* service = device->GetGattServices()[0]; |
| 97 | 97 |
| 98 // Create 3 characteristics. Two of them are duplicates. | 98 // Create 3 characteristics. Two of them are duplicates. |
| 99 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); | 99 std::string uuid_str1("11111111-0000-1000-8000-00805f9b34fb"); |
| 100 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); | 100 std::string uuid_str2("22222222-0000-1000-8000-00805f9b34fb"); |
| 101 BluetoothUUID uuid1(uuid_str1); | 101 BluetoothUUID uuid1(uuid_str1); |
| 102 BluetoothUUID uuid2(uuid_str2); | 102 BluetoothUUID uuid2(uuid_str2); |
| 103 SimulateGattCharacteristic(service, uuid_str1); | 103 SimulateGattCharacteristic(service, uuid_str1, /* properties */ 0); |
| 104 SimulateGattCharacteristic(service, uuid_str2); | 104 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); |
| 105 SimulateGattCharacteristic(service, uuid_str2); | 105 SimulateGattCharacteristic(service, uuid_str2, /* properties */ 0); |
| 106 BluetoothGattCharacteristic* char1 = service->GetCharacteristics()[0]; | 106 BluetoothGattCharacteristic* char1 = service->GetCharacteristics()[0]; |
| 107 BluetoothGattCharacteristic* char2 = service->GetCharacteristics()[1]; | 107 BluetoothGattCharacteristic* char2 = service->GetCharacteristics()[1]; |
| 108 BluetoothGattCharacteristic* char3 = service->GetCharacteristics()[2]; | 108 BluetoothGattCharacteristic* char3 = service->GetCharacteristics()[2]; |
| 109 | 109 |
| 110 // Swap as needed to have char1 point to the the characteristic with uuid1. | 110 // Swap as needed to have char1 point to the the characteristic with uuid1. |
| 111 if (char2->GetUUID() == uuid1) { | 111 if (char2->GetUUID() == uuid1) { |
| 112 std::swap(char1, char2); | 112 std::swap(char1, char2); |
| 113 } else if (char3->GetUUID() == uuid1) { | 113 } else if (char3->GetUUID() == uuid1) { |
| 114 std::swap(char1, char3); | 114 std::swap(char1, char3); |
| 115 } | 115 } |
| 116 | 116 |
| 117 EXPECT_EQ(uuid1, char1->GetUUID()); | 117 EXPECT_EQ(uuid1, char1->GetUUID()); |
| 118 EXPECT_EQ(uuid2, char2->GetUUID()); | 118 EXPECT_EQ(uuid2, char2->GetUUID()); |
| 119 EXPECT_EQ(uuid2, char3->GetUUID()); | 119 EXPECT_EQ(uuid2, char3->GetUUID()); |
| 120 } | 120 } |
| 121 #endif // defined(OS_ANDROID) | 121 #endif // defined(OS_ANDROID) |
| 122 | 122 |
| 123 #if defined(OS_ANDROID) |
| 124 TEST_F(BluetoothGattCharacteristicTest, GetProperties) { |
| 125 InitWithFakeAdapter(); |
| 126 StartLowEnergyDiscoverySession(); |
| 127 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 128 device->CreateGattConnection(GetGattConnectionCallback(), |
| 129 GetConnectErrorCallback()); |
| 130 SimulateGattConnection(device); |
| 131 std::vector<std::string> services; |
| 132 std::string uuid("00000000-0000-1000-8000-00805f9b34fb"); |
| 133 services.push_back(uuid); |
| 134 SimulateGattServicesDiscovered(device, services); |
| 135 BluetoothGattService* service = device->GetGattServices()[0]; |
| 136 |
| 137 // Create two characteristics with different properties: |
| 138 SimulateGattCharacteristic(service, uuid, /* properties */ 0); |
| 139 SimulateGattCharacteristic(service, uuid, /* properties */ 7); |
| 140 |
| 141 // Read the properties. Because ordering is unknown swap as necessary. |
| 142 int properties1 = service->GetCharacteristics()[0]->GetProperties(); |
| 143 int properties2 = service->GetCharacteristics()[1]->GetProperties(); |
| 144 if (properties2 == 0) |
| 145 std::swap(properties1, properties2); |
| 146 EXPECT_EQ(0, properties1); |
| 147 EXPECT_EQ(7, properties2); |
| 148 } |
| 149 #endif // defined(OS_ANDROID) |
| 150 |
| 123 } // namespace device | 151 } // namespace device |
| OLD | NEW |