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 76 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 LOG(WARNING) << "FD passing is not supported"; | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | |
| 105 dbus::MessageWriter writer(message.get()); | |
| 106 | |
| 107 // Append stdout. | |
| 108 dbus::FileDescriptor temp(1); | |
| 109 writer.AppendFileDescriptor(temp); | |
| 110 | |
| 111 dbus::FileDescriptor fd_value; | |
| 112 | |
| 113 dbus::MessageReader reader(message.get()); | |
| 114 ASSERT_TRUE(reader.HasMoreData()); | |
| 115 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); | |
| 116 ASSERT_FALSE(reader.HasMoreData()); | |
| 117 | |
| 118 // Stdout should be returned but we cannot check the descriptor | |
| 119 // value because stdout will be dup'd. Instead check st_rdev | |
| 120 // which should be identical. | |
| 121 struct stat sb_stdout; | |
| 122 int status_stdout = ::fstat(1, &sb_stdout); | |
|
satorux1
2012/03/28 22:20:41
nit: is :: needed?
wrapping it with HANDLE_EINTR
| |
| 123 ASSERT_TRUE(status_stdout >= 0); | |
| 124 struct stat sb_fd; | |
| 125 int status_fd = ::fstat(fd_value.value(), &sb_fd); | |
| 126 ASSERT_TRUE(status_fd >= 0); | |
| 127 EXPECT_EQ(sb_stdout.st_rdev, sb_fd.st_rdev); | |
| 128 } | |
| 129 | |
| 97 // Check all variant types can be properly written and read. | 130 // Check all variant types can be properly written and read. |
| 98 TEST(MessageTest, AppendAndPopVariantDataTypes) { | 131 TEST(MessageTest, AppendAndPopVariantDataTypes) { |
| 99 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 132 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 100 dbus::MessageWriter writer(message.get()); | 133 dbus::MessageWriter writer(message.get()); |
| 101 | 134 |
| 102 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". | 135 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". |
| 103 writer.AppendVariantOfByte(0); | 136 writer.AppendVariantOfByte(0); |
| 104 writer.AppendVariantOfBool(true); | 137 writer.AppendVariantOfBool(true); |
| 105 writer.AppendVariantOfInt16(2); | 138 writer.AppendVariantOfInt16(2); |
| 106 writer.AppendVariantOfUint16(3); | 139 writer.AppendVariantOfUint16(3); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 566 |
| 534 EXPECT_EQ("org.chromium.destination", message->GetDestination()); | 567 EXPECT_EQ("org.chromium.destination", message->GetDestination()); |
| 535 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); | 568 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); |
| 536 EXPECT_EQ("org.chromium.interface", message->GetInterface()); | 569 EXPECT_EQ("org.chromium.interface", message->GetInterface()); |
| 537 EXPECT_EQ("member", message->GetMember()); | 570 EXPECT_EQ("member", message->GetMember()); |
| 538 EXPECT_EQ("org.chromium.error", message->GetErrorName()); | 571 EXPECT_EQ("org.chromium.error", message->GetErrorName()); |
| 539 EXPECT_EQ(":1.2", message->GetSender()); | 572 EXPECT_EQ(":1.2", message->GetSender()); |
| 540 EXPECT_EQ(123U, message->GetSerial()); | 573 EXPECT_EQ(123U, message->GetSerial()); |
| 541 EXPECT_EQ(456U, message->GetReplySerial()); | 574 EXPECT_EQ(456U, message->GetReplySerial()); |
| 542 } | 575 } |
| OLD | NEW |