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

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

Issue 1412963004: bluetooth: android: Implement Characteristic GetIdentifier, fix Service IDs too. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/bluetooth_gatt_service.h"
6
7 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.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 BluetoothGattCharacteristicTest : public BluetoothTest {};
20 #endif
21
22 #if defined(OS_ANDROID)
23 TEST_F(BluetoothGattCharacteristicTest, GetIdentifier) {
24 InitWithFakeAdapter();
25 StartLowEnergyDiscoverySession();
26 // 2 devices to verify unique IDs across them.
27 BluetoothDevice* device1 = DiscoverLowEnergyDevice(3);
28 BluetoothDevice* device2 = DiscoverLowEnergyDevice(4);
29 device1->CreateGattConnection(GetGattConnectionCallback(),
30 GetConnectErrorCallback());
31 device2->CreateGattConnection(GetGattConnectionCallback(),
32 GetConnectErrorCallback());
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);
50 SimulateGattCharacteristic(service1, uuid);
51 SimulateGattCharacteristic(service2, uuid);
52 SimulateGattCharacteristic(service2, uuid);
53 SimulateGattCharacteristic(service3, uuid);
54 SimulateGattCharacteristic(service3, uuid);
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
62 // All IDs are unique, even though they have the same UUID.
63 EXPECT_NE(char1->GetIdentifier(), char2->GetIdentifier());
64 EXPECT_NE(char1->GetIdentifier(), char3->GetIdentifier());
65 EXPECT_NE(char1->GetIdentifier(), char4->GetIdentifier());
66 EXPECT_NE(char1->GetIdentifier(), char5->GetIdentifier());
67 EXPECT_NE(char1->GetIdentifier(), char6->GetIdentifier());
68
69 EXPECT_NE(char2->GetIdentifier(), char3->GetIdentifier());
70 EXPECT_NE(char2->GetIdentifier(), char4->GetIdentifier());
71 EXPECT_NE(char2->GetIdentifier(), char5->GetIdentifier());
72 EXPECT_NE(char2->GetIdentifier(), char6->GetIdentifier());
73
74 EXPECT_NE(char3->GetIdentifier(), char4->GetIdentifier());
75 EXPECT_NE(char3->GetIdentifier(), char5->GetIdentifier());
76 EXPECT_NE(char3->GetIdentifier(), char6->GetIdentifier());
77
78 EXPECT_NE(char4->GetIdentifier(), char5->GetIdentifier());
79 EXPECT_NE(char4->GetIdentifier(), char6->GetIdentifier());
80
81 EXPECT_NE(char5->GetIdentifier(), char6->GetIdentifier());
82 }
83 #endif // defined(OS_ANDROID)
84
85 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_characteristic.h ('k') | device/bluetooth/bluetooth_gatt_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698