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

Side by Side Diff: net/dbus/dbus_unittest.cc

Issue 7413004: Uploading for backup... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: today's work Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/logging.h"
6 #include "base/scoped_ptr.h"
7 #include "net/dbus/dbus.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/platform_test.h"
11
12 namespace net {
13
14 class DBusTest : public PlatformTest {
15 };
16
17 // Test that byte can be properly written and read.
18 TEST_F(DBusTest, AppendAndPopByte) {
19 dbus::Message message;
20 message.reset_raw_message(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
21 dbus::MessageWriter writer(&message);
22 writer.AppendByte(123); // The input is 123.
23
24 uint8 byte_value = 0;
25 bool bool_value = false;
26 dbus::MessageReader reader(&message);
27 ASSERT_TRUE(reader.HasMore()); // Should have data to read.
28
29 // Should fail as the type is not bool here.
30 ASSERT_FALSE(reader.PopBool(&bool_value));
31
32 ASSERT_TRUE(reader.PopByte(&byte_value));
33 EXPECT_EQ(123, byte_value); // Should match with the input.
34 ASSERT_FALSE(reader.HasMore()); // Should not have more data to read.
35 // Try to get another byte. Should fail without crashing.
36 ASSERT_FALSE(reader.PopByte(&byte_value));
37 }
38
39 // This is a bit boring, but check all basic types can be properly written
40 // and read.
41 TEST_F(DBusTest, AppendAndPopBasicTypes) {
42 dbus::Message message;
43 message.reset_raw_message(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
44 dbus::MessageWriter writer(&message);
45
46 writer.AppendByte(0);
47 writer.AppendBool(true);
48 writer.AppendInt16(2);
49 writer.AppendUint16(3);
50 writer.AppendInt32(4);
51 writer.AppendUint32(5);
52 writer.AppendInt64(6);
53 writer.AppendUint64(7);
54 writer.AppendDouble(8.0);
55 writer.AppendString("string");
56 writer.AppendObjectPath("/object/path");
57
58 uint8 byte_value = 0;
59 bool bool_value = false;
60 int16 int16_value = 0;
61 uint16 uint16_value = 0;
62 int32 int32_value = 0;
63 uint32 uint32_value = 0;
64 int64 int64_value = 0;
65 uint64 uint64_value = 0;
66 double double_value = 0;
67 std::string string_value;
68 std::string object_path_value;
69
70 dbus::MessageReader reader(&message);
71 ASSERT_TRUE(reader.HasMore());
72 ASSERT_TRUE(reader.PopByte(&byte_value));
73 ASSERT_TRUE(reader.PopBool(&bool_value));
74 ASSERT_TRUE(reader.PopInt16(&int16_value));
75 ASSERT_TRUE(reader.PopUint16(&uint16_value));
76 ASSERT_TRUE(reader.PopInt32(&int32_value));
77 ASSERT_TRUE(reader.PopUint32(&uint32_value));
78 ASSERT_TRUE(reader.PopInt64(&int64_value));
79 ASSERT_TRUE(reader.PopUint64(&uint64_value));
80 ASSERT_TRUE(reader.PopDouble(&double_value));
81 ASSERT_TRUE(reader.PopString(&string_value));
82 ASSERT_TRUE(reader.PopObjectPath(&object_path_value));
83 ASSERT_FALSE(reader.HasMore());
84
85 EXPECT_EQ(0, byte_value);
86 EXPECT_EQ(true, bool_value);
87 EXPECT_EQ(2, int16_value);
88 EXPECT_EQ(3U, uint16_value);
89 EXPECT_EQ(4, int32_value);
90 EXPECT_EQ(5U, uint32_value);
91 EXPECT_EQ(6, int64_value);
92 EXPECT_EQ(7U, uint64_value);
93 EXPECT_DOUBLE_EQ(8.0, double_value);
94 EXPECT_EQ("string", string_value);
95 EXPECT_EQ("/object/path", object_path_value);
96 }
97
98 TEST_F(DBusTest, Test) {
99 dbus::Bus::Options options;
100 options.bus_type = dbus::Bus::SESSION;
101 dbus::Bus bus(options);
102 scoped_ptr<dbus::ObjectProxy> proxy(bus.GetObjectProxy(
103 "com.example.SampleService",
104 "/SomeObject"));
105 dbus::MethodCall method_call("com.example.SampleInterface",
106 "HelloWorld");
107 dbus::MessageWriter builder(&method_call);
108 builder.AppendString("hello");
109 dbus::Response response;
110 CHECK(proxy->CallMethodSync(&method_call, &response));
111 dbus::MessageReader reader(&response);
112 dbus::MessageReader sub_reader(&response);
113 CHECK(reader.PopArray(&sub_reader));
114 std::string string_value;
115 CHECK(sub_reader.PopString(&string_value));
116 LOG(ERROR) << string_value;
117 CHECK(sub_reader.PopString(&string_value));
118 LOG(ERROR) << string_value;
119 }
120
121 } // namespace net
OLDNEW
« net/dbus/dbus.h ('K') | « net/dbus/dbus.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698