From 3cd31f675c8557f9d095a575f754299a95c332d8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 20 Apr 2012 13:54:15 +0100 Subject: [PATCH 05/11] Factor out a common test_assert_no_error macro --- test/core/proxy-peer.c | 12 +++--------- test/core/registrations.c | 18 ++++-------------- test/lib/util.c | 12 +++++++++++- test/lib/util.h | 5 +++++ 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/test/core/proxy-peer.c b/test/core/proxy-peer.c index 8c1b867..61bb531 100644 --- a/test/core/proxy-peer.c +++ b/test/core/proxy-peer.c @@ -33,6 +33,7 @@ #include #include "my-object.h" +#include "test/lib/util.h" GMainLoop *loop; @@ -54,13 +55,6 @@ typedef struct { } Fixture; static void -assert_no_error (const DBusError *e) -{ - if (G_UNLIKELY (dbus_error_is_set (e))) - g_error ("expected success but got error: %s: %s", e->name, e->message); -} - -static void new_conn_cb (DBusServer *server, DBusConnection *server_conn, void *data) @@ -91,7 +85,7 @@ setup (Fixture *f, dbus_error_init (&f->e); f->server = dbus_server_listen (addr, &f->e); - assert_no_error (&f->e); + test_assert_no_error (&f->e); g_assert (f->server != NULL); dbus_server_set_new_connection_function (f->server, @@ -102,7 +96,7 @@ setup (Fixture *f, f->client_conn = dbus_connection_open_private ( dbus_server_get_address (f->server), &f->e); - assert_no_error (&f->e); + test_assert_no_error (&f->e); g_assert (f->client_conn != NULL); dbus_connection_setup_with_g_main (f->client_conn, NULL); f->client_gconn = dbus_connection_get_g_connection (f->client_conn); diff --git a/test/core/registrations.c b/test/core/registrations.c index d4e17dd..1284e05 100644 --- a/test/core/registrations.c +++ b/test/core/registrations.c @@ -41,6 +41,7 @@ #include #include "my-object.h" +#include "test/lib/util.h" GMainLoop *loop = NULL; @@ -54,17 +55,6 @@ typedef struct { gboolean received_objectified; } Fixture; -#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__) -static void -_assert_no_error (const DBusError *e, - const char *file, - int line) -{ - if (G_UNLIKELY (dbus_error_is_set (e))) - g_error ("%s:%d: expected success but got error: %s: %s", - file, line, e->name, e->message); -} - static void setup (Fixture *f, gconstpointer path_to_use) @@ -252,7 +242,7 @@ test_twice (Fixture *f, dbus_bus_add_match (dbus_g_connection_get_connection (f->bus), "type='signal'", &f->dbus_error); - assert_no_error (&f->dbus_error); + test_assert_no_error (&f->dbus_error); mem = dbus_connection_add_filter (dbus_g_connection_get_connection (f->bus), frobnicate_cb, f, NULL); g_assert (mem); @@ -291,7 +281,7 @@ test_clean_slate (Fixture *f, dbus_bus_add_match (dbus_g_connection_get_connection (f->bus), "type='signal'", &f->dbus_error); - assert_no_error (&f->dbus_error); + test_assert_no_error (&f->dbus_error); mem = dbus_connection_add_filter (dbus_g_connection_get_connection (f->bus), frobnicate_cb, f, NULL); g_assert (mem); @@ -401,7 +391,7 @@ test_marshal_object (Fixture *f, dbus_bus_add_match (dbus_g_connection_get_connection (f->bus), "type='signal'", &f->dbus_error); - assert_no_error (&f->dbus_error); + test_assert_no_error (&f->dbus_error); mem = dbus_connection_add_filter (dbus_g_connection_get_connection (f->bus), objectified_cb, f, NULL); g_assert (mem); diff --git a/test/lib/util.c b/test/lib/util.c index ec879b5..d0482fa 100644 --- a/test/lib/util.c +++ b/test/lib/util.c @@ -1,6 +1,6 @@ /* Regression test utilities * - * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2012 Collabora Ltd. * Copyright © 2009-2011 Nokia Corporation * * Licensed under the Academic Free License version 2.1 @@ -67,3 +67,13 @@ test_run_until_disconnected (DBusGConnection *connection, g_printerr (" disconnected\n"); } + +void +_test_assert_no_error (const DBusError *e, + const char *file, + int line) +{ + if (G_UNLIKELY (dbus_error_is_set (e))) + g_error ("%s:%d: expected success but got error: %s: %s", + file, line, e->name, e->message); +} diff --git a/test/lib/util.h b/test/lib/util.h index bc6fa60..bafa01c 100644 --- a/test/lib/util.h +++ b/test/lib/util.h @@ -29,4 +29,9 @@ void test_run_until_disconnected (DBusGConnection *connection, GMainContext *context); +#define test_assert_no_error(e) _test_assert_no_error (e, __FILE__, __LINE__) +void _test_assert_no_error (const DBusError *e, + const char *file, + int line); + #endif -- 1.8.4.rc3