plugin-manager: Add API to unload all plugins

And add tests for it.

Signed-off-by: Evangelos Ribeiro Tzaras <devrtz@fortysixandtwo.eu>
Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/796>
This commit is contained in:
Evangelos Ribeiro Tzaras
2025-10-13 10:43:04 +02:00
parent 33e5b193a0
commit 9fab9ec7a5
4 changed files with 62 additions and 3 deletions

View File

@@ -439,3 +439,25 @@ calls_plugin_manager_get_plugin_names (CallsPluginManager *self,
return (const char **) g_ptr_array_free (array, FALSE);
}
gboolean
calls_plugin_manager_unload_all_plugins (CallsPluginManager *self, GError **error)
{
GListModel *plugins;
uint n_plugins;
gboolean ok = TRUE;
g_return_val_if_fail (CALLS_IS_PLUGIN_MANAGER (self), FALSE);
plugins = G_LIST_MODEL (self->plugins);
n_plugins = g_list_model_get_n_items (plugins);
for (uint i = 0; i < n_plugins; i++) {
g_autoptr (CallsPlugin) plugin = g_list_model_get_item (plugins, i);
if (calls_plugin_is_loaded (plugin))
ok = ok && calls_plugin_unload (plugin, error);
}
return ok;
}

View File

@@ -40,6 +40,7 @@ gboolean calls_plugin_manager_load_plugin (CallsPluginManager *self,
gboolean calls_plugin_manager_unload_plugin (CallsPluginManager *self,
const char *name,
GError **error);
gboolean calls_plugin_manager_unload_all_plugins (CallsPluginManager *self, GError **error);
const char **calls_plugin_manager_get_plugin_names (CallsPluginManager *self,
guint *length);
gboolean calls_plugin_manager_has_plugin (CallsPluginManager *self,

View File

@@ -66,6 +66,9 @@ on_idle_quit (gpointer user_data)
g_application_quit (app);
g_assert_true (calls_plugin_manager_has_any_plugins (plugins));
g_assert_true (calls_plugin_manager_unload_all_plugins (plugins, &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_any_plugins (plugins));
return G_SOURCE_REMOVE;
}

View File

@@ -112,13 +112,46 @@ test_calls_plugin_loading (void)
}
gint
main (gint argc,
gchar *argv[])
static void
test_calls_plugin_unload_all (void)
{
CallsPluginManager *manager = calls_plugin_manager_get_default ();
g_autoptr (GError) error = NULL;
g_assert_false (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_load_plugin (manager, "dummy", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_plugin (manager, "dummy"));
g_assert_true (calls_plugin_manager_load_plugin (manager, "mm", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_plugin (manager, "mm"));
g_assert_true (calls_plugin_manager_load_plugin (manager, "sip", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_plugin (manager, "sip"));
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_unload_all_plugins (manager, &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_plugin (manager, "dummy"));
g_assert_false (calls_plugin_manager_has_plugin (manager, "mm"));
g_assert_false (calls_plugin_manager_has_plugin (manager, "sip"));
g_assert_false (calls_plugin_manager_has_any_plugins (manager));
g_assert_finalize_object (manager);
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/Calls/Plugins/load_plugins", test_calls_plugin_loading);
g_test_add_func ("/Calls/Plugins/unload_all", test_calls_plugin_unload_all);
return g_test_run ();
}