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 <memory> |
| 6 |
5 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | |
7 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
8 #include "dbus/message.h" | 9 #include "dbus/message.h" |
9 #include "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
10 #include "dbus/object_proxy.h" | 11 #include "dbus/object_proxy.h" |
11 #include "dbus/test_service.h" | 12 #include "dbus/test_service.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace dbus { | 15 namespace dbus { |
15 | 16 |
16 // The end-to-end test exercises the synchronous APIs in ObjectProxy and | 17 // The end-to-end test exercises the synchronous APIs in ObjectProxy and |
(...skipping 23 matching lines...) Expand all Loading... |
40 ASSERT_FALSE(client_bus_->HasDBusThread()); | 41 ASSERT_FALSE(client_bus_->HasDBusThread()); |
41 } | 42 } |
42 | 43 |
43 void TearDown() override { | 44 void TearDown() override { |
44 test_service_->ShutdownAndBlock(); | 45 test_service_->ShutdownAndBlock(); |
45 test_service_->Stop(); | 46 test_service_->Stop(); |
46 client_bus_->ShutdownAndBlock(); | 47 client_bus_->ShutdownAndBlock(); |
47 } | 48 } |
48 | 49 |
49 protected: | 50 protected: |
50 scoped_ptr<TestService> test_service_; | 51 std::unique_ptr<TestService> test_service_; |
51 scoped_refptr<Bus> client_bus_; | 52 scoped_refptr<Bus> client_bus_; |
52 ObjectProxy* object_proxy_; | 53 ObjectProxy* object_proxy_; |
53 }; | 54 }; |
54 | 55 |
55 TEST_F(EndToEndSyncTest, Echo) { | 56 TEST_F(EndToEndSyncTest, Echo) { |
56 const std::string kHello = "hello"; | 57 const std::string kHello = "hello"; |
57 | 58 |
58 // Create the method call. | 59 // Create the method call. |
59 MethodCall method_call("org.chromium.TestInterface", "Echo"); | 60 MethodCall method_call("org.chromium.TestInterface", "Echo"); |
60 MessageWriter writer(&method_call); | 61 MessageWriter writer(&method_call); |
61 writer.AppendString(kHello); | 62 writer.AppendString(kHello); |
62 | 63 |
63 // Call the method. | 64 // Call the method. |
64 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 65 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
65 scoped_ptr<Response> response( | 66 std::unique_ptr<Response> response( |
66 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 67 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
67 ASSERT_TRUE(response.get()); | 68 ASSERT_TRUE(response.get()); |
68 | 69 |
69 // Check the response. kHello should be echoed back. | 70 // Check the response. kHello should be echoed back. |
70 MessageReader reader(response.get()); | 71 MessageReader reader(response.get()); |
71 std::string returned_message; | 72 std::string returned_message; |
72 ASSERT_TRUE(reader.PopString(&returned_message)); | 73 ASSERT_TRUE(reader.PopString(&returned_message)); |
73 EXPECT_EQ(kHello, returned_message); | 74 EXPECT_EQ(kHello, returned_message); |
74 } | 75 } |
75 | 76 |
76 TEST_F(EndToEndSyncTest, Timeout) { | 77 TEST_F(EndToEndSyncTest, Timeout) { |
77 const std::string kHello = "hello"; | 78 const std::string kHello = "hello"; |
78 | 79 |
79 // Create the method call. | 80 // Create the method call. |
80 MethodCall method_call("org.chromium.TestInterface", "DelayedEcho"); | 81 MethodCall method_call("org.chromium.TestInterface", "DelayedEcho"); |
81 MessageWriter writer(&method_call); | 82 MessageWriter writer(&method_call); |
82 writer.AppendString(kHello); | 83 writer.AppendString(kHello); |
83 | 84 |
84 // Call the method with timeout of 0ms. | 85 // Call the method with timeout of 0ms. |
85 const int timeout_ms = 0; | 86 const int timeout_ms = 0; |
86 scoped_ptr<Response> response( | 87 std::unique_ptr<Response> response( |
87 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 88 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
88 // Should fail because of timeout. | 89 // Should fail because of timeout. |
89 ASSERT_FALSE(response.get()); | 90 ASSERT_FALSE(response.get()); |
90 } | 91 } |
91 | 92 |
92 TEST_F(EndToEndSyncTest, NonexistentMethod) { | 93 TEST_F(EndToEndSyncTest, NonexistentMethod) { |
93 MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); | 94 MethodCall method_call("org.chromium.TestInterface", "Nonexistent"); |
94 | 95 |
95 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 96 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
96 scoped_ptr<Response> response( | 97 std::unique_ptr<Response> response( |
97 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 98 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
98 ASSERT_FALSE(response.get()); | 99 ASSERT_FALSE(response.get()); |
99 } | 100 } |
100 | 101 |
101 TEST_F(EndToEndSyncTest, BrokenMethod) { | 102 TEST_F(EndToEndSyncTest, BrokenMethod) { |
102 MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); | 103 MethodCall method_call("org.chromium.TestInterface", "BrokenMethod"); |
103 | 104 |
104 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 105 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
105 scoped_ptr<Response> response( | 106 std::unique_ptr<Response> response( |
106 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 107 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
107 ASSERT_FALSE(response.get()); | 108 ASSERT_FALSE(response.get()); |
108 } | 109 } |
109 | 110 |
110 TEST_F(EndToEndSyncTest, InvalidObjectPath) { | 111 TEST_F(EndToEndSyncTest, InvalidObjectPath) { |
111 // Trailing '/' is only allowed for the root path. | 112 // Trailing '/' is only allowed for the root path. |
112 const ObjectPath invalid_object_path("/org/chromium/TestObject/"); | 113 const ObjectPath invalid_object_path("/org/chromium/TestObject/"); |
113 | 114 |
114 // Replace object proxy with new one. | 115 // Replace object proxy with new one. |
115 object_proxy_ = client_bus_->GetObjectProxy(test_service_->service_name(), | 116 object_proxy_ = client_bus_->GetObjectProxy(test_service_->service_name(), |
116 invalid_object_path); | 117 invalid_object_path); |
117 | 118 |
118 MethodCall method_call("org.chromium.TestInterface", "Echo"); | 119 MethodCall method_call("org.chromium.TestInterface", "Echo"); |
119 | 120 |
120 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 121 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
121 scoped_ptr<Response> response( | 122 std::unique_ptr<Response> response( |
122 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 123 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
123 ASSERT_FALSE(response.get()); | 124 ASSERT_FALSE(response.get()); |
124 } | 125 } |
125 | 126 |
126 TEST_F(EndToEndSyncTest, InvalidServiceName) { | 127 TEST_F(EndToEndSyncTest, InvalidServiceName) { |
127 // Bus name cannot contain '/'. | 128 // Bus name cannot contain '/'. |
128 const std::string invalid_service_name = ":1/2"; | 129 const std::string invalid_service_name = ":1/2"; |
129 | 130 |
130 // Replace object proxy with new one. | 131 // Replace object proxy with new one. |
131 object_proxy_ = client_bus_->GetObjectProxy( | 132 object_proxy_ = client_bus_->GetObjectProxy( |
132 invalid_service_name, ObjectPath("org.chromium.TestObject")); | 133 invalid_service_name, ObjectPath("org.chromium.TestObject")); |
133 | 134 |
134 MethodCall method_call("org.chromium.TestInterface", "Echo"); | 135 MethodCall method_call("org.chromium.TestInterface", "Echo"); |
135 | 136 |
136 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; | 137 const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT; |
137 scoped_ptr<Response> response( | 138 std::unique_ptr<Response> response( |
138 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); | 139 object_proxy_->CallMethodAndBlock(&method_call, timeout_ms)); |
139 ASSERT_FALSE(response.get()); | 140 ASSERT_FALSE(response.get()); |
140 } | 141 } |
141 | 142 |
142 } // namespace dbus | 143 } // namespace dbus |
OLD | NEW |