[folks] add unit test for bgo#705289
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] add unit test for bgo#705289
- Date: Fri, 2 Aug 2013 11:06:59 +0000 (UTC)
commit 1b7e8d83bb7488aac7bcf2d59df3a7b35f316ae2
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Thu Aug 1 15:45:53 2013 +0200
add unit test for bgo#705289
https://bugzilla.gnome.org/show_bug.cgi?id=705289
Change-Id: Ief7bef8651ae1df8b2a927ae22fd5fb162e43466
tests/eds/Makefile.am | 5 +
tests/eds/double-aggregator.vala | 202 ++++++++++++++++++++++++++++++++++++++
2 files changed, 207 insertions(+), 0 deletions(-)
---
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 08f9275..1c45cb6 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -69,6 +69,7 @@ TESTS = \
set-phones \
set-postal-addresses \
link-personas \
+ double-aggregator \
set-notes \
add-contacts-stress-test \
set-gender \
@@ -247,6 +248,10 @@ helper_prepare_aggregator_SOURCES = \
helper-prepare-aggregator.vala \
$(NULL)
+double_aggregator_SOURCES = \
+ double-aggregator.vala \
+ $(NULL)
+
CLEANFILES = \
*.pid \
*.address \
diff --git a/tests/eds/double-aggregator.vala b/tests/eds/double-aggregator.vala
new file mode 100644
index 0000000..fa68a9f
--- /dev/null
+++ b/tests/eds/double-aggregator.vala
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * 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: Guillaume Desmottes <guillaume desmottes collabora co uk>
+ *
+ */
+
+using EdsTest;
+using Folks;
+using Gee;
+
+public class DoubleAggregatorTests : EdsTest.TestCase
+{
+ private IndividualAggregator _aggregator;
+ private IndividualAggregator _aggregator2;
+ private GLib.MainLoop _main_loop;
+ private int _test_num = -1;
+
+ public DoubleAggregatorTests ()
+ {
+ base ("DoubleAggregator");
+
+ this.add_test ("unlink double aggregator", this.test_unlink);
+ this.add_test ("remove double aggregator", this.test_remove);
+ }
+
+ public override void set_up ()
+ {
+ base.set_up ();
+
+ this._main_loop = new GLib.MainLoop (null, false);
+ this._aggregator = new IndividualAggregator ();
+ }
+
+ public override void create_backend ()
+ {
+ /* Create a new backend (by name) each set up to guarantee we don't
+ * inherit state from the last test.
+ * FIXME: bgo#690830 */
+ this._test_num++;
+ this.eds_backend = new EdsTest.Backend ();
+ this.eds_backend.set_up (false, @"test$_test_num");
+ }
+
+ public override void tear_down ()
+ {
+ this._aggregator = null;
+ this._aggregator2 = null;
+ this._main_loop = null;
+
+ base.tear_down ();
+ }
+
+ void test_unlink ()
+ {
+ this._prepare_test ();
+
+ this._unlink_individuals ();
+ TestUtils.loop_run_with_timeout (this._main_loop);
+ }
+
+ void test_remove ()
+ {
+ this._prepare_test ();
+
+ this._remove_individual ();
+ TestUtils.loop_run_with_timeout (this._main_loop);
+ }
+
+ void _prepare_test ()
+ {
+ // ADD 2 EDS contacts
+ Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
+ var v = Value (typeof (string));
+ v.set_string ("Badger");
+ c1.set ("full_name", (owned) v);
+ this.eds_backend.add_contact (c1);
+
+ Gee.HashMap<string, Value?> c2 = new Gee.HashMap<string, Value?> ();
+ v = Value (typeof (string));
+ v.set_string ("Mushroom");
+ c2.set ("full_name", (owned) v);
+ this.eds_backend.add_contact (c2);
+
+ this._do_test_async.begin ();
+ TestUtils.loop_run_with_timeout (this._main_loop);
+ }
+
+ private async void _prepare_aggregator (IndividualAggregator aggregator)
+ {
+ try
+ {
+ yield aggregator.prepare ();
+ }
+ catch (GLib.Error e)
+ {
+ GLib.error ("Error when calling prepare: %s\n", e.message);
+ }
+ }
+
+ private async void _do_test_async ()
+ {
+ yield this.eds_backend.commit_contacts_to_addressbook ();
+
+ this._aggregator.notify["is-quiescent"].connect (this._link_individuals);
+ this._prepare_aggregator (this._aggregator);
+ }
+
+ private async void _link_individuals ()
+ {
+ /* Link both individuals */
+ assert (this._aggregator.individuals.size == 2);
+
+ var personas = new HashSet<Persona> ();
+
+ foreach (var individual in this._aggregator.individuals.values)
+ foreach (var persona in individual.personas)
+ personas.add (persona);
+
+ try
+ {
+ yield this._aggregator.link_personas (personas);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.error ("link_personas: %s\n", e.message);
+ }
+
+ /* Individuals have been linked together */
+ assert (this._aggregator.individuals.size == 1);
+
+ this._aggregator2 = new IndividualAggregator ();
+ this._aggregator2.notify["is-quiescent"].connect (this._aggregator2_is_quiescent);
+ this._prepare_aggregator (this._aggregator2);
+ }
+
+ private void _aggregator2_is_quiescent ()
+ {
+ this._main_loop.quit ();
+ }
+
+ private async void _unlink_individuals ()
+ {
+ assert (this._aggregator.individuals.size == 1);
+
+ var individuals = this._aggregator.individuals.values.to_array ();
+
+ try
+ {
+ yield this._aggregator.unlink_individual (individuals[0]);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.error ("unlink_individual: %s\n", e.message);
+ }
+
+ this._main_loop.quit ();
+ }
+
+ private async void _remove_individual ()
+ {
+ assert (this._aggregator.individuals.size == 1);
+
+ var individuals = this._aggregator.individuals.values.to_array ();
+
+ try
+ {
+ yield this._aggregator.remove_individual (individuals[0]);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.error ("remove_individual: %s\n", e.message);
+ }
+
+ this._main_loop.quit ();
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ var tests = new DoubleAggregatorTests ();
+ tests.register ();
+ Test.run ();
+ tests.final_tear_down ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]