Commit 860ee180 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Tests done for friends' database storage

parent c1f11402
......@@ -960,7 +960,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
linphone_core_friends_storage_close(lc);
ret=_linphone_sqlite3_open(lc->friends_db_file, &db);
ret = _linphone_sqlite3_open(lc->friends_db_file, &db);
if (ret != SQLITE_OK) {
errmsg = sqlite3_errmsg(db);
ms_error("Error in the opening: %s.\n", errmsg);
......@@ -986,8 +986,13 @@ void linphone_core_friends_storage_close(LinphoneCore *lc) {
static int create_friend(void *data, int argc, char **argv, char **colName) {
MSList **list = (MSList **)data;
LinphoneFriend *lf = NULL;
LinphoneVCard *vcard = NULL;
vcard = linphone_vcard_new_from_vcard4_buffer(argv[1]);
lf = linphone_friend_new_from_vcard(vcard);
//TODO
*list = ms_list_append(*list, lf);
*list = ms_list_append(*list, linphone_friend_ref(lf));
linphone_friend_unref(lf);
return 0;
}
......@@ -1047,7 +1052,7 @@ void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
}
}
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
char *buf;
uint64_t begin,end;
MSList *result = NULL;
......@@ -1079,7 +1084,7 @@ void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf) {
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf) {
}
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc) {
return NULL;
}
......@@ -1103,4 +1108,5 @@ void linphone_core_migrate_friends_from_rc_to_db(LinphoneCore *lc) {
ms_warning("linphone has been compiled without sqlite, can't migrate friends");
return;
#endif
//TODO
}
\ No newline at end of file
......@@ -399,7 +399,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc);
void linphone_core_friends_storage_close(LinphoneCore *lc);
void linphone_core_store_friend_in_db(LinphoneCore *lc, LinphoneFriend *lf);
void linphone_core_remove_friend_from_db(LinphoneCore *lc, LinphoneFriend *lf);
const MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc);
MSList* linphone_core_fetch_friends_from_db(LinphoneCore *lc);
int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, socklen_t *socklen, int default_port);
......
......@@ -72,9 +72,104 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) {
linphone_core_manager_destroy(manager);
}
static void friends_if_no_db_set(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
LinphoneFriend *lf = linphone_friend_new();
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
const MSList *friends = NULL;
linphone_friend_set_address(lf, addr);
linphone_friend_set_name(lf, "Sylvain");
linphone_core_add_friend(manager->lc, lf);
linphone_friend_unref(lf);
friends = linphone_core_get_friend_list(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d");
linphone_core_remove_friend(manager->lc, lf);
friends = linphone_core_get_friend_list(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
linphone_address_destroy(addr);
linphone_core_manager_destroy(manager);
}
#ifdef FRIENDS_SQL_STORAGE_ENABLED
static void friends_migration(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
LinphoneFriend *lf = linphone_friend_new();
LinphoneFriend *lf2 = NULL;
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
const MSList *friends = linphone_core_get_friend_list(manager->lc);
MSList *friends_from_db = NULL;
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
linphone_friend_set_address(lf, addr);
linphone_friend_set_name(lf, "Sylvain");
linphone_core_add_friend(manager->lc, lf);
linphone_friend_unref(lf);
friends = linphone_core_get_friend_list(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d");
unlink(friends_db);
linphone_core_set_friends_database_path(manager->lc, friends_db);
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
BC_ASSERT_EQUAL_FATAL(ms_list_size(friends_from_db), 1, int, "%d");
lf2 = (LinphoneFriend *)friends_from_db->data;
BC_ASSERT_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf), const char *, "%s");
unlink(friends_db);
ms_free(friends_db);
linphone_address_destroy(addr);
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
linphone_core_manager_destroy(manager);
}
static void friends_sqlite_storage(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
LinphoneFriend *lf = linphone_friend_new();
LinphoneFriend *lf2 = NULL;
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
const MSList *friends = linphone_core_get_friend_list(manager->lc);
MSList *friends_from_db = NULL;
char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db");
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
unlink(friends_db);
linphone_core_set_friends_database_path(manager->lc, friends_db);
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
linphone_friend_set_address(lf, addr);
linphone_friend_set_name(lf, "Sylvain");
linphone_core_add_friend(manager->lc, lf);
linphone_friend_unref(lf);
friends = linphone_core_get_friend_list(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d");
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc);
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d");
lf2 = (LinphoneFriend *)friends_from_db->data;
BC_ASSERT_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf), const char *, "%s");
unlink(friends_db);
ms_free(friends_db);
linphone_address_destroy(addr);
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
linphone_core_manager_destroy(manager);
}
#endif
test_t vcard_tests[] = {
{ "Import / Export friends from vCards", linphone_vcard_import_export_friends_test },
{ "Import a lot of friends from vCards", linphone_vcard_import_a_lot_of_friends_test },
#ifdef FRIENDS_SQL_STORAGE_ENABLED
{ "Friends working if no db set", friends_if_no_db_set },
{ "Friends storage migration from rc to db", friends_migration },
{ "Friends storage in sqlite database", friends_sqlite_storage },
#endif
};
test_suite_t vcard_test_suite = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment