From 0d8642e9f18cce24ea584aff95698239fa8cc325 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 19 Feb 2013 22:54:45 +0900 Subject: [PATCH] e-test-server-utils: Add support for testing Direct Read Access books. --- tests/test-server-utils/e-test-server-utils.c | 20 ++++++++++++++++++-- tests/test-server-utils/e-test-server-utils.h | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c index 9a2d706..5f681a5 100644 --- a/tests/test-server-utils/e-test-server-utils.c +++ b/tests/test-server-utils/e-test-server-utils.c @@ -99,6 +99,8 @@ static gboolean e_test_server_utils_bootstrap_timeout (FixturePair *pair) { g_error ("Timed out while waiting for ESource creation from the registry"); + + pair->fixture->timeout_source_id = 0; return FALSE; } @@ -111,10 +113,11 @@ e_test_server_utils_source_added (ESourceRegistry *registry, switch (pair->closure->type) { case E_TEST_SERVER_ADDRESS_BOOK: + case E_TEST_SERVER_DIRECT_ADDRESS_BOOK: if (g_strcmp0 (e_source_get_uid (source), ADDRESS_BOOK_SOURCE_UID) != 0) return; - if (g_getenv ("DEBUG_DIRECT") != NULL) + if (pair->closure->type == E_TEST_SERVER_DIRECT_ADDRESS_BOOK) pair->fixture->service.book_client = (EBookClient *) e_book_client_connect_direct_sync (pair->fixture->registry, source, NULL, &error); else @@ -189,6 +192,7 @@ e_test_server_utils_bootstrap_idle (FixturePair *pair) /* Create an address book */ switch (pair->closure->type) { case E_TEST_SERVER_ADDRESS_BOOK: + case E_TEST_SERVER_DIRECT_ADDRESS_BOOK: case E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK: scratch = e_source_new_with_uid (ADDRESS_BOOK_SOURCE_UID, NULL, &error); @@ -228,7 +232,8 @@ e_test_server_utils_bootstrap_idle (FixturePair *pair) } if (pair->closure->type != E_TEST_SERVER_NONE) - g_timeout_add (20 * 1000, (GSourceFunc) e_test_server_utils_bootstrap_timeout, pair); + pair->fixture->timeout_source_id = + g_timeout_add (20 * 1000, (GSourceFunc) e_test_server_utils_bootstrap_timeout, pair); else g_main_loop_quit (pair->fixture->loop); @@ -271,6 +276,16 @@ e_test_server_utils_setup (ETestServerFixture *fixture, g_idle_add ((GSourceFunc) e_test_server_utils_bootstrap_idle, &pair); g_main_loop_run (fixture->loop); + + /* This needs to be explicitly removed, otherwise the timeout source + * stays in the default GMainContext and after running tests for 20 seconds + * in the same test suite... the tests bail out. + */ + if (fixture->timeout_source_id) { + g_source_remove (fixture->timeout_source_id); + fixture->timeout_source_id = 0; + } + g_signal_handlers_disconnect_by_func (fixture->registry, e_test_server_utils_source_added, &pair); } @@ -290,6 +305,7 @@ e_test_server_utils_teardown (ETestServerFixture *fixture, switch (closure->type) { case E_TEST_SERVER_ADDRESS_BOOK: + case E_TEST_SERVER_DIRECT_ADDRESS_BOOK: if (!e_client_remove_sync (E_CLIENT (fixture->service.book_client), NULL, &error)) { g_message ("Failed to remove test book: %s (ignoring)", error->message); g_clear_error (&error); diff --git a/tests/test-server-utils/e-test-server-utils.h b/tests/test-server-utils/e-test-server-utils.h index a1a663a..84a9562 100644 --- a/tests/test-server-utils/e-test-server-utils.h +++ b/tests/test-server-utils/e-test-server-utils.h @@ -60,6 +60,7 @@ typedef void (* ETestSourceCustomizeFunc) (ESource *scratch, * ETestServiceType: * @E_TEST_SERVER_NONE: Only the #ESourceRegistry will be created * @E_TEST_SERVER_ADDRESS_BOOK: An #EBookCLient will be created and opened for the test + * @E_TEST_SERVER_DIRECT_ADDRESS_BOOK: An #EBookCLient in direct read access mode will be created and opened for the test * @E_TEST_SERVER_CALENDAR: An #ECalClient will be created and opened for the test * @E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK: An #EBook will be created and opened for the test * @@ -68,6 +69,7 @@ typedef void (* ETestSourceCustomizeFunc) (ESource *scratch, typedef enum { E_TEST_SERVER_NONE = 0, E_TEST_SERVER_ADDRESS_BOOK, + E_TEST_SERVER_DIRECT_ADDRESS_BOOK, E_TEST_SERVER_CALENDAR, E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK, E_TEST_SERVER_DEPRECATED_CALENDAR @@ -116,6 +118,7 @@ typedef union { * @dbus: The D-Bus test scaffold * @registry: An #ESourceRegistry * @service: The #ETestService + * @timeout_source_id: A private detail, tracks the idle source which times out if the registry cannot create an ESource. * * A fixture for running tests on the Evolution Data Server * components in an encapsulated D-Bus environment. @@ -125,6 +128,7 @@ struct _ETestServerFixture { GTestDBus *dbus; ESourceRegistry *registry; ETestService service; + guint timeout_source_id; }; void e_test_server_utils_setup (ETestServerFixture *fixture, -- 2.7.4