[folks] tests: Add a test for setting an EDS extended info field



commit 1c6266fe3409b6076bdf557275c91f2f4417294e
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Mar 19 11:05:12 2015 +0000

    tests: Add a test for setting an EDS extended info field
    
    This is a unit test for commit e397d869d8f84641825252657aa34ae8487dd526.

 tests/eds/extended-info.vala |   88 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/tests/eds/extended-info.vala b/tests/eds/extended-info.vala
index 210e540..77219a9 100644
--- a/tests/eds/extended-info.vala
+++ b/tests/eds/extended-info.vala
@@ -35,6 +35,7 @@ public class ExtendedInfoTests : EdsTest.TestCase
       base ("ExtendedInfo");
 
       this.add_test ("extended info interface", this.test_extended_info);
+      this.add_test ("add extended info", this.test_add_extended_info);
     }
 
   public void test_extended_info ()
@@ -120,6 +121,93 @@ public class ExtendedInfoTests : EdsTest.TestCase
           this._main_loop.quit ();
         }
     }
+
+  /* Test that adding extended info to an existing contact works, and that the
+   * changes are notified as the change_extended_info() call returns. */
+  public void test_add_extended_info ()
+    {
+      this._main_loop = new GLib.MainLoop (null, false);
+      Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
+      Value? v;
+
+      this.eds_backend.reset ();
+
+      v = Value (typeof (string));
+      v.set_string (ExtendedInfoTests._FULL_NAME);
+      c1.set ("full_name", (owned) v);
+
+      this.eds_backend.add_contact (c1);
+
+      this._test_add_extended_info_async.begin ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
+
+      this._aggregator = null;
+      this._main_loop = null;
+    }
+
+  private async void _test_add_extended_info_async ()
+    {
+      yield this.eds_backend.commit_contacts_to_addressbook ();
+
+      this._aggregator = IndividualAggregator.dup ();
+      this._aggregator.individuals_changed_detailed.connect
+          (this._add_individuals_changed_cb);
+      try
+        {
+          yield this._aggregator.prepare ();
+        }
+      catch (GLib.Error e)
+        {
+          GLib.error ("Error when calling prepare: %s", e.message);
+        }
+    }
+
+  private void _add_individuals_changed_cb (
+       MultiMap<Individual?, Individual?> changes)
+    {
+      var added = changes.get_values ();
+      var removed = changes.get_keys ();
+
+      foreach (var i in added)
+        {
+          assert (i != null);
+
+          if (i.full_name != ExtendedInfoTests._FULL_NAME)
+              continue;
+
+          GLib.debug ("Adding an extended field");
+
+          /* Add an extended field and check it’s immediately usable. */
+          i.change_extended_field.begin ("X-FOLKS-EXTENDED-INFO",
+              new ExtendedFieldDetails ("folks-test", null), (o, r) =>
+            {
+              try
+                {
+                  i.change_extended_field.end (r);
+
+                  ExtendedFieldDetails? efd =
+                      i.get_extended_field ("X-FOLKS-EXTENDED-INFO");
+
+                  assert (efd != null);
+                  assert (efd.value == "folks-test");
+
+                  /* Success. */
+                  this._main_loop.quit ();
+                }
+              catch (GLib.Error e)
+                {
+                  GLib.error ("Failed to change extended field: %s", e.message);
+                }
+            });
+        }
+
+      assert (removed.size == 1);
+
+      foreach (var i in removed)
+        {
+          assert (i == null);
+        }
+    }
 }
 
 public int main (string[] args)


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