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

Side by Side 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: add dbus::FileDescriptor per keybuk's request Created 8 years, 8 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 unified diff | Download patch
OLDNEW
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
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.
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
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 #if defined(DBUS_TYPE_UNIX_FD)
98 // Check all basic types can be properly written and read.
99 TEST(MessageTest, AppendAndPopFileDescriptor) {
satorux1 2012/03/28 00:32:43 If we are to go with kDBusTypeUnixFdIsSupported,
Sam Leffler 2012/03/28 17:28:09 Unless kDBusTypeUnixFdIsSupported is defined in me
100 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
101 dbus::MessageWriter writer(message.get());
102
103 // Append stdout.
104 writer.AppendFileDescriptor(dbus::FileDescriptor(1));
105
106 FileDescriptor fd_value;
107
108 dbus::MessageReader reader(message.get());
109 ASSERT_TRUE(reader.HasMoreData());
110 ASSERT_TRUE(reader.PopFileDescriptor(&fd_value));
111 ASSERT_FALSE(reader.HasMoreData());
112
113 // stdout should be returned.
114 EXPECT_EQ(1, fd_value.value());
keybuk 2012/03/27 22:36:35 does this pass? I would be hella-surprised if the
Sam Leffler 2012/03/27 23:20:40 It did pass but what you say seems right so let me
115 }
116 #endif
117
97 // Check all variant types can be properly written and read. 118 // Check all variant types can be properly written and read.
98 TEST(MessageTest, AppendAndPopVariantDataTypes) { 119 TEST(MessageTest, AppendAndPopVariantDataTypes) {
99 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty()); 120 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
100 dbus::MessageWriter writer(message.get()); 121 dbus::MessageWriter writer(message.get());
101 122
102 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path". 123 // Append 0, 1, 2, 3, 4, 5, 6, 7, 8, "string", "/object/path".
103 writer.AppendVariantOfByte(0); 124 writer.AppendVariantOfByte(0);
104 writer.AppendVariantOfBool(true); 125 writer.AppendVariantOfBool(true);
105 writer.AppendVariantOfInt16(2); 126 writer.AppendVariantOfInt16(2);
106 writer.AppendVariantOfUint16(3); 127 writer.AppendVariantOfUint16(3);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 554
534 EXPECT_EQ("org.chromium.destination", message->GetDestination()); 555 EXPECT_EQ("org.chromium.destination", message->GetDestination());
535 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath()); 556 EXPECT_EQ(dbus::ObjectPath("/org/chromium/path"), message->GetPath());
536 EXPECT_EQ("org.chromium.interface", message->GetInterface()); 557 EXPECT_EQ("org.chromium.interface", message->GetInterface());
537 EXPECT_EQ("member", message->GetMember()); 558 EXPECT_EQ("member", message->GetMember());
538 EXPECT_EQ("org.chromium.error", message->GetErrorName()); 559 EXPECT_EQ("org.chromium.error", message->GetErrorName());
539 EXPECT_EQ(":1.2", message->GetSender()); 560 EXPECT_EQ(":1.2", message->GetSender());
540 EXPECT_EQ(123U, message->GetSerial()); 561 EXPECT_EQ(123U, message->GetSerial());
541 EXPECT_EQ(456U, message->GetReplySerial()); 562 EXPECT_EQ(456U, message->GetReplySerial());
542 } 563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698