| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 descriptor2_ = characteristic_->GetDescriptors()[1]; | 45 descriptor2_ = characteristic_->GetDescriptors()[1]; |
| 46 ResetEventCounts(); | 46 ResetEventCounts(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 BluetoothDevice* device_ = nullptr; | 49 BluetoothDevice* device_ = nullptr; |
| 50 BluetoothRemoteGattService* service_ = nullptr; | 50 BluetoothRemoteGattService* service_ = nullptr; |
| 51 BluetoothRemoteGattCharacteristic* characteristic_ = nullptr; | 51 BluetoothRemoteGattCharacteristic* characteristic_ = nullptr; |
| 52 BluetoothRemoteGattDescriptor* descriptor1_ = nullptr; | 52 BluetoothRemoteGattDescriptor* descriptor1_ = nullptr; |
| 53 BluetoothRemoteGattDescriptor* descriptor2_ = nullptr; | 53 BluetoothRemoteGattDescriptor* descriptor2_ = nullptr; |
| 54 }; | 54 }; |
| 55 #endif | 55 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 56 | 56 |
| 57 #if defined(OS_ANDROID) | 57 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 58 TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) { | 58 TEST_F(BluetoothRemoteGattDescriptorTest, GetIdentifier) { |
| 59 if (!PlatformSupportsLowEnergy()) { |
| 60 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 61 return; |
| 62 } |
| 59 InitWithFakeAdapter(); | 63 InitWithFakeAdapter(); |
| 60 StartLowEnergyDiscoverySession(); | 64 StartLowEnergyDiscoverySession(); |
| 61 // 2 devices to verify that descriptors on them have distinct IDs. | 65 // 2 devices to verify that descriptors on them have distinct IDs. |
| 62 BluetoothDevice* device1 = SimulateLowEnergyDevice(3); | 66 BluetoothDevice* device1 = SimulateLowEnergyDevice(3); |
| 63 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); | 67 BluetoothDevice* device2 = SimulateLowEnergyDevice(4); |
| 64 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 68 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 65 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 69 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 66 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 70 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 67 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 71 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 68 SimulateGattConnection(device1); | 72 SimulateGattConnection(device1); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 127 |
| 124 EXPECT_NE(desc3->GetIdentifier(), desc4->GetIdentifier()); | 128 EXPECT_NE(desc3->GetIdentifier(), desc4->GetIdentifier()); |
| 125 EXPECT_NE(desc3->GetIdentifier(), desc5->GetIdentifier()); | 129 EXPECT_NE(desc3->GetIdentifier(), desc5->GetIdentifier()); |
| 126 EXPECT_NE(desc3->GetIdentifier(), desc6->GetIdentifier()); | 130 EXPECT_NE(desc3->GetIdentifier(), desc6->GetIdentifier()); |
| 127 | 131 |
| 128 EXPECT_NE(desc4->GetIdentifier(), desc5->GetIdentifier()); | 132 EXPECT_NE(desc4->GetIdentifier(), desc5->GetIdentifier()); |
| 129 EXPECT_NE(desc4->GetIdentifier(), desc6->GetIdentifier()); | 133 EXPECT_NE(desc4->GetIdentifier(), desc6->GetIdentifier()); |
| 130 | 134 |
| 131 EXPECT_NE(desc5->GetIdentifier(), desc6->GetIdentifier()); | 135 EXPECT_NE(desc5->GetIdentifier(), desc6->GetIdentifier()); |
| 132 } | 136 } |
| 133 #endif // defined(OS_ANDROID) | 137 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 134 | 138 |
| 135 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 136 TEST_F(BluetoothRemoteGattDescriptorTest, GetUUID) { | 140 TEST_F(BluetoothRemoteGattDescriptorTest, GetUUID) { |
| 141 if (!PlatformSupportsLowEnergy()) { |
| 142 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 143 return; |
| 144 } |
| 137 InitWithFakeAdapter(); | 145 InitWithFakeAdapter(); |
| 138 StartLowEnergyDiscoverySession(); | 146 StartLowEnergyDiscoverySession(); |
| 139 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 147 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 140 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 148 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 141 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 149 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 142 SimulateGattConnection(device); | 150 SimulateGattConnection(device); |
| 143 std::vector<std::string> services; | 151 std::vector<std::string> services; |
| 144 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 152 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
| 145 SimulateGattServicesDiscovered(device, services); | 153 SimulateGattServicesDiscovered(device, services); |
| 146 ASSERT_EQ(1u, device->GetGattServices().size()); | 154 ASSERT_EQ(1u, device->GetGattServices().size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 BluetoothRemoteGattDescriptor* descriptor2 = | 173 BluetoothRemoteGattDescriptor* descriptor2 = |
| 166 characteristic->GetDescriptors()[1]; | 174 characteristic->GetDescriptors()[1]; |
| 167 | 175 |
| 168 // Swap as needed to have descriptor1 be the one with uuid1. | 176 // Swap as needed to have descriptor1 be the one with uuid1. |
| 169 if (descriptor2->GetUUID() == uuid1) | 177 if (descriptor2->GetUUID() == uuid1) |
| 170 std::swap(descriptor1, descriptor2); | 178 std::swap(descriptor1, descriptor2); |
| 171 | 179 |
| 172 EXPECT_EQ(uuid1, descriptor1->GetUUID()); | 180 EXPECT_EQ(uuid1, descriptor1->GetUUID()); |
| 173 EXPECT_EQ(uuid2, descriptor2->GetUUID()); | 181 EXPECT_EQ(uuid2, descriptor2->GetUUID()); |
| 174 } | 182 } |
| 175 #endif // defined(OS_ANDROID) | 183 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 176 | 184 |
| 177 #if defined(OS_ANDROID) | 185 #if defined(OS_ANDROID) |
| 178 // Tests ReadRemoteDescriptor and GetValue with empty value buffer. | 186 // Tests ReadRemoteDescriptor and GetValue with empty value buffer. |
| 179 TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_Empty) { | 187 TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_Empty) { |
| 180 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); | 188 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
| 181 | 189 |
| 182 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), | 190 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
| 183 GetGattErrorCallback(Call::NOT_EXPECTED)); | 191 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 184 EXPECT_EQ(1, gatt_read_descriptor_attempts_); | 192 EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
| 185 std::vector<uint8_t> empty_vector; | 193 std::vector<uint8_t> empty_vector; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 604 |
| 597 // Initial read should still succeed: | 605 // Initial read should still succeed: |
| 598 ResetEventCounts(); | 606 ResetEventCounts(); |
| 599 SimulateGattDescriptorRead(descriptor1_, empty_vector); | 607 SimulateGattDescriptorRead(descriptor1_, empty_vector); |
| 600 EXPECT_EQ(1, callback_count_); | 608 EXPECT_EQ(1, callback_count_); |
| 601 EXPECT_EQ(0, error_callback_count_); | 609 EXPECT_EQ(0, error_callback_count_); |
| 602 } | 610 } |
| 603 #endif // defined(OS_ANDROID) | 611 #endif // defined(OS_ANDROID) |
| 604 | 612 |
| 605 } // namespace device | 613 } // namespace device |
| OLD | NEW |