message_tester.c 122 KB
Newer Older
jehan's avatar
jehan committed
1
/*
2 3
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL
jehan's avatar
jehan committed
4

5 6 7 8
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.
jehan's avatar
jehan committed
9

10 11 12 13
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
jehan's avatar
jehan committed
14

15 16
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
jehan's avatar
jehan committed
17
*/
18

Simon Morlat's avatar
Simon Morlat committed
19

20

21
#include "linphone/core.h"
jehan's avatar
jehan committed
22
#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
23
#include "tester_utils.h"
24
#include "lime.h"
25
#include "bctoolbox/crypto.h"
26
#include <belle-sip/object.h>
27
#include "linphone/core_utils.h"
28
#include <bctoolbox/vfs.h>
jehan's avatar
jehan committed
29

30 31 32
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#endif
33

34

Simon Morlat's avatar
Simon Morlat committed
35
static char* message_external_body_url=NULL;
36

37 38 39 40
/* sql cache creation string, contains 3 string to be inserted : selfuri/selfuri/peeruri */
static const char *marie_zid_sqlcache = "BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS ziduri (zuid          INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,zid		BLOB NOT NULL DEFAULT '000000000000',selfuri	 TEXT NOT NULL DEFAULT 'unset',peeruri	 TEXT NOT NULL DEFAULT 'unset'); INSERT INTO `ziduri` (zuid,zid,selfuri,peeruri) VALUES (1,X'4ddc8042bee500ad0366bf93','%s','self'), (2,X'bcb4028bf55e1b7ac4c4edee','%s','%s'); CREATE TABLE IF NOT EXISTS zrtp (zuid		INTEGER NOT NULL DEFAULT 0 UNIQUE,rs1		BLOB DEFAULT NULL,rs2		BLOB DEFAULT NULL,aux		BLOB DEFAULT NULL,pbx		BLOB DEFAULT NULL,pvs		BLOB DEFAULT NULL,FOREIGN KEY(zuid) REFERENCES ziduri(zuid) ON UPDATE CASCADE ON DELETE CASCADE); INSERT INTO `zrtp` (zuid,rs1,rs2,aux,pbx,pvs) VALUES (2,X'f0e0ad4d3d4217ba4048d1553e5ab26fae0b386cdac603f29a66d5f4258e14ef',NULL,NULL,NULL,X'01'); CREATE TABLE IF NOT EXISTS lime (zuid		INTEGER NOT NULL DEFAULT 0 UNIQUE,sndKey		BLOB DEFAULT NULL,rcvKey		BLOB DEFAULT NULL,sndSId		BLOB DEFAULT NULL,rcvSId		BLOB DEFAULT NULL,sndIndex	BLOB DEFAULT NULL,rcvIndex	BLOB DEFAULT NULL,valid		BLOB DEFAULT NULL,FOREIGN KEY(zuid) REFERENCES ziduri(zuid) ON UPDATE CASCADE ON DELETE CASCADE); INSERT INTO `lime` (zuid,sndKey,rcvKey,sndSId,rcvSId,sndIndex,rcvIndex,valid) VALUES (2,X'97c75a5a92a041b415296beec268efc3373ef4aa8b3d5f301ac7522a7fb4e332',x'3b74b709b961e5ebccb1db6b850ea8c1f490546d6adee2f66b5def7093cead3d',X'e2ebca22ad33071bc37631393bf25fc0a9badeea7bf6dcbcb5d480be7ff8c5ea',X'a2086d195344ec2997bf3de7441d261041cda5d90ed0a0411ab2032e5860ea48',X'33376935',X'7ce32d86',X'0000000000000000'); COMMIT;";

static const char *pauline_zid_sqlcache = "BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS ziduri (zuid          INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,zid		BLOB NOT NULL DEFAULT '000000000000',selfuri	 TEXT NOT NULL DEFAULT 'unset',peeruri	 TEXT NOT NULL DEFAULT 'unset'); INSERT INTO `ziduri` (zuid,zid,selfuri,peeruri) VALUES (1,X'bcb4028bf55e1b7ac4c4edee','%s','self'), (2,X'4ddc8042bee500ad0366bf93','%s','%s'); CREATE TABLE IF NOT EXISTS zrtp (zuid		INTEGER NOT NULL DEFAULT 0 UNIQUE,rs1		BLOB DEFAULT NULL,rs2		BLOB DEFAULT NULL,aux		BLOB DEFAULT NULL,pbx		BLOB DEFAULT NULL,pvs		BLOB DEFAULT NULL,FOREIGN KEY(zuid) REFERENCES ziduri(zuid) ON UPDATE CASCADE ON DELETE CASCADE); INSERT INTO `zrtp` (zuid,rs1,rs2,aux,pbx,pvs) VALUES (2,X'f0e0ad4d3d4217ba4048d1553e5ab26fae0b386cdac603f29a66d5f4258e14ef',NULL,NULL,NULL,X'01'); CREATE TABLE IF NOT EXISTS lime (zuid		INTEGER NOT NULL DEFAULT 0 UNIQUE,sndKey		BLOB DEFAULT NULL,rcvKey		BLOB DEFAULT NULL,sndSId		BLOB DEFAULT NULL,rcvSId		BLOB DEFAULT NULL,sndIndex	BLOB DEFAULT NULL,rcvIndex	BLOB DEFAULT NULL,valid		BLOB DEFAULT NULL,FOREIGN KEY(zuid) REFERENCES ziduri(zuid) ON UPDATE CASCADE ON DELETE CASCADE); INSERT INTO `lime` (zuid,rcvKey,sndKey,rcvSId,sndSId,rcvIndex,sndIndex,valid) VALUES (2,X'97c75a5a92a041b415296beec268efc3373ef4aa8b3d5f301ac7522a7fb4e332',x'3b74b709b961e5ebccb1db6b850ea8c1f490546d6adee2f66b5def7093cead3d',X'e2ebca22ad33071bc37631393bf25fc0a9badeea7bf6dcbcb5d480be7ff8c5ea',X'a2086d195344ec2997bf3de7441d261041cda5d90ed0a0411ab2032e5860ea48',X'33376935',X'7ce32d86',X'0000000000000000'); COMMIT;";
41

42 43
static const char *xmlCacheMigration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cache><selfZID>00112233445566778899aabb</selfZID><peer><ZID>99887766554433221100ffee</ZID><rs1>c4274f13a2b6fa05c15ec93158f930e7264b0a893393376dbc80c6eb1cccdc5a</rs1><uri>sip:bob@sip.linphone.org</uri><sndKey>219d9e445d10d4ed64083c7ccbb83a23bc17a97df0af5de4261f3fe026b05b0b</sndKey><rcvKey>747e72a5cc996413cb9fa6e3d18d8b370436e274cd6ba4efc1a4580340af57ca</rcvKey><sndSId>df2bf38e719fa89e17332cf8d5e774ee70d347baa74d16dee01f306c54789869</sndSId><rcvSId>928ce78b0bfc30427a02b1b668b2b3b0496d5664d7e89b75ed292ee97e3fc850</rcvSId><sndIndex>496bcc89</sndIndex><rcvIndex>59337abe</rcvIndex><rs2>5dda11f388384b349d210612f30824268a3753a7afa52ef6df5866dca76315c4</rs2><uri>sip:bob2@sip.linphone.org</uri></peer><peer><ZID>ffeeddccbbaa987654321012</ZID><rs1>858b495dfad483af3c088f26d68c4beebc638bd44feae45aea726a771727235e</rs1><uri>sip:bob@sip.linphone.org</uri><sndKey>b6aac945057bc4466bfe9a23771c6a1b3b8d72ec3e7d8f30ed63cbc5a9479a25</sndKey><rcvKey>bea5ac3225edd0545b816f061a8190370e3ee5160e75404846a34d1580e0c263</rcvKey><sndSId>17ce70fdf12e500294bcb5f2ffef53096761bb1c912b21e972ae03a5a9f05c47</sndSId><rcvSId>7e13a20e15a517700f0be0921f74b96d4b4a0c539d5e14d5cdd8706441874ac0</rcvSId><sndIndex>75e18caa</sndIndex><rcvIndex>2cfbbf06</rcvIndex><rs2>1533dee20c8116dc2c282cae9adfea689b87bc4c6a4e18a846f12e3e7fea3959</rs2></peer><peer><ZID>0987654321fedcba5a5a5a5a</ZID><rs1>cb6ecc87d1dd87b23f225eec53a26fc541384917623e0c46abab8c0350c6929e</rs1><sndKey>92bb03988e8f0ccfefa37a55fd7c5893bea3bfbb27312f49dd9b10d0e3c15fc7</sndKey><rcvKey>2315705a5830b98f68458fcd49623144cb34a667512c4d44686aee125bb8b622</rcvKey><sndSId>94c56eea0dd829379263b6da3f6ac0a95388090f168a3568736ca0bd9f8d595f</sndSId><rcvSId>c319ae0d41183fec90afc412d42253c5b456580f7a463c111c7293623b8631f4</rcvSId><uri>sip:bob@sip.linphone.org</uri><sndIndex>2c46ddcc</sndIndex><rcvIndex>15f5779e</rcvIndex><valid>0000000058f095bf</valid><pvs>01</pvs></peer></cache>";

44
void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* msg) {
Ronan's avatar
Ronan committed
45
	char* from=linphone_address_as_string(linphone_chat_message_get_from_address(msg));
46
	stats* counters;
47 48
	const char *text=linphone_chat_message_get_text(msg);
	const char *external_body_url=linphone_chat_message_get_external_body_url(msg);
49 50 51
	ms_message("Message from [%s]  is [%s] , external URL [%s]",from?from:""
																,text?text:""
																,external_body_url?external_body_url:"");
jehan's avatar
jehan committed
52
	ms_free(from);
53
	counters = get_stats(lc);
jehan's avatar
jehan committed
54
	counters->number_of_LinphoneMessageReceived++;
55 56 57
	if (counters->last_received_chat_message) {
		linphone_chat_message_unref(counters->last_received_chat_message);
	}
58
	counters->last_received_chat_message=linphone_chat_message_ref(msg);
59
	LinphoneContent * content = linphone_chat_message_get_file_transfer_information(msg);
60
	if (content)
61
		counters->number_of_LinphoneMessageReceivedWithFile++;
62
	else if (linphone_chat_message_get_external_body_url(msg)) {
63
		counters->number_of_LinphoneMessageExtBodyReceived++;
jehan's avatar
jehan committed
64
		if (message_external_body_url) {
65
			BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_external_body_url(msg),message_external_body_url);
jehan's avatar
jehan committed
66 67
			message_external_body_url=NULL;
		}
68
	}
jehan's avatar
jehan committed
69 70
}

71 72 73
/**
 * function invoked when a file transfer is received.
 * */
74
void file_transfer_received(LinphoneChatMessage *msg, const LinphoneContent* content, const LinphoneBuffer *buffer){
75
	FILE* file=NULL;
76
	char *receive_file = NULL;
Ronan's avatar
Ronan committed
77

78
	// If a file path is set, we should NOT call the on_recv callback !
Ronan's avatar
Ronan committed
79 80
	BC_ASSERT_PTR_NULL(linphone_chat_message_get_file_transfer_filepath(msg));

81 82 83 84 85 86
	receive_file = bc_tester_file("receive_file.dump");
	if (!linphone_chat_message_get_user_data(msg)) {
		/*first chunk, creating file*/
		file = fopen(receive_file,"wb");
		linphone_chat_message_set_user_data(msg,(void*)file); /*store fd for next chunks*/
	}
87
	
88 89 90
	file = (FILE*)linphone_chat_message_get_user_data(msg);
	BC_ASSERT_PTR_NOT_NULL(file);
	if (linphone_buffer_is_empty(buffer)) { /* tranfer complete */
91 92
		struct stat st;
		
93 94
		linphone_chat_message_set_user_data(msg, NULL);
		fclose(file);
95 96
		BC_ASSERT_TRUE(stat(receive_file, &st)==0);
		BC_ASSERT_EQUAL((int)linphone_content_get_file_size(content), (int)st.st_size, int, "%i");
97 98 99
	} else { /* store content on a file*/
		if (fwrite(linphone_buffer_get_content(buffer),linphone_buffer_get_size(buffer),1,file)==0){
			ms_error("file_transfer_received(): write() failed: %s",strerror(errno));
100
		}
101
	}
102
	bc_free(receive_file);
103 104 105 106 107
}

/*
 * function called when the file transfer is initiated. file content should be feed into object LinphoneContent
 * */
108
LinphoneBuffer * tester_file_transfer_send(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t size){
109 110 111 112
	LinphoneBuffer *lb;
	size_t file_size;
	size_t size_to_send;
	uint8_t *buf;
113
	FILE *file_to_send = linphone_chat_message_get_user_data(msg);
Ronan's avatar
Ronan committed
114

115
	// If a file path is set, we should NOT call the on_send callback !
Ronan's avatar
Ronan committed
116
	BC_ASSERT_PTR_NULL(linphone_chat_message_get_file_transfer_filepath(msg));
117

Simon Morlat's avatar
Simon Morlat committed
118 119 120 121
	BC_ASSERT_PTR_NOT_NULL(file_to_send);
	if (file_to_send == NULL){
		return NULL;
	}
122 123
	fseek(file_to_send, 0, SEEK_END);
	file_size = ftell(file_to_send);
124
	fseek(file_to_send, (long)offset, SEEK_SET);
125 126
	size_to_send = MIN(size, file_size - offset);
	buf = ms_malloc(size_to_send);
127
	if (fread(buf, sizeof(uint8_t), size_to_send, file_to_send) != size_to_send){
128 129
		// reaching end of file, close it
		fclose(file_to_send);
Simon Morlat's avatar
Simon Morlat committed
130
		linphone_chat_message_set_user_data(msg, NULL);
Simon Morlat's avatar
Simon Morlat committed
131
	}
132 133 134 135 136
	lb = linphone_buffer_new_from_data(buf, size_to_send);
	ms_free(buf);
	return lb;
}

137 138 139
/**
 * function invoked to report file transfer progress.
 * */
140 141 142
void file_transfer_progress_indication(LinphoneChatMessage *msg, const LinphoneContent* content, size_t offset, size_t total) {
	LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg);
	LinphoneCore *lc = linphone_chat_room_get_core(cr);
Ronan's avatar
Ronan committed
143 144
	const LinphoneAddress* from_address = linphone_chat_message_get_from_address(msg);
	const LinphoneAddress* to_address = linphone_chat_message_get_to_address(msg);
145
	char *address = linphone_chat_message_is_outgoing(msg)?linphone_address_as_string(to_address):linphone_address_as_string(from_address);
146
	stats* counters = get_stats(lc);
François Grisez's avatar
François Grisez committed
147 148
	int progress = (int)((offset * 100)/total);
	ms_message(" File transfer  [%d%%] %s of type [%s/%s] %s [%s] \n", progress
149
																	,(linphone_chat_message_is_outgoing(msg)?"sent":"received")
150 151
																	, linphone_content_get_type(content)
																	, linphone_content_get_subtype(content)
152
																	,(linphone_chat_message_is_outgoing(msg)?"to":"from")
153
																	, address);
154
	counters->progress_of_LinphoneFileTransfer = progress;
155 156 157
	if (progress == 100) {
		counters->number_of_LinphoneFileTransferDownloadSuccessful++;
	}
158 159 160
	free(address);
}

161 162
void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
	stats *counters = get_stats(lc);
Ghislain MARY's avatar
Ghislain MARY committed
163
	if (linphone_chat_room_is_remote_composing(room)) {
164 165 166 167 168 169
		counters->number_of_LinphoneIsComposingActiveReceived++;
	} else {
		counters->number_of_LinphoneIsComposingIdleReceived++;
	}
}

Simon Morlat's avatar
Simon Morlat committed
170
void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud) {
171
	liblinphone_tester_chat_message_msg_state_changed(msg, state);
172 173
}

174
void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state) {
175 176
	LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(msg);
	LinphoneCore *lc = linphone_chat_room_get_core(cr);
177
	stats* counters = get_stats(lc);
178
	switch (state) {
Simon Morlat's avatar
Simon Morlat committed
179 180 181 182 183 184 185 186 187 188 189 190 191
		case LinphoneChatMessageStateIdle:
			return;
		case LinphoneChatMessageStateDelivered:
			counters->number_of_LinphoneMessageDelivered++;
			return;
		case LinphoneChatMessageStateNotDelivered:
			counters->number_of_LinphoneMessageNotDelivered++;
			return;
		case LinphoneChatMessageStateInProgress:
			counters->number_of_LinphoneMessageInProgress++;
			return;
		case LinphoneChatMessageStateFileTransferError:
			counters->number_of_LinphoneMessageNotDelivered++;
192
			counters->number_of_LinphoneMessageFileTransferError++;
Simon Morlat's avatar
Simon Morlat committed
193 194 195 196
			return;
		case LinphoneChatMessageStateFileTransferDone:
			counters->number_of_LinphoneMessageFileTransferDone++;
			return;
Ghislain MARY's avatar
Ghislain MARY committed
197 198 199 200 201 202
		case LinphoneChatMessageStateDeliveredToUser:
			counters->number_of_LinphoneMessageDeliveredToUser++;
			return;
		case LinphoneChatMessageStateDisplayed:
			counters->number_of_LinphoneMessageDisplayed++;
			return;
203
	}
204
	ms_error("Unexpected state [%s] for msg [%p]",linphone_chat_message_state_to_string(state), msg);
205
}
jehan's avatar
jehan committed
206

207 208 209 210 211
void compare_files(const char *path1, const char *path2) {
	size_t size1;
	size_t size2;
	uint8_t *buf1;
	uint8_t *buf2;
212

213 214 215 216
	buf1 = (uint8_t*)ms_load_path_content(path1, &size1);
	buf2 = (uint8_t*)ms_load_path_content(path2, &size2);
	BC_ASSERT_PTR_NOT_NULL(buf1);
	BC_ASSERT_PTR_NOT_NULL(buf2);
Simon Morlat's avatar
Simon Morlat committed
217 218 219
	if (buf1 && buf2){
		BC_ASSERT_EQUAL(memcmp(buf1, buf2, size1), 0, int, "%d");
	}
220
	BC_ASSERT_EQUAL((uint8_t)size2, (uint8_t)size1, uint8_t, "%u");
Ronan's avatar
Ronan committed
221

Simon Morlat's avatar
Simon Morlat committed
222 223
	if (buf1) ms_free(buf1);
	if (buf2) ms_free(buf2);
224 225
}

226
LinphoneChatMessage* create_message_from_sintel_trailer(LinphoneChatRoom *chat_room) {
227
	FILE *file_to_send = NULL;
228
	LinphoneChatMessageCbs *cbs;
229 230
	LinphoneContent* content;
	LinphoneChatMessage* msg;
231
	char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
232
	size_t file_size;
233 234 235 236 237
	file_to_send = fopen(send_filepath, "rb");
	fseek(file_to_send, 0, SEEK_END);
	file_size = ftell(file_to_send);
	fseek(file_to_send, 0, SEEK_SET);

Ghislain MARY's avatar
Ghislain MARY committed
238
	content = linphone_core_create_content(linphone_chat_room_get_core(chat_room));
239
	belle_sip_object_set_name(BELLE_SIP_OBJECT(content), "sintel trailer content");
240 241
	linphone_content_set_type(content,"video");
	linphone_content_set_subtype(content,"mkv");
242
	linphone_content_set_size(content,file_size); /*total size to be transfered*/
243
	linphone_content_set_name(content,"sintel_trailer_opus_h264.mkv");
244 245

	msg = linphone_chat_room_create_file_transfer_message(chat_room, content);
246 247 248 249
	cbs = linphone_chat_message_get_callbacks(msg);
	linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send);
	linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
	linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
250
	linphone_chat_message_set_user_data(msg, file_to_send);
251
	BC_ASSERT_PTR_NOT_NULL(linphone_chat_message_get_user_data(msg));
252 253

	linphone_content_unref(content);
254
	bc_free(send_filepath);
255 256 257
	return msg;
}

258
LinphoneChatMessage* create_file_transfer_message_from_sintel_trailer(LinphoneChatRoom *chat_room) {
259
	FILE *file_to_send = NULL;
260
	LinphoneChatMessageCbs *cbs;
261 262
	LinphoneContent* content;
	LinphoneChatMessage* msg;
263
	char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
264 265 266 267 268
	size_t file_size;
	file_to_send = fopen(send_filepath, "rb");
	fseek(file_to_send, 0, SEEK_END);
	file_size = ftell(file_to_send);
	fseek(file_to_send, 0, SEEK_SET);
269

Ghislain MARY's avatar
Ghislain MARY committed
270
	content = linphone_core_create_content(linphone_chat_room_get_core(chat_room));
271
	belle_sip_object_set_name(BELLE_SIP_OBJECT(content), "sintel trailer content");
272 273 274
	linphone_content_set_type(content,"video");
	linphone_content_set_subtype(content,"mkv");
	linphone_content_set_name(content,"sintel_trailer_opus_h264.mkv");
Ghislain MARY's avatar
Ghislain MARY committed
275
	linphone_content_set_file_path(content, send_filepath);
276
	linphone_content_set_size(content,file_size); /*total size to be transfered*/
277 278

	msg = linphone_chat_room_create_file_transfer_message(chat_room, content);
279
	cbs = linphone_chat_message_get_callbacks(msg);
280
	linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send);
281 282
	linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
	linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
283 284

	linphone_content_unref(content);
285
	bc_free(send_filepath);
286 287 288
	return msg;
}

289
void text_message_base(LinphoneCoreManager* marie, LinphoneCoreManager* pauline) {
290 291
	LinphoneChatRoom *room = linphone_core_get_chat_room(pauline->lc,marie->identity);
	LinphoneChatMessage* msg = linphone_chat_room_create_message(room,"Bli bli bli \n blu");
292 293
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
294
	linphone_chat_message_send(msg);
295 296

	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDelivered,1));
297
	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
Ghislain MARY's avatar
Ghislain MARY committed
298 299 300 301
	BC_ASSERT_PTR_NOT_NULL(marie->stat.last_received_chat_message);
	if (marie->stat.last_received_chat_message != NULL) {
		BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_content_type(marie->stat.last_received_chat_message), "text/plain");
	}
302

303
	BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room(marie->lc,pauline->identity));
Sylvain Berfini's avatar
Sylvain Berfini committed
304
	linphone_chat_message_unref(msg);
305 306 307 308 309 310 311 312
}

/****************************** Tests starting below ******************************/

static void text_message(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");

Sylvain Berfini's avatar
Sylvain Berfini committed
313
	text_message_base(marie, pauline);
314 315 316 317 318

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

319
static void text_message_within_call_dialog(void) {
320
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
321
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
322
	lp_config_set_int(linphone_core_get_config(pauline->lc),"sip","chat_use_call_dialogs",1);
323

Simon Morlat's avatar
Simon Morlat committed
324 325
	if (BC_ASSERT_TRUE(call(marie,pauline))){
		linphone_chat_room_send_message(linphone_core_get_chat_room(pauline->lc, marie->identity),"Bla bla bla bla");
326

Simon Morlat's avatar
Simon Morlat committed
327 328 329
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived,1));
		// when using call dialogs, we will never receive delivered status
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,0,int,"%d");
330

Simon Morlat's avatar
Simon Morlat committed
331 332
		end_call(marie, pauline);
	}
333 334 335 336
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

337
static LinphoneAuthInfo* text_message_with_credential_from_auth_cb_auth_info;
338
static void text_message_with_credential_from_auth_cb_auth_info_requested(LinphoneCore *lc, const char *realm, const char *username, const char *domain) {
339
	ms_message("text_message_with_credential_from_auth_callback:Auth info requested  for user id [%s] at realm [%s]\n"
340 341 342 343
						,username
						,realm);
	linphone_core_add_auth_info(lc,text_message_with_credential_from_auth_cb_auth_info); /*add stored authentication info to LinphoneCore*/
}
344
static void text_message_with_credential_from_auth_callback(void) {
345
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
346
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
347
	LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get());
348 349

	/*to force cb to be called*/
350
	text_message_with_credential_from_auth_cb_auth_info=linphone_auth_info_clone((LinphoneAuthInfo*)(linphone_core_get_auth_info_list(pauline->lc)->data));
351
	linphone_core_clear_all_auth_info(pauline->lc);
352 353 354
	linphone_core_cbs_set_auth_info_requested(cbs, text_message_with_credential_from_auth_cb_auth_info_requested);
	linphone_core_add_callbacks(pauline->lc, cbs);
	linphone_core_cbs_unref(cbs);
355

356
	text_message_base(marie, pauline);
357 358 359

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
360
	linphone_auth_info_unref(text_message_with_credential_from_auth_cb_auth_info);
Simon Morlat's avatar
Simon Morlat committed
361
	text_message_with_credential_from_auth_cb_auth_info = NULL;
362 363
}

364
static void text_message_with_privacy(void) {
Simon Morlat's avatar
Simon Morlat committed
365
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
366
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
367
	linphone_proxy_config_set_privacy(linphone_core_get_default_proxy_config(pauline->lc),LinphonePrivacyId);
368

369
	text_message_base(marie, pauline);
370

371 372 373
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
374

375
static void text_message_compatibility_mode(void) {
Simon Morlat's avatar
Simon Morlat committed
376
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
377
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
378 379 380
	LinphoneProxyConfig* proxy = linphone_core_get_default_proxy_config(marie->lc);
	LinphoneAddress* proxy_address=linphone_address_new(linphone_proxy_config_get_server_addr(proxy));
	char route[256];
381
	char*tmp;
382 383
	/*only keep tcp*/
	LCSipTransports transport = {0,-1,0,0};
384 385 386
	linphone_address_clean(proxy_address);
	tmp=linphone_address_as_string_uri_only(proxy_address);
	linphone_proxy_config_set_server_addr(proxy,tmp);
387 388
	sprintf(route,"sip:%s",test_route);
	linphone_proxy_config_set_route(proxy,route);
389
	ms_free(tmp);
Simon Morlat's avatar
Simon Morlat committed
390
	linphone_address_unref(proxy_address);
391 392
	linphone_core_set_sip_transports(marie->lc,&transport);
	marie->stat.number_of_LinphoneRegistrationOk=0;
393
	BC_ASSERT_TRUE (wait_for(marie->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationOk,1));
394

395 396
	text_message_base(marie, pauline);

397 398 399
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
400

401
static void text_message_with_ack(void) {
402 403
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
404 405 406 407 408 409 410 411 412 413 414

	text_message_base(marie, pauline);

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

static void text_message_with_send_error(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
415
	LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
416
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
417 418

	/*simulate a network error*/
419
	sal_set_send_error(linphone_core_get_sal(marie->lc), -1);
420
	linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
421
	linphone_chat_message_send(msg);
422 423

	/* check transient msg list: the msg should be in it, and should be the only one */
424 425
	BC_ASSERT_EQUAL(_linphone_chat_room_get_transient_message_count(chat_room), 1, int, "%d");
	BC_ASSERT_PTR_EQUAL(_linphone_chat_room_get_first_transient_message(chat_room), msg);
426 427 428 429 430 431

	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1));
	/*BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageInProgress,1, int, "%d");*/
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0, int, "%d");

	/* the msg should have been discarded from transient list after an error */
432
	BC_ASSERT_EQUAL(_linphone_chat_room_get_transient_message_count(chat_room), 0, int, "%d");
433

434
	sal_set_send_error(linphone_core_get_sal(marie->lc), 0);
435 436 437 438 439

	/*give a chance to register again to allow linphone_core_manager_destroy to properly unregister*/
	linphone_core_refresh_registers(marie->lc);
	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneRegistrationOk,marie->stat.number_of_LinphoneRegistrationOk + 1));

440
	linphone_chat_message_unref(msg);
441 442
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
443
}
444

Ronan's avatar
Ronan committed
445
void transfer_message_base2(LinphoneCoreManager* marie, LinphoneCoreManager* pauline, bool_t upload_error, bool_t download_error,
446 447
							bool_t use_file_body_handler_in_upload, bool_t use_file_body_handler_in_download, bool_t download_from_history, 
							int auto_download) {
448
	char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
449 450 451
	char *receive_filepath = bc_tester_file("receive_file.dump");
	LinphoneChatRoom* chat_room;
	LinphoneChatMessage* msg;
452
	LinphoneChatMessageCbs *cbs;
453
	int file_transfer_size;
454
	bctbx_list_t *msg_list = NULL;
455

456 457
	/* Remove any previously downloaded file */
	remove(receive_filepath);
Ronan's avatar
Ronan committed
458

459 460
	/* Globally configure an http file transfer server. */
	linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php");
461

462 463
	/* create a chatroom on pauline's side */
	chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Ghislain MARY's avatar
Ghislain MARY committed
464

465
	/* create a file transfer msg */
466
	if (use_file_body_handler_in_upload) {
467
		msg = create_file_transfer_message_from_sintel_trailer(chat_room);
468
	} else {
469
		msg = create_message_from_sintel_trailer(chat_room);
470
	}
471 472 473 474 475 476 477
	const bctbx_list_t *contents = linphone_chat_message_get_contents(msg);
	BC_ASSERT_PTR_NOT_NULL(contents);
	BC_ASSERT_EQUAL(1, bctbx_list_size(contents), int, "%d");
	LinphoneContent *content = (LinphoneContent *)bctbx_list_get_data(contents);
	BC_ASSERT_PTR_NOT_NULL(content);
	file_transfer_size = linphone_content_get_file_size(content);
	BC_ASSERT_NOT_EQUAL(0, file_transfer_size, int, "%d");
Ronan's avatar
Ronan committed
478

479
	linphone_chat_message_send(msg);
480

481
	if (upload_error) {
482 483 484
		int chat_room_size = 0;
		bctbx_list_t *history;

485
		/*wait for file to be 25% uploaded and simulate a network error*/
486 487 488 489 490 491 492 493 494 495
		BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer,25, 60000));
		/* Check that the message is already in the chat room history during file upload */
		chat_room_size = linphone_chat_room_get_history_size(chat_room);
		BC_ASSERT_EQUAL(chat_room_size, 1, int, "%d");
		if (chat_room_size == 1) {
			history = linphone_chat_room_get_history(chat_room, 0);
			LinphoneChatMessage *sent_msg = (LinphoneChatMessage *)bctbx_list_get_data(history);
			BC_ASSERT_EQUAL((int)linphone_chat_message_get_state(sent_msg), (int)LinphoneChatMessageStateInProgress, int, "%d");
			bctbx_list_free_with_data(history, (bctbx_list_free_func)linphone_chat_message_unref);
		}
496
		sal_set_send_error(linphone_core_get_sal(pauline->lc), -1);
497 498 499 500 501 502

		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageNotDelivered,1));

		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageNotDelivered,1, int, "%d");
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,0, int, "%d");

503
		sal_set_send_error(linphone_core_get_sal(pauline->lc), 0);
504 505 506

		linphone_core_refresh_registers(pauline->lc); /*to make sure registration is back in registered and so it can be later unregistered*/
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneRegistrationOk,pauline->stat.number_of_LinphoneRegistrationOk+1));
507 508 509 510 511 512 513 514 515 516

		/* Check that the message is in the chat room history even if the file upload failed */
		chat_room_size = linphone_chat_room_get_history_size(chat_room);
		BC_ASSERT_EQUAL(chat_room_size, 1, int, "%d");
		if (chat_room_size == 1) {
			history = linphone_chat_room_get_history(chat_room, 0);
			LinphoneChatMessage *sent_msg = (LinphoneChatMessage *)bctbx_list_get_data(history);
			BC_ASSERT_EQUAL((int)linphone_chat_message_get_state(sent_msg), (int)LinphoneChatMessageStateNotDelivered, int, "%d");
			bctbx_list_free_with_data(history, (bctbx_list_free_func)linphone_chat_message_unref);
		}
517
	} else {
518
		BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1, 60000));
519
		if (marie->stat.last_received_chat_message) {
520 521
			LinphoneChatRoom *marie_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
			linphone_chat_room_mark_as_read(marie_room);
522 523
			if (auto_download == -1 || (auto_download > 0 && auto_download < file_transfer_size)) {
				// We shoudln't get displayed IMDN until file has been downloaded
524
				BC_ASSERT_FALSE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDisplayed,1, 5000));
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557

				LinphoneChatMessage *recv_msg;
				if (download_from_history) {
					msg_list = linphone_chat_room_get_history(marie_room,1);
					BC_ASSERT_PTR_NOT_NULL(msg_list);
					if (!msg_list)  goto end;
					recv_msg = (LinphoneChatMessage *)msg_list->data;
				} else {
					recv_msg = marie->stat.last_received_chat_message;
				}
				cbs = linphone_chat_message_get_callbacks(recv_msg);
				linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
				linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
				linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
				if (use_file_body_handler_in_download) {
					linphone_chat_message_set_file_transfer_filepath(recv_msg, receive_filepath);
				}
				linphone_chat_message_download_file(recv_msg);

				if (download_error) {
					/* wait for file to be 50% downloaded */
					BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50));
					/* and simulate network error */
					belle_http_provider_set_recv_error(linphone_core_get_http_provider(marie->lc), -1);
					BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneMessageNotDelivered,1, 10000));
					belle_http_provider_set_recv_error(linphone_core_get_http_provider(marie->lc), 0);
					BC_ASSERT_FALSE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDisplayed,1, 5000));
				} else {
					/* wait for a long time in case the DNS SRV resolution takes times - it should be immediate though */
					if (BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,1,55000))) {
						compare_files(send_filepath, receive_filepath);
					}
					BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDisplayed,1, 5000));
558
				}
559
			} else {
560
				BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageDisplayed,1, 5000));
561 562 563 564 565 566
				contents = linphone_chat_message_get_contents(msg);
				BC_ASSERT_PTR_NOT_NULL(contents);
				BC_ASSERT_EQUAL(1, bctbx_list_size(contents), int, "%d");
				content = (LinphoneContent *)bctbx_list_get_data(contents);
				BC_ASSERT_PTR_NOT_NULL(content);
				compare_files(send_filepath, linphone_content_get_file_path(content));
567 568
			}
		}
569 570 571
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d"); //sent twice because of file transfer
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
	}
Sylvain Berfini's avatar
Sylvain Berfini committed
572
end:
573
	linphone_chat_message_unref(msg);
Sylvain Berfini's avatar
Sylvain Berfini committed
574
	bctbx_list_free_with_data(msg_list, (bctbx_list_free_func)linphone_chat_message_unref);
575
	remove(receive_filepath);
576
	bc_free(send_filepath);
577
	bc_free(receive_filepath);
578 579
}

580 581
void transfer_message_base(
	bool_t upload_error, bool_t download_error, bool_t use_file_body_handler_in_upload,
582
	bool_t use_file_body_handler_in_download, bool_t download_from_history, bool_t enable_imdn, int auto_download
583
) {
584 585 586
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
587 588 589 590 591 592 593

		if (enable_imdn) {
			lp_config_set_int(linphone_core_get_config(pauline->lc), "sip", "deliver_imdn", 1);
			lp_config_set_int(linphone_core_get_config(marie->lc), "sip", "deliver_imdn", 1);
			linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(marie->lc));
			linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(pauline->lc));
		}
594 595 596
		linphone_core_set_max_size_for_auto_download_incoming_files(marie->lc, auto_download);

		transfer_message_base2(marie,pauline,upload_error,download_error, use_file_body_handler_in_upload, use_file_body_handler_in_download, download_from_history, auto_download);
597
		linphone_core_manager_destroy(pauline);
598
		linphone_core_manager_destroy(marie);
599
	}
600
}
601
static void transfer_message(void) {
602
	transfer_message_base(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, -1);
603 604 605
}

static void transfer_message_2(void) {
606
	transfer_message_base(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, -1);
607 608 609
}

static void transfer_message_3(void) {
610
	transfer_message_base(FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, -1);
611 612 613
}

static void transfer_message_4(void) {
614 615 616 617 618 619 620 621 622 623 624 625 626
	transfer_message_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, -1);
}

static void transfer_message_auto_download(void) {
	transfer_message_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, 0);
}

static void transfer_message_auto_download_2(void) {
	transfer_message_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, 100000000);
}

static void transfer_message_auto_download_3(void) {
	transfer_message_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, 1);
Sylvain Berfini's avatar
Sylvain Berfini committed
627 628 629
}

static void transfer_message_from_history(void) {
630
	transfer_message_base(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, -1);
631 632 633
}

static void transfer_message_with_upload_io_error(void) {
634
	transfer_message_base(TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, -1);
635 636 637
}

static void transfer_message_with_download_io_error(void) {
638
	transfer_message_base(FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, -1);
639 640 641
}

static void transfer_message_upload_cancelled(void) {
642 643
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
644
		LinphoneChatRoom* chat_room;
645
		LinphoneChatMessage* msg;
646
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
johan's avatar
johan committed
647

648 649
		/* Globally configure an http file transfer server. */
		linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php");
johan's avatar
johan committed
650

651
		/* create a chatroom on pauline's side */
Simon Morlat's avatar
Simon Morlat committed
652
		chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
653

654
		msg = create_message_from_sintel_trailer(chat_room);
655
		linphone_chat_message_send(msg);
johan's avatar
johan committed
656

657 658
		/*wait for file to be 25% uploaded and cancel the transfer */
		BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.progress_of_LinphoneFileTransfer, 25, 60000));
659 660 661 662 663 664
		linphone_chat_message_cancel_file_transfer(msg);

		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageNotDelivered,1));

		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageNotDelivered,1, int, "%d");
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,0, int, "%d");
johan's avatar
johan committed
665

666
		linphone_chat_message_unref(msg);
667
		linphone_core_manager_destroy(pauline);
668
		linphone_core_manager_destroy(marie);
669
	}
johan's avatar
johan committed
670 671
}

672 673 674 675 676
static void transfer_message_download_cancelled(void) {
	LinphoneChatRoom* chat_room;
	LinphoneChatMessage* msg;
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
677

678 679
	/* Globally configure an http file transfer server. */
	linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php");
680

681 682
	/* create a chatroom on pauline's side */
	chat_room = linphone_core_get_chat_room(pauline->lc,marie->identity);
683
	msg = create_message_from_sintel_trailer(chat_room);
684
	linphone_chat_message_send(msg);
685 686

	/* wait for marie to receive pauline's msg */
687
	BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1, 60000));
688 689

	if (marie->stat.last_received_chat_message ) { /* get last msg and use it to download file */
690 691
		LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message);
		linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
692 693 694 695 696 697 698 699 700 701 702 703
		linphone_chat_message_start_file_download(marie->stat.last_received_chat_message, liblinphone_tester_chat_message_state_change, marie->lc);
		/* wait for file to be 50% downloaded */
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.progress_of_LinphoneFileTransfer, 50));
		/* and cancel the transfer */
		linphone_chat_message_cancel_file_transfer(marie->stat.last_received_chat_message);
	}

	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,0, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageNotDelivered,1, int, "%d");

704
	linphone_chat_message_unref(msg);
705 706 707 708
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

709
static void file_transfer_2_messages_simultaneously(void) {
710 711 712 713 714
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneChatRoom* pauline_room;
		LinphoneChatMessage* msg;
		LinphoneChatMessage* msg2;
715
		LinphoneChatMessageCbs *cbs;
716
		char *send_filepath = bc_tester_res("sounds/sintel_trailer_opus_h264.mkv");
717 718 719
		char *receive_filepath = bc_tester_file("receive_file.dump");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");

720 721
		/* Remove any previously downloaded file */
		remove(receive_filepath);
Ronan's avatar
Ronan committed
722

723 724 725 726 727
		/* Globally configure an http file transfer server. */
		linphone_core_set_file_transfer_server(pauline->lc,"https://www.linphone.org:444/lft.php");

		/* create a chatroom on pauline's side */
		pauline_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
728 729
		msg = create_message_from_sintel_trailer(pauline_room);
		msg2 = create_message_from_sintel_trailer(pauline_room);
730

731 732 733
		cbs = linphone_chat_message_get_callbacks(msg2);
		linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);

734
		BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_core_get_chat_rooms(marie->lc)), 0, unsigned int, "%u");
735
		if (bctbx_list_size(linphone_core_get_chat_rooms(marie->lc)) == 0) {
736 737
			linphone_chat_message_send(msg);
			linphone_chat_message_send(msg2);
738
			if (BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1, 60000))) {
739
				LinphoneChatMessage *recvMsg = linphone_chat_message_ref(marie->stat.last_received_chat_message);
740
				BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,2, 60000));
741
				LinphoneChatMessage *recvMsg2 = marie->stat.last_received_chat_message;
742
				BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_core_get_chat_rooms(marie->lc)), 1, unsigned int, "%u");
743 744 745 746 747 748 749 750 751
				if (bctbx_list_size(linphone_core_get_chat_rooms(marie->lc)) != 1) {
					char * buf = ms_strdup_printf("Found %d rooms instead of 1: ", bctbx_list_size(linphone_core_get_chat_rooms(marie->lc)));
					const bctbx_list_t *it = linphone_core_get_chat_rooms(marie->lc);
					while (it) {
						const LinphoneAddress * peer = linphone_chat_room_get_peer_address(it->data);
						buf = ms_strcat_printf("%s, ", linphone_address_get_username(peer));
						it = it->next;
					}
					ms_error("%s", buf);
752
				}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
753

754
				cbs = linphone_chat_message_get_callbacks(recvMsg);
755 756
				linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
				linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
757
				linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
758
				linphone_chat_message_download_file(recvMsg);
759

760
				cbs = linphone_chat_message_get_callbacks(recvMsg2);
761 762
				linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
				linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
763
				linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
764
				linphone_chat_message_download_file(recvMsg2);
765

766
				BC_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneFileTransferDownloadSuccessful,2,50000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
767

768 769 770
				BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,4, int, "%d");
				BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,2, int, "%d");
				compare_files(send_filepath, receive_filepath);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
771

772
				linphone_chat_message_unref(recvMsg);
773 774
			}
		}
775 776
		linphone_chat_message_unref(msg);
		linphone_chat_message_unref(msg2);
777
		linphone_core_manager_destroy(pauline);
778
		remove(receive_filepath);
779
		bc_free(send_filepath);
780
		bc_free(receive_filepath);
781 782 783 784
		linphone_core_manager_destroy(marie);
	}
}

785 786 787 788 789 790 791 792 793 794
static void file_transfer_external_body_url(bool_t use_file_body_handler_in_download) {
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
	LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room, NULL);
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
	char *receive_filepath = bc_tester_file("receive_file.dump");

	linphone_chat_message_set_external_body_url(msg, "https://www.linphone.org/img/linphone-open-source-voip-projectX2.png");
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
795
	linphone_chat_message_send(msg);
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
	linphone_chat_message_unref(msg);

	BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceivedWithFile, 1, 60000));

	if (pauline->stat.last_received_chat_message) {
		LinphoneChatMessage *recv_msg = pauline->stat.last_received_chat_message;
		cbs = linphone_chat_message_get_callbacks(recv_msg);
		linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
		linphone_chat_message_cbs_set_file_transfer_recv(cbs, file_transfer_received);
		linphone_chat_message_cbs_set_file_transfer_progress_indication(cbs, file_transfer_progress_indication);
		if (use_file_body_handler_in_download) {
			/* Remove any previously downloaded file */
			remove(receive_filepath);
			linphone_chat_message_set_file_transfer_filepath(recv_msg, receive_filepath);
		}
		linphone_chat_message_download_file(recv_msg);

		/* wait for a long time in case the DNS SRV resolution takes times - it should be immediate though */
		BC_ASSERT_TRUE(wait_for_until(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneFileTransferDownloadSuccessful, 1, 55000));
	}

	remove(receive_filepath);
	bc_free(receive_filepath);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

static void file_transfer_using_external_body_url(void) {
	file_transfer_external_body_url(FALSE);
}

static void file_transfer_using_external_body_url_2(void) {
	file_transfer_external_body_url(TRUE);
}

831 832 833 834 835
static void text_message_denied(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
	LinphoneChatMessage* msg = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
836
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(msg);
837 838 839

	/*pauline doesn't want to be disturbed*/
	linphone_core_disable_chat(pauline->lc,LinphoneReasonDoNotDisturb);
840
	linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
841
	linphone_chat_message_send(msg);
842 843 844

	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1));
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0, int, "%d");
845
	linphone_chat_message_unref(msg);
846 847 848 849 850 851 852 853 854 855
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

static const char *info_content="<somexml>blabla</somexml>";

void info_message_received(LinphoneCore *lc, LinphoneCall* call, const LinphoneInfoMessage *msg){
	stats* counters = get_stats(lc);

	if (counters->last_received_info_message) {
856
		linphone_info_message_unref(counters->last_received_info_message);
857 858 859 860 861 862 863 864 865 866 867 868 869
	}
	counters->last_received_info_message=linphone_info_message_copy(msg);
	counters->number_of_inforeceived++;
}

void info_message_base(bool_t with_content) {
	LinphoneInfoMessage *info;
	const LinphoneContent *content;
	const char *hvalue;

	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");

Simon Morlat's avatar
Simon Morlat committed
870 871 872 873 874 875 876 877 878 879 880
	if (BC_ASSERT_TRUE(call(pauline,marie))){

		info=linphone_core_create_info_message(marie->lc);
		linphone_info_message_add_header(info,"Weather","still bad");
		if (with_content) {
			LinphoneContent* content = linphone_core_create_content(marie->lc);
			linphone_content_set_type(content, "application");
			linphone_content_set_subtype(content, "somexml");
			linphone_content_set_buffer(content, (const uint8_t *)info_content, strlen(info_content));
			linphone_info_message_set_content(info, content);
			linphone_content_unref(content);
881
		}
Simon Morlat's avatar
Simon Morlat committed
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
		linphone_call_send_info_message(linphone_core_get_current_call(marie->lc),info);
		linphone_info_message_unref(info);

		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_inforeceived,1));

		BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_info_message);
		hvalue=linphone_info_message_get_header(pauline->stat.last_received_info_message, "Weather");
		content=linphone_info_message_get_content(pauline->stat.last_received_info_message);

		BC_ASSERT_PTR_NOT_NULL(hvalue);
		if (hvalue)
			BC_ASSERT_STRING_EQUAL(hvalue, "still bad");

		if (with_content){
			BC_ASSERT_PTR_NOT_NULL(content);
			if (content) {
				BC_ASSERT_PTR_NOT_NULL(linphone_content_get_buffer(content));
				BC_ASSERT_PTR_NOT_NULL(linphone_content_get_type(content));
				BC_ASSERT_PTR_NOT_NULL(linphone_content_get_subtype(content));
				if (linphone_content_get_type(content)) BC_ASSERT_STRING_EQUAL(linphone_content_get_type(content),"application");
				if (linphone_content_get_subtype(content)) BC_ASSERT_STRING_EQUAL(linphone_content_get_subtype(content),"somexml");
				if (linphone_content_get_buffer(content))BC_ASSERT_STRING_EQUAL(linphone_content_get_string_buffer(content),info_content);
				BC_ASSERT_EQUAL((int)linphone_content_get_size(content),(int)strlen(info_content), int, "%d");
			}
		}
		end_call(marie, pauline);
908 909 910 911 912
	}
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

913
static void info_message(void){
914 915 916
	info_message_base(FALSE);
}

917
static void info_message_with_body(void){
918 919 920
	info_message_base(TRUE);
}

921 922
static int enable_lime_for_message_test(LinphoneCoreManager *marie, LinphoneCoreManager *pauline) {
	char* filepath = NULL;
923 924 925 926 927
	char* stmt = NULL;
	char* errmsg=NULL;
	int ret = 0;
	char* paulineUri = NULL;
	char* marieUri = NULL;
Simon Morlat's avatar
Simon Morlat committed
928
	char *tmp;
929

930
	if (!linphone_core_lime_available(marie->lc) || !linphone_core_lime_available(pauline->lc)) {
931
		ms_warning("Lime not available, skipping");
932 933 934 935 936 937
		return -1;
	}
	/* make sure lime is enabled */
	linphone_core_enable_lime(marie->lc, LinphoneLimeMandatory);
	linphone_core_enable_lime(pauline->lc, LinphoneLimeMandatory);

938
	/* make sure to not trigger the cache migration function */
939 940
	lp_config_set_int(linphone_core_get_config(marie->lc), "sip", "zrtp_cache_migration_done", TRUE);
	lp_config_set_int(linphone_core_get_config(pauline->lc), "sip", "zrtp_cache_migration_done", TRUE);
941

942
	/* create temporary cache files: setting the database_path will create and initialise the files */
Simon Morlat's avatar
Simon Morlat committed
943 944 945 946 947 948
	tmp = bc_tester_file("tmpZIDCacheMarie.sqlite");
	remove(tmp);
	bc_free(tmp);
	tmp = bc_tester_file("tmpZIDCachePauline.sqlite");
	remove(tmp);
	bc_free(tmp);
949
	filepath = bc_tester_file("tmpZIDCacheMarie.sqlite");
950
	linphone_core_set_zrtp_secrets_file(marie->lc, filepath);
951 952
	bc_free(filepath);
	filepath = bc_tester_file("tmpZIDCachePauline.sqlite");
953
	linphone_core_set_zrtp_secrets_file(pauline->lc, filepath);
954 955
	bc_free(filepath);

956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
	/* caches are empty, populate them */
	paulineUri =  linphone_address_as_string_uri_only(pauline->identity);
	marieUri = linphone_address_as_string_uri_only(marie->identity);

	stmt = sqlite3_mprintf(marie_zid_sqlcache, marieUri, marieUri, paulineUri);
	ret = sqlite3_exec(linphone_core_get_zrtp_cache_db(marie->lc),stmt,NULL,NULL,&errmsg);
	sqlite3_free(stmt);
	if (ret != SQLITE_OK) {
		ms_warning("Lime can't populate marie's sqlite cache: %s", errmsg);
		sqlite3_free(errmsg);
		return -1;
	}
	stmt = sqlite3_mprintf(pauline_zid_sqlcache, paulineUri, paulineUri, marieUri);
	ret = sqlite3_exec(linphone_core_get_zrtp_cache_db(pauline->lc),stmt,NULL,NULL,&errmsg);
	sqlite3_free(stmt);
	if (ret != SQLITE_OK) {
		ms_warning("Lime can't populate pauline's sqlite cache: %s", errmsg);
		sqlite3_free(errmsg);
		return -1;
	}
Simon Morlat's avatar
Simon Morlat committed
976 977
	ms_free(paulineUri);
	ms_free(marieUri);
978

979 980 981
	return 0;
}

982
static void _is_composing_notification(bool_t lime_enabled) {
983 984
	LinphoneChatRoom* pauline_chat_room;
	LinphoneChatRoom* marie_chat_room;
985
	int dummy = 0;
986
	const bctbx_list_t *composing_addresses = NULL;
987 988 989

	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc");
990
	lp_config_set_int(linphone_core_get_config(marie->lc), "sip", "deliver_imdn", 1);
991

992
	if (lime_enabled) {
993
		if (enable_lime_for_message_test(marie, pauline) < 0) goto end;
994
	}
995

996 997
	pauline_chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
	marie_chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
998
	linphone_core_get_chat_room(marie->lc, pauline->identity); /*make marie create the chatroom with pauline, which is necessary for receiving the is-composing*/
999
	linphone_chat_room_compose(pauline_chat_room);
1000
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1));
1001 1002 1003 1004
	composing_addresses = linphone_chat_room_get_composing_addresses(marie_chat_room);
	BC_ASSERT_GREATER(bctbx_list_size(composing_addresses), 0, int, "%i");
	if (bctbx_list_size(composing_addresses) > 0) {
		LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(composing_addresses);
1005 1006 1007 1008 1009
		char *address_string = linphone_address_as_string(addr);
		char *pauline_address = linphone_address_as_string(pauline->identity);
		BC_ASSERT_STRING_EQUAL(address_string, pauline_address);
		bctbx_free(address_string);
		bctbx_free(pauline_address);
1010
	}
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1));
	LinphoneChatMessage *is_composing_msg = marie->stat.last_received_chat_message;
	if (BC_ASSERT_PTR_NOT_NULL(is_composing_msg)) {
		const char *expires = linphone_chat_message_get_custom_header(is_composing_msg, "Expires");
		if (BC_ASSERT_PTR_NOT_NULL(expires))
			BC_ASSERT_STRING_EQUAL(expires, "0");

		const char *priority = linphone_chat_message_get_custom_header(is_composing_msg, "Priority");
		if (BC_ASSERT_PTR_NOT_NULL(priority))
			BC_ASSERT_STRING_EQUAL(priority, "non-urgent");
	}
	wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /*just to sleep while iterating*/
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 1));
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 2));
	is_composing_msg = marie->stat.last_received_chat_message;
	if (BC_ASSERT_PTR_NOT_NULL(is_composing_msg)) {
		const char *expires = linphone_chat_message_get_custom_header(is_composing_msg, "Expires");
		if (BC_ASSERT_PTR_NOT_NULL(expires))
			BC_ASSERT_STRING_EQUAL(expires, "0");

		const char *priority = linphone_chat_message_get_custom_header(is_composing_msg, "Priority");
		if (BC_ASSERT_PTR_NOT_NULL(priority))
			BC_ASSERT_STRING_EQUAL(priority, "non-urgent");
	}
	linphone_chat_room_send_message(pauline_chat_room, "Composing a msg");
1036
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 2));
1037 1038
	composing_addresses = linphone_chat_room_get_composing_addresses(marie_chat_room);
	BC_ASSERT_EQUAL(bctbx_list_size(composing_addresses), 0, int, "%i");
1039

1040
end:
1041 1042
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
1043 1044
	remove("tmpZIDCacheMarie.sqlite");
	remove("tmpZIDCachePauline.sqlite");
1045 1046
}

1047
static void is_composing_notification(void) {
1048 1049 1050
	_is_composing_notification(FALSE);
}

1051
static void is_composing_notification_with_lime(void) {
1052
	_is_composing_notification(TRUE);
1053 1054
}

1055
static void _imdn_notifications(bool_t with_lime) {
Ghislain MARY's avatar
Ghislain MARY committed
1056
	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
1057
	LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_tcp_rc");
1058
	lp_config_set_int(linphone_core_get_config(pauline->lc), "sip", "deliver_imdn", 1);
Ghislain MARY's avatar
Ghislain MARY committed
1059 1060
	LinphoneChatRoom *pauline_chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
	LinphoneChatRoom *marie_chat_room;
1061 1062
	LinphoneChatMessage *sent_cm;
	LinphoneChatMessage *received_cm;
1063
	LinphoneChatMessageCbs *cbs;
Ghislain MARY's avatar
Ghislain MARY committed
1064 1065
	bctbx_list_t *history;

1066 1067 1068 1069
	if (with_lime) {
		if (enable_lime_for_message_test(marie, pauline) < 0) goto end;
	}

1070 1071
	linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(marie->lc));
	linphone_im_notif_policy_enable_all(linphone_core_get_im_notif_policy(pauline->lc));
1072 1073
	sent_cm = linphone_chat_room_create_message(pauline_chat_room, "Tell me if you get my message");
	cbs = linphone_chat_message_get_callbacks(sent_cm);
1074
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
1075
	linphone_chat_message_send(sent_cm);
Ghislain MARY's avatar
Ghislain MARY committed
1076 1077 1078 1079
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1));
	marie_chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity);
	history = linphone_chat_room_get_history(marie_chat_room, 1);
	BC_ASSERT_EQUAL((int)bctbx_list_size(history), 1, int, "%d");
Sylvain Berfini's avatar
Sylvain Berfini committed
1080 1081 1082 1083 1084
	if (bctbx_list_size(history) > 0) {
		received_cm = (LinphoneChatMessage *)bctbx_list_nth_data(history, 0);
		BC_ASSERT_PTR_NOT_NULL(received_cm);
		if (received_cm != NULL) {
			BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDeliveredToUser, 1));
1085 1086 1087 1088 1089 1090 1091
			BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceived, 1));
			LinphoneChatMessage *imdn_message = pauline->stat.last_received_chat_message;
			if (BC_ASSERT_PTR_NOT_NULL(imdn_message)) {
				const char *priority = linphone_chat_message_get_custom_header(imdn_message, "Priority");
				if (BC_ASSERT_PTR_NOT_NULL(priority))
					BC_ASSERT_STRING_EQUAL(priority, "non-urgent");
			}
Sylvain Berfini's avatar
Sylvain Berfini committed
1092 1093
			linphone_chat_room_mark_as_read(marie_chat_room); /* This sends the display notification */
			BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDisplayed, 1));
1094 1095 1096 1097 1098 1099 1100
			BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageReceived, 2));
			imdn_message = pauline->stat.last_received_chat_message;
			if (BC_ASSERT_PTR_NOT_NULL(imdn_message)) {
				const char *priority = linphone_chat_message_get_custom_header(imdn_message, "Priority");
				if (BC_ASSERT_PTR_NOT_NULL(priority))
					BC_ASSERT_STRING_EQUAL(priority, "non-urgent");
			}
Sylvain Berfini's avatar
Sylvain Berfini committed
1101 1102
			bctbx_list_free_with_data(history, (bctbx_list_free_func)linphone_chat_message_unref);
		}
Ghislain MARY's avatar
Ghislain MARY committed
1103
	}
1104
	linphone_chat_message_unref(sent_cm);
1105 1106

end:
Ghislain MARY's avatar
Ghislain MARY committed
1107 1108
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
1109 1110
	remove("tmpZIDCacheMarie.sqlite");
	remove("tmpZIDCachePauline.sqlite");
Ghislain MARY's avatar
Ghislain MARY committed
1111 1112
}

Ghislain MARY's avatar