| 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_service.h" | 5 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 6 | 6 |
| 7 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 7 #include "device/bluetooth/bluetooth_gatt_characteristic.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) |
| 11 #include "device/bluetooth/test/bluetooth_test_android.h" | 11 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 12 #elif defined(OS_MACOSX) | 12 #elif defined(OS_MACOSX) |
| 13 #include "device/bluetooth/test/bluetooth_test_mac.h" | 13 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace device { | 16 namespace device { |
| 17 | 17 |
| 18 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 18 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 19 class BluetoothGattServiceTest : public BluetoothTest {}; | 19 class BluetoothGattServiceTest : public BluetoothTest {}; |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 23 TEST_F(BluetoothGattServiceTest, GetIdentifier) { | 23 TEST_F(BluetoothGattServiceTest, GetIdentifier) { |
| 24 InitWithFakeAdapter(); | 24 InitWithFakeAdapter(); |
| 25 StartLowEnergyDiscoverySession(); | 25 StartLowEnergyDiscoverySession(); |
| 26 // 2 devices to verify unique IDs across them. | 26 // 2 devices to verify unique IDs across them. |
| 27 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3); | 27 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3); |
| 28 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4); | 28 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4); |
| 29 device1->CreateGattConnection(GetGattConnectionCallback(), | 29 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 30 GetConnectErrorCallback()); | 30 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 31 device2->CreateGattConnection(GetGattConnectionCallback(), | 31 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 32 GetConnectErrorCallback()); | 32 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 33 SimulateGattConnection(device1); | 33 SimulateGattConnection(device1); |
| 34 SimulateGattConnection(device2); | 34 SimulateGattConnection(device2); |
| 35 | 35 |
| 36 // 2 duplicate UUIDs creating 2 service instances on each device. | 36 // 2 duplicate UUIDs creating 2 service instances on each device. |
| 37 std::vector<std::string> services; | 37 std::vector<std::string> services; |
| 38 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; | 38 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; |
| 39 services.push_back(uuid); | 39 services.push_back(uuid); |
| 40 services.push_back(uuid); | 40 services.push_back(uuid); |
| 41 SimulateGattServicesDiscovered(device1, services); | 41 SimulateGattServicesDiscovered(device1, services); |
| 42 SimulateGattServicesDiscovered(device2, services); | 42 SimulateGattServicesDiscovered(device2, services); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 55 | 55 |
| 56 EXPECT_NE(service3->GetIdentifier(), service4->GetIdentifier()); | 56 EXPECT_NE(service3->GetIdentifier(), service4->GetIdentifier()); |
| 57 } | 57 } |
| 58 #endif // defined(OS_ANDROID) | 58 #endif // defined(OS_ANDROID) |
| 59 | 59 |
| 60 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
| 61 TEST_F(BluetoothGattServiceTest, GetUUID) { | 61 TEST_F(BluetoothGattServiceTest, GetUUID) { |
| 62 InitWithFakeAdapter(); | 62 InitWithFakeAdapter(); |
| 63 StartLowEnergyDiscoverySession(); | 63 StartLowEnergyDiscoverySession(); |
| 64 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 64 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 65 device->CreateGattConnection(GetGattConnectionCallback(), | 65 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 66 GetConnectErrorCallback()); | 66 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 67 SimulateGattConnection(device); | 67 SimulateGattConnection(device); |
| 68 | 68 |
| 69 // Create multiple instances with the same UUID. | 69 // Create multiple instances with the same UUID. |
| 70 BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); | 70 BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); |
| 71 std::vector<std::string> services; | 71 std::vector<std::string> services; |
| 72 services.push_back(uuid.canonical_value()); | 72 services.push_back(uuid.canonical_value()); |
| 73 services.push_back(uuid.canonical_value()); | 73 services.push_back(uuid.canonical_value()); |
| 74 SimulateGattServicesDiscovered(device, services); | 74 SimulateGattServicesDiscovered(device, services); |
| 75 | 75 |
| 76 // Each has the same UUID. | 76 // Each has the same UUID. |
| 77 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); | 77 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); |
| 78 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); | 78 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); |
| 79 } | 79 } |
| 80 #endif // defined(OS_ANDROID) | 80 #endif // defined(OS_ANDROID) |
| 81 | 81 |
| 82 #if defined(OS_ANDROID) | 82 #if defined(OS_ANDROID) |
| 83 TEST_F(BluetoothGattServiceTest, GetCharacteristics_FindNone) { | 83 TEST_F(BluetoothGattServiceTest, GetCharacteristics_FindNone) { |
| 84 InitWithFakeAdapter(); | 84 InitWithFakeAdapter(); |
| 85 StartLowEnergyDiscoverySession(); | 85 StartLowEnergyDiscoverySession(); |
| 86 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 86 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 87 device->CreateGattConnection(GetGattConnectionCallback(), | 87 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 88 GetConnectErrorCallback()); | 88 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 89 SimulateGattConnection(device); | 89 SimulateGattConnection(device); |
| 90 | 90 |
| 91 // Simulate a service, with no Characteristics: | 91 // Simulate a service, with no Characteristics: |
| 92 std::vector<std::string> services; | 92 std::vector<std::string> services; |
| 93 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 93 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
| 94 SimulateGattServicesDiscovered(device, services); | 94 SimulateGattServicesDiscovered(device, services); |
| 95 BluetoothGattService* service = device->GetGattServices()[0]; | 95 BluetoothGattService* service = device->GetGattServices()[0]; |
| 96 | 96 |
| 97 EXPECT_EQ(0u, service->GetCharacteristics().size()); | 97 EXPECT_EQ(0u, service->GetCharacteristics().size()); |
| 98 } | 98 } |
| 99 #endif // defined(OS_ANDROID) | 99 #endif // defined(OS_ANDROID) |
| 100 | 100 |
| 101 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
| 102 TEST_F(BluetoothGattServiceTest, GetCharacteristics_and_GetCharacteristic) { | 102 TEST_F(BluetoothGattServiceTest, GetCharacteristics_and_GetCharacteristic) { |
| 103 InitWithFakeAdapter(); | 103 InitWithFakeAdapter(); |
| 104 StartLowEnergyDiscoverySession(); | 104 StartLowEnergyDiscoverySession(); |
| 105 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 105 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 106 device->CreateGattConnection(GetGattConnectionCallback(), | 106 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 107 GetConnectErrorCallback()); | 107 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 108 SimulateGattConnection(device); | 108 SimulateGattConnection(device); |
| 109 | 109 |
| 110 // Simulate a service, with several Characteristics: | 110 // Simulate a service, with several Characteristics: |
| 111 std::vector<std::string> services; | 111 std::vector<std::string> services; |
| 112 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 112 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
| 113 SimulateGattServicesDiscovered(device, services); | 113 SimulateGattServicesDiscovered(device, services); |
| 114 BluetoothGattService* service = device->GetGattServices()[0]; | 114 BluetoothGattService* service = device->GetGattServices()[0]; |
| 115 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; | 115 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; |
| 116 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; | 116 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; |
| 117 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. | 117 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 BluetoothUUID char_uuid3 = service->GetCharacteristics()[2]->GetUUID(); | 133 BluetoothUUID char_uuid3 = service->GetCharacteristics()[2]->GetUUID(); |
| 134 BluetoothUUID char_uuid4 = service->GetCharacteristics()[3]->GetUUID(); | 134 BluetoothUUID char_uuid4 = service->GetCharacteristics()[3]->GetUUID(); |
| 135 EXPECT_EQ(char_uuid1, service->GetCharacteristic(char_id1)->GetUUID()); | 135 EXPECT_EQ(char_uuid1, service->GetCharacteristic(char_id1)->GetUUID()); |
| 136 EXPECT_EQ(char_uuid2, service->GetCharacteristic(char_id2)->GetUUID()); | 136 EXPECT_EQ(char_uuid2, service->GetCharacteristic(char_id2)->GetUUID()); |
| 137 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID()); | 137 EXPECT_EQ(char_uuid3, service->GetCharacteristic(char_id3)->GetUUID()); |
| 138 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID()); | 138 EXPECT_EQ(char_uuid4, service->GetCharacteristic(char_id4)->GetUUID()); |
| 139 } | 139 } |
| 140 #endif // defined(OS_ANDROID) | 140 #endif // defined(OS_ANDROID) |
| 141 | 141 |
| 142 } // namespace device | 142 } // namespace device |
| OLD | NEW |