From 866f13130ee8ea14b7c2d9b7814e53ee6cbaf96a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 2 Jun 2011 13:50:20 +0100 Subject: [PATCH 3/3] Regression test for fd.o #37852 --- test/core/my-object.c | 17 ++++++++++ test/core/my-object.h | 2 + test/core/registrations.c | 68 +++++++++++++++++++++++++++++++++++++++ test/core/test-service-glib.xml | 4 ++ 4 files changed, 91 insertions(+), 0 deletions(-) diff --git a/test/core/my-object.c b/test/core/my-object.c index ec0e301..0ff5562 100644 --- a/test/core/my-object.c +++ b/test/core/my-object.c @@ -23,6 +23,7 @@ enum enum { FROBNICATE, + OBJECTIFIED, SIG0, SIG1, SIG2, @@ -171,6 +172,15 @@ my_object_class_init (MyObjectClass *mobject_class) g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + signals[OBJECTIFIED] = + g_signal_new ("objectified", + G_OBJECT_CLASS_TYPE (mobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, G_TYPE_OBJECT); + signals[SIG0] = g_signal_new ("sig0", G_OBJECT_CLASS_TYPE (mobject_class), @@ -866,3 +876,10 @@ my_object_terminate (MyObject *obj, GError **error) g_main_loop_quit (loop); return TRUE; } + +void +my_object_emit_objectified (MyObject *obj, + GObject *other) +{ + g_signal_emit (obj, signals[OBJECTIFIED], 0, other); +} diff --git a/test/core/my-object.h b/test/core/my-object.h index 657140d..3657aa0 100644 --- a/test/core/my-object.h +++ b/test/core/my-object.h @@ -116,4 +116,6 @@ void my_object_async_throw_error (MyObject *obj, DBusGMethodInvocation *context) void my_object_unsafe_disable_legacy_property_access (MyObject *obj); +void my_object_emit_objectified (MyObject *obj, GObject *other); + #endif diff --git a/test/core/registrations.c b/test/core/registrations.c index a316313..d46b15a 100644 --- a/test/core/registrations.c +++ b/test/core/registrations.c @@ -50,6 +50,7 @@ typedef struct { GObject *object; DBusMessage *frobnicate1_message; DBusMessage *frobnicate2_message; + gboolean received_objectified; } Fixture; static void @@ -324,6 +325,71 @@ test_clean_slate (Fixture *f, f->frobnicate2_message = NULL; } +static DBusHandlerResult +objectified_cb (DBusConnection *conn, + DBusMessage *message, + void *user_data) +{ + Fixture *f = user_data; + + if (dbus_message_is_signal (message, + "org.freedesktop.DBus.GLib.Tests.MyObject", "Objectified")) + { + const char *sender = dbus_message_get_sender (message); + const char *path = dbus_message_get_path (message); + dbus_bool_t ok; + DBusError e; + + dbus_error_init (&e); + + g_assert (sender != NULL); + g_assert (path != NULL); + + g_assert_cmpstr (path, ==, "/foo"); + g_assert_cmpstr (sender, ==, dbus_bus_get_unique_name ( + dbus_g_connection_get_connection (f->bus))); + + path = NULL; + ok = dbus_message_get_args (message, &e, + DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set (&e)) + g_error ("%s: %s", e.name, e.message); + + g_assert (ok); + g_assert_cmpstr (path, ==, "/foo"); + + f->received_objectified = TRUE; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static void +test_marshal_object (Fixture *f, + gconstpointer test_data G_GNUC_UNUSED) +{ + dbus_bool_t mem; + + g_test_bug ("37852"); + + dbus_g_connection_register_g_object (f->bus, "/foo", f->object); + g_assert (dbus_g_connection_lookup_g_object (f->bus, "/foo") == + f->object); + + dbus_bus_add_match (dbus_g_connection_get_connection (f->bus), + "type='signal'", NULL); + mem = dbus_connection_add_filter (dbus_g_connection_get_connection (f->bus), + objectified_cb, f, NULL); + g_assert (mem); + + my_object_emit_objectified ((MyObject *) f->object, f->object); + + while (!f->received_objectified) + g_main_context_iteration (NULL, TRUE); +} + int main (int argc, char **argv) { @@ -349,6 +415,8 @@ main (int argc, char **argv) setup, test_twice, teardown); g_test_add ("/registrations/clean-slate", Fixture, NULL, setup, test_clean_slate, teardown); + g_test_add ("/registrations/marshal-object", Fixture, NULL, + setup, test_marshal_object, teardown); return g_test_run (); } diff --git a/test/core/test-service-glib.xml b/test/core/test-service-glib.xml index 94a836a..1b595cc 100644 --- a/test/core/test-service-glib.xml +++ b/test/core/test-service-glib.xml @@ -184,6 +184,10 @@ + + + + -- 1.7.5.3