| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" |
| 10 #include "dbus/message.h" | 11 #include "dbus/message.h" |
| 11 #include "dbus/mock_bus.h" | 12 #include "dbus/mock_bus.h" |
| 12 #include "dbus/mock_exported_object.h" | 13 #include "dbus/mock_exported_object.h" |
| 13 #include "dbus/mock_object_proxy.h" | 14 #include "dbus/mock_object_proxy.h" |
| 14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using ::testing::_; | 19 using ::testing::_; |
| 19 using ::testing::Invoke; | 20 using ::testing::Invoke; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Called when the response is received. | 68 // Called when the response is received. |
| 68 void OnResponse(Response* response) { | 69 void OnResponse(Response* response) { |
| 69 // |response| will be deleted on exit of the function. Copy the | 70 // |response| will be deleted on exit of the function. Copy the |
| 70 // payload to |response_string_|. | 71 // payload to |response_string_|. |
| 71 if (response) { | 72 if (response) { |
| 72 MessageReader reader(response); | 73 MessageReader reader(response); |
| 73 ASSERT_TRUE(reader.PopString(&response_string_)); | 74 ASSERT_TRUE(reader.PopString(&response_string_)); |
| 74 } | 75 } |
| 75 message_loop_.Quit(); | 76 run_loop_->Quit(); |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 protected: | 79 protected: |
| 79 std::string response_string_; | 80 std::string response_string_; |
| 80 base::MessageLoop message_loop_; | 81 base::MessageLoop message_loop_; |
| 82 scoped_ptr<base::RunLoop> run_loop_; |
| 81 scoped_refptr<MockBus> mock_bus_; | 83 scoped_refptr<MockBus> mock_bus_; |
| 82 scoped_refptr<MockObjectProxy> mock_proxy_; | 84 scoped_refptr<MockObjectProxy> mock_proxy_; |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 // Returns a response for the given method call. Used to implement | 87 // Returns a response for the given method call. Used to implement |
| 86 // CallMethodAndBlock() for |mock_proxy_|. | 88 // CallMethodAndBlock() for |mock_proxy_|. |
| 87 Response* CreateMockProxyResponse(MethodCall* method_call, | 89 Response* CreateMockProxyResponse(MethodCall* method_call, |
| 88 int timeout_ms) { | 90 int timeout_ms) { |
| 89 if (method_call->GetInterface() == "org.chromium.TestInterface" && | 91 if (method_call->GetInterface() == "org.chromium.TestInterface" && |
| 90 method_call->GetMember() == "Echo") { | 92 method_call->GetMember() == "Echo") { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 ObjectProxy* proxy = mock_bus_->GetObjectProxy( | 164 ObjectProxy* proxy = mock_bus_->GetObjectProxy( |
| 163 "org.chromium.TestService", | 165 "org.chromium.TestService", |
| 164 ObjectPath("/org/chromium/TestObject")); | 166 ObjectPath("/org/chromium/TestObject")); |
| 165 | 167 |
| 166 // Create a method call. | 168 // Create a method call. |
| 167 MethodCall method_call("org.chromium.TestInterface", "Echo"); | 169 MethodCall method_call("org.chromium.TestInterface", "Echo"); |
| 168 MessageWriter writer(&method_call); | 170 MessageWriter writer(&method_call); |
| 169 writer.AppendString(kHello); | 171 writer.AppendString(kHello); |
| 170 | 172 |
| 171 // Call the method. | 173 // Call the method. |
| 174 run_loop_.reset(new base::RunLoop); |
| 172 proxy->CallMethod(&method_call, | 175 proxy->CallMethod(&method_call, |
| 173 ObjectProxy::TIMEOUT_USE_DEFAULT, | 176 ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 174 base::Bind(&MockTest::OnResponse, | 177 base::Bind(&MockTest::OnResponse, |
| 175 base::Unretained(this))); | 178 base::Unretained(this))); |
| 176 // Run the message loop to let OnResponse be called. | 179 // Run the message loop to let OnResponse be called. |
| 177 message_loop_.Run(); | 180 run_loop_->Run(); |
| 178 | 181 |
| 179 EXPECT_EQ(kHello, response_string_); | 182 EXPECT_EQ(kHello, response_string_); |
| 180 } | 183 } |
| 181 | 184 |
| 182 } // namespace dbus | 185 } // namespace dbus |
| OLD | NEW |