diff options
author | Garrett Regier <garrettregier@gmail.com> | 2017-03-24 12:41:09 -0700 |
---|---|---|
committer | Garrett Regier <garrettregier@gmail.com> | 2017-03-24 21:27:15 -0700 |
commit | 7e7e850d24a930ffdaf04d0feaf6607fe797f30e (patch) | |
tree | dbde908fd4a0969afe0ee49fd668a1f74f540009 /tests | |
parent | 743ca63655ac23c24efed5aad33479fa1f4faadf (diff) | |
download | libpeas-7e7e850d24a930ffdaf04d0feaf6607fe797f30e.tar.gz |
Allow extensions to be an Abstract Base Class
https://bugzilla.gnome.org/show_bug.cgi?id=767223
Diffstat (limited to 'tests')
10 files changed, 372 insertions, 3 deletions
diff --git a/tests/libpeas/introspection/Makefile.am b/tests/libpeas/introspection/Makefile.am index 930851b..3ea3758 100644 --- a/tests/libpeas/introspection/Makefile.am +++ b/tests/libpeas/introspection/Makefile.am @@ -13,6 +13,8 @@ libintrospection_1_0_la_LIBADD = \ $(top_builddir)/libpeas/libpeas-1.0.la libintrospection_1_0_la_SOURCES = \ + introspection-abstract.c \ + introspection-abstract.h \ introspection-base.c \ introspection-base.h \ introspection-callable.c \ diff --git a/tests/libpeas/introspection/introspection-abstract.c b/tests/libpeas/introspection/introspection-abstract.c new file mode 100644 index 0000000..0363d0a --- /dev/null +++ b/tests/libpeas/introspection/introspection-abstract.c @@ -0,0 +1,132 @@ +/* + * introspection-abstract.h + * This file is part of libpeas + * + * Copyright (C) 2017 Garrett Regier + * + * libpeas is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * libpeas 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "introspection-abstract.h" + +typedef struct { + gint value; +} IntrospectionAbstractPrivate; + +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IntrospectionAbstract, + introspection_abstract, + PEAS_TYPE_EXTENSION_BASE) + +#define GET_PRIV(o) \ + (introspection_abstract_get_instance_private (o)) + +enum { + PROP_0, + PROP_ABSTRACT_PROPERTY, + N_PROPERTIES +}; + +static GParamSpec *properties[N_PROPERTIES] = { NULL }; + +static void +introspection_abstract_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + IntrospectionAbstract *abstract = INTROSPECTION_ABSTRACT (object); + IntrospectionAbstractPrivate *priv = GET_PRIV (abstract); + + switch (prop_id) + { + case PROP_ABSTRACT_PROPERTY: + g_value_set_int (value, priv->value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +introspection_abstract_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + IntrospectionAbstract *abstract = INTROSPECTION_ABSTRACT (object); + IntrospectionAbstractPrivate *priv = GET_PRIV (abstract); + + switch (prop_id) + { + case PROP_ABSTRACT_PROPERTY: + priv->value = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +introspection_abstract_class_init (IntrospectionAbstractClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = introspection_abstract_get_property; + object_class->set_property = introspection_abstract_set_property; + + properties[PROP_ABSTRACT_PROPERTY] = + g_param_spec_int ("abstract-property", + "Abstract Property", + "The IntrospectionAbstract", + G_MININT, + G_MAXINT, + -1, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, N_PROPERTIES, properties); +} + +static void +introspection_abstract_init (IntrospectionAbstract *prereq) +{ +} + +gint +introspection_abstract_get_value (IntrospectionAbstract *abstract) +{ + IntrospectionAbstractPrivate *priv = GET_PRIV (abstract); + + g_return_val_if_fail (INTROSPECTION_IS_ABSTRACT (abstract), -1); + + return priv->value; +} + +void +introspection_abstract_set_value (IntrospectionAbstract *abstract, + gint value) +{ + IntrospectionAbstractPrivate *priv = GET_PRIV (abstract); + + g_return_if_fail (INTROSPECTION_IS_ABSTRACT (abstract)); + + priv->value = value; +} diff --git a/tests/libpeas/introspection/introspection-abstract.h b/tests/libpeas/introspection/introspection-abstract.h new file mode 100644 index 0000000..bfff2c4 --- /dev/null +++ b/tests/libpeas/introspection/introspection-abstract.h @@ -0,0 +1,60 @@ +/* + * introspection-abstract.h + * This file is part of libpeas + * + * Copyright (C) 2017 Garrett Regier + * + * libpeas is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * libpeas 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __INTROSPECTION_ABSTRACT_H__ +#define __INTROSPECTION_ABSTRACT_H__ + +#include <libpeas/peas.h> + +G_BEGIN_DECLS + +/* + * Type checking and casting macros + */ +#define INTROSPECTION_TYPE_ABSTRACT (introspection_abstract_get_type ()) +#define INTROSPECTION_ABSTRACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INTROSPECTION_TYPE_ABSTRACT, IntrospectionAbstract)) +#define INTROSPECTION_ABSTRACT_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), INTROSPECTION_TYPE_ABSTRACT, IntrospectionAbstractClass)) +#define INTROSPECTION_IS_ABSTRACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INTROSPECTION_TYPE_ABSTRACT)) +#define INTROSPECTION_ABSTRACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INTROSPECTION_TYPE_ABSTRACT, IntrospectionAbstractClass)) + +typedef struct _IntrospectionAbstract IntrospectionAbstract; +typedef struct _IntrospectionAbstractClass IntrospectionAbstractClass; + +struct _IntrospectionAbstract { + PeasExtensionBase parent; +}; + +struct _IntrospectionAbstractClass { + PeasExtensionBaseClass parent_class; +}; + +/* + * Public methods + */ +GType introspection_abstract_get_type (void) G_GNUC_CONST; + +gint introspection_abstract_get_value (IntrospectionAbstract *abstract); +void introspection_abstract_set_value (IntrospectionAbstract *abstract, + gint value); + +G_END_DECLS + +#endif /* __INTROSPECTION_ABSTRACT_H__ */ diff --git a/tests/libpeas/plugins/extension-c/Makefile.am b/tests/libpeas/plugins/extension-c/Makefile.am index 751b68b..24effac 100644 --- a/tests/libpeas/plugins/extension-c/Makefile.am +++ b/tests/libpeas/plugins/extension-c/Makefile.am @@ -12,7 +12,9 @@ noinst_LTLIBRARIES = \ libextension-c-missing-symbol.la libextension_c_la_SOURCES = \ - extension-c-plugin.c \ + extension-c-abstract.c \ + extension-c-abstract.h \ + extension-c-plugin.c \ extension-c-plugin.h libextension_c_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS) diff --git a/tests/libpeas/plugins/extension-c/extension-c-abstract.c b/tests/libpeas/plugins/extension-c/extension-c-abstract.c new file mode 100644 index 0000000..c6f767e --- /dev/null +++ b/tests/libpeas/plugins/extension-c/extension-c-abstract.c @@ -0,0 +1,55 @@ +/* + * extension-c-abstract.c + * This file is part of libpeas + * + * Copyright (C) 2017 - Garrett Regier + * + * libpeas is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * libpeas 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib-object.h> + +#include <libpeas/peas.h> + +#include "extension-c-abstract.h" + +G_DEFINE_DYNAMIC_TYPE (TestingExtensionCAbstract, + testing_extension_c_abstract, + INTROSPECTION_TYPE_ABSTRACT) + +static void +testing_extension_c_abstract_init (TestingExtensionCAbstract *abstract) +{ +} + +static void +testing_extension_c_abstract_class_init (TestingExtensionCAbstractClass *klass) +{ +} + +static void +testing_extension_c_abstract_class_finalize (TestingExtensionCAbstractClass *klass) +{ +} + +void +testing_extension_c_abstract_register (GTypeModule *module) +{ + testing_extension_c_abstract_register_type (module); +} diff --git a/tests/libpeas/plugins/extension-c/extension-c-abstract.h b/tests/libpeas/plugins/extension-c/extension-c-abstract.h new file mode 100644 index 0000000..57d35c3 --- /dev/null +++ b/tests/libpeas/plugins/extension-c/extension-c-abstract.h @@ -0,0 +1,52 @@ +/* + * extension-c-abstract.h + * This file is part of libpeas + * + * Copyright (C) 2017 - Garrett Regier + * + * libpeas is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * libpeas 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __EXTENSION_C_ABSTRACT_H__ +#define __EXTENSION_C_ABSTRACT_H__ + +#include "introspection-abstract.h" + +G_BEGIN_DECLS + +#define TESTING_TYPE_EXTENSION_C_ABSTRACT (testing_extension_c_abstract_get_type ()) +#define TESTING_EXTENSION_C_ABSTRACT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TESTING_TYPE_EXTENSION_C_ABSTRACT, TestingExtensionCAbstract)) +#define TESTING_EXTENSION_C_ABSTRACT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TESTING_TYPE_EXTENSION_C_ABSTRACT, TestingExtensionCAbstract)) +#define TESTING_IS_EXTENSION_C_ABSTRACT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TESTING_TYPE_EXTENSION_C_ABSTRACT)) +#define TESTING_IS_EXTENSION_C_ABSTRACT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TESTING_TYPE_EXTENSION_C_ABSTRACT)) +#define TESTING_EXTENSION_C_ABSTRACT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TESTING_TYPE_EXTENSION_C_ABSTRACT, TestingExtensionCAbstractClass)) + +typedef struct _TestingExtensionCAbstract TestingExtensionCAbstract; +typedef struct _TestingExtensionCAbstractClass TestingExtensionCAbstractClass; + +struct _TestingExtensionCAbstract { + IntrospectionAbstract parent_instance; +}; + +struct _TestingExtensionCAbstractClass { + IntrospectionAbstractClass parent_class; +}; + +GType testing_extension_c_abstract_get_type (void) G_GNUC_CONST; +void testing_extension_c_abstract_register (GTypeModule *module); + +G_END_DECLS + +#endif /* __EXTENSION_C_ABSTRACT_H__ */ diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.c b/tests/libpeas/plugins/extension-c/extension-c-plugin.c index 3125de8..1e4b283 100644 --- a/tests/libpeas/plugins/extension-c/extension-c-plugin.c +++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.c @@ -29,11 +29,13 @@ #include <libpeas/peas.h> +#include "introspection-abstract.h" #include "introspection-base.h" #include "introspection-callable.h" #include "introspection-has-prerequisite.h" #include "introspection-prerequisite.h" +#include "extension-c-abstract.h" #include "extension-c-plugin.h" /* Used by the local linkage test */ @@ -175,9 +177,14 @@ testing_extension_c_plugin_class_finalize (TestingExtensionCPluginClass *klass) G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module) { + testing_extension_c_abstract_register (G_TYPE_MODULE (module)); testing_extension_c_plugin_register_type (G_TYPE_MODULE (module)); peas_object_module_register_extension_type (module, + INTROSPECTION_TYPE_ABSTRACT, + TESTING_TYPE_EXTENSION_C_ABSTRACT); + + peas_object_module_register_extension_type (module, INTROSPECTION_TYPE_BASE, TESTING_TYPE_EXTENSION_C_PLUGIN); peas_object_module_register_extension_type (module, diff --git a/tests/libpeas/plugins/extension-lua/extension-lua51.lua b/tests/libpeas/plugins/extension-lua/extension-lua51.lua index 69df5f7..66ee571 100644 --- a/tests/libpeas/plugins/extension-lua/extension-lua51.lua +++ b/tests/libpeas/plugins/extension-lua/extension-lua51.lua @@ -22,6 +22,10 @@ local Introspection = lgi.Introspection local Peas = lgi.Peas +local ExtensionLuaAbstract = + Introspection.Abstract:derive('ExtensionLuaAbstract') + + local ExtensionLuaPlugin = Introspection.Prerequisite:derive('ExtensionLuaPlugin', { Peas.Activatable, @@ -100,6 +104,6 @@ assert(pcall(function() __STRICT = true end)) -return { ExtensionLuaPlugin } +return { ExtensionLuaAbstract, ExtensionLuaPlugin } -- ex:set ts=4 et sw=4 ai: diff --git a/tests/libpeas/plugins/extension-python/extension-py.py.in b/tests/libpeas/plugins/extension-python/extension-py.py.in index d5ea6fa..59070c4 100644 --- a/tests/libpeas/plugins/extension-python/extension-py.py.in +++ b/tests/libpeas/plugins/extension-python/extension-py.py.in @@ -24,7 +24,11 @@ import threading from gi.repository import GObject, Introspection, Peas -__all__ = [ 'ExtensionPythonPlugin' ] +__all__ = [ 'ExtensionPythonAbstract', 'ExtensionPythonPlugin' ] + + +class ExtensionPythonAbstract(Introspection.Abstract): + pass class ExtensionPythonPlugin(Introspection.Prerequisite, Peas.Activatable, diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c index 60e88f4..e00588b 100644 --- a/tests/libpeas/testing/testing-extension.c +++ b/tests/libpeas/testing/testing-extension.c @@ -33,6 +33,7 @@ #include "testing.h" #include "testing-extension.h" +#include "introspection-abstract.h" #include "introspection-base.h" #include "introspection-callable.h" #include "introspection-has-prerequisite.h" @@ -264,6 +265,29 @@ test_extension_get_settings (PeasEngine *engine, g_object_unref (extension); } +static void +test_extension_abstract (PeasEngine *engine, + PeasPluginInfo *info) +{ + PeasExtension *extension; + IntrospectionAbstract *abstract; + + g_assert (peas_engine_load_plugin (engine, info)); + + extension = peas_engine_create_extension (engine, info, + INTROSPECTION_TYPE_ABSTRACT, + "abstract-property", 47, + NULL); + + abstract = INTROSPECTION_ABSTRACT (extension); + + g_assert_cmpint (introspection_abstract_get_value (abstract), ==, 47); + introspection_abstract_set_value (abstract, -22); + g_assert_cmpint (introspection_abstract_get_value (abstract), ==, -22); + + g_object_unref (extension); +} + static gint run_in_multiple_threads (GFunc func, gpointer user_data) @@ -479,6 +503,30 @@ test_extension_call_multi_args (PeasEngine *engine, g_object_unref (extension); } +static void +test_extension_call_abstract (PeasEngine *engine, + PeasPluginInfo *info) +{ + PeasExtension *extension; + gint value = 0; + + g_assert (peas_engine_load_plugin (engine, info)); + + extension = peas_engine_create_extension (engine, info, + INTROSPECTION_TYPE_ABSTRACT, + "abstract-property", 47, + NULL); + + g_assert (peas_extension_call (extension, "get_value", &value)); + g_assert_cmpint (value, ==, 47); + + g_assert (peas_extension_call (extension, "set_value", -22)); + g_assert (peas_extension_call (extension, "get_value", &value)); + g_assert_cmpint (value, ==, -22); + + g_object_unref (extension); +} + #define _EXTENSION_TEST(loader, path, ftest) \ G_STMT_START { \ gchar *full_path = g_strdup_printf (EXTENSION_TEST_NAME (%s, "%s"), \ @@ -533,6 +581,8 @@ testing_extension_basic (const gchar *loader_) _EXTENSION_TEST (loader, "plugin-info", plugin_info); _EXTENSION_TEST (loader, "get-settings", get_settings); + _EXTENSION_TEST (loader, "abstract", abstract); + _EXTENSION_TEST (loader, "multiple-threads/global-loaders", multiple_threads_global_loaders); _EXTENSION_TEST (loader, "multiple-threads/nonglobal-loaders", @@ -553,6 +603,7 @@ testing_extension_callable (const gchar *loader) _EXTENSION_TEST (loader, "call-with-return", call_with_return); _EXTENSION_TEST (loader, "call-single-arg", call_single_arg); _EXTENSION_TEST (loader, "call-multi-args", call_multi_args); + _EXTENSION_TEST (loader, "call-abstract", call_abstract); } void |