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 <devrtz@fortysixandtwo.eu> Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/796>
This commit is contained in:
@@ -11,6 +11,11 @@
|
|||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#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 { \
|
#define calls_assert_in_dir(file, dir) G_STMT_START { \
|
||||||
g_autofree char *__p = g_build_path ("/", dir, file, NULL); \
|
g_autofree char *__p = g_build_path ("/", dir, file, NULL); \
|
||||||
@@ -38,9 +43,30 @@ static gboolean
|
|||||||
on_idle_quit (gpointer user_data)
|
on_idle_quit (gpointer user_data)
|
||||||
{
|
{
|
||||||
GApplication *app = 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_application_quit (app);
|
||||||
|
|
||||||
|
g_assert_true (calls_plugin_manager_has_any_plugins (plugins));
|
||||||
|
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,9 +75,26 @@ static void
|
|||||||
test_application_shutdown_daemon (void)
|
test_application_shutdown_daemon (void)
|
||||||
{
|
{
|
||||||
CallsApplication *app = calls_application_new ();
|
CallsApplication *app = calls_application_new ();
|
||||||
char *argv[] = { "test", "--gapplication-service", "-p", "dummy", NULL };
|
char *argv[] = { "test", "--gapplication-service", NULL };
|
||||||
int status;
|
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);
|
g_idle_add (on_idle_quit, app);
|
||||||
|
|
||||||
status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv);
|
status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv);
|
||||||
@@ -62,12 +105,13 @@ test_application_shutdown_daemon (void)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_application_shutdown_no_daemon (void)
|
test_application_shutdown_no_daemon_dummy (void)
|
||||||
{
|
{
|
||||||
CallsApplication *app = calls_application_new ();
|
CallsApplication *app = calls_application_new ();
|
||||||
char *argv[] = { "test", "-p", "dummy", NULL };
|
char *argv[] = { "test", "-p", "dummy", NULL };
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
expected_plugins = "dummy";
|
||||||
g_idle_add (on_idle_quit, app);
|
g_idle_add (on_idle_quit, app);
|
||||||
|
|
||||||
status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv);
|
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 };
|
char *argv[] = { "test", "-p", "dummy", NULL };
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
expected_plugins = "dummy";
|
||||||
g_timeout_add_seconds (5, on_idle_quit, app);
|
g_timeout_add_seconds (5, on_idle_quit, app);
|
||||||
|
|
||||||
status = g_application_run (G_APPLICATION (app), G_N_ELEMENTS (argv), argv);
|
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_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", (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_delayed", (GTestFunc) test_application_shutdown_delayed);
|
||||||
g_test_add_func ("/Calls/application/shutdown_sigterm", (GTestFunc) test_application_shutdown_sigterm);
|
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 */
|
/* Last test so we don't need to bother if --gpplication-service keeps us alive a bit longer */
|
||||||
|
|||||||
Reference in New Issue
Block a user