mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-05 19:15:32 +00:00
tests: use plugin load API
This commit is contained in:
parent
9e92fb88af
commit
e3597f4a88
1 changed files with 8 additions and 52 deletions
|
@ -11,54 +11,6 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <libpeas/peas.h>
|
||||
|
||||
static CallsProvider *
|
||||
get_plugin (const gchar *name)
|
||||
{
|
||||
/* This is pretty much a copy of load_plugin () from calls-manager.c */
|
||||
g_autoptr (GError) error = NULL;
|
||||
PeasEngine *plugins;
|
||||
PeasPluginInfo *info;
|
||||
PeasExtension *extension;
|
||||
|
||||
// Add Calls search path and rescan
|
||||
plugins = peas_engine_get_default ();
|
||||
|
||||
// Find the plugin
|
||||
info = peas_engine_get_plugin_info (plugins, name);
|
||||
if (!info) {
|
||||
g_debug ("Could not find plugin `%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Possibly load the plugin
|
||||
if (!peas_plugin_info_is_loaded (info)) {
|
||||
peas_engine_load_plugin (plugins, info);
|
||||
|
||||
if (!peas_plugin_info_is_available (info, &error)) {
|
||||
g_debug ("Error loading plugin `%s': %s", name, error->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_debug ("Loaded plugin `%s'", name);
|
||||
}
|
||||
|
||||
// Check the plugin provides CallsProvider
|
||||
if (!peas_engine_provides_extension (plugins, info, CALLS_TYPE_PROVIDER)) {
|
||||
g_debug ("Plugin `%s' does not have a provider extension", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get the extension
|
||||
extension = peas_engine_create_extensionv (plugins, info, CALLS_TYPE_PROVIDER, 0, NULL);
|
||||
if (!extension) {
|
||||
g_debug ("Could not create provider from plugin `%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_debug ("Created provider from plugin `%s'", name);
|
||||
return CALLS_PROVIDER (extension);
|
||||
}
|
||||
|
||||
static void
|
||||
test_calls_plugin_loading ()
|
||||
{
|
||||
|
@ -67,17 +19,21 @@ test_calls_plugin_loading ()
|
|||
g_autoptr (CallsProvider) ofono_provider = NULL;
|
||||
g_autoptr (CallsProvider) not_a_provider = NULL;
|
||||
|
||||
dummy_provider = get_plugin ("dummy");
|
||||
dummy_provider = calls_provider_load_plugin ("dummy");
|
||||
g_assert_nonnull (dummy_provider);
|
||||
|
||||
mm_provider = get_plugin ("mm");
|
||||
mm_provider = calls_provider_load_plugin ("mm");
|
||||
g_assert_nonnull (mm_provider);
|
||||
|
||||
ofono_provider = get_plugin ("ofono");
|
||||
ofono_provider = calls_provider_load_plugin ("ofono");
|
||||
g_assert_nonnull (ofono_provider);
|
||||
|
||||
not_a_provider = get_plugin ("not-a-valid-provider-plugin");
|
||||
not_a_provider = calls_provider_load_plugin ("not-a-valid-provider-plugin");
|
||||
g_assert_null (not_a_provider);
|
||||
|
||||
calls_provider_unload_plugin ("dummy");
|
||||
calls_provider_unload_plugin ("mm");
|
||||
calls_provider_unload_plugin ("ofono");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue