Chromium Code Reviews| 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 "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 "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 // Try to get another byte. Should fail. | 34 // Try to get another byte. Should fail. |
| 35 ASSERT_FALSE(reader.PopByte(&byte_value)); | 35 ASSERT_FALSE(reader.PopByte(&byte_value)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Check all basic types can be properly written and read. | 38 // Check all basic types can be properly written and read. |
| 39 TEST(MessageTest, AppendAndPopBasicDataTypes) { | 39 TEST(MessageTest, AppendAndPopBasicDataTypes) { |
| 40 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 40 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 41 dbus::MessageWriter writer(message.get()); | 41 dbus::MessageWriter writer(message.get()); |
| 42 | 42 |
| 43 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". | 43 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path", stdout. |
|
satorux1
2012/03/28 20:49:37
nit: remove ", stdout"
Sam Leffler
2012/03/28 22:06:33
Done.
| |
| 44 writer.AppendByte(0); | 44 writer.AppendByte(0); |
| 45 writer.AppendBool(true); | 45 writer.AppendBool(true); |
| 46 writer.AppendInt16(2); | 46 writer.AppendInt16(2); |
| 47 writer.AppendUint16(3); | 47 writer.AppendUint16(3); |
| 48 writer.AppendInt32(4); | 48 writer.AppendInt32(4); |
| 49 writer.AppendUint32(5); | 49 writer.AppendUint32(5); |
| 50 writer.AppendInt64(6); | 50 writer.AppendInt64(6); |
| 51 writer.AppendUint64(7); | 51 writer.AppendUint64(7); |
| 52 writer.AppendDouble(8.0); | 52 writer.AppendDouble(8.0); |
| 53 writer.AppendString("string"); | 53 writer.AppendString("string"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 EXPECT_EQ(3U, uint16_value); | 87 EXPECT_EQ(3U, uint16_value); |
| 88 EXPECT_EQ(4, int32_value); | 88 EXPECT_EQ(4, int32_value); |
| 89 EXPECT_EQ(5U, uint32_value); | 89 EXPECT_EQ(5U, uint32_value); |
| 90 EXPECT_EQ(6, int64_value); | 90 EXPECT_EQ(6, int64_value); |
| 91 EXPECT_EQ(7U, uint64_value); | 91 EXPECT_EQ(7U, uint64_value); |
| 92 EXPECT_DOUBLE_EQ(8.0, double_value); | 92 EXPECT_DOUBLE_EQ(8.0, double_value); |
| 93 EXPECT_EQ("string", string_value); | 93 EXPECT_EQ("string", string_value); |
| 94 EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); | 94 EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Check all basic types can be properly written and read. | |
| 98 TEST(MessageTest, AppendAndPopFileDescriptor) { | |
| 99 if (!dbus::kDBusTypeUnixFdIsSupported) | |
| 100 return; | |
|
satorux1
2012/03/28 20:49:37
Could you add some logging like
if (!dbus::kDBusT
Sam Leffler
2012/03/28 22:06:33
Done.
| |
| 101 | |
| 102 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | |
| 103 dbus::MessageWriter writer(message.get()); | |
| 104 | |
| 105 // Append stdout. | |
| 106 dbus::FileDescriptor temp(1); | |
| 107 writer.AppendFileDescriptor(temp); | |
| 108 | |
| 109 dbus::FileDescriptor fd_value; | |
| 110 | |
| 111 dbus::MessageReader reader(message.get()); | |
| 112 ASSERT_TRUE(reader.HasMoreData()); | |
| 113 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); | |
| 114 ASSERT_FALSE(reader.HasMoreData()); | |
| 115 | |
| 116 // stdout should be returned. | |
| 117 // TODO(sleffler) need to fstat each fd to compare | |
|
keybuk
2012/03/28 20:41:30
This should be trivial enough, fstat will get you
satorux1
2012/03/28 20:49:37
Why cannot we do EXPECT_EQ(1, fd_value.value())?
keybuk
2012/03/28 20:56:18
No, dbus calls dup() all over the place like crazy
satorux1
2012/03/28 21:09:32
Then, we need some comment about it. :)
Sam Leffler
2012/03/28 22:06:33
Implemented the test case. I used fstat calls whi
satorux1
2012/03/28 22:20:41
No need to worry about #ifdef. This only compiles
| |
| 118 } | |
| 119 | |
| 97 // Check all variant types can be properly written and read. | 120 // Check all variant types can be properly written and read. |
| 98 TEST(MessageTest, AppendAndPopVariantDataTypes) { | 121 TEST(MessageTest, AppendAndPopVariantDataTypes) { |
| 99 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 122 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 100 dbus::MessageWriter writer(message.get()); | 123 dbus::MessageWriter writer(message.get()); |
| 101 | 124 |
| 102 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". | 125 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". |
| 103 writer.AppendVariantOfByte(0); | 126 writer.AppendVariantOfByte(0); |
| 104 writer.AppendVariantOfBool(true); | 127 writer.AppendVariantOfBool(true); |
| 105 writer.AppendVariantOfInt16(2); | 128 writer.AppendVariantOfInt16(2); |
| 106 writer.AppendVariantOfUint16(3); | 129 writer.AppendVariantOfUint16(3); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 556 |
| 534 EXPECT_EQ("org.chromium.destination", message->GetDestination()); | 557 EXPECT_EQ("org.chromium.destination", message->GetDestination()); |
| 535 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); | 558 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); |
| 536 EXPECT_EQ("org.chromium.interface", message->GetInterface()); | 559 EXPECT_EQ("org.chromium.interface", message->GetInterface()); |
| 537 EXPECT_EQ("member", message->GetMember()); | 560 EXPECT_EQ("member", message->GetMember()); |
| 538 EXPECT_EQ("org.chromium.error", message->GetErrorName()); | 561 EXPECT_EQ("org.chromium.error", message->GetErrorName()); |
| 539 EXPECT_EQ(":1.2", message->GetSender()); | 562 EXPECT_EQ(":1.2", message->GetSender()); |
| 540 EXPECT_EQ(123U, message->GetSerial()); | 563 EXPECT_EQ(123U, message->GetSerial()); |
| 541 EXPECT_EQ(456U, message->GetReplySerial()); | 564 EXPECT_EQ(456U, message->GetReplySerial()); |
| 542 } | 565 } |
| OLD | NEW |