• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef DBUS_MOCK_OBJECT_PROXY_H_
6 #define DBUS_MOCK_OBJECT_PROXY_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "dbus/message.h"
12 #include "dbus/object_path.h"
13 #include "dbus/object_proxy.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 
16 namespace dbus {
17 
18 // Mock for ObjectProxy.
19 class MockObjectProxy : public ObjectProxy {
20  public:
21   MockObjectProxy(Bus* bus,
22                   const std::string& service_name,
23                   const ObjectPath& object_path);
24 
25   MOCK_METHOD3(CallMethodAndBlockWithErrorDetails,
26                std::unique_ptr<Response>(MethodCall* method_call,
27                                          int timeout_ms,
28                                          ScopedDBusError* error));
29   MOCK_METHOD2(CallMethodAndBlock,
30                std::unique_ptr<Response>(MethodCall* method_call,
31                                          int timeout_ms));
32 
33   // This method is not mockable because it takes a move-only argument. To work
34   // around this, CallMethod() implementation here calls DoCallMethod() which is
35   // mockable.
36   void CallMethod(MethodCall* method_call,
37                   int timeout_ms,
38                   ResponseCallback callback) override;
39   MOCK_METHOD3(DoCallMethod,
40                void(MethodCall* method_call,
41                     int timeout_ms,
42                     ResponseCallback* callback));
43 
44   // This method is not mockable because it takes a move-only argument. To work
45   // around this, CallMethodWithErrorResponse() implementation here calls
46   // DoCallMethodWithErrorResponse() which is mockable.
47   void CallMethodWithErrorResponse(MethodCall* method_call,
48                                    int timeout_ms,
49                                    ResponseOrErrorCallback callback) override;
50   MOCK_METHOD3(DoCallMethodWithErrorResponse,
51                void(MethodCall* method_call,
52                     int timeout_ms,
53                     ResponseOrErrorCallback* callback));
54 
55   // This method is not mockable because it takes a move-only argument. To work
56   // around this, CallMethodWithErrorCallback() implementation here calls
57   // DoCallMethodWithErrorCallback() which is mockable.
58   void CallMethodWithErrorCallback(MethodCall* method_call,
59                                    int timeout_ms,
60                                    ResponseCallback callback,
61                                    ErrorCallback error_callback) override;
62   MOCK_METHOD4(DoCallMethodWithErrorCallback,
63                void(MethodCall* method_call,
64                     int timeout_ms,
65                     ResponseCallback* callback,
66                     ErrorCallback* error_callback));
67 
68   // This method is not mockable because it takes a move-only argument. To work
69   // around this, ConnectToSignal() implementation here calls
70   // DoConnectToSignal() which is mockable.
71   void ConnectToSignal(const std::string& interface_name,
72                        const std::string& signal_name,
73                        SignalCallback signal_callback,
74                        OnConnectedCallback on_connected_callback) override;
75   MOCK_METHOD4(DoConnectToSignal,
76                void(const std::string& interface_name,
77                     const std::string& signal_name,
78                     SignalCallback signal_callback,
79                     OnConnectedCallback* on_connected_callback));
80   MOCK_METHOD1(SetNameOwnerChangedCallback,
81                void(NameOwnerChangedCallback callback));
82   MOCK_METHOD0(Detach, void());
83 
84  protected:
85   ~MockObjectProxy() override;
86 };
87 
88 }  // namespace dbus
89 
90 #endif  // DBUS_MOCK_OBJECT_PROXY_H_
91