vcard_tester.c 46.3 KB
Newer Older
Sylvain Berfini's avatar
Sylvain Berfini committed
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
#include "linphone/core.h"
Simon Morlat's avatar
Simon Morlat committed
20 21 22 23

#ifdef VCARD_ENABLED


Sylvain Berfini's avatar
Sylvain Berfini committed
24
#include "liblinphone_tester.h"
25
#include "carddav.h"
26
#include <bctoolbox/map.h>
Sylvain Berfini's avatar
Sylvain Berfini committed
27 28 29

#include <time.h>
#define CARDDAV_SERVER "http://dav.linphone.org/card.php/addressbooks/tester/default"
30
#define CARDDAV_SYNC_TIMEOUT 15000
Sylvain Berfini's avatar
Sylvain Berfini committed
31 32 33 34 35 36 37 38

static void linphone_vcard_import_export_friends_test(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const bctbx_list_t *friends = linphone_friend_list_get_friends(lfl);
	char *import_filepath = bc_tester_res("vcards/vcards.vcf");
	char *export_filepath = bc_tester_file("export_vcards.vcf");
	int count = 0;
Ghislain MARY's avatar
Ghislain MARY committed
39
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
40 41 42 43
	
	count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
	BC_ASSERT_EQUAL(count, 3, int, "%d");
	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
44
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 3, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
45 46 47 48 49 50 51

	linphone_friend_list_export_friends_as_vcard4_file(lfl, export_filepath);

	lfl = linphone_core_create_friend_list(manager->lc);
	count = linphone_friend_list_import_friends_from_vcard4_file(lfl, export_filepath);
	BC_ASSERT_EQUAL(count, 3, int, "%d");
	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
52
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 3, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
53 54 55
	linphone_friend_list_unref(lfl);

	remove(export_filepath);
56 57
	bc_free(import_filepath);
	bc_free(export_filepath);
Sylvain Berfini's avatar
Sylvain Berfini committed
58 59 60 61 62 63 64 65 66 67 68 69 70
	linphone_core_manager_destroy(manager);
}

static void linphone_vcard_import_a_lot_of_friends_test(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	char *import_filepath = bc_tester_res("vcards/thousand_vcards.vcf");
	clock_t start, end;
	double elapsed = 0;
	const bctbx_list_t *friends = NULL;
	FILE    *infile = NULL;
	char    *buffer = NULL;
	long    numbytes = 0;
Ghislain MARY's avatar
Ghislain MARY committed
71
	size_t readbytes;
Sylvain Berfini's avatar
Sylvain Berfini committed
72 73 74 75 76 77

	start = clock();
	linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
	end = clock();

	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
78
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 1000, unsigned int, "%u"); // Now that we accept Friends without a SIP URI, the result must be equal to 1000
Sylvain Berfini's avatar
Sylvain Berfini committed
79 80

	elapsed = (double)(end - start);
Sylvain Berfini's avatar
Sylvain Berfini committed
81
	ms_message("Imported a thousand of vCards from file in %f seconds", elapsed / CLOCKS_PER_SEC);
Sylvain Berfini's avatar
Sylvain Berfini committed
82 83 84 85 86 87 88 89 90

	lfl = linphone_core_create_friend_list(manager->lc);
	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 + 1) * sizeof(char));
Ghislain MARY's avatar
Ghislain MARY committed
91
		readbytes = fread(buffer, sizeof(char), numbytes, infile);
Sylvain Berfini's avatar
Sylvain Berfini committed
92
		fclose(infile);
Ghislain MARY's avatar
Ghislain MARY committed
93
		buffer[readbytes] = '\0';
Sylvain Berfini's avatar
Sylvain Berfini committed
94 95 96 97 98 99 100 101

		start = clock();
		linphone_friend_list_import_friends_from_vcard4_buffer(lfl, buffer);
		end = clock();
		ms_free(buffer);
	}

	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
102
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 1000, unsigned int, "%u"); // Now that we accept Friends without a SIP URI, the result must be equal to 1000
Sylvain Berfini's avatar
Sylvain Berfini committed
103 104

	elapsed = (double)(end - start);
Sylvain Berfini's avatar
Sylvain Berfini committed
105
	ms_message("Imported a thousand of vCards from buffer in %f seconds", elapsed / CLOCKS_PER_SEC);
Sylvain Berfini's avatar
Sylvain Berfini committed
106 107 108

	linphone_friend_list_unref(lfl);

109
	bc_free(import_filepath);
Sylvain Berfini's avatar
Sylvain Berfini committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	linphone_core_manager_destroy(manager);
}

#if __clang__ || ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4)
#pragma GCC diagnostic push
#endif
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#else
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

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

	BC_ASSERT_PTR_NOT_NULL(lf);
	if (linphone_core_vcard_supported()) {
		BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_vcard(lf));
	} else {
		BC_ASSERT_PTR_NULL(linphone_friend_get_vcard(lf));
	}

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

	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");
	linphone_friend_unref(lf);
	lf = NULL;
}

#if __clang__ || ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4)
#pragma GCC diagnostic pop
#endif

static void linphone_vcard_phone_numbers_and_sip_addresses(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
148
	LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "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");
Sylvain Berfini's avatar
Sylvain Berfini committed
149
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
150
	linphone_vcard_unref(lvc);
151
	const bctbx_list_t *sip_addresses = linphone_friend_get_addresses(lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
152 153 154
	bctbx_list_t *phone_numbers = linphone_friend_get_phone_numbers(lf);
	LinphoneAddress *addr = NULL;

Ghislain MARY's avatar
Ghislain MARY committed
155 156
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 2, unsigned int, "%u");
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
157 158 159
	if (phone_numbers) bctbx_list_free(phone_numbers);
	linphone_friend_unref(lf);

160
	lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nTEL;TYPE=work:0952636505\r\nTEL:0476010203\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
161
	lf = linphone_friend_new_from_vcard(lvc);
162
	linphone_vcard_unref(lvc);
163
	linphone_friend_set_core(lf, manager->lc);
Sylvain Berfini's avatar
Sylvain Berfini committed
164 165 166
	sip_addresses = linphone_friend_get_addresses(lf);
	phone_numbers = linphone_friend_get_phone_numbers(lf);

Ghislain MARY's avatar
Ghislain MARY committed
167 168
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 0, unsigned int, "%u");
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 2, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
169 170 171 172 173
	if (phone_numbers) bctbx_list_free(phone_numbers);

	addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	linphone_friend_add_address(lf, addr);
	sip_addresses = linphone_friend_get_addresses(lf);
Ghislain MARY's avatar
Ghislain MARY committed
174
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
175 176 177

	linphone_friend_remove_phone_number(lf, "0952636505");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
Ghislain MARY's avatar
Ghislain MARY committed
178
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
179 180 181 182
	if (phone_numbers) bctbx_list_free(phone_numbers);

	linphone_friend_remove_phone_number(lf, "0476010203");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
Ghislain MARY's avatar
Ghislain MARY committed
183
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
184 185
	if (phone_numbers) bctbx_list_free(phone_numbers);

186
	linphone_friend_edit(lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
187
	linphone_friend_remove_address(lf, addr);
188
	linphone_friend_done(lf);
Sylvain Berfini's avatar
Sylvain Berfini committed
189
	sip_addresses = linphone_friend_get_addresses(lf);
Ghislain MARY's avatar
Ghislain MARY committed
190
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(sip_addresses), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
191 192 193

	linphone_friend_add_phone_number(lf, "+33952636505");
	phone_numbers = linphone_friend_get_phone_numbers(lf);
Ghislain MARY's avatar
Ghislain MARY committed
194
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(phone_numbers), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
195 196
	if (phone_numbers) bctbx_list_free(phone_numbers);

197
	linphone_address_unref(addr);
Sylvain Berfini's avatar
Sylvain Berfini committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	linphone_friend_unref(lf);
	lf = NULL;
	lvc = NULL;
	linphone_core_manager_destroy(manager);
}

#ifdef SQLITE_STORAGE_ENABLED
static void friends_if_no_db_set(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriend *lf = linphone_core_create_friend(manager->lc);
	LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	const bctbx_list_t *friends = NULL;
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);

	linphone_friend_set_address(lf, addr);
	linphone_friend_set_name(lf, "Sylvain");
	linphone_friend_list_add_friend(lfl, lf);
	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
216
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
217 218 219 220

	linphone_friend_list_remove_friend(lfl, lf);
	linphone_friend_unref(lf);
	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
221
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
222 223 224 225 226 227 228 229 230 231 232 233 234

	linphone_friend_list_unref(lfl);
	linphone_address_unref(addr);
	linphone_core_manager_destroy(manager);
}

static void friends_migration(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE);
	LpConfig *lpc = linphone_core_get_config(manager->lc);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	const bctbx_list_t *friends = linphone_friend_list_get_friends(lfl);
	bctbx_list_t *friends_from_db = NULL;
	char *friends_db = bc_tester_file("friends.db");
Ghislain MARY's avatar
Ghislain MARY committed
235
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 3, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
236 237 238 239 240 241
	BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 0, int, "%i");

	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
	lfl = linphone_core_get_default_friend_list(manager->lc);
	friends = linphone_friend_list_get_friends(lfl);
Ghislain MARY's avatar
Ghislain MARY committed
242
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 3, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
243
	friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
Ghislain MARY's avatar
Ghislain MARY committed
244
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 3, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
245 246 247
	BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 1, int, "%i");

	friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
248
	linphone_core_manager_destroy(manager);
Sylvain Berfini's avatar
Sylvain Berfini committed
249
	unlink(friends_db);
250
	bc_free(friends_db);
Sylvain Berfini's avatar
Sylvain Berfini committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
}

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);
	if (stats) {
		stats->new_list_count++;
	}
}

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

static void friends_sqlite_storage(void) {
	LinphoneCore* lc = NULL;
Ghislain MARY's avatar
Ghislain MARY committed
274
	LinphoneCoreCbs *cbs;
Sylvain Berfini's avatar
Sylvain Berfini committed
275 276 277
	LinphoneFriendList *lfl = NULL;
	LinphoneFriend *lf = NULL;
	LinphoneFriend *lf2 = NULL;
Ghislain MARY's avatar
Ghislain MARY committed
278
	LinphoneVcard *lvc = linphone_factory_create_vcard(linphone_factory_get());
Sylvain Berfini's avatar
Sylvain Berfini committed
279 280 281 282 283 284
	LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
	const bctbx_list_t *friends = NULL;
	bctbx_list_t *friends_from_db = NULL;
	bctbx_list_t *friends_lists_from_db = NULL;
	char *friends_db = bc_tester_file("friends.db");
	LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1);
Simon Morlat's avatar
Simon Morlat committed
285
	const LinphoneAddress *laddress = NULL, *laddress2 = NULL;
Sylvain Berfini's avatar
Sylvain Berfini committed
286 287
	char *address = NULL, *address2 = NULL;

Ghislain MARY's avatar
Ghislain MARY committed
288 289 290 291 292
	cbs = linphone_factory_create_core_cbs(linphone_factory_get());
	linphone_core_cbs_set_friend_list_created(cbs, friend_list_created_cb);
	linphone_core_cbs_set_friend_list_removed(cbs, friend_list_removed_cb);
	lc = linphone_factory_create_core(linphone_factory_get(), cbs, NULL, NULL);
	linphone_core_cbs_unref(cbs);
Sylvain Berfini's avatar
Sylvain Berfini committed
293 294 295
	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
	lfl = linphone_core_create_friend_list(lc);
	linphone_friend_list_set_user_data(lfl, stats);
Ghislain MARY's avatar
Ghislain MARY committed
296
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
297 298 299 300

	unlink(friends_db);
	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));
Ghislain MARY's avatar
Ghislain MARY committed
301
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
302 303 304 305

	linphone_vcard_set_etag(lvc, "\"123-456789\"");
	linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf");
	lf = linphone_friend_new_from_vcard(lvc);
306
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
307 308 309 310 311 312 313 314 315 316
	linphone_friend_set_address(lf, addr);
	linphone_friend_set_name(lf, "Sylvain");

	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");
	linphone_friend_list_unref(lfl);
	linphone_friend_list_set_display_name(lfl, "Test");
	BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i");
	linphone_friend_unref(lf);
317 318
	BC_ASSERT_EQUAL(linphone_friend_list_get_storage_id(lfl), 1, unsigned int, "%u");
	BC_ASSERT_EQUAL(linphone_friend_get_storage_id(lf), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
319 320

	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
Ghislain MARY's avatar
Ghislain MARY committed
321
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
322 323

	friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc);
Ghislain MARY's avatar
Ghislain MARY committed
324
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_lists_from_db), 1, unsigned int, "%u");
325
	friends_from_db = *linphone_friend_list_get_friends_attribute((LinphoneFriendList *)bctbx_list_get_data(friends_lists_from_db));
Ghislain MARY's avatar
Ghislain MARY committed
326
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
327
	lf2 = (LinphoneFriend *)friends_from_db->data;
328 329
	BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_core(lf2));
	BC_ASSERT_PTR_NOT_NULL(linphone_friend_get_friend_list(lf2));
Sylvain Berfini's avatar
Sylvain Berfini committed
330 331 332
	friends_lists_from_db = bctbx_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref);

	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
Ghislain MARY's avatar
Ghislain MARY committed
333
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
334 335 336 337 338
	if (bctbx_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));
339
	BC_ASSERT_EQUAL(linphone_friend_get_storage_id(lf2), linphone_friend_get_storage_id(lf), unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
340 341 342 343 344 345 346
	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)));
	laddress = linphone_friend_get_address(lf);
	address = linphone_address_as_string(laddress);
	laddress2 = linphone_friend_get_address(lf2);
	address2 = linphone_address_as_string(laddress2);
	BC_ASSERT_STRING_EQUAL(address2, address);
Simon Morlat's avatar
Simon Morlat committed
347
	
Sylvain Berfini's avatar
Sylvain Berfini committed
348 349 350 351 352 353 354 355
	ms_free(address);
	ms_free(address2);

	linphone_friend_edit(lf);
	linphone_friend_set_name(lf, "Margaux");
	linphone_friend_done(lf);
	friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
Ghislain MARY's avatar
Ghislain MARY committed
356
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
357 358 359 360 361 362 363 364 365
	if (bctbx_list_size(friends_from_db) < 1) {
		goto end;
	}
	lf2 = (LinphoneFriend *)friends_from_db->data;
	BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux");
	friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);

	linphone_friend_list_remove_friend(lfl, lf);
	friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
Ghislain MARY's avatar
Ghislain MARY committed
366
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
367
	friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
Ghislain MARY's avatar
Ghislain MARY committed
368
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(friends_from_db), 0, unsigned int, "%u");
Simon Morlat's avatar
Simon Morlat committed
369
	friends_from_db = bctbx_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
Sylvain Berfini's avatar
Sylvain Berfini committed
370 371 372 373 374 375 376 377

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

end:
	ms_free(stats);
	linphone_address_unref(addr);
Ghislain MARY's avatar
Ghislain MARY committed
378
	linphone_core_unref(lc);
379 380
	unlink(friends_db);
	bc_free(friends_db);
Sylvain Berfini's avatar
Sylvain Berfini committed
381
}
382 383

static void friends_sqlite_store_lot_of_friends(void) {
Ghislain MARY's avatar
Ghislain MARY committed
384
	LinphoneCore* lc = linphone_factory_create_core(linphone_factory_get(), NULL, NULL, NULL);
385 386 387 388 389 390
	sqlite3 *db;
	int i;
	char* errmsg = NULL;
	int ret;
	char *buf;

391
	ret = sqlite3_open(linphone_core_get_friends_database_path(lc), &db);
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	
	ret = sqlite3_exec(db,
					   "CREATE TABLE IF NOT EXISTS friends ("
					   "id                INTEGER PRIMARY KEY AUTOINCREMENT,"
					   "friend_list_id    INTEGER,"
					   "sip_uri           TEXT,"
					   "subscribe_policy  INTEGER,"
					   "send_subscribe    INTEGER,"
					   "ref_key           TEXT,"
					   "vCard             TEXT,"
					   "vCard_etag        TEXT,"
					   "vCard_url         TEXT,"
					   "presence_received INTEGER"
					   ");", 0, 0, &errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);

Simon Morlat's avatar
Simon Morlat committed
413
	ms_message("Start :\n");
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	for (i = 0; i < 20000; i++) {
		buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%u,%Q,%i,%i,'key_%i',%Q,%Q,%Q,%i);",
							  i,
							  "dummy_addr",
							  0,
							  0,
							  i,
							  NULL,
							  NULL,
							  NULL,
							  0
							  );

		ret = sqlite3_exec(db,buf,0,0,&errmsg);
		BC_ASSERT_TRUE(ret ==SQLITE_OK);
		sqlite3_free(buf);
	}
	
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	
Simon Morlat's avatar
Simon Morlat committed
437
	ms_message("End :\n");
438 439 440 441 442 443 444 445
	
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db, "DELETE FROM friends;",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	sqlite3_close(db);
Ghislain MARY's avatar
Ghislain MARY committed
446
	linphone_core_unref(lc);
447 448 449
}

static void friends_sqlite_find_friend_in_lot_of_friends(void) {
Ghislain MARY's avatar
Ghislain MARY committed
450
	LinphoneCore* lc = linphone_factory_create_core(linphone_factory_get(), NULL, NULL, NULL);
451 452 453 454 455 456 457 458
	sqlite3 *db;
	int i;
	char* errmsg = NULL;
	int ret;
	char *buf;
	bctoolboxTimeSpec t1;
	bctoolboxTimeSpec t2;

459
	ret = sqlite3_open(linphone_core_get_friends_database_path(lc), &db);
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	
	ret = sqlite3_exec(db,
					   "CREATE TABLE IF NOT EXISTS friends ("
					   "id                INTEGER PRIMARY KEY AUTOINCREMENT,"
					   "friend_list_id    INTEGER,"
					   "sip_uri           TEXT,"
					   "subscribe_policy  INTEGER,"
					   "send_subscribe    INTEGER,"
					   "ref_key           TEXT,"
					   "vCard             TEXT,"
					   "vCard_etag        TEXT,"
					   "vCard_url         TEXT,"
					   "presence_received INTEGER"
					   ");", 0, 0, &errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	for (i = 0; i < 20000; i++) {
		buf = sqlite3_mprintf("INSERT INTO friends VALUES(NULL,%u,%Q,%i,%i,'key_%i',%Q,%Q,%Q,%i);",
							  i,
							  "dummy_addr",
							  0,
							  0,
							  i,
							  NULL,
							  NULL,
							  NULL,
							  0
							  );
		
		ret = sqlite3_exec(db,buf,0,0,&errmsg);
		BC_ASSERT_TRUE(ret ==SQLITE_OK);
		sqlite3_free(buf);
		//ms_message("%i",i);
	}
	
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	
	bctbx_get_cur_time(&t1);
Simon Morlat's avatar
Simon Morlat committed
506
	ms_message("Start : %li : %li\n", (long int)t1.tv_sec, (long int)t1.tv_nsec);
507 508 509 510 511 512 513 514 515 516
	for (i = 0; i < 20000; i++) {
		buf = sqlite3_mprintf("SELECT * FROM friends WHERE ref_key LIKE 'key_%i';",
							  i);
		
		ret = sqlite3_exec(db,buf,0,0,&errmsg);
		BC_ASSERT_TRUE(ret ==SQLITE_OK);
		sqlite3_free(buf);
	}
	
	bctbx_get_cur_time(&t2);
Simon Morlat's avatar
Simon Morlat committed
517
	ms_message("End : %li : %li\n", (long int)t2.tv_sec, (long int)t2.tv_nsec);
518 519 520 521 522 523 524 525
	
	ret = sqlite3_exec(db,"BEGIN",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db, "DELETE FROM friends;",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	ret = sqlite3_exec(db,"END",0,0,&errmsg);
	BC_ASSERT_TRUE(ret ==SQLITE_OK);
	sqlite3_close(db);
Ghislain MARY's avatar
Ghislain MARY committed
526
	linphone_core_unref(lc);
527 528
}

Sylvain Berfini's avatar
Sylvain Berfini committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
#endif

typedef struct _LinphoneCardDAVStats {
	int sync_done_count;
	int new_contact_count;
	int removed_contact_count;
	int updated_contact_count;
} LinphoneCardDAVStats;

static void carddav_sync_done(LinphoneCardDavContext *c, bool_t success, const char *message) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
	BC_ASSERT_TRUE(success);
	stats->sync_done_count++;
}

static void carddav_new_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
	BC_ASSERT_PTR_NOT_NULL(lf);
	stats->new_contact_count++;
}

static void carddav_removed_contact(LinphoneCardDavContext *c, LinphoneFriend *lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
	BC_ASSERT_PTR_NOT_NULL(lf);
	stats->removed_contact_count++;
}

static void carddav_updated_contact(LinphoneCardDavContext *c, LinphoneFriend *new_lf, LinphoneFriend *old_lf) {
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_carddav_get_user_data(c);
	BC_ASSERT_PTR_NOT_NULL(new_lf);
	BC_ASSERT_PTR_NOT_NULL(old_lf);
	stats->updated_contact_count++;
}

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

	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
	linphone_core_add_friend_list(manager->lc, lfl);
	linphone_friend_list_unref(lfl);
	c = linphone_carddav_context_new(lfl);
	BC_ASSERT_PTR_NOT_NULL(c);

	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);
	linphone_carddav_synchronize(c);

582
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
583
	BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i");
584
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");

	ms_free(stats);
	linphone_carddav_context_destroy(c);
	linphone_core_manager_destroy(manager);
}

static void carddav_sync_2(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
	LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "\"Sylvain\" <sip:sylvain@sip.linphone.org>");
	char *friends_db = bc_tester_file("friends.db");
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;

	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
	linphone_core_add_friend_list(manager->lc, lfl);
	linphone_friend_list_unref(lfl);
	c = linphone_carddav_context_new(lfl);
	BC_ASSERT_PTR_NOT_NULL(c);

	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
	linphone_friend_unref(lf);

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

	linphone_carddav_synchronize(c);

619
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
620
	BC_ASSERT_EQUAL(stats->new_contact_count, 1, int, "%i");
621
	wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
622
	BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i");
623
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
624 625 626 627 628
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");

	ms_free(stats);
	linphone_carddav_context_destroy(c);
	linphone_core_manager_destroy(manager);
629 630
	unlink(friends_db);
	bc_free(friends_db);
Sylvain Berfini's avatar
Sylvain Berfini committed
631 632 633 634 635
}

static void carddav_sync_3(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
636
	LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "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
637 638 639 640 641
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
	char *friends_db = bc_tester_file("friends.db");
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;

642
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
	linphone_core_add_friend_list(manager->lc, lfl);
	linphone_friend_list_unref(lfl);
	c = linphone_carddav_context_new(lfl);
	BC_ASSERT_PTR_NOT_NULL(c);

	unlink(friends_db);
	linphone_core_set_friends_database_path(manager->lc, friends_db);
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
	linphone_friend_unref(lf);

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

	linphone_carddav_synchronize(c);

662
	wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
663
	BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i");
664
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
665 666 667 668 669
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");

	ms_free(stats);
	linphone_carddav_context_destroy(c);
	linphone_core_manager_destroy(manager);
670 671
	unlink(friends_db);
	bc_free(friends_db);
Sylvain Berfini's avatar
Sylvain Berfini committed
672 673 674 675 676
}

static void carddav_sync_4(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
677
	LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
678 679 680 681
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
	LinphoneCardDavContext *c = NULL;

682
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
	linphone_core_add_friend_list(manager->lc, lfl);
	linphone_friend_list_unref(lfl);
	c = linphone_carddav_context_new(lfl);
	BC_ASSERT_PTR_NOT_NULL(c);

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

	BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
	linphone_carddav_put_vcard(c, lf);
	BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
698
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
699 700 701
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");

	linphone_carddav_delete_vcard(c, lf);
702
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
703 704 705 706 707 708 709 710 711
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");

	linphone_friend_unref(lf);
	ms_free(stats);
	linphone_carddav_context_destroy(c);
	linphone_core_manager_destroy(manager);
}

static void carddav_contact_created(LinphoneFriendList *list, LinphoneFriend *lf) {
712
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(linphone_friend_list_get_callbacks(list));
Sylvain Berfini's avatar
Sylvain Berfini committed
713 714 715 716
	stats->new_contact_count++;
}

static void carddav_contact_deleted(LinphoneFriendList *list, LinphoneFriend *lf) {
717
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(linphone_friend_list_get_callbacks(list));
Sylvain Berfini's avatar
Sylvain Berfini committed
718 719 720 721
	stats->removed_contact_count++;
}

static void carddav_contact_updated(LinphoneFriendList *list, LinphoneFriend *new_friend, LinphoneFriend *old_friend) {
722
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(linphone_friend_list_get_callbacks(list));
Sylvain Berfini's avatar
Sylvain Berfini committed
723 724 725 726 727
	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)));
	stats->updated_contact_count++;
}

static void carddav_sync_status_changed(LinphoneFriendList *list, LinphoneFriendListSyncStatus status, const char *msg) {
728
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)linphone_friend_list_cbs_get_user_data(linphone_friend_list_get_callbacks(list));
Sylvain Berfini's avatar
Sylvain Berfini committed
729 730 731 732 733 734 735 736 737 738
	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++;
	}
}

static void carddav_integration(void) {
	LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
739
	LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
740 741 742 743 744 745 746
	LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc);
	LinphoneVcard *lvc2 = NULL;
	LinphoneFriend *lf2 = NULL;
	LinphoneFriendListCbs *cbs = NULL;
	LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1);
	const char *refkey = "toto";
	char *address = NULL;
Simon Morlat's avatar
Simon Morlat committed
747
	const LinphoneAddress *addr;
Sylvain Berfini's avatar
Sylvain Berfini committed
748

749
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
750 751 752 753 754 755 756 757 758 759
	linphone_friend_list_set_uri(lfl, CARDDAV_SERVER);
	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);
	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);

	BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
760
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_dirty_friends_to_update(lfl)), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
761
	BC_ASSERT_EQUAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
762
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_dirty_friends_to_update(lfl)), 1, unsigned int, "%u");
763
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
764
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
765
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_dirty_friends_to_update(lfl)), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
766 767
	BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
	linphone_friend_list_remove_friend(lfl, lf);
768
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_friends(lfl)), 0, unsigned int, "%u");
769
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
770 771 772 773
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");
	linphone_friend_unref(lf);
	lf = NULL;

774
	lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
775
	lf = linphone_friend_new_from_vcard(lvc);
776
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
777 778 779
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
	linphone_friend_unref(lf);

780
	lvc2 = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "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");
Sylvain Berfini's avatar
Sylvain Berfini committed
781 782
	linphone_vcard_set_url(lvc2, "/card.php/addressbooks/tester/default/me.vcf");
	lf2 = linphone_friend_new_from_vcard(lvc2);
783
	linphone_vcard_unref(lvc2);
Sylvain Berfini's avatar
Sylvain Berfini committed
784 785 786
	linphone_friend_set_ref_key(lf2, refkey);
	BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf2), LinphoneFriendListOK, int, "%d");

787
	BC_ASSERT_EQUAL(linphone_friend_list_get_revision(lfl), 0, int, "%i");
Sylvain Berfini's avatar
Sylvain Berfini committed
788
	linphone_friend_list_synchronize_friends_from_server(lfl);
789
	wait_for_until(manager->lc, NULL, &stats->new_contact_count, 0, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
790
	BC_ASSERT_EQUAL(stats->new_contact_count, 0, int, "%i");
791
	wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
792
	BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i");
793
	wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
794
	BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i");
795
	BC_ASSERT_NOT_EQUAL(linphone_friend_list_get_revision(lfl), 0, int, "%i");
796
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
797 798
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");

799 800 801 802
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_friends(lfl)), 1, unsigned int, "%u");
	lf = (LinphoneFriend *)bctbx_list_get_data((linphone_friend_list_get_friends(lfl)));
	BC_ASSERT_STRING_EQUAL(linphone_friend_get_ref_key(lf), refkey);
	BC_ASSERT_EQUAL(linphone_friend_get_storage_id(lf), linphone_friend_get_storage_id(lf2), unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
803 804
	linphone_friend_unref(lf2);
	addr = linphone_friend_get_address(lf);
805
	BC_ASSERT_PTR_NOT_NULL(addr);
Sylvain Berfini's avatar
Sylvain Berfini committed
806 807 808
	address = linphone_address_as_string_uri_only(addr);
	BC_ASSERT_STRING_EQUAL(address, "sip:sylvain@sip.linphone.org");
	ms_free(address);
Simon Morlat's avatar
Simon Morlat committed
809

Sylvain Berfini's avatar
Sylvain Berfini committed
810 811 812

	linphone_friend_edit(lf);
	linphone_friend_done(lf);
813
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_dirty_friends_to_update(linphone_friend_get_friend_list(lf))), 0, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
814 815 816 817 818

	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);
819
	BC_ASSERT_EQUAL((unsigned int)bctbx_list_size(linphone_friend_list_get_dirty_friends_to_update(linphone_friend_get_friend_list(lf))), 1, unsigned int, "%u");
Sylvain Berfini's avatar
Sylvain Berfini committed
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844

	ms_free(stats);
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

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);
	bctbx_list_t *friends = NULL;
	bctbx_list_t *friends_iterator = NULL;
	LinphoneFriend *lf = NULL;
	LinphoneVcard *lvc = NULL;

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

	linphone_friend_list_synchronize_friends_from_server(lfl);
845
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
846 847 848
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
	stats->sync_done_count = 0;

849
	friends = bctbx_list_copy(linphone_friend_list_get_friends(lfl));
Sylvain Berfini's avatar
Sylvain Berfini committed
850 851 852 853
	friends_iterator = friends;
	while (friends_iterator) {
		LinphoneFriend *lf = (LinphoneFriend *)friends_iterator->data;
		linphone_friend_list_remove_friend(lfl, lf);
854
		wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
855 856 857 858 859 860 861
		BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
		stats->sync_done_count = 0;
		stats->removed_contact_count = 0;
		friends_iterator = bctbx_list_next(friends_iterator);
	}
	bctbx_list_free(friends);

862
	lvc = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "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");
Sylvain Berfini's avatar
Sylvain Berfini committed
863 864
	linphone_vcard_set_url(lvc, "http://dav.linphone.org/card.php/addressbooks/tester/default/me.vcf");
	lf = linphone_friend_new_from_vcard(lvc);
865
	linphone_vcard_unref(lvc);
Sylvain Berfini's avatar
Sylvain Berfini committed
866
	linphone_friend_list_add_friend(lfl, lf);
867
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");

	ms_free(stats);
	linphone_friend_unref(lf);
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

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

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

	linphone_friend_list_synchronize_friends_from_server(lfl);
891
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
892 893
	BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
	linphone_friend_list_synchronize_friends_from_server(lfl);
894
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
895 896
	BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i");
	linphone_friend_list_synchronize_friends_from_server(lfl);
897
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
898 899 900 901 902 903 904 905 906 907 908 909 910
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");
	BC_ASSERT_EQUAL(stats->removed_contact_count, 0, int, "%i");

	ms_free(stats);
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

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);
911
	LinphoneVcard *lvc1 = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
912
	LinphoneFriend *lf1 = linphone_friend_new_from_vcard(lvc1);
913
	LinphoneVcard *lvc2 = linphone_vcard_context_get_vcard_from_buffer(linphone_core_get_vcard_context(manager->lc), "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
914 915 916
	LinphoneFriend *lf2 = linphone_friend_new_from_vcard(lvc2);
	bctbx_list_t *friends = NULL, *friends_iterator = NULL;

917 918
	linphone_vcard_unref(lvc1);
	linphone_vcard_unref(lvc2);
Sylvain Berfini's avatar
Sylvain Berfini committed
919 920 921 922 923 924 925 926 927 928 929 930 931
	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);

	linphone_friend_list_add_friend(lfl, lf1);
	linphone_friend_unref(lf1);
	linphone_friend_list_synchronize_friends_from_server(lfl);
	linphone_friend_list_add_friend(lfl, lf2);
	linphone_friend_unref(lf2);
932
	wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
933 934 935
	BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i");

	stats->sync_done_count = 0;
936
	friends = bctbx_list_copy(linphone_friend_list_get_friends(lfl));
Sylvain Berfini's avatar
Sylvain Berfini committed
937 938 939 940 941
	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);
942
			wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, CARDDAV_SYNC_TIMEOUT);
Sylvain Berfini's avatar
Sylvain Berfini committed
943 944 945 946 947 948 949 950 951 952 953 954
			BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
			stats->sync_done_count = 0;
		}
		friends_iterator = bctbx_list_next(friends_iterator);
	}
	bctbx_list_free(friends);

	ms_free(stats);
	linphone_friend_list_unref(lfl);
	linphone_core_manager_destroy(manager);
}

955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
static void find_friend_by_ref_key_test(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	LinphoneFriend *lf = linphone_core_create_friend_with_address(manager->lc, "sip:toto@sip.linphone.org");
	LinphoneFriend *lf2 = NULL;
	const LinphoneAddress *addr = NULL;
	linphone_friend_set_ref_key(lf, "totorefkey");
	linphone_friend_list_add_friend(lfl, lf);
	lf2 = linphone_friend_list_find_friend_by_ref_key(lfl, "totorefkey");
	BC_ASSERT_PTR_NOT_NULL(lf2);
	if (!lf2) {
		goto end;
	}
	addr = linphone_friend_get_address(lf2);
	BC_ASSERT_STRING_EQUAL(linphone_address_as_string_uri_only(addr), "sip:toto@sip.linphone.org");
	BC_ASSERT_EQUAL(lf2, lf, void*, "%p");
end:
	linphone_friend_unref(lf);
	linphone_core_manager_destroy(manager);
}
975 976 977 978

static void insert_lot_of_friends_map_test(void) {
	int i;
	bctbx_map_t *friends_map = bctbx_mmap_cchar_new();
979 980 981 982
	bctbx_pair_cchar_t *pair;
	
	char key[64];
	ms_message("Start\n");
983 984
	for(i = 0; i < 20000; i++) {
		snprintf(key, sizeof(key),"key_%i",i);
985 986
		pair = bctbx_pair_cchar_new(key,(void*)(uintptr_t)i);
		bctbx_map_cchar_insert_and_delete(friends_map, (bctbx_pair_t*)pair);
987
	}
988
	ms_message("End\n");
989 990 991 992 993 994 995
	bctbx_mmap_cchar_delete(friends_map);
}

static void find_friend_by_ref_key_in_lot_of_friends_test(void) {
	int i;
	int j;
	bctbx_map_t *friends_map = bctbx_mmap_cchar_new();
996
	bctbx_pair_cchar_t *pair;
997 998 999
	bctbx_iterator_t *it;
	bctoolboxTimeSpec t1;
	bctoolboxTimeSpec t2;
1000
	char key[64];
1001 1002
	for(i = 0; i < 20000; i++) {
		snprintf(key, sizeof(key),"key_%i",i);
1003 1004
		pair = bctbx_pair_cchar_new(key,(void*)(uintptr_t)i);
		bctbx_map_cchar_insert_and_delete(friends_map, (bctbx_pair_t*)pair);
1005 1006
	}
	bctbx_get_cur_time(&t1);
Simon Morlat's avatar
Simon Morlat committed
1007
	ms_message("Start : %li : %li\n", (long int)t1.tv_sec, (long int)t1.tv_nsec);
1008 1009 1010
	for(i = 0; i < 20000; i++) {
		snprintf(key, sizeof(key),"key_%i",i);
		it = bctbx_map_cchar_find_key(friends_map, key);
1011
		j = (int)(uintptr_t)bctbx_pair_cchar_get_second(bctbx_iterator_cchar_get_pair(it));
1012 1013 1014 1015
		BC_ASSERT_TRUE(i == j);
		bctbx_iterator_cchar_delete(it);
	}
	bctbx_get_cur_time(&t2);
Simon Morlat's avatar
Simon Morlat committed
1016
	ms_message("End : %li : %li\n", (long int)t2.tv_sec, (long int)t2.tv_nsec);
1017 1018 1019
	bctbx_mmap_cchar_delete(friends_map);
}

1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
static void find_friend_by_ref_key_empty_list_test(void) {
	LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
	LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
	LinphoneFriend *lf2;
	lf2 = linphone_friend_list_find_friend_by_ref_key(lfl, "totorefkey");
	BC_ASSERT_PTR_NULL(lf2);
	if (lf2) {
		goto end;
	}
end:
	linphone_core_manager_destroy(manager);
}
1032

Sylvain Berfini's avatar
Sylvain Berfini committed
1033 1034 1035 1036 1037 1038
test_t vcard_tests[] = {
	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),
#ifdef SQLITE_STORAGE_ENABLED
Ghislain MARY's avatar
Ghislain MARY committed
1039 1040
	TEST_NO_TAG("Friends working if no db set", friends_if_no_db_set),
	TEST_NO_TAG("Friends storage migration from rc to db", friends_migration),
Sylvain Berfini's avatar
Sylvain Berfini committed
1041
	TEST_NO_TAG("Friends storage in sqlite database", friends_sqlite_storage),
1042 1043
	TEST_NO_TAG("20000 Friends storage in sqlite database", friends_sqlite_store_lot_of_friends),
	TEST_NO_TAG("Find friend in database of 20000 objects", friends_sqlite_find_friend_in_lot_of_friends),
Sylvain Berfini's avatar
Sylvain Berfini committed
1044
#endif
1045 1046 1047 1048 1049 1050 1051 1052
	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),
1053
	TEST_NO_TAG("Find friend by ref key", find_friend_by_ref_key_test),
1054 1055
	TEST_NO_TAG("create a map and insert 20000 objects", insert_lot_of_friends_map_test),
	TEST_NO_TAG("Find ref key in 20000 objects map", find_friend_by_ref_key_in_lot_of_friends_test),
1056
	TEST_NO_TAG("Find friend by ref key in empty list", find_friend_by_ref_key_empty_list_test)
Benjamin REIS's avatar
Benjamin REIS committed
1057

Sylvain Berfini's avatar
Sylvain Berfini committed
1058 1059 1060 1061 1062 1063 1064 1065 1066
};

test_suite_t vcard_test_suite = {
	"VCard", NULL, NULL,
	liblinphone_tester_before_each, liblinphone_tester_after_each,
	sizeof(vcard_tests) / sizeof(vcard_tests[0]), vcard_tests
};

#endif