mock_bus.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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());
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(RequestOwnership, void(
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& service_name,
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      OnOwnershipCallback on_ownership_callback));
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(RequestOwnershipAndBlock, bool(const std::string& service_name));
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(ReleaseOwnership, bool(const std::string& service_name));
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(SetUpAsyncOperations, bool());
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(SendWithReplyAndBlock, DBusMessage*(DBusMessage* request,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   int timeout_ms,
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   DBusError* error));
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(SendWithReply, void(DBusMessage* request,
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   DBusPendingCall** pending_call,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   int timeout_ms));
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(Send, void(DBusMessage* request,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          uint32* serial));
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(AddFilter, void(DBusHandleMessageFunction handle_message,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               void* user_data));
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(RemoveFilter, void(DBusHandleMessageFunction handle_message,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  void* user_data));
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(AddMatch, void(const std::string& match_rule,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              DBusError* error));
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MOCK_METHOD2(RemoveMatch, bool(const std::string& match_rule,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 DBusError* error));
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD4(TryRegisterObjectPath, bool(const ObjectPath& object_path,
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           const DBusObjectPathVTable* vtable,
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           void* user_data,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           DBusError* error));
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD1(UnregisterObjectPath, void(const ObjectPath& object_path));
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(PostTaskToOriginThread, void(
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const tracked_objects::Location& from_here,
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Closure& task));
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD2(PostTaskToDBusThread, void(
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const tracked_objects::Location& from_here,
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Closure& task));
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD3(PostDelayedTaskToDBusThread, void(
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const tracked_objects::Location& from_here,
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const base::Closure& task,
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta delay));
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(HasDBusThread, bool());
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(AssertOnOriginThread, void());
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MOCK_METHOD0(AssertOnDBusThread, void());
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~MockBus();
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace dbus
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // DBUS_MOCK_BUS_H_
82