mock_bus.h 3.6 KB

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