vcard_tester.c 36.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
	vcard_tester.c
	Copyright (C) 2015  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/>.
*/

19 20
#ifdef VCARD_ENABLED

21 22 23
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"
24
#include "carddav.h"
25

26 27
#include <time.h>

28 29
#define CARDDAV_SERVER "http://dav.linphone.org/card.php/addressbooks/tester/default"

30
static void linphone_vcard_import_export_friends_test(void) {
31
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
32 33
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const MSList *friends = linphone_friend_list_get_friends(lfl);
34
	char *import_filepath = bc_tester_res("vcards/vcards.vcf");
35
	char *export_filepath = bc_tester_file("export_vcards.vcf");
36 37
	int count = 0;
	BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
38
	
39
	count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
40
	BC_ASSERT_EQUAL(count, 3, int, "%d");
41
	friends = linphone_friend_list_get_friends(lfl);
42
	BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
43

44
	linphone_friend_list_export_friends_as_vcard4_file(lfl, export_filepath);
45

46 47
	lfl = linphone_core_create_friend_list(manager->lc);
	count = linphone_friend_list_import_friends_from_vcard4_file(lfl, export_filepath);
48
	BC_ASSERT_EQUAL(count, 3, int, "%d");
49
	friends = linphone_friend_list_get_friends(lfl);
50
	BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
51
	linphone_friend_list_unref(lfl);
52

53
	remove(export_filepath);
54 55
	ms_free(import_filepath);
	ms_free(export_filepath);
56
	linphone_core_manager_destroy(manager);
57 58
}

59 60
static void linphone_vcard_import_a_lot_of_friends_test(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
61
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
62
	char *import_filepath = bc_tester_res("vcards/thousand_vcards.vcf");
63 64
	clock_t start, end;
	double elapsed = 0;
65
	const MSList *friends = NULL;
66 67 68
	FILE    *infile = NULL;
	char    *buffer = NULL;
	long    numbytes = 0;
69 70

	start = clock();
71
	linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
72
	end = clock();
73

74
	friends = linphone_friend_list_get_friends(lfl);
75
	BC_ASSERT_EQUAL(ms_list_size(friends), 482, int, "%i"); // Thousand vcards contains 482 contacts with a SIP URI
76

77
	elapsed = (double)(end - start);
Sandrine Avakian's avatar
Sandrine Avakian committed
78
	ms_error("Imported a thousand of vCards from file (only %u friends with SIP address found) in %f seconds", (unsigned int)ms_list_size(friends), elapsed / CLOCKS_PER_SEC);
79

80
	lfl = linphone_core_create_friend_list(manager->lc);
81 82 83 84 85 86 87 88 89
	infile = fopen(import_filepath, "rb");
	BC_ASSERT_PTR_NOT_NULL(infile);
	if (infile) {
		fseek(infile, 0L, SEEK_END);
		numbytes = ftell(infile);
		fseek(infile, 0L, SEEK_SET);
		buffer = (char*)ms_malloc(numbytes * sizeof(char));
		numbytes = fread(buffer, sizeof(char), numbytes, infile);
		fclose(infile);
90

91 92 93 94 95
		start = clock();
		linphone_friend_list_import_friends_from_vcard4_buffer(lfl, buffer);
		end = clock();
		ms_free(buffer);
	}
96

97 98
	friends = linphone_friend_list_get_friends(lfl);
	BC_ASSERT_EQUAL(ms_list_size(friends), 482, int, "%i"); // Thousand vcards contains 482 contacts with a SIP URI
99

100
	elapsed = (double)(end - start);
Sandrine Avakian's avatar
Sandrine Avakian committed
101
	ms_error("Imported a thousand of vCards from buffer (only %u friends with SIP address found) in %f seconds", (unsigned int)ms_list_size(friends), elapsed / CLOCKS_PER_SEC);
102

103
	linphone_friend_list_unref(lfl);
104

105
	ms_free(import_filepath);
106 107 108
	linphone_core_manager_destroy(manager);
}

109 110
static void linphone_vcard_update_existing_friends_test(void) {
	LinphoneFriend *lf = linphone_friend_new_with_addr("sip:oldfriend@sip.linphone.org");
111

112
	BC_ASSERT_PTR_NOT_NULL(lf);
113 114 115 116 117
	BC_ASSERT_PTR_NULL(linphone_friend_get_vcard(lf));

	linphone_friend_edit(lf);
	linphone_friend_set_name(lf, "Old Friend");
	linphone_friend_done(lf);
118

119 120
	BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_vcard(lf));
	BC_ASSERT_STRING_EQUAL(linphone_vcard_get_full_name(linphone_friend_get_vcard(lf)), "Old Friend");
121 122
	linphone_friend_unref(lf);
	lf = NULL;
123 124
}

125 126 127 128 129 130
static void linphone_vcard_phone_numbers_and_sip_addresses(void) {
	LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nIMPP;TYPE=home:sip:sylvain@sip.linphone.org\r\nTEL;TYPE=work:0952636505\r\nEND:VCARD\r\n");
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
	MSList *sip_addresses = linphone_friend_get_addresses(lf);
	MSList *phone_numbers = linphone_friend_get_phone_numbers(lf);
	LinphoneAddress *addr = NULL;
131

132 133 134 135 136
	BC_ASSERT_EQUAL(ms_list_size(sip_addresses), 2, int, "%i");
	BC_ASSERT_EQUAL(ms_list_size(phone_numbers), 1, int, "%i");
	if (sip_addresses) ms_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref);
	if (phone_numbers) ms_list_free(phone_numbers);
	linphone_friend_unref(lf);
137

138 139 140 141
	lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nTEL;TYPE=work:0952636505\r\nTEL:0476010203\r\nEND:VCARD\r\n");
	lf = linphone_friend_new_from_vcard(lvc);
	sip_addresses = linphone_friend_get_addresses(lf);
	phone_numbers = linphone_friend_get_phone_numbers(lf);
142

143 144 145 146
	BC_ASSERT_EQUAL(ms_list_size(sip_addresses), 0, int, "%i");
	BC_ASSERT_EQUAL(ms_list_size(phone_numbers), 2, int, "%i");
	if (sip_addresses) ms_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref);
	if (phone_numbers) ms_list_free(phone_numbers);
147

148 149 150 151 152 153
	addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	linphone_friend_add_address(lf, addr);
	linphone_address_unref(addr);
	sip_addresses = linphone_friend_get_addresses(lf);
	BC_ASSERT_EQUAL(ms_list_size(sip_addresses), 1, int, "%i");
	if (sip_addresses) ms_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref);
154

155 156 157 158
	linphone_friend_remove_phone_number(lf, "0952636505");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
	BC_ASSERT_EQUAL(ms_list_size(phone_numbers), 1, int, "%i");
	if (phone_numbers) ms_list_free(phone_numbers);
159

160 161 162 163
	linphone_friend_remove_phone_number(lf, "0476010203");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
	BC_ASSERT_EQUAL(ms_list_size(phone_numbers), 0, int, "%i");
	if (phone_numbers) ms_list_free(phone_numbers);
164

165 166 167 168 169 170
	addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	linphone_friend_remove_address(lf, addr);
	linphone_address_unref(addr);
	sip_addresses = linphone_friend_get_addresses(lf);
	BC_ASSERT_EQUAL(ms_list_size(sip_addresses), 0, int, "%i");
	if (sip_addresses) ms_list_free_with_data(sip_addresses, (void (*)(void *))linphone_address_unref);
171

172 173 174 175
	linphone_friend_add_phone_number(lf, "+33952636505");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
	BC_ASSERT_EQUAL(ms_list_size(phone_numbers), 1, int, "%i");
	if (phone_numbers) ms_list_free(phone_numbers);
176

177 178 179 180 181
	linphone_friend_unref(lf);
	lf = NULL;
	lvc = NULL;
}

Ghislain MARY's avatar
Ghislain MARY committed
182
#ifdef SQLITE_STORAGE_ENABLED
183 184
static void friends_if_no_db_set(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
185
	LinphoneFriend *lf = linphone_core_create_friend(manager->lc);
186 187
	LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	const MSList *friends = NULL;
188
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
189

190 191
	linphone_friend_set_address(lf, addr);
	linphone_friend_set_name(lf, "Sylvain");
192 193
	linphone_friend_list_add_friend(lfl, lf);
	friends = linphone_friend_list_get_friends(lfl);
194
	BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d");
195

196 197 198
	linphone_friend_list_remove_friend(lfl, lf);
	linphone_friend_unref(lf);
	friends = linphone_friend_list_get_friends(lfl);
199
	BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
200

201
	linphone_friend_list_unref(lfl);
202
	linphone_address_unref(addr);
203 204 205 206
	linphone_core_manager_destroy(manager);
}

static void friends_migration(void) {
207
	LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE);
208
	LpConfig *lpc = linphone_core_get_config(manager->lc);
209 210
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const MSList *friends = linphone_friend_list_get_friends(lfl);
211
	MSList *friends_from_db = NULL;
212
	char *friends_db = bc_tester_file("friends.db");
213 214
	BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
	BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 0, int, "%i");
215

216 217
	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
218
	lfl = linphone_core_get_default_friend_list(manager->lc);
219
	friends = linphone_friend_list_get_friends(lfl);
220
	BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
221
	friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
222
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d");
223
	BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 1, int, "%i");
224

225
	friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
226 227 228 229 230
	unlink(friends_db);
	ms_free(friends_db);
	linphone_core_manager_destroy(manager);
}

231 232 233 234 235 236 237
typedef struct _LinphoneFriendListStats {
	int new_list_count;
	int removed_list_count;
} LinphoneFriendListStats;

static void friend_list_created_cb(LinphoneCore *lc, LinphoneFriendList *list) {
	LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list);
238 239 240
	if (stats) {
		stats->new_list_count++;
	}
241 242 243 244
}

static void friend_list_removed_cb(LinphoneCore *lc, LinphoneFriendList *list) {
	LinphoneFriendListStats *stats = (LinphoneFriendListStats *)linphone_friend_list_get_user_data(list);
245 246 247
	if (stats) {
		stats->removed_list_count++;
	}
248 249
}

250
static void friends_sqlite_storage(void) {
251 252 253
	LinphoneCoreVTable *v_table = linphone_core_v_table_new();
	LinphoneCore* lc = NULL;
	LinphoneFriendList *lfl = NULL;
254
	LinphoneFriend *lf = NULL;
255
	LinphoneFriend *lf2 = NULL;
256
	LinphoneVcard *lvc = linphone_vcard_new();
257
	LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
258
	const MSList *friends = NULL;
259
	MSList *friends_from_db = NULL;
260
	MSList *friends_lists_from_db = NULL;
261
	char *friends_db = bc_tester_file("friends.db");
262
	LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1);
263

264 265 266
	v_table->friend_list_created = friend_list_created_cb;
	v_table->friend_list_removed = friend_list_removed_cb;
	lc = linphone_core_new(v_table, NULL, NULL, NULL);
267
	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
268 269
	lfl = linphone_core_create_friend_list(lc);
	linphone_friend_list_set_user_data(lfl, stats);
270
	BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
271

272
	unlink(friends_db);
273 274
	linphone_core_set_friends_database_path(lc, friends_db);
	friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc));
275
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
276

277 278
	linphone_vcard_set_etag(lvc, "\"123-456789\"");
	linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf");
279
	lf = linphone_friend_new_from_vcard(lvc);
280 281
	linphone_friend_set_address(lf, addr);
	linphone_friend_set_name(lf, "Sylvain");
282

283 284 285
	linphone_core_add_friend_list(lc, lfl);
	wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000);
	BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i");
286
	linphone_friend_list_unref(lfl);
287
	linphone_friend_list_set_display_name(lfl, "Test");
288
	BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i");
289
	linphone_friend_unref(lf);
290 291
	BC_ASSERT_EQUAL(lfl->storage_id, 1, unsigned int, "%u");
	BC_ASSERT_EQUAL(lf->storage_id, 1, unsigned int, "%u");
292

293
	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
294
	BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
295

296
	friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc);
297
	BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d");
298 299 300 301 302
	friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends;
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
	lf2 = (LinphoneFriend *)friends_from_db->data;
	BC_ASSERT_PTR_NOT_NULL(lf2->lc);
	BC_ASSERT_PTR_NOT_NULL(lf2->friend_list);
303
	friends_lists_from_db = ms_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref);
304

305
	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
306
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
307 308 309 310 311
	if (ms_list_size(friends_from_db) < 1) {
		goto end;
	}
	lf2 = (LinphoneFriend *)friends_from_db->data;
	BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf));
312
	BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, unsigned int, "%u");
313 314
	BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf)));
	BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf)));
315 316 317 318 319 320
	BC_ASSERT_STRING_EQUAL(linphone_address_as_string(linphone_friend_get_address(lf2)), linphone_address_as_string(linphone_friend_get_address(lf)));

	linphone_friend_edit(lf);
	linphone_friend_set_name(lf, "Margaux");
	linphone_friend_done(lf);
	friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
321
	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
322 323 324 325
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
	if (ms_list_size(friends_from_db) < 1) {
		goto end;
	}
326
	lf2 = (LinphoneFriend *)friends_from_db->data;
327 328
	BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux");
	friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
329

330 331
	linphone_friend_list_remove_friend(lfl, lf);
	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
332
	BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
333
	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
334
	BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
335

336 337 338
	linphone_core_remove_friend_list(lc, lfl);
	wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000);
	BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i");
339 340

end:
341
	ms_free(stats);
342 343
	unlink(friends_db);
	ms_free(friends_db);
344
	linphone_address_unref(addr);
345
	linphone_core_destroy(lc);
346 347
}
#endif
348

349 350 351 352 353 354 355
typedef struct _LinphoneCardDAVStats {
	int sync_done_count;
	int new_contact_count;
	int removed_contact_count;
	int updated_contact_count;
} LinphoneCardDAVStats;

356
static void carddav_sync_done(LinphoneCardDavContext *c, bool_t success, const char *message) {
357
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
358
	BC_ASSERT_TRUE(success);
Sylvain Berfini's avatar
Sylvain Berfini committed
359
	stats->sync_done_count++;
360 361
}

362 363
static void carddav_new_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
364
	BC_ASSERT_PTR_NOT_NULL(lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
365
	stats->new_contact_count++;
366 367 368 369
}

static void carddav_removed_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
370
	BC_ASSERT_PTR_NOT_NULL(lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
371
	stats->removed_contact_count++;
372 373
}

374
static void carddav_updated_contact(LinphoneCardDavContext *c, LinphoneFriend *new_lf, LinphoneFriend *old_lf) {
375
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
376 377
	BC_ASSERT_PTR_NOT_NULL(new_lf);
	BC_ASSERT_PTR_NOT_NULL(old_lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
378
	stats->updated_contact_count++;
379 380
}

381
static void carddav_sync(void) {
382
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
383
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
384 385
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;
386

387
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
388
	linphone_core_add_friend_list(manager->lc, lfl);
389
	linphone_friend_list_unref(lfl);
390
	c = linphone_carddav_context_new(lfl);
391
	BC_ASSERT_PTR_NOT_NULL(c);
392

393
	linphone_carddav_set_user_data(c, stats);
394
	linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done);
395 396 397
	linphone_carddav_set_new_contact_callback(c, carddav_new_contact);
	linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact);
	linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact);
398
	linphone_carddav_synchronize(c);
399

400
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
401
	BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i");
402
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
403
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
404

Sylvain Berfini's avatar
Sylvain Berfini committed
405
	ms_free(stats);
406
	linphone_carddav_context_destroy(c);
407 408
	linphone_core_manager_destroy(manager);
}
Sylvain Berfini's avatar
Sylvain Berfini committed
409 410

static void carddav_sync_2(void) {
411
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
Sylvain Berfini's avatar
Sylvain Berfini committed
412
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
413
	LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "\"Sylvain\" <sip:sylvain@sip.linphone.org>");
414
	char *friends_db = bc_tester_file("friends.db");
415 416
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;
417

418
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
419
	linphone_core_add_friend_list(manager->lc, lfl);
420
	linphone_friend_list_unref(lfl);
421
	c = linphone_carddav_context_new(lfl);
422
	BC_ASSERT_PTR_NOT_NULL(c);
423

Sylvain Berfini's avatar
Sylvain Berfini committed
424 425
	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
426
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
Sylvain Berfini's avatar
Sylvain Berfini committed
427
	linphone_friend_unref(lf);
428

Sylvain Berfini's avatar
Sylvain Berfini committed
429 430 431 432 433
	linphone_carddav_set_user_data(c, stats);
	linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done);
	linphone_carddav_set_new_contact_callback(c, carddav_new_contact);
	linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact);
	linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact);
434

Sylvain Berfini's avatar
Sylvain Berfini committed
435
	linphone_carddav_synchronize(c);
436

437
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
438
	BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i");
439
	wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
440
	BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i");
441
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
442
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
443

Sylvain Berfini's avatar
Sylvain Berfini committed
444 445 446
	ms_free(stats);
	unlink(friends_db);
	ms_free(friends_db);
447
	linphone_carddav_context_destroy(c);
Sylvain Berfini's avatar
Sylvain Berfini committed
448 449 450 451
	linphone_core_manager_destroy(manager);
}

static void carddav_sync_3(void) {
452
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
Sylvain Berfini's avatar
Sylvain Berfini committed
453
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
454
	LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nFN:Sylvain Berfini\r\nIMPP;TYPE=work:sip:sylvain@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
455
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
456
	char *friends_db = bc_tester_file("friends.db");
457 458
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;
459

460
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
461
	linphone_core_add_friend_list(manager->lc, lfl);
462
	linphone_friend_list_unref(lfl);
463
	c = linphone_carddav_context_new(lfl);
464
	BC_ASSERT_PTR_NOT_NULL(c);
465

Sylvain Berfini's avatar
Sylvain Berfini committed
466 467
	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
468
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
Sylvain Berfini's avatar
Sylvain Berfini committed
469
	linphone_friend_unref(lf);
470

Sylvain Berfini's avatar
Sylvain Berfini committed
471 472 473 474 475
	linphone_carddav_set_user_data(c, stats);
	linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done);
	linphone_carddav_set_new_contact_callback(c, carddav_new_contact);
	linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact);
	linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact);
476

Sylvain Berfini's avatar
Sylvain Berfini committed
477
	linphone_carddav_synchronize(c);
478

479
	wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
480
	BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i");
481
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
Sylvain Berfini's avatar
Sylvain Berfini committed
482
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
Sylvain Berfini's avatar
Sylvain Berfini committed
483 484 485 486

	ms_free(stats);
	unlink(friends_db);
	ms_free(friends_db);
487
	linphone_carddav_context_destroy(c);
488
	c = NULL;
489 490 491 492
	linphone_core_manager_destroy(manager);
}

static void carddav_sync_4(void) {
493
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
494
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
495
	LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
496
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
497 498
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;
499

500
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
501
	linphone_core_add_friend_list(manager->lc, lfl);
502
	linphone_friend_list_unref(lfl);
503
	c = linphone_carddav_context_new(lfl);
504
	BC_ASSERT_PTR_NOT_NULL(c);
505

506 507
	linphone_carddav_set_user_data(c, stats);
	linphone_carddav_set_synchronization_done_callback(c, carddav_sync_done);
508 509 510
	linphone_carddav_set_new_contact_callback(c, carddav_new_contact);
	linphone_carddav_set_removed_contact_callback(c, carddav_removed_contact);
	linphone_carddav_set_updated_contact_callback(c, carddav_updated_contact);
511 512

	BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
513
	linphone_carddav_put_vcard(c, lf);
514
	BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
515
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
516
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
517

518
	linphone_carddav_delete_vcard(c, lf);
519
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 5000);
520 521 522 523
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");

	linphone_friend_unref(lf);
	ms_free(stats);
524 525 526 527 528 529 530 531 532 533 534 535 536 537
	linphone_carddav_context_destroy(c);
	linphone_core_manager_destroy(manager);
}

static void carddav_contact_created(LinphoneFriendList *list, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
	stats->new_contact_count++;
}

static void carddav_contact_deleted(LinphoneFriendList *list, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
	stats->removed_contact_count++;
}

538 539
static void carddav_contact_updated(LinphoneFriendList *list, LinphoneFriend *new_friend, LinphoneFriend *old_friend) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
540
	BC_ASSERT_STRING_EQUAL(linphone_vcard_get_full_name(linphone_friend_get_vcard(new_friend)), linphone_vcard_get_full_name(linphone_friend_get_vcard(old_friend)));
541 542 543
	stats->updated_contact_count++;
}

544 545 546 547 548 549 550 551 552
static void carddav_sync_status_changed(LinphoneFriendList *list, LinphoneFriendListSyncStatus status, const char *msg) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(list->cbs);
	char *state = status == LinphoneFriendListSyncStarted ? "Sync started" : (status == LinphoneFriendListSyncFailure ? "Sync failure" : "Sync successful");
	ms_message("[CardDAV] %s : %s", state, msg);
	if (status == LinphoneFriendListSyncFailure || status == LinphoneFriendListSyncSuccessful) {
		stats->sync_done_count++;
	}
}

553
static void carddav_integration(void) {
554
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
555
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
556
	LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
557
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
558
	LinphoneVcard *lvc2 = NULL;
559
	LinphoneFriend *lf2 = NULL;
560 561
	LinphoneFriendListCbs *cbs = NULL;
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
562
	const char *refkey = "toto";
563

564
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
565 566 567 568
	cbs = linphone_friend_list_get_callbacks(lfl);
	linphone_friend_list_cbs_set_user_data(cbs, stats);
	linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);
	linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);
569
	linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated);
570
	linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed);
571
	linphone_core_add_friend_list(manager->lc, lfl);
572 573

	BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
574
	BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d");
575
	BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
576
	BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 1, int, "%d");
577
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
578
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
579 580
	BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d");
	BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
581
	linphone_friend_list_remove_friend(lfl, lf);
582
	BC_ASSERT_EQUAL(ms_list_size(lfl->friends), 0, int, "%d");
583
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 5000);
584
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");
585
	linphone_friend_unref(lf);
586
	lf = NULL;
587 588 589

	lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n");
	lf = linphone_friend_new_from_vcard(lvc);
590
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
591
	linphone_friend_unref(lf);
592

593
	lvc2 = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n");
594
	linphone_vcard_set_url(lvc2, "/card.php/addressbooks/tester/default/me.vcf");
595
	lf2 = linphone_friend_new_from_vcard(lvc2);
596
	linphone_friend_set_ref_key(lf2, refkey);
597
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf2), LinphoneFriendListOK, int, "%d");
598

599 600
	BC_ASSERT_EQUAL(lfl->revision, 0, int, "%i");
	linphone_friend_list_synchronize_friends_from_server(lfl);
601
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 0, 5000);
602
	BC_ASSERT_EQUAL(stats->new_contact_count, 0, int, "%i");
603
	wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 5000);
604
	BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i");
605
	wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, 5000);
606
	BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i");
607
	BC_ASSERT_NOT_EQUAL(lfl->revision, 0, int, "%i");
608
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, 5000);
609
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");
610

611
	BC_ASSERT_EQUAL(ms_list_size(lfl->friends), 1, int, "%i");
612
	lf = (LinphoneFriend *)lfl->friends->data;
613
	BC_ASSERT_STRING_EQUAL(lf->refkey, refkey);
614
	BC_ASSERT_EQUAL(lf->storage_id, lf2->storage_id, unsigned int, "%u");
615
	linphone_friend_unref(lf2);
616
	BC_ASSERT_STRING_EQUAL(linphone_address_as_string_uri_only(lf->uri), "sip:sylvain@sip.linphone.org");
617

618 619 620
	linphone_friend_edit(lf);
	linphone_friend_done(lf);
	BC_ASSERT_EQUAL(ms_list_size(lf->friend_list->dirty_friends_to_update), 0, int, "%i");
621

622 623 624 625 626
	linphone_core_set_network_reachable(manager->lc, FALSE); //To prevent the CardDAV update
	linphone_friend_edit(lf);
	linphone_friend_set_name(lf, "François Grisez");
	linphone_friend_done(lf);
	BC_ASSERT_EQUAL(ms_list_size(lf->friend_list->dirty_friends_to_update), 1, int, "%i");
627

628 629
	ms_free(stats);
	linphone_friend_list_unref(lfl);
Sylvain Berfini's avatar
Sylvain Berfini committed
630 631 632
	linphone_core_manager_destroy(manager);
}

633 634 635 636 637 638
static void carddav_clean(void) {  // This is to ensure the content of the test addressbook is in the correct state for the following tests
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(lfl);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
	MSList *friends = NULL;
639
	MSList *friends_iterator = NULL;
640
	LinphoneFriend *lf = NULL;
641
	LinphoneVcard *lvc = NULL;
642

643 644 645 646
	linphone_friend_list_cbs_set_user_data(cbs, stats);
	linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);
	linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);
	linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated);
647
	linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed);
648
	linphone_core_add_friend_list(manager->lc, lfl);
649
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
650

651
	linphone_friend_list_synchronize_friends_from_server(lfl);
652
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
653 654
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
	stats->sync_done_count = 0;
655

656
	friends = ms_list_copy(lfl->friends);
657 658 659
	friends_iterator = friends;
	while (friends_iterator) {
		LinphoneFriend *lf = (LinphoneFriend *)friends_iterator->data;
660
		linphone_friend_list_remove_friend(lfl, lf);
661
		wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
662 663
		BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
		stats->sync_done_count = 0;
664
		stats->removed_contact_count = 0;
665
		friends_iterator = ms_list_next(friends_iterator);
666
	}
667
	ms_list_free(friends);
668

669
	lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sylvain@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n");
670
	linphone_vcard_set_url(lvc, "http://dav.linphone.org/card.php/addressbooks/tester/default/me.vcf");
671 672
	lf = linphone_friend_new_from_vcard(lvc);
	linphone_friend_list_add_friend(lfl, lf);
673
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
674
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
675

676 677 678 679 680 681
	ms_free(stats);
	linphone_friend_unref(lf);
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

682 683 684 685 686
static void carddav_multiple_sync(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(lfl);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
687

688 689 690 691
	linphone_friend_list_cbs_set_user_data(cbs, stats);
	linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);
	linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);
	linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated);
692
	linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed);
693
	linphone_core_add_friend_list(manager->lc, lfl);
694
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
695

696
	linphone_friend_list_synchronize_friends_from_server(lfl);
697
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
698
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
699
	linphone_friend_list_synchronize_friends_from_server(lfl);
700
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 5000);
701
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");
702
	linphone_friend_list_synchronize_friends_from_server(lfl);
703
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, 5000);
704
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");
705
	BC_ASSERT_EQUAL(stats->removed_contact_count, 0, int, "%i");
706

707
	ms_free(stats);
708 709 710 711
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

712 713 714 715 716 717 718 719 720
static void carddav_server_to_client_and_client_to_sever_sync(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(lfl);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
	LinphoneVcard *lvc1 = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
	LinphoneFriend *lf1 = linphone_friend_new_from_vcard(lvc1);
	LinphoneVcard *lvc2 = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n");
	LinphoneFriend *lf2 = linphone_friend_new_from_vcard(lvc2);
721
	MSList *friends = NULL, *friends_iterator = NULL;
722

723 724 725 726 727 728 729
	linphone_friend_list_cbs_set_user_data(cbs, stats);
	linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created);
	linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted);
	linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated);
	linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed);
	linphone_core_add_friend_list(manager->lc, lfl);
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
730

731
	linphone_friend_list_add_friend(lfl, lf1);
732
	linphone_friend_unref(lf1);
733 734
	linphone_friend_list_synchronize_friends_from_server(lfl);
	linphone_friend_list_add_friend(lfl, lf2);
735
	linphone_friend_unref(lf2);
736 737
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, 15000);
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");
738

739 740 741 742 743 744 745 746 747 748 749 750 751 752
	stats->sync_done_count = 0;
	friends = ms_list_copy(lfl->friends);
	friends_iterator = friends;
	while (friends_iterator) {
		LinphoneFriend *lf = (LinphoneFriend *)friends_iterator->data;
		if (lf && strcmp(linphone_friend_get_name(lf), "Sylvain Berfini") != 0) {
			linphone_friend_list_remove_friend(lfl, lf);
			wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000);
			BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
			stats->sync_done_count = 0;
		}
		friends_iterator = ms_list_next(friends_iterator);
	}
	ms_list_free(friends);
753 754

	ms_free(stats);
755
	linphone_friend_list_unref(lfl);
756 757 758
	linphone_core_manager_destroy(manager);
}

759
test_t vcard_tests[] = {
760 761 762 763
	TEST_NO_TAG("Import / Export friends from vCards", linphone_vcard_import_export_friends_test),
	TEST_NO_TAG("Import a lot of friends from vCards", linphone_vcard_import_a_lot_of_friends_test),
	TEST_NO_TAG("vCard creation for existing friends", linphone_vcard_update_existing_friends_test),
	TEST_NO_TAG("vCard phone numbers and SIP addresses", linphone_vcard_phone_numbers_and_sip_addresses),
Ghislain MARY's avatar
Ghislain MARY committed
764
#ifdef SQLITE_STORAGE_ENABLED
765 766 767
	TEST_ONE_TAG("Friends working if no db set", friends_if_no_db_set, "LeaksMemory"),
	TEST_ONE_TAG("Friends storage migration from rc to db", friends_migration, "LeaksMemory"),
	TEST_NO_TAG("Friends storage in sqlite database", friends_sqlite_storage),
768
#endif
769 770 771 772 773 774 775 776
	TEST_NO_TAG("CardDAV clean", carddav_clean), // This is to ensure the content of the test addressbook is in the correct state for the following tests
	TEST_NO_TAG("CardDAV synchronization", carddav_sync),
	TEST_NO_TAG("CardDAV synchronization 2", carddav_sync_2),
	TEST_NO_TAG("CardDAV synchronization 3", carddav_sync_3),
	TEST_NO_TAG("CardDAV synchronization 4", carddav_sync_4),
	TEST_NO_TAG("CardDAV integration", carddav_integration),
	TEST_NO_TAG("CardDAV multiple synchronizations", carddav_multiple_sync),
	TEST_NO_TAG("CardDAV client to server and server to client sync", carddav_server_to_client_and_client_to_sever_sync)
777 778 779
};

test_suite_t vcard_test_suite = {
780
	"VCard", NULL, NULL,
781 782 783
	liblinphone_tester_before_each, liblinphone_tester_after_each,
	sizeof(vcard_tests) / sizeof(vcard_tests[0]), vcard_tests
};
784 785

#endif