From b61302f9b1e0563e34bcb392fbaa1c3483dc3c73 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 8 Dec 2014 11:30:58 +0100 Subject: [PATCH] Handle accounts manager to the Python module unit tests. --- tester/accountmanager.c | 16 ++++-- tester/liblinphone_tester.h | 1 + .../linphone_testing_module.mustache | 52 +++++++++++++++++++ tools/python/unittests/linphonetester.py | 1 + tools/python/unittests/test_call.py | 4 ++ tools/python/unittests/test_message.py | 4 ++ tools/python/unittests/test_presence.py | 4 ++ tools/python/unittests/test_register.py | 4 ++ tools/python/unittests/test_setup.py | 4 ++ 9 files changed, 85 insertions(+), 5 deletions(-) diff --git a/tester/accountmanager.c b/tester/accountmanager.c index a3086f9cf..23794a6db 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -201,16 +201,22 @@ LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyC return account->modified_identity; } -void linphone_core_manager_check_accounts(LinphoneCoreManager *m){ +LinphoneAddress * account_manager_check_accounts(LinphoneCore *lc, LinphoneAddress *identity){ const MSList *it; AccountManager *am=account_manager_get(); - for(it=linphone_core_get_proxy_config_list(m->lc);it!=NULL;it=it->next){ + for(it=linphone_core_get_proxy_config_list(lc);it!=NULL;it=it->next){ LinphoneProxyConfig *cfg=(LinphoneProxyConfig *)it->data; LinphoneAddress *modified_identity=account_manager_check_account(am,cfg); - if (m->identity){ - linphone_address_unref(m->identity); + if (identity){ + linphone_address_unref(identity); } - m->identity=linphone_address_ref(modified_identity); + identity=linphone_address_ref(modified_identity); } + + return identity; +} + +void linphone_core_manager_check_accounts(LinphoneCoreManager *m){ + m->identity=account_manager_check_accounts(m->lc,m->identity); } diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 12531a57f..f776c21c8 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -279,6 +279,7 @@ void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreMana void liblinphone_tester_clock_start(MSTimeSpec *start); bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms); void linphone_core_manager_check_accounts(LinphoneCoreManager *m); +LinphoneAddress * account_manager_check_accounts(LinphoneCore *lc, LinphoneAddress *identity); void account_manager_destroy(void); LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data); #ifdef ANDROID diff --git a/tools/python/apixml2python/linphone_testing_module.mustache b/tools/python/apixml2python/linphone_testing_module.mustache index b68f8a558..81b96f96d 100644 --- a/tools/python/apixml2python/linphone_testing_module.mustache +++ b/tools/python/apixml2python/linphone_testing_module.mustache @@ -1,4 +1,54 @@ #include "private.h" +#include "liblinphone_tester.h" + +static PyObject * pylinphone_testing_module_method_check_accounts(PyObject *self, PyObject *args) { + PyObject *_core; + PyObject *_identity; + PyObject * pyresult; + PyObject * pyret; + LinphoneCore *_core_native_ptr; + LinphoneAddress *_identity_native_ptr; + + if (!PyArg_ParseTuple(args, "OO", &_core, &_identity)) { + return NULL; + } + if ((_core != Py_None) && !PyObject_IsInstance(_core, (PyObject *)&pylinphone_CoreType)) { + PyErr_SetString(PyExc_TypeError, "The '_core' argument must be a linphone.Core instance."); + return NULL; + } + if ((_core != Py_None) && !PyObject_IsInstance(_identity, (PyObject *)&pylinphone_AddressType)) { + PyErr_SetString(PyExc_TypeError, "The '_identity' argument must be a linphone.Address instance."); + return NULL; + } + + if ((_core != NULL) && (_core != Py_None)) { + if ((_core_native_ptr = pylinphone_Core_get_native_ptr(_core)) == NULL) { + return NULL; + } + } + if ((_identity != NULL) && (_identity != Py_None)) { + if ((_identity_native_ptr = pylinphone_Address_get_native_ptr(_core)) == NULL) { + return NULL; + } + } + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p], %p [%p])", __FUNCTION__, _core, _core_native_ptr, _identity, _identity_native_ptr); + _identity_native_ptr = account_manager_check_accounts(_core_native_ptr, _identity_native_ptr); + pylinphone_dispatch_messages(); + pyresult = pylinphone_Address_from_native_ptr(&pylinphone_AddressType, _identity_native_ptr); + pyret = Py_BuildValue("O", pyresult); + + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> %p", __FUNCTION__, pyret); + return pyret; +} + +static PyObject * pylinphone_testing_module_method_clean_accounts(PyObject *self, PyObject *args) { + pylinphone_trace(1, "[PYLINPHONE] >>> %s()", __FUNCTION__); + account_manager_destroy(); + pylinphone_dispatch_messages(); + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> None", __FUNCTION__); + Py_RETURN_NONE; +} static PyObject * pylinphone_testing_module_method_set_dns_user_hosts_file(PyObject *self, PyObject *args) { PyObject *_core; @@ -28,6 +78,8 @@ static PyObject * pylinphone_testing_module_method_set_dns_user_hosts_file(PyObj } static PyMethodDef pylinphone_TestingModuleMethods[] = { + { "check_accounts", pylinphone_testing_module_method_check_accounts, METH_VARARGS, "Checks that testing SIP accounts are created or creates them." }, + { "clean_accounts", pylinphone_testing_module_method_clean_accounts, METH_VARARGS, "Cleans the testing SIP accounts." }, { "set_dns_user_hosts_file", pylinphone_testing_module_method_set_dns_user_hosts_file, METH_VARARGS, "Allows to set a user specified hosts file." }, /* Sentinel */ { NULL, NULL, 0, NULL } diff --git a/tools/python/unittests/linphonetester.py b/tools/python/unittests/linphonetester.py index fcd485c79..8ed12e7f7 100644 --- a/tools/python/unittests/linphonetester.py +++ b/tools/python/unittests/linphonetester.py @@ -493,6 +493,7 @@ class CoreManager: assert_equals(os.path.isfile(filepath), True) lc = linphone.Core.new(vtable, None, filepath) linphone.testing.set_dns_user_hosts_file(lc, os.path.join(resources_path, 'tester_hosts')) + self.identity = linphone.testing.check_accounts(lc, self.identity) lc.root_ca = os.path.join(resources_path, 'certificates', 'cn', 'cafile.pem') lc.ring = os.path.join(resources_path, 'sounds', 'oldphone.wav') lc.ringback = os.path.join(resources_path, 'sounds', 'ringback.wav') diff --git a/tools/python/unittests/test_call.py b/tools/python/unittests/test_call.py index 93dfd1175..b02daefea 100644 --- a/tools/python/unittests/test_call.py +++ b/tools/python/unittests/test_call.py @@ -12,6 +12,10 @@ class TestCall: base, ext = os.path.splitext(os.path.basename(__file__)) cls.logger = Logger(base + '.log') + @classmethod + def teardown_class(cls): + linphone.testing.clean_accounts() + def test_early_declined_call(self): marie = CoreManager('marie_rc', logger=TestCall.logger) pauline = CoreManager('pauline_rc', logger=TestCall.logger) diff --git a/tools/python/unittests/test_message.py b/tools/python/unittests/test_message.py index 56a7e9e17..04c6fa260 100644 --- a/tools/python/unittests/test_message.py +++ b/tools/python/unittests/test_message.py @@ -13,6 +13,10 @@ class TestMessage: base, ext = os.path.splitext(os.path.basename(__file__)) cls.logger = Logger(base + '.log') + @classmethod + def teardown_class(cls): + linphone.testing.clean_accounts() + def wait_for_server_to_purge_messages(self, manager1, manager2): # Wait a little bit just to have time to purge message stored in the server CoreManager.wait_for_until(manager1, manager2, lambda manager1, manager2: False, 100) diff --git a/tools/python/unittests/test_presence.py b/tools/python/unittests/test_presence.py index 3de4e2e2a..192dbae0f 100644 --- a/tools/python/unittests/test_presence.py +++ b/tools/python/unittests/test_presence.py @@ -21,6 +21,10 @@ class TestPresence: base, ext = os.path.splitext(os.path.basename(__file__)) cls.logger = Logger(base + '.log') + @classmethod + def teardown_class(cls): + linphone.testing.clean_accounts() + def subscribe_to_callee_presence(self, caller_mgr, callee_mgr): initial_caller_stats = deepcopy(caller_mgr.stats) initial_callee_stats = deepcopy(callee_mgr.stats) diff --git a/tools/python/unittests/test_register.py b/tools/python/unittests/test_register.py index 2660fbf1c..6d444e70b 100644 --- a/tools/python/unittests/test_register.py +++ b/tools/python/unittests/test_register.py @@ -81,6 +81,10 @@ class TestRegister: base, ext = os.path.splitext(os.path.basename(__file__)) cls.logger = Logger(base + '.log') + @classmethod + def teardown_class(cls): + linphone.testing.clean_accounts() + def test_simple_register(self): cm = RegisterCoreManager(logger=TestRegister.logger) cm.register_with_refresh(False, None, None) diff --git a/tools/python/unittests/test_setup.py b/tools/python/unittests/test_setup.py index ff710217f..bb3d29c63 100644 --- a/tools/python/unittests/test_setup.py +++ b/tools/python/unittests/test_setup.py @@ -10,6 +10,10 @@ class TestSetup: base, ext = os.path.splitext(os.path.basename(__file__)) cls.logger = Logger(base + '.log') + @classmethod + def teardown_class(cls): + linphone.testing.clean_accounts() + def test_address(self): create_address(None)