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

Side by Side Diff: device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.cc

Issue 1973343005: Remove service, add device, in BluetoothLocalGattService::Delegate (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
« no previous file with comments | « device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/test/test_bluetooth_local_gatt_service_delegate.h> 5 #include <device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h>
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h"
8 8
9 namespace device { 9 namespace device {
10 10
11 TestBluetoothLocalGattServiceDelegate::TestBluetoothLocalGattServiceDelegate() 11 TestBluetoothLocalGattServiceDelegate::TestBluetoothLocalGattServiceDelegate()
12 : should_fail_(false), 12 : should_fail_(false),
13 last_written_value_(0), 13 last_written_value_(0),
14 value_to_write_(0), 14 value_to_write_(0),
15 expected_service_(nullptr), 15 expected_service_(nullptr),
16 expected_characteristic_(nullptr), 16 expected_characteristic_(nullptr),
17 expected_descriptor_(nullptr) {} 17 expected_descriptor_(nullptr) {}
18 18
19 TestBluetoothLocalGattServiceDelegate:: 19 TestBluetoothLocalGattServiceDelegate::
20 ~TestBluetoothLocalGattServiceDelegate() {} 20 ~TestBluetoothLocalGattServiceDelegate() {}
21 21
22 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicReadRequest( 22 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicReadRequest(
23 const BluetoothLocalGattService* service, 23 const BluetoothDevice* device,
24 const BluetoothLocalGattCharacteristic* characteristic, 24 const BluetoothLocalGattCharacteristic* characteristic,
25 int offset, 25 int offset,
26 const ValueCallback& callback, 26 const ValueCallback& callback,
27 const ErrorCallback& error_callback) { 27 const ErrorCallback& error_callback) {
28 EXPECT_EQ(expected_service_, service); 28 EXPECT_EQ(expected_characteristic_->GetIdentifier(),
29 EXPECT_EQ(expected_characteristic_, characteristic); 29 characteristic->GetIdentifier());
30 if (should_fail_) { 30 if (should_fail_) {
31 error_callback.Run(); 31 error_callback.Run();
32 return; 32 return;
33 } 33 }
34 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); 34 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_));
35 } 35 }
36 36
37 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicWriteRequest( 37 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicWriteRequest(
38 const BluetoothLocalGattService* service, 38 const BluetoothDevice* device,
39 const BluetoothLocalGattCharacteristic* characteristic, 39 const BluetoothLocalGattCharacteristic* characteristic,
40 const std::vector<uint8_t>& value, 40 const std::vector<uint8_t>& value,
41 int offset, 41 int offset,
42 const base::Closure& callback, 42 const base::Closure& callback,
43 const ErrorCallback& error_callback) { 43 const ErrorCallback& error_callback) {
44 EXPECT_EQ(expected_service_, service); 44 EXPECT_EQ(expected_characteristic_->GetIdentifier(),
45 EXPECT_EQ(expected_characteristic_, characteristic); 45 characteristic->GetIdentifier());
46 if (should_fail_) { 46 if (should_fail_) {
47 error_callback.Run(); 47 error_callback.Run();
48 return; 48 return;
49 } 49 }
50 last_written_value_ = BluetoothGattServerTest::GetInteger(value); 50 last_written_value_ = BluetoothGattServerTest::GetInteger(value);
51 callback.Run(); 51 callback.Run();
52 } 52 }
53 53
54 void TestBluetoothLocalGattServiceDelegate::OnDescriptorReadRequest( 54 void TestBluetoothLocalGattServiceDelegate::OnDescriptorReadRequest(
55 const BluetoothLocalGattService* service, 55 const BluetoothDevice* device,
56 const BluetoothLocalGattDescriptor* descriptor, 56 const BluetoothLocalGattDescriptor* descriptor,
57 int offset, 57 int offset,
58 const ValueCallback& callback, 58 const ValueCallback& callback,
59 const ErrorCallback& error_callback) { 59 const ErrorCallback& error_callback) {
60 EXPECT_EQ(expected_service_, service); 60 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier());
61 EXPECT_EQ(expected_descriptor_, descriptor);
62 if (should_fail_) { 61 if (should_fail_) {
63 error_callback.Run(); 62 error_callback.Run();
64 return; 63 return;
65 } 64 }
66 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); 65 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_));
67 } 66 }
68 67
69 void TestBluetoothLocalGattServiceDelegate::OnDescriptorWriteRequest( 68 void TestBluetoothLocalGattServiceDelegate::OnDescriptorWriteRequest(
70 const BluetoothLocalGattService* service, 69 const BluetoothDevice* device,
71 const BluetoothLocalGattDescriptor* descriptor, 70 const BluetoothLocalGattDescriptor* descriptor,
72 const std::vector<uint8_t>& value, 71 const std::vector<uint8_t>& value,
73 int offset, 72 int offset,
74 const base::Closure& callback, 73 const base::Closure& callback,
75 const ErrorCallback& error_callback) { 74 const ErrorCallback& error_callback) {
76 EXPECT_EQ(expected_service_, service); 75 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier());
77 EXPECT_EQ(expected_descriptor_, descriptor);
78 if (should_fail_) { 76 if (should_fail_) {
79 error_callback.Run(); 77 error_callback.Run();
80 return; 78 return;
81 } 79 }
82 last_written_value_ = BluetoothGattServerTest::GetInteger(value); 80 last_written_value_ = BluetoothGattServerTest::GetInteger(value);
83 callback.Run(); 81 callback.Run();
84 } 82 }
85 83
86 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStart( 84 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStart(
87 const BluetoothLocalGattService* service, 85 const BluetoothDevice* device,
88 const BluetoothLocalGattCharacteristic* characteristic) { 86 const BluetoothLocalGattCharacteristic* characteristic) {
89 EXPECT_EQ(expected_service_, service); 87 EXPECT_EQ(expected_characteristic_->GetIdentifier(),
90 EXPECT_EQ(expected_characteristic_, characteristic); 88 characteristic->GetIdentifier());
91 notifications_started_for_characteristic_[characteristic->GetIdentifier()] = 89 notifications_started_for_characteristic_[characteristic->GetIdentifier()] =
92 true; 90 true;
93 } 91 }
94 92
95 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStop( 93 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStop(
96 const BluetoothLocalGattService* service, 94 const BluetoothDevice* device,
97 const BluetoothLocalGattCharacteristic* characteristic) { 95 const BluetoothLocalGattCharacteristic* characteristic) {
98 EXPECT_EQ(expected_service_, service); 96 EXPECT_EQ(expected_characteristic_->GetIdentifier(),
99 EXPECT_EQ(expected_characteristic_, characteristic); 97 characteristic->GetIdentifier());
100 notifications_started_for_characteristic_[characteristic->GetIdentifier()] = 98 notifications_started_for_characteristic_[characteristic->GetIdentifier()] =
101 false; 99 false;
102 } 100 }
103 101
104 bool TestBluetoothLocalGattServiceDelegate::NotificationStatusForCharacteristic( 102 bool TestBluetoothLocalGattServiceDelegate::NotificationStatusForCharacteristic(
105 BluetoothLocalGattCharacteristic* characteristic) { 103 BluetoothLocalGattCharacteristic* characteristic) {
106 auto found = notifications_started_for_characteristic_.find( 104 auto found = notifications_started_for_characteristic_.find(
107 characteristic->GetIdentifier()); 105 characteristic->GetIdentifier());
108 if (found == notifications_started_for_characteristic_.end()) 106 if (found == notifications_started_for_characteristic_.end())
109 return false; 107 return false;
110 return found->second; 108 return found->second;
111 } 109 }
112 110
113 } // namespace device 111 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698