[Telepathy-commits] [telepathy-glib/master] Various tests: use convenient GValue allocators

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Mar 4 08:11:42 PST 2009


---
 tests/dbus/channel-introspect.c |   20 +----
 tests/dbus/cli-group.c          |   16 ++---
 tests/dbus/group-mixin.c        |   32 +++------
 tests/dbus/message-mixin.c      |  154 ++++++++++++++++++++-------------------
 tests/lib/contacts-conn.c       |   31 +++-----
 5 files changed, 109 insertions(+), 144 deletions(-)

diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c
index 39ff283..b947913 100644
--- a/tests/dbus/channel-introspect.c
+++ b/tests/dbus/channel-introspect.c
@@ -114,7 +114,6 @@ main (int argc,
   GError invalidated_for_test = { TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
       "No channel for you!" };
   GHashTable *asv;
-  GValue *value;
 
   g_type_init ();
   tp_debug_set_flags ("all");
@@ -260,25 +259,14 @@ main (int argc,
   asv = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
       (GDestroyNotify) tp_g_value_slice_free);
 
-  value = tp_g_value_slice_new (G_TYPE_STRING);
-  g_value_set_static_string (value, TP_IFACE_CHANNEL_TYPE_TEXT);
   g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".ChannelType"),
-      tp_g_value_slice_dup (value));
-
-  value = tp_g_value_slice_new (G_TYPE_UINT);
-  g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
+      tp_g_value_slice_new_static_string (TP_IFACE_CHANNEL_TYPE_TEXT));
   g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".TargetHandleType"),
-      tp_g_value_slice_dup (value));
-
-  value = tp_g_value_slice_new (G_TYPE_UINT);
-  g_value_set_uint (value, handle);
+      tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT));
   g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".TargetHandle"),
-      tp_g_value_slice_dup (value));
-
-  value = tp_g_value_slice_new (G_TYPE_STRV);
-  g_value_set_static_boxed (value, NULL);
+      tp_g_value_slice_new_uint (handle));
   g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".Interfaces"),
-      tp_g_value_slice_dup (value));
+      tp_g_value_slice_new_static_boxed (G_TYPE_STRV, NULL));
 
   chan = tp_channel_new_from_properties (conn, chan_path, asv, &error);
   MYASSERT_NO_ERROR (error);
diff --git a/tests/dbus/cli-group.c b/tests/dbus/cli-group.c
index 1095643..79aee61 100644
--- a/tests/dbus/cli-group.c
+++ b/tests/dbus/cli-group.c
@@ -339,7 +339,6 @@ check_removed_error_in_invalidated (void)
   TpIntSet *self_handle_singleton = tp_intset_new ();
   GHashTable *details = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
       (GDestroyNotify) tp_g_value_slice_free);
-  GValue *v;
   gboolean invalidated = FALSE;
   GError *error = NULL;
 
@@ -370,17 +369,14 @@ check_removed_error_in_invalidated (void)
 
   test_connection_run_until_dbus_queue_processed (conn);
 
-  v = tp_g_value_slice_new (G_TYPE_UINT);
-  g_value_set_uint (v, REMOVED_REASON);
-  g_hash_table_insert (details, "change-reason", v);
+  g_hash_table_insert (details, "change-reason",
+      tp_g_value_slice_new_uint (REMOVED_REASON));
 
-  v = tp_g_value_slice_new (G_TYPE_STRING);
-  g_value_set_static_string (v, REMOVED_MESSAGE);
-  g_hash_table_insert (details, "message", v);
+  g_hash_table_insert (details, "message",
+      tp_g_value_slice_new_static_string (REMOVED_MESSAGE));
 
-  v = tp_g_value_slice_new (G_TYPE_STRING);
-  g_value_set_static_string (v, REMOVED_ERROR);
-  g_hash_table_insert (details, "error", v);
+  g_hash_table_insert (details, "error",
+      tp_g_value_slice_new_static_string (REMOVED_ERROR));
 
   tp_group_mixin_change_members_detailed ((GObject *) service_chan, NULL,
       self_handle_singleton, NULL, NULL, details);
diff --git a/tests/dbus/group-mixin.c b/tests/dbus/group-mixin.c
index 5bbbfb9..4511bcc 100644
--- a/tests/dbus/group-mixin.c
+++ b/tests/dbus/group-mixin.c
@@ -412,13 +412,10 @@ in_the_desert (void)
     TpIntSet *add = tp_intset_new ();
     GHashTable *details = g_hash_table_new_full (g_str_hash, g_str_equal,
         NULL, (GDestroyNotify) tp_g_value_slice_free);
-    GValue *v;
 
     tp_intset_add (add, camel2);
 
-    v = tp_g_value_slice_new (G_TYPE_UINT);
-    g_value_set_uint (v, camel);
-    g_hash_table_insert (details, "actor", v);
+    g_hash_table_insert (details, "actor", tp_g_value_slice_new_uint (camel));
 
     expect_signals ("", camel, TP_CHANNEL_GROUP_CHANGE_REASON_NONE,
         camel2_added);
@@ -436,33 +433,24 @@ in_the_desert (void)
     TpIntSet *del = tp_intset_new ();
     GHashTable *details = g_hash_table_new_full (g_str_hash, g_str_equal,
         NULL, (GDestroyNotify) tp_g_value_slice_free);
-    GValue *v;
 
     tp_intset_add (del, camel);
 
-    v = tp_g_value_slice_new (G_TYPE_UINT);
-    g_value_set_uint (v, camel2);
-    g_hash_table_insert (details, "actor", v);
+    g_hash_table_insert (details, "actor", tp_g_value_slice_new_uint (camel2));
 
     /* It turns out that spitting was not included in the GroupChangeReason
      * enum.
      */
-    v = tp_g_value_slice_new (G_TYPE_STRING);
-    g_value_set_static_string (v, "le.mac.Spat");
-    g_hash_table_insert (details, "error", v);
-
-    v = tp_g_value_slice_new (G_TYPE_STRING);
-    g_value_set_static_string (v, "fluid");
-    g_hash_table_insert (details, "saliva-consistency", v);
+    g_hash_table_insert (details, "error",
+        tp_g_value_slice_new_static_string ("le.mac.Spat"));
+    g_hash_table_insert (details, "saliva-consistency",
+        tp_g_value_slice_new_static_string ("fluid"));
 
     /* Kicking is the closest we have to this .. unsavory act. */
-    v = tp_g_value_slice_new (G_TYPE_UINT);
-    g_value_set_uint (v, TP_CHANNEL_GROUP_CHANGE_REASON_KICKED);
-    g_hash_table_insert (details, "change-reason", v);
-
-    v = tp_g_value_slice_new (G_TYPE_STRING);
-    g_value_set_static_string (v, "*ptooey*");
-    g_hash_table_insert (details, "message", v);
+    g_hash_table_insert (details, "change-reason",
+        tp_g_value_slice_new_uint (TP_CHANNEL_GROUP_CHANGE_REASON_KICKED));
+    g_hash_table_insert (details, "message",
+        tp_g_value_slice_new_static_string ("*ptooey*"));
 
     /* Check that all the right information was extracted from the dict. */
     expect_signals ("*ptooey*", camel2,
diff --git a/tests/dbus/message-mixin.c b/tests/dbus/message-mixin.c
index e9974b5..91d6a7e 100644
--- a/tests/dbus/message-mixin.c
+++ b/tests/dbus/message-mixin.c
@@ -200,28 +200,6 @@ on_messages_removed (TpChannel *chan,
     }
 }
 
-static GValue *
-slice_new_string (const char *string)
-{
-  GValue *ret = tp_g_value_slice_new (G_TYPE_STRING);
-
-  g_value_set_string (ret, string);
-  return ret;
-}
-
-static GValue *
-slice_new_byte_array (gconstpointer content,
-                      gsize length)
-{
-  GValue *ret = tp_g_value_slice_new (DBUS_TYPE_G_UCHAR_ARRAY);
-  GArray *arr = g_array_sized_new (FALSE, FALSE, 1, length);
-
-  g_array_append_vals (arr, content, length);
-  g_value_set_boxed (ret, arr);
-  g_array_free (arr, TRUE);
-  return ret;
-}
-
 int
 main (int argc,
       char **argv)
@@ -273,22 +251,15 @@ main (int argc,
     {
       GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal,
           NULL, (GDestroyNotify) tp_g_value_slice_free);
-      GValue *value;
 
-      value = tp_g_value_slice_new (G_TYPE_STRING);
-      g_value_set_static_string (value, TP_IFACE_CHANNEL_TYPE_TEXT);
       g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType",
-          value);
+          tp_g_value_slice_new_static_string (TP_IFACE_CHANNEL_TYPE_TEXT));
 
-      value = tp_g_value_slice_new (G_TYPE_UINT);
-      g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
       g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType",
-          value);
+          tp_g_value_slice_new_uint (TP_HANDLE_TYPE_CONTACT));
 
-      value = tp_g_value_slice_new (G_TYPE_UINT);
-      g_value_set_uint (value, handle);
       g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle",
-          value);
+          tp_g_value_slice_new_uint (handle));
 
       tp_cli_connection_interface_requests_run_create_channel (conn, -1,
           request, &chan_path, NULL, &error, NULL);
@@ -525,9 +496,12 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "alternative", slice_new_string ("main"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/html"));
-      g_hash_table_insert (part, "content", slice_new_string (
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("main"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/html"));
+      g_hash_table_insert (part, "content",
+          tp_g_value_slice_new_string (
             "Here is a photo of a cat:<br />"
             "<img src=\"cid:lolcat\" alt=\"lol!\" /><br />"
             "It's in ur regression tests verifying ur designs!"
@@ -536,17 +510,21 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "alternative", slice_new_string ("main"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("main"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
       g_hash_table_insert (part, "content",
-          slice_new_string (EXPECTED_TEXT));
+          tp_g_value_slice_new_string (EXPECTED_TEXT));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "identifier", slice_new_string ("lolcat"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("image/jpeg"));
-      g_hash_table_insert (part, "content", slice_new_byte_array (
+      g_hash_table_insert (part, "identifier",
+          tp_g_value_slice_new_string ("lolcat"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("image/jpeg"));
+      g_hash_table_insert (part, "content", tp_g_value_slice_new_bytes (
             "\xff\xd8\xff\xe0\x00\x10JFIF\x00...", 14));
       g_ptr_array_add (send_parts, part);
 
@@ -622,10 +600,14 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "alternative", slice_new_string ("main"));
-      g_hash_table_insert (part, "identifier", slice_new_string ("html"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/html"));
-      g_hash_table_insert (part, "content", slice_new_string (
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("main"));
+      g_hash_table_insert (part, "identifier",
+          tp_g_value_slice_new_string ("html"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/html"));
+      g_hash_table_insert (part, "content",
+          tp_g_value_slice_new_string (
             "Here is a photo of a cat:<br />"
             "<img src=\"cid:lolcat\" alt=\"lol!\" /><br />"
             "It's in ur regression tests verifying ur designs!"
@@ -634,28 +616,37 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "alternative", slice_new_string ("main"));
-      g_hash_table_insert (part, "identifier", slice_new_string ("text"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("main"));
+      g_hash_table_insert (part, "identifier",
+          tp_g_value_slice_new_string ("text"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
       g_hash_table_insert (part, "content",
-          slice_new_string (EXPECTED_TEXT));
+          tp_g_value_slice_new_string (EXPECTED_TEXT));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "identifier", slice_new_string ("jpeg"));
-      g_hash_table_insert (part, "alternative", slice_new_string ("lolcat"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("image/jpeg"));
-      g_hash_table_insert (part, "content", slice_new_byte_array (
+      g_hash_table_insert (part, "identifier",
+          tp_g_value_slice_new_string ("jpeg"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("lolcat"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("image/jpeg"));
+      g_hash_table_insert (part, "content", tp_g_value_slice_new_bytes (
             "\xff\xd8\xff\xe0\x00\x10JFIF\x00...", 14));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "identifier", slice_new_string ("png"));
-      g_hash_table_insert (part, "alternative", slice_new_string ("lolcat"));
-      g_hash_table_insert (part, "content-type", slice_new_string ("image/png"));
-      g_hash_table_insert (part, "content", slice_new_byte_array (
+      g_hash_table_insert (part, "identifier",
+          tp_g_value_slice_new_string ("png"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("lolcat"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("image/png"));
+      g_hash_table_insert (part, "content", tp_g_value_slice_new_bytes (
             "\x89PNG\x0d\x0a\x1a\x0a\x00...", 12));
       g_ptr_array_add (send_parts, part);
 
@@ -734,23 +725,26 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
       g_hash_table_insert (part, "content",
-          slice_new_string ("I'm on a roll\n"));
+          tp_g_value_slice_new_string ("I'm on a roll\n"));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
       g_hash_table_insert (part, "content",
-          slice_new_string ("I'm on a roll this time\n"));
+          tp_g_value_slice_new_string ("I'm on a roll this time\n"));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
       g_hash_table_insert (part, "content",
-          slice_new_string ("I feel my luck could change\n"));
+          tp_g_value_slice_new_string ("I feel my luck could change\n"));
       g_ptr_array_add (send_parts, part);
 
       tp_cli_channel_interface_messages_run_send_message (chan, -1,
@@ -824,28 +818,38 @@ main (int argc,
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
-      g_hash_table_insert (part, "alternative", slice_new_string ("alt"));
-      g_hash_table_insert (part, "lang", slice_new_string ("fr_CA at collabora"));
-      g_hash_table_insert (part, "content", slice_new_string (EXPECTED_TEXT));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("alt"));
+      g_hash_table_insert (part, "lang",
+          tp_g_value_slice_new_string ("fr_CA at collabora"));
+      g_hash_table_insert (part, "content",
+          tp_g_value_slice_new_string (EXPECTED_TEXT));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
-      g_hash_table_insert (part, "alternative", slice_new_string ("alt"));
-      g_hash_table_insert (part, "lang", slice_new_string ("en_GB"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("alt"));
+      g_hash_table_insert (part, "lang",
+          tp_g_value_slice_new_string ("en_GB"));
       g_hash_table_insert (part, "content",
-          slice_new_string ("we're fixing the colour of the video stream"));
+          tp_g_value_slice_new_string ("we're fixing the colour of the video stream"));
       g_ptr_array_add (send_parts, part);
 
       part = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
           (GDestroyNotify) tp_g_value_slice_free);
-      g_hash_table_insert (part, "content-type", slice_new_string ("text/plain"));
-      g_hash_table_insert (part, "alternative", slice_new_string ("alt"));
-      g_hash_table_insert (part, "lang", slice_new_string ("en_US"));
+      g_hash_table_insert (part, "content-type",
+          tp_g_value_slice_new_string ("text/plain"));
+      g_hash_table_insert (part, "alternative",
+          tp_g_value_slice_new_string ("alt"));
+      g_hash_table_insert (part, "lang",
+          tp_g_value_slice_new_string ("en_US"));
       g_hash_table_insert (part, "content",
-          slice_new_string ("we're fixing the color of the video stream"));
+          tp_g_value_slice_new_string ("we're fixing the color of the video stream"));
       g_ptr_array_add (send_parts, part);
 
       tp_cli_channel_interface_messages_run_send_message (chan, -1,
diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c
index b990e54..a75caed 100644
--- a/tests/lib/contacts-conn.c
+++ b/tests/lib/contacts-conn.c
@@ -100,7 +100,6 @@ aliasing_fill_contact_attributes (GObject *object,
 
   for (i = 0; i < contacts->len; i++)
     {
-      GValue *val = tp_g_value_slice_new (G_TYPE_STRING);
       TpHandle handle = g_array_index (contacts, guint, i);
       const gchar *alias = g_hash_table_lookup (self->priv->aliases,
           GUINT_TO_POINTER (handle));
@@ -110,10 +109,10 @@ aliasing_fill_contact_attributes (GObject *object,
           alias = tp_handle_inspect (contact_repo, handle);
         }
 
-        g_value_set_string (val, alias);
-        tp_contacts_mixin_set_contact_attribute (attributes, handle,
-            TP_IFACE_CONNECTION_INTERFACE_ALIASING "/alias", val);
-      }
+      tp_contacts_mixin_set_contact_attribute (attributes, handle,
+          TP_IFACE_CONNECTION_INTERFACE_ALIASING "/alias",
+          tp_g_value_slice_new_string (alias));
+    }
 }
 
 static void
@@ -132,11 +131,9 @@ avatars_fill_contact_attributes (GObject *object,
 
       if (token != NULL)
         {
-          GValue *val = tp_g_value_slice_new (G_TYPE_STRING);
-
-          g_value_set_string (val, token);
           tp_contacts_mixin_set_contact_attribute (attributes, handle,
-              TP_IFACE_CONNECTION_INTERFACE_AVATARS "/token", val);
+              TP_IFACE_CONNECTION_INTERFACE_AVATARS "/token",
+              tp_g_value_slice_new_string (token));
         }
     }
 }
@@ -222,12 +219,8 @@ my_get_contact_statuses (GObject *object,
           g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free);
 
       if (presence_message != NULL)
-        {
-          GValue *value = tp_g_value_slice_new (G_TYPE_STRING);
-
-          g_value_set_string (value, presence_message);
-          g_hash_table_insert (parameters, "message", value);
-        }
+        g_hash_table_insert (parameters, "message",
+            tp_g_value_slice_new_string (presence_message));
 
       g_hash_table_insert (result, key,
           tp_presence_status_new (index, parameters));
@@ -356,12 +349,8 @@ contacts_connection_change_presences (
           g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free);
 
       if (messages[i] != NULL && messages[i][0] != '\0')
-        {
-          GValue *value = tp_g_value_slice_new (G_TYPE_STRING);
-
-          g_value_set_string (value, messages[i]);
-          g_hash_table_insert (parameters, "message", value);
-        }
+        g_hash_table_insert (parameters, "message",
+            tp_g_value_slice_new_string (messages[i]));
 
       g_hash_table_insert (presences, key, tp_presence_status_new (indexes[i],
             parameters));
-- 
1.5.6.5




More information about the telepathy-commits mailing list