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

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

Issue 1804093003: Add BluetoothGattCharacteristicTest::StartNotifySession_Reentrant unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months 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
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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 984
985 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); 985 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr);
986 EXPECT_EQ(0, callback_count_); 986 EXPECT_EQ(0, callback_count_);
987 EXPECT_EQ(1, error_callback_count_); 987 EXPECT_EQ(1, error_callback_count_);
988 ASSERT_EQ(0u, notify_sessions_.size()); 988 ASSERT_EQ(0u, notify_sessions_.size());
989 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, 989 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
990 last_gatt_error_code_); 990 last_gatt_error_code_);
991 } 991 }
992 #endif // defined(OS_ANDROID) 992 #endif // defined(OS_ANDROID)
993 993
994 #if defined(OS_WIN)
995 // Tests StartNotifySession reentrant in start notify session success callback
996 // and the reentrant start notify session success.
997 TEST_F(BluetoothRemoteGattCharacteristicTest,
998 StartNotifySession_Reentrant_Success_Success) {
999 ASSERT_NO_FATAL_FAILURE(
1000 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1001 SimulateGattDescriptor(
1002 characteristic1_,
1003 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1004 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1005
1006 characteristic1_->StartNotifySession(
1007 GetReentrantStartNotifySessionSuccessCallback(Call::EXPECTED,
1008 characteristic1_),
1009 GetReentrantStartNotifySessionErrorCallback(Call::NOT_EXPECTED,
1010 characteristic1_, false));
ortuno 2016/04/22 16:23:39 false /* error_in_reentrant */
gogerald1 2016/04/27 20:15:32 Done.
1011 EXPECT_EQ(0, callback_count_);
1012 SimulateGattNotifySessionStarted(characteristic1_);
1013 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1014
1015 // Simulate reentrant StartNotifySession request from
1016 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback.
1017 SimulateGattNotifySessionStarted(characteristic1_);
1018 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1019 EXPECT_EQ(2, callback_count_);
1020 EXPECT_EQ(0, error_callback_count_);
1021 ASSERT_EQ(2u, notify_sessions_.size());
1022 for (unsigned int i = 0; i < notify_sessions_.size(); i++) {
1023 ASSERT_TRUE(notify_sessions_[i]);
1024 EXPECT_EQ(characteristic1_->GetIdentifier(),
1025 notify_sessions_[i]->GetCharacteristicIdentifier());
1026 EXPECT_TRUE(notify_sessions_[i]->IsActive());
1027 }
1028 }
1029 #endif // defined(OS_WIN)
1030
1031 #if defined(OS_WIN)
1032 // Tests StartNotifySession reentrant in start notify session error callback
1033 // and the reentrant start notify session success.
1034 TEST_F(BluetoothRemoteGattCharacteristicTest,
1035 StartNotifySession_Reentrant_Error_Success) {
1036 ASSERT_NO_FATAL_FAILURE(
1037 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1038 SimulateGattDescriptor(
1039 characteristic1_,
1040 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1041 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1042
1043 SimulateGattCharacteristicSetNotifyWillFailAsynchronouslyOnce(
1044 characteristic1_);
1045
1046 characteristic1_->StartNotifySession(
1047 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1048 characteristic1_),
1049 GetReentrantStartNotifySessionErrorCallback(Call::EXPECTED,
1050 characteristic1_, false));
ortuno 2016/04/22 16:23:39 false /* error_in_reentrant */
gogerald1 2016/04/27 20:15:31 Done.
1051 EXPECT_EQ(0, callback_count_);
1052 SimulateGattNotifySessionStarted(characteristic1_);
1053 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
ortuno 2016/04/22 16:23:39 Add: EXPECT_EQ(1, error_callback_count_);
gogerald1 2016/04/27 20:15:32 Done.
1054
1055 // Simulate reentrant StartNotifySession request from
1056 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1057 SimulateGattNotifySessionStarted(characteristic1_);
1058 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1059 EXPECT_EQ(1, callback_count_);
1060 EXPECT_EQ(1, error_callback_count_);
1061 ASSERT_EQ(1u, notify_sessions_.size());
1062 ASSERT_TRUE(notify_sessions_[0]);
1063 EXPECT_EQ(characteristic1_->GetIdentifier(),
1064 notify_sessions_[0]->GetCharacteristicIdentifier());
1065 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1066 }
1067 #endif // defined(OS_WIN)
1068
1069 #if defined(OS_WIN)
1070 // Tests StartNotifySession reentrant in start notify session error callback
1071 // and the reentrant start notify session error.
1072 TEST_F(BluetoothRemoteGattCharacteristicTest,
1073 StartNotifySession_Reentrant_Error_Error) {
1074 ASSERT_NO_FATAL_FAILURE(
1075 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1076 SimulateGattDescriptor(
1077 characteristic1_,
1078 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1079 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1080
1081 SimulateGattCharacteristicSetNotifyWillFailAsynchronouslyOnce(
1082 characteristic1_);
1083
1084 characteristic1_->StartNotifySession(
1085 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1086 characteristic1_),
1087 GetReentrantStartNotifySessionErrorCallback(Call::EXPECTED,
1088 characteristic1_, true));
ortuno 2016/04/22 16:23:39 true /* error_in_reentrant */
gogerald1 2016/04/27 20:15:32 Done.
1089 EXPECT_EQ(0, callback_count_);
1090 SimulateGattNotifySessionStarted(characteristic1_);
1091 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1092
1093 // Simulate reentrant StartNotifySession request from
1094 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1095 SimulateGattNotifySessionStarted(characteristic1_);
1096 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1097 EXPECT_EQ(0, callback_count_);
1098 EXPECT_EQ(2, error_callback_count_);
1099 ASSERT_EQ(0u, notify_sessions_.size());
1100 }
1101 #endif // defined(OS_WIN)
1102
994 #if defined(OS_ANDROID) || defined(OS_WIN) 1103 #if defined(OS_ANDROID) || defined(OS_WIN)
995 // Tests Characteristic Value changes during a Notify Session. 1104 // Tests Characteristic Value changes during a Notify Session.
996 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { 1105 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
997 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1106 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
998 /* properties: NOTIFY */ 0x10, 1107 /* properties: NOTIFY */ 0x10,
999 /* expected_config_descriptor_value: NOTIFY */ 1)); 1108 /* expected_config_descriptor_value: NOTIFY */ 1));
1000 1109
1001 TestBluetoothAdapterObserver observer(adapter_); 1110 TestBluetoothAdapterObserver observer(adapter_);
1002 1111
1003 std::vector<uint8_t> test_vector1, test_vector2; 1112 std::vector<uint8_t> test_vector1, test_vector2;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 1222 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1114 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1223 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1115 1224
1116 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1225 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1117 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1226 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1118 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1227 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1119 } 1228 }
1120 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1229 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1121 1230
1122 } // namespace device 1231 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698