diff options
Diffstat (limited to 'tests/libpeas')
-rw-r--r-- | tests/libpeas/extension-c.c | 6 | ||||
-rw-r--r-- | tests/libpeas/extension-lua.c | 12 | ||||
-rw-r--r-- | tests/libpeas/extension-py.c | 6 | ||||
-rw-r--r-- | tests/libpeas/extension-set.c | 26 | ||||
-rw-r--r-- | tests/libpeas/introspection/introspection-activatable.c | 135 | ||||
-rw-r--r-- | tests/libpeas/introspection/introspection-activatable.h | 51 | ||||
-rw-r--r-- | tests/libpeas/introspection/meson.build | 2 | ||||
-rw-r--r-- | tests/libpeas/plugins/embedded/embedded-plugin.c | 16 | ||||
-rw-r--r-- | tests/libpeas/plugins/embedded/meson.build | 2 | ||||
-rw-r--r-- | tests/libpeas/plugins/extension-python/extension-py.py.in | 5 | ||||
-rw-r--r-- | tests/libpeas/testing/testing-extension.c | 11 |
11 files changed, 230 insertions, 42 deletions
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c index c2e9a24..55c559c 100644 --- a/tests/libpeas/extension-c.c +++ b/tests/libpeas/extension-c.c @@ -31,7 +31,7 @@ #include "plugins/embedded/embedded-plugin.h" #include "plugins/embedded/embedded-resources.h" -#include "peas-activatable.h" +#include "introspection/introspection-activatable.h" static void test_extension_c_embedded (PeasEngine *engine) @@ -67,7 +67,7 @@ test_extension_c_embedded (PeasEngine *engine) g_assert (peas_plugin_info_is_loaded (info)); extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, NULL); g_assert (TESTING_IS_EMBEDDED_PLUGIN (extension)); @@ -137,7 +137,7 @@ test_extension_c_local_linkage (PeasEngine *engine, INTROSPECTION_TYPE_BASE, NULL); loadable_extension = peas_engine_create_extension (engine, loadable_info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, NULL); g_assert (G_IS_OBJECT (c_extension)); diff --git a/tests/libpeas/extension-lua.c b/tests/libpeas/extension-lua.c index 1fbd09e..0818025 100644 --- a/tests/libpeas/extension-lua.c +++ b/tests/libpeas/extension-lua.c @@ -45,18 +45,18 @@ set_garbage_collector_state (PeasEngine *engine, GObject *extension; extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, NULL); if (start) { /* collectgarbage('restart') */ - peas_activatable_activate (PEAS_ACTIVATABLE (extension)); + peas_activatable_activate (INTROSPECTION_ACTIVATABLE (extension)); } else { /* collectgarbage('stop') */ - peas_activatable_deactivate (PEAS_ACTIVATABLE (extension)); + peas_activatable_deactivate (INTROSPECTION_ACTIVATABLE (extension)); } g_object_unref (extension); @@ -71,7 +71,7 @@ test_extension_lua_instance_refcount (PeasEngine *engine, set_garbage_collector_state (engine, info, FALSE); extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, NULL); g_object_add_weak_pointer (extension, (gpointer *) &extension); @@ -87,7 +87,7 @@ test_extension_lua_instance_refcount (PeasEngine *engine, g_assert_cmpint (G_OBJECT (extension)->ref_count, ==, 1); /* Create a new Lua wrapper around the extension */ - peas_activatable_update_state (PEAS_ACTIVATABLE (extension)); + peas_activatable_update_state (INTROSPECTION_ACTIVATABLE (extension)); g_assert_cmpint (G_OBJECT (extension)->ref_count, ==, 2); /* The Lua wrapper still exists */ @@ -120,7 +120,7 @@ test_extension_lua_activatable_subject_refcount (PeasEngine *engine, /* We pre-create the wrapper to make it easier to check reference count */ extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, "object", object, NULL); g_object_add_weak_pointer (extension, (gpointer *) &extension); diff --git a/tests/libpeas/extension-py.c b/tests/libpeas/extension-py.c index 132482f..ed086e2 100644 --- a/tests/libpeas/extension-py.c +++ b/tests/libpeas/extension-py.c @@ -28,9 +28,9 @@ #include "libpeas/peas-engine-priv.h" -#include "peas-activatable.h" - #include "testing/testing-extension.h" + +#include "introspection/introspection-activatable.h" #include "introspection/introspection-base.h" #define PY_LOADER python @@ -73,7 +73,7 @@ test_extension_py_activatable_subject_refcount (PeasEngine *engine, /* we pre-create the wrapper to make it easier to check reference count */ extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, "object", object, NULL); diff --git a/tests/libpeas/extension-set.c b/tests/libpeas/extension-set.c index 06aa318..60cec72 100644 --- a/tests/libpeas/extension-set.c +++ b/tests/libpeas/extension-set.c @@ -29,7 +29,7 @@ #include <glib-object.h> #include <libpeas.h> -#include "peas-activatable.h" +#include "introspection-activatable.h" #include "testing/testing.h" @@ -71,7 +71,7 @@ testing_extension_set_new (PeasEngine *engine, PeasExtensionSet *extension_set; extension_set = peas_extension_set_new (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, "object", NULL, NULL); @@ -106,7 +106,7 @@ testing_extension_set_new (PeasEngine *engine, g_assert (peas_engine_load_plugin (engine, info)); } - /* Load a plugin that does not provide a PeasActivatable */ + /* Load a plugin that does not provide a IntrospectionActivatable */ info = peas_engine_get_plugin_info (engine, "extension-c"); g_assert (peas_engine_load_plugin (engine, info)); @@ -142,7 +142,7 @@ test_extension_set_create_valid (PeasEngine *engine) PeasExtensionSet *extension_set; extension_set = peas_extension_set_new (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, "object", NULL, NULL); @@ -156,7 +156,7 @@ valid_extension_added_cb (PeasExtensionSet *extension_set, GObject **obj_ptr) { g_clear_object (obj_ptr); - g_object_get (PEAS_ACTIVATABLE (extension), "object", obj_ptr, NULL); + g_object_get (INTROSPECTION_ACTIVATABLE (extension), "object", obj_ptr, NULL); } static void @@ -174,7 +174,7 @@ test_extension_set_create_valid_with_properties (PeasEngine *engine) g_value_set_object (&prop_value, obj); extension_set = peas_extension_set_new_with_properties (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, G_N_ELEMENTS (prop_names), prop_names, &prop_value); @@ -202,7 +202,7 @@ test_extension_set_create_invalid (PeasEngine *engine) PeasExtensionSet *extension_set; testing_util_push_log_hook ("*assertion*G_TYPE_IS_INTERFACE*failed"); - testing_util_push_log_hook ("*type 'PeasActivatable' has no property named 'invalid-property'"); + testing_util_push_log_hook ("*type 'IntrospectionActivatable' has no property named 'invalid-property'"); /* Invalid GType */ extension_set = peas_extension_set_new (engine, G_TYPE_INVALID, NULL); @@ -216,7 +216,7 @@ test_extension_set_create_invalid (PeasEngine *engine) /* Interface does not have an 'invalid-property' property */ extension_set = peas_extension_set_new (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, "invalid-property", "does-not-exist", NULL); g_assert (!PEAS_IS_EXTENSION_SET (extension_set)); @@ -242,7 +242,7 @@ test_extension_set_create_invalid_with_properties (PeasEngine *engine) /* Interface has a NULL property name*/ n_elements = G_N_ELEMENTS (prop_values); extension_set = peas_extension_set_new_with_properties (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, n_elements, prop_names, prop_values); @@ -258,7 +258,7 @@ test_extension_set_create_invalid_with_properties (PeasEngine *engine) /* Uninitialized GValue */ n_elements = 1; extension_set = peas_extension_set_new_with_properties (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, n_elements, prop_names, prop_values); @@ -269,7 +269,7 @@ test_extension_set_create_invalid_with_properties (PeasEngine *engine) g_value_set_pointer (&prop_values[0], NULL); n_elements = G_N_ELEMENTS (prop_names_not_exist); extension_set = peas_extension_set_new_with_properties (engine, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, n_elements, prop_names_not_exist, prop_values); @@ -307,7 +307,7 @@ test_extension_set_extension_removed (PeasEngine *engine) extension_set = testing_extension_set_new (engine, &active); - /* Unload the plugin that does not provide a PeasActivatable */ + /* Unload the plugin that does not provide a IntrospectionActivatable */ info = peas_engine_get_plugin_info (engine, "extension-c"); g_assert (peas_engine_unload_plugin (engine, info)); @@ -337,7 +337,7 @@ test_extension_set_get_extension (PeasEngine *engine) info = peas_engine_get_plugin_info (engine, loadable_plugins[0]); extension = peas_extension_set_get_extension (extension_set, info); - g_assert (PEAS_IS_ACTIVATABLE (extension)); + g_assert (INTROSPECTION_IS_ACTIVATABLE (extension)); g_object_add_weak_pointer (G_OBJECT (extension), (gpointer) &extension); diff --git a/tests/libpeas/introspection/introspection-activatable.c b/tests/libpeas/introspection/introspection-activatable.c new file mode 100644 index 0000000..1805c61 --- /dev/null +++ b/tests/libpeas/introspection/introspection-activatable.c @@ -0,0 +1,135 @@ +/* + * introspection-activatable.c + * This file is part of libintrospection + * + * Copyright (C) 2010 Steve Frécinaux + * + * libintrospection 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. + * + * libintrospection 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. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "config.h" + +#include "introspection-activatable.h" + +/** + * IntrospectionActivatable: + * + * Interface for activatable plugins. + * + * #IntrospectionActivatable is an interface which should be implemented by plugins + * that should be activated on an object of a certain type (depending on the + * application). For instance, in a typical windowed application, + * #IntrospectionActivatable plugin instances could be bound to individual toplevel + * windows. + * + * It is typical to use #IntrospectionActivatable along with [class@ExtensionSet] in order + * to activate and deactivate extensions automatically when plugins are loaded + * or unloaded. + * + * You can also use the code of this interface as a base for your own + * extension types, as illustrated by gedit's %GeditWindowActivatable and + * %GeditDocumentActivatable interfaces. + **/ + +G_DEFINE_INTERFACE(IntrospectionActivatable, introspection_activatable, G_TYPE_OBJECT) + +static void +introspection_activatable_default_init (IntrospectionActivatableInterface *iface) +{ + /** + * IntrospectionActivatable:object: + * + * The object property contains the targetted object for this #IntrospectionActivatable + * instance. + * + * For example a toplevel window in a typical windowed application. It is set + * at construction time and won't change. + */ + g_object_interface_install_property (iface, + g_param_spec_object ("object", + "Object", + "Object", + G_TYPE_OBJECT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} + +/** + * introspection_activatable_activate: + * @activatable: A #IntrospectionActivatable. + * + * Activates the extension on the targetted object. + * + * On activation, the extension should hook itself to the object + * where it makes sense. + */ +void +introspection_activatable_activate (IntrospectionActivatable *activatable) +{ + IntrospectionActivatableInterface *iface; + + g_return_if_fail (INTROSPECTION_IS_ACTIVATABLE (activatable)); + + iface = INTROSPECTION_ACTIVATABLE_GET_IFACE (activatable); + g_return_if_fail (iface->activate != NULL); + + iface->activate (activatable); +} + +/** + * introspection_activatable_deactivate: + * @activatable: A #IntrospectionActivatable. + * + * Deactivates the extension on the targetted object. + * + * On deactivation, an extension should remove itself from all the hooks it + * used and should perform any cleanup required, so it can be unreffed safely + * and without any more effect on the host application. + */ +void +introspection_activatable_deactivate (IntrospectionActivatable *activatable) +{ + IntrospectionActivatableInterface *iface; + + g_return_if_fail (INTROSPECTION_IS_ACTIVATABLE (activatable)); + + iface = INTROSPECTION_ACTIVATABLE_GET_IFACE (activatable); + g_return_if_fail (iface->deactivate != NULL); + + iface->deactivate (activatable); +} + +/** + * introspection_activatable_update_state: + * @activatable: A #IntrospectionActivatable. + * + * Triggers an update of the extension internal state to take into account + * state changes in the targetted object, due to some event or user action. + */ +void +introspection_activatable_update_state (IntrospectionActivatable *activatable) +{ + IntrospectionActivatableInterface *iface; + + g_return_if_fail (INTROSPECTION_IS_ACTIVATABLE (activatable)); + + iface = INTROSPECTION_ACTIVATABLE_GET_IFACE (activatable); + if (iface->update_state != NULL) + iface->update_state (activatable); +} + diff --git a/tests/libpeas/introspection/introspection-activatable.h b/tests/libpeas/introspection/introspection-activatable.h new file mode 100644 index 0000000..c38456a --- /dev/null +++ b/tests/libpeas/introspection/introspection-activatable.h @@ -0,0 +1,51 @@ +/* + * introspection-activatable.h + * This file is part of libintrospection + * + * Copyright (C) 2010 - Steve Frécinaux + * + * libintrospection 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. + * + * libintrospection 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. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define INTROSPECTION_TYPE_ACTIVATABLE (introspection_activatable_get_type ()) +#define INTROSPECTION_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INTROSPECTION_TYPE_ACTIVATABLE, IntrospectionActivatable)) +#define INTROSPECTION_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), INTROSPECTION_TYPE_ACTIVATABLE, IntrospectionActivatableInterface)) +#define INTROSPECTION_IS_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INTROSPECTION_TYPE_ACTIVATABLE)) +#define INTROSPECTION_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), INTROSPECTION_TYPE_ACTIVATABLE, IntrospectionActivatableInterface)) + +typedef struct _IntrospectionActivatable IntrospectionActivatable; /* dummy typedef */ +typedef struct _IntrospectionActivatableInterface IntrospectionActivatableInterface; + +struct _IntrospectionActivatableInterface { + GTypeInterface g_iface; + void (*activate) (IntrospectionActivatable *activatable); + void (*deactivate) (IntrospectionActivatable *activatable); + void (*update_state) (IntrospectionActivatable *activatable); +}; + +GType introspection_activatable_get_type (void) G_GNUC_CONST; +void introspection_activatable_activate (IntrospectionActivatable *activatable); +void introspection_activatable_deactivate (IntrospectionActivatable *activatable); +void introspection_activatable_update_state (IntrospectionActivatable *activatable); + +G_END_DECLS diff --git a/tests/libpeas/introspection/meson.build b/tests/libpeas/introspection/meson.build index f2e3853..a7eb8c1 100644 --- a/tests/libpeas/introspection/meson.build +++ b/tests/libpeas/introspection/meson.build @@ -3,6 +3,7 @@ libintrospection_string = '@0@-@1@'.format(libintrospection_name, api_version) libintrospection_public_h = [ 'introspection-abstract.h', + 'introspection-activatable.h', 'introspection-base.h', 'introspection-callable.h', 'introspection-has-prerequisite.h', @@ -12,6 +13,7 @@ libintrospection_public_h = [ libintrospection_c = [ 'introspection-abstract.c', + 'introspection-activatable.c', 'introspection-base.c', 'introspection-callable.c', 'introspection-has-prerequisite.c', diff --git a/tests/libpeas/plugins/embedded/embedded-plugin.c b/tests/libpeas/plugins/embedded/embedded-plugin.c index 747b2c5..22fe447 100644 --- a/tests/libpeas/plugins/embedded/embedded-plugin.c +++ b/tests/libpeas/plugins/embedded/embedded-plugin.c @@ -29,21 +29,21 @@ #include "embedded-plugin.h" -#include "peas-activatable.h" +#include "introspection-activatable.h" typedef struct { GObject *object; } TestingEmbeddedPluginPrivate; -static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void introspection_activatable_iface_init (IntrospectionActivatableInterface *iface); G_DEFINE_TYPE_EXTENDED (TestingEmbeddedPlugin, testing_embedded_plugin, PEAS_TYPE_EXTENSION_BASE, 0, G_ADD_PRIVATE (TestingEmbeddedPlugin) - G_IMPLEMENT_INTERFACE (PEAS_TYPE_ACTIVATABLE, - peas_activatable_iface_init)) + G_IMPLEMENT_INTERFACE (INTROSPECTION_TYPE_ACTIVATABLE, + introspection_activatable_iface_init)) #define GET_PRIV(o) \ (testing_embedded_plugin_get_instance_private (o)) @@ -101,12 +101,12 @@ testing_embedded_plugin_init (TestingEmbeddedPlugin *plugin) } static void -testing_embedded_plugin_activate (PeasActivatable *activatable) +testing_embedded_plugin_activate (IntrospectionActivatable *activatable) { } static void -testing_embedded_plugin_deactivate (PeasActivatable *activatable) +testing_embedded_plugin_deactivate (IntrospectionActivatable *activatable) { } @@ -122,7 +122,7 @@ testing_embedded_plugin_class_init (TestingEmbeddedPluginClass *klass) } static void -peas_activatable_iface_init (PeasActivatableInterface *iface) +introspection_activatable_iface_init (IntrospectionActivatableInterface *iface) { iface->activate = testing_embedded_plugin_activate; iface->deactivate = testing_embedded_plugin_deactivate; @@ -132,6 +132,6 @@ G_MODULE_EXPORT void testing_embedded_plugin_register_types (PeasObjectModule *module) { peas_object_module_register_extension_type (module, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, TESTING_TYPE_EMBEDDED_PLUGIN); } diff --git a/tests/libpeas/plugins/embedded/meson.build b/tests/libpeas/plugins/embedded/meson.build index bd8b81b..c7711b9 100644 --- a/tests/libpeas/plugins/embedded/meson.build +++ b/tests/libpeas/plugins/embedded/meson.build @@ -33,7 +33,7 @@ libembedded_res = gnome.compile_resources( libembedded_deps = [ glib_dep, libpeas_dep, - libtesting_util_dep, + libintrospection_dep, ] libembedded_lib = shared_library( diff --git a/tests/libpeas/plugins/extension-python/extension-py.py.in b/tests/libpeas/plugins/extension-python/extension-py.py.in index 59070c4..75e8cd1 100644 --- a/tests/libpeas/plugins/extension-python/extension-py.py.in +++ b/tests/libpeas/plugins/extension-python/extension-py.py.in @@ -21,7 +21,7 @@ import threading -from gi.repository import GObject, Introspection, Peas +from gi.repository import GObject, Introspection __all__ = [ 'ExtensionPythonAbstract', 'ExtensionPythonPlugin' ] @@ -31,7 +31,8 @@ class ExtensionPythonAbstract(Introspection.Abstract): pass -class ExtensionPythonPlugin(Introspection.Prerequisite, Peas.Activatable, +class ExtensionPythonPlugin(Introspection.Prerequisite, + Introspection.Activatable, Introspection.Base, Introspection.Callable, Introspection.HasPrerequisite): diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c index 796bcc8..d4790d5 100644 --- a/tests/libpeas/testing/testing-extension.c +++ b/tests/libpeas/testing/testing-extension.c @@ -34,13 +34,12 @@ #include "testing-extension.h" #include "introspection-abstract.h" +#include "introspection-activatable.h" #include "introspection-base.h" #include "introspection-callable.h" #include "introspection-has-prerequisite.h" #include "introspection-unimplemented.h" -#include "peas-activatable.h" - typedef struct _TestFixture TestFixture; struct _TestFixture { @@ -477,13 +476,13 @@ test_extension_multiple_threads_nonglobal_loaders (PeasEngine *engine, } static void -multiple_threads_callbacks_in_thread (guint nth_thread, - PeasActivatable *activatable) +multiple_threads_callbacks_in_thread (guint nth_thread, + IntrospectionActivatable *activatable) { gint i; for (i = 0; i < 100; ++i) - peas_activatable_update_state (activatable); + introspection_activatable_update_state (activatable); } static void @@ -494,7 +493,7 @@ test_extension_multiple_threads_callbacks (PeasEngine *engine, gint n_threads, update_count; extension = peas_engine_create_extension (engine, info, - PEAS_TYPE_ACTIVATABLE, + INTROSPECTION_TYPE_ACTIVATABLE, NULL); n_threads = run_in_multiple_threads ((GFunc) multiple_threads_callbacks_in_thread, |