Chromium Code Reviews| Index: dbus/message_unittest.cc |
| diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc |
| index a40ba0aa740f5538ec5b0c784020fa6587096616..92950469e32fe8a0866d15fdcb6361f589456bf4 100644 |
| --- a/dbus/message_unittest.cc |
| +++ b/dbus/message_unittest.cc |
| @@ -94,6 +94,39 @@ TEST(MessageTest, AppendAndPopBasicDataTypes) { |
| EXPECT_EQ(dbus::ObjectPath("/object/path"), object_path_value); |
| } |
| +// Check all basic types can be properly written and read. |
| +TEST(MessageTest, AppendAndPopFileDescriptor) { |
| + if (!dbus::kDBusTypeUnixFdIsSupported) { |
| + LOG(WARNING) << "FD passing is not supported"; |
| + return; |
| + } |
| + |
| + scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |
| + dbus::MessageWriter writer(message.get()); |
| + |
| + // Append stdout. |
| + dbus::FileDescriptor temp(1); |
| + writer.AppendFileDescriptor(temp); |
| + |
| + dbus::FileDescriptor fd_value; |
| + |
| + dbus::MessageReader reader(message.get()); |
| + ASSERT_TRUE(reader.HasMoreData()); |
| + ASSERT_TRUE(reader.PopFileDescriptor(&fd_value)); |
| + ASSERT_FALSE(reader.HasMoreData()); |
| + |
| + // Stdout should be returned but we cannot check the descriptor |
| + // value because stdout will be dup'd. Instead check st_rdev |
| + // which should be identical. |
| + struct stat sb_stdout; |
| + int status_stdout = ::fstat(1, &sb_stdout); |
|
satorux1
2012/03/28 22:20:41
nit: is :: needed?
wrapping it with HANDLE_EINTR
|
| + ASSERT_TRUE(status_stdout >= 0); |
| + struct stat sb_fd; |
| + int status_fd = ::fstat(fd_value.value(), &sb_fd); |
| + ASSERT_TRUE(status_fd >= 0); |
| + EXPECT_EQ(sb_stdout.st_rdev, sb_fd.st_rdev); |
| +} |
| + |
| // Check all variant types can be properly written and read. |
| TEST(MessageTest, AppendAndPopVariantDataTypes) { |
| scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); |