From d8ddbe013f569177b482ceb04eb00ab37de37b57 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 20 Apr 2011 12:54:23 +0100 Subject: [PATCH 2/2] Add a regression test for GetAll on objects with no properties Bug: https://bugs.freedesktop.org/show_bug.cgi?id=22156 --- .gitignore | 2 + test/core/22156.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ test/core/Makefile.am | 11 +++ test/core/boring-iface.c | 70 +++++++++++++++++ test/core/boring-iface.h | 102 ++++++++++++++++++++++++ test/core/boring-iface.xml | 6 ++ test/core/boring-object.c | 56 +++++++++++++ test/core/boring-object.h | 72 +++++++++++++++++ 8 files changed, 502 insertions(+), 0 deletions(-) create mode 100644 test/core/22156.c create mode 100644 test/core/boring-iface.c create mode 100644 test/core/boring-iface.h create mode 100644 test/core/boring-iface.xml create mode 100644 test/core/boring-object.c create mode 100644 test/core/boring-object.h diff --git a/.gitignore b/.gitignore index 3bbaf2a..f1d93b9 100644 --- a/.gitignore +++ b/.gitignore @@ -94,7 +94,9 @@ test/Makefile.in test/core/Makefile test/core/Makefile.in /test/core/test-5688 +/test/core/test-22156 /test/core/test-30574 +/test/core/boring-iface-glue.h test/core/my-object-marshal.c test/core/my-object-marshal.h test/core/run-with-tmp-session-bus.conf diff --git a/test/core/22156.c b/test/core/22156.c new file mode 100644 index 0000000..d02be9c --- /dev/null +++ b/test/core/22156.c @@ -0,0 +1,183 @@ +/* Regression test for freedesktop.org #22156. + * + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2011 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 "boring-object.h" +#include "boring-iface.h" + +typedef struct { + DBusGConnection *bus; + BoringObject *object; + BoringUsable *implementor; + DBusGProxy *proxy; + DBusGProxyCall *call; + + GHashTable *asv; + GError *error; +} Fixture; + +static void +get_all_cb (DBusGProxy *proxy, + DBusGProxyCall *call, + gpointer user_data) +{ + Fixture *f = user_data; + + f->asv = NULL; + f->error = NULL; + + g_assert (proxy == f->proxy); + g_assert (call == f->call); + + if (dbus_g_proxy_end_call (proxy, call, &f->error, + dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), + &f->asv)) + { + g_assert (f->asv != NULL); + g_assert_no_error (f->error); + } + else + { + g_assert (f->asv == NULL); + g_assert (f->error != NULL); + } +} + +static void +setup (Fixture *f, + gconstpointer path_to_use) +{ + f->error = NULL; + f->asv = NULL; + + f->bus = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, NULL); + g_assert (f->bus != NULL); + + f->object = g_object_new (BORING_TYPE_OBJECT, NULL); + g_assert (BORING_IS_OBJECT (f->object)); + dbus_g_connection_register_g_object (f->bus, "/object", + (GObject *) f->object); + + f->implementor = g_object_new (BORING_TYPE_USABLE_IMPL, NULL); + g_assert (BORING_IS_USABLE (f->implementor)); + dbus_g_connection_register_g_object (f->bus, "/implementor", + (GObject *) f->implementor); + + f->proxy = dbus_g_proxy_new_for_name (f->bus, + dbus_bus_get_unique_name (dbus_g_connection_get_connection (f->bus)), + path_to_use, DBUS_INTERFACE_PROPERTIES); +} + +static void +teardown (Fixture *f, + gconstpointer test_data G_GNUC_UNUSED) +{ + if (f->asv != NULL) + g_hash_table_unref (f->asv); + + g_clear_error (&f->error); + + if (f->proxy != NULL) + g_object_unref (f->proxy); + + if (f->object != NULL) + g_object_unref (f->object); + + if (f->implementor != NULL) + g_object_unref (f->implementor); + + if (f->bus != NULL) + { + dbus_connection_close (dbus_g_connection_get_connection (f->bus)); + dbus_g_connection_unref (f->bus); + } +} + +static void +test_present (Fixture *f, + gconstpointer test_data G_GNUC_UNUSED) +{ + f->call = dbus_g_proxy_begin_call (f->proxy, "GetAll", get_all_cb, f, NULL, + G_TYPE_STRING, "org.freedesktop.DBus.GLib.Tests.Boring", + G_TYPE_INVALID); + + while (f->asv == NULL && f->error == NULL) + g_main_context_iteration (NULL, TRUE); + + g_assert_no_error (f->error); + g_assert (f->asv != NULL); + g_assert_cmpuint (g_hash_table_size (f->asv), ==, 0); +} + +static void +test_absent (Fixture *f, + gconstpointer test_data G_GNUC_UNUSED) +{ + f->call = dbus_g_proxy_begin_call (f->proxy, "GetAll", get_all_cb, f, NULL, + G_TYPE_STRING, "com.example.WeDoNotHaveThisInterface", + G_TYPE_INVALID); + + while (f->asv == NULL && f->error == NULL) + g_main_context_iteration (NULL, TRUE); + + g_assert_no_error (f->error); + g_assert (f->asv != NULL); + g_assert_cmpuint (g_hash_table_size (f->asv), ==, 0); +} + +int +main (int argc, + char **argv) +{ + g_type_init (); + dbus_g_type_specialized_init (); + + g_test_init (&argc, &argv, NULL); + + g_test_add ("/no-props/object/present", Fixture, "/object", + setup, test_present, teardown); + g_test_add ("/no-props/implementor/present", Fixture, "/implementor", + setup, test_present, teardown); + g_test_add ("/no-props/object/absent", Fixture, "/object", + setup, test_absent, teardown); + g_test_add ("/no-props/implementor/absent", Fixture, "/implementor", + setup, test_absent, teardown); + + return g_test_run (); +} diff --git a/test/core/Makefile.am b/test/core/Makefile.am index ccb17f6..63281e4 100644 --- a/test/core/Makefile.am +++ b/test/core/Makefile.am @@ -54,6 +54,7 @@ noinst_PROGRAMS = \ peer-client \ test-types \ test-5688 \ + test-22156 \ test-30574 \ test-unregister \ test-variant-recursion \ @@ -67,6 +68,13 @@ test_5688_SOURCES = \ my-object-marshal.c \ 5688.c +test_22156_SOURCES = \ + boring-object.c \ + boring-object.h \ + boring-iface.c \ + boring-iface.h \ + 22156.c + test_30574_SOURCES = \ 30574.c @@ -98,6 +106,9 @@ test_service_glib_SOURCES= \ my-object-marshal.c \ test-service-glib.c +boring-iface-glue.h: boring-iface.xml $(top_builddir)/dbus/dbus-binding-tool$(EXEEXT) + $(DEBUG) $(DBUS_BINDING_TOOL) --prefix=boring --mode=glib-server --output=$@ $< + test-service-glib-glue.h: test-service-glib.xml $(top_builddir)/dbus/dbus-binding-tool$(EXEEXT) $(DEBUG) $(DBUS_BINDING_TOOL) --prefix=my_object --mode=glib-server --output=test-service-glib-glue.h $(srcdir)/test-service-glib.xml diff --git a/test/core/boring-iface.c b/test/core/boring-iface.c new file mode 100644 index 0000000..0ffeef8 --- /dev/null +++ b/test/core/boring-iface.c @@ -0,0 +1,70 @@ +/* GInterface with no D-Bus API, part of a test for freedesktop.org #22156. + * + * Author: Simon McVittie + * Copyright © 2011 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 "boring-iface.h" + +#include "boring-iface-glue.h" + +G_DEFINE_INTERFACE (BoringUsable, boring_usable, G_TYPE_OBJECT) + +static void +boring_usable_default_init (BoringUsableInterface *iface G_GNUC_UNUSED) +{ + static gsize initialized = 0; + + if (g_once_init_enter (&initialized)) + { + dbus_g_object_type_install_info (BORING_TYPE_USABLE, + &dbus_glib_boring_object_info); + + g_once_init_leave (&initialized, 1); + } +} + +G_DEFINE_TYPE_WITH_CODE (BoringUsableImpl, boring_usable_impl, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (BORING_TYPE_USABLE, NULL)) + +static void +boring_usable_impl_init (BoringUsableImpl *self G_GNUC_UNUSED) +{ +} + +static void +boring_usable_impl_class_init (BoringUsableImplClass *cls G_GNUC_UNUSED) +{ +} diff --git a/test/core/boring-iface.h b/test/core/boring-iface.h new file mode 100644 index 0000000..699eebe --- /dev/null +++ b/test/core/boring-iface.h @@ -0,0 +1,102 @@ +/* GInterface with no D-Bus API, part of a test for freedesktop.org #22156. + * + * Author: Simon McVittie + * Copyright © 2011 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. + */ + +#ifndef __BORING_IFACE_H__ +#define __BORING_IFACE_H__ + +#include +#include + +G_BEGIN_DECLS + +typedef struct _BoringUsable BoringUsable; + +typedef struct _BoringUsableInterface BoringUsableInterface; + +struct _BoringUsableInterface +{ + GTypeInterface parent; +}; + +GType boring_usable_get_type (void); + +#define BORING_TYPE_USABLE \ + (boring_usable_get_type ()) +#define BORING_USABLE(self) \ + (G_TYPE_CHECK_INSTANCE_CAST((self), BORING_TYPE_USABLE, BoringUsable)) +#define BORING_IS_USABLE(self) \ + (G_TYPE_CHECK_INSTANCE_TYPE((self), BORING_TYPE_USABLE)) +#define BORING_USABLE_GET_INTERFACE(self) \ + (G_TYPE_INSTANCE_GET_INTERFACE((self), BORING_TYPE_USABLE, \ + BoringUsableInterface)) + +typedef struct _BoringUsableImpl BoringUsableImpl; +typedef struct _BoringUsableImplClass BoringUsableImplClass; + +GType boring_usable_impl_get_type (void); + +struct _BoringUsableImpl +{ + GObject parent; +}; + +struct _BoringUsableImplClass +{ + GObjectClass parent; +}; + +#define BORING_TYPE_USABLE_IMPL \ + (boring_usable_impl_get_type ()) +#define BORING_USABLE_IMPL(self) \ + (G_TYPE_CHECK_INSTANCE_CAST ((self), BORING_TYPE_USABLE_IMPL, \ + BoringUsableImpl)) +#define BORING_USABLE_IMPL_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST ((cls), BORING_TYPE_USABLE_IMPL, \ + BoringUsableImplClass)) +#define BORING_IS_USABLE_IMPL(self) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((self), BORING_TYPE_USABLE_IMPL)) +#define BORING_IS_USABLE_IMPL_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE ((cls), BORING_TYPE_USABLE_IMPL)) +#define BORING_USABLE_IMPL_GET_CLASS(self) \ + (G_TYPE_INSTANCE_GET_CLASS ((self), BORING_TYPE_USABLE_IMPL, \ + BoringUsableImplClass)) + +extern const DBusGObjectInfo dbus_glib_boring_object_info; + +G_END_DECLS + +#endif diff --git a/test/core/boring-iface.xml b/test/core/boring-iface.xml new file mode 100644 index 0000000..76f9566 --- /dev/null +++ b/test/core/boring-iface.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/core/boring-object.c b/test/core/boring-object.c new file mode 100644 index 0000000..25a783c --- /dev/null +++ b/test/core/boring-object.c @@ -0,0 +1,56 @@ +/* Object with no D-Bus API, part of a test for freedesktop.org #22156. + * + * Author: Simon McVittie + * Copyright © 2011 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 "boring-object.h" + +/* it shares the DBusGObjectInfo */ +#include "boring-iface.h" + +G_DEFINE_TYPE (BoringObject, boring_object, G_TYPE_OBJECT) + +static void +boring_object_init (BoringObject *self G_GNUC_UNUSED) +{ +} + +static void +boring_object_class_init (BoringObjectClass *cls G_GNUC_UNUSED) +{ + dbus_g_object_type_install_info (BORING_TYPE_OBJECT, + &dbus_glib_boring_object_info); +} diff --git a/test/core/boring-object.h b/test/core/boring-object.h new file mode 100644 index 0000000..3de1e2e --- /dev/null +++ b/test/core/boring-object.h @@ -0,0 +1,72 @@ +/* Object with no D-Bus API, part of a test for freedesktop.org #22156. + * + * Author: Simon McVittie + * Copyright © 2011 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. + */ + +#ifndef __BORING_OBJECT_H__ +#define __BORING_OBJECT_H__ + +#include +#include + +typedef struct BoringObject BoringObject; +typedef struct BoringObjectClass BoringObjectClass; + +GType boring_object_get_type (void); + +struct BoringObject +{ + GObject parent; +}; + +struct BoringObjectClass +{ + GObjectClass parent; +}; + +#define BORING_TYPE_OBJECT \ + (boring_object_get_type ()) +#define BORING_OBJECT(self) \ + (G_TYPE_CHECK_INSTANCE_CAST ((self), BORING_TYPE_OBJECT, BoringObject)) +#define BORING_OBJECT_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST ((cls), BORING_TYPE_OBJECT, BoringObjectClass)) +#define BORING_IS_OBJECT(self) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((self), BORING_TYPE_OBJECT)) +#define BORING_IS_OBJECT_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE ((cls), BORING_TYPE_OBJECT)) +#define BORING_OBJECT_GET_CLASS(self) \ + (G_TYPE_INSTANCE_GET_CLASS ((self), BORING_TYPE_OBJECT, BoringObjectClass)) + +#endif -- 1.7.4.4