1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-11-14 04:15:37 +00:00
Purism-Calls/tests/test-plugins.c

125 lines
3.7 KiB
C
Raw Normal View History

2021-03-23 13:20:24 +00:00
/*
2021-04-09 13:07:30 +00:00
* Copyright (C) 2021 Purism SPC
2021-03-23 13:20:24 +00:00
*
* SPDX-License-Identifier: GPL-3.0+
*
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
*/
#include "calls-config.h"
2021-03-23 13:20:24 +00:00
#include "calls-provider.h"
#include "calls-plugin-manager.h"
2021-03-23 13:20:24 +00:00
#include <glib.h>
static void
on_providers_changed (GListModel *model,
guint position,
guint removed,
guint added,
gpointer unused)
{
g_autoptr (CallsProvider) provider = NULL;
static guint phase = 0;
switch (phase) {
case 0:
case 1:
case 2:
case 3:
g_assert_cmpint (added, ==, 1);
provider = g_list_model_get_item (model, position);
g_assert_true (CALLS_IS_PROVIDER (provider));
break;
case 4:
case 5:
case 6:
case 7:
g_assert_cmpint (removed, ==, 1);
break;
default:
g_assert_not_reached ();
}
phase++;
}
2021-03-23 13:20:24 +00:00
static void
test_calls_plugin_loading (void)
2021-03-23 13:20:24 +00:00
{
CallsPluginManager *manager = calls_plugin_manager_get_default ();
g_autoptr (GError) error = NULL;
g_assert_false (calls_plugin_manager_has_any_plugins (manager));
g_signal_connect (calls_plugin_manager_get_providers (manager),
"items-changed",
G_CALLBACK (on_providers_changed),
NULL);
g_assert_true (calls_plugin_manager_load_plugin (manager, "dummy", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
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_any_plugins (manager));
g_assert_true (calls_plugin_manager_has_plugin (manager, "mm"));
2021-03-23 13:20:24 +00:00
g_assert_true (calls_plugin_manager_load_plugin (manager, "sip", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_has_plugin (manager, "sip"));
2021-03-23 13:20:24 +00:00
g_assert_true (calls_plugin_manager_load_plugin (manager, "ofono", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_has_plugin (manager, "ofono"));
2021-03-23 13:20:24 +00:00
g_assert_false (calls_plugin_manager_load_plugin (manager, "not-a-plugin", &error));
g_assert_nonnull (error);
g_clear_error (&error);
2021-03-23 13:20:24 +00:00
2021-04-05 00:05:00 +00:00
g_assert_true (calls_plugin_manager_unload_plugin (manager, "dummy", &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_plugin (manager, "dummy"));
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
2021-04-02 17:50:09 +00:00
g_assert_true (calls_plugin_manager_unload_plugin (manager, "mm", &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_plugin (manager, "mm"));
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_unload_plugin (manager, "sip", &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_plugin (manager, "sip"));
g_assert_true (calls_plugin_manager_has_any_plugins (manager));
g_assert_true (calls_plugin_manager_unload_plugin (manager, "ofono", &error));
g_assert_no_error (error);
g_assert_false (calls_plugin_manager_has_plugin (manager, "ofono"));
g_assert_false (calls_plugin_manager_has_any_plugins (manager));
g_assert_cmpint (g_list_model_get_n_items (calls_plugin_manager_get_providers (manager)),
==, 0);
g_assert_finalize_object (manager);
2021-03-23 13:20:24 +00:00
}
gint
main (gint argc,
gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
2021-03-23 13:20:24 +00:00
g_test_add_func ("/Calls/Plugins/load_plugins", test_calls_plugin_loading);
2021-03-23 13:20:24 +00:00
return g_test_run ();
2021-03-23 13:20:24 +00:00
}