[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DBUS_MOCK_OBJECT_PROXY_H_ |
| 6 | #define DBUS_MOCK_OBJECT_PROXY_H_ |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 9b25d45 | 2013-02-07 09:46:24 | [diff] [blame] | 10 | #include "dbus/message.h" |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 11 | #include "dbus/object_path.h" |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 12 | #include "dbus/object_proxy.h" |
| 13 | #include "testing/gmock/include/gmock/gmock.h" |
| 14 | |
| 15 | namespace dbus { |
| 16 | |
| 17 | // Mock for ObjectProxy. |
| 18 | class MockObjectProxy : public ObjectProxy { |
| 19 | public: |
| 20 | MockObjectProxy(Bus* bus, |
| 21 | const std::string& service_name, |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 22 | const ObjectPath& object_path); |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 23 | |
[email protected] | 9b25d45 | 2013-02-07 09:46:24 | [diff] [blame] | 24 | // GMock doesn't support the return type of scoped_ptr<> because scoped_ptr is |
| 25 | // uncopyable. This is a workaround which defines |MockCallMethodAndBlock| as |
| 26 | // a mock method and makes |CallMethodAndBlock| call the mocked method. |
| 27 | // Use |MockCallMethodAndBlock| for setting/testing expectations. |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 28 | MOCK_METHOD3(MockCallMethodAndBlockWithErrorDetails, |
| 29 | Response*(MethodCall* method_call, |
| 30 | int timeout_ms, |
| 31 | ScopedDBusError* error)); |
nick | 0e1afc9 | 2015-04-23 04:41:54 | [diff] [blame] | 32 | scoped_ptr<Response> CallMethodAndBlockWithErrorDetails( |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 33 | MethodCall* method_call, |
| 34 | int timeout_ms, |
anujk.sharma | 1a60a65 | 2014-10-07 07:29:56 | [diff] [blame] | 35 | ScopedDBusError* error) override { |
avakulenko | 6b571de | 2014-09-17 01:44:09 | [diff] [blame] | 36 | return scoped_ptr<Response>( |
| 37 | MockCallMethodAndBlockWithErrorDetails(method_call, timeout_ms, error)); |
| 38 | } |
[email protected] | 9b25d45 | 2013-02-07 09:46:24 | [diff] [blame] | 39 | MOCK_METHOD2(MockCallMethodAndBlock, Response*(MethodCall* method_call, |
| 40 | int timeout_ms)); |
nick | 0e1afc9 | 2015-04-23 04:41:54 | [diff] [blame] | 41 | scoped_ptr<Response> CallMethodAndBlock(MethodCall* method_call, |
| 42 | int timeout_ms) override { |
[email protected] | 9b25d45 | 2013-02-07 09:46:24 | [diff] [blame] | 43 | return scoped_ptr<Response>(MockCallMethodAndBlock(method_call, |
| 44 | timeout_ms)); |
| 45 | } |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 46 | MOCK_METHOD3(CallMethod, void(MethodCall* method_call, |
| 47 | int timeout_ms, |
| 48 | ResponseCallback callback)); |
[email protected] | e8ebcf1 | 2012-04-24 02:29:36 | [diff] [blame] | 49 | MOCK_METHOD4(CallMethodWithErrorCallback, void(MethodCall* method_call, |
| 50 | int timeout_ms, |
| 51 | ResponseCallback callback, |
| 52 | ErrorCallback error_callback)); |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 53 | MOCK_METHOD4(ConnectToSignal, |
| 54 | void(const std::string& interface_name, |
| 55 | const std::string& signal_name, |
| 56 | SignalCallback signal_callback, |
| 57 | OnConnectedCallback on_connected_callback)); |
| 58 | MOCK_METHOD0(Detach, void()); |
[email protected] | 4e0f45f5 | 2012-05-18 18:00:22 | [diff] [blame] | 59 | |
| 60 | protected: |
nick | 0e1afc9 | 2015-04-23 04:41:54 | [diff] [blame] | 61 | ~MockObjectProxy() override; |
[email protected] | b8ae051 | 2011-08-25 05:18:29 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // namespace dbus |
| 65 | |
| 66 | #endif // DBUS_MOCK_OBJECT_PROXY_H_ |