use IndividualAggregator.dup () in tests and tools
[platform/upstream/folks.git] / tests / tracker / set-emails.vala
index 28bf8d3..b7e1dad 100644 (file)
@@ -23,10 +23,9 @@ using TrackerTest;
 using Folks;
 using Gee;
 
-public class SetEmailsTests : Folks.TestCase
+public class SetEmailsTests : TrackerTest.TestCase
 {
   private GLib.MainLoop _main_loop;
-  private TrackerTest.Backend _tracker_backend;
   private IndividualAggregator _aggregator;
   private string _persona_fullname;
   private string _email_1;
@@ -38,19 +37,9 @@ public class SetEmailsTests : Folks.TestCase
     {
       base ("SetEmailsTests");
 
-      this._tracker_backend = new TrackerTest.Backend ();
-
       this.add_test ("test setting emails ", this.test_set_emails);
     }
 
-  public override void set_up ()
-    {
-    }
-
-  public override void tear_down ()
-    {
-    }
-
   public void test_set_emails ()
     {
       this._main_loop = new GLib.MainLoop (null, false);
@@ -60,35 +49,27 @@ public class SetEmailsTests : Folks.TestCase
       this._email_2 = "email-2@example.org";
 
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
-      this._tracker_backend.add_contact (c1);
+      ((!) this.tracker_backend).add_contact (c1);
 
-      this._tracker_backend.set_up ();
+      ((!) this.tracker_backend).set_up ();
 
       this._email_1_found = false;
       this._email_2_found = false;
 
-      this._test_set_emails_async ();
+      this._test_set_emails_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._email_1_found);
       assert (this._email_2_found);
-
-     this._tracker_backend.tear_down ();
     }
 
   private async void _test_set_emails_async ()
     {
       var store = BackendStore.dup ();
       yield store.prepare ();
-      this._aggregator = new IndividualAggregator ();
-      this._aggregator.individuals_changed.connect
+      this._aggregator = IndividualAggregator.dup ();
+      this._aggregator.individuals_changed_detailed.connect
           (this._individuals_changed_cb);
       try
         {
@@ -100,23 +81,26 @@ public class SetEmailsTests : Folks.TestCase
         }
     }
 
- private void _individuals_changed_cb
-      (GLib.List<Individual>? added,
-       GLib.List<Individual>? removed,
-       string? message,
-       Persona? actor,
-       GroupDetails.ChangeReason reason)
+  private void _individuals_changed_cb (
+       MultiMap<Individual?, Individual?> changes)
     {
-      foreach (unowned Individual i in added)
+      var added = changes.get_values ();
+      var removed = changes.get_keys ();
+
+      foreach (var i in added)
         {
+          assert (i != null);
+
           if (i.full_name == this._persona_fullname)
             {
               i.notify["email-addresses"].connect (this._notify_emails_cb);
 
-              var emails = new HashSet<FieldDetails> ();
-              var p1 = new FieldDetails (this._email_1);
+              var emails = new HashSet<EmailFieldDetails> (
+                  AbstractFieldDetails<string>.hash_static,
+                  AbstractFieldDetails<string>.equal_static);
+              var p1 = new EmailFieldDetails (this._email_1);
               emails.add (p1);
-              var p2 = new FieldDetails (this._email_2);
+              var p2 = new EmailFieldDetails (this._email_2);
               emails.add (p2);
 
               foreach (var p in i.personas)
@@ -126,7 +110,12 @@ public class SetEmailsTests : Folks.TestCase
             }
         }
 
-      assert (removed == null);
+      assert (removed.size == 1);
+
+      foreach (var i in removed)
+        {
+          assert (i == null);
+        }
     }
 
   private void _notify_emails_cb (Object individual_obj, ParamSpec ps)
@@ -154,10 +143,10 @@ public int main (string[] args)
 {
   Test.init (ref args);
 
-  TestSuite root = TestSuite.get_root ();
-  root.add_suite (new SetEmailsTests ().get_suite ());
-
+  var tests = new SetEmailsTests ();
+  tests.register ();
   Test.run ();
+  tests.final_tear_down ();
 
   return 0;
 }