[folks] Tests: Do no hardcode individual sha1



commit 47c63fd926cf1c6a6a0061e57662d3d3df1adc46
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Thu Sep 26 16:06:41 2013 -0400

    Tests: Do no hardcode individual sha1
    
    With telepathy 1.0 the account prefix is going to change, so all
    sha1 will have to be recalculated. It's better to calculate them
    so changing one line is enough to port to tp1.

 tests/folks/aggregation.vala               |   42 ++++++++-----------------
 tests/telepathy/individual-properties.vala |   11 +++++--
 tests/telepathy/individual-retrieval.vala  |   47 +++++++++++++---------------
 3 files changed, 43 insertions(+), 57 deletions(-)
---
diff --git a/tests/folks/aggregation.vala b/tests/folks/aggregation.vala
index 2f9c2d6..22946bb 100644
--- a/tests/folks/aggregation.vala
+++ b/tests/folks/aggregation.vala
@@ -25,6 +25,11 @@ public class AggregationTests : TpfTest.MixedTestCase
 {
   private HashSet<string> _default_personas;
 
+  private static string iid_prefix =
+      "telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:";
+  private string olivier_sha1 = Checksum.compute_for_string (ChecksumType.SHA1,
+      iid_prefix + "olivier example com");
+
   public AggregationTests ()
     {
       base ("Aggregation");
@@ -88,33 +93,13 @@ public class AggregationTests : TpfTest.MixedTestCase
       void* account2_handle = tp_backend.add_account ("protocol",
           "me2 example com", "cm", "account2");
 
-      /* IDs of the individuals we expect to see.
-       * These are externally opaque, but internally are SHA-1 hashes of the
-       * concatenated UIDs of the Personas in the Individual. In these cases,
-       * each default_individual contains two Personas with the same IID.
-       * e.g.
-       *  telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account2:sjoerd example com
-       * and
-       *  telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:sjoerd example com
-       * in a single Individual. */
+      /* IDs of the individuals we expect to see. */
       var default_individuals = new HashSet<string> ();
-
-      /* guillaume example com */
-      default_individuals.add ("6380b17dc511b21a1defd4811f1add97b278f92c");
-      /* sjoerd example com */
-      default_individuals.add ("6b08188cb2ef8cbaca140b277780069b5af8add6");
-      /* travis example com */
-      default_individuals.add ("60c91326018f6a60604f8d260fc24a60a5b8512c");
-      /* olivier example com */
-      default_individuals.add ("0e46c5e74f61908f49550d241f2a1651892a1695");
-      /* christian example com */
-      default_individuals.add ("07b913b8977c04d2f2011e26a46ea3e3dcfe3e3d");
-      /* geraldine example com */
-      default_individuals.add ("f948d4d2af79085ab860f0ef67bf0c201c4602d4");
-      /* helen example com */
-      default_individuals.add ("f34529a442577b840a75271b464e90666c38c464");
-      /* wim example com */
-      default_individuals.add ("467d13f955e62bf30ebf9620fa052aaee2160260");
+      foreach (var id in this._default_personas)
+        {
+          default_individuals.add (Checksum.compute_for_string (
+              ChecksumType.SHA1, iid_prefix + id));
+        }
 
       /* Work on a copy of the set of individuals so we can mangle it. We keep
        * one copy of the set for the individuals_changed signal, and one for
@@ -1106,8 +1091,7 @@ public class AggregationTests : TpfTest.MixedTestCase
             {
               assert (i != null);
 
-              /* olivier example com */
-              if (i.id == "0e46c5e74f61908f49550d241f2a1651892a1695")
+              if (i.id == olivier_sha1)
                 {
                   assert (individual == null);
                   individual = i;
@@ -1196,7 +1180,7 @@ public class AggregationTests : TpfTest.MixedTestCase
                * we have to check for the personas themselves. */
               foreach (var p in i.personas)
                 {
-                  if (p.uid == "telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:olivier 
example com")
+                  if (p.uid == iid_prefix + "olivier example com")
                     {
                       got_tpf = true;
                     }
diff --git a/tests/telepathy/individual-properties.vala b/tests/telepathy/individual-properties.vala
index 45acb62..5351824 100644
--- a/tests/telepathy/individual-properties.vala
+++ b/tests/telepathy/individual-properties.vala
@@ -28,6 +28,11 @@ public class IndividualPropertiesTests : TpfTest.TestCase
 {
   private HashSet<string>? _changes_pending = null;
 
+  private static string iid_prefix =
+      "telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:";
+  private string olivier_sha1 = Checksum.compute_for_string (ChecksumType.SHA1,
+      iid_prefix + "olivier example com");
+
   public IndividualPropertiesTests ()
     {
       base ("IndividualProperties");
@@ -117,7 +122,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
 
               /* Check the Individual containing just
                * Tpf.Persona(olivier example com) */
-              else if (i.id == "0e46c5e74f61908f49550d241f2a1651892a1695")
+              else if (i.id == olivier_sha1)
                 {
                   /* Check properties */
                   assert (i.alias == "Olivier");
@@ -205,7 +210,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
 
               /* We only check one (singleton Individual containing just
                * olivier example com) */
-              if (i.id != "0e46c5e74f61908f49550d241f2a1651892a1695")
+              if (i.id != olivier_sha1)
                 {
                   continue;
                 }
@@ -278,7 +283,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
 
               /* We only check one (singleton Individual containing just
                * olivier example com) */
-              if (i.id != "0e46c5e74f61908f49550d241f2a1651892a1695")
+              if (i.id != olivier_sha1)
                 {
                   continue;
                 }
diff --git a/tests/telepathy/individual-retrieval.vala b/tests/telepathy/individual-retrieval.vala
index 8524240..5908c05 100644
--- a/tests/telepathy/individual-retrieval.vala
+++ b/tests/telepathy/individual-retrieval.vala
@@ -28,37 +28,34 @@ public class IndividualRetrievalTests : TpfTest.TestCase
 {
   private HashSet<string> default_individuals;
 
+  private static string iid_prefix =
+      "telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:";
+
   public IndividualRetrievalTests ()
     {
       base ("IndividualRetrieval");
 
-      /* IDs of the individuals we expect to see.
-       * These are externally opaque, but internally are SHA-1 hashes of the
-       * concatenated UIDs of the Personas in the Individual. In these cases,
-       * each default_individual contains one Persona.
-       * e.g.
-       *  telepathy:/org/freedesktop/Telepathy/Account/cm/protocol/account:me example com
-       * only in each Individual. */
+      /* IDs of the individuals we expect to see. */
       this.default_individuals = new HashSet<string> ();
 
-      /* me example com */
-      default_individuals.add ("48fa372a81026063187255e3f5c184665d2ed7ce");
-      /* travis example com */
-      default_individuals.add ("60c91326018f6a60604f8d260fc24a60a5b8512c");
-      /* guillaume example com */
-      default_individuals.add ("6380b17dc511b21a1defd4811f1add97b278f92c");
-      /* olivier example com */
-      default_individuals.add ("0e46c5e74f61908f49550d241f2a1651892a1695");
-      /* sjoerd example com */
-      default_individuals.add ("6b08188cb2ef8cbaca140b277780069b5af8add6");
-      /* geraldine example com */
-      default_individuals.add ("f948d4d2af79085ab860f0ef67bf0c201c4602d4");
-      /* helen example com */
-      default_individuals.add ("f34529a442577b840a75271b464e90666c38c464");
-      /* wim example com */
-      default_individuals.add ("467d13f955e62bf30ebf9620fa052aaee2160260");
-      /* christian example com */
-      default_individuals.add ("07b913b8977c04d2f2011e26a46ea3e3dcfe3e3d");
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "me example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "travis example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "guillaume example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "olivier example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "sjoerd example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "geraldine example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "helen example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "wim example com"));
+      default_individuals.add (Checksum.compute_for_string (ChecksumType.SHA1,
+          iid_prefix + "christian example com"));
 
       this.add_test ("aggregator", this.test_aggregator);
       this.add_test ("aggregator:add", this.test_aggregator_add);


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