[folks] eds: Add create_address_book and remove_address_book to Edsf.PersonaStore. eds: Add create-remove-st
- From: Jeremy Whiting <jpwhiting src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] eds: Add create_address_book and remove_address_book to Edsf.PersonaStore. eds: Add create-remove-st
- Date: Wed, 17 Oct 2012 22:18:11 +0000 (UTC)
commit 11b13fc8c2827c1e39843d26e331c266a3e7ee64
Author: Jeremy Whiting <jpwhiting kde org>
Date: Mon Oct 15 15:23:04 2012 -0600
eds: Add create_address_book and remove_address_book to Edsf.PersonaStore.
eds: Add create-remove-stores unit test.
backends/eds/lib/edsf-persona-store.vala | 52 +++++++++
tests/eds/Makefile.am | 5 +
tests/eds/create-remove-stores.vala | 176 ++++++++++++++++++++++++++++++
3 files changed, 233 insertions(+), 0 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index e97bf2f..adc2c1c 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -74,6 +74,58 @@ public class Edsf.PersonaStore : Folks.PersonaStore
*/
public override string type_id { get { return BACKEND_NAME; } }
+ /**
+ * Create a new address book with the given ID.
+ *
+ * A new Address Book will be created with the given ID and the EDS
+ * SourceRegistry will notice the new Address Book source and will emit
+ * source_added with the new { link E.Source} object which { link Eds.Backend}
+ * will then create a new { link Edsf.PersonaStore} from.
+ *
+ * @param id the name and id for the new address book
+ * @throws GLib.Error
+ *
+ * @since UNRELEASED
+ */
+ public static async void create_address_book (string id) throws GLib.Error
+ {
+ debug ("Creating addressbook %s", id);
+ /* In order to create a new Address Book with the given id we follow
+ * the guidelines explained here:
+ * https://live.gnome.org/Evolution/ESourceMigrationGuide#How_do_I_create_a_new_calendar_or_address_book.3F
+ * for setting the backend name and parent UID to "local" and
+ * "local-stub" respectively.
+ */
+ E.Source new_source = new E.Source.with_uid (id, null);
+
+ new_source.set_parent ("local-stub");
+ new_source.set_display_name (id);
+
+ E.SourceAddressBook ab_extension =
+ (E.SourceAddressBook) new_source.get_extension ("Address Book");
+ ab_extension.set_backend_name ("local");
+
+ E.SourceRegistry registry = yield create_source_registry ();
+ yield registry.commit_source (new_source, null);
+ }
+
+ /**
+ * Remove a persona store's address book permamently.
+ *
+ * This is a utility function to remove an { link Edsf.PersonaStore}'s address
+ * book from the disk permanently. This simply wraps the EDS API to do
+ * the same.
+ *
+ * @param store the PersonaStore to delete the address book for.
+ * @throws GLib.Error
+ *
+ * @since UNRELEASED
+ */
+ public static async void remove_address_book (Edsf.PersonaStore store) throws GLib.Error
+ {
+ yield store.source.remove (null);
+ }
+
private void _address_book_notify_read_only_cb (Object address_book,
ParamSpec pspec)
{
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 613b6b5..c4626a5 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -77,6 +77,7 @@ noinst_PROGRAMS = \
set-roles \
link-personas-diff-stores \
enable-disable-stores \
+ create-remove-stores \
set-is-favourite \
$(NULL)
@@ -221,6 +222,10 @@ enable_disable_stores_SOURCES = \
enable-disable-stores.vala \
$(NULL)
+create_remove_stores_SOURCES = \
+ create-remove-stores.vala \
+ $(NULL)
+
set_is_favourite_SOURCES = \
set-is-favourite.vala \
$(NULL)
diff --git a/tests/eds/create-remove-stores.vala b/tests/eds/create-remove-stores.vala
new file mode 100644
index 0000000..92e97f5
--- /dev/null
+++ b/tests/eds/create-remove-stores.vala
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2012 Collabora Ltd.
+ *
+ * This library 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.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Jeremy Whiting <jeremy whiting collabora com>
+ *
+ */
+
+using Folks;
+using Gee;
+
+public class CreateRemoveStoresTests : Folks.TestCase
+{
+ private GLib.MainLoop _main_loop;
+ private EdsTest.Backend? _eds_backend;
+ private IndividualAggregator _aggregator;
+ private HashMap<string, bool> _store_removed;
+ private HashMap<string, bool> _store_added;
+ private BackendStore? _backend_store;
+
+ public CreateRemoveStoresTests ()
+ {
+ base ("CreateRemoveStoresTests");
+
+ this.add_test ("test creating and removing of PersonaStores",
+ this.test_creating_removing_stores);
+ }
+
+ public override void set_up ()
+ {
+ this._eds_backend = new EdsTest.Backend ();
+ this._store_removed = new HashMap<string, bool> ();
+ this._store_added = new HashMap<string, bool> ();
+ this._backend_store = BackendStore.dup();
+
+ this._eds_backend.set_up ();
+
+ /* We configure eds as the primary store */
+ var config_val = "eds:%s".printf (this._eds_backend.address_book_uid);
+ Environment.set_variable ("FOLKS_PRIMARY_STORE", config_val, true);
+ Environment.set_variable ("FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS",
+ "test:other:test1:test2", true);
+ }
+
+ public override void tear_down ()
+ {
+ this._eds_backend.tear_down ();
+
+ Environment.unset_variable ("FOLKS_PRIMARY_STORE");
+ Environment.unset_variable ("FOLKS_BACKEND_EDS_USE_ADDRESS_BOOKS");
+
+ this._eds_backend = null;
+ }
+
+ public void test_creating_removing_stores ()
+ {
+ this._main_loop = new GLib.MainLoop (null, false);
+
+ this._test_creating_removing_stores_async.begin ();
+
+ var timer_id = Timeout.add_seconds (20, () =>
+ {
+ this._main_loop.quit ();
+ assert_not_reached ();
+ });
+
+ this._main_loop.run ();
+
+ assert (this._store_removed.size > 0);
+ foreach (bool removed in this._store_removed.values)
+ {
+ assert (removed == true);
+ }
+
+ GLib.Source.remove (timer_id);
+ this._aggregator = null;
+ this._main_loop = null;
+ }
+
+ private async void _test_creating_removing_stores_async ()
+ {
+ yield this._backend_store.prepare ();
+ this._aggregator = new IndividualAggregator ();
+ try
+ {
+ yield this._backend_store.load_backends ();
+
+ var backend = this._backend_store.enabled_backends.get ("eds");
+ assert (backend != null);
+
+ yield this._aggregator.prepare ();
+ assert (this._aggregator.is_prepared);
+ backend.persona_store_removed.connect (this._store_removed_cb);
+ backend.persona_store_added.connect (this._store_added_cb);
+
+ var pstore = "test1";
+ this._store_removed[pstore] = false;
+ this._store_added[pstore] = false;
+
+ debug ("Creating addressbook test1");
+ yield Edsf.PersonaStore.create_address_book (pstore);
+
+ pstore = "test2";
+ this._store_removed[pstore] = false;
+ this._store_added[pstore] = false;
+
+ debug ("Creating addressbook test2");
+ yield Edsf.PersonaStore.create_address_book (pstore);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Error when calling prepare: %s\n", e.message);
+ }
+ }
+
+ private void _store_removed_cb (
+ PersonaStore store)
+ {
+ assert (store != null);
+ debug ("store removed %s", store.id);
+ this._store_removed[store.id] = true;
+
+ int removed_count = 0;
+
+ foreach (bool removed in this._store_removed.values)
+ {
+ if (removed)
+ {
+ ++removed_count;
+ }
+ }
+
+ debug ("removed_count is %d, expected size is %d\n", removed_count,
+ this._store_removed.size);
+ if (removed_count == this._store_removed.size)
+ {
+ this._main_loop.quit ();
+ }
+ }
+
+ private void _store_added_cb (PersonaStore store)
+ {
+ debug ("store added %s", store.id);
+ this._store_added[store.id] = true;
+
+ var backend = this._backend_store.enabled_backends.get ("eds");
+ assert (backend != null);
+
+ debug ("removing store %s", store.id);
+ Edsf.PersonaStore.remove_address_book.begin ((Edsf.PersonaStore)store);
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ TestSuite root = TestSuite.get_root ();
+ root.add_suite (new CreateRemoveStoresTests ().get_suite ());
+
+ Test.run ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]