2020-03-20 17:33:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Purism SPC
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "calls-manager.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <libpeas/peas.h>
|
|
|
|
|
|
|
|
CallsCall *test_call = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
call_add_cb (CallsManager *manager, CallsCall *call)
|
|
|
|
{
|
|
|
|
test_call = call;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
call_remove_cb (CallsManager *manager, CallsCall *call)
|
|
|
|
{
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_true (call == test_call);
|
2020-03-20 17:33:59 +00:00
|
|
|
test_call = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_calls_manager_without_provider ()
|
|
|
|
{
|
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
|
|
|
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_PROVIDER);
|
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-04-13 09:36:58 +00:00
|
|
|
g_assert_null (calls_manager_get_suitable_origins (manager, "tel:+123456789"));
|
|
|
|
g_assert_null (calls_manager_get_suitable_origins (manager, "sip:alice@example.org"));
|
|
|
|
g_assert_null (calls_manager_get_suitable_origins (manager, "sips:bob@example.org"));
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_calls_manager_dummy_provider ()
|
|
|
|
{
|
|
|
|
g_autoptr (CallsManager) manager = calls_manager_new ();
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *origins;
|
2021-04-13 09:36:58 +00:00
|
|
|
GListModel *origins_tel;
|
|
|
|
guint position;
|
|
|
|
g_autoptr (CallsOrigin) origin = NULL;
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_PROVIDER);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
|
|
|
origins = calls_manager_get_origins (manager);
|
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");
|
|
|
|
g_assert_true (calls_manager_has_provider (manager, "dummy"));
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_READY);
|
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));
|
|
|
|
|
|
|
|
test_call = NULL;
|
2021-04-13 09:36:58 +00:00
|
|
|
g_signal_connect (manager, "call-add", G_CALLBACK (call_add_cb), NULL);
|
|
|
|
g_signal_connect (manager, "call-remove", G_CALLBACK (call_remove_cb), NULL);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
origin = g_list_model_get_item (origins, 0);
|
|
|
|
g_assert_true (CALLS_IS_ORIGIN (origin));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
origins_tel = calls_manager_get_suitable_origins (manager, "tel:+393422342");
|
|
|
|
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), origin, &position));
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_origin_dial (origin, "+393422342");
|
|
|
|
g_assert_true (CALLS_IS_CALL (test_call));
|
|
|
|
calls_call_hang_up (test_call);
|
|
|
|
g_assert_null (test_call);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
/* Add new call do check if we remove it when we unload the provider */
|
|
|
|
calls_origin_dial (origin, "+393422342");
|
2020-03-20 17:33:59 +00:00
|
|
|
|
|
|
|
/* Unload the provider */
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_remove_provider (manager, "dummy");
|
2020-03-20 17:33:59 +00:00
|
|
|
|
|
|
|
g_assert_null (test_call);
|
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
|
|
|
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_PROVIDER);
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_calls_manager_mm_provider ()
|
|
|
|
{
|
|
|
|
g_autoptr (CallsManager) manager = calls_manager_new ();
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_true (CALLS_IS_MANAGER (manager));
|
|
|
|
|
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_PROVIDER);
|
2020-03-20 17:33:59 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_add_provider (manager, "mm");
|
2021-05-05 15:19:24 +00:00
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), >, CALLS_MANAGER_STATE_NO_PROVIDER);
|
2020-03-20 17:33:59 +00:00
|
|
|
g_assert_null (calls_manager_get_calls (manager));
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_remove_provider (manager, "mm");
|
|
|
|
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_PROVIDER);
|
2020-03-20 17:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc,
|
|
|
|
gchar *argv[])
|
|
|
|
{
|
|
|
|
gtk_test_init (&argc, &argv, NULL);
|
|
|
|
|
|
|
|
/* Add builddir as search path */
|
|
|
|
#ifdef PLUGIN_BUILDDIR
|
|
|
|
peas_engine_add_search_path (peas_engine_get_default (), PLUGIN_BUILDDIR, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|