• 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 <string>
9 
10 #include "dbus/message.h"
11 #include "dbus/object_path.h"
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,
22                   const ObjectPath& object_path);
23 
24   // GMock doesn't support the return type of std::unique_ptr<> because
25   // std::unique_ptr is uncopyable. This is a workaround which defines
26   // |MockCallMethodAndBlock| as a mock method and makes
27   // |CallMethodAndBlock| call the mocked method.  Use |MockCallMethodAndBlock|
28   // for setting/testing expectations.
29   MOCK_METHOD3(MockCallMethodAndBlockWithErrorDetails,
30                Response*(MethodCall* method_call,
31                          int timeout_ms,
32                          ScopedDBusError* error));
CallMethodAndBlockWithErrorDetails(MethodCall * method_call,int timeout_ms,ScopedDBusError * error)33   std::unique_ptr<Response> CallMethodAndBlockWithErrorDetails(
34       MethodCall* method_call,
35       int timeout_ms,
36       ScopedDBusError* error) override {
37     return std::unique_ptr<Response>(
38         MockCallMethodAndBlockWithErrorDetails(method_call, timeout_ms, error));
39   }
40   MOCK_METHOD2(MockCallMethodAndBlock, Response*(MethodCall* method_call,
41                                                  int timeout_ms));
CallMethodAndBlock(MethodCall * method_call,int timeout_ms)42   std::unique_ptr<Response> CallMethodAndBlock(MethodCall* method_call,
43                                                int timeout_ms) override {
44     return std::unique_ptr<Response>(
45         MockCallMethodAndBlock(method_call, timeout_ms));
46   }
47   MOCK_METHOD3(CallMethod, void(MethodCall* method_call,
48                                 int timeout_ms,
49                                 ResponseCallback callback));
50   MOCK_METHOD4(CallMethodWithErrorCallback, void(MethodCall* method_call,
51                                                  int timeout_ms,
52                                                  ResponseCallback callback,
53                                                  ErrorCallback error_callback));
54   MOCK_METHOD4(ConnectToSignal,
55                void(const std::string& interface_name,
56                     const std::string& signal_name,
57                     SignalCallback signal_callback,
58                     OnConnectedCallback on_connected_callback));
59   MOCK_METHOD0(Detach, void());
60 
61  protected:
62   ~MockObjectProxy() override;
63 };
64 
65 }  // namespace dbus
66 
67 #endif  // DBUS_MOCK_OBJECT_PROXY_H_
68