diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index ba2e6ad4c9fe8bd78fd59374aab956dceaff46ca..81c555743dadbf73569448870f206b7e55d7f7eb 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -67,7 +67,7 @@ static bool fwError; "target prot opt source destination\n" # if WITH_DBUS -VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block, +VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block, DBusMessage *, DBusConnection *, connection, DBusMessage *, message, @@ -82,7 +82,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block, char **args = NULL; char *type = NULL; - VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block); + VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block); if (STREQ(service, "org.freedesktop.DBus") && STREQ(member, "ListNames")) { diff --git a/tests/virmock.h b/tests/virmock.h index 0dd8bb50d8c13d54edf1be484b80f414a9500d96..8352e30197a48ca0052b87d5867b2425ad49ed62 100644 --- a/tests/virmock.h +++ b/tests/virmock.h @@ -234,33 +234,61 @@ */ # define VIR_MOCK_IMPL_RET_ARGS(name, rettype, ...) \ + rettype name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__)); \ + static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__)); \ + rettype name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__)) + +# define VIR_MOCK_IMPL_RET_VOID(name, rettype) \ + rettype name(void); \ + static rettype (*real_##name)(void); \ + rettype name(void) + +# define VIR_MOCK_IMPL_VOID_ARGS(name, ...) \ + void name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__)); \ + static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__)); \ + void name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__)) + +# define VIR_MOCK_IMPL_VOID_VOID(name) \ + void name(void); \ + static void (*real_##name)(void); \ + void name(void) + +/* + * The VIR_MOCK_WRAP_NNN_MMM() macros are intended for use in the + * individual test suites. The define a stub implementation of + * the wrapped method and insert the caller provided code snippet + * as the body of the method. + */ + +# define VIR_MOCK_WRAP_RET_ARGS(name, rettype, ...) \ rettype wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__)); \ static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__)); \ rettype wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__)) -# define VIR_MOCK_IMPL_INIT_REAL(name) \ - do { \ - if (real_##name == NULL && \ - !(real_##name = dlsym(RTLD_NEXT, \ - #name))) { \ - fprintf(stderr, "Missing symbol '" #name "'\n"); \ - abort(); \ - } \ - } while (0) - -# define VIR_MOCK_IMPL_RET_VOID(name, rettype) \ +# define VIR_MOCK_WRAP_RET_VOID(name, rettype) \ rettype wrap_##name(void); \ static rettype (*real_##name)(void); \ rettype wrap_##name(void) -# define VIR_MOCK_IMPL_VOID_ARGS(name, ...) \ +# define VIR_MOCK_WRAP_VOID_ARGS(name, ...) \ void wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__)); \ static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__)); \ void wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__)) -# define VIR_MOCK_IMPL_VOID_VOID(name) \ +# define VIR_MOCK_WRAP_VOID_VOID(name) \ void wrap_##name(void); \ static void (*real_##name)(void); \ void wrap_##name(void) + +# define VIR_MOCK_REAL_INIT(name) \ + do { \ + if (real_##name == NULL && \ + !(real_##name = dlsym(RTLD_NEXT, \ + #name))) { \ + fprintf(stderr, "Missing symbol '" #name "'\n"); \ + abort(); \ + } \ + } while (0) + #endif /* __VIR_MOCK_H__ */ diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 8f7b47eb5a51925c79b85e042357348004a323de..0d57a6aae14d6a298de8a44e63dc5c6f51975499 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -34,7 +34,7 @@ VIR_LOG_INIT("tests.systemdtest"); -VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block, +VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block, DBusMessage *, DBusConnection *, connection, DBusMessage *, message, @@ -45,7 +45,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block, const char *service = dbus_message_get_destination(message); const char *member = dbus_message_get_member(message); - VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block); + VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block); if (STREQ(service, "org.freedesktop.machine1")) { if (getenv("FAIL_BAD_SERVICE")) {