setup_tester.c 38.3 KB
Newer Older
1
/*
2 3
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL
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.
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.
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/>.
17 18
*/

19

20
#include "liblinphone_tester.h"
Erwan Croze's avatar
Erwan Croze committed
21 22 23
#include "linphone/core.h"
#include "linphone/friend.h"
#include "linphone/friendlist.h"
24
#include "linphone/lpconfig.h"
Erwan Croze's avatar
Erwan Croze committed
25
#include "linphone/api/c-magic-search.h"
Benjamin REIS's avatar
Benjamin REIS committed
26
#include "tester_utils.h"
27

28
#define S_SIZE_FRIEND 12
Erwan Croze's avatar
Erwan Croze committed
29 30
static const unsigned int sSizeFriend = S_SIZE_FRIEND;
static const char *sFriends[S_SIZE_FRIEND] = {
31 32
	"sip:charu@sip.test.org",//0
	"sip:charette@sip.example.org",//1
33 34 35 36 37 38 39 40 41 42
	"sip:allo@sip.example.org",//2
	"sip:hello@sip.example.org",//3
	"sip:hello@sip.test.org",//4
	"sip:marie@sip.example.org",//5
	"sip:laura@sip.example.org",//6
	"sip:loic@sip.example.org",//7
	"sip:laure@sip.test.org",//8
	"sip:loic@sip.test.org",//9
	"sip:+111223344@sip.example.org",//10
	"sip:+33655667788@sip.example.org"//11
Erwan Croze's avatar
Erwan Croze committed
43 44
};

Erwan Croze's avatar
Erwan Croze committed
45 46
static void _create_friends_from_tab(LinphoneCore *lc, LinphoneFriendList *list, const char *friends[], const unsigned int size) {
	for (unsigned int i = 0 ; i < size ; i++) {
Erwan Croze's avatar
Erwan Croze committed
47 48 49 50 51
		LinphoneFriend *fr = linphone_core_create_friend_with_address(lc, friends[i]);
		linphone_friend_list_add_friend(list, fr);
	}
}

Erwan Croze's avatar
Erwan Croze committed
52 53 54
static void _remove_friends_from_list(LinphoneFriendList *list, const char *friends[], const unsigned int size) {
	for (unsigned int i = 0 ; i < size ; i++) {
		LinphoneFriend *fr = linphone_friend_list_find_friend_by_uri(list, friends[i]);
55
		if (fr) linphone_friend_list_remove_friend(list, fr);
Erwan Croze's avatar
Erwan Croze committed
56 57 58
	}
}

59 60 61 62 63
static void _check_friend_result_list(LinphoneCore *lc, const bctbx_list_t *resultList, const unsigned int index, const char* uri, const char* phone) {
	if (index >= bctbx_list_size(resultList)) {
		ms_error("Attempt to access result to an outbound index");
		return;
	}
Erwan Croze's avatar
Erwan Croze committed
64 65
	const LinphoneSearchResult *sr = bctbx_list_nth_data(resultList, index);
	const LinphoneFriend *lf = linphone_search_result_get_friend(sr);
66
	if (lf) {
Erwan Croze's avatar
Erwan Croze committed
67
		const LinphoneAddress *la = linphone_friend_get_address(lf);
68
		if (la) {
69 70 71 72
			char* fa = linphone_address_as_string(la);
			BC_ASSERT_STRING_EQUAL(fa , uri);
			free(fa);
			return;
73
		} else if (phone) {
74
			const LinphonePresenceModel *presence = linphone_friend_get_presence_model_for_uri_or_tel(lf, phone);
75
			if (BC_ASSERT_PTR_NOT_NULL(presence)) {
76 77 78 79 80
				char *contact = linphone_presence_model_get_contact(presence);
				BC_ASSERT_STRING_EQUAL(contact, uri);
				free(contact);
				return;
			}
Erwan Croze's avatar
Erwan Croze committed
81
		}
82 83 84 85 86 87 88 89 90 91 92 93 94 95
	} else {
		const bctbx_list_t *callLog = linphone_core_get_call_logs(lc);
		for (const bctbx_list_t *f = callLog ; f != NULL ; f = bctbx_list_next(f)) {
			LinphoneCallLog *log = (LinphoneCallLog*)(f->data);
			const LinphoneAddress *addr = (linphone_call_log_get_dir(log) == LinphoneCallIncoming) ?
			linphone_call_log_get_from_address(log) : linphone_call_log_get_to_address(log);
			if (addr) {
				char *addrUri = linphone_address_as_string_uri_only(addr);
				if (addrUri && strcmp(addrUri, uri) == 0) {
					return;
				}
				if (addrUri) free(addrUri);
			}
		}
Erwan Croze's avatar
Erwan Croze committed
96
	}
97
	BC_ASSERT(FALSE);
98
	ms_error("Address NULL and Presence NULL");
Erwan Croze's avatar
Erwan Croze committed
99 100
}

101 102 103 104
static void _create_call_log(LinphoneCore *lc, LinphoneAddress *addrFrom, LinphoneAddress *addrTo) {
	linphone_core_create_call_log(lc, addrFrom, addrTo, LinphoneCallOutgoing, 100, time(NULL), time(NULL), LinphoneCallSuccess, FALSE, 1.0);
}

105 106 107
static void linphone_version_test(void){
	const char *version=linphone_core_get_version();
	/*make sure the git version is always included in the version number*/
108
	BC_ASSERT_PTR_NOT_NULL(version);
109
	BC_ASSERT_PTR_NULL(strstr(version,"unknown"));
110 111
}

112
static void core_init_test(void) {
Sylvain Berfini's avatar
Sylvain Berfini committed
113
	LinphoneCore* lc;
114
	lc = linphone_factory_create_core(linphone_factory_get(),NULL,NULL,NULL);
Simon Morlat's avatar
Simon Morlat committed
115 116
	/* until we have good certificates on our test server... */
	linphone_core_verify_server_certificates(lc,FALSE);
117
	if (BC_ASSERT_PTR_NOT_NULL(lc)) {
118
		linphone_core_unref(lc);
119
	}
120 121 122
}

static void linphone_address_test(void) {
Simon Morlat's avatar
Simon Morlat committed
123
	linphone_address_unref(create_linphone_address(NULL));
jehan's avatar
jehan committed
124
	BC_ASSERT_PTR_NULL(linphone_address_new("sip:@sip.linphone.org"));
125 126
}

127 128 129
static void core_sip_transport_test(void) {
	LinphoneCore* lc;
	LCSipTransports tr;
130
	lc = linphone_factory_create_core(linphone_factory_get(),NULL,NULL,NULL);
131
	if (!BC_ASSERT_PTR_NOT_NULL(lc)) return;
132
	linphone_core_get_sip_transports(lc,&tr);
133 134
	BC_ASSERT_EQUAL(tr.udp_port,5060, int, "%d"); /*default config*/
	BC_ASSERT_EQUAL(tr.tcp_port,5060, int, "%d"); /*default config*/
135 136 137 138 139 140 141 142

	tr.udp_port=LC_SIP_TRANSPORT_RANDOM;
	tr.tcp_port=LC_SIP_TRANSPORT_RANDOM;
	tr.tls_port=LC_SIP_TRANSPORT_RANDOM;

	linphone_core_set_sip_transports(lc,&tr);
	linphone_core_get_sip_transports(lc,&tr);

143 144
	BC_ASSERT_NOT_EQUAL(tr.udp_port,5060,int,"%d"); /*default config*/
	BC_ASSERT_NOT_EQUAL(tr.tcp_port,5060,int,"%d"); /*default config*/
145

146 147 148
	BC_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_port",-2),LC_SIP_TRANSPORT_RANDOM, int, "%d");
	BC_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tcp_port",-2),LC_SIP_TRANSPORT_RANDOM, int, "%d");
	BC_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tls_port",-2),LC_SIP_TRANSPORT_RANDOM, int, "%d");
149

150
	linphone_core_unref(lc);
151 152
}

153
static void linphone_interpret_url_test(void) {
154 155 156
	LinphoneCore* lc;
	const char* sips_address = "sips:margaux@sip.linphone.org";
	LinphoneAddress* address;
157 158
	LinphoneProxyConfig *proxy_config;
	char *tmp;
159
	lc = linphone_factory_create_core(linphone_factory_get(),NULL,NULL,NULL);
160
	if (!BC_ASSERT_PTR_NOT_NULL( lc )) return;
161

162 163 164 165 166 167
	proxy_config =linphone_core_create_proxy_config(lc);
	linphone_proxy_config_set_identity(proxy_config, "sip:moi@sip.linphone.org");
	linphone_proxy_config_enable_register(proxy_config, FALSE);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_core_add_proxy_config(lc, proxy_config);
	linphone_core_set_default_proxy_config(lc,proxy_config);
168
	linphone_proxy_config_unref(proxy_config);
169 170

	address = linphone_core_interpret_url(lc, sips_address);
171 172 173 174
	BC_ASSERT_PTR_NOT_NULL(address);
	BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sips");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "margaux");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org");
Simon Morlat's avatar
Simon Morlat committed
175
	linphone_address_unref(address);
176

177 178 179 180 181
	address = linphone_core_interpret_url(lc,"23");
	BC_ASSERT_PTR_NOT_NULL(address);
	BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "23");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org");
Simon Morlat's avatar
Simon Morlat committed
182
	linphone_address_unref(address);
183 184 185 186 187 188 189 190

	address = linphone_core_interpret_url(lc,"#24");
	BC_ASSERT_PTR_NOT_NULL(address);
	BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org");
	tmp = linphone_address_as_string(address);
	BC_ASSERT_TRUE(strcmp (tmp,"sip:%2324@sip.linphone.org") == 0);
Simon Morlat's avatar
Simon Morlat committed
191
	linphone_address_unref(address);
192 193 194 195 196

	address = linphone_core_interpret_url(lc,tmp);
	BC_ASSERT_STRING_EQUAL(linphone_address_get_scheme(address), "sip");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_username(address), "#24");
	BC_ASSERT_STRING_EQUAL(linphone_address_get_domain(address), "sip.linphone.org");
Simon Morlat's avatar
Simon Morlat committed
197
	linphone_address_unref(address);
198 199
	ms_free(tmp);

200
	linphone_core_unref(lc);
201 202
}

203
static void linphone_lpconfig_from_buffer(void){
204 205
	const char* buffer = "[buffer]\ntest=ok";
	const char* buffer_linebreaks = "[buffer_linebreaks]\n\n\n\r\n\n\r\ntest=ok";
206 207 208
	LpConfig* conf;

	conf = lp_config_new_from_buffer(buffer);
209
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"buffer","test",""),"ok");
210 211 212
	lp_config_destroy(conf);

	conf = lp_config_new_from_buffer(buffer_linebreaks);
213
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"buffer_linebreaks","test",""),"ok");
214
	lp_config_destroy(conf);
215 216
}

217
static void linphone_lpconfig_from_buffer_zerolen_value(void){
218
	/* parameters that have no value should return NULL, not "". */
219
	const char* zerolen = "[test]\nzero_len=\nnon_zero_len=test";
220 221 222 223
	LpConfig* conf;

	conf = lp_config_new_from_buffer(zerolen);

224 225
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");
226 227

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
228
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");
229 230 231 232

	lp_config_destroy(conf);
}

233
static void linphone_lpconfig_from_file_zerolen_value(void){
234
	/* parameters that have no value should return NULL, not "". */
235
	const char* zero_rc_file = "zero_length_params_rc";
236
	char* rc_path = ms_strdup_printf("%s/rcfiles/%s", bc_tester_get_resource_dir_prefix(), zero_rc_file);
237 238
	LpConfig* conf;

239 240 241
	/* not using lp_config_new() because it expects a readable file, and iOS (for instance)
	   stores the app bundle in read-only */
	conf = lp_config_new_with_factory(NULL, rc_path);
242

243
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
244 245

	// non_zero_len=test -> should return test
246
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");
247 248

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
249
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");
250

251
	ms_free(rc_path);
252
	lp_config_destroy(conf);
253
}
254

255
static void linphone_lpconfig_from_xml_zerolen_value(void){
256
	const char* zero_xml_file = "remote_zero_length_params_rc";
257
	char* xml_path = ms_strdup_printf("%s/rcfiles/%s", bc_tester_get_resource_dir_prefix(), zero_xml_file);
258 259 260 261
	LpConfig* conf;

	LinphoneCoreManager* mgr = linphone_core_manager_new2("empty_rc",FALSE);

262 263 264 265
	/* BUG
	 * This test makes a provisionning by xml outside of the Configuring state of the LinphoneCore.
	 * It is leaking memory because the config is litterally erased and rewritten by the invocation
	 * of the private function linphone_remote_provisioning_load_file .
266 267
	 */

268
	BC_ASSERT_EQUAL(linphone_remote_provisioning_load_file(mgr->lc, xml_path), 0, int, "%d");
269

270
	conf = linphone_core_get_config(mgr->lc);
271

272 273
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");
274 275

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
276
	BC_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");
277 278

	linphone_core_manager_destroy(mgr);
279
	ms_free(xml_path);
280 281
}

282
void linphone_proxy_config_address_equal_test(void) {
283 284 285 286 287
	LinphoneAddress *a = linphone_address_new("sip:toto@titi");
	LinphoneAddress *b = linphone_address_new("sips:toto@titi");
	LinphoneAddress *c = linphone_address_new("sip:toto@titi;transport=tcp");
	LinphoneAddress *d = linphone_address_new("sip:toto@titu");
	LinphoneAddress *e = linphone_address_new("sip:toto@titi;transport=udp");
288 289
	LinphoneAddress *f = linphone_address_new("sip:toto@titi?X-Create-Account=yes");

290 291 292 293 294 295 296 297 298
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,NULL), LinphoneProxyConfigAddressDifferent, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,b), LinphoneProxyConfigAddressDifferent, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,c), LinphoneProxyConfigAddressDifferent, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,d), LinphoneProxyConfigAddressDifferent, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,e), LinphoneProxyConfigAddressWeakEqual, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(NULL,NULL), LinphoneProxyConfigAddressEqual, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(a,f), LinphoneProxyConfigAddressWeakEqual, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(c,f), LinphoneProxyConfigAddressDifferent, int, "%d");
	BC_ASSERT_EQUAL(linphone_proxy_config_address_equal(e,f), LinphoneProxyConfigAddressWeakEqual, int, "%d");
299

Simon Morlat's avatar
Simon Morlat committed
300 301 302 303 304 305
	linphone_address_unref(a);
	linphone_address_unref(b);
	linphone_address_unref(c);
	linphone_address_unref(d);
	linphone_address_unref(e);
	linphone_address_unref(f);
306 307
}

308
void linphone_proxy_config_is_server_config_changed_test(void) {
309 310
	LinphoneProxyConfig* proxy_config = linphone_proxy_config_new();

311 312
	linphone_proxy_config_done(proxy_config); /*test done without edit*/

313 314 315
	linphone_proxy_config_set_identity(proxy_config,"sip:toto@titi");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_identity(proxy_config,"sips:toto@titi");
316
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");
317 318 319 320

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:toto.com");
321
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");
322

323
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
324
	linphone_proxy_config_edit(proxy_config);
325
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org:4444");
326
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");
327

328
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
329
	linphone_proxy_config_edit(proxy_config);
330
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;transport=tcp");
331
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressDifferent, int, "%d");
332

333
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
334
	linphone_proxy_config_edit(proxy_config);
335
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;param=blue");
336
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressWeakEqual, int, "%d");
337 338 339 340


	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_contact_parameters(proxy_config,"blabla=blue");
341
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d");
342 343 344

	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_enable_register(proxy_config,TRUE);
345
	BC_ASSERT_EQUAL(linphone_proxy_config_is_server_config_changed(proxy_config), LinphoneProxyConfigAddressEqual, int, "%d");
346 347 348

	linphone_proxy_config_destroy(proxy_config);
}
349

Simon Morlat's avatar
Simon Morlat committed
350
static void chat_room_test(void) {
jehan's avatar
jehan committed
351
	LinphoneCore* lc;
352
	lc = linphone_factory_create_core(linphone_factory_get(),NULL,NULL,NULL);
353
	if (!BC_ASSERT_PTR_NOT_NULL(lc)) return;
Simon Morlat's avatar
Simon Morlat committed
354
	BC_ASSERT_PTR_NOT_NULL(linphone_core_get_chat_room_from_uri(lc,"sip:toto@titi.com"));
355
	linphone_core_unref(lc);
jehan's avatar
jehan committed
356 357
}

358 359 360 361 362 363 364 365
static void devices_reload_test(void) {
	char *devid1;
	char *devid2;
	LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE);

	devid1 = ms_strdup(linphone_core_get_capture_device(mgr->lc));
	linphone_core_reload_sound_devices(mgr->lc);
	devid2 = ms_strdup(linphone_core_get_capture_device(mgr->lc));
366
	BC_ASSERT_STRING_EQUAL(devid1, devid2);
367 368 369 370 371 372
	ms_free(devid1);
	ms_free(devid2);

	devid1 = ms_strdup(linphone_core_get_video_device(mgr->lc));
	linphone_core_reload_video_devices(mgr->lc);
	devid2 = ms_strdup(linphone_core_get_video_device(mgr->lc));
373 374 375 376 377 378 379

	if (devid1 && devid2) {
		BC_ASSERT_STRING_EQUAL(devid1, devid2);
	} else {
		BC_ASSERT_PTR_NULL(devid1);
		BC_ASSERT_PTR_NULL(devid2);
	}
380 381 382 383 384 385
	ms_free(devid1);
	ms_free(devid2);

	linphone_core_manager_destroy(mgr);
}

386 387 388
static void codec_usability_test(void) {
	LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE);
	PayloadType *pt = linphone_core_find_payload_type(mgr->lc, "PCMU", 8000, -1);
389

390
	BC_ASSERT_PTR_NOT_NULL(pt);
391 392 393 394 395 396 397 398 399
	if (!pt) goto end;
	/*no limit*/
	linphone_core_set_upload_bandwidth(mgr->lc, 0);
	linphone_core_set_download_bandwidth(mgr->lc, 0);
	BC_ASSERT_TRUE(linphone_core_check_payload_type_usability(mgr->lc, pt));
	/*low limit*/
	linphone_core_set_upload_bandwidth(mgr->lc, 50);
	linphone_core_set_download_bandwidth(mgr->lc, 50);
	BC_ASSERT_FALSE(linphone_core_check_payload_type_usability(mgr->lc, pt));
400

401 402 403 404
	/*reasonable limit*/
	linphone_core_set_upload_bandwidth(mgr->lc, 200);
	linphone_core_set_download_bandwidth(mgr->lc, 200);
	BC_ASSERT_TRUE(linphone_core_check_payload_type_usability(mgr->lc, pt));
405

406 407 408 409
end:
	linphone_core_manager_destroy(mgr);
}

410 411 412 413 414 415 416 417
/*this test checks default codec list, assuming VP8 and H264 are both supported.
 * - with an empty config, the order must be as expected: VP8 first, H264 second.
 * - with a config that references only H264, VP8 must be added automatically as first codec.
 * - with a config that references only VP8, H264 must be added in second position.
**/
static void codec_setup(void){
	LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE);
	PayloadType *vp8, *h264;
418
	const bctbx_list_t *codecs;
419 420 421 422 423 424 425 426
	if ((vp8 = linphone_core_find_payload_type(mgr->lc, "VP8", 90000, -1)) == NULL ||
		(h264 = linphone_core_find_payload_type(mgr->lc, "H264", 90000, -1)) == NULL){
		linphone_core_manager_destroy(mgr);
		ms_error("H264 or VP8 not available, test skipped.");
		BC_PASS("H264 or VP8 not available, test skipped.");
		return;
	}
	codecs = linphone_core_get_video_codecs(mgr->lc);
427
	BC_ASSERT_TRUE(bctbx_list_size(codecs)>=2);
428 429 430
	BC_ASSERT_TRUE(codecs->data == vp8);
	BC_ASSERT_TRUE(codecs->next->data == h264);
	linphone_core_manager_destroy(mgr);
431

432 433 434 435
	mgr = linphone_core_manager_new2("marie_h264_rc", FALSE);
	vp8 = linphone_core_find_payload_type(mgr->lc, "VP8", 90000, -1);
	h264 = linphone_core_find_payload_type(mgr->lc, "H264", 90000, -1);
	codecs = linphone_core_get_video_codecs(mgr->lc);
436
	BC_ASSERT_TRUE(bctbx_list_size(codecs)>=2);
437 438 439 440 441
	BC_ASSERT_PTR_NOT_NULL(vp8);
	BC_ASSERT_PTR_NOT_NULL(h264);
	BC_ASSERT_TRUE(codecs->data == vp8);
	BC_ASSERT_TRUE(codecs->next->data == h264);
	linphone_core_manager_destroy(mgr);
442

443 444 445 446
	mgr = linphone_core_manager_new2("marie_rc", FALSE);
	vp8 = linphone_core_find_payload_type(mgr->lc, "VP8", 90000, -1);
	h264 = linphone_core_find_payload_type(mgr->lc, "H264", 90000, -1);
	codecs = linphone_core_get_video_codecs(mgr->lc);
447
	BC_ASSERT_TRUE(bctbx_list_size(codecs)>=2);
448 449 450 451 452
	BC_ASSERT_PTR_NOT_NULL(vp8);
	BC_ASSERT_PTR_NOT_NULL(h264);
	BC_ASSERT_TRUE(codecs->data == vp8);
	BC_ASSERT_TRUE(codecs->next->data == h264);
	linphone_core_manager_destroy(mgr);
453

454 455
}

456 457 458
static void custom_tones_setup(void){
	LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE);
	const char *tone;
459

460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
	linphone_core_set_tone(mgr->lc, LinphoneToneCallOnHold, "callonhold.wav");
	tone = linphone_core_get_tone_file(mgr->lc, LinphoneToneCallOnHold);
	BC_ASSERT_PTR_NOT_NULL(tone);
	if (tone){
		BC_ASSERT_STRING_EQUAL(tone, "callonhold.wav");
	}
	linphone_core_set_tone(mgr->lc, LinphoneToneCallOnHold, "callonhold2.wav");
	tone = linphone_core_get_tone_file(mgr->lc, LinphoneToneCallOnHold);
	BC_ASSERT_PTR_NOT_NULL(tone);
	if (tone){
		BC_ASSERT_STRING_EQUAL(tone, "callonhold2.wav");
	}
	linphone_core_manager_destroy(mgr);
}

Erwan Croze's avatar
Erwan Croze committed
475
static void search_friend_all_domains(void) {
Erwan Croze's avatar
Erwan Croze committed
476 477
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
Erwan Croze's avatar
Erwan Croze committed
478 479 480
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);

Erwan Croze's avatar
Erwan Croze committed
481 482 483 484 485 486
	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "llo", "");

487
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
Erwan Croze's avatar
Erwan Croze committed
488
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 3, int, "%d");
489 490 491
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[2], NULL);//"sip:allo@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[3], NULL);//"sip:hello@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, sFriends[4], NULL);//"sip:hello@sip.test.org"
492
		free(resultList);
Erwan Croze's avatar
Erwan Croze committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
	}

	_remove_friends_from_list(lfl, sFriends, sSizeFriend);

	linphone_core_manager_destroy(manager);
}

static void search_friend_one_domain(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "llo", "sip.example.org");

512
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
Erwan Croze's avatar
Erwan Croze committed
513
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
514 515
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[2], NULL);//"sip:allo@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[3], NULL);//"sip:hello@sip.example.org"
516
		free(resultList);
Erwan Croze's avatar
Erwan Croze committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
	}


	_remove_friends_from_list(lfl, sFriends, sSizeFriend);

	linphone_core_manager_destroy(manager);
}

static void search_friend_research_estate(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "l", "");

537
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
Erwan Croze's avatar
Erwan Croze committed
538
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 7, int, "%d");
539 540 541 542 543 544 545
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[6], NULL);//"sip:laura@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[7], NULL);//"sip:loic@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, sFriends[8], NULL);//"sip:laure@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 3, sFriends[9], NULL);//"sip:loic@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 4, sFriends[2], NULL);//"sip:allo@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 5, sFriends[3], NULL);//"sip:hello@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 6, sFriends[4], NULL);//"sip:hello@sip.test.org"
546
		free(resultList);
Erwan Croze's avatar
Erwan Croze committed
547 548 549 550
	}

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "la", "");

551
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
Erwan Croze's avatar
Erwan Croze committed
552
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
553 554
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[8], NULL);//"sip:laure@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[6], NULL);//"sip:laura@sip.example.org"
555
		free(resultList);
Erwan Croze's avatar
Erwan Croze committed
556 557 558
	}

	_remove_friends_from_list(lfl, sFriends, sSizeFriend);
Erwan Croze's avatar
Erwan Croze committed
559 560 561 562

	linphone_core_manager_destroy(manager);
}

563 564 565 566 567 568 569 570 571 572 573 574
static void search_friend_research_estate_reset(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "la", "");

575
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
576
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
577 578
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[6], NULL);//"sip:laura@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[8], NULL);//"sip:laure@sip.test.org"
579
		free(resultList);
580 581 582 583 584 585
	}

	linphone_magic_search_reset_search_cache(magicSearch);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "l", "");

586
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
587
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 7, int, "%d");
588 589 590 591 592 593 594
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[6], NULL);//"sip:laura@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[7], NULL);//"sip:loic@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, sFriends[8], NULL);//"sip:laure@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 3, sFriends[9], NULL);//"sip:loic@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 4, sFriends[2], NULL);//"sip:allo@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 5, sFriends[3], NULL);//"sip:hello@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 6, sFriends[4], NULL);//"sip:hello@sip.test.org"
595
		free(resultList);
596 597 598 599 600 601 602
	}

	_remove_friends_from_list(lfl, sFriends, sSizeFriend);

	linphone_core_manager_destroy(manager);
}

603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
static void search_friend_with_phone_number(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const char* mariePhoneNumber = {"0633556644"};

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	linphone_friend_add_phone_number(linphone_friend_list_find_friend_by_uri(lfl, sFriends[5]), mariePhoneNumber);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "33", "");

618
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
619
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 3, int, "%d");
620 621 622
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[11], NULL);//"sip:+111223344@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[10], NULL);//"sip:+33655667788@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, sFriends[5], NULL);//"sip:marie@sip.example.org"
623
		free(resultList);
624 625
	}

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
	_remove_friends_from_list(lfl, sFriends, sSizeFriend);

	linphone_core_manager_destroy(manager);
}

static void search_friend_with_presence(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_create("marie_rc");
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const char* chloeSipUri = {"sip:chloe@sip.example.org"};
	const char* chloePhoneNumber = {"0633556644"};
	LinphoneFriend *chloeFriend = linphone_core_create_friend(manager->lc);
	LinphonePresenceModel *chloePresence = linphone_core_create_presence_model(manager->lc);
	LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(manager->lc);

	linphone_proxy_config_edit(proxy);
	linphone_proxy_config_set_dial_prefix(proxy, "33");
	linphone_proxy_config_done(proxy);
	linphone_core_set_default_proxy(manager->lc, proxy);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);
	linphone_presence_model_set_contact(chloePresence, chloeSipUri);
	linphone_friend_add_phone_number(chloeFriend, chloePhoneNumber);
	linphone_friend_set_presence_model_for_uri_or_tel(chloeFriend, chloePhoneNumber, chloePresence);
	linphone_friend_list_add_friend(lfl, chloeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "33", "");

657 658 659
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
		// 3 + last address from filter "sip:33@sip.example.org"
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 4, int, "%d");
660 661 662
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[11], NULL);//"sip:+111223344@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, chloeSipUri, chloePhoneNumber);//"sip:chloe@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, sFriends[10], NULL);//"sip:+33655667788@sip.example.org"
663
		free(resultList);
664 665 666 667 668 669
	}

	linphone_magic_search_reset_search_cache(magicSearch);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "chloe", "");

670
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
671
		// 1 + last address from filter "sip:chloe@sip.example.org"
672
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
673
		_check_friend_result_list(manager->lc, resultList, 0, chloeSipUri, chloePhoneNumber);//"sip:chloe@sip.example.org"
674
		free(resultList);
675 676
	}

677
	_remove_friends_from_list(lfl, sFriends, sSizeFriend);
678 679 680 681 682 683 684 685
	{
		LinphoneFriend *fr = linphone_friend_list_find_friend_by_uri(lfl, chloeSipUri);
		if (fr != NULL) linphone_friend_list_remove_friend(lfl, fr);
	}

	linphone_core_manager_destroy(manager);
}

686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
static void search_friend_in_call_log(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const char *chloeSipUri = {"sip:chloe@sip.example.org"};
	const char *benjaminSipUri = {"sip:benjamin@sip.example.org"};
	const char *charlesSipUri = {"sip:charles@sip.test.org"};
	const char *ronanSipUri = {"sip:ronan@sip.example.org"};
	LinphoneAddress *chloeAddress = linphone_address_new(chloeSipUri);
	LinphoneAddress *benjaminAddress = linphone_address_new(benjaminSipUri);
	LinphoneAddress *charlesAddress = linphone_address_new(charlesSipUri);
	LinphoneAddress *ronanAddress = linphone_address_new(ronanSipUri);

	_create_call_log(manager->lc, ronanAddress, chloeAddress);
	_create_call_log(manager->lc, ronanAddress, charlesAddress);
	_create_call_log(manager->lc, ronanAddress, benjaminAddress);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "ch", "");

710
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
711 712 713 714 715
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 4, int, "%d");
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[0], NULL);//"sip:charu@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 1, sFriends[1], NULL);//"sip:charette@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 2, chloeSipUri, NULL);//"sip:chloe@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 3, charlesSipUri, NULL);//"sip:charles@sip.test.org"
716
		free(resultList);
717 718 719 720 721 722
	}

	linphone_magic_search_reset_search_cache(magicSearch);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "ch", "sip.test.org");

723
	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
724 725 726
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
		_check_friend_result_list(manager->lc, resultList, 0, sFriends[0], NULL);//"sip:charu@sip.test.org"
		_check_friend_result_list(manager->lc, resultList, 1, charlesSipUri, NULL);//"sip:charles@sip.test.org"
727
		free(resultList);
728 729 730 731 732 733 734
	}

	_remove_friends_from_list(lfl, sFriends, sSizeFriend);

	linphone_core_manager_destroy(manager);
}

735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
static void search_friend_last_item_is_filter(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_create("marie_rc");
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "newaddress", "");

	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 1, int, "%d");
		const LinphoneSearchResult *sr = bctbx_list_nth_data(resultList, 0);
		if (BC_ASSERT_PTR_NOT_NULL(sr)) {
			const LinphoneAddress *srAddress = linphone_search_result_get_address(sr);
			if (BC_ASSERT_PTR_NOT_NULL(srAddress)) {
				BC_ASSERT_STRING_EQUAL(linphone_address_get_username(srAddress), "newaddress");
			}
		}
		free(resultList);
	}

	linphone_core_manager_destroy(manager);
}

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
static void search_friend_with_name(void) {
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const char *stephanie1SipUri = {"sip:toto@sip.example.org"};
	const char *stephanie2SipUri = {"sip:stephanie@sip.example.org"};
	LinphoneFriend *stephanie1Friend = linphone_core_create_friend(manager->lc);
	LinphoneFriend *stephanie2Friend = linphone_core_create_friend(manager->lc);
	LinphoneVcard *stephanie1Vcard = linphone_factory_create_vcard(linphone_factory_get());
	LinphoneVcard *stephanie2Vcard = linphone_factory_create_vcard(linphone_factory_get());
	const char *stephanie1Name = {"stephanie delarue"};
	const char *stephanie2Name = {"alias delarue"};

	_create_friends_from_tab(manager->lc, lfl, sFriends, sSizeFriend);

	linphone_vcard_set_full_name(stephanie1Vcard, stephanie1Name); // stephanie delarue
	linphone_vcard_set_url(stephanie1Vcard, stephanie1SipUri); //sip:toto@sip.example.org
	linphone_vcard_add_sip_address(stephanie1Vcard, stephanie1SipUri);
	linphone_friend_set_vcard(stephanie1Friend, stephanie1Vcard);
	linphone_core_add_friend(manager->lc, stephanie1Friend);

	linphone_vcard_set_full_name(stephanie2Vcard, stephanie2Name); // alias delarue
	linphone_vcard_set_url(stephanie2Vcard, stephanie2SipUri); //sip:stephanie@sip.example.org
	linphone_vcard_add_sip_address(stephanie2Vcard, stephanie2SipUri);
	linphone_friend_set_vcard(stephanie2Friend, stephanie2Vcard);
	linphone_core_add_friend(manager->lc, stephanie2Friend);

	magicSearch = linphone_magic_search_new(manager->lc);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "stephanie", "");

	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
		_check_friend_result_list(manager->lc, resultList, 0, stephanie1SipUri, NULL);//"sip:toto@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, stephanie2SipUri, NULL);//"sip:stephanie@sip.example.org"
		free(resultList);
	}

	linphone_magic_search_reset_search_cache(magicSearch);

	resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, "delarue", "");

	if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
		BC_ASSERT_EQUAL(bctbx_list_size(resultList), 2, int, "%d");
		_check_friend_result_list(manager->lc, resultList, 0, stephanie2SipUri, NULL);//"sip:stephanie@sip.example.org"
		_check_friend_result_list(manager->lc, resultList, 1, stephanie1SipUri, NULL);//"sip:toto@sip.example.org"
		free(resultList);
	}

	_remove_friends_from_list(lfl, sFriends, sSizeFriend);
	linphone_friend_list_remove_friend(lfl, stephanie1Friend);
	linphone_friend_list_remove_friend(lfl, stephanie2Friend);

	linphone_core_manager_destroy(manager);
}

819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
static void search_friend_large_database(void) {
	MSTimeSpec start, current;
	LinphoneMagicSearch *magicSearch = NULL;
	bctbx_list_t *resultList = NULL;
	char *dbPath = bc_tester_res("db/friends.db");
	char searchedFriend[] = {"6295103032641994169"};
	char subBuff[30];
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	linphone_core_set_friends_database_path(manager->lc, dbPath);

	magicSearch = linphone_magic_search_new(manager->lc);

	for (unsigned int i = 1; i < sizeof(searchedFriend) ; i++) {
		memcpy(subBuff, &searchedFriend, i);
		subBuff[i] = '\0';
		liblinphone_tester_clock_start(&start);
		resultList = linphone_magic_search_get_contact_list_from_filter(magicSearch, subBuff, "");
836 837 838
		if (BC_ASSERT_PTR_NOT_NULL(resultList)) {
			ms_get_cur_time(&current);
			ms_message("Searching time: %lld ms" ,((current.tv_sec - start.tv_sec)*1000LL) + ((current.tv_nsec - start.tv_nsec)/1000000LL));
839

840
			if (BC_ASSERT_PTR_NOT_NULL(resultList)) ms_message("List size: %zu", bctbx_list_size(resultList));
841

842 843
			free(resultList);
		}
844
	}
845 846 847 848

	linphone_core_manager_destroy(manager);
}

849
test_t setup_tests[] = {
850 851 852 853 854 855
	TEST_NO_TAG("Version check", linphone_version_test),
	TEST_NO_TAG("Linphone Address", linphone_address_test),
	TEST_NO_TAG("Linphone proxy config address equal (internal api)", linphone_proxy_config_address_equal_test),
	TEST_NO_TAG("Linphone proxy config server address change (internal api)", linphone_proxy_config_is_server_config_changed_test),
	TEST_NO_TAG("Linphone core init/uninit", core_init_test),
	TEST_NO_TAG("Linphone random transport port",core_sip_transport_test),
856
	TEST_NO_TAG("Linphone interpret url", linphone_interpret_url_test),
857 858 859
	TEST_NO_TAG("LPConfig from buffer", linphone_lpconfig_from_buffer),
	TEST_NO_TAG("LPConfig zero_len value from buffer", linphone_lpconfig_from_buffer_zerolen_value),
	TEST_NO_TAG("LPConfig zero_len value from file", linphone_lpconfig_from_file_zerolen_value),
860
	TEST_NO_TAG("LPConfig zero_len value from XML", linphone_lpconfig_from_xml_zerolen_value),
861 862
	TEST_NO_TAG("Chat room", chat_room_test),
	TEST_NO_TAG("Devices reload", devices_reload_test),
863
	TEST_NO_TAG("Codec usability", codec_usability_test),
864
	TEST_NO_TAG("Codec setup", codec_setup),
Erwan Croze's avatar
Erwan Croze committed
865
	TEST_NO_TAG("Custom tones setup", custom_tones_setup),
Erwan Croze's avatar
Erwan Croze committed
866 867
	TEST_TWO_TAGS("Search friend from all domains", search_friend_all_domains, "MagicSearch", "LeaksMemory"),
	TEST_TWO_TAGS("Search friend from one domain", search_friend_one_domain, "MagicSearch", "LeaksMemory"),
868
	TEST_TWO_TAGS("Multiple looking for friends with the same cache", search_friend_research_estate, "MagicSearch", "LeaksMemory"),
869
	TEST_TWO_TAGS("Multiple looking for friends with cache resetting", search_friend_research_estate_reset, "MagicSearch", "LeaksMemory"),
870 871
	TEST_TWO_TAGS("Search friend with phone number", search_friend_with_phone_number, "MagicSearch", "LeaksMemory"),
	TEST_TWO_TAGS("Search friend and find it with its presence", search_friend_with_presence, "MagicSearch", "LeaksMemory"),
872
	TEST_TWO_TAGS("Search friend in call log", search_friend_in_call_log, "MagicSearch", "LeaksMemory"),
873
	TEST_TWO_TAGS("Search friend last item is the filter", search_friend_last_item_is_filter, "MagicSearch", "LeaksMemory"),
874
	TEST_TWO_TAGS("Search friend with name", search_friend_with_name, "MagicSearch", "LeaksMemory"),
875
	TEST_TWO_TAGS("Search friend in large friends database", search_friend_large_database, "MagicSearch", "LeaksMemory")
876 877
};

878
test_suite_t setup_test_suite = {"Setup", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
879
								 sizeof(setup_tests) / sizeof(setup_tests[0]), setup_tests};