[folks] tests: Add test for primary-store setting changes
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] tests: Add test for primary-store setting changes
- Date: Fri, 12 Sep 2014 15:23:57 +0000 (UTC)
commit 5f33f801cf3ce4ccb8ca4905125f1891f5a05bbf
Author: Erick PĂ©rez Castellanos <erick red gmail com>
Date: Wed Sep 10 09:52:58 2014 -0400
tests: Add test for primary-store setting changes
https://bugzilla.gnome.org/show_bug.cgi?id=731470
tests/folks/Makefile.am | 9 ++
tests/folks/primary-store-changes.vala | 136 ++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+), 0 deletions(-)
---
diff --git a/tests/folks/Makefile.am b/tests/folks/Makefile.am
index 9fda574..46f100b 100644
--- a/tests/folks/Makefile.am
+++ b/tests/folks/Makefile.am
@@ -11,10 +11,12 @@ AM_VALAFLAGS = \
--vapidir=$(abs_top_builddir)/tests/lib/telepathy \
--vapidir=$(abs_top_srcdir)/tests/lib/telepathy/contactlist/ \
--vapidir=$(abs_top_builddir)/tests/lib/telepathy/contactlist/ \
+ --vapidir=$(abs_top_builddir)/tests/lib/dummy \
--pkg folks-generics \
--pkg kf-test \
--pkg tpf-test \
--pkg tp-test-contactlist \
+ --pkg dummy-test \
$(NULL)
AM_CPPFLAGS = \
@@ -23,6 +25,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/tests/lib/key-file \
-I$(top_srcdir)/tests/lib/telepathy \
-I$(top_srcdir)/tests/lib/telepathy/contactlist \
+ -I$(top_srcdir)/tests/lib/dummy \
$(NULL)
AM_CFLAGS = \
@@ -36,6 +39,7 @@ LDADD = \
$(top_builddir)/tests/lib/telepathy/libtpf-test.la \
$(top_builddir)/tests/lib/telepathy/contactlist/libtp-test-contactlist.la \
$(TP_GLIB_LIBS) \
+ $(top_builddir)/tests/lib/dummy/libdummy-test.la \
$(NULL)
# in order from least to most complex
@@ -44,6 +48,7 @@ noinst_PROGRAMS = \
abstract-field-details \
async-locking \
utils \
+ primary-store-changes \
backend-loading \
aggregation \
standalone-individuals \
@@ -56,6 +61,10 @@ noinst_PROGRAMS = \
TESTS = $(noinst_PROGRAMS)
+primary_store_changes_SOURCES = \
+ primary-store-changes.vala \
+ $(NULL)
+
backend_loading_SOURCES = \
backend-loading.vala \
$(NULL)
diff --git a/tests/folks/primary-store-changes.vala b/tests/folks/primary-store-changes.vala
new file mode 100644
index 0000000..321424a
--- /dev/null
+++ b/tests/folks/primary-store-changes.vala
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2013 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: Philip Withnall <philip withnall collabora co uk>
+ */
+
+using Gee;
+using Folks;
+
+public class PrimaryStoreChangesTests : DummyTest.TestCase
+{
+ private GLib.MainLoop _main_loop;
+ private Settings _settings;
+
+ public FolksDummy.PersonaStore second_persona_store;
+
+ public PrimaryStoreChangesTests ()
+ {
+ base ("PrimaryStoreChangesTests");
+
+ Environment.unset_variable ("FOLKS_PRIMARY_STORE");
+
+ /* Set up the tests */
+ this.add_test ("change primary-store setting",
+ this.test_change_primary_store_setting);
+ }
+
+ public override void set_up ()
+ {
+ base.set_up ();
+
+ this.configure_second_persona_store ();
+ this.dummy_persona_store.update_trust_level (PersonaStoreTrust.FULL);
+ }
+
+ public override void tear_down ()
+ {
+ /* Release setting to avoid test failing on tear_down */
+ var key_changed = this._settings.set_string ("primary-store",
+ "dummy:dummy-store");
+
+ var persona_stores = new HashSet<PersonaStore> ();
+ persona_stores.add (this.second_persona_store);
+ this.dummy_backend.unregister_persona_stores (persona_stores);
+
+ this.second_persona_store = null;
+
+ base.tear_down ();
+ }
+
+ public void configure_second_persona_store ()
+ {
+ string[] writable_properties =
+ {
+ Folks.PersonaStore.detail_key (PersonaDetail.EMAIL_ADDRESSES),
+ Folks.PersonaStore.detail_key (PersonaDetail.PHONE_NUMBERS),
+ null
+ };
+
+ /* Create a new persona store. */
+ this.second_persona_store =
+ new FolksDummy.PersonaStore ("dummy-store-1", "Dummy personas I",
+ writable_properties);
+ this.second_persona_store.persona_type = typeof (FolksDummy.FullPersona);
+
+ /* Register it with the backend. */
+ var persona_stores = new HashSet<PersonaStore> ();
+ persona_stores.add (this.second_persona_store);
+ this.dummy_backend.register_persona_stores (persona_stores);
+ }
+
+ /* Test that when manually changing ::primary-store gsetting key, the
+ IndividualAgreggator instance gets notified */
+ public void test_change_primary_store_setting ()
+ {
+ this._main_loop = new GLib.MainLoop (null, false);
+ test_change_primary_store_setting_async.begin ();
+ TestUtils.loop_run_with_timeout (this._main_loop);
+ }
+
+ private async void test_change_primary_store_setting_async ()
+ {
+ this._settings = new Settings ("org.freedesktop.folks");
+ var key_set = this._settings.set_string ("primary-store", "dummy:dummy-store");
+ assert (key_set == true);
+
+ var aggregator = IndividualAggregator.dup ();
+
+ try
+ {
+ yield aggregator.prepare ();
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Error when calling prepare: %s\n", e.message);
+ }
+
+ /* Initially */
+ assert (aggregator.primary_store.id == "dummy-store");
+
+ /* Change the setting value */
+ var key_changed = this._settings.set_string ("primary-store",
+ "dummy:dummy-store-1");
+ assert (key_changed == true);
+
+ /* Checking propagation */
+ assert (aggregator.primary_store.id == "dummy-store-1");
+
+ this._main_loop.quit ();
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ var tests = new PrimaryStoreChangesTests ();
+ tests.register ();
+ Test.run ();
+ tests.final_tear_down ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]