flexisip_tester.c 42.3 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
    liblinphone_tester - liblinphone test suite
    Copyright (C) 2013  Belledonne Communications SARL

    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.

    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.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
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()));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
41

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

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

Simon Morlat's avatar
Simon Morlat committed
72
	linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc);
73 74 75 76
	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));
	BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,1, int, "%d");
Simon Morlat's avatar
Simon Morlat committed
77 78 79 80 81 82 83 84
	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");
85
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
86 87 88
	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
89
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
90
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
91

Simon Morlat's avatar
Simon Morlat committed
92 93 94
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
95

Simon Morlat's avatar
Simon Morlat committed
96 97 98
	/*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
99

Simon Morlat's avatar
Simon Morlat committed
100
	linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc);
101 102 103
	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");
104 105
	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
106 107
	/*marie 2 goes online */
	linphone_core_set_network_reachable(marie2->lc,TRUE);
108
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
109

Simon Morlat's avatar
Simon Morlat committed
110 111
	/*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
112

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

Simon Morlat's avatar
Simon Morlat committed
117 118
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
119
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
120 121 122 123 124 125
	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");
126
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
127 128 129
	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
130
	LinphoneChatRoom* chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
Simon Morlat's avatar
Simon Morlat committed
131
	LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
132

Simon Morlat's avatar
Simon Morlat committed
133 134 135
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
136

Simon Morlat's avatar
Simon Morlat committed
137 138 139 140
	/*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
141

Simon Morlat's avatar
Simon Morlat committed
142
	linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
143

144
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageInProgress,1,5000));
Simon Morlat's avatar
Simon Morlat committed
145
	/*flexisip will accept the message with 202 after 16 seconds*/
146
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,18000));
147 148 149
	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
150

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

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

Simon Morlat's avatar
Simon Morlat committed
159 160
	/*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
161

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

Simon Morlat's avatar
Simon Morlat committed
166 167
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
168
	linphone_core_manager_destroy(marie3);
Simon Morlat's avatar
Simon Morlat committed
169 170 171 172 173 174
	linphone_core_manager_destroy(pauline);
	ms_list_free(lcs);
}

static void call_forking(void){
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
175
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
176 177 178
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
179

Simon Morlat's avatar
Simon Morlat committed
180 181 182
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
183

Simon Morlat's avatar
Simon Morlat committed
184 185 186 187
	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
188

Simon Morlat's avatar
Simon Morlat committed
189 190
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
191
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
192
	/*all devices from Marie should be ringing*/
193 194 195
	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
196

Simon Morlat's avatar
Simon Morlat committed
197 198
	/*marie accepts the call on its first device*/
	linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc));
199 200 201 202
	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
203

Simon Morlat's avatar
Simon Morlat committed
204
	/*other devices should stop ringing*/
205 206
	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
207

Simon Morlat's avatar
Simon Morlat committed
208
	linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
209 210
	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
211

Simon Morlat's avatar
Simon Morlat committed
212 213 214 215 216 217 218 219 220
	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");
221
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
222 223 224 225 226 227
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	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
257 258 259 260 261 262 263 264 265
	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");
266
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
267 268 269
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
270

Simon Morlat's avatar
Simon Morlat committed
271 272 273
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
274

Simon Morlat's avatar
Simon Morlat committed
275 276 277 278
	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
279

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

Simon Morlat's avatar
Simon Morlat committed
288 289
	/*pauline finally cancels the call*/
	linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
290
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
291

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

Simon Morlat's avatar
Simon Morlat committed
297 298 299 300 301 302 303 304 305
	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");
306
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
307 308 309
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
310

Simon Morlat's avatar
Simon Morlat committed
311 312 313
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
314

Simon Morlat's avatar
Simon Morlat committed
315 316 317 318
	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
319

Simon Morlat's avatar
Simon Morlat committed
320 321
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
322
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
Simon Morlat's avatar
Simon Morlat committed
323
	/*all devices from Marie should be ringing*/
324 325 326
	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
327

328
	/*marie finally declines the call*/
Simon Morlat's avatar
Simon Morlat committed
329 330 331
	linphone_core_decline_call(marie->lc,linphone_core_get_current_call(marie->lc),
		declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy
	);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
332

Simon Morlat's avatar
Simon Morlat committed
333
	if (declined_globaly){
334
		BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000));
Simon Morlat's avatar
Simon Morlat committed
335
		/*all devices should stop ringing*/
336 337 338
		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
339 340 341
	}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));
342 343
		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
344
		liblinphone_tester_check_rtcp(pauline,marie2);
345 346
		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
347
		linphone_core_terminate_call(marie2->lc,linphone_core_get_current_call(marie2->lc));
348 349
		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
350
	}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
351

Simon Morlat's avatar
Simon Morlat committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
	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){
368
	MSList* lcs;
369
	LinphoneCoreManager* marie = linphone_core_manager_new2( "marie_rc", FALSE);
370
	LinphoneCoreManager* pauline = linphone_core_manager_new2( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc",FALSE);
371
	int dummy=0;
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
372

Simon Morlat's avatar
Simon Morlat committed
373 374
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
375 376 377
	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
378

379
	lcs=ms_list_append(NULL,pauline->lc);
Simon Morlat's avatar
Simon Morlat committed
380
	lcs=ms_list_append(lcs,marie->lc);
381

382 383
	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
384

Simon Morlat's avatar
Simon Morlat committed
385 386
	/*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
387

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

390 391
	/*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
392
	linphone_core_set_network_reachable(marie->lc,TRUE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
393

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

Simon Morlat's avatar
Simon Morlat committed
399 400
	/*marie accepts the call*/
	linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc));
401 402 403 404
	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
405

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

Simon Morlat's avatar
Simon Morlat committed
408
	linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
409 410
	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
411

Simon Morlat's avatar
Simon Morlat committed
412 413 414 415 416 417 418
	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");
419
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
420
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
421

Simon Morlat's avatar
Simon Morlat committed
422
	MSList* lcs=ms_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
423

Simon Morlat's avatar
Simon Morlat committed
424 425
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
426

Simon Morlat's avatar
Simon Morlat committed
427 428 429
	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
430

Simon Morlat's avatar
Simon Morlat committed
431 432
	/*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
433

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

436
	/*marie will ring*/
437
	BC_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000));
Simon Morlat's avatar
Simon Morlat committed
438
	/*pauline should hear ringback as well*/
439
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
440

Simon Morlat's avatar
Simon Morlat committed
441 442
	/*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
443

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

Simon Morlat's avatar
Simon Morlat committed
447 448
	/*marie2 accepts the call*/
	linphone_core_accept_call(marie2->lc,linphone_core_get_current_call(marie2->lc));
449 450 451 452
	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
453

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

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

Simon Morlat's avatar
Simon Morlat committed
459
	linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
460

461 462
	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
463

Simon Morlat's avatar
Simon Morlat committed
464 465 466 467 468
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(marie2);
}

Simon Morlat's avatar
Simon Morlat committed
469
static void call_forking_not_responded(void){
470
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
471
	LinphoneCoreManager* pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
472 473 474
	LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc");
	MSList* lcs=ms_list_append(NULL,pauline->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
475

476 477 478
	lcs=ms_list_append(lcs,marie->lc);
	lcs=ms_list_append(lcs,marie2->lc);
	lcs=ms_list_append(lcs,marie3->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
479

480 481 482 483
	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
484

485 486
	linphone_core_invite_address(pauline->lc,marie->identity);
	/*pauline should hear ringback*/
487
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000));
488
	/*all devices from Marie should be ringing*/
489 490 491
	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
492

493
	/*nobody answers, flexisip should close the call after XX seconds*/
494
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallError,1,22000));
495
	/*all devices should stop ringing*/
496 497 498
	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
499

500 501 502 503 504 505 506
	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
507
static void early_media_call_forking(void) {
508
	LinphoneCoreManager* marie = linphone_core_manager_new("marie_early_rc");
Simon Morlat's avatar
Simon Morlat committed
509
	LinphoneCoreManager* marie2 = linphone_core_manager_new("marie_early_rc");
510
	LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
Simon Morlat's avatar
Simon Morlat committed
511
	MSList *lcs=NULL;
512
	LinphoneCallParams *params=linphone_core_create_call_params(pauline->lc, NULL);
Simon Morlat's avatar
Simon Morlat committed
513 514
	LinphoneVideoPolicy pol;
	int dummy=0;
515

Simon Morlat's avatar
Simon Morlat committed
516 517
	pol.automatically_accept=1;
	pol.automatically_initiate=1;
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
518

519
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
Simon Morlat's avatar
Simon Morlat committed
520 521
	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
522

Simon Morlat's avatar
Simon Morlat committed
523
	linphone_core_enable_video(pauline->lc,TRUE,TRUE);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
524

525 526
	linphone_core_enable_video(marie->lc,TRUE,TRUE);
	linphone_core_set_video_policy(marie->lc,&pol);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
527

Simon Morlat's avatar
Simon Morlat committed
528 529 530 531
	linphone_core_enable_video(marie2->lc,TRUE,TRUE);
	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
532

533
	lcs=ms_list_append(lcs,marie->lc);
Simon Morlat's avatar
Simon Morlat committed
534 535 536 537 538
	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);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
539

540
	linphone_core_invite_address_with_params(pauline->lc,marie->identity,params);
Simon Morlat's avatar
Simon Morlat committed
541 542
	linphone_call_params_destroy(params);

543
	BC_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000));
544 545 546
	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
547

Simon Morlat's avatar
Simon Morlat committed
548
	/*wait a bit that streams are established*/
549 550 551 552 553 554 555
	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
556

557 558
	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));
559
	BC_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,3000));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
560

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

Simon Morlat's avatar
Simon Morlat committed
564
	/*wait a bit that streams are established*/
Simon Morlat's avatar
Simon Morlat committed
565
	wait_for_list(lcs,&dummy,1,3000);
566 567 568 569
	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
570

571
	end_call(pauline, marie);
Simon Morlat's avatar
Simon Morlat committed
572 573 574

	ms_list_free(lcs);
	linphone_core_manager_destroy(pauline);
575 576
	linphone_core_manager_destroy(marie2);
	linphone_core_manager_destroy(marie);
Simon Morlat's avatar
Simon Morlat committed
577 578
}

579
static void call_with_sips(void){
580
	if (transport_supported(LinphoneTransportTls)) {
581 582
		LinphoneCoreManager* marie = linphone_core_manager_new( "marie_sips_rc");
		LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_sips_rc");
583
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
584
		MSList* lcs=ms_list_append(NULL,marie->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
585

586 587
		lcs=ms_list_append(lcs,pauline1->lc);
		lcs=ms_list_append(lcs,pauline2->lc);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
588

589 590 591
		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
592

593
		linphone_core_invite_address(marie->lc,pauline1->identity);
594

595 596 597 598
		/*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
599

600 601 602 603 604 605
		/*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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
606

607 608
		/*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
609

610 611 612
		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));
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
613

614 615
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
616
		linphone_core_manager_destroy(pauline2);
617 618
		ms_list_free(lcs);
	}
619 620 621
}

static void call_with_sips_not_achievable(void){
622 623
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc");
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
		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");
		}
648

649 650
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline1);
651
		linphone_core_manager_destroy(pauline2);
652
		ms_list_free(lcs);
653 654 655 656 657 658 659 660
	}
}

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

Simon Morlat's avatar
Simon Morlat committed
661 662
	/*calling ortp_init() here is done to have WSAStartup() done, otherwise liblinphone_tester_ipv6_available() will not work.*/
	ortp_init();
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
663

664 665 666 667
	if (!liblinphone_tester_ipv6_available()){
		ms_warning("Call with ipv6 not tested, no ipv6 connectivity");
		return;
	}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
668

669 670
	liblinphone_tester_enable_ipv6(TRUE);
	marie = linphone_core_manager_new( "marie_rc");
671
	pauline = linphone_core_manager_new( transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc");
672 673 674

	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
675
	BC_ASSERT_TRUE(call(marie,pauline));
676
	pauline_call=linphone_core_get_current_call(pauline->lc);
677
	BC_ASSERT_PTR_NOT_NULL(pauline_call);
678 679 680 681
	if (pauline_call){
		/*check that the remote contact is IPv6*/
		const char *contact=linphone_call_get_remote_contact(pauline_call);
		LinphoneAddress *ct_addr;
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
682

683
		BC_ASSERT_PTR_NOT_NULL(contact);
684 685
		if (contact){
			ct_addr=linphone_address_new(contact);
686
			BC_ASSERT_PTR_NOT_NULL(ct_addr);
687
			if (ct_addr){
688
				BC_ASSERT_PTR_NOT_NULL(strchr(linphone_address_get_domain(ct_addr),':'));
689 690 691
			}
			linphone_address_destroy(ct_addr);
		}
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
692

693
	}
694 695 696 697 698 699 700

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

Simon Morlat's avatar
Simon Morlat committed
701
	ortp_exit();
702
}
Simon Morlat's avatar
Simon Morlat committed
703

704
static void file_transfer_message_rcs_to_external_body_client(void) {
705 706
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_init( "marie_rc");
707 708 709 710 711 712
		LinphoneChatRoom* chat_room;
		LinphoneChatMessage* message;
		LinphoneChatMessageCbs *cbs;
		LinphoneContent* content;
		FILE *file_to_send = NULL;
		size_t file_size;
713 714
		char *send_filepath = bc_tester_res("images/nowebcamCIF.jpg");
		char *receive_filepath = bc_tester_file("receive_file.dump");
715 716 717 718 719 720 721
		LinphoneCoreManager* pauline = linphone_core_manager_init( "pauline_rc");

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

		linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml");
		linphone_core_manager_start(pauline, "pauline_rc", TRUE);
722 723 724

		reset_counters(&marie->stat);
		reset_counters(&pauline->stat);
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
725

726 727 728 729 730 731 732 733 734
		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
735 736

		chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity);
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
		/* 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);
753
		linphone_chat_message_cbs_set_file_transfer_send(cbs, tester_file_transfer_send);
754 755
		linphone_chat_room_send_chat_message(chat_room,message);
		BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageExtBodyReceived,1));
756

757 758 759 760 761 762 763 764
		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));

765
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageInProgress,2, int, "%d");
766 767
		BC_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1, int, "%d");
		BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1, int, "%d");
768
		compare_files(send_filepath, receive_filepath);