[folks] Make Folks.Utils public and add Gee structure equality checking.



commit b5c35cc3dbd331367fa67ff8846e0ea229391789
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Wed Jul 20 11:29:57 2011 -0700

    Make Folks.Utils public and add Gee structure equality checking.
    
    Helps: bgo#655019 - Don't notify twice for nickname changes

 NEWS                    |    1 +
 folks/utils.vala        |   44 +++++++++++++++++++++++++-
 tests/folks/Makefile.am |    6 +++
 tests/folks/utils.vala  |   78 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 127 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index ea2f598..dcc5f8c 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,7 @@ API changes:
 * Add a Persona.writeable_properties property and implement it in all the
   Persona subclasses
 * Make BirthdayDetails.calendar_event_id nullable
+* Make Folks.Utils public and add Gee structure equality functions
 
 Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
 =========================================================
diff --git a/folks/utils.vala b/folks/utils.vala
index a4b5a66..5f75765 100644
--- a/folks/utils.vala
+++ b/folks/utils.vala
@@ -16,13 +16,53 @@
  *
  * Authors:
  *       Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *       Travis Reitter <travis reitter collabora co uk>
  */
 
+using Gee;
 
-internal class Folks.Utils : Object
+public class Folks.Utils : Object
 {
   internal static bool _str_equal_safe (string a, string b)
     {
       return (a != "" && b != "" && a.down () == b.down ());
     }
-}
\ No newline at end of file
+
+  public static bool multi_map_str_str_equal (
+      MultiMap<string, string> a,
+      MultiMap<string, string> b)
+    {
+      if (a == b)
+        return true;
+
+      if (a.size == b.size)
+        {
+          foreach (var key in a.get_keys ())
+            {
+              if (b.contains (key))
+                {
+                  var a_values = a.get (key);
+                  var b_values = b.get (key);
+                  if (a_values.size != b_values.size)
+                    return false;
+
+                  foreach (var a_value in a_values)
+                    {
+                      if (!b_values.contains (a_value))
+                        return false;
+                    }
+                }
+              else
+                {
+                  return false;
+                }
+            }
+        }
+      else
+        {
+          return false;
+        }
+
+      return true;
+    }
+}
diff --git a/tests/folks/Makefile.am b/tests/folks/Makefile.am
index bc97b94..2bbaca8 100644
--- a/tests/folks/Makefile.am
+++ b/tests/folks/Makefile.am
@@ -40,6 +40,7 @@ AM_VALAFLAGS = \
 # in order from least to most complex
 noinst_PROGRAMS = \
 	field-details \
+	utils \
 	backend-loading \
 	aggregation \
 	$(NULL)
@@ -68,6 +69,10 @@ field_details_SOURCES = \
 	field-details.vala \
 	$(NULL)
 
+utils_SOURCES = \
+	utils.vala \
+	$(NULL)
+
 CLEANFILES = \
         *.pid \
         *.address \
@@ -79,6 +84,7 @@ MAINTAINERCLEANFILES = \
         backend_loading_vala.stamp \
         aggregation_vala.stamp \
         field_details_vala.stamp \
+        utils_vala.stamp \
         $(NULL)
 
 EXTRA_DIST = \
diff --git a/tests/folks/utils.vala b/tests/folks/utils.vala
new file mode 100644
index 0000000..506d977
--- /dev/null
+++ b/tests/folks/utils.vala
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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: Travis Reitter <travis reitter collabora co uk>
+ */
+
+using Gee;
+using Folks;
+
+public class UtilsTests : Folks.TestCase
+{
+  public UtilsTests ()
+    {
+      base ("Utils");
+      this.add_test ("MultiMap equality", this.test_multi_map_equality);
+    }
+
+  public override void set_up ()
+    {
+    }
+
+  public override void tear_down ()
+    {
+    }
+
+  public void test_multi_map_equality ()
+    {
+      var a_1 = new HashMultiMap<string, string> ();
+      var a_2 = new HashMultiMap<string, string> ();
+      var a_1_subset = new HashMultiMap<string, string> ();
+      var b_1 = new HashMultiMap<string, string> ();
+
+      a_1.set ("foo", "bar");
+      a_1.set ("foo", "qux");
+      a_1.set ("baz", "quux");
+
+      a_2.set ("foo", "bar");
+      a_2.set ("foo", "qux");
+      a_2.set ("baz", "quux");
+
+      a_1_subset.set ("foo", "bar");
+      a_1_subset.set ("foo", "qux");
+
+      b_1.set ("not", "at");
+      b_1.set ("all", "related");
+
+      assert (Utils.multi_map_str_str_equal (a_1, a_1));
+      assert (Utils.multi_map_str_str_equal (a_1, a_2));
+      assert (Utils.multi_map_str_str_equal (a_2, a_1));
+      assert (!Utils.multi_map_str_str_equal (a_1, a_1_subset));
+      assert (!Utils.multi_map_str_str_equal (a_1, b_1));
+    }
+}
+
+public int main (string[] args)
+{
+  Test.init (ref args);
+
+  TestSuite root = TestSuite.get_root ();
+  root.add_suite (new UtilsTests ().get_suite ());
+
+  Test.run ();
+
+  return 0;
+}



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