flexisip_tester.c 65.5 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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
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()));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
47

48
	lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",expires,content);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
75

76 77
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
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

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

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

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

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

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

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

121
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
122
	linphone_chat_room_send_chat_message(chat_room, message);
123 124 125
	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");
126 127
	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
128 129
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
130
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
131

Simon Morlat's avatar
Simon Morlat committed
132 133
	/*wait a long time so that all transactions are expired*/
	wait_for_list(lcs,NULL,0,32000);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
134

Simon Morlat's avatar
Simon Morlat committed
135 136
	/*marie 3 goes online now*/
	linphone_core_set_network_reachable(marie3->lc,TRUE);
137
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
138

Simon Morlat's avatar
Simon Morlat committed
139 140
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
141
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
142
	linphone_core_manager_destroy(pauline);
143
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
144 145 146 147
}

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

156 157 158
	lcs=bctbx_list_append(lcs,pauline->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
159

Simon Morlat's avatar
Simon Morlat committed
160 161 162 163 164 165 166
	/*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;

167

Simon Morlat's avatar
Simon Morlat committed
168 169 170 171
	/*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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
172

173
	linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed);
174
	linphone_chat_room_send_chat_message(chat_room, message);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
175

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

Simon Morlat's avatar
Simon Morlat committed
183 184
	/*marie 1 goes online */
	linphone_core_set_network_reachable(marie->lc,TRUE);
185
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
186

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

Simon Morlat's avatar
Simon Morlat committed
191 192
	/*wait a long time so that all transactions are expired*/
	wait_for_list(lcs,NULL,0,32000);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
193

Simon Morlat's avatar
Simon Morlat committed
194 195
	/*marie 3 goes online now*/
	linphone_core_set_network_reachable(marie3->lc,TRUE);
196
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
197

Simon Morlat's avatar
Simon Morlat committed
198 199
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
200
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
201
	linphone_core_manager_destroy(pauline);
202
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
203 204 205 206
}

static void call_forking(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
207
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
208 209
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
210
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
211

212 213 214
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
215

Simon Morlat's avatar
Simon Morlat committed
216 217 218 219
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
220

Simon Morlat's avatar
Simon Morlat committed
221 222
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
223
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
224
	/*all devices from Marie should be ringing*/
225 226 227
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
228

Simon Morlat's avatar
Simon Morlat committed
229
	/*marie accepts the call on its first device*/
230
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
231 232 233 234
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
235

Simon Morlat's avatar
Simon Morlat committed
236
	/*other devices should stop ringing*/
237 238
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
239

240
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
241 242
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
243

Simon Morlat's avatar
Simon Morlat committed
244 245 246 247
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
248
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
249 250 251 252
}

static void call_forking_with_urgent_reply(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
253
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
254 255
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
256 257 258 259
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
260

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	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*/
279
		linphone_call_accept(linphone_core_get_current_call(marie->lc));
280 281 282 283 284
		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));

285
		linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
286 287 288
		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
289 290 291 292
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
293
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
294 295 296 297
}

static void call_forking_cancelled(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
298
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
299 300
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
301
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
302

303 304 305
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
306

Simon Morlat's avatar
Simon Morlat committed
307 308 309 310
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
311

Simon Morlat's avatar
Simon Morlat committed
312 313
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
314
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
315
	/*all devices from Marie should be ringing*/
316 317 318
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
319

Simon Morlat's avatar
Simon Morlat committed
320
	/*pauline finally cancels the call*/
321
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
322
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
323

Simon Morlat's avatar
Simon Morlat committed
324
	/*all devices should stop ringing*/
325 326 327
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
328

Simon Morlat's avatar
Simon Morlat committed
329 330 331 332
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
333
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
334 335 336 337
}

static void call_forking_declined(bool_t declined_globaly){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
338
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
339 340
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
341
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
342

343 344 345
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
346

Simon Morlat's avatar
Simon Morlat committed
347 348 349 350
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
351

Simon Morlat's avatar
Simon Morlat committed
352 353
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
354
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
355
	/*all devices from Marie should be ringing*/
356 357 358
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
359

360
	/*marie finally declines the call*/
361
	linphone_call_decline(linphone_core_get_current_call(marie->lc),
Simon Morlat's avatar
Simon Morlat committed
362 363
		declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy
	);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
364

Simon Morlat's avatar
Simon Morlat committed
365
	if (declined_globaly){
366
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Simon Morlat's avatar
Simon Morlat committed
367
		/*all devices should stop ringing*/
368 369 370
		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
371 372
	}else{
		/*pauline should continue ringing and be able to hear a call taken by marie2 */
373
		linphone_call_accept(linphone_core_get_current_call(marie2->lc));
374 375
		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
376
		liblinphone_tester_check_rtcp(pauline,marie2);
377 378
		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));
379
		linphone_call_terminate(linphone_core_get_current_call(marie2->lc));
380 381
		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
382
	}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
383

Simon Morlat's avatar
Simon Morlat committed
384 385 386 387
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
388
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
389 390 391 392 393 394 395 396 397 398 399
}

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){
400
	bctbx_list_t* lcs;
401
	LinphoneCoreManager* marie = linphone_core_manager_new2( "marie_rc", FALSE);
402
	LinphoneCoreManager* pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc",FALSE);
403
	int dummy=0;
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
404

Simon Morlat's avatar
Simon Morlat committed
405 406
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
407 408 409
	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;");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
410

411 412
	lcs=bctbx_list_append(NULL,pauline->lc);
	lcs=bctbx_list_append(lcs,marie->lc);
413

414 415
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
416

Simon Morlat's avatar
Simon Morlat committed
417 418
	/*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/
	linphone_core_set_network_reachable(marie->lc,FALSE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
419

Simon Morlat's avatar
Simon Morlat committed
420
	linphone_core_invite_address(pauline->lc,marie->identity);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
421

422 423
	/*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
424
	linphone_core_set_network_reachable(marie->lc,TRUE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
425

Simon Morlat's avatar
Simon Morlat committed
426
	/*Marie shall receive the call immediately*/
427
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
428
	/*pauline should hear ringback as well*/
429
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
430

Simon Morlat's avatar
Simon Morlat committed
431
	/*marie accepts the call*/
432
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
433 434 435 436
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
437

Simon Morlat's avatar
Simon Morlat committed
438
	liblinphone_tester_check_rtcp(pauline,marie);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
439

440
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
441 442
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
443

Simon Morlat's avatar
Simon Morlat committed
444 445
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
446
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
447 448 449 450
}

static void call_forking_with_push_notification_multiple(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
451
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
452
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
453

454
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
455

456 457
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
458

Simon Morlat's avatar
Simon Morlat committed
459 460 461
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
462

Simon Morlat's avatar
Simon Morlat committed
463 464
	/*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/
	linphone_core_set_network_reachable(marie2->lc,FALSE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
465

Simon Morlat's avatar
Simon Morlat committed
466
	linphone_core_invite_address(pauline->lc,marie->identity);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
467

468
	/*marie will ring*/
469
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
470
	/*pauline should hear ringback as well*/
471
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
472

Simon Morlat's avatar
Simon Morlat committed
473 474
	/*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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
475

Simon Morlat's avatar
Simon Morlat committed
476
	/*Marie shall receive the call immediately*/
477
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
478

Simon Morlat's avatar
Simon Morlat committed
479
	/*marie2 accepts the call*/
480
	linphone_call_accept(linphone_core_get_current_call(marie2->lc));
481 482 483 484
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
485

486
	/*call to marie should be cancelled*/
487
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
488

Simon Morlat's avatar
Simon Morlat committed
489
	liblinphone_tester_check_rtcp(pauline,marie2);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
490

491
	linphone_call_terminate(linphone_core_get_current_call(pauline->lc));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
492

493 494
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
495

Simon Morlat's avatar
Simon Morlat committed
496 497 498 499 500
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
}

Simon Morlat's avatar
Simon Morlat committed
501
static void call_forking_not_responded(void){
502
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
503
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
504 505
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
506
	bctbx_list_t* lcs=bctbx_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
507

508 509 510
	lcs=bctbx_list_append(lcs,marie->lc);
	lcs=bctbx_list_append(lcs,marie2->lc);
	lcs=bctbx_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
511

512 513 514 515
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
516

517 518
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
519
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
520
	/*all devices from Marie should be ringing*/
521 522 523
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
524

525
	/*nobody answers, flexisip should close the call after XX seconds*/
526
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallError,1,22000));
527
	/*all devices should stop ringing*/
528 529 530
	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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
531

532 533 534 535
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie3);
536
	bctbx_list_free(lcs);
537 538
}

Simon Morlat's avatar
Simon Morlat committed
539
static void early_media_call_forking(void) {
540
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_early_rc");
Simon Morlat's avatar
Simon Morlat committed
541
	LinphoneCoreManager* marie2 = linphone_core_manager_new("marie_early_rc");
542
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
543
	bctbx_list_t *lcs=NULL;
544
	LinphoneCallParams *params=linphone_core_create_call_params(pauline->lc, NULL);
Simon Morlat's avatar
Simon Morlat committed
545 546
	LinphoneVideoPolicy pol;
	int dummy=0;
547

Simon Morlat's avatar
Simon Morlat committed
548 549
	pol.automatically_accept=1;
	pol.automatically_initiate=1;
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
550

551
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
Simon Morlat's avatar
Simon Morlat committed
552 553
	linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
554

555 556
	linphone_core_enable_video_capture(pauline->lc,TRUE);
	linphone_core_enable_video_display(pauline->lc,TRUE);
557

558 559
	linphone_core_enable_video_capture(marie->lc,TRUE);
	linphone_core_enable_video_display(marie->lc,TRUE);
560
	linphone_core_set_video_policy(marie->lc,&pol);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
561

562 563 564
	linphone_core_enable_video_capture(marie2->lc,TRUE);
	linphone_core_enable_video_display(marie2->lc,TRUE);

Simon Morlat's avatar
Simon Morlat committed
565 566 567
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
568

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

	linphone_call_params_enable_early_media_sending(params,TRUE);
	linphone_call_params_enable_video(params,TRUE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
575

576
	linphone_core_invite_address_with_params(pauline->lc,marie->identity,params);
Simon Morlat's avatar
Simon Morlat committed
577
	linphone_call_params_unref(params);
Simon Morlat's avatar
Simon Morlat committed
578

579
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000));
580 581 582
	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");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
583

Simon Morlat's avatar
Simon Morlat committed
584
	/*wait a bit that streams are established*/
585 586 587 588 589 590 591
	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");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
592

593
	linphone_call_accept(linphone_core_get_current_call(marie->lc));
594
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,3000));
595
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
596

Simon Morlat's avatar
Simon Morlat committed
597
	/*marie2 should get her call terminated*/
598
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
599

Simon Morlat's avatar
Simon Morlat committed
600
	/*wait a bit that streams are established*/
Simon Morlat's avatar
Simon Morlat committed
601
	wait_for_list(lcs,&dummy,1,3000);
602 603 604 605
	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");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
606

607
	end_call(pauline, marie);
Simon Morlat's avatar
Simon Morlat committed
608

609
	bctbx_list_free(lcs);
Simon Morlat's avatar
Simon Morlat committed
610
	linphone_core_manager_destroy(pauline);
611 612
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie);
Simon Morlat's avatar
Simon Morlat committed
613 614
}

615
static void call_with_sips(void){
616
	if (transport_supported(LinphoneTransportTls)) {
617 618
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_sips_rc");
619
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
620
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
621

622 623
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
624

625 626 627
		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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
628

629
		linphone_core_invite_address(marie->lc,pauline1->identity);
630

631 632 633 634
		/*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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
635

636
		/*pauline accepts the call */
637
		linphone_call_accept(linphone_core_get_current_call(pauline1->lc));
638 639 640 641
		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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
642

643 644
		/*pauline2 should not have ring*/
		BC_ASSERT_EQUAL(pauline2->stat.number_of_LinphoneCallIncomingReceived, 0, int, "%d");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
645

646
		linphone_call_terminate(linphone_core_get_current_call(pauline1->lc));
647 648
		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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
649

650 651
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
652
		linphone_core_manager_destroy(pauline2);
653
		bctbx_list_free(lcs);
654
	}
655 656 657
}

static void call_with_sips_not_achievable(void){
658 659
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
660 661
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_rc");
662
		bctbx_list_t* lcs=bctbx_list_append(NULL,marie->lc);
663 664 665 666
		LinphoneAddress *dest;
		LinphoneCall *call;
		const LinphoneErrorInfo *ei;

667 668
		lcs=bctbx_list_append(lcs,pauline1->lc);
		lcs=bctbx_list_append(lcs,pauline2->lc);
669 670 671 67