[folks/wip/arbitrary-field-interface] Add ExtendedInfo interface EDS test



commit a57ea700a40407234b2bc5be2c6e47b5fcdbcaac
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jul 5 14:10:38 2013 +0200

    Add ExtendedInfo interface EDS test

 backends/eds/lib/edsf-persona-store.vala |    3 +
 tests/eds/Makefile.am                    |    5 ++
 tests/eds/extended-info.vala             |  111 ++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index ef98fb0..a1b3ddd 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -886,6 +886,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
                     }
                 }
 
+              /* Add extended_info field */
+              prop_set.add ((!) Folks.PersonaStore.detail_key (PersonaDetail.EXTENDED_INFO));
+
               /* Convert the property set to an array. We can't use .to_array()
                * here because it fails to null-terminate the array. Sigh. */
               this._always_writeable_properties = new string[prop_set.size];
diff --git a/tests/eds/Makefile.am b/tests/eds/Makefile.am
index 4316b90..3441440 100644
--- a/tests/eds/Makefile.am
+++ b/tests/eds/Makefile.am
@@ -83,6 +83,7 @@ TESTS = \
        enable-disable-stores \
        set-is-favourite \
        perf \
+       extended-info \
        $(NULL)
 
 RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus-eds.sh
@@ -235,6 +236,10 @@ perf_SOURCES = \
        perf.vala \
        $(NULL)
 
+extended_info_SOURCES = \
+       extended-info.vala
+       $(NULL)
+
 helper_create_many_contacts_SOURCES = \
        helper-create-many-contacts.vala \
        $(NULL)
diff --git a/tests/eds/extended-info.vala b/tests/eds/extended-info.vala
index 126675e..3f880c0 100644
--- a/tests/eds/extended-info.vala
+++ b/tests/eds/extended-info.vala
@@ -18,3 +18,114 @@
  *
  */
 
+using EdsTest;
+using Folks;
+using Gee;
+
+public class ExtendedInfoTests : EdsTest.TestCase
+{
+  private GLib.MainLoop _main_loop;
+  private IndividualAggregator _aggregator;
+  private string _full_name;
+  private bool _found_field_1;
+  private bool _found_field_2;
+
+  public ExtendedInfoTests ()
+    {
+      base ("ExtendedInfo");
+
+      this.add_test ("extended info interface", this.test_extended_info);
+    }
+
+  public void test_extended_info ()
+    {
+      this._main_loop = new GLib.MainLoop (null, false);
+      this._full_name = "persona #1";
+      Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
+      Value? v;
+
+      this.eds_backend.reset ();
+
+      v = Value (typeof (string));
+      v.set_string (this._full_name);
+      c1.set ("full_name", (owned) v);
+      v = Value (typeof (string));
+         v.set_string ("X-FIELD-1=value1,X-FIELD-2=value2");
+      c1.set ("extended_info", (owned) v);
+
+      this.eds_backend.add_contact (c1);
+
+      this._found_field_1 = false;
+      this._found_field_2 = false;
+
+         this._test_extended_info_async.begin ();
+
+         TestUtils.loop_run_with_timeout (this._main_loop);
+
+      assert (this._found_field_1 == true);
+      assert (this._found_field_2 == true);
+    }
+
+  private async void _test_extended_info_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_cb);
+      try
+        {
+          yield this._aggregator.prepare ();
+        }
+      catch (GLib.Error e)
+        {
+          GLib.warning ("Error when calling prepare: %s\n", e.message);
+        }
+    }
+
+  private void _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);
+
+          string full_name = i.full_name;
+          if (full_name == this._full_name);
+            {
+              if (i.get_extended_field ("X-FIELD-1") != null)
+                this._found_field_1 = true;
+              if (i.get_extended_field ("X-FIELD-2") != null)
+                this._found_field_2 = true;
+                       }
+        }
+
+      assert (removed.size == 1);
+
+      foreach (var i in removed)
+        {
+          assert (i == null);
+        }
+
+         if (this._found_field_1 == true &&
+          this._found_field_2 == true)
+        this._main_loop.quit ();
+       }
+}
+
+public int main (string[] args)
+{
+  Test.init (ref args);
+
+  var tests = new ExtendedInfoTests ();
+  tests.register ();
+  Test.run ();
+  tests.final_tear_down ();
+
+  return 0;
+}
\ No newline at end of file


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