15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef DBUS_MOCK_BUS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define DBUS_MOCK_BUS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "dbus/bus.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "dbus/object_path.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace dbus {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Mock for Bus class. Along with MockObjectProxy and MockExportedObject,
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the mock classes can be used to write unit tests without issuing real
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// D-Bus calls.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockBus : public Bus {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MockBus(const Bus::Options& options);
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(GetObjectProxy, ObjectProxy*(const std::string& service_name,
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            const ObjectPath& object_path));
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(GetObjectProxyWithOptions,
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)               ObjectProxy*(const std::string& service_name,
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const ObjectPath& object_path,
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int options));
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(GetExportedObject, ExportedObject*(
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const ObjectPath& object_path));
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD2(GetObjectManager, ObjectManager*(const std::string&,
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                const ObjectPath&));
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(ShutdownAndBlock, void());
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(ShutdownOnDBusThreadAndBlock, void());
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(Connect, bool());
34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  MOCK_METHOD3(RequestOwnership, void(
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& service_name,
36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      ServiceOwnershipOptions options,
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      OnOwnershipCallback on_ownership_callback));
38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  MOCK_METHOD2(RequestOwnershipAndBlock, bool(const std::string& service_name,
39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)                                              ServiceOwnershipOptions options));
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(ReleaseOwnership, bool(const std::string& service_name));
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(SetUpAsyncOperations, bool());
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(SendWithReplyAndBlock, DBusMessage*(DBusMessage* request,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   int timeout_ms,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   DBusError* error));
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(SendWithReply, void(DBusMessage* request,
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   DBusPendingCall** pending_call,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   int timeout_ms));
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(Send, void(DBusMessage* request,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          uint32* serial));
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(AddFilter, void(DBusHandleMessageFunction handle_message,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               void* user_data));
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(RemoveFilter, void(DBusHandleMessageFunction handle_message,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  void* user_data));
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(AddMatch, void(const std::string& match_rule,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              DBusError* error));
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD2(RemoveMatch, bool(const std::string& match_rule,
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 DBusError* error));
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD4(TryRegisterObjectPath, bool(const ObjectPath& object_path,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const DBusObjectPathVTable* vtable,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           void* user_data,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           DBusError* error));
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(UnregisterObjectPath, void(const ObjectPath& object_path));
6368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  MOCK_METHOD0(GetDBusTaskRunner, base::TaskRunner*());
6468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  MOCK_METHOD0(GetOriginTaskRunner, base::TaskRunner*());
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(HasDBusThread, bool());
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(AssertOnOriginThread, void());
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(AssertOnDBusThread, void());
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~MockBus();
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace dbus
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // DBUS_MOCK_BUS_H_
76