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

Simon Morlat's avatar
Simon Morlat committed
19

jehan's avatar
jehan committed
20
#include <stdio.h>
21 22
#include <sys/types.h>
#include <sys/stat.h>
jehan's avatar
jehan committed
23 24
#include "CUnit/Basic.h"
#include "linphonecore.h"
25
#include "lpconfig.h"
jehan's avatar
jehan committed
26 27
#include "private.h"
#include "liblinphone_tester.h"
Simon Morlat's avatar
Simon Morlat committed
28
#include "mediastreamer2/msutils.h"
jehan's avatar
jehan committed
29
#include "belle-sip/sipstack.h"
Simon Morlat's avatar
Simon Morlat committed
30 31 32

#ifdef WIN32
#define unlink _unlink
33
#define F_OK 00
Simon Morlat's avatar
Simon Morlat committed
34
#endif
jehan's avatar
jehan committed
35

36
static void srtp_call(void);
Simon Morlat's avatar
Simon Morlat committed
37
static char *create_filepath(const char *dir, const char *filename, const char *ext);
jehan's avatar
jehan committed
38

39 40 41 42 43 44 45
// prototype definition for call_recording()
#ifdef ANDROID
#ifdef HAVE_OPENH264
extern void libmsopenh264_init(void);
#endif
#endif

jehan's avatar
jehan committed
46 47 48
void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg){
	char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to);
	char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from);
49
	stats* counters;
jehan's avatar
jehan committed
50 51 52 53
	ms_message(" %s call from [%s] to [%s], new state is [%s]"	,linphone_call_get_call_log(call)->dir==LinphoneCallIncoming?"Incoming":"Outgoing"
																,from
																,to
																,linphone_call_state_to_string(cstate));
jehan's avatar
jehan committed
54 55
	ms_free(to);
	ms_free(from);
56
	counters = get_stats(lc);
jehan's avatar
jehan committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	switch (cstate) {
	case LinphoneCallIncomingReceived:counters->number_of_LinphoneCallIncomingReceived++;break;
	case LinphoneCallOutgoingInit :counters->number_of_LinphoneCallOutgoingInit++;break;
	case LinphoneCallOutgoingProgress :counters->number_of_LinphoneCallOutgoingProgress++;break;
	case LinphoneCallOutgoingRinging :counters->number_of_LinphoneCallOutgoingRinging++;break;
	case LinphoneCallOutgoingEarlyMedia :counters->number_of_LinphoneCallOutgoingEarlyMedia++;break;
	case LinphoneCallConnected :counters->number_of_LinphoneCallConnected++;break;
	case LinphoneCallStreamsRunning :counters->number_of_LinphoneCallStreamsRunning++;break;
	case LinphoneCallPausing :counters->number_of_LinphoneCallPausing++;break;
	case LinphoneCallPaused :counters->number_of_LinphoneCallPaused++;break;
	case LinphoneCallResuming :counters->number_of_LinphoneCallResuming++;break;
	case LinphoneCallRefered :counters->number_of_LinphoneCallRefered++;break;
	case LinphoneCallError :counters->number_of_LinphoneCallError++;break;
	case LinphoneCallEnd :counters->number_of_LinphoneCallEnd++;break;
	case LinphoneCallPausedByRemote :counters->number_of_LinphoneCallPausedByRemote++;break;
	case LinphoneCallUpdatedByRemote :counters->number_of_LinphoneCallUpdatedByRemote++;break;
	case LinphoneCallIncomingEarlyMedia :counters->number_of_LinphoneCallIncomingEarlyMedia++;break;
	case LinphoneCallUpdating :counters->number_of_LinphoneCallUpdating++;break;
	case LinphoneCallReleased :counters->number_of_LinphoneCallReleased++;break;
76 77
	case LinphoneCallEarlyUpdating: counters->number_of_LinphoneCallEarlyUpdating++;break;
	case LinphoneCallEarlyUpdatedByRemote: counters->number_of_LinphoneCallEarlyUpdatedByRemote++;break;
jehan's avatar
jehan committed
78 79 80 81
	default:
		CU_FAIL("unexpected event");break;
	}
}
82 83 84 85 86 87 88 89 90 91

void call_stats_updated(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *lstats) {
	stats* counters = get_stats(lc);
	if (lstats->updated == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE) {
		counters->number_of_rtcp_received++;
	} else if (lstats->updated == LINPHONE_CALL_STATS_SENT_RTCP_UPDATE) {
		counters->number_of_rtcp_sent++;
	}
}

jehan's avatar
jehan committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
void linphone_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token) {
	char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to);
	char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from);
	stats* counters;
	ms_message(" %s call from [%s] to [%s], is now [%s]",linphone_call_get_call_log(call)->dir==LinphoneCallIncoming?"Incoming":"Outgoing"
														,from
														,to
														,(on?"encrypted":"unencrypted"));
	ms_free(to);
	ms_free(from);
	counters = get_stats(lc);
	if (on)
		counters->number_of_LinphoneCallEncryptedOn++;
	else
		counters->number_of_LinphoneCallEncryptedOff++;
}
johan's avatar
johan committed
108

jehan's avatar
jehan committed
109 110 111
void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state) {
	char* to=linphone_address_as_string(linphone_call_get_call_log(transfered)->to);
	char* from=linphone_address_as_string(linphone_call_get_call_log(transfered)->from);
112
	stats* counters;
jehan's avatar
jehan committed
113 114 115 116
	ms_message("Transferred call from [%s] to [%s], new state is [%s]",from,to,linphone_call_state_to_string(new_call_state));
	ms_free(to);
	ms_free(from);

117
	counters = get_stats(lc);
jehan's avatar
jehan committed
118
	switch (new_call_state) {
jehan's avatar
jehan committed
119
	case LinphoneCallOutgoingInit :counters->number_of_LinphoneTransferCallOutgoingInit++;break;
120 121 122 123 124
	case LinphoneCallOutgoingProgress :counters->number_of_LinphoneTransferCallOutgoingProgress++;break;
	case LinphoneCallOutgoingRinging :counters->number_of_LinphoneTransferCallOutgoingRinging++;break;
	case LinphoneCallOutgoingEarlyMedia :counters->number_of_LinphoneTransferCallOutgoingEarlyMedia++;break;
	case LinphoneCallConnected :counters->number_of_LinphoneTransferCallConnected++;break;
	case LinphoneCallStreamsRunning :counters->number_of_LinphoneTransferCallStreamsRunning++;break;
125
	case LinphoneCallError :counters->number_of_LinphoneTransferCallError++;break;
jehan's avatar
jehan committed
126 127 128 129
	default:
		CU_FAIL("unexpected event");break;
	}
}
Ghislain MARY's avatar
Ghislain MARY committed
130

jehan's avatar
jehan committed
131 132

void linphone_call_cb(LinphoneCall *call,void * user_data) {
jehan's avatar
jehan committed
133 134
	char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to);
	char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from);
135
	stats* counters;
jehan's avatar
jehan committed
136 137 138 139
	LinphoneCore* lc=(LinphoneCore*)user_data;
	ms_message("call from [%s] to [%s] receive iFrame",from,to);
	ms_free(to);
	ms_free(from);
140
	counters = (stats*)get_stats(lc);
jehan's avatar
jehan committed
141 142
	counters->number_of_IframeDecoded++;
}
Simon Morlat's avatar
Simon Morlat committed
143

Simon Morlat's avatar
Simon Morlat committed
144
void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee) {
145 146
	LinphoneCall *c1,*c2;
	int dummy=0;
Simon Morlat's avatar
Simon Morlat committed
147
	MSTimeSpec ts;
148 149 150

	c1=linphone_core_get_current_call(caller->lc);
	c2=linphone_core_get_current_call(callee->lc);
151

Simon Morlat's avatar
Simon Morlat committed
152 153
	CU_ASSERT_PTR_NOT_NULL(c1);
	CU_ASSERT_PTR_NOT_NULL(c2);
154

Simon Morlat's avatar
Simon Morlat committed
155
	if (!c1 || !c2) return;
jehan's avatar
jehan committed
156 157
	linphone_call_ref(c1);
	linphone_call_ref(c2);
158

Simon Morlat's avatar
Simon Morlat committed
159 160
	liblinphone_tester_clock_start(&ts);
	do {
161 162
		if (linphone_call_get_audio_stats(c1)->round_trip_delay >0.0
				&& linphone_call_get_audio_stats(c2)->round_trip_delay >0.0
jehan's avatar
jehan committed
163 164
				&& (!linphone_call_log_video_enabled(linphone_call_get_call_log(c1)) || linphone_call_get_video_stats(c1)->round_trip_delay>0.0)
				&& (!linphone_call_log_video_enabled(linphone_call_get_call_log(c2))  || linphone_call_get_video_stats(c2)->round_trip_delay>0.0)) {
165
			break;
jehan's avatar
jehan committed
166

167
		}
jehan's avatar
jehan committed
168
		wait_for_until(caller->lc,callee->lc,&dummy,1,500); /*just to sleep while iterating*/
Simon Morlat's avatar
Simon Morlat committed
169
	}while (!liblinphone_tester_clock_elapsed(&ts,12000));
170 171 172 173 174 175 176 177
	CU_ASSERT_TRUE(linphone_call_get_audio_stats(c1)->round_trip_delay>0.0);
	CU_ASSERT_TRUE(linphone_call_get_audio_stats(c2)->round_trip_delay>0.0);
	if (linphone_call_log_video_enabled(linphone_call_get_call_log(c1))) {
		CU_ASSERT_TRUE(linphone_call_get_video_stats(c1)->round_trip_delay>0.0);
	}
	if (linphone_call_log_video_enabled(linphone_call_get_call_log(c2))) {
		CU_ASSERT_TRUE(linphone_call_get_video_stats(c2)->round_trip_delay>0.0);
	}
jehan's avatar
jehan committed
178 179
	linphone_call_unref(c1);
	linphone_call_unref(c2);
180 181
}

182 183 184 185 186 187 188 189
static void setup_sdp_handling(const LinphoneCallTestParams* params, LinphoneCoreManager* mgr ){
	if( params->sdp_removal ){
		sal_default_set_sdp_handling(mgr->lc->sal, SalOpSDPSimulateRemove);
	} else if( params->sdp_simulate_error ){
		sal_default_set_sdp_handling(mgr->lc->sal, SalOpSDPSimulateError);
	}
}

190
bool_t call_with_params2(LinphoneCoreManager* caller_mgr
191
						,LinphoneCoreManager* callee_mgr
192 193 194
						, const LinphoneCallTestParams *caller_test_params
						, const LinphoneCallTestParams *callee_test_params
						, bool_t build_callee_params) {
jehan's avatar
jehan committed
195
	int retry=0;
jehan's avatar
jehan committed
196 197
	stats initial_caller=caller_mgr->stat;
	stats initial_callee=callee_mgr->stat;
jehan's avatar
jehan committed
198
	bool_t result=FALSE;
199 200
	LinphoneCallParams *caller_params = caller_test_params->base;
	LinphoneCallParams *callee_params = callee_test_params->base;
201
	bool_t did_receive_call;
202

203 204
	setup_sdp_handling(caller_test_params, caller_mgr);
	setup_sdp_handling(callee_test_params, callee_mgr);
205

206
	if (!caller_params){
Simon Morlat's avatar
Simon Morlat committed
207 208
		CU_ASSERT_PTR_NOT_NULL(linphone_core_invite_address(caller_mgr->lc,callee_mgr->identity));
	}else{
209
		CU_ASSERT_PTR_NOT_NULL(linphone_core_invite_address_with_params(caller_mgr->lc,callee_mgr->identity,caller_params));
Simon Morlat's avatar
Simon Morlat committed
210
	}
jehan's avatar
jehan committed
211

212
	did_receive_call = wait_for(callee_mgr->lc
213 214 215
				,caller_mgr->lc
				,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived
				,initial_callee.number_of_LinphoneCallIncomingReceived+1);
216
	CU_ASSERT_EQUAL(did_receive_call, !callee_test_params->sdp_simulate_error);
217

218 219
	sal_default_set_sdp_handling(caller_mgr->lc->sal, SalOpSDPNormal);
	sal_default_set_sdp_handling(callee_mgr->lc->sal, SalOpSDPNormal);
220

221
	if (!did_receive_call) return 0;
222 223


jehan's avatar
jehan committed
224
	CU_ASSERT_TRUE(linphone_core_inc_invite_pending(callee_mgr->lc));
jehan's avatar
jehan committed
225 226
	CU_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,initial_caller.number_of_LinphoneCallOutgoingProgress+1);

jehan's avatar
jehan committed
227

jehan's avatar
jehan committed
228 229 230
	while (caller_mgr->stat.number_of_LinphoneCallOutgoingRinging!=(initial_caller.number_of_LinphoneCallOutgoingRinging + 1)
			&& caller_mgr->stat.number_of_LinphoneCallOutgoingEarlyMedia!=(initial_caller.number_of_LinphoneCallOutgoingEarlyMedia +1)
			&& retry++ <20) {
jehan's avatar
jehan committed
231 232 233 234 235 236
			linphone_core_iterate(caller_mgr->lc);
			linphone_core_iterate(callee_mgr->lc);
			ms_usleep(100000);
	}


jehan's avatar
jehan committed
237
	CU_ASSERT_TRUE((caller_mgr->stat.number_of_LinphoneCallOutgoingRinging==initial_caller.number_of_LinphoneCallOutgoingRinging+1)
Simon Morlat's avatar
Simon Morlat committed
238
							||(caller_mgr->stat.number_of_LinphoneCallOutgoingEarlyMedia==initial_caller.number_of_LinphoneCallOutgoingEarlyMedia+1));
jehan's avatar
jehan committed
239

jehan's avatar
jehan committed
240

jehan's avatar
jehan committed
241
	CU_ASSERT_PTR_NOT_NULL(linphone_core_get_current_call_remote_address(callee_mgr->lc));
242
	if(!linphone_core_get_current_call(caller_mgr->lc) || !linphone_core_get_current_call(callee_mgr->lc) || !linphone_core_get_current_call_remote_address(callee_mgr->lc)) {
jehan's avatar
jehan committed
243
		return 0;
244
	} else if (caller_mgr->identity){
jehan's avatar
jehan committed
245 246
		LinphoneAddress* callee_from=linphone_address_clone(caller_mgr->identity);
		linphone_address_set_port(callee_from,0); /*remove port because port is never present in from header*/
247

jehan's avatar
jehan committed
248
		if (linphone_call_params_get_privacy(linphone_call_get_current_params(linphone_core_get_current_call(caller_mgr->lc))) == LinphonePrivacyNone) {
249 250 251
			/*don't check in case of p asserted id*/
			if (!lp_config_get_int(callee_mgr->lc->config,"sip","call_logs_use_asserted_id_instead_of_from",0))
				CU_ASSERT_TRUE(linphone_address_weak_equal(callee_from,linphone_core_get_current_call_remote_address(callee_mgr->lc)));
jehan's avatar
jehan committed
252 253 254 255
		} else {
			CU_ASSERT_FALSE(linphone_address_weak_equal(callee_from,linphone_core_get_current_call_remote_address(callee_mgr->lc)));
		}
		linphone_address_destroy(callee_from);
jehan's avatar
jehan committed
256
	}
257
	if (callee_params){
258
		linphone_core_accept_call_with_params(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc),callee_params);
259 260 261 262 263 264
	}else if (build_callee_params){
		LinphoneCallParams *default_params=linphone_core_create_call_params(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc));
		ms_error("Created default call params with video=%i", linphone_call_params_video_enabled(default_params));
		linphone_core_accept_call_with_params(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc),default_params);
		linphone_call_params_destroy(default_params);
	}else{
265
		linphone_core_accept_call(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc));
266
	}
jehan's avatar
jehan committed
267

jehan's avatar
jehan committed
268 269
	CU_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallConnected,initial_callee.number_of_LinphoneCallConnected+1));
	CU_ASSERT_TRUE(wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallConnected,initial_callee.number_of_LinphoneCallConnected+1));
jehan's avatar
jehan committed
270
	/*just to sleep*/
jehan's avatar
jehan committed
271
	result = wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_caller.number_of_LinphoneCallStreamsRunning+1)
jehan's avatar
jehan committed
272
			&&
jehan's avatar
jehan committed
273
			wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_callee.number_of_LinphoneCallStreamsRunning+1);
jehan's avatar
jehan committed
274

jehan's avatar
jehan committed
275 276
	if (linphone_core_get_media_encryption(caller_mgr->lc) != LinphoneMediaEncryptionNone
		&& linphone_core_get_media_encryption(callee_mgr->lc) != LinphoneMediaEncryptionNone) {
johan's avatar
johan committed
277 278
		/*wait for encryption to be on, in case of zrtp or dtls, it can take a few seconds*/
		if ((linphone_core_get_media_encryption(caller_mgr->lc) == LinphoneMediaEncryptionZRTP) || (linphone_core_get_media_encryption(caller_mgr->lc) == LinphoneMediaEncryptionDTLS))
jehan's avatar
jehan committed
279
			wait_for(callee_mgr->lc,caller_mgr->lc,&caller_mgr->stat.number_of_LinphoneCallEncryptedOn,initial_caller.number_of_LinphoneCallEncryptedOn+1);
johan's avatar
johan committed
280
		if ((linphone_core_get_media_encryption(callee_mgr->lc) == LinphoneMediaEncryptionZRTP) || (linphone_core_get_media_encryption(callee_mgr->lc) == LinphoneMediaEncryptionDTLS))
jehan's avatar
jehan committed
281 282
			wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallEncryptedOn,initial_callee.number_of_LinphoneCallEncryptedOn+1);
		{
Simon Morlat's avatar
Simon Morlat committed
283 284 285 286
			const LinphoneCallParams* call_param = linphone_call_get_current_params(linphone_core_get_current_call(callee_mgr->lc));
			CU_ASSERT_EQUAL(linphone_call_params_get_media_encryption(call_param),linphone_core_get_media_encryption(caller_mgr->lc));
			call_param = linphone_call_get_current_params(linphone_core_get_current_call(caller_mgr->lc));
			CU_ASSERT_EQUAL(linphone_call_params_get_media_encryption(call_param),linphone_core_get_media_encryption(callee_mgr->lc));
jehan's avatar
jehan committed
287
		}
jehan's avatar
jehan committed
288 289
	}
	return result;
jehan's avatar
jehan committed
290
}
291 292 293

bool_t call_with_params(LinphoneCoreManager* caller_mgr
						,LinphoneCoreManager* callee_mgr
294 295 296 297 298 299 300 301 302 303 304 305 306
						,const LinphoneCallParams *caller_params
						,const LinphoneCallParams *callee_params){
	LinphoneCallTestParams caller_test_params = {0}, callee_test_params =  {0};
	caller_test_params.base = (LinphoneCallParams*)caller_params;
	callee_test_params.base = (LinphoneCallParams*)caller_params;
	return call_with_params2(caller_mgr,callee_mgr,&caller_test_params,&callee_test_params,FALSE);
}

bool_t call_with_test_params(LinphoneCoreManager* caller_mgr
				,LinphoneCoreManager* callee_mgr
				,const LinphoneCallTestParams *caller_test_params
				,const LinphoneCallTestParams *callee_test_params){
	return call_with_params2(caller_mgr,callee_mgr,caller_test_params,callee_test_params,FALSE);
307 308
}

309 310 311
bool_t call_with_caller_params(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr, const LinphoneCallParams *params) {
	return call_with_params(caller_mgr,callee_mgr,params,NULL);
}
312

Simon Morlat's avatar
Simon Morlat committed
313
bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr){
314
	return call_with_params(caller_mgr,callee_mgr,NULL,NULL);
Simon Morlat's avatar
Simon Morlat committed
315 316
}

317
void end_call(LinphoneCoreManager *m1, LinphoneCoreManager *m2){
Simon Morlat's avatar
Simon Morlat committed
318 319 320
	linphone_core_terminate_all_calls(m1->lc);
	CU_ASSERT_TRUE(wait_for(m1->lc,m2->lc,&m1->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for(m1->lc,m2->lc,&m2->stat.number_of_LinphoneCallEnd,1));
321 322
	CU_ASSERT_TRUE(wait_for(m1->lc,m2->lc,&m1->stat.number_of_LinphoneCallReleased,1));
	CU_ASSERT_TRUE(wait_for(m1->lc,m2->lc,&m2->stat.number_of_LinphoneCallReleased,1));
Simon Morlat's avatar
Simon Morlat committed
323 324
}

jehan's avatar
jehan committed
325
void simple_call_base(bool_t enable_multicast_recv_side) {
326
	int begin;
Simon Morlat's avatar
Simon Morlat committed
327
	int leaked_objects;
328 329
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
330 331
	const LinphoneAddress *from;
	LinphoneCall *pauline_call;
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
332 333
	LinphoneProxyConfig* marie_cfg;
	const char* marie_id = NULL;
334 335 336 337 338 339

	belle_sip_object_enable_leak_detector(TRUE);
	begin=belle_sip_object_get_object_count();

	marie = linphone_core_manager_new( "marie_rc");
	pauline = linphone_core_manager_new( "pauline_rc");
Gautier Pelloux-Prayer's avatar
Gautier Pelloux-Prayer committed
340

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
	/* with the account manager, we might lose the identity */
	marie_cfg = linphone_core_get_default_proxy_config(marie->lc);
	marie_id = linphone_proxy_config_get_identity(marie_cfg);
	{
		LinphoneAddress* marie_addr = linphone_address_new(marie_id);
		char* marie_tmp_id = NULL;
		linphone_address_set_display_name(marie_addr, "Super Marie");
		marie_tmp_id = linphone_address_as_string(marie_addr);

		linphone_proxy_config_edit(marie_cfg);
		linphone_proxy_config_set_identity(marie_cfg,marie_tmp_id);
		linphone_proxy_config_done(marie_cfg);

		ms_free(marie_tmp_id);
		linphone_address_unref(marie_addr);
	}

jehan's avatar
jehan committed
358 359
	linphone_core_enable_audio_multicast(pauline->lc,enable_multicast_recv_side);

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	CU_ASSERT_TRUE(call(marie,pauline));
	pauline_call=linphone_core_get_current_call(pauline->lc);
	CU_ASSERT_PTR_NOT_NULL(pauline_call);
	/*check that display name is correctly propagated in From */
	if (pauline_call){
		from=linphone_call_get_remote_address(linphone_core_get_current_call(pauline->lc));
		CU_ASSERT_PTR_NOT_NULL(from);
		if (from){
			const char *dname=linphone_address_get_display_name(from);
			CU_ASSERT_PTR_NOT_NULL(dname);
			if (dname){
				CU_ASSERT_STRING_EQUAL(dname, "Super Marie");
			}
		}
	}
375 376


377 378 379 380
	liblinphone_tester_check_rtcp(marie,pauline);
	end_call(marie,pauline);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
Simon Morlat's avatar
Simon Morlat committed
381 382 383 384 385 386

	leaked_objects=belle_sip_object_get_object_count()-begin;
	CU_ASSERT_TRUE(leaked_objects==0);
	if (leaked_objects>0){
		belle_sip_object_dump_active_objects();
	}
jehan's avatar
jehan committed
387
}
jehan's avatar
jehan committed
388 389 390
static void simple_call() {
	simple_call_base(FALSE);
}
jehan's avatar
jehan committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
static void call_with_timeouted_bye(void) {
	int begin;
	int leaked_objects;
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;
	belle_sip_timer_config_t timer_config;
	belle_sip_object_enable_leak_detector(TRUE);
	begin=belle_sip_object_get_object_count();

	marie = linphone_core_manager_new( "marie_rc");
	pauline = linphone_core_manager_new( "pauline_rc");

	CU_ASSERT_TRUE(call(marie,pauline));

	sal_set_send_error(pauline->lc->sal,1500); /*to trash the message without generating error*/
	timer_config.T1=50; /*to have timer F = 3s*/
	timer_config.T2=4000;
	timer_config.T3=0;
	timer_config.T4=5000;

	belle_sip_stack_set_timer_config(sal_get_belle_sip_stack(pauline->lc->sal),&timer_config);
	linphone_core_terminate_all_calls(pauline->lc);

	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1,timer_config.T1*84));

	sal_set_send_error(pauline->lc->sal,0);

	linphone_core_terminate_all_calls(marie->lc);
	CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1,5000));
	CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallReleased,1,5000));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);

	leaked_objects=belle_sip_object_get_object_count()-begin;
	CU_ASSERT_TRUE(leaked_objects==0);
	if (leaked_objects>0){
		belle_sip_object_dump_active_objects();
	}
}


Simon Morlat's avatar
Simon Morlat committed
434 435 436 437 438
static void direct_call_over_ipv6(){
	LinphoneCoreManager* marie;
	LinphoneCoreManager* pauline;

	if (liblinphone_tester_ipv6_available()){
jehan's avatar
jehan committed
439 440
		LCSipTransports pauline_transports;
		LinphoneAddress* pauline_dest = linphone_address_new("sip:[::1];transport=tcp");
Simon Morlat's avatar
Simon Morlat committed
441 442
		marie = linphone_core_manager_new( "marie_rc");
		pauline = linphone_core_manager_new( "pauline_tcp_rc");
jehan's avatar
jehan committed
443

Simon Morlat's avatar
Simon Morlat committed
444 445 446
		linphone_core_enable_ipv6(marie->lc,TRUE);
		linphone_core_enable_ipv6(pauline->lc,TRUE);
		linphone_core_set_default_proxy_config(marie->lc,NULL);
447 448
		/*wait for register in v6 mode, however sip2.linphone.org has an ipv6 address but doesn't listen to it*/
#if 0
jehan's avatar
jehan committed
449 450
		CU_ASSERT_TRUE(wait_for_until(pauline->lc, NULL, &pauline->stat.number_of_LinphoneRegistrationOk, 2, 2000));
		CU_ASSERT_TRUE(wait_for_until(pauline->lc, NULL, &marie->stat.number_of_LinphoneRegistrationOk, 2, 2000));
451
#endif
452

jehan's avatar
jehan committed
453 454 455
		linphone_core_get_sip_transports_used(pauline->lc,&pauline_transports);
		linphone_address_set_port(pauline_dest,pauline_transports.tcp_port);
		linphone_core_invite_address(marie->lc,pauline_dest);
456

Simon Morlat's avatar
Simon Morlat committed
457 458 459 460 461
		CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneCallOutgoingRinging,1));
		CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_LinphoneCallIncomingReceived,1));
		linphone_core_accept_call(pauline->lc,linphone_core_get_current_call(pauline->lc));
		CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,1));
		CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,1));
462

Simon Morlat's avatar
Simon Morlat committed
463 464 465 466
		liblinphone_tester_check_rtcp(marie,pauline);
		end_call(marie,pauline);
		linphone_core_manager_destroy(marie);
		linphone_core_manager_destroy(pauline);
jehan's avatar
jehan committed
467
		linphone_address_destroy(pauline_dest);
Simon Morlat's avatar
Simon Morlat committed
468 469 470
	}else ms_warning("Test skipped, no ipv6 available");
}

471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
static void call_outbound_with_multiple_proxy() {
	LinphoneCoreManager* pauline = linphone_core_manager_new2( "pauline_rc", FALSE);
	LinphoneCoreManager* marie   = linphone_core_manager_new2( "marie_rc", FALSE);

	LinphoneProxyConfig* lpc = NULL;
	LinphoneProxyConfig* registered_lpc = linphone_proxy_config_new();

	linphone_core_get_default_proxy(marie->lc, &lpc);
	linphone_core_set_default_proxy(marie->lc,NULL);

	CU_ASSERT_FATAL(lpc != NULL);
	CU_ASSERT_FATAL(registered_lpc != NULL);

	// create new LPC that will successfully register
	linphone_proxy_config_set_identity(registered_lpc, linphone_proxy_config_get_identity(lpc));
	linphone_proxy_config_set_server_addr(registered_lpc, linphone_proxy_config_get_addr(lpc));
	linphone_proxy_config_set_route(registered_lpc, linphone_proxy_config_get_route(lpc));
	linphone_proxy_config_enable_register(registered_lpc, TRUE);

	linphone_core_add_proxy_config(marie->lc, registered_lpc);

	// set first LPC to unreacheable proxy addr
	linphone_proxy_config_edit(lpc);
	linphone_proxy_config_set_server_addr(lpc,"12.13.14.15:5223;transport=udp");
	linphone_proxy_config_set_route(lpc, "12.13.14.15:5223;transport=udp;lr");
	linphone_proxy_config_done(lpc);

	CU_ASSERT_TRUE(wait_for_until(pauline->lc, NULL, &pauline->stat.number_of_LinphoneRegistrationOk, 1, 2000));

	CU_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneRegistrationProgress, 2, 200));
	CU_ASSERT_TRUE(wait_for_until(marie->lc, NULL, &marie->stat.number_of_LinphoneRegistrationOk, 1, 2000));

	// calling marie should go through the second proxy config
	CU_ASSERT_TRUE(call(marie, pauline));

506 507
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
508 509
}

510
#if 0 /* TODO: activate test when the implementation is ready */
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
511 512
static void multiple_answers_call() {
	/* Scenario is this: pauline calls marie, which is registered 2 times.
513
	   Both linphones answer at the same time, and only one should get the
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
514 515 516 517
	   call running, the other should be terminated */
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc" );
	LinphoneCoreManager* marie1  = linphone_core_manager_new( "marie_rc" );
	LinphoneCoreManager* marie2  = linphone_core_manager_new( "marie_rc" );
518

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
519
	LinphoneCall* call1, *call2;
520

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
521 522 523
	MSList* lcs = ms_list_append(NULL,pauline->lc);
	lcs = ms_list_append(lcs,marie1->lc);
	lcs = ms_list_append(lcs,marie2->lc);
524 525


526
	CU_ASSERT_TRUE(wait_for_until(pauline->lc, NULL, &pauline->stat.number_of_LinphoneRegistrationOk, 1, 2000));
527

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
528 529
	CU_ASSERT_PTR_NOT_NULL( linphone_core_invite_address(pauline->lc, marie1->identity ) );

530 531 532
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie1->stat.number_of_LinphoneCallIncomingReceived, 1, 2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived, 1, 2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingProgress, 1, 2000));
533

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
534 535 536
	// marie 1 and 2 answer at the same time
	call1 = linphone_core_get_current_call(marie1->lc);
	call2 = linphone_core_get_current_call(marie2->lc);
537

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
538 539
	CU_ASSERT_PTR_NOT_NULL_FATAL(call1);
	CU_ASSERT_PTR_NOT_NULL_FATAL(call2);
540

Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
541 542
	CU_ASSERT_EQUAL( linphone_core_accept_call(marie1->lc, call1), 0);
	CU_ASSERT_EQUAL( linphone_core_accept_call(marie2->lc, call2), 0);
543

544 545 546
	CU_ASSERT_TRUE( wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1, 2000) );
	CU_ASSERT_TRUE( wait_for_list(lcs, &marie1->stat.number_of_LinphoneCallStreamsRunning, 1, 2000) );
	CU_ASSERT_TRUE( wait_for_list(lcs, &marie2->stat.number_of_LinphoneCallEnd, 1, 2000) );
547 548


Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
549 550 551
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie1);
	linphone_core_manager_destroy(marie2);
552 553 554 555
}
#endif

static void multiple_answers_call_with_media_relay() {
556

557
	/* Scenario is this: pauline calls marie, which is registered 2 times.
558
	 *   Both linphones answer at the same time, and only one should get the
559 560 561 562
	 *   call running, the other should be terminated */
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc" );
	LinphoneCoreManager* marie1  = linphone_core_manager_new( "marie_rc" );
	LinphoneCoreManager* marie2  = linphone_core_manager_new( "marie_rc" );
563

564
	LinphoneCall* call1, *call2;
565

566 567 568
	MSList* lcs = ms_list_append(NULL,pauline->lc);
	lcs = ms_list_append(lcs,marie1->lc);
	lcs = ms_list_append(lcs,marie2->lc);
569

570 571 572
	linphone_core_set_user_agent(pauline->lc, "Natted Linphone", NULL);
	linphone_core_set_user_agent(marie1->lc, "Natted Linphone", NULL);
	linphone_core_set_user_agent(marie2->lc, "Natted Linphone", NULL);
573

574
	CU_ASSERT_TRUE(wait_for_until(pauline->lc, NULL, &pauline->stat.number_of_LinphoneRegistrationOk, 1, 2000));
575

576
	CU_ASSERT_PTR_NOT_NULL( linphone_core_invite_address(pauline->lc, marie1->identity ) );
577

578 579 580
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie1->stat.number_of_LinphoneCallIncomingReceived, 1, 2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived, 1, 2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingProgress, 1, 2000));
581

582 583 584
	// marie 1 and 2 answer at the same time
	call1 = linphone_core_get_current_call(marie1->lc);
	call2 = linphone_core_get_current_call(marie2->lc);
585

586 587
	CU_ASSERT_PTR_NOT_NULL_FATAL(call1);
	CU_ASSERT_PTR_NOT_NULL_FATAL(call2);
588

589 590
	CU_ASSERT_EQUAL( linphone_core_accept_call(marie1->lc, call1), 0);
	CU_ASSERT_EQUAL( linphone_core_accept_call(marie2->lc, call2), 0);
591

592 593 594
	CU_ASSERT_TRUE( wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallStreamsRunning, 1, 2000) );
	CU_ASSERT_TRUE( wait_for_list(lcs, &marie1->stat.number_of_LinphoneCallStreamsRunning, 1, 2000) );
	CU_ASSERT_TRUE( wait_for_list(lcs, &marie2->stat.number_of_LinphoneCallEnd, 1, 2000) );
595 596


597 598 599
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(marie1);
	linphone_core_manager_destroy(marie2);
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
600 601
}

602 603 604 605 606
static void call_with_specified_codec_bitrate(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	const LinphoneCallStats *pauline_stats,*marie_stats;
	bool_t call_ok;
607 608
	char * codec = "opus";
	int rate = 48000;
609 610 611
	int min_bw=24;
	int max_bw=40;

612 613
#ifdef __arm__
	if (ms_get_cpu_count() <2) { /*2 opus codec channel + resampler is too much for a single core*/
614
#ifndef ANDROID
615
		codec = "speex";
616 617 618
		rate = 8000;
		min_bw=20;
		max_bw=35;
619 620 621 622
#else
		CU_PASS("Test requires at least a dual core");
		goto end;
#endif
623 624 625 626
	}
#endif

	if (linphone_core_find_payload_type(marie->lc,codec,rate,-1)==NULL){
627 628 629
		ms_warning("opus codec not supported, test skipped.");
		goto end;
	}
630

631 632
	disable_all_audio_codecs_except_one(marie->lc,codec,rate);
	disable_all_audio_codecs_except_one(pauline->lc,codec,rate);
633

634
	linphone_core_set_payload_type_bitrate(marie->lc,
635
		linphone_core_find_payload_type(marie->lc,codec,rate,-1),
636
		max_bw);
637
	linphone_core_set_payload_type_bitrate(pauline->lc,
638
		linphone_core_find_payload_type(pauline->lc,codec,rate,-1),
639
		min_bw);
640

641 642 643 644 645
	CU_ASSERT_TRUE((call_ok=call(pauline,marie)));
	if (!call_ok) goto end;
	liblinphone_tester_check_rtcp(marie,pauline);
	marie_stats=linphone_call_get_audio_stats(linphone_core_get_current_call(marie->lc));
	pauline_stats=linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc));
646 647
	CU_ASSERT_TRUE(marie_stats->download_bandwidth<(min_bw+5+min_bw*.1));
	CU_ASSERT_TRUE(pauline_stats->download_bandwidth>(max_bw-5-max_bw*.1));
648 649 650 651 652 653

end:
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

654
static void simple_call_compatibility_mode(void) {
655
	char route[256];
Simon Morlat's avatar
Simon Morlat committed
656 657
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677

	LinphoneCore* lc_marie=marie->lc;
	LinphoneCore* lc_pauline=pauline->lc;
	stats* stat_marie=&marie->stat;
	stats* stat_pauline=&pauline->stat;
	LinphoneProxyConfig* proxy;
	LinphoneAddress* identity;
	LinphoneAddress* proxy_address;
	char*tmp;
	LCSipTransports transport;

	linphone_core_get_default_proxy(lc_marie,&proxy);
	CU_ASSERT_PTR_NOT_NULL (proxy);
	identity = linphone_address_new(linphone_proxy_config_get_identity(proxy));


	proxy_address=linphone_address_new(linphone_proxy_config_get_addr(proxy));
	linphone_address_clean(proxy_address);
	tmp=linphone_address_as_string_uri_only(proxy_address);
	linphone_proxy_config_set_server_addr(proxy,tmp);
678 679
	sprintf(route,"sip:%s",test_route);
	linphone_proxy_config_set_route(proxy,route);
680 681 682 683 684 685 686 687 688 689 690 691
	ms_free(tmp);
	linphone_address_destroy(proxy_address);
	linphone_core_get_sip_transports(lc_marie,&transport);
	transport.udp_port=0;
	transport.tls_port=0;
	transport.dtls_port=0;
	/*only keep tcp*/
	linphone_core_set_sip_transports(lc_marie,&transport);
	stat_marie->number_of_LinphoneRegistrationOk=0;

	CU_ASSERT_TRUE (wait_for(lc_marie,lc_marie,&stat_marie->number_of_LinphoneRegistrationOk,1));

692
	linphone_core_invite_address(lc_marie,pauline->identity);
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719

	CU_ASSERT_TRUE (wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallIncomingReceived,1));
	CU_ASSERT_TRUE(linphone_core_inc_invite_pending(lc_pauline));
	CU_ASSERT_EQUAL(stat_marie->number_of_LinphoneCallOutgoingProgress,1);
	CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallOutgoingRinging,1));

	CU_ASSERT_PTR_NOT_NULL(linphone_core_get_current_call_remote_address(lc_pauline));
	if (linphone_core_get_current_call_remote_address(lc_pauline)) {
		CU_ASSERT_TRUE(linphone_address_weak_equal(identity,linphone_core_get_current_call_remote_address(lc_pauline)));
		linphone_address_destroy(identity);

		linphone_core_accept_call(lc_pauline,linphone_core_get_current_call(lc_pauline));

		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallConnected,1));
		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallConnected,1));
		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallStreamsRunning,1));
		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallStreamsRunning,1));
		/*just to sleep*/
		wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallStreamsRunning,3);
		linphone_core_terminate_all_calls(lc_pauline);
		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_pauline->number_of_LinphoneCallEnd,1));
		CU_ASSERT_TRUE(wait_for(lc_pauline,lc_marie,&stat_marie->number_of_LinphoneCallEnd,1));
	}
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
720 721

static void cancelled_call(void) {
Simon Morlat's avatar
Simon Morlat committed
722 723
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
724

725
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
jehan's avatar
jehan committed
726
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
727
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));
jehan's avatar
jehan committed
728 729

	linphone_core_terminate_call(pauline->lc,out_call);
jehan's avatar
jehan committed
730
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
731
	//CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonCanceled);
jehan's avatar
jehan committed
732
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);
jehan's avatar
jehan committed
733
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingReceived,0);
734 735
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));

jehan's avatar
jehan committed
736 737 738 739
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
jehan's avatar
jehan committed
740

741
void disable_all_audio_codecs_except_one(LinphoneCore *lc, const char *mime, int rate){
742 743
	const MSList *elem=linphone_core_get_audio_codecs(lc);
	PayloadType *pt;
744

745 746 747 748
	for(;elem!=NULL;elem=elem->next){
		pt=(PayloadType*)elem->data;
		linphone_core_enable_payload_type(lc,pt,FALSE);
	}
749
	pt=linphone_core_find_payload_type(lc,mime,rate,-1);
750 751 752 753
	CU_ASSERT_PTR_NOT_NULL_FATAL(pt);
	linphone_core_enable_payload_type(lc,pt,TRUE);
}

754
#ifdef VIDEO_ENABLED
755
void disable_all_video_codecs_except_one(LinphoneCore *lc, const char *mime) {
756 757 758 759 760 761 762 763 764 765
	const MSList *codecs = linphone_core_get_video_codecs(lc);
	const MSList *it = NULL;
	PayloadType *pt = NULL;

	for(it = codecs; it != NULL; it = it->next) {
		linphone_core_enable_payload_type(lc, (PayloadType *)it->data, FALSE);
	}
	CU_ASSERT_PTR_NOT_NULL_FATAL(pt = linphone_core_find_payload_type(lc, mime, -1, -1));
	linphone_core_enable_payload_type(lc, pt, TRUE);
}
766
#endif
767

Ghislain MARY's avatar
Ghislain MARY committed
768
static void call_with_dns_time_out(void) {
Simon Morlat's avatar
Simon Morlat committed
769
	LinphoneCoreManager* marie = linphone_core_manager_new2( "empty_rc", FALSE);
jehan's avatar
jehan committed
770
	LCSipTransports transport = {9773,0,0,0};
Simon Morlat's avatar
Simon Morlat committed
771
	int i;
772

jehan's avatar
jehan committed
773 774 775
	linphone_core_set_sip_transports(marie->lc,&transport);
	linphone_core_iterate(marie->lc);
	sal_set_dns_timeout(marie->lc->sal,0);
776
	linphone_core_invite(marie->lc,"\"t\x8et\x8e\" <sip:toto@toto.com>"); /*just to use non ascii values*/
Simon Morlat's avatar
Simon Morlat committed
777 778 779
	for(i=0;i<10;i++){
		ms_usleep(200000);
		linphone_core_iterate(marie->lc);
780
	}
jehan's avatar
jehan committed
781 782 783
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallOutgoingInit,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallOutgoingProgress,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallError,1);
784
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallReleased,1);
jehan's avatar
jehan committed
785 786 787
	linphone_core_manager_destroy(marie);
}

788 789
static void early_cancelled_call(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
790
	LinphoneCoreManager* pauline = linphone_core_manager_new2( "empty_rc",FALSE);
791

792
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
793

794 795
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));
	linphone_core_terminate_call(pauline->lc,out_call);
796

797 798
	/*since everything is executed in a row, no response can be received from the server, thus the CANCEL cannot be sent.
	 It will ring at Marie's side.*/
799

800
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
801

802
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);
803

804 805 806
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
	/* now the CANCEL should have been sent and the the call at marie's side should terminate*/
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
807

808 809 810 811 812 813
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
814
static void cancelled_ringing_call(void) {
Simon Morlat's avatar
Simon Morlat committed
815 816
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
817

818
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
jehan's avatar
jehan committed
819
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
820
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
jehan's avatar
jehan committed
821 822

	linphone_core_terminate_call(pauline->lc,out_call);
823 824 825 826 827
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallReleased,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallEnd,1);
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);

jehan's avatar
jehan committed
828 829 830 831 832
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
833
static void early_declined_call(void) {
Simon Morlat's avatar
Simon Morlat committed
834 835
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
836
	LinphoneCallLog* out_call_log;
837 838 839
	LinphoneCall* out_call;

	linphone_core_set_max_calls(marie->lc,0);
840
	out_call = linphone_core_invite_address(pauline->lc,marie->identity);
jehan's avatar
jehan committed
841 842
	linphone_call_ref(out_call);

843 844
	/*wait until flexisip transfers the busy...*/
	CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallError,1,33000));
jehan's avatar
jehan committed
845
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallError,1);
846
	/* FIXME http://git.linphone.org/mantis/view.php?id=757
847

848
	CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonBusy);
849
	 */
850 851 852
	if (ms_list_size(linphone_core_get_call_logs(pauline->lc))>0) {
		CU_ASSERT_PTR_NOT_NULL(out_call_log=(LinphoneCallLog*)(linphone_core_get_call_logs(pauline->lc)->data));
		CU_ASSERT_EQUAL(linphone_call_log_get_status(out_call_log),LinphoneCallAborted);
jehan's avatar
jehan committed
853 854 855 856 857 858 859
	}
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

static void call_declined(void) {
Simon Morlat's avatar
Simon Morlat committed
860 861
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
862

863
	LinphoneCall* in_call;
864
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
jehan's avatar
jehan committed
865
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
866
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1