From e42535c3c0dace3ede96c50f5a9b3cc315c80190 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 16 Apr 2009 12:11:15 +0100 Subject: [PATCH 2/5] fd.o #5688: Add a regression test Also assert that dbus_g_connection_lookup_g_object works (my previous attempt to fix #5688 broke this). --- test/core/5688.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ test/core/Makefile.am | 13 +++++++- test/core/run-test.sh | 1 + 3 files changed, 94 insertions(+), 1 deletions(-) create mode 100644 test/core/5688.c diff --git a/test/core/5688.c b/test/core/5688.c new file mode 100644 index 0000000..c08240d --- /dev/null +++ b/test/core/5688.c @@ -0,0 +1,81 @@ +/* Regression test for freedesktop.org #5688. + * + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009 Nokia Corporation + * + * In preparation for dbus-glib relicensing (if it ever happens), this file is + * licensed under (at your option) either the AFL v2.1, the GPL v2 or later, + * or an MIT/X11-style license: + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include "dbus/dbus-gutils.h" /* for DBUS_G_CONNECTION_FROM_CONNECTION */ + +#include "my-object.h" + +GMainLoop *loop; + +int +main (int argc, char **argv) +{ + DBusConnection *d_connection; + DBusGConnection *connection; + DBusError d_error; + GObject *obj; + + dbus_error_init (&d_error); + loop = g_main_loop_new (NULL, FALSE); + + g_type_init (); + g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); + + d_connection = dbus_bus_get_private (DBUS_BUS_SESSION, NULL); + + if (d_connection == NULL) + g_error ("%s: %s", d_error.name, d_error.message); + + dbus_connection_setup_with_g_main (d_connection, NULL); + + connection = DBUS_G_CONNECTION_FROM_CONNECTION (d_connection); + + obj = g_object_new (MY_TYPE_OBJECT, NULL); + dbus_g_connection_register_g_object (connection, "/foo", obj); + g_assert (dbus_g_connection_lookup_g_object (connection, "/foo") == obj); + g_assert (dbus_g_connection_lookup_g_object (connection, "/bar") == NULL); + + dbus_connection_close (d_connection); + dbus_connection_unref (d_connection); + + g_object_unref (obj); + + return 0; +} diff --git a/test/core/Makefile.am b/test/core/Makefile.am index c70f64c..48184a3 100644 --- a/test/core/Makefile.am +++ b/test/core/Makefile.am @@ -39,7 +39,18 @@ endif ## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we ## build even when not doing "make check" -noinst_PROGRAMS= test-dbus-glib test-service-glib $(THREAD_APPS) peer-server peer-client test-types test-variant-recursion +noinst_PROGRAMS= test-dbus-glib test-service-glib $(THREAD_APPS) peer-server peer-client test-types test-5688 test-variant-recursion + +test_5688_SOURCES = \ + my-object.c \ + my-object.h \ + my-object-subclass.c \ + my-object-subclass.h \ + my-object-marshal.c \ + 5688.c +test_5688_LDADD = \ + $(top_builddir)/dbus/libdbus-glib-1.la \ + $(DBUS_GLIB_THREADS_LIBS) test_dbus_glib_SOURCES= \ my-object-marshal.c \ diff --git a/test/core/run-test.sh b/test/core/run-test.sh index aa41718..8058570 100755 --- a/test/core/run-test.sh +++ b/test/core/run-test.sh @@ -44,6 +44,7 @@ else dbus-monitor --session & fi ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-types || die "test-types failed" + ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-5688 || die "test-5688 failed" ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-dbus-glib || die "test-dbus-glib failed" ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/core/test-variant-recursion || die "test-variant-recursion failed" fi -- 1.6.2.2