[telepathy-glib/master] Test that new_from_properties doesn't call GetAll

Will Thompson will.thompson at collabora.co.uk
Wed Jul 22 04:54:04 PDT 2009


The artificially-constructed properties hash didn't have all of the
mandatory properties (Requested, Initiator* and TargetID were missing).
The test also used a service-side channel that didn't implement the
Properties interface. Finally, wrap the GObject property getter given to
the properties mixin with one that records that it's been called, and
assert that it hasn't been called once the channel becomes ready.
---
 tests/dbus/channel-introspect.c |   43 +++++++++++++++++++++-----------------
 tests/lib/textchan-null.c       |   17 ++++++++++++++-
 tests/lib/textchan-null.h       |    2 +
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/tests/dbus/channel-introspect.c b/tests/dbus/channel-introspect.c
index f52d076..1b12037 100644
--- a/tests/dbus/channel-introspect.c
+++ b/tests/dbus/channel-introspect.c
@@ -93,6 +93,7 @@ main (int argc,
   TpHandleRepoIface *contact_repo;
   TestTextChannelNull *service_chan;
   TestTextChannelNull *service_props_chan;
+  TestPropsTextChannel *service_props_chan_;
   TpDBusDaemon *dbus;
   TpConnection *conn;
   TpChannel *chan;
@@ -156,6 +157,7 @@ main (int argc,
         "object-path", props_chan_path,
         "handle", handle,
         NULL));
+  service_props_chan_ = TEST_PROPS_TEXT_CHANNEL (service_props_chan);
 
   mainloop = g_main_loop_new (NULL, FALSE);
 
@@ -245,23 +247,25 @@ main (int argc,
 
   test_connection_run_until_dbus_queue_processed (conn);
 
-  service_chan->get_handle_called = 0;
-  service_chan->get_interfaces_called = 0;
-  service_chan->get_channel_type_called = 0;
-
-  asv = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
-      (GDestroyNotify) tp_g_value_slice_free);
-
-  g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".ChannelType"),
-      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_new_uint (TP_HANDLE_TYPE_CONTACT));
-  g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".TargetHandle"),
-      tp_g_value_slice_new_uint (handle));
-  g_hash_table_insert (asv, g_strdup (TP_IFACE_CHANNEL ".Interfaces"),
-      tp_g_value_slice_new_static_boxed (G_TYPE_STRV, NULL));
+  service_props_chan->get_handle_called = 0;
+  service_props_chan->get_interfaces_called = 0;
+  service_props_chan->get_channel_type_called = 0;
 
-  chan = tp_channel_new_from_properties (conn, chan_path, asv, &error);
+  service_props_chan_->dbus_property_retrieved = 0;
+
+  asv = tp_asv_new (
+      TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
+          TP_IFACE_CHANNEL_TYPE_TEXT,
+      TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
+      TP_IFACE_CHANNEL ".TargetHandle", G_TYPE_UINT, handle,
+      TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, IDENTIFIER,
+      TP_IFACE_CHANNEL ".InitiatorHandle", G_TYPE_UINT, handle,
+      TP_IFACE_CHANNEL ".InitiatorID", G_TYPE_STRING, IDENTIFIER,
+      TP_IFACE_CHANNEL ".Interfaces", G_TYPE_STRV, NULL,
+      TP_IFACE_CHANNEL ".Requested", G_TYPE_BOOLEAN, FALSE,
+      NULL);
+
+  chan = tp_channel_new_from_properties (conn, props_chan_path, asv, &error);
   test_assert_no_error (error);
 
   g_hash_table_destroy (asv);
@@ -269,10 +273,11 @@ main (int argc,
 
   MYASSERT (tp_channel_run_until_ready (chan, &error, NULL), "");
   test_assert_no_error (error);
-  MYASSERT_SAME_UINT (service_chan->get_handle_called, 0);
-  MYASSERT_SAME_UINT (service_chan->get_channel_type_called, 0);
+  MYASSERT_SAME_UINT (service_props_chan_->dbus_property_retrieved, 0);
+  MYASSERT_SAME_UINT (service_props_chan->get_handle_called, 0);
+  MYASSERT_SAME_UINT (service_props_chan->get_channel_type_called, 0);
   /* FIXME: with an improved fast-path we could avoid this one too maybe? */
-  /* MYASSERT_SAME_UINT (service_chan->get_interfaces_called, 0); */
+  /* MYASSERT_SAME_UINT (service_props_chan->get_interfaces_called, 0); */
 
   assert_chan_sane (chan, handle);
 
diff --git a/tests/lib/textchan-null.c b/tests/lib/textchan-null.c
index e716776..3713b38 100644
--- a/tests/lib/textchan-null.c
+++ b/tests/lib/textchan-null.c
@@ -297,6 +297,21 @@ test_text_channel_null_class_init (TestTextChannelNullClass *klass)
 }
 
 static void
+test_props_text_channel_getter_gobject_properties (GObject *object,
+    GQuark interface,
+    GQuark name,
+    GValue *value,
+    gpointer getter_data)
+{
+  TestPropsTextChannel *self = TEST_PROPS_TEXT_CHANNEL (object);
+
+  self->dbus_property_retrieved = 1;
+
+  tp_dbus_properties_mixin_getter_gobject_properties (object, interface, name,
+      value, getter_data);
+}
+
+static void
 test_props_text_channel_class_init (TestPropsTextChannelClass *klass)
 {
   static TpDBusPropertiesMixinPropImpl channel_props[] = {
@@ -312,7 +327,7 @@ test_props_text_channel_class_init (TestPropsTextChannelClass *klass)
   };
   static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
       { TP_IFACE_CHANNEL,
-        tp_dbus_properties_mixin_getter_gobject_properties,
+        test_props_text_channel_getter_gobject_properties,
         NULL,
         channel_props,
       },
diff --git a/tests/lib/textchan-null.h b/tests/lib/textchan-null.h
index 4417f21..2c51b0c 100644
--- a/tests/lib/textchan-null.h
+++ b/tests/lib/textchan-null.h
@@ -64,6 +64,8 @@ typedef struct _TestPropsTextChannelClass TestPropsTextChannelClass;
 
 struct _TestPropsTextChannel {
     TestTextChannelNull parent;
+
+    guint dbus_property_retrieved;
 };
 
 struct _TestPropsTextChannelClass {
-- 
1.5.6.5




More information about the telepathy-commits mailing list