flexisip_tester.c 53.3 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

Simon Morlat's avatar
Simon Morlat committed
20 21 22 23 24 25 26
#include "linphonecore.h"
#include "lpconfig.h"
#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 32
	LinphoneEvent *lev;
	int expires=  600;
	MSList* lcs=ms_list_append(NULL,marie->lc);
33

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

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 45 46 47
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionOutgoingInit,1,1000));
	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 58 59 60 61 62
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(pauline2);
	ms_list_free(lcs);
}

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 65
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_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

Simon Morlat's avatar
Simon Morlat committed
70 71
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,marie2->lc);
72

73 74
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
	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 87 88 89 90 91
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(pauline);
	ms_list_free(lcs);
}

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 95
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_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

Simon Morlat's avatar
Simon Morlat committed
100 101 102
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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 116
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
	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 137 138 139 140 141
	linphone_core_manager_destroy(pauline);
	ms_list_free(lcs);
}

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 145
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_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

Simon Morlat's avatar
Simon Morlat committed
150 151 152
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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 168
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
	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 196 197 198 199 200
	linphone_core_manager_destroy(pauline);
	ms_list_free(lcs);
}

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 204
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
205

Simon Morlat's avatar
Simon Morlat committed
206 207 208
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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 224
	/*marie accepts the call on its first device*/
	linphone_core_accept_call(marie->lc,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

Simon Morlat's avatar
Simon Morlat committed
234
	linphone_core_terminate_call(pauline->lc,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 242 243 244 245 246
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
	ms_list_free(lcs);
}

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 250 251 252 253
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
254

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
	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*/
		linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc));
		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));

		linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
		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 287 288 289 290 291
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
	ms_list_free(lcs);
}

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 295
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
296

Simon Morlat's avatar
Simon Morlat committed
297 298 299
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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 315
	/*pauline finally cancels the call*/
	linphone_core_terminate_call(pauline->lc,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 327 328 329 330 331
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
	ms_list_free(lcs);
}

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 335
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
336

Simon Morlat's avatar
Simon Morlat committed
337 338 339
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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*/
Simon Morlat's avatar
Simon Morlat committed
355 356 357
	linphone_core_decline_call(marie->lc,linphone_core_get_current_call(marie->lc),
		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 367
	}else{
		/*pauline should continue ringing and be able to hear a call taken by marie2 */
		linphone_core_accept_call(marie2->lc, 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));
Simon Morlat's avatar
Simon Morlat committed
373
		linphone_core_terminate_call(marie2->lc,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 382 383 384 385 386 387 388 389 390 391 392 393
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
	ms_list_free(lcs);
}

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
	MSList* 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
	lcs=ms_list_append(NULL,pauline->lc);
Simon Morlat's avatar
Simon Morlat committed
406
	lcs=ms_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 426
	/*marie accepts the call*/
	linphone_core_accept_call(marie->lc,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

Simon Morlat's avatar
Simon Morlat committed
434
	linphone_core_terminate_call(pauline->lc,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 440 441 442 443 444
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	ms_list_free(lcs);
}

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

Simon Morlat's avatar
Simon Morlat committed
448
	MSList* lcs=ms_list_append(NULL,pauline->lc);
449

Simon Morlat's avatar
Simon Morlat committed
450 451
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_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 474
	/*marie2 accepts the call*/
	linphone_core_accept_call(marie2->lc,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

Simon Morlat's avatar
Simon Morlat committed
485
	linphone_core_terminate_call(pauline->lc,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 500
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
501

502 503 504
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_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 530 531 532
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
	ms_list_free(lcs);
}

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");
Simon Morlat's avatar
Simon Morlat committed
537
	MSList *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
	lcs=ms_list_append(lcs,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
564 565 566 567 568
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,pauline->lc);

	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 572
	linphone_call_params_destroy(params);

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 588
	linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc));
	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 604

	ms_list_free(lcs);
	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
		MSList* lcs=ms_list_append(NULL,marie->lc);
615

616 617
		lcs=ms_list_append(lcs,pauline1->lc);
		lcs=ms_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 631 632 633 634 635
		/*pauline accepts the call */
		linphone_core_accept_call(pauline1->lc,linphone_core_get_current_call(pauline1->lc));
		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 641 642
		linphone_core_terminate_call(pauline1->lc,linphone_core_get_current_call(pauline1->lc));
		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 648
		ms_list_free(lcs);
	}
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 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_rc");
		MSList* lcs=ms_list_append(NULL,marie->lc);
		LinphoneAddress *dest;
		LinphoneCall *call;
		const LinphoneErrorInfo *ei;

		lcs=ms_list_append(lcs,pauline1->lc);
		lcs=ms_list_append(lcs,pauline2->lc);


		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");
		}
678

679 680
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
681
		linphone_core_manager_destroy(pauline2);
682
		ms_list_free(lcs);
683 684 685 686 687 688 689 690
	}
}

static void call_with_ipv6(void) {
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
	LinphoneCall *pauline_call;

691 692
	/*calling ortp_init() here is done to have WSAStartup() done, otherwise liblinphone_tester_ipv6_available() will not work.*/
	ortp_init();
693

694 695 696 697
	if (!liblinphone_tester_ipv6_available()){
		ms_warning("Call with ipv6 not tested, no ipv6 connectivity");
		return;
	}
698

699 700
	liblinphone_tester_enable_ipv6(TRUE);
	marie = linphone_core_manager_new( "marie_rc");
701
	pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
702 703 704

	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
705
	BC_ASSERT_TRUE(call(marie,pauline));
706
	pauline_call=linphone_core_get_current_call(pauline->lc);
707
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
708 709 710 711
	if (pauline_call){
		/*check that the remote contact is IPv6*/
		const char *contact=linphone_call_get_remote_contact(pauline_call);
		LinphoneAddress *ct_addr;
712

713
		BC_ASSERT_PTR_NOT_NULL(contact);
714 715
		if (contact){
			ct_addr=linphone_address_new(contact);
716
			BC_ASSERT_PTR_NOT_NULL(ct_addr);
717
			if (ct_addr){
718
				BC_ASSERT_PTR_NOT_NULL(strchr(linphone_address_get_domain(ct_addr),':'));
719 720 721
			}
			linphone_address_destroy(ct_addr);
		}
722

723
	}
724 725 726 727 728 729 730

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

731
	ortp_exit();
732
}
Simon Morlat's avatar
Simon Morlat committed
733

734
static void file_transfer_message_rcs_to_external_body_client(void) {
735
	if (transport_supported(LinphoneTransportTls)) {
736 737 738 739 740 741
		LinphoneChatRoom* chat_room;
		LinphoneChatMessage* message;
		LinphoneChatMessageCbs *cbs;
		LinphoneContent* content;
		FILE *file_to_send = NULL;
		size_t file_size;
742 743
		char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg");
		char *receive_filepath = bc_tester_file("receive_file.dump");
744 745 746 747 748
		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);
749 750

		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
Sylvain Berfini's avatar
Sylvain Berfini committed
751
		linphone_core_set_network_reachable(marie->lc, TRUE);
752 753
		linphone_core_manager_start(marie, TRUE);
		
754 755

		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
756
		linphone_core_set_network_reachable(pauline->lc, TRUE);
757
		linphone_core_manager_start(pauline, TRUE);
758 759 760

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

762 763 764 765 766 767 768 769 770
		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
771 772

		chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
		/* 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);
		cbs = linphone_chat_message_get_callbacks(message);
		{
			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);
		}
		linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed);
789
		linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send);
790 791
		linphone_chat_room_send_chat_message(chat_room,message);
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1));
792

793 794 795 796 797 798 799 800
		if (marie->stat.last_received_chat_message ) {
			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);
			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));

801
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
802 803
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1, int, "%d");
804
		compare_files(send_filepath, receive_filepath);
805 806 807 808 809

		linphone_content_unref(content);
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline);
		ms_free(send_filepath);
810
		bc_free(receive_filepath);
811
	}
812 813
}

814
void send_file_transfer_message_using_external_body_url(LinphoneCoreManager *marie, LinphoneCoreManager *pauline) {
815 816 817
	LinphoneChatMessageCbs *cbs;
	LinphoneChatRoom *chat_room;
	LinphoneChatMessage *message;
818

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

822
	message = linphone_chat_room_create_message(chat_room, NULL);
823

824 825
	cbs = linphone_chat_message_get_callbacks(message);
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
826

827 828
	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);
829

830
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1));
831 832 833
	if (marie->stat.last_received_chat_message) {
		linphone_chat_message_download_file(marie->stat.last_received_chat_message);
	}
834
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageExtBodyReceived, 1));
835

836 837
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress, 1, int, "%d");
	BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived, 1, int, "%d");
838 839 840
	
	BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &pauline->stat.number_of_LinphoneMessageDelivered, 1));
	
841 842 843
}

static void file_transfer_message_external_body_to_external_body_client(void) {
844
	if (transport_supported(LinphoneTransportTls)) {
845 846
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
847

848
		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
849
		linphone_core_manager_start(marie, TRUE);
850

851
		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp");
852
		linphone_core_manager_start(pauline, TRUE);
853

854 855
		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
856

857 858
		linphone_core_refresh_registers(marie->lc);
		linphone_core_refresh_registers(pauline->lc);
859

860
		send_file_transfer_message_using_external_body_url(marie, pauline);
861

862
		linphone_core_manager_destroy(pauline);
863
		linphone_core_manager_destroy(marie);
864
	}
865 866 867
}

static void file_transfer_message_external_body_to_rcs_client(void) {
868
	if (transport_supported(LinphoneTransportTls)) {
869 870
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
		LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
871

872
		linphone_proxy_config_set_custom_header(marie->lc->default_proxy, "Accept", "application/sdp");
873
		linphone_core_manager_start(marie, TRUE);
874

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

878 879
		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
880

881
		send_file_transfer_message_using_external_body_url(marie, pauline);
882

883
		linphone_core_manager_destroy(pauline);
884
		linphone_core_manager_destroy(marie);
885
	}
886 887
}

888 889 890
static void dos_module_trigger(void) {
	LinphoneChatRoom *chat_room;
	int i = 0;
891
	const char* passmsg = "This one should pass through";
892
	int number_of_messge_to_send = 100;
893
	LinphoneChatMessage * chat_msg = NULL;
894
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc");
895
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
896

897 898
	reset_counters(&marie->stat);
	reset_counters(&pauline->stat);
899

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

902 903 904
	do {
		char msg[128];
		sprintf(msg, "Flood message number %i", i);
905 906
		chat_msg = linphone_chat_room_create_message(chat_room, msg);
		linphone_chat_room_send_chat_message(chat_room, chat_msg);
907
		ms_usleep(10000);
908 909 910
		i++;
	} while (i < number_of_messge_to_send);
	// At this point we should be banned for a minute
911

912
	ms_usleep(65000000); // Wait several seconds to ensure we are not banned anymore
913
	BC_ASSERT_LOWER(marie->stat.number_of_LinphoneMessageReceived, number_of_messge_to_send, int, "%d");
914

915 916
	reset_counters(&marie->stat);
	reset_counters(&pauline->stat);
917 918
	chat_msg = linphone_chat_room_create_message(chat_room, passmsg);
	linphone_chat_room_send_chat_message(chat_room, chat_msg);
919
	BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageReceived, 1));
920 921 922 923
	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));
	}
924 925 926 927
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

928

jehan's avatar
jehan committed
929 930 931 932 933 934
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");
935 936
	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
937
	LpConfig *pauline_lp = linphone_core_get_config(pauline->lc);
Simon Morlat's avatar
Simon Morlat committed
938 939
	char* lf_identity=linphone_address_as_string_uri_only(marie->identity);
	LinphoneFriend *lf = linphone_core_create_friend_with_address(pauline->lc,lf_identity);
940

941 942
	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
943

jehan's avatar
jehan committed
944
	ms_free(lf_identity);
945

jehan's avatar
jehan committed
946
	lp_config_set_int(pauline_lp,"sip","subscribe_expires",5);
947

jehan's avatar
jehan committed
948
	linphone_core_add_friend(pauline->lc,lf);
949

jehan's avatar
jehan committed
950
	/*wait for subscribe acknowledgment*/
951
	BC_ASSERT_TRUE(wait_for_until(pauline->lc,pauline->lc,&pauline->stat.number_of_NotifyPresenceReceived,1,2000));
jehan's avatar
jehan committed
952
	BC_ASSERT_EQUAL(LinphoneStatusOffline,linphone_friend_get_status(lf), int, "%d");
953

jehan's avatar
jehan committed
954
	scen = bc_tester_res("sipp/simple_publish.xml");
955

956 957 958
	sip_example_org = linphone_core_manager_resolve(marie, marie->identity);
	sipp_out = sip_start(scen, linphone_address_get_username(marie->identity), linphone_auth_info_get_passwd(marie_auth), sip_example_org);
	linphone_address_destroy(sip_example_org);
959

960
	if (sipp_out) {
jehan's avatar
jehan committed
961
		/*wait for marie status*/
962
		BC_ASSERT_TRUE(wait_for_until(pauline->lc,pauline->lc,&pauline->stat.number_of_NotifyPresenceReceived,2,3000));
jehan's avatar
jehan committed
963
		BC_ASSERT_EQUAL(LinphoneStatusOnline,linphone_friend_get_status(lf), int, "%d");
964
		BC_ASSERT_EQUAL(0,pclose(sipp_out),int,"%d");
jehan's avatar
jehan committed
965
	}
966

jehan's avatar
jehan committed
967 968 969
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
970
	//does not work because sipp seams not able to manage 2 call  id in case file
971
#if 0
972
static void test_subscribe_notify_with_sipp_publisher_double_publish(void) {
jehan's avatar
jehan committed
973 974 975 976 977
	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");
978
	LinphoneAddress *sip_example_org;
979

980 981
	linphone_core_set_user_agent(marie->lc, "full-presence-support", NULL);
	linphone_core_set_user_agent(pauline->lc, "full-presence-support", NULL);
982

jehan's avatar
jehan committed
983 984 985 986 987
	LpConfig *pauline_lp = linphone_core_get_config(pauline->lc);
	char* lf_identity=linphone_address_as_string_uri_only(marie->identity);
	LinphoneFriend *lf = linphone_core_create_friend_with_address(pauline->lc,lf_identity);
	ms_free(lf_identity);
	lp_config_set_int(pauline_lp,"sip","subscribe_expires",5);
988

jehan's avatar
jehan committed
989
	linphone_core_add_friend(pauline->lc,lf);
990

jehan's avatar
jehan committed
991
	/*wait for subscribe acknowledgment*/
992
	BC_ASSERT_TRUE(wait_for_until(pauline->lc,pauline->lc,&pauline->stat.number_of_NotifyPresenceReceived,1,2000));
jehan's avatar
jehan committed
993
	BC_ASSERT_EQUAL(LinphoneStatusOffline,linphone_friend_get_status(lf), int, "%d");
994

jehan's avatar
jehan committed
995
	scen = bc_tester_res("sipp/double_publish_with_error.xml");
996

997