diff --git a/tests/meson.build b/tests/meson.build index 8bb6b48..eb66869 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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 diff --git a/tests/test-account.c b/tests/test-account.c new file mode 100644 index 0000000..764c9df --- /dev/null +++ b/tests/test-account.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2021 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0+ + * + * Author: Evangelos Ribeiro Tzaras + */ + +#include "calls-account.h" +#include "calls-account-provider.h" +#include "calls-provider.h" +#include "calls-sip-provider.h" + +#include + +#include +#include + +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(); +}