Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_INTERFACE_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_INTERFACE_H__ |
| 7 | |
| 8 | #include <gmock/gmock.h> |
| 9 | |
| 10 | #include "update_engine/dbus_interface.h" |
| 11 | |
| 12 | namespace chromeos_update_engine { |
| 13 | |
| 14 | class MockDbusGlib : public DbusGlibInterface { |
| 15 | public: |
| 16 | MOCK_METHOD5(ProxyNewForNameOwner, DBusGProxy*(DBusGConnection *connection, |
| 17 | const char *name, |
| 18 | const char *path, |
| 19 | const char *interface, |
| 20 | GError **error)); |
| 21 | |
| 22 | MOCK_METHOD1(ProxyUnref, void(DBusGProxy* proxy)); |
| 23 | |
| 24 | MOCK_METHOD2(BusGet, DBusGConnection*(DBusBusType type, GError **error)); |
| 25 | |
| 26 | MOCK_METHOD7(ProxyCall, gboolean(DBusGProxy *proxy, |
| 27 | const char *method, |
| 28 | GError **error, |
| 29 | GType first_arg_type, |
| 30 | GType var_arg1, |
| 31 | GHashTable** var_arg2, |
| 32 | GType var_arg3)); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 33 | MOCK_METHOD10(ProxyCall, gboolean(DBusGProxy* proxy, |
| 34 | const char* method, |
| 35 | GError** error, |
| 36 | GType var_arg1, const char* var_arg2, |
| 37 | GType var_arg3, |
| 38 | GType var_arg4, gchar** var_arg5, |
| 39 | GType var_arg6, GArray** var_arg7)); |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame^] | 40 | MOCK_METHOD10(ProxyCall, gboolean(DBusGProxy* proxy, |
| 41 | const char* method, |
| 42 | GError** error, |
| 43 | GType var_arg1, const char* var_arg2, |
| 44 | GType var_arg3, const char* var_arg4, |
| 45 | GType var_arg5, const char* var_arg6, |
| 46 | GType var_arg7)); |
| 47 | |
| 48 | MOCK_METHOD1(ConnectionGetConnection, DBusConnection*(DBusGConnection* gbus)); |
| 49 | |
| 50 | MOCK_METHOD3(DbusBusAddMatch, void(DBusConnection* connection, |
| 51 | const char* rule, |
| 52 | DBusError* error)); |
| 53 | |
| 54 | MOCK_METHOD4(DbusConnectionAddFilter, dbus_bool_t( |
| 55 | DBusConnection* connection, |
| 56 | DBusHandleMessageFunction function, |
| 57 | void* user_data, |
| 58 | DBusFreeFunction free_data_function)); |
| 59 | |
| 60 | MOCK_METHOD3(DbusConnectionRemoveFilter, void( |
| 61 | DBusConnection* connection, |
| 62 | DBusHandleMessageFunction function, |
| 63 | void* user_data)); |
| 64 | |
| 65 | MOCK_METHOD3(DbusMessageIsSignal, dbus_bool_t(DBusMessage* message, |
| 66 | const char* interface, |
| 67 | const char* signal_name)); |
| 68 | |
| 69 | MOCK_METHOD9(DbusMessageGetArgs, dbus_bool_t( |
| 70 | DBusMessage* message, |
| 71 | DBusError* error, |
| 72 | GType var_arg1, char** var_arg2, |
| 73 | GType var_arg3, char** var_arg4, |
| 74 | GType var_arg5, char** var_arg6, |
| 75 | GType var_arg7)); |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 76 | |
| 77 | // Since gmock only supports mocking functions up to 10 args, we |
| 78 | // take the 11-arg function we'd like to mock, drop the last arg |
| 79 | // and call the 10-arg version. Dropping the last arg isn't ideal, |
| 80 | // but this is a lot better than nothing. |
| 81 | gboolean ProxyCall(DBusGProxy* proxy, |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame^] | 82 | const char* method, |
| 83 | GError** error, |
| 84 | GType var_arg1, const char* var_arg2, |
| 85 | GType var_arg3, |
| 86 | GType var_arg4, gchar** var_arg5, |
| 87 | GType var_arg6, GArray** var_arg7, |
| 88 | GType var_arg8) { |
| 89 | return ProxyCall(proxy, |
| 90 | method, |
| 91 | error, |
| 92 | var_arg1, var_arg2, |
| 93 | var_arg3, |
| 94 | var_arg4, var_arg5, |
| 95 | var_arg6, var_arg7); |
| 96 | } |
| 97 | gboolean ProxyCall(DBusGProxy* proxy, |
| 98 | const char* method, |
| 99 | GError** error, |
| 100 | GType var_arg1, const char* var_arg2, |
| 101 | GType var_arg3, const char* var_arg4, |
| 102 | GType var_arg5, const char* var_arg6, |
| 103 | GType var_arg7, GType var_arg8) { |
Andrew de los Reyes | 9cd120d | 2010-11-18 17:50:03 -0800 | [diff] [blame] | 104 | return ProxyCall(proxy, |
| 105 | method, |
| 106 | error, |
| 107 | var_arg1, var_arg2, |
| 108 | var_arg3, |
| 109 | var_arg4, var_arg5, |
| 110 | var_arg6, var_arg7); |
| 111 | } |
Andrew de los Reyes | d57d147 | 2010-10-21 13:34:08 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace chromeos_update_engine |
| 115 | |
| 116 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_MOCK_DBUS_INTERFACE_H__ |