diff options
| author | Matthew Barnes <mbarnes@redhat.com> | 2012-10-26 16:34:10 -0400 |
|---|---|---|
| committer | Matthew Barnes <mbarnes@redhat.com> | 2012-10-27 08:46:41 -0400 |
| commit | d62d6eef737b30510ab10993b9e78f440b542477 (patch) | |
| tree | 9d9c11e70a28714195952d3418e34be92cd7d1a8 /tests/libedataserver | |
| parent | bb30f5774058af0fbcf8a969d61cf83d819b6df1 (diff) | |
| download | evolution-data-server-d62d6eef737b30510ab10993b9e78f440b542477.tar.gz | |
Add a test case for bug 685986.
Managed to reproduce the bug using the test case.
Diffstat (limited to 'tests/libedataserver')
| -rw-r--r-- | tests/libedataserver/Makefile.am | 47 | ||||
| -rw-r--r-- | tests/libedataserver/e-source-registry-test.c | 152 |
2 files changed, 187 insertions, 12 deletions
diff --git a/tests/libedataserver/Makefile.am b/tests/libedataserver/Makefile.am index 2019aa825..06469987a 100644 --- a/tests/libedataserver/Makefile.am +++ b/tests/libedataserver/Makefile.am @@ -1,17 +1,40 @@ -TESTS = e-source-test +NULL = + +TESTS = \ + e-source-test \ + e-source-registry-test \ + $(NULL) noinst_PROGRAMS = $(TESTS) -e_source_test_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -DG_LOG_DOMAIN=\"e-data-server\" \ - $(E_DATA_SERVER_CFLAGS) \ - $(GIO_UNIX_CFLAGS) - -e_source_test_LDADD = \ - $(top_builddir)/libedataserver/libedataserver-1.2.la \ - $(E_DATA_SERVER_LIBS) \ - $(GIO_UNIX_LIBS) +test_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"e-data-server\" \ + $(E_DATA_SERVER_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ + $(NULL) + +test_LDADD = \ + $(top_builddir)/libedataserver/libedataserver-1.2.la \ + $(E_DATA_SERVER_LIBS) \ + $(GIO_UNIX_LIBS) \ + $(NULL) + +e_source_test_SOURCES = \ + e-source-test.c \ + $(NULL) + +e_source_registry_test_SOURCES = \ + e-source-registry-test.c \ + e-test-dbus-utils.c \ + e-test-dbus-utils.h \ + $(NULL) + +e_source_test_CPPFLAGS = $(test_CPPFLAGS) +e_source_test_LDADD = $(test_LDADD) + +e_source_registry_test_CPPFLAGS = $(test_CPPFLAGS) +e_source_registry_test_LDADD = $(test_LDADD) -include $(top_srcdir)/git.mk diff --git a/tests/libedataserver/e-source-registry-test.c b/tests/libedataserver/e-source-registry-test.c new file mode 100644 index 000000000..d5111f765 --- /dev/null +++ b/tests/libedataserver/e-source-registry-test.c @@ -0,0 +1,152 @@ +/* + * e-source-registry-test.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see <http://www.gnu.org/licenses/> + * + */ + +#include "e-test-dbus-utils.h" + +#include <libedataserver/libedataserver.h> + +typedef struct _TestClosure TestClosure; +typedef struct _TestFixture TestFixture; + +struct _TestClosure { + GTestDBus *test_dbus; + const gchar *base_directory; +}; + +struct _TestFixture { + ESourceRegistry *registry; + GMainLoop *main_loop; +}; + +static void +test_fixture_setup_session (TestFixture *fixture, + gconstpointer user_data) +{ + const TestClosure *closure = user_data; + GError *error = NULL; + + g_assert (fixture->registry == NULL); + g_assert (fixture->main_loop == NULL); + + g_test_dbus_up (closure->test_dbus); + + fixture->registry = e_source_registry_new_sync (NULL, &error); + g_assert_no_error (error); + + fixture->main_loop = g_main_loop_new (NULL, FALSE); +} + +static void +test_fixture_teardown_session (TestFixture *fixture, + gconstpointer user_data) +{ + const TestClosure *closure = user_data; + GError *error = NULL; + + g_object_unref (fixture->registry); + fixture->registry = NULL; + + g_main_loop_unref (fixture->main_loop); + fixture->main_loop = NULL; + + g_test_dbus_stop (closure->test_dbus); + + e_test_clean_base_directories (&error); + g_assert_no_error (error); +} + +static gboolean +test_commit_source_idle_cb (gpointer user_data) +{ + TestFixture *fixture = user_data; + ESource *source; + gchar *uid; + GError *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"); + + /* Note the ESource UID. */ + uid = e_source_dup_uid (source); + + /* Submit the scratch source. */ + e_source_registry_commit_source_sync ( + fixture->registry, source, NULL, &error); + g_assert_no_error (error); + + /* Discard the scratch source. */ + g_object_unref (source); + + /* Verify the registry has an ESource with the same UID. */ + source = e_source_registry_ref_source (fixture->registry, uid); + + g_free (uid); + + if (source != NULL) { + g_object_unref (source); + } else { + g_test_fail (); + } + + g_main_loop_quit (fixture->main_loop); + + return FALSE; +} + +static void +test_commit_source (TestFixture *fixture, + gconstpointer user_data) +{ + g_test_bug ("685986"); + g_idle_add (test_commit_source_idle_cb, fixture); + g_main_loop_run (fixture->main_loop); +} + +gint +main (gint argc, + gchar **argv) +{ + TestClosure closure; + gint retval; + + g_type_init (); + + g_test_init (&argc, &argv, NULL); + g_test_bug_base ("http://bugzilla.gnome.org/"); + + closure.base_directory = e_test_setup_base_directories (); + closure.test_dbus = e_test_setup_dbus_session (); + + g_test_add ( + "/e-source-registry-test/CommitSource", + TestFixture, &closure, + test_fixture_setup_session, + test_commit_source, + test_fixture_teardown_session); + + retval = g_test_run (); + + /* XXX Something is leaking a GDBusConnection reference. + * Leave this disabled until I can track it down. */ + /* g_object_unref (closure.test_dbus); */ + + return retval; +} |
