From 581da48a50776b50ed4f58010c1f1718d3744b75 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 10 Sep 2014 11:40:23 +0200 Subject: [PATCH] Add testing module in Python. --- .../apixml2python/linphone_module.mustache | 4 ++ .../linphone_testing_module.mustache | 40 +++++++++++++++++++ tools/python/unittests/linphonetester.py | 3 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tools/python/apixml2python/linphone_testing_module.mustache diff --git a/tools/python/apixml2python/linphone_module.mustache b/tools/python/apixml2python/linphone_module.mustache index 3bcace1de..925902da7 100644 --- a/tools/python/apixml2python/linphone_module.mustache +++ b/tools/python/apixml2python/linphone_module.mustache @@ -272,6 +272,8 @@ static PyMethodDef pylinphone_{{enum_name}}_ModuleMethods[] = { {{/enums}} +{{> linphone_testing_module}} + PyMODINIT_FUNC initlinphone(void) { PyObject *m; PyObject *menum; @@ -318,4 +320,6 @@ PyMODINIT_FUNC initlinphone(void) { /* Hand-written classes. */ Py_INCREF(&pylinphone_VideoSizeType); PyModule_AddObject(m, "VideoSize", (PyObject *)&pylinphone_VideoSizeType); + + pylinphone_init_testing_module(m); } diff --git a/tools/python/apixml2python/linphone_testing_module.mustache b/tools/python/apixml2python/linphone_testing_module.mustache new file mode 100644 index 000000000..b68f8a558 --- /dev/null +++ b/tools/python/apixml2python/linphone_testing_module.mustache @@ -0,0 +1,40 @@ +#include "private.h" + +static PyObject * pylinphone_testing_module_method_set_dns_user_hosts_file(PyObject *self, PyObject *args) { + PyObject *_core; + char *_path; + LinphoneCore *_core_native_ptr; + + if (!PyArg_ParseTuple(args, "Oz", &_core, &_path)) { + 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 != NULL) && (_core != Py_None)) { + if ((_core_native_ptr = pylinphone_Core_get_native_ptr(_core)) == NULL) { + return NULL; + } + } + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p], %s)", __FUNCTION__, _core, _core_native_ptr, _path); + sal_set_dns_user_hosts_file(_core_native_ptr->sal, _path); + pylinphone_dispatch_messages(); + + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> None", __FUNCTION__); + Py_RETURN_NONE; +} + +static PyMethodDef pylinphone_TestingModuleMethods[] = { + { "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 } +}; + +static void pylinphone_init_testing_module(PyObject *linphone_module) { + PyObject *mtesting = Py_InitModule3("testing", pylinphone_TestingModuleMethods, "Python module adding some testing features for the Linphone library."); + Py_INCREF(mtesting); + if (PyModule_AddObject(linphone_module, "testing", mtesting) < 0) return; +} diff --git a/tools/python/unittests/linphonetester.py b/tools/python/unittests/linphonetester.py index 0968e551f..15d0f1327 100644 --- a/tools/python/unittests/linphonetester.py +++ b/tools/python/unittests/linphonetester.py @@ -392,8 +392,6 @@ class CoreManager: else: proxy_count = 0 if proxy_count: - if self.logger is not None: - self.logger.warning(self) CoreManager.wait_for_until(self, None, lambda manager: manager.stats.number_of_LinphoneRegistrationOk == proxy_count, 5000 * proxy_count) assert_equals(self.stats.number_of_LinphoneRegistrationOk, proxy_count) self.enable_audio_codec("PCMU", 8000) @@ -411,6 +409,7 @@ class CoreManager: filepath = os.path.join(resources_path, rc_path) 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')) 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')