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