[folks] e-d-s: test case for changing primary store



commit 9ec53e830cf1ff12681b58f068a08cec6511dd8d
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date:   Thu Sep 1 19:29:06 2011 +0100

    e-d-s: test case for changing primary store

 tests/eds/Makefile.am               |    6 ++
 tests/eds/change-primary-store.vala |  144 +++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+), 0 deletions(-)
---
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 287dca0..a0ee578 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -71,6 +71,7 @@ noinst_PROGRAMS = \
 	set-properties-race \
 	set-birthday \
 	set-roles \
+	change-primary-store \
 	$(NULL)
 
 RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-eds.sh
@@ -201,6 +202,10 @@ set_roles_SOURCES = \
 	set-roles.vala \
 	$(NULL)
 
+change_primary_store_SOURCES = \
+	change-primary-store.vala \
+	$(NULL)
+
 CLEANFILES = \
         *.pid \
         *.address \
@@ -237,6 +242,7 @@ MAINTAINERCLEANFILES = \
 	set_urls_vala.stamp \
 	set_birthday_vala.stamp \
 	set_roles_vala.stamp \
+	change_primary_store_vala.stamp \
         $(NULL)
 
 EXTRA_DIST = \
diff --git a/tests/eds/change-primary-store.vala b/tests/eds/change-primary-store.vala
new file mode 100644
index 0000000..44f7d37
--- /dev/null
+++ b/tests/eds/change-primary-store.vala
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2011 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: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *
+ */
+
+using Folks;
+using Gee;
+
+public class ChangePrimaryStoreTests : Folks.TestCase
+{
+  private GLib.MainLoop _main_loop;
+  private EdsTest.Backend _eds_backend;
+  private EdsTest.Backend _eds_backend_other;
+  private IndividualAggregator _aggregator;
+  private Folks.PersonaStore _pstore1;
+  private Folks.PersonaStore _pstore2;
+  private bool _new_primary_store_found;
+
+  public ChangePrimaryStoreTests ()
+    {
+      base ("ChangePrimaryStoreTests");
+
+      this._eds_backend = new EdsTest.Backend ();
+      this._eds_backend.address_book_uri = "system";
+      this._eds_backend_other = new EdsTest.Backend ();
+      this._eds_backend_other.address_book_uri = "other";
+
+      this.add_test ("test primary store changes in the IndividualAggregator",
+          this.test_change_primary_store);
+    }
+
+  public override void set_up ()
+    {
+      Environment.unset_variable ("FOLKS_PRIMARY_STORE");
+      this._eds_backend.set_up (true);
+      this._eds_backend_other.set_up ();
+    }
+
+  public override void tear_down ()
+    {
+      this._eds_backend.tear_down ();
+      this._eds_backend_other.tear_down ();
+    }
+
+  public void test_change_primary_store ()
+    {
+      this._main_loop = new GLib.MainLoop (null, false);
+      this._new_primary_store_found = false;
+
+      this._test_change_primary_store ();
+
+      var timer_id = Timeout.add_seconds (8, () =>
+        {
+          this._main_loop.quit ();
+          assert_not_reached ();
+        });
+
+      this._main_loop.run ();
+
+      assert (this._new_primary_store_found);
+
+      GLib.Source.remove (timer_id);
+      this._aggregator = null;
+      this._main_loop = null;
+    }
+
+  private async void _test_change_primary_store ()
+    {
+      var store = BackendStore.dup ();
+      yield store.prepare ();
+      this._aggregator = new IndividualAggregator ();
+      try
+        {
+          yield this._aggregator.prepare ();
+
+          this._pstore1 = this._get_persona_store (store, "system");
+          this._pstore2 = this._get_persona_store (store, "other");
+
+          assert (this._pstore1 != null);
+          assert (this._pstore2 != null);
+
+          assert (this._aggregator.primary_store == this._pstore1);
+
+          this._aggregator.notify["primary-store"].connect (
+              this._primary_store_cb);
+
+          this._eds_backend_other.set_as_default ();
+        }
+      catch (GLib.Error e)
+        {
+          GLib.warning ("Error when calling prepare: %s\n", e.message);
+        }
+    }
+
+  private PersonaStore? _get_persona_store (BackendStore store, string store_id)
+    {
+      PersonaStore? pstore = null;
+      foreach (var backend in store.enabled_backends.values)
+        {
+          pstore = backend.persona_stores.get (store_id);
+          if (pstore != null)
+            break;
+        }
+      return pstore;
+    }
+
+  private void _primary_store_cb (Object ia_obj, ParamSpec ps)
+    {
+      IndividualAggregator ia = (IndividualAggregator) ia_obj;
+
+      if (ia.primary_store == this._pstore2)
+        {
+          this._new_primary_store_found = true;
+          this._main_loop.quit ();
+        }
+    }
+}
+
+public int main (string[] args)
+{
+  Test.init (ref args);
+
+  TestSuite root = TestSuite.get_root ();
+  root.add_suite (new ChangePrimaryStoreTests ().get_suite ());
+
+  Test.run ();
+
+  return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]