[glib] Add a generic property test
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add a generic property test
- Date: Wed, 1 Jan 2014 23:01:12 +0000 (UTC)
commit b5ba22f163f884f14724b54d001bd044308f9f63
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 23 15:47:45 2013 -0500
Add a generic property test
This test is inspired by its namesake in GTK+. We instantiate
all types, and check the default values of their properties,
with some exceptions for types that are known not to work.
gio/tests/Makefile.am | 15 +++-
gio/tests/defaultvalue.c | 228 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 242 insertions(+), 1 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index d3a2162..bffbe8d 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -31,6 +31,7 @@ test_programs = \
credentials \
data-input-stream \
data-output-stream \
+ defaultvalue \
fileattributematcher \
filter-streams \
gsubprocess \
@@ -302,7 +303,7 @@ dist_test_data += \
x-content/image-dcf/DCIM/Camera/20130831_203925.jpg \
x-content/image-dcf/DCIM/Camera/20130831_203928.jpg \
x-content/unix-software/autorun.sh \
- x-content/win32-software/autorun.exe \
+ x-content/win32-software/autorun.exe \
$(NULL)
test_extra_programs += \
@@ -527,3 +528,15 @@ test.gresource: test.gresource.xml Makefile $(shell $(glib_compile_resources) --
EXTRA_DIST += test.gresource.xml test1.txt test2.gresource.xml test2.txt test3.gresource.xml test3.txt
test4.gresource.xml
CLEANFILES += test_resources.c test_resources2.[ch] plugin_resources.c test.gresource
+
+BUILT_SOURCES: giotypefuncs.c
+
+giotypefuncs.c: Makefile
+ $(AM_V_GEN) echo '#include <gio/gio.h>' > xgen-giosrc.c && \
+ echo "G_GNUC_BEGIN_IGNORE_DEPRECATIONS" > xgen-gio && \
+ ${CPP} $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) xgen-giosrc.c | \
+ $(GREP) -o '\bg_.*_get_type\b' | \
+ $(GREP) -v 'g_io_extension_get_type\|g_variant_get_type' | \
+ sort | uniq | \
+ $(SED) -e 's/^/*tp++ = /' -e 's/$$/ ();/' >> xgen-gio && \
+ cp xgen-gio $@ # && rm -f xgen-gio xgen-giosrc.c
diff --git a/gio/tests/defaultvalue.c b/gio/tests/defaultvalue.c
new file mode 100644
index 0000000..023bc3d
--- /dev/null
+++ b/gio/tests/defaultvalue.c
@@ -0,0 +1,228 @@
+/* GIO default value tests
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <gio/gio.h>
+
+static void
+check_property (const char *output,
+ GParamSpec *pspec,
+ GValue *value)
+{
+ GValue default_value = G_VALUE_INIT;
+ char *v, *dv, *msg;
+
+ if (g_param_value_defaults (pspec, value))
+ return;
+
+ g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+ g_param_value_set_default (pspec, &default_value);
+
+ v = g_strdup_value_contents (value);
+ dv = g_strdup_value_contents (&default_value);
+
+ msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
+ output,
+ g_type_name (pspec->owner_type),
+ pspec->name,
+ dv, v);
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
+ g_free (msg);
+
+ g_free (v);
+ g_free (dv);
+ g_value_unset (&default_value);
+}
+
+static void
+test_type (gconstpointer data)
+{
+ GObjectClass *klass;
+ GObject *instance;
+ GParamSpec **pspecs;
+ guint n_pspecs, i;
+ GType type;
+
+ type = * (GType *) data;
+
+ if (g_type_is_a (type, G_TYPE_APP_INFO_MONITOR))
+ {
+ g_test_skip ("singleton");
+ return;
+ }
+
+ if (g_type_is_a (type, G_TYPE_BINDING) ||
+ g_type_is_a (type, G_TYPE_BUFFERED_INPUT_STREAM) ||
+ g_type_is_a (type, G_TYPE_BUFFERED_OUTPUT_STREAM) ||
+ g_type_is_a (type, G_TYPE_CHARSET_CONVERTER) ||
+ g_type_is_a (type, G_TYPE_DBUS_ACTION_GROUP) ||
+ g_type_is_a (type, G_TYPE_DBUS_CONNECTION) ||
+ g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT) ||
+ g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_SERVER) ||
+ g_type_is_a (type, G_TYPE_DBUS_PROXY) ||
+ g_type_is_a (type, G_TYPE_DBUS_SERVER) ||
+ g_type_is_a (type, G_TYPE_FILTER_OUTPUT_STREAM) ||
+ g_type_is_a (type, G_TYPE_FILTER_INPUT_STREAM) ||
+ g_type_is_a (type, G_TYPE_INET_ADDRESS) ||
+ g_type_is_a (type, G_TYPE_INET_SOCKET_ADDRESS) ||
+ g_type_is_a (type, G_TYPE_PROPERTY_ACTION) ||
+ g_type_is_a (type, G_TYPE_SETTINGS) ||
+ g_type_is_a (type, G_TYPE_SOCKET_CONNECTION) ||
+ g_type_is_a (type, G_TYPE_THEMED_ICON) ||
+ FALSE)
+ {
+ g_test_skip ("mandatory construct params");
+ return;
+ }
+
+ if (g_type_is_a (type, G_TYPE_DBUS_MENU_MODEL) ||
+ g_type_is_a (type, G_TYPE_DBUS_METHOD_INVOCATION))
+ {
+ g_test_skip ("crash in finalize");
+ return;
+ }
+
+ if (g_type_is_a (type, G_TYPE_FILE_ENUMERATOR) ||
+ g_type_is_a (type, G_TYPE_FILE_IO_STREAM))
+ {
+ g_test_skip ("should be abstract");
+ return;
+ }
+
+ klass = g_type_class_ref (type);
+ instance = g_object_new (type, NULL);
+
+ if (G_IS_INITABLE (instance) &&
+ !g_initable_init (G_INITABLE (instance), NULL, NULL))
+ {
+ g_test_skip ("initialization failed");
+ g_object_unref (instance);
+ g_type_class_unref (klass);
+ return;
+ }
+
+ if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
+ g_object_ref_sink (instance);
+
+ pspecs = g_object_class_list_properties (klass, &n_pspecs);
+ for (i = 0; i < n_pspecs; ++i)
+ {
+ GParamSpec *pspec = pspecs[i];
+ GValue value = G_VALUE_INIT;
+
+ if (pspec->owner_type != type)
+ continue;
+
+ if ((pspec->flags & G_PARAM_READABLE) == 0)
+ continue;
+
+ if (g_type_is_a (type, G_TYPE_APPLICATION) &&
+ (strcmp (pspec->name, "is-remote") == 0))
+ {
+ g_test_message ("skipping GApplication:is-remote");
+ continue;
+ }
+
+ if (g_type_is_a (type, G_TYPE_PROXY_ADDRESS_ENUMERATOR) &&
+ (strcmp (pspec->name, "proxy-resolver") == 0))
+ {
+ g_test_message ("skipping GProxyAddressEnumerator:proxy-resolver");
+ continue;
+ }
+
+ if (g_type_is_a (type, G_TYPE_SOCKET_CLIENT) &&
+ (strcmp (pspec->name, "proxy-resolver") == 0))
+ {
+ g_test_message ("skipping GSocketClient:proxy-resolver");
+ continue;
+ }
+
+ if (g_test_verbose ())
+ g_print ("Property %s.%s\n", g_type_name (pspec->owner_type), pspec->name);
+ g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+ g_object_get_property (instance, pspec->name, &value);
+ check_property ("Property", pspec, &value);
+ g_value_unset (&value);
+ }
+ g_free (pspecs);
+ g_object_unref (instance);
+ g_type_class_unref (klass);
+}
+
+static GType *all_registered_types;
+
+static const GType *
+list_all_types (void)
+{
+ if (!all_registered_types)
+ {
+ GType *tp;
+ all_registered_types = g_new0 (GType, 1000);
+ tp = all_registered_types;
+#include "giotypefuncs.c"
+ *tp = 0;
+ }
+
+ return all_registered_types;
+}
+
+int
+main (int argc, char **argv)
+{
+ const GType *otypes;
+ guint i;
+ GTestDBus *bus;
+ gint result;
+
+ g_setenv ("GIO_USE_VFS", "local", TRUE);
+ g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
+
+ g_test_init (&argc, &argv, NULL);
+
+ /* Create one test bus for all tests, as we have a lot of very small
+ * and quick tests.
+ */
+ bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (bus);
+
+ otypes = list_all_types ();
+ for (i = 0; otypes[i]; i++)
+ {
+ gchar *testname;
+
+ if (!G_TYPE_IS_CLASSED (otypes[i]))
+ continue;
+
+ if (G_TYPE_IS_ABSTRACT (otypes[i]))
+ continue;
+
+ if (!g_type_is_a (otypes[i], G_TYPE_OBJECT))
+ continue;
+
+ testname = g_strdup_printf ("/Default Values/%s",
+ g_type_name (otypes[i]));
+ g_test_add_data_func (testname, &otypes[i], test_type);
+ g_free (testname);
+ }
+
+ result = g_test_run ();
+
+ g_test_dbus_down (bus);
+ g_object_unref (bus);
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]