Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1701)

Unified Diff: dbus/message_unittest.cc

Issue 9700072: dbus: add support for passing file descriptors (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: unit test nits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/message.cc ('k') | dbus/values_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/message_unittest.cc
diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc
index a40ba0aa740f5538ec5b0c784020fa6587096616..424b50a8519e98b18a272eb110645bc9b18a3531 100644
--- a/dbus/message_unittest.cc
+++ b/dbus/message_unittest.cc
@@ -5,6 +5,7 @@
#include "dbus/message.h"
#include "base/basictypes.h"
+#include "base/eintr_wrapper.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "dbus/object_path.h"
@@ -94,6 +95,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 = HANDLE_EINTR(fstat(1, &sb_stdout));
+ ASSERT_TRUE(status_stdout >= 0);
+ struct stat sb_fd;
+ int status_fd = HANDLE_EINTR(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());
« no previous file with comments | « dbus/message.cc ('k') | dbus/values_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698