| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 ASSERT_TRUE(notify_sessions_[1]); | 694 ASSERT_TRUE(notify_sessions_[1]); |
| 695 EXPECT_EQ(characteristic1_->GetIdentifier(), | 695 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 696 notify_sessions_[0]->GetCharacteristicIdentifier()); | 696 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 697 EXPECT_EQ(characteristic1_->GetIdentifier(), | 697 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 698 notify_sessions_[1]->GetCharacteristicIdentifier()); | 698 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 699 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 699 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 700 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 700 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 701 } | 701 } |
| 702 #endif // defined(OS_ANDROID) | 702 #endif // defined(OS_ANDROID) |
| 703 | 703 |
| 704 #if defined(OS_ANDROID) |
| 705 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
| 706 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 707 |
| 708 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); |
| 709 } |
| 710 #endif // defined(OS_ANDROID) |
| 711 |
| 712 #if defined(OS_ANDROID) |
| 713 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { |
| 714 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 715 |
| 716 // Add several Descriptors: |
| 717 BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb"); |
| 718 BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb"); |
| 719 BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb"); |
| 720 BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb"); |
| 721 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value()); |
| 722 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value()); |
| 723 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value()); |
| 724 SimulateGattDescriptor(characteristic2_, uuid4.canonical_value()); |
| 725 |
| 726 // Verify that GetDescriptor can retrieve descriptors again by ID, |
| 727 // and that the same Descriptor is returned when searched by ID. |
| 728 EXPECT_EQ(2u, characteristic1_->GetDescriptors().size()); |
| 729 EXPECT_EQ(2u, characteristic2_->GetDescriptors().size()); |
| 730 std::string c1_id1 = characteristic1_->GetDescriptors()[0]->GetIdentifier(); |
| 731 std::string c1_id2 = characteristic1_->GetDescriptors()[1]->GetIdentifier(); |
| 732 std::string c2_id1 = characteristic2_->GetDescriptors()[0]->GetIdentifier(); |
| 733 std::string c2_id2 = characteristic2_->GetDescriptors()[1]->GetIdentifier(); |
| 734 BluetoothUUID c1_uuid1 = characteristic1_->GetDescriptors()[0]->GetUUID(); |
| 735 BluetoothUUID c1_uuid2 = characteristic1_->GetDescriptors()[1]->GetUUID(); |
| 736 BluetoothUUID c2_uuid1 = characteristic2_->GetDescriptors()[0]->GetUUID(); |
| 737 BluetoothUUID c2_uuid2 = characteristic2_->GetDescriptors()[1]->GetUUID(); |
| 738 EXPECT_EQ(c1_uuid1, characteristic1_->GetDescriptor(c1_id1)->GetUUID()); |
| 739 EXPECT_EQ(c1_uuid2, characteristic1_->GetDescriptor(c1_id2)->GetUUID()); |
| 740 EXPECT_EQ(c2_uuid1, characteristic2_->GetDescriptor(c2_id1)->GetUUID()); |
| 741 EXPECT_EQ(c2_uuid2, characteristic2_->GetDescriptor(c2_id2)->GetUUID()); |
| 742 |
| 743 // GetDescriptors & GetDescriptor return the same object for the same ID: |
| 744 EXPECT_EQ(characteristic1_->GetDescriptors()[0], |
| 745 characteristic1_->GetDescriptor(c1_id1)); |
| 746 EXPECT_EQ(characteristic1_->GetDescriptor(c1_id1), |
| 747 characteristic1_->GetDescriptor(c1_id1)); |
| 748 |
| 749 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
| 750 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
| 751 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
| 752 // ... but not uuid 3 |
| 753 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
| 754 } |
| 755 #endif // defined(OS_ANDROID) |
| 756 |
| 704 } // namespace device | 757 } // namespace device |
| OLD | NEW |