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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc

Issue 1946053002: Fixes to DBus GATT components. (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 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 <base/bind.h> 5 #include <base/bind.h>
6 #include <base/memory/ptr_util.h> 6 #include <base/memory/ptr_util.h>
7 #include <dbus/bus.h> 7 #include <dbus/bus.h>
8 #include <dbus/message.h> 8 #include <dbus/message.h>
9 #include <dbus/object_path.h> 9 #include <dbus/object_path.h>
10 #include <device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h> 10 #include <device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h>
(...skipping 12 matching lines...) Expand all
23 const char kAppObjectPath[] = "/fake/hci0/gatt_application"; 23 const char kAppObjectPath[] = "/fake/hci0/gatt_application";
24 const char kFakeServiceUuid[] = "00000000-0000-0000-0000-010040008000"; 24 const char kFakeServiceUuid[] = "00000000-0000-0000-0000-010040008000";
25 const char kFakeCharacteristicUuid[] = "00000000-0000-0000-0000-010040908000"; 25 const char kFakeCharacteristicUuid[] = "00000000-0000-0000-0000-010040908000";
26 const char kFakeDescriptorUuid[] = "00000000-0000-0000-0000-018390008000"; 26 const char kFakeDescriptorUuid[] = "00000000-0000-0000-0000-018390008000";
27 27
28 // This is really ugly, but it really is the best way to verify our message 28 // This is really ugly, but it really is the best way to verify our message
29 // was constructed correctly. This string was generated from the test data 29 // was constructed correctly. This string was generated from the test data
30 // and then manually verified to match the expected signature. 30 // and then manually verified to match the expected signature.
31 const char kExpectedMessage[] = 31 const char kExpectedMessage[] =
32 "message_type: MESSAGE_METHOD_RETURN\n" 32 "message_type: MESSAGE_METHOD_RETURN\n"
33 "signature: a(oa(sa{sv}))\n" 33 "signature: a{oa{sa{sv}}}\n"
34 "reply_serial: 123\n" 34 "reply_serial: 123\n"
35 "\n" 35 "\n"
36 "array [\n" 36 "array [\n"
37 " struct {\n" 37 " dict entry {\n"
38 " object_path \"/fake/hci0/gatt_application/service0\"\n" 38 " object_path \"/fake/hci0/gatt_application/service0\"\n"
39 " array [\n" 39 " array [\n"
40 " struct {\n" 40 " dict entry {\n"
41 " string \"org.bluez.GattService1\"\n" 41 " string \"org.bluez.GattService1\"\n"
42 " array [\n" 42 " array [\n"
43 " dict entry {\n" 43 " dict entry {\n"
44 " string \"UUID\"\n" 44 " string \"UUID\"\n"
45 " variant string " 45 " variant string "
46 "\"00000000-0000-0000-0000-010040008000\"\n" 46 "\"00000000-0000-0000-0000-010040008000\"\n"
47 " }\n" 47 " }\n"
48 " dict entry {\n" 48 " dict entry {\n"
49 " string \"Primary\"\n"
50 " variant bool true\n"
51 " }\n"
52 " dict entry {\n"
49 " string \"Includes\"\n" 53 " string \"Includes\"\n"
50 " variant array [\n" 54 " variant array [\n"
51 " ]\n" 55 " ]\n"
52 " }\n" 56 " }\n"
53 " ]\n" 57 " ]\n"
54 " }\n" 58 " }\n"
55 " ]\n" 59 " ]\n"
56 " }\n" 60 " }\n"
57 " struct {\n" 61 " dict entry {\n"
58 " object_path \"/fake/hci0/gatt_application/service1\"\n" 62 " object_path \"/fake/hci0/gatt_application/service1\"\n"
59 " array [\n" 63 " array [\n"
60 " struct {\n" 64 " dict entry {\n"
61 " string \"org.bluez.GattService1\"\n" 65 " string \"org.bluez.GattService1\"\n"
62 " array [\n" 66 " array [\n"
63 " dict entry {\n" 67 " dict entry {\n"
64 " string \"UUID\"\n" 68 " string \"UUID\"\n"
65 " variant string " 69 " variant string "
66 "\"00000000-0000-0000-0000-010040008000\"\n" 70 "\"00000000-0000-0000-0000-010040008000\"\n"
67 " }\n" 71 " }\n"
68 " dict entry {\n" 72 " dict entry {\n"
73 " string \"Primary\"\n"
74 " variant bool true\n"
75 " }\n"
76 " dict entry {\n"
69 " string \"Includes\"\n" 77 " string \"Includes\"\n"
70 " variant array [\n" 78 " variant array [\n"
71 " ]\n" 79 " ]\n"
72 " }\n" 80 " }\n"
73 " ]\n" 81 " ]\n"
74 " }\n" 82 " }\n"
75 " ]\n" 83 " ]\n"
76 " }\n" 84 " }\n"
77 " struct {\n" 85 " dict entry {\n"
78 " object_path \"/fake/hci0/gatt_application/service0/characteristic0\"\n" 86 " object_path \"/fake/hci0/gatt_application/service0/characteristic0\"\n"
79 " array [\n" 87 " array [\n"
80 " struct {\n" 88 " dict entry {\n"
81 " string \"org.bluez.GattCharacteristic1\"\n" 89 " string \"org.bluez.GattCharacteristic1\"\n"
82 " array [\n" 90 " array [\n"
83 " dict entry {\n" 91 " dict entry {\n"
84 " string \"UUID\"\n" 92 " string \"UUID\"\n"
85 " variant string " 93 " variant string "
86 "\"00000000-0000-0000-0000-010040908000\"\n" 94 "\"00000000-0000-0000-0000-010040908000\"\n"
87 " }\n" 95 " }\n"
88 " dict entry {\n" 96 " dict entry {\n"
89 " string \"Service\"\n" 97 " string \"Service\"\n"
90 " variant object_path " 98 " variant object_path "
91 "\"/fake/hci0/gatt_application/service0\"\n" 99 "\"/fake/hci0/gatt_application/service0\"\n"
92 " }\n" 100 " }\n"
93 " ]\n" 101 " ]\n"
94 " }\n" 102 " }\n"
95 " ]\n" 103 " ]\n"
96 " }\n" 104 " }\n"
97 " struct {\n" 105 " dict entry {\n"
98 " object_path \"/fake/hci0/gatt_application/service0/characteristic1\"\n" 106 " object_path \"/fake/hci0/gatt_application/service0/characteristic1\"\n"
99 " array [\n" 107 " array [\n"
100 " struct {\n" 108 " dict entry {\n"
101 " string \"org.bluez.GattCharacteristic1\"\n" 109 " string \"org.bluez.GattCharacteristic1\"\n"
102 " array [\n" 110 " array [\n"
103 " dict entry {\n" 111 " dict entry {\n"
104 " string \"UUID\"\n" 112 " string \"UUID\"\n"
105 " variant string " 113 " variant string "
106 "\"00000000-0000-0000-0000-010040908000\"\n" 114 "\"00000000-0000-0000-0000-010040908000\"\n"
107 " }\n" 115 " }\n"
108 " dict entry {\n" 116 " dict entry {\n"
109 " string \"Service\"\n" 117 " string \"Service\"\n"
110 " variant object_path " 118 " variant object_path "
111 "\"/fake/hci0/gatt_application/service0\"\n" 119 "\"/fake/hci0/gatt_application/service0\"\n"
112 " }\n" 120 " }\n"
113 " ]\n" 121 " ]\n"
114 " }\n" 122 " }\n"
115 " ]\n" 123 " ]\n"
116 " }\n" 124 " }\n"
117 " struct {\n" 125 " dict entry {\n"
118 " object_path \"/fake/hci0/gatt_application/service1/characteristic0\"\n" 126 " object_path \"/fake/hci0/gatt_application/service1/characteristic0\"\n"
119 " array [\n" 127 " array [\n"
120 " struct {\n" 128 " dict entry {\n"
121 " string \"org.bluez.GattCharacteristic1\"\n" 129 " string \"org.bluez.GattCharacteristic1\"\n"
122 " array [\n" 130 " array [\n"
123 " dict entry {\n" 131 " dict entry {\n"
124 " string \"UUID\"\n" 132 " string \"UUID\"\n"
125 " variant string " 133 " variant string "
126 "\"00000000-0000-0000-0000-010040908000\"\n" 134 "\"00000000-0000-0000-0000-010040908000\"\n"
127 " }\n" 135 " }\n"
128 " dict entry {\n" 136 " dict entry {\n"
129 " string \"Service\"\n" 137 " string \"Service\"\n"
130 " variant object_path " 138 " variant object_path "
131 "\"/fake/hci0/gatt_application/service1\"\n" 139 "\"/fake/hci0/gatt_application/service1\"\n"
132 " }\n" 140 " }\n"
133 " ]\n" 141 " ]\n"
134 " }\n" 142 " }\n"
135 " ]\n" 143 " ]\n"
136 " }\n" 144 " }\n"
137 " struct {\n" 145 " dict entry {\n"
138 " object_path " 146 " object_path "
139 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor0\"\n" 147 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor0\"\n"
140 " array [\n" 148 " array [\n"
141 " struct {\n" 149 " dict entry {\n"
142 " string \"org.bluez.GattDescriptor1\"\n" 150 " string \"org.bluez.GattDescriptor1\"\n"
143 " array [\n" 151 " array [\n"
144 " dict entry {\n" 152 " dict entry {\n"
145 " string \"UUID\"\n" 153 " string \"UUID\"\n"
146 " variant string " 154 " variant string "
147 "\"00000000-0000-0000-0000-018390008000\"\n" 155 "\"00000000-0000-0000-0000-018390008000\"\n"
148 " }\n" 156 " }\n"
149 " dict entry {\n" 157 " dict entry {\n"
150 " string \"Characteristic\"\n" 158 " string \"Characteristic\"\n"
151 " variant object_path " 159 " variant object_path "
152 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n" 160 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n"
153 " }\n" 161 " }\n"
154 " ]\n" 162 " ]\n"
155 " }\n" 163 " }\n"
156 " ]\n" 164 " ]\n"
157 " }\n" 165 " }\n"
158 " struct {\n" 166 " dict entry {\n"
159 " object_path " 167 " object_path "
160 "\"/fake/hci0/gatt_application/service0/characteristic1/descriptor1\"\n" 168 "\"/fake/hci0/gatt_application/service0/characteristic1/descriptor1\"\n"
161 " array [\n" 169 " array [\n"
162 " struct {\n" 170 " dict entry {\n"
163 " string \"org.bluez.GattDescriptor1\"\n" 171 " string \"org.bluez.GattDescriptor1\"\n"
164 " array [\n" 172 " array [\n"
165 " dict entry {\n" 173 " dict entry {\n"
166 " string \"UUID\"\n" 174 " string \"UUID\"\n"
167 " variant string " 175 " variant string "
168 "\"00000000-0000-0000-0000-018390008000\"\n" 176 "\"00000000-0000-0000-0000-018390008000\"\n"
169 " }\n" 177 " }\n"
170 " dict entry {\n" 178 " dict entry {\n"
171 " string \"Characteristic\"\n" 179 " string \"Characteristic\"\n"
172 " variant object_path " 180 " variant object_path "
173 "\"/fake/hci0/gatt_application/service0/characteristic1\"\n" 181 "\"/fake/hci0/gatt_application/service0/characteristic1\"\n"
174 " }\n" 182 " }\n"
175 " ]\n" 183 " ]\n"
176 " }\n" 184 " }\n"
177 " ]\n" 185 " ]\n"
178 " }\n" 186 " }\n"
179 " struct {\n" 187 " dict entry {\n"
180 " object_path " 188 " object_path "
181 "\"/fake/hci0/gatt_application/service1/characteristic0/descriptor2\"\n" 189 "\"/fake/hci0/gatt_application/service1/characteristic0/descriptor2\"\n"
182 " array [\n" 190 " array [\n"
183 " struct {\n" 191 " dict entry {\n"
184 " string \"org.bluez.GattDescriptor1\"\n" 192 " string \"org.bluez.GattDescriptor1\"\n"
185 " array [\n" 193 " array [\n"
186 " dict entry {\n" 194 " dict entry {\n"
187 " string \"UUID\"\n" 195 " string \"UUID\"\n"
188 " variant string " 196 " variant string "
189 "\"00000000-0000-0000-0000-018390008000\"\n" 197 "\"00000000-0000-0000-0000-018390008000\"\n"
190 " }\n" 198 " }\n"
191 " dict entry {\n" 199 " dict entry {\n"
192 " string \"Characteristic\"\n" 200 " string \"Characteristic\"\n"
193 " variant object_path " 201 " variant object_path "
194 "\"/fake/hci0/gatt_application/service1/characteristic0\"\n" 202 "\"/fake/hci0/gatt_application/service1/characteristic0\"\n"
195 " }\n" 203 " }\n"
196 " ]\n" 204 " ]\n"
197 " }\n" 205 " }\n"
198 " ]\n" 206 " ]\n"
199 " }\n" 207 " }\n"
200 " struct {\n" 208 " dict entry {\n"
201 " object_path " 209 " object_path "
202 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor3\"\n" 210 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor3\"\n"
203 " array [\n" 211 " array [\n"
204 " struct {\n" 212 " dict entry {\n"
205 " string \"org.bluez.GattDescriptor1\"\n" 213 " string \"org.bluez.GattDescriptor1\"\n"
206 " array [\n" 214 " array [\n"
207 " dict entry {\n" 215 " dict entry {\n"
208 " string \"UUID\"\n" 216 " string \"UUID\"\n"
209 " variant string " 217 " variant string "
210 "\"00000000-0000-0000-0000-018390008000\"\n" 218 "\"00000000-0000-0000-0000-018390008000\"\n"
211 " }\n" 219 " }\n"
212 " dict entry {\n" 220 " dict entry {\n"
213 " string \"Characteristic\"\n" 221 " string \"Characteristic\"\n"
214 " variant object_path " 222 " variant object_path "
(...skipping 15 matching lines...) Expand all
230 class BluetoothGattApplicationServiceProviderTest : public testing::Test { 238 class BluetoothGattApplicationServiceProviderTest : public testing::Test {
231 public: 239 public:
232 std::string CreateFakeService( 240 std::string CreateFakeService(
233 dbus::Bus* bus, 241 dbus::Bus* bus,
234 BluetoothGattApplicationServiceProviderImpl* app_provider, 242 BluetoothGattApplicationServiceProviderImpl* app_provider,
235 const std::string& service_path) { 243 const std::string& service_path) {
236 const std::string& full_service_path = 244 const std::string& full_service_path =
237 std::string(kAppObjectPath) + "/" + service_path; 245 std::string(kAppObjectPath) + "/" + service_path;
238 app_provider->service_providers_.push_back( 246 app_provider->service_providers_.push_back(
239 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl( 247 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl(
240 dbus::ObjectPath(full_service_path), kFakeServiceUuid))); 248 dbus::ObjectPath(full_service_path), kFakeServiceUuid, true)));
241 return full_service_path; 249 return full_service_path;
242 } 250 }
243 251
244 std::string CreateFakeCharacteristic( 252 std::string CreateFakeCharacteristic(
245 dbus::Bus* bus, 253 dbus::Bus* bus,
246 BluetoothGattApplicationServiceProviderImpl* app_provider, 254 BluetoothGattApplicationServiceProviderImpl* app_provider,
247 const std::string& characteristic_path, 255 const std::string& characteristic_path,
248 const std::string& service_path) { 256 const std::string& service_path) {
249 const std::string& full_characteristic_path = 257 const std::string& full_characteristic_path =
250 service_path + "/" + characteristic_path; 258 service_path + "/" + characteristic_path;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 CreateFakeAttributes(nullptr, app_provider.get()); 309 CreateFakeAttributes(nullptr, app_provider.get());
302 310
303 dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); 311 dbus::MethodCall method_call("com.example.Interface", "SomeMethod");
304 // Not setting the serial causes a crash. 312 // Not setting the serial causes a crash.
305 method_call.SetSerial(123); 313 method_call.SetSerial(123);
306 app_provider->GetManagedObjects( 314 app_provider->GetManagedObjects(
307 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage)); 315 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage));
308 } 316 }
309 317
310 } // namespace bluez 318 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698