• 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_BUS_H_
6 #define DBUS_MOCK_BUS_H_
7 
8 #include <stdint.h>
9 
10 #include "dbus/bus.h"
11 #include "dbus/object_path.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 
14 namespace dbus {
15 
16 // Mock for Bus class. Along with MockObjectProxy and MockExportedObject,
17 // the mock classes can be used to write unit tests without issuing real
18 // D-Bus calls.
19 class MockBus : public Bus {
20  public:
21   MockBus(const Bus::Options& options);
22 
23   MOCK_METHOD2(GetObjectProxy, ObjectProxy*(const std::string& service_name,
24                                             const ObjectPath& object_path));
25   MOCK_METHOD3(GetObjectProxyWithOptions,
26                ObjectProxy*(const std::string& service_name,
27                             const ObjectPath& object_path,
28                             int options));
29   MOCK_METHOD3(RemoveObjectProxy, bool(
30       const std::string& service_name,
31       const ObjectPath& object_path,
32       const base::Closure& callback));
33   MOCK_METHOD4(RemoveObjectProxyWithOptions, bool(
34       const std::string& service_name,
35       const ObjectPath& object_path,
36       int options,
37       const base::Closure& callback));
38   MOCK_METHOD1(GetExportedObject, ExportedObject*(
39       const ObjectPath& object_path));
40   MOCK_METHOD2(GetObjectManager, ObjectManager*(const std::string&,
41                                                 const ObjectPath&));
42   MOCK_METHOD0(ShutdownAndBlock, void());
43   MOCK_METHOD0(ShutdownOnDBusThreadAndBlock, void());
44   MOCK_METHOD0(Connect, bool());
45   MOCK_METHOD3(RequestOwnership, void(
46       const std::string& service_name,
47       ServiceOwnershipOptions options,
48       OnOwnershipCallback on_ownership_callback));
49   MOCK_METHOD2(RequestOwnershipAndBlock, bool(const std::string& service_name,
50                                               ServiceOwnershipOptions options));
51   MOCK_METHOD1(ReleaseOwnership, bool(const std::string& service_name));
52   MOCK_METHOD0(SetUpAsyncOperations, bool());
53   MOCK_METHOD3(SendWithReplyAndBlock, DBusMessage*(DBusMessage* request,
54                                                    int timeout_ms,
55                                                    DBusError* error));
56   MOCK_METHOD3(SendWithReply, void(DBusMessage* request,
57                                    DBusPendingCall** pending_call,
58                                    int timeout_ms));
59   MOCK_METHOD2(Send, void(DBusMessage* request, uint32_t* serial));
60   MOCK_METHOD2(AddFilter, void(DBusHandleMessageFunction handle_message,
61                                void* user_data));
62   MOCK_METHOD2(RemoveFilter, void(DBusHandleMessageFunction handle_message,
63                                   void* user_data));
64   MOCK_METHOD2(AddMatch, void(const std::string& match_rule,
65                               DBusError* error));
66   MOCK_METHOD2(RemoveMatch, bool(const std::string& match_rule,
67                                  DBusError* error));
68   MOCK_METHOD4(TryRegisterObjectPath, bool(const ObjectPath& object_path,
69                                            const DBusObjectPathVTable* vtable,
70                                            void* user_data,
71                                            DBusError* error));
72   MOCK_METHOD1(UnregisterObjectPath, void(const ObjectPath& object_path));
73   MOCK_METHOD0(GetDBusTaskRunner, base::TaskRunner*());
74   MOCK_METHOD0(GetOriginTaskRunner, base::TaskRunner*());
75   MOCK_METHOD0(HasDBusThread, bool());
76   MOCK_METHOD0(AssertOnOriginThread, void());
77   MOCK_METHOD0(AssertOnDBusThread, void());
78 
79  protected:
80   virtual ~MockBus();
81 };
82 
83 }  // namespace dbus
84 
85 #endif  // DBUS_MOCK_BUS_H_
86