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 "chromeos/dbus/blocking_method_caller.h" | 5 #include "chromeos/dbus/blocking_method_caller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 mock_bus_ = new dbus::MockBus(options); | 32 mock_bus_ = new dbus::MockBus(options); |
33 | 33 |
34 // Create a mock proxy. | 34 // Create a mock proxy. |
35 mock_proxy_ = new dbus::MockObjectProxy( | 35 mock_proxy_ = new dbus::MockObjectProxy( |
36 mock_bus_.get(), | 36 mock_bus_.get(), |
37 "org.chromium.TestService", | 37 "org.chromium.TestService", |
38 dbus::ObjectPath("/org/chromium/TestObject")); | 38 dbus::ObjectPath("/org/chromium/TestObject")); |
39 | 39 |
40 // Set an expectation so mock_proxy's CallMethodAndBlock() will use | 40 // Set an expectation so mock_proxy's CallMethodAndBlock() will use |
41 // CreateMockProxyResponse() to return responses. | 41 // CreateMockProxyResponse() to return responses. |
42 EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _)) | 42 EXPECT_CALL(*mock_proxy_, MockCallMethodAndBlock(_, _)) |
43 .WillRepeatedly(Invoke( | 43 .WillRepeatedly(Invoke( |
44 this, &BlockingMethodCallerTest::CreateMockProxyResponse)); | 44 this, &BlockingMethodCallerTest::CreateMockProxyResponse)); |
45 | 45 |
46 // Set an expectation so mock_bus's GetObjectProxy() for the given | 46 // Set an expectation so mock_bus's GetObjectProxy() for the given |
47 // service name and the object path will return mock_proxy_. | 47 // service name and the object path will return mock_proxy_. |
48 EXPECT_CALL(*mock_bus_, GetObjectProxy( | 48 EXPECT_CALL(*mock_bus_, GetObjectProxy( |
49 "org.chromium.TestService", | 49 "org.chromium.TestService", |
50 dbus::ObjectPath("/org/chromium/TestObject"))) | 50 dbus::ObjectPath("/org/chromium/TestObject"))) |
51 .WillOnce(Return(mock_proxy_.get())); | 51 .WillOnce(Return(mock_proxy_.get())); |
52 | 52 |
(...skipping 18 matching lines...) Expand all Loading... |
71 private: | 71 private: |
72 // Returns a response for the given method call. Used to implement | 72 // Returns a response for the given method call. Used to implement |
73 // CallMethodAndBlock() for |mock_proxy_|. | 73 // CallMethodAndBlock() for |mock_proxy_|. |
74 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, | 74 dbus::Response* CreateMockProxyResponse(dbus::MethodCall* method_call, |
75 int timeout_ms) { | 75 int timeout_ms) { |
76 if (method_call->GetInterface() == "org.chromium.TestInterface" && | 76 if (method_call->GetInterface() == "org.chromium.TestInterface" && |
77 method_call->GetMember() == "Echo") { | 77 method_call->GetMember() == "Echo") { |
78 dbus::MessageReader reader(method_call); | 78 dbus::MessageReader reader(method_call); |
79 std::string text_message; | 79 std::string text_message; |
80 if (reader.PopString(&text_message)) { | 80 if (reader.PopString(&text_message)) { |
81 dbus::Response* response = dbus::Response::CreateEmpty(); | 81 scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty(); |
82 dbus::MessageWriter writer(response); | 82 dbus::MessageWriter writer(response.get()); |
83 writer.AppendString(text_message); | 83 writer.AppendString(text_message); |
84 return response; | 84 return response.release(); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); | 88 LOG(ERROR) << "Unexpected method call: " << method_call->ToString(); |
89 return NULL; | 89 return NULL; |
90 } | 90 } |
91 | 91 |
92 // Runs the given task. | 92 // Runs the given task. |
93 void RunTask(const tracked_objects::Location& from_here, | 93 void RunTask(const tracked_objects::Location& from_here, |
94 const base::Closure& task) { | 94 const base::Closure& task) { |
(...skipping 21 matching lines...) Expand all Loading... |
116 // Check the response. | 116 // Check the response. |
117 ASSERT_TRUE(response.get()); | 117 ASSERT_TRUE(response.get()); |
118 dbus::MessageReader reader(response.get()); | 118 dbus::MessageReader reader(response.get()); |
119 std::string text_message; | 119 std::string text_message; |
120 ASSERT_TRUE(reader.PopString(&text_message)); | 120 ASSERT_TRUE(reader.PopString(&text_message)); |
121 // The text message should be echo'ed back. | 121 // The text message should be echo'ed back. |
122 EXPECT_EQ(kHello, text_message); | 122 EXPECT_EQ(kHello, text_message); |
123 } | 123 } |
124 | 124 |
125 } // namespace chromeos | 125 } // namespace chromeos |
OLD | NEW |