summaryrefslogtreecommitdiff
path: root/test/core/test-dbus-glib.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/test-dbus-glib.c')
-rw-r--r--test/core/test-dbus-glib.c286
1 files changed, 281 insertions, 5 deletions
diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c
index f32b2d4..d78ce58 100644
--- a/test/core/test-dbus-glib.c
+++ b/test/core/test-dbus-glib.c
@@ -268,7 +268,6 @@ increment_async_cb (DBusGProxy *proxy, guint val, GError *error, gpointer data)
g_source_remove (exit_timeout);
}
-
static void
lose (const char *str, ...)
{
@@ -313,6 +312,7 @@ main (int argc, char **argv)
DBusGProxy *driver;
DBusGProxy *proxy;
DBusGProxy *proxy2;
+ DBusGProxy *property_proxy;
char **name_list;
guint name_list_len;
guint i;
@@ -1577,7 +1577,10 @@ main (int argc, char **argv)
node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
if (!node)
- lose_gerror ("Failed to parse introspection data: %s", error);
+ {
+ g_printerr ("===\n%s\n===\n", v_STRING_2);
+ lose_gerror ("Failed to parse introspection data: %s", error);
+ }
found_introspectable = FALSE;
found_properties = FALSE;
@@ -1595,9 +1598,10 @@ main (int argc, char **argv)
{
GSList *elt;
gboolean found_manyargs;
-
+ gboolean found_no_touching = FALSE;
+
found_myobject = TRUE;
-
+
found_manyargs = FALSE;
for (elt = interface_info_get_methods (iface); elt; elt = elt->next)
{
@@ -1612,6 +1616,23 @@ main (int argc, char **argv)
}
if (!found_manyargs)
lose ("Missing method org.freedesktop.DBus.GLib.Tests.MyObject.ManyArgs");
+ for (elt = interface_info_get_properties (iface); elt; elt = elt->next)
+ {
+ PropertyInfo *prop = elt->data;
+
+ if (strcmp (property_info_get_name (prop), "no-touching") == 0)
+ {
+ if (property_info_get_access (prop) != PROPERTY_READ)
+ lose ("property no-touching had incorrect access %d", property_info_get_access (prop));
+ else
+ {
+ found_no_touching = TRUE;
+ break;
+ }
+ }
+ }
+ if (!found_no_touching)
+ lose ("didn't find property \"no-touching\" in org.freedesktop.DBus.GLib.Tests.MyObject");
}
else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.GLib.Tests.FooObject") == 0)
found_fooobject = TRUE;
@@ -1623,7 +1644,262 @@ main (int argc, char **argv)
lose ("Missing interface");
}
g_free (v_STRING_2);
-
+
+ /* Properties tests */
+ property_proxy = dbus_g_proxy_new_from_proxy (proxy, DBUS_INTERFACE_PROPERTIES, NULL);
+ g_object_unref (proxy);
+ proxy = NULL;
+
+ g_print ("Calling GetProperty (1)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "this_is_a_string",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_STRING));
+ g_assert (!strcmp (g_value_get_string (&value), ""));
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling SetProperty (1)\n");
+ {
+ GValue value = {0,};
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, "testing value");
+ if (!dbus_g_proxy_call (property_proxy, "Set", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "this_is_a_string",
+ G_TYPE_VALUE, &value, G_TYPE_INVALID, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete SetProperty call", error);
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty of read-only property\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "no-touching",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty no-touching call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_UINT));
+ g_assert (g_value_get_uint (&value) == 42);
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling SetProperty (1)\n");
+ {
+ GValue value = {0,};
+ g_value_init (&value, G_TYPE_UINT);
+ g_value_set_uint (&value, 40);
+ if (dbus_g_proxy_call (property_proxy, "Set", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "no-touching",
+ G_TYPE_VALUE, &value, G_TYPE_INVALID, G_TYPE_INVALID))
+ lose ("Unexpected success from SetProperty call for read-only value \"no-touching\"");
+ g_clear_error (&error);
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty of read-only property (again)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "no-touching",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_UINT));
+ g_assert (g_value_get_uint (&value) == 42);
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty (2)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "this_is_a_string",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_STRING));
+ g_assert (!strcmp (g_value_get_string (&value), "testing value"));
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty: SuperStudly\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "SuperStudly",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE));
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty: super-studly\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "super-studly",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE));
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty: super_studly\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "super_studly",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed to complete GetProperty call", error);
+ g_assert (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE));
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty on unknown property\n");
+ {
+ GValue value = {0,};
+ if (dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "SomeUnknownProperty",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose ("Unexpected success for GetProperty call of unknown property");
+
+ g_clear_error (&error);
+ }
+
+ /* These two are expected to pass unless we call disable_legacy_property_access */
+
+ g_print ("Calling GetProperty on not-exported property (legacy enabled)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "should-be-hidden",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed GetProperty call of \"should-be-hidden\" property", error);
+ g_assert (G_VALUE_HOLDS_BOOLEAN (&value));
+ g_assert (g_value_get_boolean (&value) == FALSE);
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling GetProperty on not-exported property (legacy enabled)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "ShouldBeHidden",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed GetProperty call of \"ShouldBeHidden\" property", error);
+
+ g_value_unset (&value);
+ }
+
+ g_print ("Calling SetProperty on not-exported property (legacy enabled)\n");
+ {
+ GValue value = {0,};
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, TRUE);
+ if (dbus_g_proxy_call (property_proxy, "Set", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "should-be-hidden",
+ G_TYPE_VALUE, &value,
+ G_TYPE_INVALID, G_TYPE_INVALID))
+ lose ("Unexpected success from SetProperty call of \"should-be-hidden\" property");
+ g_value_unset (&value);
+ g_clear_error (&error);
+ }
+
+ g_print ("Calling GetProperty on not-exported property (legacy enabled)\n");
+ {
+ GValue value = {0,};
+ if (!dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "should-be-hidden",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose_gerror ("Failed GetProperty call of \"should-be-hidden\" property", error);
+ g_assert (G_VALUE_HOLDS_BOOLEAN (&value));
+ g_assert (g_value_get_boolean (&value) == FALSE);
+ g_value_unset (&value);
+ }
+
+ /* Now, call disable_legacy_property_access */
+
+ g_assert (proxy == NULL);
+ proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.freedesktop.DBus.GLib.TestService",
+ "/org/freedesktop/DBus/GLib/Tests/MyTestObject",
+ "org.freedesktop.DBus.GLib.Tests.MyObject",
+ &error);
+
+ if (!dbus_g_proxy_call (proxy, "UnsafeDisableLegacyPropertyAccess", &error,
+ G_TYPE_INVALID, G_TYPE_INVALID))
+ lose_gerror ("Failed to invoke UnsafeDisableLegacyPropertyAccess", error);
+
+ g_object_unref (proxy);
+ proxy = NULL;
+
+ g_print ("Calling GetProperty on not-exported property (legacy *disabled*)\n");
+ {
+ GValue value = {0,};
+ if (dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "should-be-hidden",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose ("Unexpected success from GetProperty call of \"should-be-hidden\" property");
+ g_clear_error (&error);
+ }
+
+ g_print ("Calling GetProperty on not-exported property (legacy *disabled*)\n");
+ {
+ GValue value = {0,};
+ if (dbus_g_proxy_call (property_proxy, "Get", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "ShouldBeHidden",
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID))
+ lose ("Unexpected success from GetProperty call of \"ShouldBeHidden\" property");
+ g_clear_error (&error);
+ }
+
+ g_print ("Calling SetProperty on not-exported property (legacy *disabled*)\n");
+ {
+ GValue value = {0,};
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, FALSE);
+ if (dbus_g_proxy_call (property_proxy, "Set", &error,
+ G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.MyObject",
+ G_TYPE_STRING, "should-be-hidden",
+ G_TYPE_VALUE, &value,
+ G_TYPE_INVALID, G_TYPE_INVALID))
+ lose ("Unexpected success from SetProperty call of \"should-be-hidden\" property");
+ g_value_unset (&value);
+ g_clear_error (&error);
+ }
+
+ g_object_unref (property_proxy);
+ property_proxy = NULL;
test_terminate_proxy1 = dbus_g_proxy_new_for_name_owner (connection,
"org.freedesktop.DBus.GLib.TestService",