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

Side by Side Diff: dbus/message_unittest.cc

Issue 502793002: Add a GetSignature() method to dbus::MessageReader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « dbus/message.cc ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "dbus/message.h" 5 #include "dbus/message.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
11 #include "dbus/object_path.h" 11 #include "dbus/object_path.h"
12 #include "dbus/test_proto.pb.h" 12 #include "dbus/test_proto.pb.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace dbus { 15 namespace dbus {
16 16
17 // Test that a byte can be properly written and read. We only have this 17 // Test that a byte can be properly written and read. We only have this
18 // test for byte, as repeating this for other basic types is too redundant. 18 // test for byte, as repeating this for other basic types is too redundant.
19 TEST(MessageTest, AppendAndPopByte) { 19 TEST(MessageTest, AppendAndPopByte) {
20 scoped_ptr<Response> message(Response::CreateEmpty()); 20 scoped_ptr<Response> message(Response::CreateEmpty());
21 MessageWriter writer(message.get()); 21 MessageWriter writer(message.get());
22 writer.AppendByte(123); // The input is 123. 22 writer.AppendByte(123); // The input is 123.
23 23
24 MessageReader reader(message.get()); 24 MessageReader reader(message.get());
25 ASSERT_TRUE(reader.HasMoreData()); // Should have data to read. 25 ASSERT_TRUE(reader.HasMoreData()); // Should have data to read.
26 ASSERT_EQ(Message::BYTE, reader.GetDataType()); 26 ASSERT_EQ(Message::BYTE, reader.GetDataType());
27 ASSERT_EQ("y", reader.GetDataSignature());
27 28
28 bool bool_value = false; 29 bool bool_value = false;
29 // Should fail as the type is not bool here. 30 // Should fail as the type is not bool here.
30 ASSERT_FALSE(reader.PopBool(&bool_value)); 31 ASSERT_FALSE(reader.PopBool(&bool_value));
31 32
32 uint8 byte_value = 0; 33 uint8 byte_value = 0;
33 ASSERT_TRUE(reader.PopByte(&byte_value)); 34 ASSERT_TRUE(reader.PopByte(&byte_value));
34 EXPECT_EQ(123, byte_value); // Should match with the input. 35 EXPECT_EQ(123, byte_value); // Should match with the input.
35 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read. 36 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read.
36 37
(...skipping 26 matching lines...) Expand all
63 int32 int32_value = 0; 64 int32 int32_value = 0;
64 uint32 uint32_value = 0; 65 uint32 uint32_value = 0;
65 int64 int64_value = 0; 66 int64 int64_value = 0;
66 uint64 uint64_value = 0; 67 uint64 uint64_value = 0;
67 double double_value = 0; 68 double double_value = 0;
68 std::string string_value; 69 std::string string_value;
69 ObjectPath object_path_value; 70 ObjectPath object_path_value;
70 71
71 MessageReader reader(message.get()); 72 MessageReader reader(message.get());
72 ASSERT_TRUE(reader.HasMoreData()); 73 ASSERT_TRUE(reader.HasMoreData());
74 ASSERT_EQ("y", reader.GetDataSignature());
73 ASSERT_TRUE(reader.PopByte(&byte_value)); 75 ASSERT_TRUE(reader.PopByte(&byte_value));
76 ASSERT_EQ("b", reader.GetDataSignature());
74 ASSERT_TRUE(reader.PopBool(&bool_value)); 77 ASSERT_TRUE(reader.PopBool(&bool_value));
78 ASSERT_EQ("n", reader.GetDataSignature());
75 ASSERT_TRUE(reader.PopInt16(&int16_value)); 79 ASSERT_TRUE(reader.PopInt16(&int16_value));
80 ASSERT_EQ("q", reader.GetDataSignature());
76 ASSERT_TRUE(reader.PopUint16(&uint16_value)); 81 ASSERT_TRUE(reader.PopUint16(&uint16_value));
82 ASSERT_EQ("i", reader.GetDataSignature());
77 ASSERT_TRUE(reader.PopInt32(&int32_value)); 83 ASSERT_TRUE(reader.PopInt32(&int32_value));
84 ASSERT_EQ("u", reader.GetDataSignature());
78 ASSERT_TRUE(reader.PopUint32(&uint32_value)); 85 ASSERT_TRUE(reader.PopUint32(&uint32_value));
86 ASSERT_EQ("x", reader.GetDataSignature());
79 ASSERT_TRUE(reader.PopInt64(&int64_value)); 87 ASSERT_TRUE(reader.PopInt64(&int64_value));
88 ASSERT_EQ("t", reader.GetDataSignature());
80 ASSERT_TRUE(reader.PopUint64(&uint64_value)); 89 ASSERT_TRUE(reader.PopUint64(&uint64_value));
90 ASSERT_EQ("d", reader.GetDataSignature());
81 ASSERT_TRUE(reader.PopDouble(&double_value)); 91 ASSERT_TRUE(reader.PopDouble(&double_value));
92 ASSERT_EQ("s", reader.GetDataSignature());
82 ASSERT_TRUE(reader.PopString(&string_value)); 93 ASSERT_TRUE(reader.PopString(&string_value));
94 ASSERT_EQ("o", reader.GetDataSignature());
83 ASSERT_TRUE(reader.PopObjectPath(&object_path_value)); 95 ASSERT_TRUE(reader.PopObjectPath(&object_path_value));
96 ASSERT_EQ("", reader.GetDataSignature());
84 ASSERT_FALSE(reader.HasMoreData()); 97 ASSERT_FALSE(reader.HasMoreData());
85 98
86 // 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path" should be returned. 99 // 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path" should be returned.
87 EXPECT_EQ(0, byte_value); 100 EXPECT_EQ(0, byte_value);
88 EXPECT_EQ(true, bool_value); 101 EXPECT_EQ(true, bool_value);
89 EXPECT_EQ(2, int16_value); 102 EXPECT_EQ(2, int16_value);
90 EXPECT_EQ(3U, uint16_value); 103 EXPECT_EQ(3U, uint16_value);
91 EXPECT_EQ(4, int32_value); 104 EXPECT_EQ(4, int32_value);
92 EXPECT_EQ(5U, uint32_value); 105 EXPECT_EQ(5U, uint32_value);
93 EXPECT_EQ(6, int64_value); 106 EXPECT_EQ(6, int64_value);
(...skipping 19 matching lines...) Expand all
113 ASSERT_FALSE(temp.is_valid()); 126 ASSERT_FALSE(temp.is_valid());
114 // NB: thread IO requirements not relevant for unit tests. 127 // NB: thread IO requirements not relevant for unit tests.
115 temp.CheckValidity(); 128 temp.CheckValidity();
116 ASSERT_TRUE(temp.is_valid()); 129 ASSERT_TRUE(temp.is_valid());
117 writer.AppendFileDescriptor(temp); 130 writer.AppendFileDescriptor(temp);
118 131
119 FileDescriptor fd_value; 132 FileDescriptor fd_value;
120 133
121 MessageReader reader(message.get()); 134 MessageReader reader(message.get());
122 ASSERT_TRUE(reader.HasMoreData()); 135 ASSERT_TRUE(reader.HasMoreData());
136 ASSERT_EQ(Message::UNIX_FD, reader.GetDataType());
137 ASSERT_EQ("h", reader.GetDataSignature());
123 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); 138 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value));
124 ASSERT_FALSE(reader.HasMoreData()); 139 ASSERT_FALSE(reader.HasMoreData());
125 // Descriptor is not valid until explicitly checked. 140 // Descriptor is not valid until explicitly checked.
126 ASSERT_FALSE(fd_value.is_valid()); 141 ASSERT_FALSE(fd_value.is_valid());
127 fd_value.CheckValidity(); 142 fd_value.CheckValidity();
128 ASSERT_TRUE(fd_value.is_valid()); 143 ASSERT_TRUE(fd_value.is_valid());
129 144
130 // Stdout should be returned but we cannot check the descriptor 145 // Stdout should be returned but we cannot check the descriptor
131 // value because stdout will be dup'd. Instead check st_rdev 146 // value because stdout will be dup'd. Instead check st_rdev
132 // which should be identical. 147 // which should be identical.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 int32 int32_value = 0; 179 int32 int32_value = 0;
165 uint32 uint32_value = 0; 180 uint32 uint32_value = 0;
166 int64 int64_value = 0; 181 int64 int64_value = 0;
167 uint64 uint64_value = 0; 182 uint64 uint64_value = 0;
168 double double_value = 0; 183 double double_value = 0;
169 std::string string_value; 184 std::string string_value;
170 ObjectPath object_path_value; 185 ObjectPath object_path_value;
171 186
172 MessageReader reader(message.get()); 187 MessageReader reader(message.get());
173 ASSERT_TRUE(reader.HasMoreData()); 188 ASSERT_TRUE(reader.HasMoreData());
189 ASSERT_EQ("v", reader.GetDataSignature());
174 ASSERT_TRUE(reader.PopVariantOfByte(&byte_value)); 190 ASSERT_TRUE(reader.PopVariantOfByte(&byte_value));
191 ASSERT_EQ("v", reader.GetDataSignature());
175 ASSERT_TRUE(reader.PopVariantOfBool(&bool_value)); 192 ASSERT_TRUE(reader.PopVariantOfBool(&bool_value));
193 ASSERT_EQ("v", reader.GetDataSignature());
176 ASSERT_TRUE(reader.PopVariantOfInt16(&int16_value)); 194 ASSERT_TRUE(reader.PopVariantOfInt16(&int16_value));
195 ASSERT_EQ("v", reader.GetDataSignature());
177 ASSERT_TRUE(reader.PopVariantOfUint16(&uint16_value)); 196 ASSERT_TRUE(reader.PopVariantOfUint16(&uint16_value));
197 ASSERT_EQ("v", reader.GetDataSignature());
178 ASSERT_TRUE(reader.PopVariantOfInt32(&int32_value)); 198 ASSERT_TRUE(reader.PopVariantOfInt32(&int32_value));
199 ASSERT_EQ("v", reader.GetDataSignature());
179 ASSERT_TRUE(reader.PopVariantOfUint32(&uint32_value)); 200 ASSERT_TRUE(reader.PopVariantOfUint32(&uint32_value));
201 ASSERT_EQ("v", reader.GetDataSignature());
180 ASSERT_TRUE(reader.PopVariantOfInt64(&int64_value)); 202 ASSERT_TRUE(reader.PopVariantOfInt64(&int64_value));
203 ASSERT_EQ("v", reader.GetDataSignature());
181 ASSERT_TRUE(reader.PopVariantOfUint64(&uint64_value)); 204 ASSERT_TRUE(reader.PopVariantOfUint64(&uint64_value));
205 ASSERT_EQ("v", reader.GetDataSignature());
182 ASSERT_TRUE(reader.PopVariantOfDouble(&double_value)); 206 ASSERT_TRUE(reader.PopVariantOfDouble(&double_value));
207 ASSERT_EQ("v", reader.GetDataSignature());
183 ASSERT_TRUE(reader.PopVariantOfString(&string_value)); 208 ASSERT_TRUE(reader.PopVariantOfString(&string_value));
209 ASSERT_EQ("v", reader.GetDataSignature());
184 ASSERT_TRUE(reader.PopVariantOfObjectPath(&object_path_value)); 210 ASSERT_TRUE(reader.PopVariantOfObjectPath(&object_path_value));
211 ASSERT_EQ("", reader.GetDataSignature());
185 ASSERT_FALSE(reader.HasMoreData()); 212 ASSERT_FALSE(reader.HasMoreData());
186 213
187 // 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path" should be returned. 214 // 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path" should be returned.
188 EXPECT_EQ(0, byte_value); 215 EXPECT_EQ(0, byte_value);
189 EXPECT_EQ(true, bool_value); 216 EXPECT_EQ(true, bool_value);
190 EXPECT_EQ(2, int16_value); 217 EXPECT_EQ(2, int16_value);
191 EXPECT_EQ(3U, uint16_value); 218 EXPECT_EQ(3U, uint16_value);
192 EXPECT_EQ(4, int32_value); 219 EXPECT_EQ(4, int32_value);
193 EXPECT_EQ(5U, uint32_value); 220 EXPECT_EQ(5U, uint32_value);
194 EXPECT_EQ(6, int64_value); 221 EXPECT_EQ(6, int64_value);
195 EXPECT_EQ(7U, uint64_value); 222 EXPECT_EQ(7U, uint64_value);
196 EXPECT_DOUBLE_EQ(8.0, double_value); 223 EXPECT_DOUBLE_EQ(8.0, double_value);
197 EXPECT_EQ("string", string_value); 224 EXPECT_EQ("string", string_value);
198 EXPECT_EQ(ObjectPath("/object/path"), object_path_value); 225 EXPECT_EQ(ObjectPath("/object/path"), object_path_value);
199 } 226 }
200 227
201 TEST(MessageTest, ArrayOfBytes) { 228 TEST(MessageTest, ArrayOfBytes) {
202 scoped_ptr<Response> message(Response::CreateEmpty()); 229 scoped_ptr<Response> message(Response::CreateEmpty());
203 MessageWriter writer(message.get()); 230 MessageWriter writer(message.get());
204 std::vector<uint8> bytes; 231 std::vector<uint8> bytes;
205 bytes.push_back(1); 232 bytes.push_back(1);
206 bytes.push_back(2); 233 bytes.push_back(2);
207 bytes.push_back(3); 234 bytes.push_back(3);
208 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); 235 writer.AppendArrayOfBytes(bytes.data(), bytes.size());
209 236
210 MessageReader reader(message.get()); 237 MessageReader reader(message.get());
211 const uint8* output_bytes = NULL; 238 const uint8* output_bytes = NULL;
212 size_t length = 0; 239 size_t length = 0;
240 ASSERT_EQ("ay", reader.GetDataSignature());
213 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); 241 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length));
214 ASSERT_FALSE(reader.HasMoreData()); 242 ASSERT_FALSE(reader.HasMoreData());
215 ASSERT_EQ(3U, length); 243 ASSERT_EQ(3U, length);
216 EXPECT_EQ(1, output_bytes[0]); 244 EXPECT_EQ(1, output_bytes[0]);
217 EXPECT_EQ(2, output_bytes[1]); 245 EXPECT_EQ(2, output_bytes[1]);
218 EXPECT_EQ(3, output_bytes[2]); 246 EXPECT_EQ(3, output_bytes[2]);
219 } 247 }
220 248
221 TEST(MessageTest, ArrayOfBytes_Empty) { 249 TEST(MessageTest, ArrayOfBytes_Empty) {
222 scoped_ptr<Response> message(Response::CreateEmpty()); 250 scoped_ptr<Response> message(Response::CreateEmpty());
223 MessageWriter writer(message.get()); 251 MessageWriter writer(message.get());
224 std::vector<uint8> bytes; 252 std::vector<uint8> bytes;
225 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); 253 writer.AppendArrayOfBytes(bytes.data(), bytes.size());
226 254
227 MessageReader reader(message.get()); 255 MessageReader reader(message.get());
228 const uint8* output_bytes = NULL; 256 const uint8* output_bytes = NULL;
229 size_t length = 0; 257 size_t length = 0;
258 ASSERT_EQ("ay", reader.GetDataSignature());
230 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); 259 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length));
231 ASSERT_FALSE(reader.HasMoreData()); 260 ASSERT_FALSE(reader.HasMoreData());
232 ASSERT_EQ(0U, length); 261 ASSERT_EQ(0U, length);
233 EXPECT_EQ(NULL, output_bytes); 262 EXPECT_EQ(NULL, output_bytes);
234 } 263 }
235 264
236 TEST(MessageTest, ArrayOfStrings) { 265 TEST(MessageTest, ArrayOfStrings) {
237 scoped_ptr<Response> message(Response::CreateEmpty()); 266 scoped_ptr<Response> message(Response::CreateEmpty());
238 MessageWriter writer(message.get()); 267 MessageWriter writer(message.get());
239 std::vector<std::string> strings; 268 std::vector<std::string> strings;
240 strings.push_back("fee"); 269 strings.push_back("fee");
241 strings.push_back("fie"); 270 strings.push_back("fie");
242 strings.push_back("foe"); 271 strings.push_back("foe");
243 strings.push_back("fum"); 272 strings.push_back("fum");
244 writer.AppendArrayOfStrings(strings); 273 writer.AppendArrayOfStrings(strings);
245 274
246 MessageReader reader(message.get()); 275 MessageReader reader(message.get());
247 std::vector<std::string> output_strings; 276 std::vector<std::string> output_strings;
277 ASSERT_EQ("as", reader.GetDataSignature());
248 ASSERT_TRUE(reader.PopArrayOfStrings(&output_strings)); 278 ASSERT_TRUE(reader.PopArrayOfStrings(&output_strings));
249 ASSERT_FALSE(reader.HasMoreData()); 279 ASSERT_FALSE(reader.HasMoreData());
250 ASSERT_EQ(4U, output_strings.size()); 280 ASSERT_EQ(4U, output_strings.size());
251 EXPECT_EQ("fee", output_strings[0]); 281 EXPECT_EQ("fee", output_strings[0]);
252 EXPECT_EQ("fie", output_strings[1]); 282 EXPECT_EQ("fie", output_strings[1]);
253 EXPECT_EQ("foe", output_strings[2]); 283 EXPECT_EQ("foe", output_strings[2]);
254 EXPECT_EQ("fum", output_strings[3]); 284 EXPECT_EQ("fum", output_strings[3]);
255 } 285 }
256 286
257 TEST(MessageTest, ArrayOfObjectPaths) { 287 TEST(MessageTest, ArrayOfObjectPaths) {
258 scoped_ptr<Response> message(Response::CreateEmpty()); 288 scoped_ptr<Response> message(Response::CreateEmpty());
259 MessageWriter writer(message.get()); 289 MessageWriter writer(message.get());
260 std::vector<ObjectPath> object_paths; 290 std::vector<ObjectPath> object_paths;
261 object_paths.push_back(ObjectPath("/object/path/1")); 291 object_paths.push_back(ObjectPath("/object/path/1"));
262 object_paths.push_back(ObjectPath("/object/path/2")); 292 object_paths.push_back(ObjectPath("/object/path/2"));
263 object_paths.push_back(ObjectPath("/object/path/3")); 293 object_paths.push_back(ObjectPath("/object/path/3"));
264 writer.AppendArrayOfObjectPaths(object_paths); 294 writer.AppendArrayOfObjectPaths(object_paths);
265 295
266 MessageReader reader(message.get()); 296 MessageReader reader(message.get());
267 std::vector<ObjectPath> output_object_paths; 297 std::vector<ObjectPath> output_object_paths;
298 ASSERT_EQ("ao", reader.GetDataSignature());
268 ASSERT_TRUE(reader.PopArrayOfObjectPaths(&output_object_paths)); 299 ASSERT_TRUE(reader.PopArrayOfObjectPaths(&output_object_paths));
269 ASSERT_FALSE(reader.HasMoreData()); 300 ASSERT_FALSE(reader.HasMoreData());
270 ASSERT_EQ(3U, output_object_paths.size()); 301 ASSERT_EQ(3U, output_object_paths.size());
271 EXPECT_EQ(ObjectPath("/object/path/1"), output_object_paths[0]); 302 EXPECT_EQ(ObjectPath("/object/path/1"), output_object_paths[0]);
272 EXPECT_EQ(ObjectPath("/object/path/2"), output_object_paths[1]); 303 EXPECT_EQ(ObjectPath("/object/path/2"), output_object_paths[1]);
273 EXPECT_EQ(ObjectPath("/object/path/3"), output_object_paths[2]); 304 EXPECT_EQ(ObjectPath("/object/path/3"), output_object_paths[2]);
274 } 305 }
275 306
276 TEST(MessageTest, ProtoBuf) { 307 TEST(MessageTest, ProtoBuf) {
277 scoped_ptr<Response> message(Response::CreateEmpty()); 308 scoped_ptr<Response> message(Response::CreateEmpty());
278 MessageWriter writer(message.get()); 309 MessageWriter writer(message.get());
279 TestProto send_message; 310 TestProto send_message;
280 send_message.set_text("testing"); 311 send_message.set_text("testing");
281 send_message.set_number(123); 312 send_message.set_number(123);
282 writer.AppendProtoAsArrayOfBytes(send_message); 313 writer.AppendProtoAsArrayOfBytes(send_message);
283 314
284 MessageReader reader(message.get()); 315 MessageReader reader(message.get());
285 TestProto receive_message; 316 TestProto receive_message;
317 ASSERT_EQ("ay", reader.GetDataSignature());
286 ASSERT_TRUE(reader.PopArrayOfBytesAsProto(&receive_message)); 318 ASSERT_TRUE(reader.PopArrayOfBytesAsProto(&receive_message));
287 EXPECT_EQ(receive_message.text(), send_message.text()); 319 EXPECT_EQ(receive_message.text(), send_message.text());
288 EXPECT_EQ(receive_message.number(), send_message.number()); 320 EXPECT_EQ(receive_message.number(), send_message.number());
289 } 321 }
290 322
291 323
292 // Test that an array can be properly written and read. We only have this 324 // Test that an array can be properly written and read. We only have this
293 // test for array, as repeating this for other container types is too 325 // test for array, as repeating this for other container types is too
294 // redundant. 326 // redundant.
295 TEST(MessageTest, OpenArrayAndPopArray) { 327 TEST(MessageTest, OpenArrayAndPopArray) {
296 scoped_ptr<Response> message(Response::CreateEmpty()); 328 scoped_ptr<Response> message(Response::CreateEmpty());
297 MessageWriter writer(message.get()); 329 MessageWriter writer(message.get());
298 MessageWriter array_writer(NULL); 330 MessageWriter array_writer(NULL);
299 writer.OpenArray("s", &array_writer); // Open an array of strings. 331 writer.OpenArray("s", &array_writer); // Open an array of strings.
300 array_writer.AppendString("foo"); 332 array_writer.AppendString("foo");
301 array_writer.AppendString("bar"); 333 array_writer.AppendString("bar");
302 array_writer.AppendString("baz"); 334 array_writer.AppendString("baz");
303 writer.CloseContainer(&array_writer); 335 writer.CloseContainer(&array_writer);
304 336
305 MessageReader reader(message.get()); 337 MessageReader reader(message.get());
306 ASSERT_EQ(Message::ARRAY, reader.GetDataType()); 338 ASSERT_EQ(Message::ARRAY, reader.GetDataType());
339 ASSERT_EQ("as", reader.GetDataSignature());
307 MessageReader array_reader(NULL); 340 MessageReader array_reader(NULL);
308 ASSERT_TRUE(reader.PopArray(&array_reader)); 341 ASSERT_TRUE(reader.PopArray(&array_reader));
309 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read. 342 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read.
310 343
311 std::string string_value; 344 std::string string_value;
312 ASSERT_TRUE(array_reader.PopString(&string_value)); 345 ASSERT_TRUE(array_reader.PopString(&string_value));
313 EXPECT_EQ("foo", string_value); 346 EXPECT_EQ("foo", string_value);
314 ASSERT_TRUE(array_reader.PopString(&string_value)); 347 ASSERT_TRUE(array_reader.PopString(&string_value));
315 EXPECT_EQ("bar", string_value); 348 EXPECT_EQ("bar", string_value);
316 ASSERT_TRUE(array_reader.PopString(&string_value)); 349 ASSERT_TRUE(array_reader.PopString(&string_value));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 " variant array [\n" 423 " variant array [\n"
391 " dict entry {\n" 424 " dict entry {\n"
392 " string \"foo\"\n" 425 " string \"foo\"\n"
393 " int64 1234567890123456789\n" 426 " int64 1234567890123456789\n"
394 " }\n" 427 " }\n"
395 " ]\n" 428 " ]\n"
396 "]\n", 429 "]\n",
397 message->ToString()); 430 message->ToString());
398 431
399 MessageReader reader(message.get()); 432 MessageReader reader(message.get());
433 ASSERT_EQ("av", reader.GetDataSignature());
400 MessageReader array_reader(NULL); 434 MessageReader array_reader(NULL);
401 ASSERT_TRUE(reader.PopArray(&array_reader)); 435 ASSERT_TRUE(reader.PopArray(&array_reader));
402 436
403 // The first value in the array. 437 // The first value in the array.
404 bool bool_value = false; 438 bool bool_value = false;
439 ASSERT_EQ("v", array_reader.GetDataSignature());
405 ASSERT_TRUE(array_reader.PopVariantOfBool(&bool_value)); 440 ASSERT_TRUE(array_reader.PopVariantOfBool(&bool_value));
406 EXPECT_EQ(true, bool_value); 441 EXPECT_EQ(true, bool_value);
407 442
408 // The second value in the array. 443 // The second value in the array.
409 { 444 {
410 MessageReader variant_reader(NULL); 445 MessageReader variant_reader(NULL);
411 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); 446 ASSERT_TRUE(array_reader.PopVariant(&variant_reader));
412 { 447 {
413 MessageReader struct_reader(NULL); 448 MessageReader struct_reader(NULL);
449 ASSERT_EQ("(si)", variant_reader.GetDataSignature());
414 ASSERT_TRUE(variant_reader.PopStruct(&struct_reader)); 450 ASSERT_TRUE(variant_reader.PopStruct(&struct_reader));
415 std::string string_value; 451 std::string string_value;
416 ASSERT_TRUE(struct_reader.PopString(&string_value)); 452 ASSERT_TRUE(struct_reader.PopString(&string_value));
417 EXPECT_EQ("string", string_value); 453 EXPECT_EQ("string", string_value);
418 int32 int32_value = 0; 454 int32 int32_value = 0;
419 ASSERT_TRUE(struct_reader.PopInt32(&int32_value)); 455 ASSERT_TRUE(struct_reader.PopInt32(&int32_value));
420 EXPECT_EQ(123, int32_value); 456 EXPECT_EQ(123, int32_value);
421 ASSERT_FALSE(struct_reader.HasMoreData()); 457 ASSERT_FALSE(struct_reader.HasMoreData());
422 } 458 }
423 ASSERT_FALSE(variant_reader.HasMoreData()); 459 ASSERT_FALSE(variant_reader.HasMoreData());
424 } 460 }
425 461
426 // The third value in the array. 462 // The third value in the array.
427 { 463 {
428 MessageReader variant_reader(NULL); 464 MessageReader variant_reader(NULL);
429 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); 465 ASSERT_TRUE(array_reader.PopVariant(&variant_reader));
430 { 466 {
431 MessageReader dict_array_reader(NULL); 467 MessageReader dict_array_reader(NULL);
468 ASSERT_EQ("a{sx}", variant_reader.GetDataSignature());
432 ASSERT_TRUE(variant_reader.PopArray(&dict_array_reader)); 469 ASSERT_TRUE(variant_reader.PopArray(&dict_array_reader));
433 { 470 {
434 MessageReader dict_entry_reader(NULL); 471 MessageReader dict_entry_reader(NULL);
435 ASSERT_TRUE(dict_array_reader.PopDictEntry(&dict_entry_reader)); 472 ASSERT_TRUE(dict_array_reader.PopDictEntry(&dict_entry_reader));
436 std::string string_value; 473 std::string string_value;
437 ASSERT_TRUE(dict_entry_reader.PopString(&string_value)); 474 ASSERT_TRUE(dict_entry_reader.PopString(&string_value));
438 EXPECT_EQ("foo", string_value); 475 EXPECT_EQ("foo", string_value);
439 int64 int64_value = 0; 476 int64 int64_value = 0;
440 ASSERT_TRUE(dict_entry_reader.PopInt64(&int64_value)); 477 ASSERT_TRUE(dict_entry_reader.PopInt64(&int64_value));
441 EXPECT_EQ(GG_INT64_C(1234567890123456789), int64_value); 478 EXPECT_EQ(GG_INT64_C(1234567890123456789), int64_value);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 660
624 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" 661 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n"
625 "signature: s\n\n" 662 "signature: s\n\n"
626 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo" 663 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo"
627 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... " 664 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... "
628 "(1000 bytes in total)\"\n", 665 "(1000 bytes in total)\"\n",
629 message->ToString()); 666 message->ToString());
630 } 667 }
631 668
632 } // namespace dbus 669 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698