4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
20 #include <gio/gunixoutputstream.h>
22 #include <libedataserver/libedataserver.h>
24 #define SIMPLE_KEY_FILE \
26 "DisplayName=Simple Test Case\n" \
29 typedef struct _TestESource TestESource;
30 typedef struct _TestFixture TestFixture;
40 TestESource same_file;
41 TestESource same_content;
45 #if 0 /* ACCOUNT_MGMT */
47 source_changed_cb (ESource *source,
54 setup_test_source (TestESource *test,
57 GOutputStream *stream;
62 /* Create a new temporary key file. */
63 fd = g_file_open_tmp ("test-source-XXXXXX", &filename, &error);
64 g_assert_no_error (error);
66 /* Write the given content to the temporary key file. */
67 stream = g_unix_output_stream_new (fd, TRUE);
68 g_output_stream_write_all (
69 stream, content, strlen (content), NULL, NULL, &error);
70 g_object_unref (stream);
71 g_assert_no_error (error);
73 /* Create a GFile that points to the temporary key file. */
74 test->file = g_file_new_for_path (filename);
76 /* Create an ESource from the GFile and load the key file. */
77 test->source = e_source_new (test->file, &error);
78 g_assert_no_error (error);
81 test->source, "changed",
82 G_CALLBACK (source_changed_cb), test);
88 teardown_test_source (TestESource *test)
92 /* Delete the temporary key file. */
93 g_file_delete (test->file, NULL, &error);
94 g_assert_no_error (error);
96 g_object_unref (test->file);
97 g_object_unref (test->source);
99 #endif /* ACCOUNT_MGMT */
102 test_fixture_setup_key_file (TestFixture *fixture,
103 gconstpointer test_data)
105 #if 0 /* ACCOUNT_MGMT */
106 GError *error = NULL;
108 /* The primary ESource for testing. */
109 setup_test_source (&fixture->test, SIMPLE_KEY_FILE);
111 /* Secondary ESource: different file with identical content. */
112 setup_test_source (&fixture->same_content, SIMPLE_KEY_FILE);
114 /* Secondary ESource: a clone of the primary ESource. */
115 fixture->same_file.file =
116 g_file_dup (fixture->test.file);
117 fixture->same_file.source =
118 e_source_new (fixture->same_file.file, &error);
119 g_assert_no_error (error);
120 #endif /* ACCOUNT_MGMT */
124 test_fixture_teardown_key_file (TestFixture *fixture,
125 gconstpointer test_data)
127 #if 0 /* ACCOUNT_MGMT */
128 teardown_test_source (&fixture->test);
133 test_single_source (TestFixture *fixture,
134 gconstpointer test_data)
136 #if 0 /* ACCOUNT_MGMT */
138 ESourceExtension *extension;
139 const gchar *extension_name;
140 const gchar *backend_name;
141 const gchar *display_name;
146 GError *error = NULL;
148 /* Extract a bunch of data from the primary ESource. */
149 backend_name = e_source_get_backend_name (fixture->test.source);
150 display_name = e_source_get_display_name (fixture->test.source);
151 parent = e_source_get_parent (fixture->test.source);
152 file = e_source_get_file (fixture->test.source);
153 uid = e_source_get_uid (fixture->test.source);
154 hash = e_source_hash (fixture->test.source);
156 /* An ESource's GFile should compare equal to the GFile
157 * used to create it. */
158 g_assert (g_file_equal (file, fixture->test.file));
160 /* An ESource's UID should match the key file's basename. */
161 basename = g_file_get_basename (fixture->test.file);
162 g_assert_cmpstr (uid, ==, basename);
165 /* An ESource's hash value is based on its UID. */
166 g_assert_cmpuint (hash, ==, g_str_hash (uid));
168 /* Check the other fields specified in this key file. */
169 g_assert_cmpstr (display_name, ==, "Simple Test Case");
170 g_assert_cmpstr (parent, ==, "local");
172 /* The backend name was omitted, so it should be NULL. */
173 g_assert_cmpstr (backend_name, ==, NULL);
175 /* ESource equality is based solely on UIDs. */
176 g_assert (e_source_equal (
177 fixture->test.source, fixture->test.source));
178 g_assert (e_source_equal (
179 fixture->test.source, fixture->same_file.source));
180 g_assert (!e_source_equal (
181 fixture->test.source, fixture->same_content.source));
183 /* Nothing done so far should have triggered ESource::changed. */
184 g_assert (!fixture->test.changed);
186 /* Check on-demand extension loading. */
187 E_TYPE_SOURCE_AUTHENTICATION; /* register the type */
188 extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
189 g_assert (!e_source_has_extension (
190 fixture->test.source, extension_name));
191 extension = e_source_get_extension (
192 fixture->test.source, extension_name);
193 g_assert (e_source_has_extension (
194 fixture->test.source, extension_name));
195 g_assert (E_IS_SOURCE_AUTHENTICATION (extension));
197 /* Loading an extension should trigger ESource::changed. */
198 g_assert (fixture->test.changed);
200 fixture->test.changed = FALSE;
202 /* The ESource::changed signal is wired to its own "notify" and
203 * the "notify" signals of its extensions. Passing any property
204 * to g_object_notify() should trigger it. */
205 g_object_notify (G_OBJECT (fixture->test.source), "display-name");
206 g_assert (fixture->test.changed);
208 fixture->test.changed = FALSE;
210 /* Now try the extension we loaded. */
211 g_object_notify (G_OBJECT (extension), "host");
212 g_assert (fixture->test.changed);
214 /* The primary ESource and cloned ESource both handle the same
215 * key file. If we change a property in one ESource and sync it
216 * to disk, then reload the other ESource and examine the same
217 * property, the values should match. */
218 display_name = "Modified Test Case";
219 e_source_set_display_name (fixture->test.source, display_name);
220 e_source_sync (fixture->test.source, &error);
221 g_assert_no_error (error);
222 e_source_reload (fixture->same_file.source, &error);
223 g_assert_no_error (error);
224 display_name = e_source_get_display_name (fixture->same_file.source);
225 g_assert_cmpstr (display_name, ==, "Modified Test Case");
226 #endif /* ACOCUNT_MGMT */
235 g_test_init (&argc, &argv, NULL);
238 "/e-source-test/SingleSource",
240 test_fixture_setup_key_file,
242 test_fixture_teardown_key_file);
244 return g_test_run ();