summaryrefslogtreecommitdiff
path: root/tests/libpeas
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2023-03-17 15:24:11 -0700
committerChristian Hergert <chergert@redhat.com>2023-03-22 16:44:35 -0700
commiteefef26682bea3b82e9c34cb8fad2fdd0af42632 (patch)
tree853f7081ba00122c6ed712c37278409e07d3e69b /tests/libpeas
parentf8f2b53a7fd8626a5ed3a3a5122dea083b6def76 (diff)
downloadlibpeas-eefef26682bea3b82e9c34cb8fad2fdd0af42632.tar.gz
engine: implement GListModel
This commit makes PeasEngine a GListModel containing PeasPluginInfo. Such a design is useful for modern GTK development because it allows binding the engine to various list widgetry. Additionally, you may use a GtkFilterListModel or others to alter or even map the PeasPluginInfo into other forms. This also removes the G_TYPE_POINTER based plugin-list property as that is no longer needed (as well as rather unsafe).
Diffstat (limited to 'tests/libpeas')
-rw-r--r--tests/libpeas/engine.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/tests/libpeas/engine.c b/tests/libpeas/engine.c
index cbc2b4e..cf8a3be 100644
--- a/tests/libpeas/engine.c
+++ b/tests/libpeas/engine.c
@@ -245,23 +245,38 @@ test_engine_not_loadable_plugin (PeasEngine *engine)
g_error_free (error);
}
+static int
+list_index (GListModel *model,
+ PeasPluginInfo *info)
+{
+ guint n_items = g_list_model_get_n_items (model);
+
+ for (guint i = 0; i < n_items; i++)
+ {
+ PeasPluginInfo *item = g_list_model_get_item (model, i);
+ g_object_unref (item);
+
+ if (item == info)
+ return (int)i;
+ }
+
+ return -1;
+}
+
static void
test_engine_plugin_list (PeasEngine *engine)
{
- GList *plugin_list;
const gchar * const *dependencies;
gint builtin_index, loadable_index, two_deps_index;
PeasPluginInfo *builtin_info, *loadable_info, *two_deps_info;
- plugin_list = (GList *) peas_engine_get_plugin_list (engine);
-
builtin_info = peas_engine_get_plugin_info (engine, "builtin");
loadable_info = peas_engine_get_plugin_info (engine, "loadable");
two_deps_info = peas_engine_get_plugin_info (engine, "two-deps");
- builtin_index = g_list_index (plugin_list, builtin_info);
- loadable_index = g_list_index (plugin_list, loadable_info);
- two_deps_index = g_list_index (plugin_list, two_deps_info);
+ builtin_index = list_index (G_LIST_MODEL (engine), builtin_info);
+ loadable_index = list_index (G_LIST_MODEL (engine), loadable_info);
+ two_deps_index = list_index (G_LIST_MODEL (engine), two_deps_info);
g_assert_cmpint (builtin_index, !=, -1);
g_assert_cmpint (loadable_index, !=, -1);