flexisip_tester.c 67.9 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
#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
23
#include "tester_utils.h"
Simon Morlat's avatar
Simon Morlat committed
24

Erwan Croze's avatar
Erwan Croze committed
25 26 27 28 29 30
static void setPublish(LinphoneProxyConfig * proxy_config, bool_t enable) {
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_enable_publish(proxy_config, enable);
	linphone_proxy_config_done(proxy_config);
}

Simon Morlat's avatar
Simon Morlat committed
31 32
static void subscribe_forking(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
33 34
	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");
35
	LinphoneContent* content;
Simon Morlat's avatar
Simon Morlat committed
36 37
	LinphoneEvent *lev;
	int expires=  600;
38
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
39

40 41
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,pauline2->lc);
Simon Morlat's avatar
Simon Morlat committed
42

43 44 45
	content = linphone_core_create_content(marie->lc);
	linphone_content_set_type(content,"application");
	linphone_content_set_subtype(content,"somexml");
46
	linphone_content_set_buffer(content, (const uint8_t *)liblinphone_tester_get_subscribe_content(), strlen(liblinphone_tester_get_subscribe_content()));
47

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

50
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionOutgoingProgress,1,1000));
51 52 53
	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
54 55

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

	linphone_event_terminate(lev);
59 60

	linphone_content_unref(content);
Simon Morlat's avatar
Simon Morlat committed
61 62 63
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(pauline2);
64
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
65 66 67 68
}

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

76 77
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
78

79
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
80
	linphone_chat_room_send_chat_message(chat_room, message);
81 82 83
	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));
84
	linphone_chat_message_unref(message);
85

Simon Morlat's avatar
Simon Morlat committed
86 87 88
	/*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);
89

90
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d");
Simon Morlat's avatar
Simon Morlat committed
91 92 93
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(pauline);
94
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
95 96 97 98
}

static void message_forking_with_unreachable_recipients(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
99
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
100 101
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
102
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
103
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
104
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
105
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message);
106

107 108 109
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
110

Simon Morlat's avatar
Simon Morlat committed
111 112 113 114 115 116
	/*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;
117

Simon Morlat's avatar
Simon Morlat committed
118 119 120
	/*marie2 and marie3 go offline*/
	linphone_core_set_network_reachable(marie2->lc,FALSE);
	linphone_core_set_network_reachable(marie3->lc,FALSE);
121

122
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
123
	linphone_chat_room_send_chat_message(chat_room, message);
124 125 126
	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");
127 128
	BC_ASSERT_EQUAL(marie2->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
	BC_ASSERT_EQUAL(marie3->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
129 130
	linphone_chat_message_unref(message);

Simon Morlat's avatar
Simon Morlat committed
131 132
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
133
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
134

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

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

Simon Morlat's avatar
Simon Morlat committed
142 143
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
144
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
145
	linphone_core_manager_destroy(pauline);
146
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
147 148 149 150
}

static void message_forking_with_all_recipients_unreachable(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
151
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
152 153
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
154
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
155
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
156
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
157
	LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message);
158

159 160 161
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
162

Simon Morlat's avatar
Simon Morlat committed
163 164 165 166 167 168 169
	/*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;

170

Simon Morlat's avatar
Simon Morlat committed
171 172 173 174
	/*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);
175

176
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
177
	linphone_chat_room_send_chat_message(chat_room, message);
178

179
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageInProgress,1,5000));
Simon Morlat's avatar
Simon Morlat committed
180
	/*flexisip will accept the message with 202 after 16 seconds*/
181
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,18000));
182 183 184
	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");
185
	linphone_chat_message_unref(message);
186

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

Simon Morlat's avatar
Simon Morlat committed
191 192
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
193
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
194

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

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

Simon Morlat's avatar
Simon Morlat committed
202 203
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
204
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
205
	linphone_core_manager_destroy(pauline);
206
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
207 208
}

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
static void message_forking_with_unreachable_recipients_with_gruu(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);

	LinphoneProxyConfig *marie_proxy_config = linphone_core_get_default_proxy_config(marie->lc);
	LinphoneProxyConfig *marie2_proxy_config = linphone_core_get_default_proxy_config(marie2->lc);
	const LinphoneAddress *marie_address = linphone_proxy_config_get_contact(marie_proxy_config);
	const LinphoneAddress *marie2_address = linphone_proxy_config_get_contact(marie2_proxy_config);
	LinphoneChatRoom* chat_room_1 = linphone_core_get_chat_room(pauline->lc, marie_address);
	LinphoneChatMessage* message_1 = linphone_chat_room_create_message(chat_room_1,"Bli bli bli \n blu");
	LinphoneChatRoom* chat_room_2 = linphone_core_get_chat_room(pauline->lc, marie2_address);
	LinphoneChatMessage* message_2 = linphone_chat_room_create_message(chat_room_2,"Bla bla bla \n bli");

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

	/*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;

	/*marie and marie2 go offline*/
	linphone_core_set_network_reachable(marie->lc,FALSE);
	linphone_core_set_network_reachable(marie2->lc,FALSE);

	linphone_chat_room_send_chat_message(chat_room_1, message_1);
	linphone_chat_room_send_chat_message(chat_room_2, message_2);

	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
	BC_ASSERT_EQUAL(marie2->stat.number_of_LinphoneMessageReceived, 0, int, "%d");
242

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));

	/*wait a long time so that all transactions are expired*/
	wait_for_list(lcs,NULL,0,32000);

	/*marie goes online now*/
	linphone_core_set_network_reachable(marie->lc,TRUE);
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000));

	linphone_chat_message_unref(message_1);
	linphone_chat_message_unref(message_2);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(pauline);
	bctbx_list_free(lcs);
}

Simon Morlat's avatar
Simon Morlat committed
262 263
static void call_forking(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
264
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
265 266
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
267
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
268

269 270 271
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
272

Simon Morlat's avatar
Simon Morlat committed
273 274 275 276
	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);
277

Simon Morlat's avatar
Simon Morlat committed
278 279
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
280
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
281
	/*all devices from Marie should be ringing*/
282 283 284
	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));
285

Simon Morlat's avatar
Simon Morlat committed
286
	/*marie accepts the call on its first device*/
287
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
288 289 290 291
	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));
292

Simon Morlat's avatar
Simon Morlat committed
293
	/*other devices should stop ringing*/
294 295
	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));
296

297
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
298 299
	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));
300

Simon Morlat's avatar
Simon Morlat committed
301 302 303 304
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
305
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
306 307 308 309
}

static void call_forking_with_urgent_reply(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
310
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
311 312
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
313 314 315 316
	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);
317

318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
	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*/
336
		linphone_call_accept(linphone_core_get_current_call(marie->lc));
337 338 339 340 341
		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));

342
		linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
343 344 345
		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
346 347 348 349
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
350
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
351 352 353 354
}

static void call_forking_cancelled(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
355
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
356 357
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
358
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
359

360 361 362
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
363

Simon Morlat's avatar
Simon Morlat committed
364 365 366 367
	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);
368

Simon Morlat's avatar
Simon Morlat committed
369 370
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
371
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
372
	/*all devices from Marie should be ringing*/
373 374 375
	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));
376

Simon Morlat's avatar
Simon Morlat committed
377
	/*pauline finally cancels the call*/
378
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
379
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
380

Simon Morlat's avatar
Simon Morlat committed
381
	/*all devices should stop ringing*/
382 383 384
	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));
385

Simon Morlat's avatar
Simon Morlat committed
386 387 388 389
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
390
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
391 392 393 394
}

static void call_forking_declined(bool_t declined_globaly){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
395
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
396 397
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
398
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
399

400 401 402
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
403

Simon Morlat's avatar
Simon Morlat committed
404 405 406 407
	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);
408

Simon Morlat's avatar
Simon Morlat committed
409 410
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
411
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
412
	/*all devices from Marie should be ringing*/
413 414 415
	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));
416

417
	/*marie finally declines the call*/
418
	linphone_call_decline(linphone_core_get_current_call(marie->lc),
Simon Morlat's avatar
Simon Morlat committed
419 420
		declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy
	);
421

Simon Morlat's avatar
Simon Morlat committed
422
	if (declined_globaly){
423
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Simon Morlat's avatar
Simon Morlat committed
424
		/*all devices should stop ringing*/
425 426 427
		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
428 429
	}else{
		/*pauline should continue ringing and be able to hear a call taken by marie2 */
430
		linphone_call_accept(linphone_core_get_current_call(marie2->lc));
431 432
		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
433
		liblinphone_tester_check_rtcp(pauline,marie2);
434 435
		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));
436
		linphone_call_terminate(linphone_core_get_current_call(marie2->lc));
437 438
		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
439
	}
440

Simon Morlat's avatar
Simon Morlat committed
441 442 443 444
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
445
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
446 447 448 449 450 451 452 453 454 455 456
}

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){
457
	bctbx_list_t* lcs;
458
	LinphoneCoreManager* marie = linphone_core_manager_new2( "marie_rc", FALSE);
459
	LinphoneCoreManager* pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc",FALSE);
460
	int dummy=0;
461

Simon Morlat's avatar
Simon Morlat committed
462 463
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
464 465 466
	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;");
467

468 469
	lcs=bctbx_list_append(NULL,pauline->lc);
	lcs=bctbx_list_append(lcs,marie->lc);
470

471 472
	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));
473

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

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

479 480
	/*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
481
	linphone_core_set_network_reachable(marie->lc,TRUE);
482

Simon Morlat's avatar
Simon Morlat committed
483
	/*Marie shall receive the call immediately*/
484
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
485
	/*pauline should hear ringback as well*/
486
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
487

Simon Morlat's avatar
Simon Morlat committed
488
	/*marie accepts the call*/
489
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
490 491 492 493
	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));
494

Simon Morlat's avatar
Simon Morlat committed
495
	liblinphone_tester_check_rtcp(pauline,marie);
496

497
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
498 499
	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));
500

Simon Morlat's avatar
Simon Morlat committed
501 502
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
503
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
504 505 506 507
}

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

511
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
512

513 514
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
515

Simon Morlat's avatar
Simon Morlat committed
516 517 518
	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);
519

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

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

525
	/*marie will ring*/
526
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
527
	/*pauline should hear ringback as well*/
528
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
529

Simon Morlat's avatar
Simon Morlat committed
530 531
	/*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);
532

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

Simon Morlat's avatar
Simon Morlat committed
536
	/*marie2 accepts the call*/
537
	linphone_call_accept(linphone_core_get_current_call(marie2->lc));
538 539 540 541
	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));
542

543
	/*call to marie should be cancelled*/
544
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
545

Simon Morlat's avatar
Simon Morlat committed
546
	liblinphone_tester_check_rtcp(pauline,marie2);
547

548
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
549

550 551
	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));
552

Simon Morlat's avatar
Simon Morlat committed
553 554 555 556 557
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
}

558
static void call_forking_not_responded(void){
559
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
560
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
561 562
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
563
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
564

565 566 567
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
568

569 570 571 572
	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);
573

574 575
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
576
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
577
	/*all devices from Marie should be ringing*/
578 579 580
	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));
581

582
	/*nobody answers, flexisip should close the call after XX seconds*/
583
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallError,1,22000));
584
	/*all devices should stop ringing*/
585 586 587
	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));
588

589 590 591 592
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
593
	bctbx_list_free(lcs);
594 595
}

Simon Morlat's avatar
Simon Morlat committed
596
static void early_media_call_forking(void) {
597
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_early_rc");
Simon Morlat's avatar
Simon Morlat committed
598
	LinphoneCoreManager* marie2 = linphone_core_manager_new("marie_early_rc");
599
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
600
	bctbx_list_t *lcs=NULL;
601
	LinphoneCallParams *params=linphone_core_create_call_params(pauline->lc, NULL);
Simon Morlat's avatar
Simon Morlat committed
602 603
	LinphoneVideoPolicy pol;
	int dummy=0;
604

Simon Morlat's avatar
Simon Morlat committed
605 606
	pol.automatically_accept=1;
	pol.automatically_initiate=1;
607

608
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
Simon Morlat's avatar
Simon Morlat committed
609 610
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
611

612 613
	linphone_core_enable_video_capture(pauline->lc,TRUE);
	linphone_core_enable_video_display(pauline->lc,TRUE);
614

615 616
	linphone_core_enable_video_capture(marie->lc,TRUE);
	linphone_core_enable_video_display(marie->lc,TRUE);
617
	linphone_core_set_video_policy(marie->lc,&pol);
618

619 620 621
	linphone_core_enable_video_capture(marie2->lc,TRUE);
	linphone_core_enable_video_display(marie2->lc,TRUE);

Simon Morlat's avatar
Simon Morlat committed
622 623 624
	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);
625

626 627 628
	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
629 630 631

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

633
	linphone_core_invite_address_with_params(pauline->lc,marie->identity,params);
Simon Morlat's avatar
Simon Morlat committed
634
	linphone_call_params_unref(params);
Simon Morlat's avatar
Simon Morlat committed
635

636
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000));
637 638 639
	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");
640

Simon Morlat's avatar
Simon Morlat committed
641
	/*wait a bit that streams are established*/
642 643 644 645 646 647 648
	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");
649

650
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
651
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,3000));
652
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,3000));
653

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

Simon Morlat's avatar
Simon Morlat committed
657
	/*wait a bit that streams are established*/
Simon Morlat's avatar
Simon Morlat committed
658
	wait_for_list(lcs,&dummy,1,3000);
659 660 661 662
	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");
663

664
	end_call(pauline, marie);
Simon Morlat's avatar
Simon Morlat committed
665

666
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
667
	linphone_core_manager_destroy(pauline);
668 669
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie);
Simon Morlat's avatar
Simon Morlat committed
670 671
}

672
static void call_with_sips(void){
673
	if (transport_supported(LinphoneTransportTls)) {
674 675
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_sips_rc");
676
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
677
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
678

679 680
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
681

682 683 684
		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);
685

686
		linphone_core_invite_address(marie->lc,pauline1->identity);
687

688 689 690 691
		/*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));
692

693
		/*pauline accepts the call */
694
		linphone_call_accept(linphone_core_get_current_call(pauline1->lc));
695 696 697 698
		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));
699

700 701
		/*pauline2 should not have ring*/
		BC_ASSERT_EQUAL(pauline2->stat.number_of_LinphoneCallIncomingReceived, 0, int, "%d");
702

703
		linphone_call_terminate(linphone_core_get_current_call(pauline1->lc));
704 705
		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));
706

707 708
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
709
		linphone_core_manager_destroy(pauline2);
710
		bctbx_list_free(lcs);
711
	}
712 713 714
}

static void call_with_sips_not_achievable(void){
715 716
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
717 718
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_rc");
719
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
720 721 722 723
		LinphoneAddress *dest;
		LinphoneCall *call;
		const LinphoneErrorInfo *ei;

724 725
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740


		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
741
		linphone_call_unref(call);
742

743 744
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
745
		linphone_core_manager_destroy(pauline2);
746
		bctbx_list_free(lcs);
747 748 749
	}
}

750 751 752 753 754 755

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);
}
756

757 758 759 760 761 762 763 764 765 766 767 768
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
769
		linphone_address_unref(ct_addr);
770 771 772 773 774
	}
	return ret;
}

static void _call_with_ipv6(bool_t caller_with_ipv6, bool_t callee_with_ipv6) {
775 776
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
777
	LinphoneCall *pauline_call, *marie_call;
778

779 780
	/*calling ortp_init() here is done to have WSAStartup() done, otherwise liblinphone_tester_ipv6_available() will not work.*/
	ortp_init();
781

782 783 784 785
	if (!liblinphone_tester_ipv6_available()){
		ms_warning("Call with ipv6 not tested, no ipv6 connectivity");
		return;
	}
786

787
	marie = linphone_core_manager_new2( "marie_rc", FALSE);
788
	linphone_core_remove_supported_tag(marie->lc,"gruu"); // With gruu, we have no access to the "public IP from contact
789 790
	linphone_core_enable_ipv6(marie->lc, caller_with_ipv6);
	linphone_core_manager_start(marie, TRUE);
Erwan Croze's avatar
Erwan Croze committed
791

792
	pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc", FALSE);
793
	linphone_core_remove_supported_tag(pauline->lc,"gruu"); // With gruu, we have no access to the "public IP from contact
794 795
	linphone_core_enable_ipv6(pauline->lc, callee_with_ipv6);
	linphone_core_manager_start(pauline, TRUE);
796 797 798

	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
799
	BC_ASSERT_TRUE(call(marie,pauline));
800 801
	pauline_call = linphone_core_get_current_call(pauline->lc);
	marie_call = linphone_core_get_current_call(marie->lc);
802
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
803 804
	BC_ASSERT_PTR_NOT_NULL(marie_call);
	if (pauline_call && marie_call){
805
		/*check that the remote contact is IPv6*/
806 807
		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");
Erwan Croze's avatar
Erwan Croze committed
808

809
		/*check that the RTP destinations are IPv6 (flexisip should propose an IPv6 relay for parties with IPv6)*/
810 811 812 813
		BC_ASSERT_EQUAL(is_sending_ipv6(linphone_call_get_stream(marie_call, LinphoneStreamTypeAudio)->sessions.rtp_session, FALSE), caller_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(linphone_call_get_stream(marie_call, LinphoneStreamTypeAudio)->sessions.rtp_session, TRUE), caller_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(linphone_call_get_stream(pauline_call, LinphoneStreamTypeAudio)->sessions.rtp_session, FALSE), callee_with_ipv6, int, "%i");
		BC_ASSERT_EQUAL(is_sending_ipv6(linphone_call_get_stream(pauline_call, LinphoneStreamTypeAudio)->sessions.rtp_session, TRUE), callee_with_ipv6, int, "%i");
814
	}
815 816 817 818 819 820

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

821
	ortp_exit();
822
}
Simon Morlat's avatar
Simon Morlat committed
823

824 825 826 827 828 829 830 831 832 833 834 835
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);
}

836
static void file_transfer_message_rcs_to_external_body_client(void) {
837
	if (transport_supported(LinphoneTransportTls)) {
838 839
		LinphoneChatRoom* chat_room;
		LinphoneChatMessage* message;
840
		LinphoneChatMessageCbs *cbs;
841 842 843
		LinphoneContent* content;
		FILE *file_to_send = NULL;
		size_t file_size;
844 845
		char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg");
		char *receive_filepath = bc_tester_file("receive_file.dump");
846 847 848 849 850
		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);
851

852
		linphone_proxy_config_set_custom_header(linphone_core_get_default_proxy_config(marie->lc), "Accept", "application/sdp");
Sylvain Berfini's avatar
Sylvain Berfini committed
853
		linphone_core_set_network_reachable(marie->lc, TRUE);
854
		linphone_core_manager_start(marie, TRUE);
855

856

857
		linphone_proxy_config_set_custom_header(linphone_core_get_default_proxy_config(pauline->lc), "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
858
		linphone_core_set_network_reachable(pauline->lc, TRUE);
859
		linphone_core_manager_start(pauline, TRUE);
860 861 862

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

864 865 866 867 868 869 870 871 872
		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
873
		chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Ghislain MARY's avatar
Ghislain MARY committed
874

875 876 877 878 879 880 881 882
		/* 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);
883
		cbs = linphone_chat_message_get_callbacks(message);
884 885 886 887 888 889
		{
			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);
		}
890 891
		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);
892
		linphone_chat_room_send_chat_message(chat_room,message);
893
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceivedWithFile,1));
894

895
		if (marie->stat.last_received_chat_message ) {
896 897 898
			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);
899 900 901 902
			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));

903
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
904
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
905
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceivedWithFile,1, int, "%d");
906
		compare_files(send_filepath, receive_filepath);
907

908
		linphone_chat_message_unref(message);
909 910 911 912
		linphone_content_unref(content);
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline);
		ms_free(send_filepath);
913
		bc_free(receive_filepath);
914
	}
915 916
}

917 918 919
static void dos_module_trigger(void) {
	LinphoneChatRoom *chat_room;
	int i = 0;
920
	int dummy = 0;
921
	const char* passmsg = "This one should pass through";
922
	int number_of_messge_to_send = 100;
923
	LinphoneChatMessage * chat_msg = NULL;
924
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
925
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
926

927 928
	reset_counters(&marie->stat);
	reset_counters(&pauline->stat);
929

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

932 933 934
	do {
		char msg[128];
		sprintf(msg, "Flood message number %i", i);
935 936
		chat_msg = linphone_chat_room_create_message(chat_room, msg);
		linphone_chat_room_send_chat_message(chat_room, chat_msg);
937
		wait_for_until(marie->lc, pauline->lc, &dummy, 1, 10);
938 939 940
		i++;
	} while (i < number_of_messge_to_send);
	// At this point we should be banned for a minute
941

942
	wait_for_until(marie->lc, pauline->lc, &dummy, 1, 65000);; // Wait several seconds to ensure we are not banned anymore
943
	BC_ASSERT_LOWER_STRICT(marie->stat.number_of_LinphoneMessageReceived, number_of_messge_to_send, int, "%d");
944

945 946
	reset_counters(&marie->stat);
	reset_counters(&pauline->stat);
947 948
	chat_msg = linphone_chat_room_create_message(chat_room, passmsg);
	linphone_chat_room_send_chat_message(chat_room, chat_msg);
949
	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived, 1));
950 951 952 953
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageReceived, 1, int, "%d");
	if (marie->stat.last_received_chat_message) {
		BC_ASSERT_NSTRING_EQUAL(linphone_chat_message_get_text(marie->stat.last_received_chat_message), passmsg, strlen(passmsg));
	}
954 955 956 957
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

958
#if HAVE_SIPP
jehan's avatar
jehan committed
959 960 961 962 963 964
static void test_subscribe_notify_with_sipp_publisher(void) {
	char *scen;
	FILE * sipp_out;
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	/*just to get an identity*/
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
965 966
	LinphoneAddress *sip_example_org;
	const LinphoneAuthInfo	*marie_auth = linphone_core_find_auth_info(marie->lc, NULL, linphone_address_get_username(marie->identity), NULL);
jehan's avatar
jehan committed
967
	LpConfig *pauline_lp = linphone_core_get_config(pauline->lc);
Simon Morlat's avatar
Simon Morlat committed
968 969
	char* lf_identity=linphone_address_as_string_uri_only(marie->identity);
	LinphoneFriend *lf = linphone_core_create_friend_with_address(pauline->lc,lf_identity);
970

971 972
	linphone_core_set_user_agent(marie->lc, "full-presence-support", NULL);
	linphone_core_set_user_agent(pauline->lc, "full-presence-support", NULL);
Simon Morlat's avatar
Simon Morlat committed
973

jehan's avatar
jehan committed
974
	ms_free(lf_identity);
975

jehan's avatar
jehan committed
976
	lp_config_set_int(pauline_lp,"sip","subscribe_expires",5);
977

jehan's avatar
jehan committed
978
	linphone_core_add_friend(pauline->lc,lf);
979

jehan's avatar
jehan committed
980
	/*wait for subscribe acknowledgment*/
jehan's avatar