From 33e5b193a0a29401585bc2244819ab847288ac56 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Mon, 13 Oct 2025 12:17:12 +0200 Subject: [PATCH] test-application: Check for expected plugins to be loaded These tests helps ensure the application will always have plugins loaded and prevent regressions. Helps: https://gitlab.gnome.org/GNOME/calls/-/issues/718 Signed-off-by: Evangelos Ribeiro Tzaras Part-of: --- tests/test-application.c | 50 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/test-application.c b/tests/test-application.c index 74d8bb0..dae9dc4 100644 --- a/tests/test-application.c +++ b/tests/test-application.c @@ -11,6 +11,11 @@ #include #include +#include "calls-plugin-manager.h" +#include "calls-settings.h" + +static const char *expected_plugins = NULL; /* comma separated string of plugins, see on_idle_quit() */ + #define calls_assert_in_dir(file, dir) G_STMT_START { \ g_autofree char *__p = g_build_path ("/", dir, file, NULL); \ @@ -38,9 +43,30 @@ static gboolean on_idle_quit (gpointer user_data) { GApplication *app = user_data; + CallsPluginManager *plugins = calls_plugin_manager_get_default (); + g_autoptr (GError) error = NULL; + g_auto (GStrv) expected = NULL; + uint n_plugins; + + if (expected_plugins) { + expected = g_strsplit (expected_plugins, ",", -1); + } else { + CallsSettings *settings = calls_settings_get_default (); + expected = calls_settings_get_autoload_plugins (settings); + } + + n_plugins = g_strv_length (expected); + /* we always should have *some* plugin, either the defaults, or explicitly loaded ones */ + g_assert_cmpuint (n_plugins, >, 0); + + for (uint i = 0; i < n_plugins; i++) { + g_assert_true (calls_plugin_manager_has_plugin (plugins, expected[i])); + } g_application_quit (app); + g_assert_true (calls_plugin_manager_has_any_plugins (plugins)); + return G_SOURCE_REMOVE; } @@ -49,9 +75,26 @@ static void test_application_shutdown_daemon (void) { CallsApplication *app = calls_application_new (); - char *argv[] = { "test", "--gapplication-service", "-p", "dummy", NULL }; + char *argv[] = { "test", "--gapplication-service", NULL }; int status; + expected_plugins = NULL; + g_idle_add (on_idle_quit, app); + + status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv); + g_assert_cmpint (status, ==, 0); + + g_assert_finalize_object (app); +} + +static void +test_application_shutdown_no_daemon (void) +{ + CallsApplication *app = calls_application_new (); + char *argv[] = { "test", NULL }; + int status; + + expected_plugins = NULL; g_idle_add (on_idle_quit, app); status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv); @@ -62,12 +105,13 @@ test_application_shutdown_daemon (void) static void -test_application_shutdown_no_daemon (void) +test_application_shutdown_no_daemon_dummy (void) { CallsApplication *app = calls_application_new (); char *argv[] = { "test", "-p", "dummy", NULL }; int status; + expected_plugins = "dummy"; g_idle_add (on_idle_quit, app); status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv); @@ -84,6 +128,7 @@ test_application_shutdown_delayed (void) char *argv[] = { "test", "-p", "dummy", NULL }; int status; + expected_plugins = "dummy"; g_timeout_add_seconds (5, on_idle_quit, app); status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv); @@ -136,6 +181,7 @@ main (int argc, g_test_init (&argc, &argv, NULL); g_test_add_func ("/Calls/application/shutdown_no_daemon", (GTestFunc) test_application_shutdown_no_daemon); + g_test_add_func ("/Calls/application/shutdown_no_daemon_dummy", (GTestFunc) test_application_shutdown_no_daemon_dummy); g_test_add_func ("/Calls/application/shutdown_delayed", (GTestFunc) test_application_shutdown_delayed); g_test_add_func ("/Calls/application/shutdown_sigterm", (GTestFunc) test_application_shutdown_sigterm); /* Last test so we don't need to bother if --gpplication-service keeps us alive a bit longer */