flexisip_tester.c 63.8 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1
/*
2 3
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL
Simon Morlat's avatar
Simon Morlat 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.
Simon Morlat's avatar
Simon Morlat 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.
Simon Morlat's avatar
Simon Morlat 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/>.
Simon Morlat's avatar
Simon Morlat committed
17 18
*/

19

20 21
#include "linphone/core.h"
#include "linphone/lpconfig.h"
Simon Morlat's avatar
Simon Morlat committed
22 23 24 25 26
#include "private.h"
#include "liblinphone_tester.h"

static void subscribe_forking(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
27 28
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
	LinphoneCoreManager* pauline2 = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
29
	LinphoneContent* content;
Simon Morlat's avatar
Simon Morlat committed
30 31
	LinphoneEvent *lev;
	int expires=  600;
32
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
33

34 35
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,pauline2->lc);
Simon Morlat's avatar
Simon Morlat committed
36

37 38 39
	content = linphone_core_create_content(marie->lc);
	linphone_content_set_type(content,"application");
	linphone_content_set_subtype(content,"somexml");
40
	linphone_content_set_buffer(content, liblinphone_tester_get_subscribe_content(), strlen(liblinphone_tester_get_subscribe_content()));
41

42
	lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",expires,content);
43

44
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionOutgoingProgress,1,1000));
45 46 47
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionIncomingReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline2->stat.number_of_LinphoneSubscriptionIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionActive,1,1000));
Simon Morlat's avatar
Simon Morlat committed
48 49

	/*make sure marie receives first notification before terminating*/
50
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_NotifyReceived,1,1000));
Simon Morlat's avatar
Simon Morlat committed
51 52

	linphone_event_terminate(lev);
53 54

	linphone_content_unref(content);
Simon Morlat's avatar
Simon Morlat committed
55 56 57
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(pauline2);
58
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
59 60 61 62
}

static void message_forking(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
63
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
64
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
65
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
66
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
67
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
68
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message);
69

70 71
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
72

73
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
74
	linphone_chat_room_send_chat_message(chat_room, message);
75 76 77
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,1000));
78

Simon Morlat's avatar
Simon Morlat committed
79 80 81
	/*wait a bit that 200Ok for MESSAGE are sent to server before shuting down the cores, because otherwise Flexisip will consider the messages
	 * as not delivered and will expedite them in the next test, after receiving the REGISTER from marie's instances*/
	wait_for_list(lcs, NULL, 0, 2000);
82

83
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d");
Simon Morlat's avatar
Simon Morlat committed
84 85 86
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(pauline);
87
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
88 89 90 91
}

static void message_forking_with_unreachable_recipients(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
92
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
93 94
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
95
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
96
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
97
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
98
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message);
99

100 101 102
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
103

Simon Morlat's avatar
Simon Morlat committed
104 105 106 107 108 109
	/*the following lines are to workaround a problem with messages sent by a previous test (Message forking) that arrive together with REGISTER responses,
	 * because the ForkMessageContext is not terminated at flexisip side if Message forking test is passing fast*/
	wait_for_list(lcs,NULL,0,1000);
	marie->stat.number_of_LinphoneMessageReceived = 0;
	marie2->stat.number_of_LinphoneMessageReceived = 0;
	marie3->stat.number_of_LinphoneMessageReceived = 0;
110

Simon Morlat's avatar
Simon Morlat committed
111 112 113
	/*marie2 and marie3 go offline*/
	linphone_core_set_network_reachable(marie2->lc,FALSE);
	linphone_core_set_network_reachable(marie3->lc,FALSE);
114

115
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
116
	linphone_chat_room_send_chat_message(chat_room, message);
117 118 119
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,1000));
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d");
120 121
	BC_ASSERT_EQUAL(marie2->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
	BC_ASSERT_EQUAL(marie3->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
Simon Morlat's avatar
Simon Morlat committed
122 123
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
124
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
125

Simon Morlat's avatar
Simon Morlat committed
126 127
	/*wait a long time so that all transactions are expired*/
	wait_for_list(lcs,NULL,0,32000);
128

Simon Morlat's avatar
Simon Morlat committed
129 130
	/*marie 3 goes online now*/
	linphone_core_set_network_reachable(marie3->lc,TRUE);
131
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000));
132

Simon Morlat's avatar
Simon Morlat committed
133 134
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
135
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
136
	linphone_core_manager_destroy(pauline);
137
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
138 139 140 141
}

static void message_forking_with_all_recipients_unreachable(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
142
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
143 144
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
145
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
146
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
147
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
148
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message);
149

150 151 152
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
153

Simon Morlat's avatar
Simon Morlat committed
154 155 156 157 158 159 160
	/*the following lines are to workaround a problem with messages sent by a previous test (Message forking) that arrive together with REGISTER responses,
	 * because the ForkMessageContext is not terminated at flexisip side if Message forking test is passing fast*/
	wait_for_list(lcs,NULL,0,1000);
	marie->stat.number_of_LinphoneMessageReceived = 0;
	marie2->stat.number_of_LinphoneMessageReceived = 0;
	marie3->stat.number_of_LinphoneMessageReceived = 0;

161

Simon Morlat's avatar
Simon Morlat committed
162 163 164 165
	/*All marie's device go offline*/
	linphone_core_set_network_reachable(marie->lc,FALSE);
	linphone_core_set_network_reachable(marie2->lc,FALSE);
	linphone_core_set_network_reachable(marie3->lc,FALSE);
166

167
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
168
	linphone_chat_room_send_chat_message(chat_room, message);
169

170
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageInProgress,1,5000));
Simon Morlat's avatar
Simon Morlat committed
171
	/*flexisip will accept the message with 202 after 16 seconds*/
172
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,18000));
173 174 175
	BC_ASSERT_EQUAL( marie->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
	BC_ASSERT_EQUAL( marie2->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
	BC_ASSERT_EQUAL( marie3->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
176

Simon Morlat's avatar
Simon Morlat committed
177 178
	/*marie 1 goes online */
	linphone_core_set_network_reachable(marie->lc,TRUE);
179
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000));
180

Simon Morlat's avatar
Simon Morlat committed
181 182
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
183
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
184

Simon Morlat's avatar
Simon Morlat committed
185 186
	/*wait a long time so that all transactions are expired*/
	wait_for_list(lcs,NULL,0,32000);
187

Simon Morlat's avatar
Simon Morlat committed
188 189
	/*marie 3 goes online now*/
	linphone_core_set_network_reachable(marie3->lc,TRUE);
190
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000));
191

Simon Morlat's avatar
Simon Morlat committed
192 193
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
194
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
195
	linphone_core_manager_destroy(pauline);
196
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
197 198 199 200
}

static void call_forking(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
201
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
202 203
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
204
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
205

206 207 208
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
209

Simon Morlat's avatar
Simon Morlat committed
210 211 212 213
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
214

Simon Morlat's avatar
Simon Morlat committed
215 216
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
217
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
218
	/*all devices from Marie should be ringing*/
219 220 221
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,3000));
222

Simon Morlat's avatar
Simon Morlat committed
223
	/*marie accepts the call on its first device*/
224
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
225 226 227 228
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000));
229

Simon Morlat's avatar
Simon Morlat committed
230
	/*other devices should stop ringing*/
231 232
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000));
233

234
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
235 236
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
237

Simon Morlat's avatar
Simon Morlat committed
238 239 240 241
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
242
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
243 244 245 246
}

static void call_forking_with_urgent_reply(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
247
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
248 249
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
250 251 252 253
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
254

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
	if (linphone_core_media_encryption_supported(pauline->lc,LinphoneMediaEncryptionSRTP)) {
		linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
		linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
		linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL);
		linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);


		linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP);
		linphone_core_set_network_reachable(marie2->lc,FALSE);
		linphone_core_set_network_reachable(marie3->lc,FALSE);

		linphone_core_invite_address(pauline->lc,marie->identity);
		/*pauline should hear ringback, after 5 seconds, when it will retry without SRTP*/
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,9000));
		/*Marie should be ringing*/
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000));

		/*marie accepts the call on its first device*/
273
		linphone_call_accept(linphone_core_get_current_call(marie->lc));
274 275 276 277 278
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000));

279
		linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
280 281 282
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
	}
Simon Morlat's avatar
Simon Morlat committed
283 284 285 286
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
287
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
288 289 290 291
}

static void call_forking_cancelled(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
292
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
293 294
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
295
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
296

297 298 299
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
300

Simon Morlat's avatar
Simon Morlat committed
301 302 303 304
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
305

Simon Morlat's avatar
Simon Morlat committed
306 307
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
308
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
309
	/*all devices from Marie should be ringing*/
310 311 312
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000));
313

Simon Morlat's avatar
Simon Morlat committed
314
	/*pauline finally cancels the call*/
315
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
316
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
317

Simon Morlat's avatar
Simon Morlat committed
318
	/*all devices should stop ringing*/
319 320 321
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000));
322

Simon Morlat's avatar
Simon Morlat committed
323 324 325 326
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
327
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
328 329 330 331
}

static void call_forking_declined(bool_t declined_globaly){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
332
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
333 334
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
335
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
336

337 338 339
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
340

Simon Morlat's avatar
Simon Morlat committed
341 342 343 344
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
345

Simon Morlat's avatar
Simon Morlat committed
346 347
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
348
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
349
	/*all devices from Marie should be ringing*/
350 351 352
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000));
353

354
	/*marie finally declines the call*/
355
	linphone_call_decline(linphone_core_get_current_call(marie->lc),
Simon Morlat's avatar
Simon Morlat committed
356 357
		declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy
	);
358

Simon Morlat's avatar
Simon Morlat committed
359
	if (declined_globaly){
360
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Simon Morlat's avatar
Simon Morlat committed
361
		/*all devices should stop ringing*/
362 363 364
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000));
Simon Morlat's avatar
Simon Morlat committed
365 366
	}else{
		/*pauline should continue ringing and be able to hear a call taken by marie2 */
367
		linphone_call_accept(linphone_core_get_current_call(marie2->lc));
368 369
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,2000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallStreamsRunning,1,2000));
Simon Morlat's avatar
Simon Morlat committed
370
		liblinphone_tester_check_rtcp(pauline,marie2);
371 372
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,3000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,3000));
373
		linphone_call_terminate(linphone_core_get_current_call(marie2->lc));
374 375
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,3000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,3000));
Simon Morlat's avatar
Simon Morlat committed
376
	}
377

Simon Morlat's avatar
Simon Morlat committed
378 379 380 381
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
382
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
383 384 385 386 387 388 389 390 391 392 393
}

static void call_forking_declined_globaly(void){
	call_forking_declined(TRUE);
}

static void call_forking_declined_localy(void){
	call_forking_declined(FALSE);
}

static void call_forking_with_push_notification_single(void){
394
	bctbx_list_t* lcs;
395
	LinphoneCoreManager* marie = linphone_core_manager_new2( "marie_rc", FALSE);
396
	LinphoneCoreManager* pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc",FALSE);
397
	int dummy=0;
398

Simon Morlat's avatar
Simon Morlat committed
399 400
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
401 402 403
	linphone_proxy_config_set_contact_uri_parameters(
		linphone_core_get_default_proxy_config(marie->lc),
		"app-id=org.linphonetester;pn-tok=aaabbb;pn-type=apple;pn-msg-str=33;pn-call-str=34;");
404

405 406
	lcs=bctbx_list_append(NULL,pauline->lc);
	lcs=bctbx_list_append(lcs,marie->lc);
407

408 409
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneRegistrationOk,1,5000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneRegistrationOk,1,5000));
410

Simon Morlat's avatar
Simon Morlat committed
411 412
	/*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/
	linphone_core_set_network_reachable(marie->lc,FALSE);
413

Simon Morlat's avatar
Simon Morlat committed
414
	linphone_core_invite_address(pauline->lc,marie->identity);
415

416 417
	/*After 5 seconds the server is expected to send a push notification to marie, this will wake up linphone, that will reconnect:*/
	wait_for_list(lcs,&dummy,1,6000);
Simon Morlat's avatar
Simon Morlat committed
418
	linphone_core_set_network_reachable(marie->lc,TRUE);
419

Simon Morlat's avatar
Simon Morlat committed
420
	/*Marie shall receive the call immediately*/
421
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
422
	/*pauline should hear ringback as well*/
423
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
424

Simon Morlat's avatar
Simon Morlat committed
425
	/*marie accepts the call*/
426
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
427 428 429 430
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,5000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000));
431

Simon Morlat's avatar
Simon Morlat committed
432
	liblinphone_tester_check_rtcp(pauline,marie);
433

434
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
435 436
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,5000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,5000));
437

Simon Morlat's avatar
Simon Morlat committed
438 439
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
440
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
441 442 443 444
}

static void call_forking_with_push_notification_multiple(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
445
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
446
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
447

448
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
449

450 451
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
452

Simon Morlat's avatar
Simon Morlat committed
453 454 455
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
456

Simon Morlat's avatar
Simon Morlat committed
457 458
	/*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/
	linphone_core_set_network_reachable(marie2->lc,FALSE);
459

Simon Morlat's avatar
Simon Morlat committed
460
	linphone_core_invite_address(pauline->lc,marie->identity);
461

462
	/*marie will ring*/
463
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
464
	/*pauline should hear ringback as well*/
465
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
466

Simon Morlat's avatar
Simon Morlat committed
467 468
	/*the server is expected to send a push notification to marie2, this will wake up linphone, that will reconnect:*/
	linphone_core_set_network_reachable(marie2->lc,TRUE);
469

Simon Morlat's avatar
Simon Morlat committed
470
	/*Marie shall receive the call immediately*/
471
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,5000));
472

Simon Morlat's avatar
Simon Morlat committed
473
	/*marie2 accepts the call*/
474
	linphone_call_accept(linphone_core_get_current_call(marie2->lc));
475 476 477 478
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallConnected,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallStreamsRunning,1,1000));
479

480
	/*call to marie should be cancelled*/
481
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
482

Simon Morlat's avatar
Simon Morlat committed
483
	liblinphone_tester_check_rtcp(pauline,marie2);
484

485
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
486

487 488
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
489

Simon Morlat's avatar
Simon Morlat committed
490 491 492 493 494
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
}

495
static void call_forking_not_responded(void){
496
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
497
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
498 499
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
500
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
501

502 503 504
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
505

506 507 508 509
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
510

511 512
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
513
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
514
	/*all devices from Marie should be ringing*/
515 516 517
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000));
518

519
	/*nobody answers, flexisip should close the call after XX seconds*/
520
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallError,1,22000));
521
	/*all devices should stop ringing*/
522 523 524
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000));
525

526 527 528 529
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
530
	bctbx_list_free(lcs);
531 532
}

Simon Morlat's avatar
Simon Morlat committed
533
static void early_media_call_forking(void) {
534
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_early_rc");
Simon Morlat's avatar
Simon Morlat committed
535
	LinphoneCoreManager* marie2 = linphone_core_manager_new("marie_early_rc");
536
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
537
	bctbx_list_t *lcs=NULL;
538
	LinphoneCallParams *params=linphone_core_create_call_params(pauline->lc, NULL);
Simon Morlat's avatar
Simon Morlat committed
539 540
	LinphoneVideoPolicy pol;
	int dummy=0;
541

Simon Morlat's avatar
Simon Morlat committed
542 543
	pol.automatically_accept=1;
	pol.automatically_initiate=1;
544

545
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
Simon Morlat's avatar
Simon Morlat committed
546 547
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
548

549 550
	linphone_core_enable_video_capture(pauline->lc,TRUE);
	linphone_core_enable_video_display(pauline->lc,TRUE);
551

552 553
	linphone_core_enable_video_capture(marie->lc,TRUE);
	linphone_core_enable_video_display(marie->lc,TRUE);
554
	linphone_core_set_video_policy(marie->lc,&pol);
555

556 557 558
	linphone_core_enable_video_capture(marie2->lc,TRUE);
	linphone_core_enable_video_display(marie2->lc,TRUE);

Simon Morlat's avatar
Simon Morlat committed
559 560 561
	linphone_core_set_video_policy(marie2->lc,&pol);
	linphone_core_set_audio_port_range(marie2->lc,40200,40300);
	linphone_core_set_video_port_range(marie2->lc,40400,40500);
562

563 564 565
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,pauline->lc);
Simon Morlat's avatar
Simon Morlat committed
566 567 568

	linphone_call_params_enable_early_media_sending(params,TRUE);
	linphone_call_params_enable_video(params,TRUE);
569

570
	linphone_core_invite_address_with_params(pauline->lc,marie->identity,params);
Simon Morlat's avatar
Simon Morlat committed
571
	linphone_call_params_unref(params);
Simon Morlat's avatar
Simon Morlat committed
572

573
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000));
574 575 576
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie2->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000));
	BC_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1,3000));
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1, int, "%d");
577

Simon Morlat's avatar
Simon Morlat committed
578
	/*wait a bit that streams are established*/
579 580 581 582 583 584 585
	wait_for_list(lcs,&dummy,1,5000);
	BC_ASSERT_GREATER(linphone_core_manager_get_mean_audio_down_bw(pauline), 60, int, "%d");
	BC_ASSERT_LOWER(linphone_core_manager_get_mean_audio_down_bw(pauline), 99, int, "%d");
	BC_ASSERT_GREATER(linphone_core_manager_get_mean_audio_down_bw(marie), 60, int, "%d");
	BC_ASSERT_LOWER(linphone_core_manager_get_mean_audio_down_bw(marie), 99, int, "%d");
	BC_ASSERT_GREATER(linphone_core_manager_get_mean_audio_down_bw(marie2), 60, int, "%d");
	BC_ASSERT_LOWER(linphone_core_manager_get_mean_audio_down_bw(marie2), 99, int, "%d");
586

587
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
588
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,3000));
589
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,3000));
590

Simon Morlat's avatar
Simon Morlat committed
591
	/*marie2 should get her call terminated*/
592
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
593

Simon Morlat's avatar
Simon Morlat committed
594
	/*wait a bit that streams are established*/
Simon Morlat's avatar
Simon Morlat committed
595
	wait_for_list(lcs,&dummy,1,3000);
596 597 598 599
	BC_ASSERT_GREATER(linphone_core_manager_get_mean_audio_down_bw(pauline), 60, int, "%d");
	BC_ASSERT_LOWER(linphone_core_manager_get_mean_audio_down_bw(pauline), 99, int, "%d");
	BC_ASSERT_GREATER(linphone_core_manager_get_mean_audio_down_bw(marie), 60, int, "%d");
	BC_ASSERT_LOWER(linphone_core_manager_get_mean_audio_down_bw(marie), 99, int, "%d");
600

601
	end_call(pauline, marie);
Simon Morlat's avatar
Simon Morlat committed
602

603
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
604
	linphone_core_manager_destroy(pauline);
605 606
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie);
Simon Morlat's avatar
Simon Morlat committed
607 608
}

609
static void call_with_sips(void){
610
	if (transport_supported(LinphoneTransportTls)) {
611 612
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_sips_rc");
613
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
614
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
615

616 617
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
618

619 620 621
		linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
		linphone_core_set_user_agent(pauline1->lc,"Natted Linphone",NULL);
		linphone_core_set_user_agent(pauline2->lc,"Natted Linphone",NULL);
622

623
		linphone_core_invite_address(marie->lc,pauline1->identity);
624

625 626 627 628
		/*marie should hear ringback*/
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
		/*Only the sips registered device from pauline should ring*/
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallIncomingReceived,1,1000));
629

630
		/*pauline accepts the call */
631
		linphone_call_accept(linphone_core_get_current_call(pauline1->lc));
632 633 634 635
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallConnected,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallStreamsRunning,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000));
636

637 638
		/*pauline2 should not have ring*/
		BC_ASSERT_EQUAL(pauline2->stat.number_of_LinphoneCallIncomingReceived, 0, int, "%d");
639

640
		linphone_call_terminate(linphone_core_get_current_call(pauline1->lc));
641 642
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallEnd,1,3000));
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,3000));
643

644 645
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
646
		linphone_core_manager_destroy(pauline2);
647
		bctbx_list_free(lcs);
648
	}
649 650 651
}

static void call_with_sips_not_achievable(void){
652 653
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
654 655
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_rc");
656
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
657 658 659 660
		LinphoneAddress *dest;
		LinphoneCall *call;
		const LinphoneErrorInfo *ei;

661 662
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677


		dest=linphone_address_clone(pauline1->identity);
		linphone_address_set_secure(dest,TRUE);
		call=linphone_core_invite_address(marie->lc,dest);
		linphone_call_ref(call);
		linphone_address_unref(dest);

		/*Call should be rejected by server with 480*/
		BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallError,1,6000));
		ei=linphone_call_get_error_info(call);
		BC_ASSERT_PTR_NOT_NULL(ei);
		if (ei){
			BC_ASSERT_EQUAL(linphone_error_info_get_reason(ei), LinphoneReasonTemporarilyUnavailable, int, "%d");
		}
Simon Morlat's avatar
Simon Morlat committed
678
		linphone_call_unref(call);
679

680 681
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
682
		linphone_core_manager_destroy(pauline2);
683
		bctbx_list_free(lcs);
684 685 686
	}
}

687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705


static bool_t is_sending_ipv6(RtpSession *session, bool_t rtcp){
	const struct sockaddr *dest = rtcp ? (struct sockaddr*)&session->rtcp.gs.rem_addr : (struct sockaddr*)&session->rtp.gs.rem_addr;
	struct sockaddr_in6 *in6=(struct sockaddr_in6*)dest;
	return dest->sa_family == AF_INET6 && !IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr);
}
static bool_t is_remote_contact_ipv6(LinphoneCall *call){
	const char *contact=linphone_call_get_remote_contact(call);
	LinphoneAddress *ct_addr;
	bool_t ret = FALSE;

	BC_ASSERT_PTR_NOT_NULL(contact);
	if (contact){
		ct_addr=linphone_address_new(contact);
		BC_ASSERT_PTR_NOT_NULL(ct_addr);
		if (ct_addr){
			ret = strchr(linphone_address_get_domain(ct_addr),':') != NULL;
		}
Simon Morlat's avatar
Simon Morlat committed
706
		linphone_address_unref(ct_addr);
707 708 709 710 711
	}
	return ret;
}

static void _call_with_ipv6(bool_t caller_with_ipv6, bool_t callee_with_ipv6) {
712 713
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
714
	LinphoneCall *pauline_call, *marie_call;
715

716 717
	/*calling ortp_init() here is done to have WSAStartup() done, otherwise liblinphone_tester_ipv6_available() will not work.*/
	ortp_init();
718

719 720 721 722
	if (!liblinphone_tester_ipv6_available()){
		ms_warning("Call with ipv6 not tested, no ipv6 connectivity");
		return;
	}
723

724 725 726 727 728 729 730
	marie = linphone_core_manager_new2( "marie_rc", FALSE);
	linphone_core_enable_ipv6(marie->lc, caller_with_ipv6);
	linphone_core_manager_start(marie, TRUE);
	
	pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc", FALSE);
	linphone_core_enable_ipv6(pauline->lc, callee_with_ipv6);
	linphone_core_manager_start(pauline, TRUE);
731 732 733

	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
734
	BC_ASSERT_TRUE(call(marie,pauline));
735 736
	pauline_call = linphone_core_get_current_call(pauline->lc);
	marie_call = linphone_core_get_current_call(marie->lc);
737
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
738 739
	BC_ASSERT_PTR_NOT_NULL(marie_call);
	if (pauline_call && marie_call){
740
		/*check that the remote contact is IPv6*/
741 742 743 744 745 746 747 748 749
		BC_ASSERT_EQUAL(is_remote_contact_ipv6(pauline_call), caller_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_remote_contact_ipv6(marie_call), callee_with_ipv6, int, "%i");
		
		/*check that the RTP destinations are IPv6 (flexisip should propose an IPv6 relay for parties with IPv6)*/
		BC_ASSERT_EQUAL(is_sending_ipv6(marie_call->sessions[0].rtp_session, FALSE), caller_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(marie_call->sessions[0].rtp_session, TRUE), caller_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(pauline_call->sessions[0].rtp_session, FALSE), callee_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(pauline_call->sessions[0].rtp_session, TRUE), callee_with_ipv6, int, "%i");
		
750
	}
751 752 753 754 755 756

	liblinphone_tester_check_rtcp(marie,pauline);
	end_call(marie,pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);

757
	ortp_exit();
758
}
Simon Morlat's avatar
Simon Morlat committed
759

760 761 762 763 764 765 766 767 768 769 770 771
static void call_with_ipv6(void){
	_call_with_ipv6(TRUE, TRUE);
}

static void call_ipv4_to_ipv6(void){
	_call_with_ipv6(FALSE, TRUE);
}

static void call_ipv6_to_ipv4(void){
	_call_with_ipv6(TRUE, FALSE);
}

772
static void file_transfer_message_rcs_to_external_body_client(void) {
773
	if (transport_supported(LinphoneTransportTls)) {
774 775
		LinphoneChatRoom* chat_room;
		LinphoneChatMessage* message;
776
		LinphoneChatMessageCbs *cbs;
777 778 779
		LinphoneContent* content;
		FILE *file_to_send = NULL;
		size_t file_size;
780 781
		char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg");
		char *receive_filepath = bc_tester_file("receive_file.dump");
782 783 784 785 786
		LinphoneCoreManager* marie = linphone_core_manager_new2( "marie_rc", FALSE);
		LinphoneCoreManager* pauline = linphone_core_manager_new2( "pauline_rc", FALSE);
		// This is done to prevent register to be sent before the custom header is set
		linphone_core_set_network_reachable(marie->lc, FALSE);
		linphone_core_set_network_reachable(pauline->lc, FALSE);
787 788

		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
Sylvain Berfini's avatar
Sylvain Berfini committed
789
		linphone_core_set_network_reachable(marie->lc, TRUE);
790
		linphone_core_manager_start(marie, TRUE);
791

792 793

		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
794
		linphone_core_set_network_reachable(pauline->lc, TRUE);
795
		linphone_core_manager_start(pauline, TRUE);
796 797 798

		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
799

800 801 802 803 804 805 806 807 808
		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);

		/* 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 */
Simon Morlat's avatar
Simon Morlat committed
809
		chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Ghislain MARY's avatar
Ghislain MARY committed
810

811 812 813 814 815 816 817 818
		/* create a file transfer message */
		content = linphone_core_create_content(pauline->lc);
		linphone_content_set_type(content,"image");
		linphone_content_set_subtype(content,"jpeg");
		linphone_content_set_size(content,file_size); /*total size to be transfered*/
		linphone_content_set_name(content,"nowebcamCIF.jpg");
		message = linphone_chat_room_create_file_transfer_message(chat_room, content);
		linphone_chat_message_set_user_data(message, file_to_send);
819
		cbs = linphone_chat_message_get_callbacks(message);
820 821 822 823 824 825
		{
			int dummy=0;
			wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/
			reset_counters(&marie->stat);
			reset_counters(&pauline->stat);
		}
826 827
		linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
		linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send);
828 829
		linphone_chat_room_send_chat_message(chat_room,message);
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1));
830

831
		if (marie->stat.last_received_chat_message ) {
832 833 834
			cbs = linphone_chat_message_get_callbacks(marie->stat.last_received_chat_message);
			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);
835 836 837 838
			linphone_chat_message_download_file(marie->stat.last_received_chat_message);
		}
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageFileTransferDone,1));

839
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
840 841
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1, int, "%d");
842
		compare_files(send_filepath, receive_filepath);
843 844 845 846 847

		linphone_content_unref(content);
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline);
		ms_free(send_filepath);
848
		bc_free(receive_filepath);
849
	}
850 851
}

852
void send_file_transfer_message_using_external_body_url(LinphoneCoreManager *marie, LinphoneCoreManager *pauline) {
853
	LinphoneChatMessageCbs *cbs;
854 855
	LinphoneChatRoom *chat_room;
	LinphoneChatMessage *message;
856

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

860
	message = linphone_chat_room_create_message(chat_room, NULL);
861

862 863 864
	cbs = linphone_chat_message_get_callbacks(message);
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);

865 866
	linphone_chat_message_set_external_body_url(message, "https://www.linphone.org:444//tmp/54ec58280ace9_c30709218df8eaba61d1.jpg");
	linphone_chat_room_send_chat_message(chat_room, message);
867

868
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1));
869 870 871
	if (marie->stat.last_received_chat_message) {
		linphone_chat_message_download_file(marie->stat.last_received_chat_message);
	}
872
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageExtBodyReceived, 1));
873

874 875
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress, 1, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived, 1, int, "%d");
876

877
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDelivered, 1));
878

879 880 881
}

static void file_transfer_message_external_body_to_external_body_client(void) {
882
	if (transport_supported(LinphoneTransportTls)) {
883 884
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
885

886
		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
887
		linphone_core_manager_start(marie, TRUE);
888

889
		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp");
890
		linphone_core_manager_start(pauline, TRUE);
891

892 893
		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
894

895 896
		linphone_core_refresh_registers(marie->lc);
		linphone_core_refresh_registers(pauline->lc);
897

898
		send_file_transfer_message_using_external_body_url(marie, pauline);
899

900
		linphone_core_manager_destroy(pauline);
901
		linphone_core_manager_destroy(marie);
902
	}
903 904 905
}

static void file_transfer_message_external_body_to_rcs_client(void) {
906
	if (transport_supported(LinphoneTransportTls)) {
907 908
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
909

910
		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
911
		linphone_core_manager_start(marie, TRUE);
912

913
		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
914
		linphone_core_manager_start(pauline, TRUE);
915

916 917
		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
918

919
		send_file_transfer_message_using_external_body_url(marie, pauline);
920

921
		linphone_core_manager_destroy(pauline);
922
		linphone_core_manager_destroy(marie);
923
	}
924 925
}

926 927 928
static void dos_module_trigger(void) {
	LinphoneChatRoom *chat_room;
	int i = 0;
929
	int dummy = 0;
930
	const char* passmsg = "This one should pass through";
931
	int number_of_messge_to_send = 100;
932
	LinphoneChatMessage * chat_msg = NULL;
933
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
934
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
935

936 937
	reset_counters(&marie->stat);
	reset_counters(&pauline->stat);
938

Simon Morlat's avatar
Simon Morlat committed
939
	chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
940

941 942 943
	do {
		char msg[128];
		sprintf(msg, "Flood message number %i", i);
944 945
		chat_msg = linphone_chat_room_create_message(chat_room, msg);
		linphone_chat_room_send_chat_message(chat_room, chat_msg);
946
		wait_for_until(marie->lc, pauline->lc, &dummy, 1, 10);
947 948 949
		i++;
	} while (i < number_of_messge_to_send);
	// At this point we should be banned for a minute
950

951
	wait_for_until(marie->lc, pauline->lc, &dummy, 1, 65000);;