call_tester.c 64.3 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  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 3 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/>.
*/
Ghislain MARY's avatar
Ghislain MARY committed
18

jehan's avatar
jehan committed
19 20 21
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
22
#include "lpconfig.h"
jehan's avatar
jehan committed
23 24
#include "private.h"
#include "liblinphone_tester.h"
jehan's avatar
jehan committed
25

jehan's avatar
jehan committed
26

jehan's avatar
jehan committed
27 28 29
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);
30
	stats* counters;
jehan's avatar
jehan committed
31 32 33 34
	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
35 36
	ms_free(to);
	ms_free(from);
37
	counters = get_stats(lc);
jehan's avatar
jehan committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	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;
	default:
		CU_FAIL("unexpected event");break;
	}
}
Ghislain MARY's avatar
Ghislain MARY committed
61

jehan's avatar
jehan committed
62 63 64
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);
65
	stats* counters;
jehan's avatar
jehan committed
66 67 68 69
	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);

70
	counters = get_stats(lc);
jehan's avatar
jehan committed
71
	switch (new_call_state) {
jehan's avatar
jehan committed
72
	case LinphoneCallOutgoingInit :counters->number_of_LinphoneTransferCallOutgoingInit++;break;
73 74 75 76 77
	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;
78
	case LinphoneCallError :counters->number_of_LinphoneTransferCallError++;break;
jehan's avatar
jehan committed
79 80 81 82
	default:
		CU_FAIL("unexpected event");break;
	}
}
Ghislain MARY's avatar
Ghislain MARY committed
83

84
#ifdef VIDEO_ENABLED
jehan's avatar
jehan committed
85 86 87
static void linphone_call_cb(LinphoneCall *call,void * user_data) {
	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);
88
	stats* counters;
jehan's avatar
jehan committed
89 90 91 92
	LinphoneCore* lc=(LinphoneCore*)user_data;
	ms_message("call from [%s] to [%s] receive iFrame",from,to);
	ms_free(to);
	ms_free(from);
93
	counters = (stats*)get_stats(lc);
jehan's avatar
jehan committed
94 95
	counters->number_of_IframeDecoded++;
}
96
#endif
Simon Morlat's avatar
Simon Morlat committed
97

98 99 100 101 102 103 104 105
static void check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee) {
	LinphoneCall *c1,*c2;
	int i;
	int dummy=0;

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

jehan's avatar
jehan committed
106
	for (i=0; i<24 /*=12s need at least one exchange of SR to maybe 10s*/; i++) {
107 108
		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
109 110
				&& (!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)) {
111
			break;
jehan's avatar
jehan committed
112

113
		}
jehan's avatar
jehan committed
114
		wait_for_until(caller->lc,callee->lc,&dummy,1,500); /*just to sleep while iterating*/
115 116 117 118 119 120 121 122 123 124 125 126 127

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

}

128 129 130 131
bool_t call_with_params(LinphoneCoreManager* caller_mgr
						,LinphoneCoreManager* callee_mgr
						, const LinphoneCallParams *caller_params
						, const LinphoneCallParams *callee_params) {
jehan's avatar
jehan committed
132
	int retry=0;
jehan's avatar
jehan committed
133 134
	stats initial_caller=caller_mgr->stat;
	stats initial_callee=callee_mgr->stat;
jehan's avatar
jehan committed
135
	bool_t result=FALSE;
jehan's avatar
jehan committed
136 137 138 139 140
	char hellopath[256];
	/*use playfile for callee to avoid locking on capture card*/
	linphone_core_use_files (callee_mgr->lc,TRUE);
	snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", liblinphone_tester_file_prefix);
	linphone_core_set_play_file(callee_mgr->lc,hellopath);
141
	if (!caller_params){
Simon Morlat's avatar
Simon Morlat committed
142 143
		CU_ASSERT_PTR_NOT_NULL(linphone_core_invite_address(caller_mgr->lc,callee_mgr->identity));
	}else{
144
		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
145
	}
jehan's avatar
jehan committed
146 147 148

	/*linphone_core_invite(caller_mgr->lc,"pauline");*/

jehan's avatar
jehan committed
149
	CU_ASSERT_TRUE(wait_for(callee_mgr->lc
jehan's avatar
jehan committed
150 151 152
									,caller_mgr->lc
									,&callee_mgr->stat.number_of_LinphoneCallIncomingReceived
									,initial_callee.number_of_LinphoneCallIncomingReceived+1));
jehan's avatar
jehan committed
153
	CU_ASSERT_TRUE(linphone_core_inc_invite_pending(callee_mgr->lc));
jehan's avatar
jehan committed
154 155
	CU_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,initial_caller.number_of_LinphoneCallOutgoingProgress+1);

jehan's avatar
jehan committed
156

jehan's avatar
jehan committed
157 158 159
	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
160 161 162 163 164 165
			linphone_core_iterate(caller_mgr->lc);
			linphone_core_iterate(callee_mgr->lc);
			ms_usleep(100000);
	}


jehan's avatar
jehan committed
166
	CU_ASSERT_TRUE((caller_mgr->stat.number_of_LinphoneCallOutgoingRinging==initial_caller.number_of_LinphoneCallOutgoingRinging+1)
jehan's avatar
jehan committed
167
							|(caller_mgr->stat.number_of_LinphoneCallOutgoingEarlyMedia==initial_caller.number_of_LinphoneCallOutgoingEarlyMedia+1));
jehan's avatar
jehan committed
168

jehan's avatar
jehan committed
169

jehan's avatar
jehan committed
170 171 172
	CU_ASSERT_PTR_NOT_NULL(linphone_core_get_current_call_remote_address(callee_mgr->lc));
	if (!linphone_core_get_current_call_remote_address(callee_mgr->lc))
		return 0;
jehan's avatar
jehan committed
173 174 175 176 177 178 179 180 181
	else {
		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*/
		if (linphone_call_params_get_privacy(linphone_call_get_current_params(linphone_core_get_current_call(caller_mgr->lc))) == LinphonePrivacyNone) {
			CU_ASSERT_TRUE(linphone_address_weak_equal(callee_from,linphone_core_get_current_call_remote_address(callee_mgr->lc)));
		} 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
182
	}
183 184 185 186
	if (callee_params)
		linphone_core_accept_call_with_params(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc),callee_params);
	else
		linphone_core_accept_call(callee_mgr->lc,linphone_core_get_current_call(callee_mgr->lc));
jehan's avatar
jehan committed
187

jehan's avatar
jehan committed
188 189
	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
190
	/*just to sleep*/
jehan's avatar
jehan committed
191
	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
192
			&&
jehan's avatar
jehan committed
193
			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
194

jehan's avatar
jehan committed
195 196 197 198 199 200 201 202
	if (linphone_core_get_media_encryption(caller_mgr->lc)
		&& linphone_core_get_media_encryption(callee_mgr->lc)) {
		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(caller_mgr->lc));
	}
	return result;
jehan's avatar
jehan committed
203
}
204 205 206
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);
}
207

Simon Morlat's avatar
Simon Morlat committed
208
bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr){
209
	return call_with_params(caller_mgr,callee_mgr,NULL,NULL);
Simon Morlat's avatar
Simon Morlat committed
210 211
}

Ghislain MARY's avatar
Ghislain MARY committed
212
static void simple_call(void) {
Simon Morlat's avatar
Simon Morlat committed
213 214
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
215

216 217
	CU_ASSERT_TRUE(call(pauline,marie));
	check_rtcp(marie,pauline);
218

jehan's avatar
jehan committed
219 220 221
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
Simon Morlat's avatar
Simon Morlat committed
222

223
static void simple_call_compatibility_mode(void) {
224
	char route[256];
Simon Morlat's avatar
Simon Morlat committed
225 226
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

	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);
247 248
	sprintf(route,"sip:%s",test_route);
	linphone_proxy_config_set_route(proxy,route);
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
	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));

	linphone_core_invite(lc_marie,"pauline");

	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
289 290

static void cancelled_call(void) {
Simon Morlat's avatar
Simon Morlat committed
291 292
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
293 294 295

	LinphoneCall* out_call = linphone_core_invite(pauline->lc,"marie");
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
296
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));
jehan's avatar
jehan committed
297 298

	linphone_core_terminate_call(pauline->lc,out_call);
jehan's avatar
jehan committed
299
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
300
	//CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonCanceled);
jehan's avatar
jehan committed
301
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);
jehan's avatar
jehan committed
302
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingReceived,0);
303 304
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallReleased,1));

jehan's avatar
jehan committed
305 306 307 308
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
jehan's avatar
jehan committed
309

310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
static void disable_all_codecs_except_one(LinphoneCore *lc, const char *mime){
	const MSList *elem=linphone_core_get_audio_codecs(lc);
	PayloadType *pt;
	
	for(;elem!=NULL;elem=elem->next){
		pt=(PayloadType*)elem->data;
		linphone_core_enable_payload_type(lc,pt,FALSE);
	}
	pt=linphone_core_find_payload_type(lc,mime,-1,-1);
	CU_ASSERT_PTR_NOT_NULL_FATAL(pt);
	linphone_core_enable_payload_type(lc,pt,TRUE);
}

static void call_failed_because_of_codecs(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	LinphoneCall* out_call;

	disable_all_codecs_except_one(marie->lc,"pcmu");
	disable_all_codecs_except_one(pauline->lc,"pcma");
	out_call = linphone_core_invite(pauline->lc,"marie");
	linphone_call_ref(out_call);
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));

	/*flexisip will retain the 415 until the "urgent reply" timeout arrives.*/
	CU_ASSERT_TRUE(wait_for_until(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallError,1,6000));
	CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonMedia);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingReceived,0);

	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
344
static void call_with_dns_time_out(void) {
Simon Morlat's avatar
Simon Morlat committed
345
	LinphoneCoreManager* marie = linphone_core_manager_new2( "empty_rc", FALSE);
jehan's avatar
jehan committed
346
	LCSipTransports transport = {9773,0,0,0};
Simon Morlat's avatar
Simon Morlat committed
347 348
	int i;
	
jehan's avatar
jehan committed
349 350 351 352
	linphone_core_set_sip_transports(marie->lc,&transport);
	linphone_core_iterate(marie->lc);
	sal_set_dns_timeout(marie->lc->sal,0);
	linphone_core_invite(marie->lc,"sip:toto@toto.com");
Simon Morlat's avatar
Simon Morlat committed
353 354 355 356
	for(i=0;i<10;i++){
		ms_usleep(200000);
		linphone_core_iterate(marie->lc);
	}	
jehan's avatar
jehan committed
357 358 359
	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);
360
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallReleased,1);
jehan's avatar
jehan committed
361 362 363
	linphone_core_manager_destroy(marie);
}

364 365
static void early_cancelled_call(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
366
	LinphoneCoreManager* pauline = linphone_core_manager_new2( "empty_rc",FALSE);
367

368
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
	
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallOutgoingInit,1));
	linphone_core_terminate_call(pauline->lc,out_call);
	
	/*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.*/
	
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallEnd,1);
	
	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));
	
	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
390
static void cancelled_ringing_call(void) {
Simon Morlat's avatar
Simon Morlat committed
391 392
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
393 394 395

	LinphoneCall* out_call = linphone_core_invite(pauline->lc,"marie");
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
396
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
jehan's avatar
jehan committed
397 398

	linphone_core_terminate_call(pauline->lc,out_call);
399 400 401 402 403
	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
404 405 406 407 408
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
409
static void early_declined_call(void) {
Simon Morlat's avatar
Simon Morlat committed
410 411
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
412
	LinphoneCallLog* out_call_log;
413 414 415 416
	LinphoneCall* out_call;

	linphone_core_set_max_calls(marie->lc,0);
	out_call = linphone_core_invite(pauline->lc,"marie");
jehan's avatar
jehan committed
417 418
	linphone_call_ref(out_call);

419 420
	/*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
421
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallError,1);
422
	/* FIXME http://git.linphone.org/mantis/view.php?id=757
423 424
	
	CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonBusy);
425
	 */
426 427 428
	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
429 430 431 432 433 434 435
	}
	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
436 437
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
438

439
	LinphoneCall* in_call;
440
	LinphoneCall* out_call = linphone_core_invite_address(pauline->lc,marie->identity);
jehan's avatar
jehan committed
441
	linphone_call_ref(out_call);
jehan's avatar
jehan committed
442
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallIncomingReceived,1));
jehan's avatar
jehan committed
443 444 445 446
	CU_ASSERT_PTR_NOT_NULL(in_call=linphone_core_get_current_call(marie->lc));
	if (in_call) {
		linphone_call_ref(in_call);
		linphone_core_terminate_call(marie->lc,in_call);
447 448 449 450
		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
451 452 453 454
		CU_ASSERT_EQUAL(linphone_call_get_reason(in_call),LinphoneReasonDeclined);
		CU_ASSERT_EQUAL(linphone_call_get_reason(out_call),LinphoneReasonDeclined);
		linphone_call_unref(in_call);
	}
jehan's avatar
jehan committed
455 456 457 458 459
	linphone_call_unref(out_call);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
460
static void call_terminated_by_caller(void) {
Simon Morlat's avatar
Simon Morlat committed
461 462
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
463 464 465 466 467 468 469 470 471 472
	
	CU_ASSERT_TRUE(call(pauline,marie));
	/*just to sleep*/
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
jehan's avatar
jehan committed
473

Simon Morlat's avatar
Simon Morlat committed
474
static void call_with_no_sdp(void) {
Simon Morlat's avatar
Simon Morlat committed
475 476
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_no_sdp_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
Simon Morlat's avatar
Simon Morlat committed
477 478 479 480 481 482 483 484 485 486 487
	
	CU_ASSERT_TRUE(call(marie,pauline));
	/*just to sleep*/
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

jehan's avatar
jehan committed
488
static bool_t check_ice(LinphoneCoreManager* caller, LinphoneCoreManager* callee, LinphoneIceState state) {
489 490
	LinphoneCall *c1,*c2;
	bool_t success=FALSE;
jehan's avatar
jehan committed
491 492 493 494
	int i;

	c1=linphone_core_get_current_call(caller->lc);
	c2=linphone_core_get_current_call(callee->lc);
495 496 497
	
	CU_ASSERT_PTR_NOT_NULL(c1);
	CU_ASSERT_PTR_NOT_NULL(c2);
jehan's avatar
jehan committed
498 499

	for (i=0;i<200;i++){
Ghislain MARY's avatar
Ghislain MARY committed
500 501 502 503 504 505 506 507
		if ((c1 != NULL) && (c2 != NULL)) {
			if (linphone_call_get_audio_stats(c1)->ice_state==LinphoneIceStateHostConnection &&
				linphone_call_get_audio_stats(c2)->ice_state==LinphoneIceStateHostConnection ){
				success=TRUE;
				break;
			}
			linphone_core_iterate(caller->lc);
			linphone_core_iterate(callee->lc);
508
		}
jehan's avatar
jehan committed
509
		ms_usleep(50000);
510
	}
jehan's avatar
jehan committed
511 512
	return success;
}
513

jehan's avatar
jehan committed
514
static void call_with_ice(void) {
Simon Morlat's avatar
Simon Morlat committed
515 516
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
517
	
jehan's avatar
jehan committed
518 519 520 521 522 523 524 525
	linphone_core_set_firewall_policy(marie->lc,LinphonePolicyUseIce);
	linphone_core_set_stun_server(marie->lc,"stun.linphone.org");
	linphone_core_set_firewall_policy(pauline->lc,LinphonePolicyUseIce);
	linphone_core_set_stun_server(pauline->lc,"stun.linphone.org");

	CU_ASSERT_TRUE(call(pauline,marie));

	CU_ASSERT_TRUE(check_ice(pauline,marie,LinphoneIceStateHostConnection));
526 527 528
	/*wait for the ICE reINVITE to complete*/
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2));
529
	
530 531 532
	check_rtcp(marie,pauline);


533
	/*then close the call*/
jehan's avatar
jehan committed
534
	linphone_core_terminate_all_calls(pauline->lc);
jehan's avatar
jehan committed
535 536
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
537 538 539 540 541

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Simon Morlat's avatar
Simon Morlat committed
542
static void call_with_custom_headers(void) {
Simon Morlat's avatar
Simon Morlat committed
543 544
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
Simon Morlat's avatar
Simon Morlat committed
545 546 547 548
	LinphoneCall *c1,*c2;
	LinphoneCallParams *params;
	const LinphoneCallParams *remote_params;
	const char *hvalue;
jehan's avatar
jehan committed
549 550 551 552 553 554 555
	char* tmp=linphone_address_as_string_uri_only(marie->identity);
	char tmp2[256];
	snprintf(tmp2,sizeof(tmp2),"%s?uriHeader=myUriHeader",tmp);
	LinphoneAddress* marie_identity=linphone_address_new(tmp2);
	ms_free(tmp);
	linphone_address_destroy(marie->identity);
	marie->identity=marie_identity;
Simon Morlat's avatar
Simon Morlat committed
556 557 558 559 560
	
	params=linphone_core_create_default_call_parameters(marie->lc);
	linphone_call_params_add_custom_header(params,"Weather","bad");
	linphone_call_params_add_custom_header(params,"Working","yes");
	
561
	CU_ASSERT_TRUE(call_with_caller_params(pauline,marie,params));
Simon Morlat's avatar
Simon Morlat committed
562 563 564 565 566 567 568 569 570 571 572
	linphone_call_params_destroy(params);
	
	c1=linphone_core_get_current_call(marie->lc);
	c2=linphone_core_get_current_call(pauline->lc);
	
	CU_ASSERT_PTR_NOT_NULL(c1);
	CU_ASSERT_PTR_NOT_NULL(c2);

	remote_params=linphone_call_get_remote_params(c1);
	hvalue=linphone_call_params_get_custom_header(remote_params,"Weather");
	CU_ASSERT_PTR_NOT_NULL(hvalue);
jehan's avatar
jehan committed
573 574 575 576 577
	CU_ASSERT_STRING_EQUAL(hvalue,"bad");
	hvalue=linphone_call_params_get_custom_header(remote_params,"uriHeader");
	CU_ASSERT_PTR_NOT_NULL(hvalue);
	CU_ASSERT_STRING_EQUAL(hvalue,"myUriHeader");

578 579
	CU_ASSERT_PTR_NOT_NULL(linphone_call_get_remote_contact(c1));
	
Simon Morlat's avatar
Simon Morlat committed
580 581 582 583 584 585 586 587 588
	/*just to sleep*/
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

Ghislain MARY's avatar
Ghislain MARY committed
589
static void call_paused_resumed(void) {
Simon Morlat's avatar
Simon Morlat committed
590 591
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
592 593 594 595 596 597
	LinphoneCall* call_obj;

	CU_ASSERT_TRUE(call(pauline,marie));
	call_obj = linphone_core_get_current_call(pauline->lc);

	linphone_core_pause_call(pauline->lc,call_obj);
jehan's avatar
jehan committed
598 599 600
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallPausing,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallPausedByRemote,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallPaused,1));
jehan's avatar
jehan committed
601 602 603 604 605 606 607

	linphone_core_resume_call(pauline->lc,call_obj);
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2));

	/*just to sleep*/
	linphone_core_terminate_all_calls(pauline->lc);
jehan's avatar
jehan committed
608 609
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
610 611 612 613 614

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

jehan's avatar
jehan committed
615 616 617 618 619 620 621 622 623 624 625
static bool_t pause_call_1(LinphoneCoreManager* mgr_1,LinphoneCall* call_1,LinphoneCoreManager* mgr_2,LinphoneCall* call_2) {
	stats initial_call_stat_1=mgr_1->stat;
	stats initial_call_stat_2=mgr_2->stat;
	linphone_core_pause_call(mgr_1->lc,call_1);
	CU_ASSERT_TRUE(wait_for(mgr_1->lc,mgr_2->lc,&mgr_1->stat.number_of_LinphoneCallPausing,initial_call_stat_1.number_of_LinphoneCallPausing+1));
	CU_ASSERT_TRUE(wait_for(mgr_1->lc,mgr_2->lc,&mgr_1->stat.number_of_LinphoneCallPaused,initial_call_stat_1.number_of_LinphoneCallPaused+1));
	CU_ASSERT_TRUE(wait_for(mgr_1->lc,mgr_2->lc,&mgr_2->stat.number_of_LinphoneCallPausedByRemote,initial_call_stat_2.number_of_LinphoneCallPausedByRemote+1));
	CU_ASSERT_EQUAL(linphone_call_get_state(call_1),LinphoneCallPaused);
	CU_ASSERT_EQUAL(linphone_call_get_state(call_2),LinphoneCallPausedByRemote);
	return linphone_call_get_state(call_1) == LinphoneCallPaused && linphone_call_get_state(call_2)==LinphoneCallPausedByRemote;
}
Ghislain MARY's avatar
Ghislain MARY committed
626 627

static void call_paused_resumed_from_callee(void) {
Simon Morlat's avatar
Simon Morlat committed
628 629
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
630 631 632 633 634 635
	LinphoneCall* call_obj;

	CU_ASSERT_TRUE(call(pauline,marie));
	call_obj = linphone_core_get_current_call(marie->lc);

	linphone_core_pause_call(marie->lc,call_obj);
jehan's avatar
jehan committed
636 637 638
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallPausing,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallPausedByRemote,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallPaused,1));
jehan's avatar
jehan committed
639 640 641 642 643 644 645

	linphone_core_resume_call(marie->lc,call_obj);
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2));

	/*just to sleep*/
	linphone_core_terminate_all_calls(pauline->lc);
jehan's avatar
jehan committed
646 647
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
648 649 650 651 652

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

653

654
#ifdef VIDEO_ENABLED
jehan's avatar
jehan committed
655 656 657
static bool_t add_video(LinphoneCoreManager* caller,LinphoneCoreManager* callee) {
	LinphoneVideoPolicy  caller_policy;
	LinphoneCallParams* callee_params;
jehan's avatar
jehan committed
658
	LinphoneCall* call_obj;
jehan's avatar
jehan committed
659 660
	caller_policy.automatically_accept=TRUE;
	caller_policy.automatically_initiate=TRUE;
661 662 663 664
	linphone_core_enable_video_capture(callee->lc, TRUE);
	linphone_core_enable_video_display(callee->lc, TRUE);
	linphone_core_enable_video_capture(caller->lc, TRUE);
	linphone_core_enable_video_display(caller->lc, FALSE);
jehan's avatar
jehan committed
665 666 667 668 669 670
	linphone_core_set_video_policy(caller->lc,&caller_policy);
	stats initial_caller_stat=caller->stat;
	stats initial_callee_stat=callee->stat;

	call_obj = linphone_core_get_current_call(callee->lc);
	callee_params = linphone_call_params_copy(linphone_call_get_current_params(call_obj));
jehan's avatar
jehan committed
671
	/*add video*/
jehan's avatar
jehan committed
672 673
	linphone_call_params_enable_video(callee_params,TRUE);
	linphone_core_update_call(callee->lc,call_obj,callee_params);
jehan's avatar
jehan committed
674

jehan's avatar
jehan committed
675 676 677 678
	CU_ASSERT_TRUE(wait_for(caller->lc,callee->lc,&caller->stat.number_of_LinphoneCallUpdatedByRemote,initial_caller_stat.number_of_LinphoneCallUpdatedByRemote+1));
	CU_ASSERT_TRUE(wait_for(caller->lc,callee->lc,&callee->stat.number_of_LinphoneCallUpdating,initial_callee_stat.number_of_LinphoneCallUpdating+1));
	CU_ASSERT_TRUE(wait_for(caller->lc,callee->lc,&callee->stat.number_of_LinphoneCallStreamsRunning,initial_callee_stat.number_of_LinphoneCallStreamsRunning+1));
	CU_ASSERT_TRUE(wait_for(caller->lc,callee->lc,&caller->stat.number_of_LinphoneCallStreamsRunning,initial_caller_stat.number_of_LinphoneCallStreamsRunning+1));
jehan's avatar
jehan committed
679

jehan's avatar
jehan committed
680 681
	CU_ASSERT_TRUE(linphone_call_params_video_enabled(linphone_call_get_current_params(linphone_core_get_current_call(callee->lc))));
	CU_ASSERT_TRUE(linphone_call_params_video_enabled(linphone_call_get_current_params(linphone_core_get_current_call(caller->lc))));
jehan's avatar
jehan committed
682

jehan's avatar
jehan committed
683
	linphone_call_set_next_video_frame_decoded_callback(call_obj,linphone_call_cb,callee->lc);
jehan's avatar
jehan committed
684 685
	/*send vfu*/
	linphone_call_send_vfu_request(call_obj);
jehan's avatar
jehan committed
686
	return wait_for(caller->lc,callee->lc,&callee->stat.number_of_IframeDecoded,initial_callee_stat.number_of_IframeDecoded+1);
jehan's avatar
jehan committed
687

jehan's avatar
jehan committed
688 689
}
static void call_with_video_added(void) {
Simon Morlat's avatar
Simon Morlat committed
690 691
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
692 693 694
	CU_ASSERT_TRUE(call(pauline,marie));

	CU_ASSERT_TRUE(add_video(pauline,marie));
jehan's avatar
jehan committed
695 696
	/*just to sleep*/
	linphone_core_terminate_all_calls(pauline->lc);
jehan's avatar
jehan committed
697 698
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
jehan's avatar
jehan committed
699 700 701 702

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
Ghislain MARY's avatar
Ghislain MARY committed
703

704 705


706 707 708 709 710 711 712 713
static void call_with_declined_video(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	LinphoneCallParams* callee_params;
	LinphoneCallParams* caller_params;
	LinphoneCall* marie_call;
	LinphoneCall* pauline_call;

714 715 716 717
	linphone_core_enable_video_capture(marie->lc, TRUE);
	linphone_core_enable_video_display(marie->lc, TRUE);
	linphone_core_enable_video_capture(pauline->lc, TRUE);
	linphone_core_enable_video_display(pauline->lc, FALSE);
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746

	caller_params=linphone_core_create_default_call_parameters(marie->lc);
	linphone_call_params_enable_video(caller_params,TRUE);
	callee_params=linphone_core_create_default_call_parameters(pauline->lc);
	linphone_call_params_enable_video(callee_params,FALSE);
	CU_ASSERT_TRUE(call_with_params(pauline,marie,caller_params,callee_params));
	marie_call=linphone_core_get_current_call(marie->lc);
	pauline_call=linphone_core_get_current_call(pauline->lc);

	CU_ASSERT_FALSE(linphone_call_log_video_enabled(linphone_call_get_call_log(marie_call)));
	CU_ASSERT_FALSE(linphone_call_log_video_enabled(linphone_call_get_call_log(pauline_call)));


	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

static void video_call(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	LinphoneCallParams* callee_params;
	LinphoneCallParams* caller_params;
	LinphoneCall* marie_call;
	LinphoneCall* pauline_call;

747 748 749 750
	linphone_core_enable_video_capture(marie->lc, TRUE);
	linphone_core_enable_video_display(marie->lc, TRUE);
	linphone_core_enable_video_capture(pauline->lc, TRUE);
	linphone_core_enable_video_display(pauline->lc, FALSE);
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767

	caller_params=linphone_core_create_default_call_parameters(marie->lc);
	linphone_call_params_enable_video(caller_params,TRUE);
	callee_params=linphone_core_create_default_call_parameters(pauline->lc);
	linphone_call_params_enable_video(callee_params,TRUE);
	CU_ASSERT_TRUE(call_with_params(pauline,marie,caller_params,callee_params));
	marie_call=linphone_core_get_current_call(marie->lc);
	pauline_call=linphone_core_get_current_call(pauline->lc);

	CU_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(marie_call)));
	CU_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(pauline_call)));

	/*check video path*/
	linphone_call_set_next_video_frame_decoded_callback(marie_call,linphone_call_cb,marie->lc);
	linphone_call_send_vfu_request(marie_call);
	CU_ASSERT_TRUE( wait_for(marie->lc,pauline->lc,&marie->stat.number_of_IframeDecoded,1));

768 769
	check_rtcp(marie,pauline);

770 771 772 773 774 775 776
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
777 778 779 780 781 782 783 784 785 786 787 788 789
#endif /*VIDEO_ENABLED*/

static void call_with_media_relay(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL);
	linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL);
	CU_ASSERT_TRUE(call(pauline,marie));
	check_rtcp(pauline,marie);

#ifdef VIDEO_ENABLED
	CU_ASSERT_TRUE(add_video(pauline,marie));
	check_rtcp(pauline,marie);
790 791
#endif

792 793 794 795 796 797 798 799 800 801
	/*just to sleep*/
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);

}

jehan's avatar
jehan committed
802
static void call_with_privacy(void) {
Simon Morlat's avatar
Simon Morlat committed
803 804
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
805 806
	LinphoneCall *c1,*c2;
	LinphoneCallParams *params;
jehan's avatar
jehan committed
807
	LinphoneProxyConfig* pauline_proxy;
jehan's avatar
jehan committed
808
	params=linphone_core_create_default_call_parameters(pauline->lc);
jehan's avatar
jehan committed
809
	linphone_call_params_set_privacy(params,LinphonePrivacyId);
jehan's avatar
jehan committed
810

811
	CU_ASSERT_TRUE(call_with_caller_params(pauline,marie,params));
jehan's avatar
jehan committed
812 813 814 815 816 817 818 819 820 821 822 823 824 825
	linphone_call_params_destroy(params);

	c1=linphone_core_get_current_call(pauline->lc);
	c2=linphone_core_get_current_call(marie->lc);

	CU_ASSERT_PTR_NOT_NULL(c1);
	CU_ASSERT_PTR_NOT_NULL(c2);

	/*make sure local identity is unchanged*/
	CU_ASSERT_TRUE(linphone_address_weak_equal(linphone_call_log_get_from(linphone_call_get_call_log(c1)),pauline->identity));

	/*make sure remote identity is hidden*/
	CU_ASSERT_FALSE(linphone_address_weak_equal(linphone_call_get_remote_address(c2),pauline->identity));

jehan's avatar
jehan committed
826
	CU_ASSERT_EQUAL(linphone_call_params_get_privacy(linphone_call_get_current_params(c2)),LinphonePrivacyId);
jehan's avatar
jehan committed
827 828 829 830 831 832

	/*just to sleep*/
	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(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));

jehan's avatar
jehan committed
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
	/*test proxy config privacy*/
	linphone_core_get_default_proxy(pauline->lc,&pauline_proxy);
	linphone_proxy_config_set_privacy(pauline_proxy,LinphonePrivacyId);

	CU_ASSERT_TRUE(call(pauline,marie));
	c1=linphone_core_get_current_call(pauline->lc);
	c2=linphone_core_get_current_call(marie->lc);

	CU_ASSERT_PTR_NOT_NULL(c1);
	CU_ASSERT_PTR_NOT_NULL(c2);

	/*make sure remote identity is hidden*/
	CU_ASSERT_FALSE(linphone_address_weak_equal(linphone_call_get_remote_address(c2),pauline->identity));

	CU_ASSERT_EQUAL(linphone_call_params_get_privacy(linphone_call_get_current_params(c2)),LinphonePrivacyId);
	/*just to sleep*/
	linphone_core_terminate_all_calls(pauline->lc);
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,2));
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,2));

jehan's avatar
jehan committed
853 854 855 856 857 858 859
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}




Ghislain MARY's avatar
Ghislain MARY committed
860
static void simple_conference(void) {
Simon Morlat's avatar
Simon Morlat committed
861 862 863
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
	LinphoneCoreManager* laure = linphone_core_manager_new( "laure_rc");
jehan's avatar
jehan committed
864 865 866 867 868 869 870 871
	stats initial_marie_stat;
	stats initial_pauline_stat;
	stats initial_laure_stat;

	LinphoneCall* marie_call_pauline;
	LinphoneCall* pauline_called_by_marie;
	LinphoneCall* marie_call_laure;

872 873 874 875
	MSList* lcs=ms_list_append(NULL,marie->lc);
	lcs=ms_list_append(lcs,pauline->lc);
	lcs=ms_list_append(lcs,laure->lc);

jehan's avatar
jehan committed
876 877 878 879 880 881 882 883 884 885 886 887
	CU_ASSERT_TRUE(call(marie,pauline));
	marie_call_pauline=linphone_core_get_current_call(marie->lc);
	pauline_called_by_marie=linphone_core_get_current_call(pauline->lc);
	CU_ASSERT_TRUE(pause_call_1(marie,marie_call_pauline,pauline,pauline_called_by_marie));

	CU_ASSERT_TRUE(call(marie,laure));
	initial_marie_stat=marie->stat;
	initial_pauline_stat=pauline->stat;
	initial_laure_stat=laure->stat;

	marie_call_laure=linphone_core_get_current_call(marie->lc);

888
	CU_ASSERT_PTR_NOT_NULL_FATAL(marie_call_laure);
jehan's avatar
jehan committed
889 890 891 892 893 894 895 896 897 898 899
	linphone_core_add_to_conference(marie->lc,marie_call_laure);
	CU_ASSERT_TRUE(wait_for(marie->lc,laure->lc,&marie->stat.number_of_LinphoneCallUpdating,initial_marie_stat.number_of_LinphoneCallUpdating+1));



	linphone_core_add_to_conference(marie->lc,marie_call_pauline);

	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallResuming,initial_marie_stat.number_of_LinphoneCallResuming+1,2000));

	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,initial_pauline_stat.number_of_LinphoneCallStreamsRunning+1,2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&laure->stat.number_of_LinphoneCallStreamsRunning,initial_laure_stat.number_of_LinphoneCallStreamsRunning+1,2000));
jehan's avatar
jehan committed
900
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,initial_marie_stat.number_of_LinphoneCallStreamsRunning+2,3000));
jehan's avatar
jehan committed
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916

	CU_ASSERT_TRUE(linphone_core_is_in_conference(marie->lc));
	CU_ASSERT_EQUAL(linphone_core_get_conference_size(marie->lc),3)

	linphone_core_terminate_conference(marie->lc);

	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,2000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&laure->stat.number_of_LinphoneCallEnd,1,2000));


	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(laure);
	ms_list_free(lcs);
}
jehan's avatar
jehan committed
917

jehan's avatar
jehan committed
918

Ghislain MARY's avatar
Ghislain MARY committed
919
static void srtp_call(void) {
Simon Morlat's avatar
Simon Morlat committed
920 921
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
922

jehan's avatar
jehan committed
923 924 925
	if (linphone_core_media_encryption_supported(marie->lc,LinphoneMediaEncryptionSRTP)) {
		linphone_core_set_media_encryption(marie->lc,LinphoneMediaEncryptionSRTP);
		linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP);
jehan's avatar
jehan committed
926

jehan's avatar
jehan committed
927
		CU_ASSERT_TRUE(call(pauline,marie));
jehan's avatar
jehan committed
928

jehan's avatar
jehan committed
929 930
		CU_ASSERT_EQUAL(linphone_core_get_media_encryption(marie->lc),LinphoneMediaEncryptionSRTP);
		CU_ASSERT_EQUAL(linphone_core_get_media_encryption(pauline->lc),LinphoneMediaEncryptionSRTP);
jehan's avatar
jehan committed
931

jehan's avatar
jehan committed
932 933 934 935 936 937 938 939 940 941 942
		/*just to sleep*/
		linphone_core_terminate_all_calls(marie->lc);
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
	} else {
		ms_warning ("not tested because srtp not available");
	}
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
static void call_with_declined_srtp(void) {
Simon Morlat's avatar
Simon Morlat committed
943 944
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
	if (linphone_core_media_encryption_supported(marie->lc,LinphoneMediaEncryptionSRTP)) {
		linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP);

		CU_ASSERT_TRUE(call(pauline,marie));

		/*just to sleep*/
		linphone_core_terminate_all_calls(marie->lc);
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
	} else {
		ms_warning ("not tested because srtp not available");
	}
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
#ifdef VIDEO_ENABLED
static void srtp_video_ice_call(void) {
962
	int i=0;
jehan's avatar
jehan committed
963 964 965
#else
static void srtp_ice_call(void) {
#endif
Simon Morlat's avatar
Simon Morlat committed
966 967
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
968 969 970 971 972 973 974 975 976 977 978 979

	if (linphone_core_media_encryption_supported(marie->lc,LinphoneMediaEncryptionSRTP)) {
		linphone_core_set_media_encryption(marie->lc,LinphoneMediaEncryptionSRTP);
		linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP);

		linphone_core_set_firewall_policy(marie->lc,LinphonePolicyUseIce);
		linphone_core_set_stun_server(marie->lc,"stun.linphone.org");
		linphone_core_set_firewall_policy(pauline->lc,LinphonePolicyUseIce);
		linphone_core_set_stun_server(pauline->lc,"stun.linphone.org");


		CU_ASSERT_TRUE(call(pauline,marie));
jehan's avatar
jehan committed
980

jehan's avatar
jehan committed
981 982 983 984 985 986 987 988 989 990 991
		CU_ASSERT_TRUE(check_ice(pauline,marie,LinphoneIceStateHostConnection));
#ifdef VIDEO_ENABLED
		for (i=0;i<100;i++) { /*fixme to workaround a crash*/
			ms_usleep(20000);
			linphone_core_iterate(marie->lc);
			linphone_core_iterate(pauline->lc);
		}

		add_video(pauline,marie);

		CU_ASSERT_TRUE(check_ice(pauline,marie,LinphoneIceStateHostConnection));
992
		check_rtcp(marie,pauline);
jehan's avatar
jehan committed
993 994
		/*wait for ice to found the direct path*/
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_IframeDecoded,1));
995 996
#endif
		
jehan's avatar
jehan committed
997 998 999 1000 1001 1002 1003 1004

		/*just to sleep*/
		linphone_core_terminate_all_calls(marie->lc);
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallEnd,1));
		CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallEnd,1));
	} else {
		ms_warning ("not tested because srtp not available");
	}
jehan's avatar
jehan committed
1005 1006 1007
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
jehan's avatar
jehan committed
1008

jehan's avatar
jehan committed
1009

Ghislain MARY's avatar
Ghislain MARY committed
1010
static void early_media_call(void) {
Simon Morlat's avatar
Simon Morlat committed
1011 1012
	LinphoneCoreManager* marie = linphone_core_manager_new( "marie_early_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
jehan's avatar
jehan committed
1013 1014 1015

	CU_ASSERT_TRUE(call(pauline,marie));

jehan's avatar
jehan committed
1016 1017
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallIncomingEarlyMedia,1);
	CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1);
jehan's avatar
jehan committed
1018 1019
	/*just to sleep*/
	linphone_core_terminate_all_calls(marie->lc);
jehan's avatar
jehan committed
1020 1021
	CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->