[evolution-data-server] e-test-server-utils.[ch]: Making the test fixture more strict.



commit da8a14446e5b96fcae48e88517b847cd6a8be8a4
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Mar 16 19:02:49 2013 +0900

    e-test-server-utils.[ch]: Making the test fixture more strict.
    
    Now the fixture also asserts that any client/registry created by
    the fixture is properly finalized after the final g_object_unref()
    while tearing down the fixture.
    
    The checks are performed by added g_object_weak_ref() callbacks.

 tests/test-server-utils/e-test-server-utils.c |   40 +++++++++++++++++++++++++
 tests/test-server-utils/e-test-server-utils.h |    2 +
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c
index 531dc6f..32f3c88 100644
--- a/tests/test-server-utils/e-test-server-utils.c
+++ b/tests/test-server-utils/e-test-server-utils.c
@@ -117,6 +117,24 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 }
 
 static void
+registry_weak_notify (gpointer data,
+                     GObject *where_the_object_was)
+{
+       ETestServerFixture *fixture = (ETestServerFixture *)data;
+
+       fixture->registry_finalized = TRUE;
+}
+
+static void
+client_weak_notify (gpointer data,
+                   GObject *where_the_object_was)
+{
+       ETestServerFixture *fixture = (ETestServerFixture *)data;
+
+       fixture->client_finalized = TRUE;
+}
+
+static void
 e_test_server_utils_source_added (ESourceRegistry *registry,
                                   ESource *source,
                                   FixturePair *pair)
@@ -140,6 +158,9 @@ e_test_server_utils_source_added (ESourceRegistry *registry,
                if (!pair->fixture->service.book_client)
                        g_error ("Unable to create the test book: %s", error->message);
 
+               g_object_weak_ref (G_OBJECT (pair->fixture->service.book_client),
+                                  client_weak_notify, pair->fixture);
+
                break;
 
        case E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK:
@@ -151,6 +172,9 @@ e_test_server_utils_source_added (ESourceRegistry *registry,
                if (!e_book_open (pair->fixture->service.book, FALSE, &error))
                        g_error ("Unable to open book: %s", error->message);
 
+               g_object_weak_ref (G_OBJECT (pair->fixture->service.book),
+                                  client_weak_notify, pair->fixture);
+
                break;
 
        case E_TEST_SERVER_CALENDAR:
@@ -162,6 +186,9 @@ e_test_server_utils_source_added (ESourceRegistry *registry,
                if (!pair->fixture->service.calendar_client)
                        g_error ("Unable to create the test calendar: %s", error->message);
 
+               g_object_weak_ref (G_OBJECT (pair->fixture->service.calendar_client),
+                                  client_weak_notify, pair->fixture);
+
                break;
 
        case E_TEST_SERVER_DEPRECATED_CALENDAR:
@@ -173,6 +200,9 @@ e_test_server_utils_source_added (ESourceRegistry *registry,
                if (!e_cal_open (pair->fixture->service.calendar, FALSE, &error))
                        g_error ("Unable to open calendar: %s", error->message);
 
+               g_object_weak_ref (G_OBJECT (pair->fixture->service.calendar),
+                                  client_weak_notify, pair->fixture);
+
                break;
 
        case E_TEST_SERVER_NONE:
@@ -194,6 +224,9 @@ e_test_server_utils_bootstrap_idle (FixturePair *pair)
        if (!pair->fixture->registry)
                g_error ("Unable to create the test registry: %s", error->message);
 
+       g_object_weak_ref (G_OBJECT (pair->fixture->registry),
+                          registry_weak_notify, pair->fixture);
+
        g_signal_connect (
                pair->fixture->registry, "source-added",
                G_CALLBACK (e_test_server_utils_source_added), pair);
@@ -359,11 +392,18 @@ e_test_server_utils_teardown (ETestServerFixture *fixture,
                break;
        }
 
+       if (closure->type != E_TEST_SERVER_NONE &&
+           fixture->client_finalized == FALSE)
+               g_error ("Failed to destroy client while tearing down test case; reference count imbalance");
+
        g_free (fixture->source_name);
        g_object_run_dispose (G_OBJECT (fixture->registry));
        g_object_unref (fixture->registry);
        fixture->registry = NULL;
 
+       if (fixture->registry_finalized == FALSE)
+               g_error ("Failed to destroy registry while tearing down test case; reference count 
imbalance");
+
        g_main_loop_unref (fixture->loop);
        fixture->loop = NULL;
 
diff --git a/tests/test-server-utils/e-test-server-utils.h b/tests/test-server-utils/e-test-server-utils.h
index e08fb24..1e5f72e 100644
--- a/tests/test-server-utils/e-test-server-utils.h
+++ b/tests/test-server-utils/e-test-server-utils.h
@@ -131,6 +131,8 @@ struct _ETestServerFixture {
        ETestService     service;
        gchar           *source_name;
        guint            timeout_source_id;
+       guint            client_finalized : 1;
+       guint            registry_finalized : 1;
 };
 
 void e_test_server_utils_setup    (ETestServerFixture *fixture,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]