From afe5abba860de13f92e28545ad682a5a976a7dbe Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 19 Dec 2014 15:56:30 +0100 Subject: [PATCH] Add some Python setup tests. --- coreapi/linphonecore.c | 4 +- tools/python/apixml2python.py | 2 + .../handwritten_declarations.mustache | 3 + .../handwritten_definitions.mustache | 69 +++++++++++++++++++ tools/python/unittests/test_setup.py | 40 +++++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index d5248b96e..a90b25162 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2125,7 +2125,7 @@ void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833) /** * Returns the UDP port used by SIP. * - * Deprecated: use linphone_core_get_sip_transports() instead. + * @deprecated use linphone_core_get_sip_transports() instead. * @ingroup network_parameters **/ int linphone_core_get_sip_port(LinphoneCore *lc){ @@ -2293,7 +2293,7 @@ void linphone_core_get_sip_transports_used(LinphoneCore *lc, LCSipTransports *tr /** * Sets the UDP port to be used by SIP. * - * Deprecated: use linphone_core_set_sip_transports() instead. + * @deprecated use linphone_core_set_sip_transports() instead. * @ingroup network_parameters **/ void linphone_core_set_sip_port(LinphoneCore *lc,int port) diff --git a/tools/python/apixml2python.py b/tools/python/apixml2python.py index 2c32a24f6..2e976abe9 100755 --- a/tools/python/apixml2python.py +++ b/tools/python/apixml2python.py @@ -74,6 +74,8 @@ hand_written_functions = [ HandWrittenClassMethod('Buffer', 'new_from_data', 'linphone_buffer_new_from_data', "Create a new LinphoneBuffer object from existing data.\n\n:param data: The initial data to store in the LinphoneBuffer.\n:type data: ByteArray\n:returns: A new LinphoneBuffer object.\n:rtype: linphone.Buffer"), HandWrittenProperty('Buffer', 'content', 'linphone_buffer_get_content', 'linphone_buffer_set_content', "[ByteArray] Set the content of the data buffer."), HandWrittenProperty('Content', 'buffer', 'linphone_content_get_buffer', 'linphone_content_set_buffer', "[ByteArray] Set the content data buffer."), + HandWrittenProperty('Core', 'sip_transports', 'linphone_core_get_sip_transports', 'linphone_core_set_sip_transports', "[:py:class:`linphone.SipTransports`] Sets the ports to be used for each transport. A zero value port for a given transport means the transport is not used. A value of LC_SIP_TRANSPORT_RANDOM (-1) means the port is to be chosen randomly by the system."), + HandWrittenProperty('Core', 'sip_transports_used', 'linphone_core_get_sip_transports_used', None, "[:py:class:`linphone.SipTransports`] Retrieves the real port number assigned for each sip transport (udp, tcp, tls). A zero value means that the transport is not activated. If LC_SIP_TRANSPORT_RANDOM was passed to :py:attr:`linphone.Core.sip_transports`, the random port choosed by the system is returned."), HandWrittenProperty('Core', 'sound_devices', 'linphone_core_get_sound_devices', None, "[list of string] Get the available sound devices."), HandWrittenProperty('Core', 'video_devices', 'linphone_core_get_video_devices', None, "[list of string] Get the available video capture devices."), HandWrittenClassMethod('Core', 'new', 'linphone_core_new', "Instantiate a LinphoneCore object.\n\n:param vtable: The callbacks.\n:type vtable: dictionary\n:param configPath: A path to a config file. If it does not exists it will be created. The config file is used to store all settings, call logs, friends, proxies... so that all these settings become persistent over the life of the LinphoneCore object. It is allowed to set to None. In that case LinphoneCore will not store any settings.\n:type configPath: string\n:param factoryConfigPath: A path to a read-only config file that can be used to store hard-coded preference such as proxy settings or internal preferences. The settings in this factory file always override the one in the normal config file. It is OPTIONAL, use None if unneeded.\n:type factoryConfigPath: string\n:rtype: linphone.Core"), diff --git a/tools/python/apixml2python/handwritten_declarations.mustache b/tools/python/apixml2python/handwritten_declarations.mustache index a9c2d1ee6..3fcb43c2b 100644 --- a/tools/python/apixml2python/handwritten_declarations.mustache +++ b/tools/python/apixml2python/handwritten_declarations.mustache @@ -1,3 +1,6 @@ +static PyObject * pylinphone_Core_get_sip_transports(PyObject *self, void *closure); +static int pylinphone_Core_set_sip_transports(PyObject *self, PyObject *value, void *closure); +static PyObject * pylinphone_Core_get_sip_transports_used(PyObject *self, void *closure); static PyObject * pylinphone_Core_get_sound_devices(PyObject *self, void *closure); static PyObject * pylinphone_Core_get_video_devices(PyObject *self, void *closure); diff --git a/tools/python/apixml2python/handwritten_definitions.mustache b/tools/python/apixml2python/handwritten_definitions.mustache index 6b2e176f1..cf1b9b1d8 100644 --- a/tools/python/apixml2python/handwritten_definitions.mustache +++ b/tools/python/apixml2python/handwritten_definitions.mustache @@ -128,6 +128,75 @@ static PyObject * pylinphone_module_method_set_log_handler(PyObject *self, PyObj } +static PyObject * pylinphone_Core_get_sip_transports(PyObject *self, void *closure) { + PyObject *pytr; + LCSipTransports tr = { 0 }; + LinphoneCore *native_ptr = pylinphone_Core_get_native_ptr(self); + + if (native_ptr == NULL) { + PyErr_SetString(PyExc_TypeError, "Invalid linphone.Core instance"); + return NULL; + } + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p])", __FUNCTION__, self, native_ptr); + linphone_core_get_sip_transports(native_ptr, &tr); + pylinphone_dispatch_messages(); + + pytr = PyLinphoneSipTransports_FromLCSipTransports(tr); + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> %p", __FUNCTION__, pytr); + return pytr; +} + +static int pylinphone_Core_set_sip_transports(PyObject *self, PyObject *value, void *closure) { + LinphoneCore *native_ptr; + PyObject * _tr_config; + const LCSipTransports * _tr_config_native_obj; + native_ptr = pylinphone_Core_get_native_ptr(self); + if (native_ptr == NULL) { + PyErr_SetString(PyExc_TypeError, "Invalid linphone.Core instance"); + return -1; + } + + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot delete the 'sip_transports' attribute."); + return -1; + } + if (!PyLinphoneSipTransports_Check(value)) { + PyErr_SetString(PyExc_TypeError, "The 'sip_transports' attribute value must be a linphone.SipTransports."); + return -1; + } + + _tr_config = value; + _tr_config_native_obj = PyLinphoneSipTransports_AsLCSipTransports(value); + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p], %p [%p])", __FUNCTION__, self, native_ptr, _tr_config, _tr_config_native_obj); + linphone_core_set_sip_transports(native_ptr, _tr_config_native_obj); + pylinphone_dispatch_messages(); + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> 0", __FUNCTION__); + return 0; +} + +static PyObject * pylinphone_Core_get_sip_transports_used(PyObject *self, void *closure) { + PyObject *pytr; + LCSipTransports tr = { 0 }; + LinphoneCore *native_ptr = pylinphone_Core_get_native_ptr(self); + + if (native_ptr == NULL) { + PyErr_SetString(PyExc_TypeError, "Invalid linphone.Core instance"); + return NULL; + } + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p])", __FUNCTION__, self, native_ptr); + linphone_core_get_sip_transports_used(native_ptr, &tr); + pylinphone_dispatch_messages(); + + pytr = PyLinphoneSipTransports_FromLCSipTransports(tr); + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> %p", __FUNCTION__, pytr); + return pytr; +} + + + static PyObject * pylinphone_Core_get_sound_devices(PyObject *self, void *closure) { PyObject *_list; const char **_devices; diff --git a/tools/python/unittests/test_setup.py b/tools/python/unittests/test_setup.py index 9afcda434..9fcafa8b8 100644 --- a/tools/python/unittests/test_setup.py +++ b/tools/python/unittests/test_setup.py @@ -5,6 +5,13 @@ import os class TestSetup: + def test_address(self): + create_address(None) + + def test_version(self): + lc = linphone.Core.new({}, None, None) + assert_equals(lc.version.find("unknown"), -1) + def test_address(self): create_address(None) @@ -14,6 +21,23 @@ class TestSetup: if lc is not None: lc.verify_server_certificates(False) + def test_random_transport(self): + lc = linphone.Core.new({}, None, None) + assert lc is not None + tr = lc.sip_transports + assert_equals(tr.udp_port, 5060) # default config + assert_equals(tr.tcp_port, 5060) # default config + tr.udp_port = -1 + tr.tcp_port = -1 + tr.tls_port = -1 + lc.sip_transports = tr + tr = lc.sip_transports + assert tr.udp_port != 5060 # default config + assert tr.tcp_port != 5060 # default config + assert_equals(lc.config.get_int('sip', 'sip_port', -2), -1) + assert_equals(lc.config.get_int('sip', 'sip_tcp_port', -2), -1) + assert_equals(lc.config.get_int('sip', 'sip_tls_port', -2), -1) + def test_interpret_url(self): lc = linphone.Core.new({}, None, None) assert lc is not None @@ -32,6 +56,22 @@ class TestSetup: conf = linphone.LpConfig.new_from_buffer(buffer_linebreaks) assert_equals(conf.get_string("buffer_linebreaks", "test", ""), "ok") + def test_lpconfig_zerolen_value_from_buffer(self): + zerolen = "[test]\nzero_len=\nnon_zero_len=test" + conf = linphone.LpConfig.new_from_buffer(zerolen) + assert_equals(conf.get_string("test", "zero_len", "LOL"), "LOL") + assert_equals(conf.get_string("test", "non_zero_len", ""), "test") + conf.set_string("test", "non_zero_len", "") # should remove "non_zero_len" + assert_equals(conf.get_string("test", "non_zero_len", "LOL"), "LOL") + + def test_lpconfig_zerolen_value_from_file(self): + conf = linphone.LpConfig.new_with_factory(None, os.path.join(tester_resources_path, 'rcfiles', 'zero_length_params_rc')) + assert_equals(conf.get_string("test", "zero_len", "LOL"), "LOL") + # non_zero_len=test -> should return test + assert_equals(conf.get_string("test", "non_zero_len", ""), "test") + conf.set_string("test", "non_zero_len", "") # should remove "non_zero_len" + assert_equals(conf.get_string("test", "non_zero_len", "LOL"), "LOL") + def test_create_chat_room(self): lc = linphone.Core.new({}, None, None) assert lc is not None