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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 uint16_t expected_config_descriptor_value, | 65 uint16_t expected_config_descriptor_value, |
66 StartNotifySetupError error = StartNotifySetupError::NONE) { | 66 StartNotifySetupError error = StartNotifySetupError::NONE) { |
67 if (error == StartNotifySetupError::CHARACTERISTIC_PROPERTIES) { | 67 if (error == StartNotifySetupError::CHARACTERISTIC_PROPERTIES) { |
68 properties = 0; | 68 properties = 0; |
69 } | 69 } |
70 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(properties)); | 70 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(properties)); |
71 | 71 |
72 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { | 72 if (error != StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING) { |
73 SimulateGattDescriptor( | 73 SimulateGattDescriptor( |
74 characteristic1_, | 74 characteristic1_, |
75 /* Client Characteristic Configuration descriptor's standard UUID: */ | 75 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
76 "00002902-0000-1000-8000-00805F9B34FB"); | 76 .canonical_value()); |
77 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 77 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
78 } | 78 } |
79 | 79 |
80 if (error == StartNotifySetupError::SET_NOTIFY) { | 80 if (error == StartNotifySetupError::SET_NOTIFY) { |
81 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( | 81 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
82 characteristic1_); | 82 characteristic1_); |
83 } | 83 } |
84 | 84 |
85 if (error == StartNotifySetupError::WRITE_DESCRIPTOR) { | 85 if (error == StartNotifySetupError::WRITE_DESCRIPTOR) { |
86 SimulateGattDescriptorWriteWillFailSynchronouslyOnce( | 86 SimulateGattDescriptorWriteWillFailSynchronouslyOnce( |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 } | 890 } |
891 #endif // defined(OS_ANDROID) | 891 #endif // defined(OS_ANDROID) |
892 | 892 |
893 #if defined(OS_ANDROID) | 893 #if defined(OS_ANDROID) |
894 // Tests multiple StartNotifySession success. | 894 // Tests multiple StartNotifySession success. |
895 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { | 895 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
896 ASSERT_NO_FATAL_FAILURE( | 896 ASSERT_NO_FATAL_FAILURE( |
897 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 897 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
898 SimulateGattDescriptor( | 898 SimulateGattDescriptor( |
899 characteristic1_, | 899 characteristic1_, |
900 /* Client Characteristic Configuration descriptor's standard UUID: */ | 900 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
901 "00002902-0000-1000-8000-00805F9B34FB"); | 901 .canonical_value()); |
902 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 902 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
903 | 903 |
904 characteristic1_->StartNotifySession( | 904 characteristic1_->StartNotifySession( |
905 GetNotifyCallback(Call::EXPECTED), | 905 GetNotifyCallback(Call::EXPECTED), |
906 GetGattErrorCallback(Call::NOT_EXPECTED)); | 906 GetGattErrorCallback(Call::NOT_EXPECTED)); |
907 characteristic1_->StartNotifySession( | 907 characteristic1_->StartNotifySession( |
908 GetNotifyCallback(Call::EXPECTED), | 908 GetNotifyCallback(Call::EXPECTED), |
909 GetGattErrorCallback(Call::NOT_EXPECTED)); | 909 GetGattErrorCallback(Call::NOT_EXPECTED)); |
910 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 910 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
911 EXPECT_EQ(0, callback_count_); | 911 EXPECT_EQ(0, callback_count_); |
912 SimulateGattNotifySessionStarted(characteristic1_); | 912 SimulateGattNotifySessionStarted(characteristic1_); |
913 EXPECT_EQ(2, callback_count_); | 913 EXPECT_EQ(2, callback_count_); |
914 EXPECT_EQ(0, error_callback_count_); | 914 EXPECT_EQ(0, error_callback_count_); |
915 ASSERT_EQ(2u, notify_sessions_.size()); | 915 ASSERT_EQ(2u, notify_sessions_.size()); |
916 ASSERT_TRUE(notify_sessions_[0]); | 916 ASSERT_TRUE(notify_sessions_[0]); |
917 ASSERT_TRUE(notify_sessions_[1]); | 917 ASSERT_TRUE(notify_sessions_[1]); |
918 EXPECT_EQ(characteristic1_->GetIdentifier(), | 918 EXPECT_EQ(characteristic1_->GetIdentifier(), |
919 notify_sessions_[0]->GetCharacteristicIdentifier()); | 919 notify_sessions_[0]->GetCharacteristicIdentifier()); |
920 EXPECT_EQ(characteristic1_->GetIdentifier(), | 920 EXPECT_EQ(characteristic1_->GetIdentifier(), |
921 notify_sessions_[1]->GetCharacteristicIdentifier()); | 921 notify_sessions_[1]->GetCharacteristicIdentifier()); |
922 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 922 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
923 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 923 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
924 } | 924 } |
925 #endif // defined(OS_ANDROID) | 925 #endif // defined(OS_ANDROID) |
926 | 926 |
927 #if defined(OS_ANDROID) | |
928 // Tests multiple StartNotifySession success. | |
929 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { | |
ortuno
2016/03/04 18:55:21
We should add a test for when the gatt objects get
scheib
2016/03/11 04:44:59
Done in https://codereview.chromium.org/1779083002
| |
930 ASSERT_NO_FATAL_FAILURE( | |
931 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | |
932 SimulateGattDescriptor( | |
933 characteristic1_, | |
934 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() | |
935 .canonical_value()); | |
936 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | |
937 | |
938 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | |
939 GetGattErrorCallback(Call::EXPECTED)); | |
940 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED), | |
941 GetGattErrorCallback(Call::EXPECTED)); | |
942 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
943 EXPECT_EQ(0, callback_count_); | |
944 SimulateGattNotifySessionStartError(characteristic1_, | |
945 BluetoothGattService::GATT_ERROR_FAILED); | |
946 EXPECT_EQ(0, callback_count_); | |
947 EXPECT_EQ(2, error_callback_count_); | |
948 ASSERT_EQ(0u, notify_sessions_.size()); | |
949 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); | |
950 } | |
951 #endif // defined(OS_ANDROID) | |
952 | |
927 #if defined(OS_ANDROID) || defined(OS_WIN) | 953 #if defined(OS_ANDROID) || defined(OS_WIN) |
928 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { | 954 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
929 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 955 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
930 | 956 |
931 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); | 957 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); |
932 } | 958 } |
933 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 959 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
934 | 960 |
935 #if defined(OS_ANDROID) || defined(OS_WIN) | 961 #if defined(OS_ANDROID) || defined(OS_WIN) |
936 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { | 962 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_and_GetDescriptor) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 characteristic1_->GetDescriptor(c1_id1)); | 996 characteristic1_->GetDescriptor(c1_id1)); |
971 | 997 |
972 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). | 998 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
973 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); | 999 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
974 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); | 1000 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
975 // ... but not uuid 3 | 1001 // ... but not uuid 3 |
976 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); | 1002 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
977 } | 1003 } |
978 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1004 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
979 | 1005 |
1006 #if defined(OS_ANDROID) || defined(OS_WIN) | |
1007 TEST_F(BluetoothGattCharacteristicTest, GetDescriptorsForUUID) { | |
1008 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | |
1009 | |
1010 // Add several Descriptors: | |
1011 BluetoothUUID uuid1("11111111-0000-1000-8000-00805f9b34fb"); | |
1012 BluetoothUUID uuid2("22222222-0000-1000-8000-00805f9b34fb"); | |
1013 BluetoothUUID uuid3("33333333-0000-1000-8000-00805f9b34fb"); | |
1014 BluetoothUUID uuid4("44444444-0000-1000-8000-00805f9b34fb"); | |
1015 SimulateGattDescriptor(characteristic1_, uuid1.canonical_value()); | |
1016 SimulateGattDescriptor(characteristic1_, uuid2.canonical_value()); | |
1017 SimulateGattDescriptor(characteristic2_, uuid3.canonical_value()); | |
1018 SimulateGattDescriptor(characteristic2_, uuid4.canonical_value()); | |
1019 | |
1020 EXPECT_EQ(uuid1, characteristic1_->GetDescriptorForUUID(uuid1)->GetUUID()); | |
1021 EXPECT_EQ(uuid2, characteristic1_->GetDescriptorForUUID(uuid2)->GetUUID()); | |
1022 EXPECT_EQ(uuid3, characteristic2_->GetDescriptorForUUID(uuid3)->GetUUID()); | |
1023 EXPECT_EQ(uuid4, characteristic2_->GetDescriptorForUUID(uuid4)->GetUUID()); | |
1024 | |
1025 EXPECT_EQ(nullptr, characteristic2_->GetDescriptorForUUID(uuid1)); | |
1026 EXPECT_EQ(nullptr, characteristic2_->GetDescriptorForUUID(uuid2)); | |
1027 EXPECT_EQ(nullptr, characteristic1_->GetDescriptorForUUID(uuid3)); | |
1028 EXPECT_EQ(nullptr, characteristic1_->GetDescriptorForUUID(uuid4)); | |
1029 } | |
1030 #endif // defined(OS_ANDROID) || defined(OS_WIN) | |
1031 | |
980 } // namespace device | 1032 } // namespace device |
OLD | NEW |