refactor: Switch to CallsPluginManager

This commit is contained in:
Evangelos Ribeiro Tzaras
2023-05-15 10:08:55 +02:00
parent 37b208f040
commit d3e42c93cd
9 changed files with 371 additions and 589 deletions

View File

@@ -52,7 +52,6 @@ t = executable('emergency-call-types', test_sources,
)
test('emergency-call-types', t, env: test_env)
test_sources = [ 'test-manager.c' ]
t = executable('manager', test_sources,

View File

@@ -11,6 +11,7 @@
#include "calls-manager.h"
#include "calls-dbus-manager.h"
#include "calls-plugin-manager.h"
#include <glib-unix.h>
@@ -51,8 +52,10 @@ int
main (int argc, char *argv[])
{
g_autoptr (CallsManager) manager = NULL;
CallsDBusManager *dbus_manager = NULL;
g_autoptr (CallsPluginManager) plugin_manager = NULL;
g_autoptr (GMainLoop) loop = g_main_loop_new (NULL, FALSE);
g_autoptr (GError) error = NULL;
CallsDBusManager *dbus_manager = NULL;
guint bus_id;
/* Setup environment */
@@ -62,9 +65,11 @@ main (int argc, char *argv[])
g_print ("Starting up DBus service\n");
plugin_manager = calls_plugin_manager_get_default ();
manager = calls_manager_get_default ();
dbus_manager = calls_dbus_manager_new ();
calls_manager_add_provider (manager, "dummy");
g_assert_true (calls_plugin_manager_load_plugin (plugin_manager, "dummy", &error));
g_assert_no_error (error);
bus_id = g_bus_own_name (G_BUS_TYPE_SESSION,
CALLS_DBUS_NAME,
@@ -79,7 +84,8 @@ main (int argc, char *argv[])
g_print ("Shutting down DBus service\n");
calls_manager_remove_provider (manager, "dummy");
g_assert_true (calls_plugin_manager_unload_plugin (plugin_manager, "dummy", &error));
g_assert_no_error (error);
/* The DBus manager unexports any objects it may still have.
* Do this before releasing the DBus name ownership */

View File

@@ -5,6 +5,8 @@
*/
#include "calls-manager.h"
#include "calls-plugin-manager.h"
#include "calls-util.h"
#include <cui-call.h>
#include <glib.h>
@@ -12,6 +14,7 @@
struct TestData {
GMainLoop *loop;
CallsManager *manager;
CallsPluginManager *plugin_manager;
GListModel *origins;
GListModel *origins_tel;
CallsOrigin *origin;
@@ -24,6 +27,7 @@ call_add_cb (CallsManager *manager,
struct TestData *data)
{
static guint phase = 0;
g_autoptr (GError) error = NULL;
data->call = call;
switch (phase++) {
@@ -33,9 +37,11 @@ call_add_cb (CallsManager *manager,
case 1:
/* Unload the provider */
calls_manager_remove_provider (data->manager, "dummy");
g_assert_false (calls_manager_has_provider (data->manager, "dummy"));
g_assert_false (calls_manager_has_any_provider (data->manager));
calls_plugin_manager_unload_plugin (data->plugin_manager, "dummy", &error);
g_assert_false (calls_plugin_manager_has_plugin (data->plugin_manager, "dummy"));
g_assert_false (calls_plugin_manager_has_any_plugins (data->plugin_manager));
g_assert_cmpuint (g_list_model_get_n_items (calls_manager_get_origins (data->manager)),
==, 0);
break;
@@ -72,19 +78,20 @@ call_remove_cb (CallsManager *manager,
static void
test_calls_manager_without_provider (void)
{
guint no_origins;
GListModel *origins;
g_autoptr (CallsManager) manager = calls_manager_new ();
CallsManager *manager = calls_manager_get_default ();
CallsPluginManager *plugin_manager = calls_plugin_manager_get_default ();
g_assert_true (CALLS_IS_MANAGER (manager));
g_assert_true (CALLS_IS_PLUGIN_MANAGER (plugin_manager));
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
origins = calls_manager_get_origins (manager);
no_origins = g_list_model_get_n_items (origins);
g_assert_cmpuint (no_origins, ==, 0);
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
g_assert_null (calls_manager_get_calls (manager));
g_assert_false (calls_manager_has_any_provider (manager));
g_assert_false (calls_plugin_manager_has_any_plugins (plugin_manager));
origins = calls_manager_get_suitable_origins (manager, "tel:+123456789");
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
@@ -94,11 +101,16 @@ test_calls_manager_without_provider (void)
origins = calls_manager_get_suitable_origins (manager, "sips:bob@example.org");
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
g_assert_finalize_object (manager);
g_assert_finalize_object (plugin_manager);
}
static void
test_calls_manager_dummy_provider (void)
{
g_autoptr (GError) error = NULL;
CallsManager *manager;
GListModel *origins;
GListModel *origins_tel;
@@ -106,7 +118,9 @@ test_calls_manager_dummy_provider (void)
struct TestData *test_data;
test_data = g_new0 (struct TestData, 1);
test_data->manager = calls_manager_new ();
test_data->manager = calls_manager_get_default ();
test_data->plugin_manager = calls_plugin_manager_get_default ();
manager = test_data->manager;
g_assert_true (CALLS_IS_MANAGER (manager));
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
@@ -117,9 +131,11 @@ test_calls_manager_dummy_provider (void)
g_assert_true (origins);
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
calls_manager_add_provider (manager, "dummy");
g_assert_true (calls_manager_has_any_provider (manager));
g_assert_true (calls_manager_has_provider (manager, "dummy"));
g_assert_true (calls_plugin_manager_load_plugin (test_data->plugin_manager, "dummy", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_any_plugins (test_data->plugin_manager));
g_assert_true (calls_plugin_manager_has_plugin (test_data->plugin_manager, "dummy"));
/* Dummy plugin fakes being a modem */
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==,
CALLS_MANAGER_FLAGS_HAS_CELLULAR_PROVIDER |
@@ -134,8 +150,7 @@ test_calls_manager_dummy_provider (void)
test_data->origins_tel = calls_manager_get_suitable_origins (manager, "tel:+393422342");
origins_tel = test_data->origins_tel;
g_assert_true (G_IS_LIST_MODEL (origins_tel));
g_assert_true (G_IS_LIST_STORE (origins_tel));
g_assert_true (g_list_store_find (G_LIST_STORE (origins_tel), test_data->origin, &position));
g_assert_true (calls_find_in_model (origins_tel, test_data->origin, &position));
g_signal_connect (manager, "ui-call-added", G_CALLBACK (call_add_cb), test_data);
g_signal_connect (manager, "ui-call-removed", G_CALLBACK (call_remove_cb), test_data);
@@ -155,22 +170,29 @@ test_calls_manager_dummy_provider (void)
g_assert_finalize_object (test_data->origin);
g_assert_finalize_object (test_data->manager);
g_assert_finalize_object (test_data->plugin_manager);
g_free (test_data);
}
static void
test_calls_manager_mm_provider (void)
{
GListModel *origins_tel;
g_autoptr (CallsManager) manager = calls_manager_new ();
CallsManager *manager = calls_manager_get_default ();
CallsPluginManager *plugin_manager = calls_plugin_manager_get_default ();
g_autoptr (GError) error = NULL;
g_assert_true (CALLS_IS_MANAGER (manager));
g_assert_true (CALLS_IS_PLUGIN_MANAGER (plugin_manager));
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
calls_manager_add_provider (manager, "mm");
g_assert_true (calls_manager_has_any_provider (manager));
g_assert_true (calls_manager_has_provider (manager, "mm"));
g_assert_true (calls_plugin_manager_load_plugin (plugin_manager, "mm", &error));
g_assert_no_error (error);
g_assert_true (calls_plugin_manager_has_any_plugins (plugin_manager));
g_assert_true (calls_plugin_manager_has_plugin (plugin_manager, "mm"));
g_assert_cmpuint (calls_manager_get_state_flags (manager), >, CALLS_MANAGER_FLAGS_UNKNOWN);
@@ -180,22 +202,28 @@ test_calls_manager_mm_provider (void)
g_assert_nonnull (origins_tel);
g_assert_cmpuint (g_list_model_get_n_items (origins_tel), ==, 0);
calls_manager_remove_provider (manager, "mm");
g_assert_true (calls_plugin_manager_unload_plugin (plugin_manager, "mm", &error));
g_assert_no_error (error);
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
g_assert_finalize_object (manager);
g_assert_finalize_object (plugin_manager);
}
static void
test_calls_manager_multiple_providers_mm_sip (void)
{
g_autoptr (CallsOrigin) origin_alice = NULL;
g_autoptr (CallsOrigin) origin_bob = NULL;
g_autoptr (CallsManager) manager = calls_manager_new ();
CallsManager *manager = calls_manager_get_default ();
CallsPluginManager *plugin_manager = calls_plugin_manager_get_default ();
GListModel *origins;
GListModel *origins_tel;
GListModel *origins_sip;
GListModel *origins_sips;
g_autoptr (GError) error = NULL;
g_assert_true (CALLS_IS_MANAGER (manager));
g_assert_true (CALLS_IS_PLUGIN_MANAGER (plugin_manager));
origins = calls_manager_get_origins (manager);
g_assert_true (G_IS_LIST_MODEL (origins));
@@ -215,10 +243,7 @@ test_calls_manager_multiple_providers_mm_sip (void)
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
/* First add the SIP provider, MM provider later */
calls_manager_add_provider (manager, "sip");
g_assert_true (calls_manager_has_any_provider (manager));
g_assert_true (calls_manager_has_provider (manager, "sip"));
g_assert_true (calls_manager_is_modem_provider (manager, "sip") == FALSE);
g_assert_true (calls_plugin_manager_load_plugin (plugin_manager, "sip", &error));
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_HAS_VOIP_PROVIDER);
/* Still no origins */
@@ -237,13 +262,13 @@ test_calls_manager_multiple_providers_mm_sip (void)
* see https://source.puri.sm/Librem5/calls/-/issues/280
* and https://source.puri.sm/Librem5/calls/-/issues/178
*/
calls_manager_add_provider (manager, "mm");
g_assert_true (calls_manager_has_any_provider (manager));
g_assert_true (calls_manager_has_provider (manager, "mm"));
g_assert_true (calls_plugin_manager_load_plugin (plugin_manager, "mm", &error));
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==,
CALLS_MANAGER_FLAGS_HAS_VOIP_PROVIDER |
CALLS_MANAGER_FLAGS_HAS_CELLULAR_PROVIDER);
g_assert_finalize_object (manager);
g_assert_finalize_object (plugin_manager);
}
gint