diff --git a/tests/meson.build b/tests/meson.build index 618b1c4..8d94c29 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -12,11 +12,13 @@ test_env = [ test_cflags = [ '-fPIE', - '-DFOR_TESTING', '-Wno-error=deprecated-declarations', '-DPLUGIN_BUILDDIR="@0@"'.format(full_calls_plugin_builddir), ] +test_cflags_with_test_define = test_cflags +test_cflags_with_test_define += [ '-DFOR_TESTING' ] + test_link_args = [ '-fPIC', ] @@ -44,7 +46,7 @@ foreach test : tests t = executable(name, test_sources, calls_sources, dummy_sources, calls_enum_sources, calls_resources, wl_proto_sources, wayland_sources, - c_args : test_cflags, + c_args : test_cflags_with_test_define, link_args: test_link_args, link_with : calls_vala, dependencies: calls_deps, @@ -71,5 +73,19 @@ t = executable('manager', test_sources, ) test('manager', t, env: test_env) +test_sources = [ 'test-plugins.c' ] + +t = executable('plugins', test_sources, + calls_sources, calls_enum_sources, calls_resources, + wl_proto_sources, wayland_sources, + c_args : test_cflags, + link_args: test_link_args, + link_with : calls_vala, + dependencies: calls_deps, + include_directories : [ + calls_includes + ] + ) +test('plugins', t, env: test_env) endif diff --git a/tests/test-plugins.c b/tests/test-plugins.c new file mode 100644 index 0000000..0018c69 --- /dev/null +++ b/tests/test-plugins.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2020 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0+ + * + * Author: Evangelos Ribeiro Tzaras + */ + +#include "calls-provider.h" + +#include +#include + +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 () +{ + g_autoptr (CallsProvider) dummy_provider = NULL; + g_autoptr (CallsProvider) mm_provider = NULL; + g_autoptr (CallsProvider) ofono_provider = NULL; + g_autoptr (CallsProvider) not_a_provider = NULL; + + dummy_provider = get_plugin ("dummy"); + g_assert_nonnull (dummy_provider); + + mm_provider = get_plugin ("mm"); + g_assert_nonnull (mm_provider); + + ofono_provider = get_plugin ("ofono"); + g_assert_nonnull (ofono_provider); + + not_a_provider = get_plugin ("not-a-valid-provider-plugin"); + g_assert_null (not_a_provider); +} + + +gint +main (gint argc, + gchar *argv[]) +{ + gtk_test_init (&argc, &argv, NULL); + + /* Add builddir as search path */ +#ifdef PLUGIN_BUILDDIR + peas_engine_add_search_path (peas_engine_get_default (), PLUGIN_BUILDDIR, NULL); +#endif + + g_test_add_func("/Calls/Plugins/load_plugins", test_calls_plugin_loading); + + return g_test_run(); +}