[folks] eds test: ensure basic anti-link removal works
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] eds test: ensure basic anti-link removal works
- Date: Sun, 6 Jan 2013 01:35:55 +0000 (UTC)
commit 9de55174d7a7b4fa9dfbddc60e5490e27542acf0
Author: Travis Reitter <travis reitter collabora co uk>
Date: Thu Jan 3 21:55:19 2013 -0800
eds test: ensure basic anti-link removal works
tests/eds/anti-linking.vala | 184 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 184 insertions(+), 0 deletions(-)
---
diff --git a/tests/eds/anti-linking.vala b/tests/eds/anti-linking.vala
index 74a46fe..30bc909 100644
--- a/tests/eds/anti-linking.vala
+++ b/tests/eds/anti-linking.vala
@@ -29,6 +29,7 @@ public class AntiLinkingTests : Folks.TestCase
private GLib.MainLoop _main_loop;
private bool _found_before_update;
private bool _found_after_update;
+ private bool _found_after_final_update;
/* NOTE: each full name should remain unique */
private const string _full_name_1 = "bernie h. innocenti";
@@ -40,12 +41,14 @@ public class AntiLinkingTests : Folks.TestCase
base ("AntiLinking");
this.add_test ("basic anti-linking", this.test_anti_linking_basic);
+ this.add_test ("anti-link removal", this.test_anti_linking_removal);
}
public override void set_up ()
{
this._found_before_update = false;
this._found_after_update = false;
+ this._found_after_final_update = false;
this._eds_backend = new EdsTest.Backend ();
this._eds_backend.set_up ();
@@ -187,6 +190,187 @@ public class AntiLinkingTests : Folks.TestCase
}
}
}
+
+ /* Confirm that anti-link removal works for two Personas who have a common
+ * linkable property value.
+ *
+ * FIXME: this test should be moved to tests/folks and rebased upon the Dummy
+ * backend once bgo#648811 is fixed.
+ */
+ void test_anti_linking_removal ()
+ {
+ Gee.HashMap<string, Value?> c;
+ this._main_loop = new GLib.MainLoop (null, false);
+ Value? v;
+
+ this._found_before_update = false;
+ this._found_after_update = false;
+
+ this._eds_backend.reset ();
+
+ c = new Gee.HashMap<string, Value?> ();
+ v = Value (typeof (string));
+ v.set_string (_full_name_1);
+ c.set ("full_name", (owned) v);
+ v = Value (typeof (string));
+ v.set_string (_email_1);
+ c.set ("email_1", (owned) v);
+ this._eds_backend.add_contact (c);
+
+ c = new Gee.HashMap<string, Value?> ();
+ v = Value (typeof (string));
+ v.set_string (_full_name_2);
+ c.set ("full_name", (owned) v);
+ v = Value (typeof (string));
+ /* Intentionally set the same email address so these will be linked */
+ v.set_string (_email_1);
+ c.set ("email_1", (owned) v);
+ this._eds_backend.add_contact (c);
+
+ this._test_anti_linking_removal_async.begin ();
+
+ Timeout.add_seconds (5, () =>
+ {
+ this._main_loop.quit ();
+ stderr.printf ("Personas failed to be anti-linked\n");
+ assert_not_reached ();
+ });
+
+ this._main_loop.run ();
+
+ assert (this._found_before_update);
+ assert (this._found_after_update);
+ assert (this._found_after_final_update);
+ }
+
+ private async void _test_anti_linking_removal_async ()
+ {
+ yield this._eds_backend.commit_contacts_to_addressbook ();
+
+ var store = BackendStore.dup ();
+ yield store.prepare ();
+ this._aggregator = new IndividualAggregator ();
+ this._aggregator.individuals_changed_detailed.connect
+ (this._individuals_changed_anti_linking_removal_cb);
+ try
+ {
+ yield this._aggregator.prepare ();
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Error when calling prepare: %s\n", e.message);
+ }
+ }
+
+ private void _individuals_changed_anti_linking_removal_cb (
+ MultiMap<Individual?, Individual?> changes)
+ {
+ var added = changes.get_values ();
+ var removed = changes.get_values ();
+
+ if (!this._found_before_update)
+ {
+ assert (changes.size == 1);
+ assert (added.size == 1);
+ assert (removed.size == 1);
+
+ foreach (Individual i in added)
+ {
+ assert (i != null);
+ assert (i.personas.size == 2);
+
+ this._found_before_update = true;
+
+ var iter = i.personas.iterator ();
+ iter.next ();
+ var al_1 = iter.get () as AntiLinkable;
+ iter.next ();
+ var al_2 = iter.get () as AntiLinkable;
+
+ var anti_links = new HashSet<Persona> ();
+ anti_links.add (al_2);
+ al_1.add_anti_links.begin (anti_links);
+ }
+ }
+ else if (!this._found_after_update)
+ {
+ /* the first Individual should have been split in two new ones */
+ assert (changes.size == 2);
+ assert (added.size == 2);
+
+ Individual? ind_1 = null;
+ Individual? ind_2 = null;
+
+ foreach (var i in added)
+ {
+ if (i.full_name == _full_name_1)
+ {
+ ind_1 = i;
+ }
+ if (i.full_name == _full_name_2)
+ {
+ ind_2 = i;
+ }
+ }
+
+ assert (ind_1 != null);
+ assert (ind_2 != null);
+
+ this._found_after_update = true;
+
+ Iterator<Persona> iter;
+ iter = ind_1.personas.iterator ();
+ iter.next ();
+ var al_1 = iter.get () as AntiLinkable;
+
+ iter = ind_2.personas.iterator ();
+ iter.next ();
+ var al_2 = iter.get () as AntiLinkable;
+
+ /* revert anti-links (in both directions) */
+ HashSet<Persona> anti_links;
+ anti_links = new HashSet<Persona> ();
+ anti_links.add (al_2);
+ al_1.remove_anti_links.begin (anti_links);
+
+ anti_links = new HashSet<Persona> ();
+ anti_links.add (al_1);
+ al_2.remove_anti_links.begin (anti_links);
+ }
+ else
+ {
+ /* ensure the two Individuals got replaced by a single one */
+ assert (removed.size == 2);
+ var added_unique = new HashSet<Individual> ();
+ added_unique.add_all (added);
+ assert (added_unique.size == 1);
+
+ var found_1 = false;
+ var found_2 = false;
+
+ /* The Personas should have been re-aggregated here */
+ foreach (var i in added)
+ {
+ foreach (var p in i.personas)
+ {
+ if (((NameDetails) p).full_name == _full_name_1)
+ {
+ found_1 = true;
+ }
+ if (((NameDetails) p).full_name == _full_name_2)
+ {
+ found_2 = true;
+ }
+ }
+ }
+
+ if (found_1 && found_2)
+ {
+ this._found_after_final_update = true;
+ this._main_loop.quit ();
+ }
+ }
+ }
}
public int main (string[] args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]