From 65a696cbd59bb06f0050a73ead4d3b792fba8ad4 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 26 Oct 2013 14:29:50 -0400 Subject: [PATCH] Add a test case for bug 710668. --- tests/libedataserver/e-source-registry-test.c | 123 ++++++++++++++++++++------ 1 file changed, 95 insertions(+), 28 deletions(-) diff --git a/tests/libedataserver/e-source-registry-test.c b/tests/libedataserver/e-source-registry-test.c index a4f66fc..e3217c2 100644 --- a/tests/libedataserver/e-source-registry-test.c +++ b/tests/libedataserver/e-source-registry-test.c @@ -22,53 +22,113 @@ static ETestServerClosure test_closure = { E_TEST_SERVER_NONE, NULL, 0, FALSE, NULL }; -static gboolean -test_commit_source_idle_cb (gpointer user_data) +static ESource * +create_source (ESourceRegistry *registry) { - ETestServerFixture *fixture = user_data; - ESource *source; - gchar *uid; - GError *error = NULL; + ESource *scratch_source; + ESource *created_source; + const gchar *uid; + GError *local_error = NULL; /* Configure a minimal scratch source. */ - source = e_source_new (NULL, NULL, &error); - g_assert_no_error (error); - e_source_set_parent (source, "local-stub"); - e_source_set_display_name (source, "Test Commit Source"); + scratch_source = e_source_new (NULL, NULL, &local_error); + g_assert_no_error (local_error); + e_source_set_parent (scratch_source, "local-stub"); + e_source_set_display_name (scratch_source, "Test Commit Source"); - /* Note the ESource UID. */ - uid = e_source_dup_uid (source); + /* Note the scratch source UID. */ + uid = e_source_get_uid (scratch_source); - /* Submit the scratch source. */ + /* Commit the scratch source. */ e_source_registry_commit_source_sync ( - fixture->registry, source, NULL, &error); - g_assert_no_error (error); + registry, scratch_source, NULL, &local_error); + g_assert_no_error (local_error); + + /* Obtain the newly-created source from the registry. */ + created_source = e_source_registry_ref_source (registry, uid); /* Discard the scratch source. */ - g_object_unref (source); + g_clear_object (&scratch_source); + + return created_source; +} + +static gboolean +remove_source (ESourceRegistry *registry, + ESource *source) +{ + ESource *removed_source; + const gchar *uid; + gboolean success; + GError *local_error = NULL; + + if (source == NULL) + return FALSE; + + /* Request the source be removed. */ + e_source_remove_sync (source, NULL, &local_error); + g_assert_no_error (local_error); - /* Verify the registry has an ESource with the same UID. */ - source = e_source_registry_ref_source (fixture->registry, uid); + /* Verify the registry no longer has the source. */ + uid = e_source_get_uid (source); + removed_source = e_source_registry_ref_source (registry, uid); + success = (removed_source == NULL); + g_clear_object (&removed_source); - g_free (uid); + return success; +} + +static gboolean +test_create_source_idle_cb (gpointer user_data) +{ + ETestServerFixture *fixture = user_data; + ESource *source; - if (source != NULL) { - g_object_unref (source); - } else { + source = create_source (fixture->registry); + + if (source == NULL) g_test_fail (); - } + + g_clear_object (&source); g_main_loop_quit (fixture->loop); - return FALSE; + return G_SOURCE_REMOVE; +} + +static gboolean +test_remove_source_idle_cb (gpointer user_data) +{ + ETestServerFixture *fixture = user_data; + ESource *source; + + source = create_source (fixture->registry); + + if (!remove_source (fixture->registry, source)) + g_test_fail (); + + g_clear_object (&source); + + g_main_loop_quit (fixture->loop); + + return G_SOURCE_REMOVE; } static void -test_commit_source (ETestServerFixture *fixture, +test_create_source (ETestServerFixture *fixture, gconstpointer user_data) { g_test_bug ("685986"); - g_idle_add (test_commit_source_idle_cb, fixture); + g_idle_add (test_create_source_idle_cb, fixture); + g_main_loop_run (fixture->loop); +} + +static void +test_remove_source (ETestServerFixture *fixture, + gconstpointer user_data) +{ + g_test_bug ("710668"); + g_idle_add (test_remove_source_idle_cb, fixture); g_main_loop_run (fixture->loop); } @@ -82,10 +142,17 @@ main (gint argc, g_test_bug_base ("http://bugzilla.gnome.org/"); g_test_add ( - "/e-source-registry-test/CommitSource", + "/e-source-registry-test/CreateSource", + ETestServerFixture, &test_closure, + e_test_server_utils_setup, + test_create_source, + e_test_server_utils_teardown); + + g_test_add ( + "/e-source-registry-test/RemoveSource", ETestServerFixture, &test_closure, e_test_server_utils_setup, - test_commit_source, + test_remove_source, e_test_server_utils_teardown); retval = e_test_server_utils_run (); -- 2.7.4