| 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/eintr_wrapper.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "dbus/object_path.h" | 11 #include "dbus/object_path.h" |
| 11 #include "dbus/test_proto.pb.h" | 12 #include "dbus/test_proto.pb.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 // Test that a byte can be properly written and read. We only have this | 15 // Test that a byte can be properly written and read. We only have this |
| 15 // test for byte, as repeating this for other basic types is too redundant. | 16 // test for byte, as repeating this for other basic types is too redundant. |
| 16 TEST(MessageTest, AppendAndPopByte) { | 17 TEST(MessageTest, AppendAndPopByte) { |
| 17 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 18 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 EXPECT_EQ(3U, uint16_value); | 88 EXPECT_EQ(3U, uint16_value); |
| 88 EXPECT_EQ(4, int32_value); | 89 EXPECT_EQ(4, int32_value); |
| 89 EXPECT_EQ(5U, uint32_value); | 90 EXPECT_EQ(5U, uint32_value); |
| 90 EXPECT_EQ(6, int64_value); | 91 EXPECT_EQ(6, int64_value); |
| 91 EXPECT_EQ(7U, uint64_value); | 92 EXPECT_EQ(7U, uint64_value); |
| 92 EXPECT_DOUBLE_EQ(8.0, double_value); | 93 EXPECT_DOUBLE_EQ(8.0, double_value); |
| 93 EXPECT_EQ("string", string_value); | 94 EXPECT_EQ("string", string_value); |
| 94 EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); | 95 EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); |
| 95 } | 96 } |
| 96 | 97 |
| 98 // Check all basic types can be properly written and read. |
| 99 TEST(MessageTest, AppendAndPopFileDescriptor) { |
| 100 if (!dbus::kDBusTypeUnixFdIsSupported) { |
| 101 LOG(WARNING) << "FD passing is not supported"; |
| 102 return; |
| 103 } |
| 104 |
| 105 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 106 dbus::MessageWriter writer(message.get()); |
| 107 |
| 108 // Append stdout. |
| 109 dbus::FileDescriptor temp(1); |
| 110 writer.AppendFileDescriptor(temp); |
| 111 |
| 112 dbus::FileDescriptor fd_value; |
| 113 |
| 114 dbus::MessageReader reader(message.get()); |
| 115 ASSERT_TRUE(reader.HasMoreData()); |
| 116 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); |
| 117 ASSERT_FALSE(reader.HasMoreData()); |
| 118 |
| 119 // Stdout should be returned but we cannot check the descriptor |
| 120 // value because stdout will be dup'd. Instead check st_rdev |
| 121 // which should be identical. |
| 122 struct stat sb_stdout; |
| 123 int status_stdout = HANDLE_EINTR(fstat(1, &sb_stdout)); |
| 124 ASSERT_TRUE(status_stdout >= 0); |
| 125 struct stat sb_fd; |
| 126 int status_fd = HANDLE_EINTR(fstat(fd_value.value(), &sb_fd)); |
| 127 ASSERT_TRUE(status_fd >= 0); |
| 128 EXPECT_EQ(sb_stdout.st_rdev, sb_fd.st_rdev); |
| 129 } |
| 130 |
| 97 // Check all variant types can be properly written and read. | 131 // Check all variant types can be properly written and read. |
| 98 TEST(MessageTest, AppendAndPopVariantDataTypes) { | 132 TEST(MessageTest, AppendAndPopVariantDataTypes) { |
| 99 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); | 133 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| 100 dbus::MessageWriter writer(message.get()); | 134 dbus::MessageWriter writer(message.get()); |
| 101 | 135 |
| 102 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". | 136 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". |
| 103 writer.AppendVariantOfByte(0); | 137 writer.AppendVariantOfByte(0); |
| 104 writer.AppendVariantOfBool(true); | 138 writer.AppendVariantOfBool(true); |
| 105 writer.AppendVariantOfInt16(2); | 139 writer.AppendVariantOfInt16(2); |
| 106 writer.AppendVariantOfUint16(3); | 140 writer.AppendVariantOfUint16(3); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 567 |
| 534 EXPECT_EQ("org.chromium.destination", message->GetDestination()); | 568 EXPECT_EQ("org.chromium.destination", message->GetDestination()); |
| 535 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); | 569 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); |
| 536 EXPECT_EQ("org.chromium.interface", message->GetInterface()); | 570 EXPECT_EQ("org.chromium.interface", message->GetInterface()); |
| 537 EXPECT_EQ("member", message->GetMember()); | 571 EXPECT_EQ("member", message->GetMember()); |
| 538 EXPECT_EQ("org.chromium.error", message->GetErrorName()); | 572 EXPECT_EQ("org.chromium.error", message->GetErrorName()); |
| 539 EXPECT_EQ(":1.2", message->GetSender()); | 573 EXPECT_EQ(":1.2", message->GetSender()); |
| 540 EXPECT_EQ(123U, message->GetSerial()); | 574 EXPECT_EQ(123U, message->GetSerial()); |
| 541 EXPECT_EQ(456U, message->GetReplySerial()); | 575 EXPECT_EQ(456U, message->GetReplySerial()); |
| 542 } | 576 } |
| OLD | NEW |