mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 11:35:32 +00:00
test: Add account tests
This commit is contained in:
parent
95f16cb527
commit
1db1ba6ca9
2 changed files with 117 additions and 0 deletions
|
@ -101,4 +101,18 @@ t = executable('sip', test_sources,
|
|||
)
|
||||
test('sip', t, env: test_env)
|
||||
|
||||
test_sources = [ 'test-account.c' ]
|
||||
t = executable('account', test_sources,
|
||||
calls_sources,
|
||||
c_args : test_cflags,
|
||||
link_args: test_link_args,
|
||||
link_with : [calls_vala, calls_sip],
|
||||
dependencies: [calls_deps, sip_deps],
|
||||
include_directories : [
|
||||
calls_includes,
|
||||
sip_include,
|
||||
]
|
||||
)
|
||||
test('account', t, env: test_env)
|
||||
|
||||
endif
|
||||
|
|
103
tests/test-account.c
Normal file
103
tests/test-account.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Purism SPC
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*
|
||||
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
|
||||
*/
|
||||
|
||||
#include "calls-account.h"
|
||||
#include "calls-account-provider.h"
|
||||
#include "calls-provider.h"
|
||||
#include "calls-sip-provider.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <sofia-sip/su_uniqueid.h>
|
||||
#include <libpeas/peas.h>
|
||||
|
||||
static void
|
||||
test_account_basic ()
|
||||
{
|
||||
CallsCredentials *alice = calls_credentials_new ();
|
||||
CallsCredentials *bob = calls_credentials_new ();
|
||||
CallsSipProvider *sip =
|
||||
CALLS_SIP_PROVIDER (calls_provider_load_plugin ("sip"));
|
||||
CallsAccountProvider *acc_provider;
|
||||
GListModel *origins;
|
||||
CallsOrigin *origin_alice;
|
||||
CallsOrigin *origin_bob;
|
||||
|
||||
g_assert_true (CALLS_IS_ACCOUNT_PROVIDER (sip));
|
||||
acc_provider = CALLS_ACCOUNT_PROVIDER (sip);
|
||||
|
||||
g_object_set (alice,
|
||||
"name", "Alice",
|
||||
"user", "alice",
|
||||
"host", "example.org",
|
||||
"password", "password123",
|
||||
NULL);
|
||||
g_object_set (bob,
|
||||
"name", "Bob",
|
||||
"user", "bob",
|
||||
"host", "example.org",
|
||||
"password", "password123",
|
||||
NULL);
|
||||
|
||||
/* Add credentials */
|
||||
g_assert_true (calls_account_provider_add_account (acc_provider, alice));
|
||||
g_assert_true (calls_account_provider_add_account (acc_provider, bob));
|
||||
|
||||
/* Are the returned accounts of the correct types? */
|
||||
g_assert_true (CALLS_IS_ACCOUNT (calls_account_provider_get_account (acc_provider, alice)));
|
||||
g_assert_true (CALLS_IS_ORIGIN (calls_account_provider_get_account (acc_provider, alice)));
|
||||
|
||||
g_assert_true (CALLS_IS_ACCOUNT (calls_account_provider_get_account (acc_provider, bob)));
|
||||
g_assert_true (CALLS_IS_ORIGIN (calls_account_provider_get_account (acc_provider, bob)));
|
||||
|
||||
/* Are we getting the correct corresponding origins back? */
|
||||
origins = calls_provider_get_origins (CALLS_PROVIDER (sip));
|
||||
|
||||
g_assert_cmpint (g_list_model_get_n_items (origins), ==, 2);
|
||||
|
||||
origin_alice = g_list_model_get_item (origins, 0);
|
||||
origin_bob = g_list_model_get_item (origins, 1);
|
||||
|
||||
g_assert_true (origin_alice ==
|
||||
CALLS_ORIGIN (calls_account_provider_get_account (acc_provider, alice)));
|
||||
g_assert_true (origin_bob ==
|
||||
CALLS_ORIGIN (calls_account_provider_get_account (acc_provider, bob)));
|
||||
|
||||
g_object_unref (origin_alice);
|
||||
g_object_unref (origin_bob);
|
||||
|
||||
/* Try adding credentials a second time */
|
||||
g_test_expect_message ("CallsSipProvider", G_LOG_LEVEL_WARNING,
|
||||
"Cannot add credentials with name 'Alice' multiple times");
|
||||
g_assert_false (calls_account_provider_add_account (acc_provider, alice));
|
||||
|
||||
/* Remove credentials */
|
||||
g_assert_true (calls_account_provider_remove_account (acc_provider, alice));
|
||||
g_assert_false (calls_account_provider_remove_account (acc_provider, alice));
|
||||
g_assert_true (calls_account_provider_remove_account (acc_provider, bob));
|
||||
g_assert_false (calls_account_provider_remove_account (acc_provider, bob));
|
||||
|
||||
g_assert_cmpint (g_list_model_get_n_items (origins), ==, 0);
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc,
|
||||
gchar *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
#ifdef PLUGIN_BUILDDIR
|
||||
peas_engine_add_search_path (peas_engine_get_default (), PLUGIN_BUILDDIR, NULL);
|
||||
#endif
|
||||
/* this is a workaround for an issue with sofia: https://github.com/freeswitch/sofia-sip/issues/58 */
|
||||
su_random64 ();
|
||||
|
||||
g_test_add_func ("/Calls/Account/basic", test_account_basic);
|
||||
|
||||
return g_test_run();
|
||||
}
|
Loading…
Reference in a new issue