[dconf] tests: improve coverage of D-Bus backends



commit fa270c41e31f19b366beb03eaf340a38586144f9
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Nov 24 23:11:52 2013 -0500

    tests: improve coverage of D-Bus backends
    
    Add a weird test to hit two additional obscure cases

 dbus-1/dconf-libdbus-1.c |    8 ++++++++
 tests/dbus.c             |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/dbus-1/dconf-libdbus-1.c b/dbus-1/dconf-libdbus-1.c
index f04062d..8ea187b 100644
--- a/dbus-1/dconf-libdbus-1.c
+++ b/dbus-1/dconf-libdbus-1.c
@@ -65,6 +65,14 @@ dconf_libdbus_1_new_method_call (const gchar *bus_name,
           dbus_message_iter_append_basic (&dbus_iter, DBUS_TYPE_STRING, &str);
         }
 
+      else if (g_variant_is_of_type (child, G_VARIANT_TYPE_UINT32))
+        {
+          guint32 uint;
+
+          uint = g_variant_get_uint32 (child);
+          dbus_message_iter_append_basic (&dbus_iter, DBUS_TYPE_UINT32, &uint);
+        }
+
       else
         {
           DBusMessageIter subiter;
diff --git a/tests/dbus.c b/tests/dbus.c
index f11be97..8d564e6 100644
--- a/tests/dbus.c
+++ b/tests/dbus.c
@@ -295,6 +295,49 @@ test_sync_call_error (void)
   g_assert (error != NULL);
   g_assert (strstr (error->message, " type "));
   g_clear_error (&error);
+
+  /* Test two oddities:
+   *
+   *  - first, the dbus-1 backend can't handle return types other than
+   *    's' and 'as', so we do a method call that will get something
+   *    else in order that we can check that the failure is treated
+   *    properly
+   *
+   *  - next, we want to make sure that the filter function for
+   *    gdbus-filter doesn't block incoming method calls
+   */
+  reply = dconf_engine_dbus_call_sync_func (G_BUS_TYPE_SESSION,
+                                            "org.freedesktop.DBus", "/", "org.freedesktop.DBus", 
"RequestName",
+                                            g_variant_new_parsed ("('ca.desrt.dconf.testsuite', uint32 0)"),
+                                            G_VARIANT_TYPE ("(u)"), &error);
+  if (reply != NULL)
+    {
+      guint s;
+
+      /* It worked, so we must be on gdbus... */
+      g_assert_no_error (error);
+
+      g_variant_get (reply, "(u)", &s);
+      g_assert_cmpuint (s, ==, 1);
+      g_variant_unref (reply);
+
+      /* Ping ourselves... */
+      reply = dconf_engine_dbus_call_sync_func (G_BUS_TYPE_SESSION,
+                                                "ca.desrt.dconf.testsuite", "/", "org.freedesktop.DBus.Peer",
+                                                "Ping", g_variant_new ("()"), G_VARIANT_TYPE_UNIT, &error);
+      g_assert (reply != NULL);
+      g_assert_no_error (error);
+      g_variant_unref (reply);
+    }
+  else
+    {
+      /* Else, we're on dbus1...
+       *
+       * Check that the error was emitted correctly.
+       */
+      g_assert_cmpstr (error->message, ==, "unable to handle message type '(u)'");
+      g_clear_error (&error);
+    }
 }
 
 static void


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