Remove CallsCredentials and adapt to changes
The provider knows best which credentials it needs and CallsCredentials was not generic to begin with, so get rid of it.
This commit is contained in:
committed by
Evangelos Ribeiro Tzaras
parent
10a2046549
commit
babd013bd7
@@ -101,20 +101,6 @@ t = executable('sip', test_sources,
|
||||
)
|
||||
test('sip', t, env: test_env)
|
||||
|
||||
test_sources = [ 'test-account.c' ]
|
||||
t = executable('account', test_sources,
|
||||
c_args : test_cflags,
|
||||
link_args: test_link_args,
|
||||
pie: true,
|
||||
link_with : [calls_vala, calls_sip, libcalls],
|
||||
dependencies: [calls_deps, sip_deps],
|
||||
include_directories : [
|
||||
calls_includes,
|
||||
sip_include,
|
||||
]
|
||||
)
|
||||
test('account', t, env: test_env)
|
||||
|
||||
test_sources = [ 'test-util.c' ]
|
||||
t = executable('util', test_sources,
|
||||
c_args : test_cflags,
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* 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 (void)
|
||||
{
|
||||
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_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();
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
#include "calls-manager.h"
|
||||
#include "calls-credentials.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libpeas/peas.h>
|
||||
@@ -130,8 +129,6 @@ test_calls_manager_mm_provider (void)
|
||||
static void
|
||||
test_calls_manager_multiple_providers_mm_sip (void)
|
||||
{
|
||||
g_autoptr (CallsCredentials) alice = NULL;
|
||||
g_autoptr (CallsCredentials) bob = NULL;
|
||||
g_autoptr (CallsOrigin) origin_alice = NULL;
|
||||
g_autoptr (CallsOrigin) origin_bob = NULL;
|
||||
g_autoptr (CallsManager) manager = calls_manager_new ();
|
||||
@@ -171,39 +168,6 @@ test_calls_manager_multiple_providers_mm_sip (void)
|
||||
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_ORIGIN);
|
||||
|
||||
/* Add Alice SIP account */
|
||||
alice = calls_credentials_new ();
|
||||
g_object_set (alice,
|
||||
"name", "Alice",
|
||||
"user", "alice",
|
||||
"host", "example.org",
|
||||
"password", "password123",
|
||||
NULL);
|
||||
g_assert_true (calls_manager_provider_add_account (manager, "sip", alice));
|
||||
g_assert_false (calls_manager_provider_add_account (manager, "sip", alice));
|
||||
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_READY);
|
||||
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 1);
|
||||
|
||||
/**
|
||||
* Add a second SIP origin to mix things up.
|
||||
* TODO We can expand on this later to test the call routing
|
||||
* starting with a simple "default" mechanism for now
|
||||
* needs https://source.puri.sm/Librem5/calls/-/issues/259 first though
|
||||
*/
|
||||
bob = calls_credentials_new ();
|
||||
g_object_set (bob,
|
||||
"name", "Bob",
|
||||
"user", "bob",
|
||||
"host", "example.org",
|
||||
"password", "password123",
|
||||
NULL);
|
||||
|
||||
g_assert_true (calls_manager_provider_add_account (manager, "sip", bob));
|
||||
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_READY);
|
||||
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 2);
|
||||
|
||||
/**
|
||||
* If we now load the MM plugin, the manager state should be *_STATE_NO_VOICE_MODEM
|
||||
* (unless run on a phone I guess?)
|
||||
@@ -216,19 +180,6 @@ test_calls_manager_multiple_providers_mm_sip (void)
|
||||
g_assert_true (calls_manager_has_provider (manager, "mm"));
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_VOICE_MODEM);
|
||||
|
||||
/* Remove alice */
|
||||
g_assert_true (calls_manager_provider_remove_account (manager, "sip", alice));
|
||||
g_assert_false (calls_manager_provider_remove_account (manager, "sip", alice));
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_VOICE_MODEM);
|
||||
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 1);
|
||||
|
||||
/* Unload MM plugin, since we still have Bob we should be ready (and bob should be the default sip origin) */
|
||||
calls_manager_remove_provider (manager, "mm");
|
||||
g_assert_true (calls_manager_has_any_provider (manager));
|
||||
g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_READY);
|
||||
|
||||
g_assert_true (calls_manager_provider_remove_account (manager, "sip", bob));
|
||||
g_assert_cmpuint (g_list_model_get_n_items (origins_sip), ==, 0);
|
||||
}
|
||||
|
||||
gint
|
||||
|
||||
@@ -21,12 +21,9 @@
|
||||
|
||||
typedef struct {
|
||||
CallsSipProvider *provider;
|
||||
CallsSipOrigin *origin_alice;
|
||||
CallsSipOrigin *origin_bob;
|
||||
CallsSipOrigin *origin_offline;
|
||||
CallsCredentials *credentials_alice;
|
||||
CallsCredentials *credentials_bob;
|
||||
CallsCredentials *credentials_offline;
|
||||
CallsSipOrigin *origin_alice;
|
||||
CallsSipOrigin *origin_bob;
|
||||
CallsSipOrigin *origin_offline;
|
||||
} SipFixture;
|
||||
|
||||
|
||||
@@ -361,59 +358,50 @@ static void
|
||||
setup_sip_origins (SipFixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
GListModel *origins;
|
||||
CallsCredentials *alice = calls_credentials_new ();
|
||||
CallsCredentials *bob = calls_credentials_new ();
|
||||
CallsCredentials *offline = calls_credentials_new ();
|
||||
|
||||
setup_sip_provider (fixture, user_data);
|
||||
|
||||
g_object_set (alice, "name", "Alice", "user", "alice", NULL);
|
||||
fixture->origin_alice =
|
||||
calls_sip_provider_add_origin_full (fixture->provider,
|
||||
NULL,
|
||||
"alice",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
FALSE,
|
||||
TRUE,
|
||||
5060);
|
||||
|
||||
calls_sip_provider_add_origin (fixture->provider, alice, 5060, TRUE);
|
||||
fixture->origin_bob =
|
||||
calls_sip_provider_add_origin_full (fixture->provider,
|
||||
NULL,
|
||||
"bob",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
FALSE,
|
||||
TRUE,
|
||||
5061);
|
||||
|
||||
g_object_set (bob, "name", "Bob", "user", "bob", NULL);
|
||||
fixture->origin_offline =
|
||||
calls_sip_provider_add_origin_full (fixture->provider,
|
||||
"sip.imaginary-host.org",
|
||||
"username",
|
||||
"password",
|
||||
NULL,
|
||||
"UDP",
|
||||
0,
|
||||
FALSE,
|
||||
FALSE,
|
||||
0);
|
||||
|
||||
calls_sip_provider_add_origin (fixture->provider, bob, 5061, TRUE);
|
||||
|
||||
g_object_set (offline,
|
||||
"name", "Offline",
|
||||
"user", "someuser",
|
||||
"host", "sip.imaginary-host.org",
|
||||
"password", "password123",
|
||||
"port", 5060,
|
||||
"protocol", "UDP",
|
||||
"auto-connect", FALSE,
|
||||
NULL);
|
||||
|
||||
calls_sip_provider_add_origin (fixture->provider, offline, 0, FALSE);
|
||||
|
||||
origins = calls_provider_get_origins
|
||||
(CALLS_PROVIDER (fixture->provider));
|
||||
|
||||
fixture->origin_alice = g_list_model_get_item (origins, 0);
|
||||
fixture->credentials_alice = alice;
|
||||
|
||||
fixture->origin_bob = g_list_model_get_item (origins, 1);
|
||||
fixture->credentials_bob = bob;
|
||||
|
||||
fixture->origin_offline = g_list_model_get_item (origins, 2);
|
||||
fixture->credentials_offline = offline;
|
||||
}
|
||||
|
||||
static void
|
||||
tear_down_sip_origins (SipFixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
g_clear_object (&fixture->origin_alice);
|
||||
g_clear_object (&fixture->credentials_alice);
|
||||
|
||||
g_clear_object (&fixture->origin_bob);
|
||||
g_clear_object (&fixture->credentials_bob);
|
||||
|
||||
g_clear_object (&fixture->origin_offline);
|
||||
g_clear_object (&fixture->credentials_offline);
|
||||
|
||||
tear_down_sip_provider (fixture, user_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user