Commit e07c0194 authored by Ghislain MARY's avatar Ghislain MARY

Fix unittests in Python module.

parent be79d631
......@@ -46,32 +46,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
#endif
#ifndef PyInt_Check
#if PY_MAJOR_VERSION >= 3
#define PyInt_Check(p) PyLong_Check(p)
#endif
#ifndef PyInt_AsLong
#if PY_MAJOR_VERSION >= 3
#define PyInt_AsLong(io) PyLong_AsLong(io)
#endif
#ifndef PyInt_AS_LONG
#if PY_MAJOR_VERSION >= 3
static int pylinphone_aslongoverflow;
#define PyInt_AS_LONG(io) PyLong_AsLongAndOverflow(io, &pylinphone_aslongoverflow)
#endif
#ifndef PyInt_AsSsize_t
#if PY_MAJOR_VERSION >= 3
#define PyInt_AsSsize_t(io) PyLong_AsSsize_t(io)
#endif
#ifndef PyInt_AsUnsignedLongMask
#if PY_MAJOR_VERSION >= 3
#define PyInt_AsUnsignedLongMask(io) PyLong_AsUnsignedLongMask(io)
#endif
#ifndef PyString_Check
#if PY_MAJOR_VERSION >= 3
#define PyString_Check(io) PyUnicode_Check(io)
#endif
#ifndef PyString_FromString
#if PY_MAJOR_VERSION >= 3
#define PyString_FromString(v) PyUnicode_FromString(v)
#endif
......
......@@ -216,6 +216,9 @@ class CoreManagerStats:
self.number_of_LinphoneMessageInProgress = 0
self.number_of_LinphoneMessageDelivered = 0
self.number_of_LinphoneMessageNotDelivered = 0
self.number_of_LinphoneMessageFileTransferDone = 0
self.number_of_LinphoneMessageDeliveredToUser = 0
self.number_of_LinphoneMessageDisplayed = 0
self.number_of_LinphoneIsComposingActiveReceived = 0
self.number_of_LinphoneIsComposingIdleReceived = 0
self.number_of_LinphoneFileTransferDownloadSuccessful = 0
......
......@@ -22,6 +22,12 @@ class TestMessage:
stats.number_of_LinphoneMessageInProgress += 1
elif state == linphone.ChatMessageState.FileTransferError:
stats.number_of_LinphoneMessageNotDelivered += 1
elif state == linphone.ChatMessageState.FileTransferDone:
stats.number_of_LinphoneMessageFileTransferDone += 1
elif state == linphone.ChatMessageState.DeliveredToUser:
stats.number_of_LinphoneMessageDeliveredToUser += 1
elif state == linphone.ChatMessageState.Displayed:
stats.number_of_LinphoneMessageDisplayed += 1
else:
linphonetester_logger.error("[TESTER] Unexpected state [{state}] for message [{msg}]".format(msg=msg, state=linphone.ChatMessageState.string(state)))
......@@ -65,13 +71,15 @@ class TestMessage:
f.write(buf.content)
f.close()
def create_message_from_no_webcam(self, chat_room):
send_filepath = os.path.join(tester_resources_path, 'images', 'nowebcamCIF.jpg')
def create_message_from_sintel_trailer(self, chat_room):
send_filepath = os.path.join(tester_resources_path, 'sounds', 'sintel_trailer_opus_h264.mkv')
content = chat_room.core.create_content()
content.type = 'image'
content.subtype = 'jpeg'
content.type = 'video'
content.subtype = 'mkv'
linphonetester_logger.info("[TESTER] os.path.getsize(send_filepath)={}".format(os.path.getsize(send_filepath)))
content.size = os.path.getsize(send_filepath) # total size to be transfered
content.name = 'nowebcamCIF.jpg'
linphonetester_logger.info("[TESTER] content.size={}".format(content.size))
content.name = 'sintel_trailer_opus_h264.mkv'
message = chat_room.create_file_transfer_message(content)
message.callbacks.msg_state_changed = TestMessage.msg_state_changed
message.callbacks.file_transfer_send = TestMessage.file_transfer_send
......@@ -119,14 +127,16 @@ class TestMessage:
def test_transfer_message(self):
marie = CoreManager('marie_rc')
pauline = CoreManager('pauline_tcp_rc')
send_filepath = os.path.join(tester_resources_path, 'images', 'nowebcamCIF.jpg')
send_filepath = os.path.join(tester_resources_path, 'sounds', 'sintel_trailer_opus_h264.mkv')
receive_filepath = 'receive_file.dump'
if os.path.exists(receive_filepath):
os.remove(receive_filepath)
pauline.lc.file_transfer_server = "https://www.linphone.org:444/lft.php"
self.wait_for_server_to_purge_messages(marie, pauline)
chat_room = pauline.lc.get_chat_room(marie.identity)
message = self.create_message_from_no_webcam(chat_room)
message = self.create_message_from_sintel_trailer(chat_room)
chat_room.send_chat_message_2(message)
assert_equals(CoreManager.wait_for(pauline, marie, lambda pauline, marie: marie.stats.number_of_LinphoneMessageReceivedWithFile == 1), True)
assert_equals(CoreManager.wait_for_until(pauline, marie, lambda pauline, marie: marie.stats.number_of_LinphoneMessageReceivedWithFile == 1, 60000), True)
if marie.stats.last_received_chat_message is not None:
cbs = marie.stats.last_received_chat_message.callbacks
cbs.msg_state_changed = TestMessage.msg_state_changed
......@@ -134,7 +144,7 @@ class TestMessage:
cbs.file_transfer_progress_indication = TestMessage.file_transfer_progress_indication
marie.stats.last_received_chat_message.user_data = receive_filepath
marie.stats.last_received_chat_message.download_file()
assert_equals(CoreManager.wait_for(pauline, marie, lambda pauline, marie: marie.stats.number_of_LinphoneFileTransferDownloadSuccessful == 1), True)
assert_equals(CoreManager.wait_for_until(pauline, marie, lambda pauline, marie: marie.stats.number_of_LinphoneFileTransferDownloadSuccessful == 1, 55000), True)
assert_equals(pauline.stats.number_of_LinphoneMessageInProgress, 2)
assert_equals(CoreManager.wait_for(pauline, marie, lambda pauline, marie: pauline.stats.number_of_LinphoneMessageDelivered == 1), True)
assert_equals(filecmp.cmp(send_filepath, receive_filepath, shallow=False), True)
......@@ -147,10 +157,10 @@ class TestMessage:
pauline.lc.file_transfer_server = "https://www.linphone.org:444/lft.php"
self.wait_for_server_to_purge_messages(marie, pauline)
chat_room = pauline.lc.get_chat_room(marie.identity)
message = self.create_message_from_no_webcam(chat_room)
message = self.create_message_from_sintel_trailer(chat_room)
chat_room.send_chat_message_2(message)
# Wait for file to be at least 50% uploaded and cancel the transfer
assert_equals(CoreManager.wait_for(pauline, marie, lambda pauline, marie: pauline.stats.progress_of_LinphoneFileTransfer >= 50), True)
# Wait for file to be at least 25% uploaded and cancel the transfer
assert_equals(CoreManager.wait_for_until(pauline, marie, lambda pauline, marie: pauline.stats.progress_of_LinphoneFileTransfer >= 25, 60000), True)
message.cancel_file_transfer()
assert_equals(CoreManager.wait_for(pauline, marie, lambda pauline, marie: pauline.stats.number_of_LinphoneMessageNotDelivered == 1), True)
assert_equals(pauline.stats.number_of_LinphoneMessageNotDelivered, 1)
......
......@@ -9,8 +9,7 @@ class TestSetup:
linphone.Factory.clean()
def test_version(self):
lc = linphone.Factory.get().create_core(None, None, None)
assert_equals(lc.version.find("unknown"), -1)
assert_equals(linphone.Core.get_version().find("unknown"), -1)
def test_address(self):
create_address(None)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment