File: e-source-registry-test.c

package info (click to toggle)
evolution-data-server 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,108 kB
  • sloc: ansic: 365,415; xml: 578; cpp: 482; perl: 297; sh: 62; makefile: 60; python: 35; javascript: 29
file content (164 lines) | stat: -rw-r--r-- 4,073 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * 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.
 *
 * 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 this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "e-test-server-utils.h"

#include <libedataserver/libedataserver.h>

static ETestServerClosure test_closure = { E_TEST_SERVER_NONE, NULL, 0, FALSE, NULL };

static ESource *
create_source (ESourceRegistry *registry)
{
	ESource *scratch_source;
	ESource *created_source;
	const gchar *uid;
	GError *local_error = NULL;

	/* Configure a minimal scratch 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 scratch source UID. */
	uid = e_source_get_uid (scratch_source);

	/* Commit the scratch source. */
	e_source_registry_commit_source_sync (
		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_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 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);

	return success;
}

static gboolean
test_create_source_idle_cb (gpointer user_data)
{
	ETestServerFixture *fixture = user_data;
	ESource *source;

	source = create_source (fixture->registry);

	if (source == NULL)
		g_test_fail ();

	g_clear_object (&source);

	g_main_loop_quit (fixture->loop);

	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_create_source (ETestServerFixture *fixture,
                    gconstpointer user_data)
{
	g_test_bug ("685986");
	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);
}

gint
main (gint argc,
      gchar **argv)
{
	gint retval;

	g_test_init (&argc, &argv, NULL);
	g_test_bug_base ("http://bugzilla.gnome.org/");

	g_test_add (
		"/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_remove_source,
		e_test_server_utils_teardown);

	retval = e_test_server_utils_run (argc, argv);

	/* XXX Something is leaking a GDBusConnection reference.
	 *     Leave this disabled until I can track it down. */
	/* g_object_unref (closure.test_dbus); */

	return retval;
}