2020-03-20 17:33:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Purism SPC
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "calls-manager.h"
|
|
|
|
|
2022-01-31 16:07:41 +00:00
|
|
|
#include <cui-call.h>
|
2023-05-01 09:44:29 +00:00
|
|
|
#include <glib.h>
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
struct TestData {
|
|
|
|
GMainLoop *loop;
|
|
|
|
CallsManager *manager;
|
|
|
|
GListModel *origins;
|
|
|
|
GListModel *origins_tel;
|
|
|
|
CallsOrigin *origin;
|
|
|
|
CuiCall *call;
|
|
|
|
};
|
2020-03-20 17:33:59 +00:00
|
|
|
|
|
|
|
static void
|
2022-02-03 06:49:55 +00:00
|
|
|
call_add_cb (CallsManager *manager,
|
|
|
|
CuiCall *call,
|
|
|
|
struct TestData *data)
|
2020-03-20 17:33:59 +00:00
|
|
|
{
|
2022-02-03 06:49:55 +00:00
|
|
|
static guint phase = 0;
|
|
|
|
|
|
|
|
data->call = call;
|
|
|
|
switch (phase++) {
|
|
|
|
case 0:
|
|
|
|
cui_call_hang_up (call);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-02-03 06:49:55 +00:00
|
|
|
call_remove_cb (CallsManager *manager,
|
|
|
|
CuiCall *call,
|
|
|
|
struct TestData *data)
|
2020-03-20 17:33:59 +00:00
|
|
|
{
|
2022-02-03 06:49:55 +00:00
|
|
|
static guint phase = 0;
|
|
|
|
|
|
|
|
g_assert_true (call == data->call);
|
|
|
|
data->call = NULL;
|
|
|
|
switch (phase++) {
|
|
|
|
case 0:
|
|
|
|
/* Add new call do check if we remove it when we unload the provider */
|
|
|
|
calls_origin_dial (data->origin, "+393422342");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
g_main_loop_quit (data->loop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-06-02 18:18:50 +00:00
|
|
|
test_calls_manager_without_provider (void)
|
2020-03-20 17:33:59 +00:00
|
|
|
{
|
2021-04-13 09:36:58 +00:00
|
|
|
guint no_origins;
|
|
|
|
GListModel *origins;
|
2020-03-20 17:33:59 +00:00
|
|
|
g_autoptr (CallsManager) manager = calls_manager_new ();
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2021-04-13 09:36:58 +00:00
|
|
|
|
|
|
|
origins = calls_manager_get_origins (manager);
|
|
|
|
no_origins = g_list_model_get_n_items (origins);
|
|
|
|
g_assert_cmpuint (no_origins, ==, 0);
|
|
|
|
|
2020-03-20 17:33:59 +00:00
|
|
|
g_assert_null (calls_manager_get_calls (manager));
|
2021-05-19 22:54:40 +00:00
|
|
|
g_assert_false (calls_manager_has_any_provider (manager));
|
2022-01-26 07:24:09 +00:00
|
|
|
|
|
|
|
origins = calls_manager_get_suitable_origins (manager, "tel:+123456789");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
|
|
|
|
|
|
|
origins = calls_manager_get_suitable_origins (manager, "sip:alice@example.org");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
|
|
|
|
|
|
|
origins = calls_manager_get_suitable_origins (manager, "sips:bob@example.org");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-06-02 18:18:50 +00:00
|
|
|
test_calls_manager_dummy_provider (void)
|
2020-03-20 17:33:59 +00:00
|
|
|
{
|
2022-02-03 06:49:55 +00:00
|
|
|
CallsManager *manager;
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *origins;
|
2021-04-13 09:36:58 +00:00
|
|
|
GListModel *origins_tel;
|
|
|
|
guint position;
|
2022-02-03 06:49:55 +00:00
|
|
|
struct TestData *test_data;
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
test_data = g_new0 (struct TestData, 1);
|
|
|
|
test_data->manager = calls_manager_new ();
|
|
|
|
manager = test_data->manager;
|
2021-05-05 18:53:37 +00:00
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
|
|
|
|
test_data->origins = calls_manager_get_origins (manager);
|
|
|
|
origins = test_data->origins;
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert_true (origins);
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
|
|
|
|
|
|
|
calls_manager_add_provider (manager, "dummy");
|
2021-05-19 22:54:40 +00:00
|
|
|
g_assert_true (calls_manager_has_any_provider (manager));
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert_true (calls_manager_has_provider (manager, "dummy"));
|
2022-01-26 13:18:24 +00:00
|
|
|
/* Dummy plugin fakes being a modem */
|
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==,
|
|
|
|
CALLS_MANAGER_FLAGS_HAS_CELLULAR_PROVIDER |
|
|
|
|
CALLS_MANAGER_FLAGS_HAS_CELLULAR_MODEM);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), >, 0);
|
2020-03-20 17:33:59 +00:00
|
|
|
g_assert_null (calls_manager_get_calls (manager));
|
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
test_data->origin = g_list_model_get_item (origins, 0);
|
|
|
|
g_assert_true (CALLS_IS_ORIGIN (test_data->origin));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
test_data->origins_tel = calls_manager_get_suitable_origins (manager, "tel:+393422342");
|
|
|
|
origins_tel = test_data->origins_tel;
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert_true (G_IS_LIST_MODEL (origins_tel));
|
|
|
|
g_assert_true (G_IS_LIST_STORE (origins_tel));
|
2022-02-03 06:49:55 +00:00
|
|
|
g_assert_true (g_list_store_find (G_LIST_STORE (origins_tel), test_data->origin, &position));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
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);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
calls_origin_dial (test_data->origin, "+393422343");
|
|
|
|
g_assert_true (CUI_IS_CALL (test_data->call));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-02-03 06:49:55 +00:00
|
|
|
test_data->loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
g_main_loop_run (test_data->loop);
|
|
|
|
|
|
|
|
g_main_loop_unref (test_data->loop);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
2021-05-05 18:53:37 +00:00
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_tel), ==, 0);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2022-02-03 06:49:55 +00:00
|
|
|
|
|
|
|
g_assert_finalize_object (test_data->origin);
|
|
|
|
g_assert_finalize_object (test_data->manager);
|
|
|
|
|
|
|
|
g_free (test_data);
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-06-02 18:18:50 +00:00
|
|
|
test_calls_manager_mm_provider (void)
|
2020-03-20 17:33:59 +00:00
|
|
|
{
|
2021-05-05 18:53:37 +00:00
|
|
|
GListModel *origins_tel;
|
2020-03-20 17:33:59 +00:00
|
|
|
g_autoptr (CallsManager) manager = calls_manager_new ();
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
|
|
|
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_add_provider (manager, "mm");
|
2021-05-19 22:54:40 +00:00
|
|
|
g_assert_true (calls_manager_has_any_provider (manager));
|
|
|
|
g_assert_true (calls_manager_has_provider (manager, "mm"));
|
|
|
|
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), >, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2021-05-05 18:53:37 +00:00
|
|
|
|
2020-03-20 17:33:59 +00:00
|
|
|
g_assert_null (calls_manager_get_calls (manager));
|
|
|
|
|
2021-05-05 18:53:37 +00:00
|
|
|
origins_tel = calls_manager_get_suitable_origins (manager, "tel:+123456789");
|
|
|
|
g_assert_nonnull (origins_tel);
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_tel), ==, 0);
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_remove_provider (manager, "mm");
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 18:53:37 +00:00
|
|
|
static void
|
2021-06-02 18:18:50 +00:00
|
|
|
test_calls_manager_multiple_providers_mm_sip (void)
|
2021-05-05 18:53:37 +00:00
|
|
|
{
|
|
|
|
g_autoptr (CallsOrigin) origin_alice = NULL;
|
|
|
|
g_autoptr (CallsOrigin) origin_bob = NULL;
|
|
|
|
g_autoptr (CallsManager) manager = calls_manager_new ();
|
|
|
|
GListModel *origins;
|
|
|
|
GListModel *origins_tel;
|
|
|
|
GListModel *origins_sip;
|
|
|
|
GListModel *origins_sips;
|
|
|
|
|
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
|
|
|
|
|
|
|
origins = calls_manager_get_origins (manager);
|
|
|
|
g_assert_true (G_IS_LIST_MODEL (origins));
|
|
|
|
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_UNKNOWN);
|
2022-01-26 07:24:09 +00:00
|
|
|
|
|
|
|
origins_tel = calls_manager_get_suitable_origins (manager, "tel:+123456789");
|
|
|
|
g_assert_nonnull (origins_tel);
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_tel), ==, 0);
|
|
|
|
|
|
|
|
origins_sip = calls_manager_get_suitable_origins (manager, "sip:alice@example.org");
|
|
|
|
g_assert_nonnull (origins_sip);
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 0);
|
|
|
|
|
|
|
|
origins_sips = calls_manager_get_suitable_origins (manager, "sips:bob@example.org");
|
|
|
|
g_assert_nonnull (origins_sips);
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins), ==, 0);
|
2021-05-05 18:53:37 +00:00
|
|
|
|
|
|
|
/* First add the SIP provider, MM provider later */
|
|
|
|
calls_manager_add_provider (manager, "sip");
|
2021-05-19 22:54:40 +00:00
|
|
|
g_assert_true (calls_manager_has_any_provider (manager));
|
2021-05-05 18:53:37 +00:00
|
|
|
g_assert_true (calls_manager_has_provider (manager, "sip"));
|
|
|
|
g_assert_true (calls_manager_is_modem_provider (manager, "sip") == FALSE);
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==, CALLS_MANAGER_FLAGS_HAS_VOIP_PROVIDER);
|
2021-05-05 18:53:37 +00:00
|
|
|
|
2022-01-26 07:24:09 +00:00
|
|
|
/* Still no origins */
|
2021-05-05 18:53:37 +00:00
|
|
|
origins_tel = calls_manager_get_suitable_origins (manager, "tel:+123456789");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_tel), ==, 0);
|
|
|
|
|
|
|
|
origins_sip = calls_manager_get_suitable_origins (manager, "sip:alice@example.org");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 0);
|
|
|
|
|
|
|
|
origins_sips = calls_manager_get_suitable_origins (manager, "sips:bob@example.org");
|
|
|
|
g_assert_cmpuint (g_list_model_get_n_items (origins_sips), ==, 0);
|
|
|
|
|
|
|
|
/**
|
2022-01-26 13:18:24 +00:00
|
|
|
* If we now load the MM plugin, the manager flag _HAS_CELLULAR_PROVIDER should be set
|
2021-05-05 18:53:37 +00:00
|
|
|
* TODO DBus mock to add modems
|
|
|
|
* see https://source.puri.sm/Librem5/calls/-/issues/280
|
|
|
|
* and https://source.puri.sm/Librem5/calls/-/issues/178
|
|
|
|
*/
|
|
|
|
calls_manager_add_provider (manager, "mm");
|
2021-05-19 22:54:40 +00:00
|
|
|
g_assert_true (calls_manager_has_any_provider (manager));
|
2021-05-05 18:53:37 +00:00
|
|
|
g_assert_true (calls_manager_has_provider (manager, "mm"));
|
2022-01-26 13:18:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state_flags (manager), ==,
|
|
|
|
CALLS_MANAGER_FLAGS_HAS_VOIP_PROVIDER |
|
|
|
|
CALLS_MANAGER_FLAGS_HAS_CELLULAR_PROVIDER);
|
2021-05-05 18:53:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:33:59 +00:00
|
|
|
gint
|
|
|
|
main (gint argc,
|
|
|
|
gchar *argv[])
|
|
|
|
{
|
2023-05-01 09:44:29 +00:00
|
|
|
g_test_init (&argc, &argv, NULL);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2023-05-01 09:44:29 +00:00
|
|
|
g_test_add_func ("/Calls/Manager/without_provider", test_calls_manager_without_provider);
|
|
|
|
g_test_add_func ("/Calls/Manager/dummy_provider", test_calls_manager_dummy_provider);
|
|
|
|
g_test_add_func ("/Calls/Manager/mm_provider", test_calls_manager_mm_provider);
|
|
|
|
g_test_add_func ("/Calls/Manager/multiple_provider_mm_sip", test_calls_manager_multiple_providers_mm_sip);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2023-05-01 09:44:29 +00:00
|
|
|
return g_test_run ();
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|