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

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: Created 4 years, 7 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(
1010 Call::NOT_EXPECTED, characteristic1_,
1011 false /* error_in_reentrant */));
1012 EXPECT_EQ(0, callback_count_);
1013 SimulateGattNotifySessionStarted(characteristic1_);
1014 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1015
1016 // Simulate reentrant StartNotifySession request from
1017 // BluetoothTestBase::ReentrantStartNotifySessionSuccessCallback.
1018 SimulateGattNotifySessionStarted(characteristic1_);
1019 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1020 EXPECT_EQ(2, callback_count_);
1021 EXPECT_EQ(0, error_callback_count_);
1022 ASSERT_EQ(2u, notify_sessions_.size());
1023 for (unsigned int i = 0; i < notify_sessions_.size(); i++) {
1024 ASSERT_TRUE(notify_sessions_[i]);
1025 EXPECT_EQ(characteristic1_->GetIdentifier(),
1026 notify_sessions_[i]->GetCharacteristicIdentifier());
1027 EXPECT_TRUE(notify_sessions_[i]->IsActive());
1028 }
1029 }
1030 #endif // defined(OS_WIN)
1031
1032 #if defined(OS_WIN)
1033 // Tests StartNotifySession reentrant in start notify session error callback
1034 // and the reentrant start notify session success.
1035 TEST_F(BluetoothRemoteGattCharacteristicTest,
1036 StartNotifySession_Reentrant_Error_Success) {
1037 ASSERT_NO_FATAL_FAILURE(
1038 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1039 SimulateGattDescriptor(
1040 characteristic1_,
1041 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1042 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1043
1044 SimulateGattNotifySessionStartError(
1045 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1046
1047 characteristic1_->StartNotifySession(
1048 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1049 characteristic1_),
1050 GetReentrantStartNotifySessionErrorCallback(
1051 Call::EXPECTED, characteristic1_, false /* error_in_reentrant */));
1052 EXPECT_EQ(0, callback_count_);
1053 SimulateGattNotifySessionStarted(characteristic1_);
1054 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1055 EXPECT_EQ(1, error_callback_count_);
1056
1057 // Simulate reentrant StartNotifySession request from
1058 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1059 SimulateGattNotifySessionStarted(characteristic1_);
1060 EXPECT_EQ(1, gatt_notify_characteristic_attempts_);
1061 EXPECT_EQ(1, callback_count_);
1062 EXPECT_EQ(1, error_callback_count_);
1063 ASSERT_EQ(1u, notify_sessions_.size());
1064 ASSERT_TRUE(notify_sessions_[0]);
1065 EXPECT_EQ(characteristic1_->GetIdentifier(),
1066 notify_sessions_[0]->GetCharacteristicIdentifier());
1067 EXPECT_TRUE(notify_sessions_[0]->IsActive());
1068 }
1069 #endif // defined(OS_WIN)
1070
1071 #if defined(OS_WIN)
1072 // Tests StartNotifySession reentrant in start notify session error callback
1073 // and the reentrant start notify session error.
1074 TEST_F(BluetoothRemoteGattCharacteristicTest,
1075 StartNotifySession_Reentrant_Error_Error) {
1076 ASSERT_NO_FATAL_FAILURE(
1077 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10));
1078 SimulateGattDescriptor(
1079 characteristic1_,
1080 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid().value());
1081 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size());
1082
1083 SimulateGattNotifySessionStartError(
1084 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_UNKNOWN);
1085
1086 characteristic1_->StartNotifySession(
1087 GetReentrantStartNotifySessionSuccessCallback(Call::NOT_EXPECTED,
1088 characteristic1_),
1089 GetReentrantStartNotifySessionErrorCallback(
1090 Call::EXPECTED, characteristic1_, true /* error_in_reentrant */));
1091 EXPECT_EQ(0, callback_count_);
1092 SimulateGattNotifySessionStarted(characteristic1_);
1093 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1094
1095 // Simulate reentrant StartNotifySession request from
1096 // BluetoothTestBase::ReentrantStartNotifySessionErrorCallback.
1097 SimulateGattNotifySessionStarted(characteristic1_);
1098 EXPECT_EQ(0, gatt_notify_characteristic_attempts_);
1099 EXPECT_EQ(0, callback_count_);
1100 EXPECT_EQ(2, error_callback_count_);
1101 ASSERT_EQ(0u, notify_sessions_.size());
1102 }
1103 #endif // defined(OS_WIN)
1104
994 #if defined(OS_ANDROID) || defined(OS_WIN) 1105 #if defined(OS_ANDROID) || defined(OS_WIN)
995 // Tests Characteristic Value changes during a Notify Session. 1106 // Tests Characteristic Value changes during a Notify Session.
996 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) { 1107 TEST_F(BluetoothRemoteGattCharacteristicTest, GattCharacteristicValueChanged) {
997 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 1108 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
998 /* properties: NOTIFY */ 0x10, 1109 /* properties: NOTIFY */ 0x10,
999 /* expected_config_descriptor_value: NOTIFY */ 1)); 1110 /* expected_config_descriptor_value: NOTIFY */ 1));
1000 1111
1001 TestBluetoothAdapterObserver observer(adapter_); 1112 TestBluetoothAdapterObserver observer(adapter_);
1002 1113
1003 std::vector<uint8_t> test_vector1, test_vector2; 1114 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()); 1224 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1114 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1225 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1115 1226
1116 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1227 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1117 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1228 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1118 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1229 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1119 } 1230 }
1120 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1231 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1121 1232
1122 } // namespace device 1233 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_low_energy_win_fake.cc ('k') | device/bluetooth/test/bluetooth_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698