mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
Manager: add test
This commit is contained in:
parent
9055724f33
commit
3e138eeccd
3 changed files with 165 additions and 1 deletions
|
@ -40,10 +40,13 @@ calls_version = meson.project_version()
|
|||
top_include = include_directories('.')
|
||||
|
||||
prefix = get_option('prefix')
|
||||
builddir = meson.current_build_dir()
|
||||
libdir = get_option('libdir')
|
||||
localedir = get_option('localedir')
|
||||
full_localedir = join_paths(prefix, localedir)
|
||||
full_calls_plugin_libdir = join_paths(prefix, libdir, calls_name, 'plugins')
|
||||
# Path to plugins inside the build dir, used for testing
|
||||
full_calls_plugin_builddir = join_paths(builddir, 'plugins')
|
||||
|
||||
config_data = configuration_data()
|
||||
config_data.set_quoted('APP_ID', calls_id)
|
||||
|
|
|
@ -12,7 +12,8 @@ test_env = [
|
|||
test_cflags = [
|
||||
'-fPIE',
|
||||
'-DFOR_TESTING',
|
||||
'-Wno-error=deprecated-declarations'
|
||||
'-Wno-error=deprecated-declarations',
|
||||
'-DPLUGIN_BUILDDIR="@0@"'.format(full_calls_plugin_builddir),
|
||||
]
|
||||
|
||||
test_link_args = [
|
||||
|
@ -54,4 +55,20 @@ foreach test : tests
|
|||
test(name, t, env: test_env)
|
||||
endforeach
|
||||
|
||||
test_sources = [ 'test-manager.c' ]
|
||||
|
||||
t = executable('manager', test_sources,
|
||||
calls_sources, calls_enum_sources, calls_resources,
|
||||
wl_proto_sources, wayland_sources,
|
||||
c_args : test_cflags,
|
||||
link_args: test_link_args,
|
||||
link_with : calls_vala,
|
||||
dependencies: calls_deps,
|
||||
include_directories : [
|
||||
calls_includes
|
||||
]
|
||||
)
|
||||
test('manager', t, env: test_env)
|
||||
|
||||
|
||||
endif
|
||||
|
|
144
tests/test-manager.c
Normal file
144
tests/test-manager.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Purism SPC
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
|
||||
#include "calls-manager.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libpeas/peas.h>
|
||||
|
||||
gint origin_count = 0;
|
||||
CallsCall *test_call = NULL;
|
||||
|
||||
static void
|
||||
origin_add_cb (CallsManager *manager)
|
||||
{
|
||||
origin_count++;
|
||||
}
|
||||
|
||||
static void
|
||||
origin_remove_cb (CallsManager *manager)
|
||||
{
|
||||
origin_count--;
|
||||
}
|
||||
|
||||
static void
|
||||
call_add_cb (CallsManager *manager, CallsCall *call)
|
||||
{
|
||||
test_call = call;
|
||||
}
|
||||
|
||||
static void
|
||||
call_remove_cb (CallsManager *manager, CallsCall *call)
|
||||
{
|
||||
g_assert (call == test_call);
|
||||
test_call = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
test_calls_manager_without_provider ()
|
||||
{
|
||||
g_autoptr (CallsManager) manager = calls_manager_new ();
|
||||
g_assert (CALLS_IS_MANAGER (manager));
|
||||
|
||||
g_assert_null (calls_manager_get_provider (manager));
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
g_assert_null (calls_manager_get_origins (manager));
|
||||
g_assert_null (calls_manager_get_calls (manager));
|
||||
g_assert_null (calls_manager_get_default_origin (manager));
|
||||
}
|
||||
|
||||
static void
|
||||
test_calls_manager_dummy_provider ()
|
||||
{
|
||||
g_autoptr (CallsManager) manager = calls_manager_new ();
|
||||
g_autoptr (GList) origins = NULL;
|
||||
gint no_origins = 0;
|
||||
CallsOrigin *origin;
|
||||
g_assert (CALLS_IS_MANAGER (manager));
|
||||
|
||||
origin_count = 0;
|
||||
g_signal_connect (manager, "origin-remove", G_CALLBACK (origin_remove_cb), NULL);
|
||||
g_signal_connect (manager, "origin-add", G_CALLBACK (origin_add_cb), NULL);
|
||||
|
||||
g_assert_null (calls_manager_get_provider (manager));
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
|
||||
calls_manager_set_provider (manager, "dummy");
|
||||
g_assert_cmpstr (calls_manager_get_provider (manager), ==, "dummy");
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_READY);
|
||||
|
||||
origins = calls_manager_get_origins (manager);
|
||||
no_origins = g_list_length (origins);
|
||||
g_assert_cmpint (origin_count, ==, no_origins);
|
||||
|
||||
g_assert_nonnull (calls_manager_get_origins (manager));
|
||||
g_assert_null (calls_manager_get_calls (manager));
|
||||
g_assert_null (calls_manager_get_default_origin (manager));
|
||||
|
||||
test_call = NULL;
|
||||
if (no_origins > 0) {
|
||||
g_signal_connect (manager, "call-add", G_CALLBACK (call_add_cb), NULL);
|
||||
g_signal_connect (manager, "call-remove", G_CALLBACK (call_remove_cb), NULL);
|
||||
|
||||
origin = CALLS_ORIGIN (g_list_first (origins)->data);
|
||||
g_assert (CALLS_IS_ORIGIN (origin));
|
||||
|
||||
calls_manager_set_default_origin (manager, origin);
|
||||
g_assert (calls_manager_get_default_origin (manager) == origin);
|
||||
|
||||
calls_origin_dial (origin, "+393422342");
|
||||
g_assert (CALLS_IS_CALL (test_call));
|
||||
calls_call_hang_up (test_call);
|
||||
g_assert_null (test_call);
|
||||
|
||||
/* Add new call do check if we remove it when we unload the provider */
|
||||
calls_origin_dial (origin, "+393422342");
|
||||
}
|
||||
|
||||
/* Unload the provider */
|
||||
calls_manager_set_provider (manager, NULL);
|
||||
|
||||
g_assert_cmpint (origin_count, ==, 0);
|
||||
g_assert_null (test_call);
|
||||
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
}
|
||||
|
||||
static void
|
||||
test_calls_manager_mm_provider ()
|
||||
{
|
||||
g_autoptr (CallsManager) manager = calls_manager_new ();
|
||||
g_assert (CALLS_IS_MANAGER (manager));
|
||||
|
||||
g_assert_null (calls_manager_get_provider (manager));
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
calls_manager_set_provider (manager, "mm");
|
||||
g_assert_cmpstr (calls_manager_get_provider (manager), ==, "mm");
|
||||
g_assert (calls_manager_get_state (manager) > CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
g_assert_null (calls_manager_get_calls (manager));
|
||||
g_assert_null (calls_manager_get_default_origin (manager));
|
||||
|
||||
calls_manager_set_provider (manager, NULL);
|
||||
g_assert (calls_manager_get_state (manager) == CALLS_MANAGER_STATE_NO_PROVIDER);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
Loading…
Reference in a new issue