| OLD | NEW |
| 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 <stddef.h> |
| 7 #include <stdint.h> | 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
| 13 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
| 14 #include "dbus/test_proto.pb.h" | 14 #include "dbus/test_proto.pb.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace dbus { | 17 namespace dbus { |
| 18 | 18 |
| 19 // Test that a byte can be properly written and read. We only have this | 19 // Test that a byte can be properly written and read. We only have this |
| 20 // test for byte, as repeating this for other basic types is too redundant. | 20 // test for byte, as repeating this for other basic types is too redundant. |
| 21 TEST(MessageTest, AppendAndPopByte) { | 21 TEST(MessageTest, AppendAndPopByte) { |
| 22 scoped_ptr<Response> message(Response::CreateEmpty()); | 22 scoped_ptr<Response> message(Response::CreateEmpty()); |
| 23 MessageWriter writer(message.get()); | 23 MessageWriter writer(message.get()); |
| 24 writer.AppendByte(123); // The input is 123. | 24 writer.AppendByte(123); // The input is 123. |
| 25 | 25 |
| 26 MessageReader reader(message.get()); | 26 MessageReader reader(message.get()); |
| 27 ASSERT_TRUE(reader.HasMoreData()); // Should have data to read. | 27 ASSERT_TRUE(reader.HasMoreData()); // Should have data to read. |
| 28 ASSERT_EQ(Message::BYTE, reader.GetDataType()); | 28 ASSERT_EQ(Message::BYTE, reader.GetDataType()); |
| 29 ASSERT_EQ("y", reader.GetDataSignature()); | 29 ASSERT_EQ("y", reader.GetDataSignature()); |
| 30 | 30 |
| 31 bool bool_value = false; | 31 bool bool_value = false; |
| 32 // Should fail as the type is not bool here. | 32 // Should fail as the type is not bool here. |
| 33 ASSERT_FALSE(reader.PopBool(&bool_value)); | 33 ASSERT_FALSE(reader.PopBool(&bool_value)); |
| 34 | 34 |
| 35 uint8 byte_value = 0; | 35 uint8_t byte_value = 0; |
| 36 ASSERT_TRUE(reader.PopByte(&byte_value)); | 36 ASSERT_TRUE(reader.PopByte(&byte_value)); |
| 37 EXPECT_EQ(123, byte_value); // Should match with the input. | 37 EXPECT_EQ(123, byte_value); // Should match with the input. |
| 38 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read. | 38 ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read. |
| 39 | 39 |
| 40 // Try to get another byte. Should fail. | 40 // Try to get another byte. Should fail. |
| 41 ASSERT_FALSE(reader.PopByte(&byte_value)); | 41 ASSERT_FALSE(reader.PopByte(&byte_value)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Check all basic types can be properly written and read. | 44 // Check all basic types can be properly written and read. |
| 45 TEST(MessageTest, AppendAndPopBasicDataTypes) { | 45 TEST(MessageTest, AppendAndPopBasicDataTypes) { |
| 46 scoped_ptr<Response> message(Response::CreateEmpty()); | 46 scoped_ptr<Response> message(Response::CreateEmpty()); |
| 47 MessageWriter writer(message.get()); | 47 MessageWriter writer(message.get()); |
| 48 | 48 |
| 49 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". | 49 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". |
| 50 writer.AppendByte(0); | 50 writer.AppendByte(0); |
| 51 writer.AppendBool(true); | 51 writer.AppendBool(true); |
| 52 writer.AppendInt16(2); | 52 writer.AppendInt16(2); |
| 53 writer.AppendUint16(3); | 53 writer.AppendUint16(3); |
| 54 writer.AppendInt32(4); | 54 writer.AppendInt32(4); |
| 55 writer.AppendUint32(5); | 55 writer.AppendUint32(5); |
| 56 writer.AppendInt64(6); | 56 writer.AppendInt64(6); |
| 57 writer.AppendUint64(7); | 57 writer.AppendUint64(7); |
| 58 writer.AppendDouble(8.0); | 58 writer.AppendDouble(8.0); |
| 59 writer.AppendString("string"); | 59 writer.AppendString("string"); |
| 60 writer.AppendObjectPath(ObjectPath("/object/path")); | 60 writer.AppendObjectPath(ObjectPath("/object/path")); |
| 61 | 61 |
| 62 uint8 byte_value = 0; | 62 uint8_t byte_value = 0; |
| 63 bool bool_value = false; | 63 bool bool_value = false; |
| 64 int16 int16_value = 0; | 64 int16_t int16_value = 0; |
| 65 uint16 uint16_value = 0; | 65 uint16_t uint16_value = 0; |
| 66 int32 int32_value = 0; | 66 int32_t int32_value = 0; |
| 67 uint32 uint32_value = 0; | 67 uint32_t uint32_value = 0; |
| 68 int64 int64_value = 0; | 68 int64_t int64_value = 0; |
| 69 uint64 uint64_value = 0; | 69 uint64_t uint64_value = 0; |
| 70 double double_value = 0; | 70 double double_value = 0; |
| 71 std::string string_value; | 71 std::string string_value; |
| 72 ObjectPath object_path_value; | 72 ObjectPath object_path_value; |
| 73 | 73 |
| 74 MessageReader reader(message.get()); | 74 MessageReader reader(message.get()); |
| 75 ASSERT_TRUE(reader.HasMoreData()); | 75 ASSERT_TRUE(reader.HasMoreData()); |
| 76 ASSERT_EQ("y", reader.GetDataSignature()); | 76 ASSERT_EQ("y", reader.GetDataSignature()); |
| 77 ASSERT_TRUE(reader.PopByte(&byte_value)); | 77 ASSERT_TRUE(reader.PopByte(&byte_value)); |
| 78 ASSERT_EQ("b", reader.GetDataSignature()); | 78 ASSERT_EQ("b", reader.GetDataSignature()); |
| 79 ASSERT_TRUE(reader.PopBool(&bool_value)); | 79 ASSERT_TRUE(reader.PopBool(&bool_value)); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 writer.AppendVariantOfInt16(2); | 167 writer.AppendVariantOfInt16(2); |
| 168 writer.AppendVariantOfUint16(3); | 168 writer.AppendVariantOfUint16(3); |
| 169 writer.AppendVariantOfInt32(4); | 169 writer.AppendVariantOfInt32(4); |
| 170 writer.AppendVariantOfUint32(5); | 170 writer.AppendVariantOfUint32(5); |
| 171 writer.AppendVariantOfInt64(6); | 171 writer.AppendVariantOfInt64(6); |
| 172 writer.AppendVariantOfUint64(7); | 172 writer.AppendVariantOfUint64(7); |
| 173 writer.AppendVariantOfDouble(8.0); | 173 writer.AppendVariantOfDouble(8.0); |
| 174 writer.AppendVariantOfString("string"); | 174 writer.AppendVariantOfString("string"); |
| 175 writer.AppendVariantOfObjectPath(ObjectPath("/object/path")); | 175 writer.AppendVariantOfObjectPath(ObjectPath("/object/path")); |
| 176 | 176 |
| 177 uint8 byte_value = 0; | 177 uint8_t byte_value = 0; |
| 178 bool bool_value = false; | 178 bool bool_value = false; |
| 179 int16 int16_value = 0; | 179 int16_t int16_value = 0; |
| 180 uint16 uint16_value = 0; | 180 uint16_t uint16_value = 0; |
| 181 int32 int32_value = 0; | 181 int32_t int32_value = 0; |
| 182 uint32 uint32_value = 0; | 182 uint32_t uint32_value = 0; |
| 183 int64 int64_value = 0; | 183 int64_t int64_value = 0; |
| 184 uint64 uint64_value = 0; | 184 uint64_t uint64_value = 0; |
| 185 double double_value = 0; | 185 double double_value = 0; |
| 186 std::string string_value; | 186 std::string string_value; |
| 187 ObjectPath object_path_value; | 187 ObjectPath object_path_value; |
| 188 | 188 |
| 189 MessageReader reader(message.get()); | 189 MessageReader reader(message.get()); |
| 190 ASSERT_TRUE(reader.HasMoreData()); | 190 ASSERT_TRUE(reader.HasMoreData()); |
| 191 ASSERT_EQ("v", reader.GetDataSignature()); | 191 ASSERT_EQ("v", reader.GetDataSignature()); |
| 192 ASSERT_TRUE(reader.PopVariantOfByte(&byte_value)); | 192 ASSERT_TRUE(reader.PopVariantOfByte(&byte_value)); |
| 193 ASSERT_EQ("v", reader.GetDataSignature()); | 193 ASSERT_EQ("v", reader.GetDataSignature()); |
| 194 ASSERT_TRUE(reader.PopVariantOfBool(&bool_value)); | 194 ASSERT_TRUE(reader.PopVariantOfBool(&bool_value)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 223 EXPECT_EQ(6, int64_value); | 223 EXPECT_EQ(6, int64_value); |
| 224 EXPECT_EQ(7U, uint64_value); | 224 EXPECT_EQ(7U, uint64_value); |
| 225 EXPECT_DOUBLE_EQ(8.0, double_value); | 225 EXPECT_DOUBLE_EQ(8.0, double_value); |
| 226 EXPECT_EQ("string", string_value); | 226 EXPECT_EQ("string", string_value); |
| 227 EXPECT_EQ(ObjectPath("/object/path"), object_path_value); | 227 EXPECT_EQ(ObjectPath("/object/path"), object_path_value); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST(MessageTest, ArrayOfBytes) { | 230 TEST(MessageTest, ArrayOfBytes) { |
| 231 scoped_ptr<Response> message(Response::CreateEmpty()); | 231 scoped_ptr<Response> message(Response::CreateEmpty()); |
| 232 MessageWriter writer(message.get()); | 232 MessageWriter writer(message.get()); |
| 233 std::vector<uint8> bytes; | 233 std::vector<uint8_t> bytes; |
| 234 bytes.push_back(1); | 234 bytes.push_back(1); |
| 235 bytes.push_back(2); | 235 bytes.push_back(2); |
| 236 bytes.push_back(3); | 236 bytes.push_back(3); |
| 237 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); | 237 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); |
| 238 | 238 |
| 239 MessageReader reader(message.get()); | 239 MessageReader reader(message.get()); |
| 240 const uint8* output_bytes = NULL; | 240 const uint8_t* output_bytes = NULL; |
| 241 size_t length = 0; | 241 size_t length = 0; |
| 242 ASSERT_EQ("ay", reader.GetDataSignature()); | 242 ASSERT_EQ("ay", reader.GetDataSignature()); |
| 243 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); | 243 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); |
| 244 ASSERT_FALSE(reader.HasMoreData()); | 244 ASSERT_FALSE(reader.HasMoreData()); |
| 245 ASSERT_EQ(3U, length); | 245 ASSERT_EQ(3U, length); |
| 246 EXPECT_EQ(1, output_bytes[0]); | 246 EXPECT_EQ(1, output_bytes[0]); |
| 247 EXPECT_EQ(2, output_bytes[1]); | 247 EXPECT_EQ(2, output_bytes[1]); |
| 248 EXPECT_EQ(3, output_bytes[2]); | 248 EXPECT_EQ(3, output_bytes[2]); |
| 249 } | 249 } |
| 250 | 250 |
| 251 TEST(MessageTest, ArrayOfBytes_Empty) { | 251 TEST(MessageTest, ArrayOfBytes_Empty) { |
| 252 scoped_ptr<Response> message(Response::CreateEmpty()); | 252 scoped_ptr<Response> message(Response::CreateEmpty()); |
| 253 MessageWriter writer(message.get()); | 253 MessageWriter writer(message.get()); |
| 254 std::vector<uint8> bytes; | 254 std::vector<uint8_t> bytes; |
| 255 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); | 255 writer.AppendArrayOfBytes(bytes.data(), bytes.size()); |
| 256 | 256 |
| 257 MessageReader reader(message.get()); | 257 MessageReader reader(message.get()); |
| 258 const uint8* output_bytes = NULL; | 258 const uint8_t* output_bytes = NULL; |
| 259 size_t length = 0; | 259 size_t length = 0; |
| 260 ASSERT_EQ("ay", reader.GetDataSignature()); | 260 ASSERT_EQ("ay", reader.GetDataSignature()); |
| 261 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); | 261 ASSERT_TRUE(reader.PopArrayOfBytes(&output_bytes, &length)); |
| 262 ASSERT_FALSE(reader.HasMoreData()); | 262 ASSERT_FALSE(reader.HasMoreData()); |
| 263 ASSERT_EQ(0U, length); | 263 ASSERT_EQ(0U, length); |
| 264 EXPECT_EQ(NULL, output_bytes); | 264 EXPECT_EQ(NULL, output_bytes); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST(MessageTest, ArrayOfStrings) { | 267 TEST(MessageTest, ArrayOfStrings) { |
| 268 scoped_ptr<Response> message(Response::CreateEmpty()); | 268 scoped_ptr<Response> message(Response::CreateEmpty()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 MessageWriter variant_writer(NULL); | 369 MessageWriter variant_writer(NULL); |
| 370 // Open a variant of a boolean. | 370 // Open a variant of a boolean. |
| 371 array_writer.OpenVariant("b", &variant_writer); | 371 array_writer.OpenVariant("b", &variant_writer); |
| 372 variant_writer.AppendBool(true); | 372 variant_writer.AppendBool(true); |
| 373 array_writer.CloseContainer(&variant_writer); | 373 array_writer.CloseContainer(&variant_writer); |
| 374 } | 374 } |
| 375 | 375 |
| 376 // The second value in the array. | 376 // The second value in the array. |
| 377 { | 377 { |
| 378 MessageWriter variant_writer(NULL); | 378 MessageWriter variant_writer(NULL); |
| 379 // Open a variant of a struct that contains a string and an int32. | 379 // Open a variant of a struct that contains a string and an int32_t. |
| 380 array_writer.OpenVariant("(si)", &variant_writer); | 380 array_writer.OpenVariant("(si)", &variant_writer); |
| 381 { | 381 { |
| 382 MessageWriter struct_writer(NULL); | 382 MessageWriter struct_writer(NULL); |
| 383 variant_writer.OpenStruct(&struct_writer); | 383 variant_writer.OpenStruct(&struct_writer); |
| 384 struct_writer.AppendString("string"); | 384 struct_writer.AppendString("string"); |
| 385 struct_writer.AppendInt32(123); | 385 struct_writer.AppendInt32(123); |
| 386 variant_writer.CloseContainer(&struct_writer); | 386 variant_writer.CloseContainer(&struct_writer); |
| 387 } | 387 } |
| 388 array_writer.CloseContainer(&variant_writer); | 388 array_writer.CloseContainer(&variant_writer); |
| 389 } | 389 } |
| 390 | 390 |
| 391 // The third value in the array. | 391 // The third value in the array. |
| 392 { | 392 { |
| 393 MessageWriter variant_writer(NULL); | 393 MessageWriter variant_writer(NULL); |
| 394 // Open a variant of an array of string-to-int64 dict entries. | 394 // Open a variant of an array of string-to-int64_t dict entries. |
| 395 array_writer.OpenVariant("a{sx}", &variant_writer); | 395 array_writer.OpenVariant("a{sx}", &variant_writer); |
| 396 { | 396 { |
| 397 // Opens an array of string-to-int64 dict entries. | 397 // Opens an array of string-to-int64_t dict entries. |
| 398 MessageWriter dict_array_writer(NULL); | 398 MessageWriter dict_array_writer(NULL); |
| 399 variant_writer.OpenArray("{sx}", &dict_array_writer); | 399 variant_writer.OpenArray("{sx}", &dict_array_writer); |
| 400 { | 400 { |
| 401 // Opens a string-to-int64 dict entries. | 401 // Opens a string-to-int64_t dict entries. |
| 402 MessageWriter dict_entry_writer(NULL); | 402 MessageWriter dict_entry_writer(NULL); |
| 403 dict_array_writer.OpenDictEntry(&dict_entry_writer); | 403 dict_array_writer.OpenDictEntry(&dict_entry_writer); |
| 404 dict_entry_writer.AppendString("foo"); | 404 dict_entry_writer.AppendString("foo"); |
| 405 dict_entry_writer.AppendInt64(INT64_C(1234567890123456789)); | 405 dict_entry_writer.AppendInt64(INT64_C(1234567890123456789)); |
| 406 dict_array_writer.CloseContainer(&dict_entry_writer); | 406 dict_array_writer.CloseContainer(&dict_entry_writer); |
| 407 } | 407 } |
| 408 variant_writer.CloseContainer(&dict_array_writer); | 408 variant_writer.CloseContainer(&dict_array_writer); |
| 409 } | 409 } |
| 410 array_writer.CloseContainer(&variant_writer); | 410 array_writer.CloseContainer(&variant_writer); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 writer.CloseContainer(&array_writer); | 413 writer.CloseContainer(&array_writer); |
| 414 } | 414 } |
| 415 // What we have created looks like this: | 415 // What we have created looks like this: |
| 416 EXPECT_EQ("message_type: MESSAGE_METHOD_RETURN\n" | 416 EXPECT_EQ( |
| 417 "signature: av\n" | 417 "message_type: MESSAGE_METHOD_RETURN\n" |
| 418 "\n" | 418 "signature: av\n" |
| 419 "array [\n" | 419 "\n" |
| 420 " variant bool true\n" | 420 "array [\n" |
| 421 " variant struct {\n" | 421 " variant bool true\n" |
| 422 " string \"string\"\n" | 422 " variant struct {\n" |
| 423 " int32 123\n" | 423 " string \"string\"\n" |
| 424 " }\n" | 424 " int32_t 123\n" |
| 425 " variant array [\n" | 425 " }\n" |
| 426 " dict entry {\n" | 426 " variant array [\n" |
| 427 " string \"foo\"\n" | 427 " dict entry {\n" |
| 428 " int64 1234567890123456789\n" | 428 " string \"foo\"\n" |
| 429 " }\n" | 429 " int64_t 1234567890123456789\n" |
| 430 " ]\n" | 430 " }\n" |
| 431 "]\n", | 431 " ]\n" |
| 432 message->ToString()); | 432 "]\n", |
| 433 message->ToString()); |
| 433 | 434 |
| 434 MessageReader reader(message.get()); | 435 MessageReader reader(message.get()); |
| 435 ASSERT_EQ("av", reader.GetDataSignature()); | 436 ASSERT_EQ("av", reader.GetDataSignature()); |
| 436 MessageReader array_reader(NULL); | 437 MessageReader array_reader(NULL); |
| 437 ASSERT_TRUE(reader.PopArray(&array_reader)); | 438 ASSERT_TRUE(reader.PopArray(&array_reader)); |
| 438 | 439 |
| 439 // The first value in the array. | 440 // The first value in the array. |
| 440 bool bool_value = false; | 441 bool bool_value = false; |
| 441 ASSERT_EQ("v", array_reader.GetDataSignature()); | 442 ASSERT_EQ("v", array_reader.GetDataSignature()); |
| 442 ASSERT_TRUE(array_reader.PopVariantOfBool(&bool_value)); | 443 ASSERT_TRUE(array_reader.PopVariantOfBool(&bool_value)); |
| 443 EXPECT_EQ(true, bool_value); | 444 EXPECT_EQ(true, bool_value); |
| 444 | 445 |
| 445 // The second value in the array. | 446 // The second value in the array. |
| 446 { | 447 { |
| 447 MessageReader variant_reader(NULL); | 448 MessageReader variant_reader(NULL); |
| 448 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); | 449 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); |
| 449 { | 450 { |
| 450 MessageReader struct_reader(NULL); | 451 MessageReader struct_reader(NULL); |
| 451 ASSERT_EQ("(si)", variant_reader.GetDataSignature()); | 452 ASSERT_EQ("(si)", variant_reader.GetDataSignature()); |
| 452 ASSERT_TRUE(variant_reader.PopStruct(&struct_reader)); | 453 ASSERT_TRUE(variant_reader.PopStruct(&struct_reader)); |
| 453 std::string string_value; | 454 std::string string_value; |
| 454 ASSERT_TRUE(struct_reader.PopString(&string_value)); | 455 ASSERT_TRUE(struct_reader.PopString(&string_value)); |
| 455 EXPECT_EQ("string", string_value); | 456 EXPECT_EQ("string", string_value); |
| 456 int32 int32_value = 0; | 457 int32_t int32_value = 0; |
| 457 ASSERT_TRUE(struct_reader.PopInt32(&int32_value)); | 458 ASSERT_TRUE(struct_reader.PopInt32(&int32_value)); |
| 458 EXPECT_EQ(123, int32_value); | 459 EXPECT_EQ(123, int32_value); |
| 459 ASSERT_FALSE(struct_reader.HasMoreData()); | 460 ASSERT_FALSE(struct_reader.HasMoreData()); |
| 460 } | 461 } |
| 461 ASSERT_FALSE(variant_reader.HasMoreData()); | 462 ASSERT_FALSE(variant_reader.HasMoreData()); |
| 462 } | 463 } |
| 463 | 464 |
| 464 // The third value in the array. | 465 // The third value in the array. |
| 465 { | 466 { |
| 466 MessageReader variant_reader(NULL); | 467 MessageReader variant_reader(NULL); |
| 467 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); | 468 ASSERT_TRUE(array_reader.PopVariant(&variant_reader)); |
| 468 { | 469 { |
| 469 MessageReader dict_array_reader(NULL); | 470 MessageReader dict_array_reader(NULL); |
| 470 ASSERT_EQ("a{sx}", variant_reader.GetDataSignature()); | 471 ASSERT_EQ("a{sx}", variant_reader.GetDataSignature()); |
| 471 ASSERT_TRUE(variant_reader.PopArray(&dict_array_reader)); | 472 ASSERT_TRUE(variant_reader.PopArray(&dict_array_reader)); |
| 472 { | 473 { |
| 473 MessageReader dict_entry_reader(NULL); | 474 MessageReader dict_entry_reader(NULL); |
| 474 ASSERT_TRUE(dict_array_reader.PopDictEntry(&dict_entry_reader)); | 475 ASSERT_TRUE(dict_array_reader.PopDictEntry(&dict_entry_reader)); |
| 475 std::string string_value; | 476 std::string string_value; |
| 476 ASSERT_TRUE(dict_entry_reader.PopString(&string_value)); | 477 ASSERT_TRUE(dict_entry_reader.PopString(&string_value)); |
| 477 EXPECT_EQ("foo", string_value); | 478 EXPECT_EQ("foo", string_value); |
| 478 int64 int64_value = 0; | 479 int64_t int64_value = 0; |
| 479 ASSERT_TRUE(dict_entry_reader.PopInt64(&int64_value)); | 480 ASSERT_TRUE(dict_entry_reader.PopInt64(&int64_value)); |
| 480 EXPECT_EQ(INT64_C(1234567890123456789), int64_value); | 481 EXPECT_EQ(INT64_C(1234567890123456789), int64_value); |
| 481 } | 482 } |
| 482 ASSERT_FALSE(dict_array_reader.HasMoreData()); | 483 ASSERT_FALSE(dict_array_reader.HasMoreData()); |
| 483 } | 484 } |
| 484 ASSERT_FALSE(variant_reader.HasMoreData()); | 485 ASSERT_FALSE(variant_reader.HasMoreData()); |
| 485 } | 486 } |
| 486 ASSERT_FALSE(array_reader.HasMoreData()); | 487 ASSERT_FALSE(array_reader.HasMoreData()); |
| 487 ASSERT_FALSE(reader.HasMoreData()); | 488 ASSERT_FALSE(reader.HasMoreData()); |
| 488 } | 489 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 551 } |
| 551 | 552 |
| 552 TEST(MessageTest, Response) { | 553 TEST(MessageTest, Response) { |
| 553 scoped_ptr<Response> response(Response::CreateEmpty()); | 554 scoped_ptr<Response> response(Response::CreateEmpty()); |
| 554 EXPECT_TRUE(response->raw_message()); | 555 EXPECT_TRUE(response->raw_message()); |
| 555 EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); | 556 EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); |
| 556 EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); | 557 EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); |
| 557 } | 558 } |
| 558 | 559 |
| 559 TEST(MessageTest, Response_FromMethodCall) { | 560 TEST(MessageTest, Response_FromMethodCall) { |
| 560 const uint32 kSerial = 123; | 561 const uint32_t kSerial = 123; |
| 561 MethodCall method_call("com.example.Interface", "SomeMethod"); | 562 MethodCall method_call("com.example.Interface", "SomeMethod"); |
| 562 method_call.SetSerial(kSerial); | 563 method_call.SetSerial(kSerial); |
| 563 | 564 |
| 564 scoped_ptr<Response> response( | 565 scoped_ptr<Response> response( |
| 565 Response::FromMethodCall(&method_call)); | 566 Response::FromMethodCall(&method_call)); |
| 566 EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); | 567 EXPECT_EQ(Message::MESSAGE_METHOD_RETURN, response->GetMessageType()); |
| 567 EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); | 568 EXPECT_EQ("MESSAGE_METHOD_RETURN", response->GetMessageTypeAsString()); |
| 568 // The serial should be copied to the reply serial. | 569 // The serial should be copied to the reply serial. |
| 569 EXPECT_EQ(kSerial, response->GetReplySerial()); | 570 EXPECT_EQ(kSerial, response->GetReplySerial()); |
| 570 } | 571 } |
| 571 | 572 |
| 572 TEST(MessageTest, ErrorResponse_FromMethodCall) { | 573 TEST(MessageTest, ErrorResponse_FromMethodCall) { |
| 573 const uint32 kSerial = 123; | 574 const uint32_t kSerial = 123; |
| 574 const char kErrorMessage[] = "error message"; | 575 const char kErrorMessage[] = "error message"; |
| 575 | 576 |
| 576 MethodCall method_call("com.example.Interface", "SomeMethod"); | 577 MethodCall method_call("com.example.Interface", "SomeMethod"); |
| 577 method_call.SetSerial(kSerial); | 578 method_call.SetSerial(kSerial); |
| 578 | 579 |
| 579 scoped_ptr<ErrorResponse> error_response( | 580 scoped_ptr<ErrorResponse> error_response( |
| 580 ErrorResponse::FromMethodCall(&method_call, | 581 ErrorResponse::FromMethodCall(&method_call, |
| 581 DBUS_ERROR_FAILED, | 582 DBUS_ERROR_FAILED, |
| 582 kErrorMessage)); | 583 kErrorMessage)); |
| 583 EXPECT_EQ(Message::MESSAGE_ERROR, error_response->GetMessageType()); | 584 EXPECT_EQ(Message::MESSAGE_ERROR, error_response->GetMessageType()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 663 |
| 663 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" | 664 ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" |
| 664 "signature: s\n\n" | 665 "signature: s\n\n" |
| 665 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo" | 666 "string \"oooooooooooooooooooooooooooooooooooooooooooooooo" |
| 666 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... " | 667 "oooooooooooooooooooooooooooooooooooooooooooooooooooo... " |
| 667 "(1000 bytes in total)\"\n", | 668 "(1000 bytes in total)\"\n", |
| 668 message->ToString()); | 669 message->ToString()); |
| 669 } | 670 } |
| 670 | 671 |
| 671 } // namespace dbus | 672 } // namespace dbus |
| OLD | NEW |