mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-01 18:06:24 +00:00
Removed deprecated methods from vcard tester + updated import/export vCard API
This commit is contained in:
parent
f5e86f8f95
commit
0676eaf4f1
11 changed files with 198 additions and 187 deletions
|
|
@ -912,96 +912,6 @@ LinphoneFriend *linphone_friend_new_from_vcard(LinphoneVCard *vcard) {
|
|||
return fr;
|
||||
}
|
||||
|
||||
int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *vcard_file) {
|
||||
MSList *vcards = linphone_vcard_list_from_vcard4_file(vcard_file);
|
||||
int count = 0;
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
return -1;
|
||||
#endif
|
||||
if (!vcards) {
|
||||
ms_error("Failed to parse the file %s", vcard_file);
|
||||
return -1;
|
||||
}
|
||||
while (vcards != NULL && vcards->data != NULL) {
|
||||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(linphone_core_get_default_friend_list(lc), lf, TRUE)) {
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
} else {
|
||||
linphone_vcard_free(vcard);
|
||||
}
|
||||
vcards = ms_list_next(vcards);
|
||||
}
|
||||
#ifndef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_write_friends_config(lc);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char *vcard_buffer) {
|
||||
MSList *vcards = linphone_vcard_list_from_vcard4_buffer(vcard_buffer);
|
||||
int count = 0;
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
return -1;
|
||||
#endif
|
||||
if (!vcards) {
|
||||
ms_error("Failed to parse the buffer");
|
||||
return -1;
|
||||
}
|
||||
while (vcards != NULL && vcards->data != NULL) {
|
||||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(linphone_core_get_default_friend_list(lc), lf, TRUE)) {
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
} else {
|
||||
linphone_vcard_free(vcard);
|
||||
}
|
||||
vcards = ms_list_next(vcards);
|
||||
}
|
||||
#ifndef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_write_friends_config(lc);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
void linphone_core_export_friends_as_vcard4_file(LinphoneCore *lc, const char *vcard_file) {
|
||||
FILE *file = NULL;
|
||||
const MSList *friends = linphone_core_get_friend_list(lc);
|
||||
|
||||
file = fopen(vcard_file, "w");
|
||||
if (file == NULL) {
|
||||
ms_warning("Could not write %s ! Maybe it is read-only. Contacts will not be saved.", vcard_file);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
#endif
|
||||
while (friends != NULL && friends->data != NULL) {
|
||||
LinphoneFriend *lf = (LinphoneFriend *)friends->data;
|
||||
LinphoneVCard *vcard = linphone_friend_get_vcard(lf);
|
||||
if (vcard) {
|
||||
const char *vcard_text = linphone_vcard_as_vcard4_string(vcard);
|
||||
fprintf(file, "%s", vcard_text);
|
||||
} else {
|
||||
ms_warning("Couldn't export friend %s because it doesn't have a vCard attached", linphone_address_as_string(linphone_friend_get_address(lf)));
|
||||
}
|
||||
friends = ms_list_next(friends);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/*drops all references to the core and unref*/
|
||||
void _linphone_friend_release(LinphoneFriend *lf){
|
||||
lf->lc = NULL;
|
||||
|
|
|
|||
|
|
@ -731,3 +731,103 @@ void linphone_friend_list_subscription_state_changed(LinphoneCore *lc, LinphoneE
|
|||
LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list) {
|
||||
return list->lc;
|
||||
}
|
||||
|
||||
int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *list, const char *vcard_file) {
|
||||
MSList *vcards = linphone_vcard_list_from_vcard4_file(vcard_file);
|
||||
int count = 0;
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
return -1;
|
||||
#endif
|
||||
if (!vcards) {
|
||||
ms_error("Failed to parse the file %s", vcard_file);
|
||||
return -1;
|
||||
}
|
||||
if (!list) {
|
||||
ms_error("Can't import into a NULL list");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (vcards != NULL && vcards->data != NULL) {
|
||||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) {
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
} else {
|
||||
linphone_vcard_free(vcard);
|
||||
}
|
||||
vcards = ms_list_next(vcards);
|
||||
}
|
||||
#ifndef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_write_friends_config(list->lc);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer) {
|
||||
MSList *vcards = linphone_vcard_list_from_vcard4_buffer(vcard_buffer);
|
||||
int count = 0;
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
return -1;
|
||||
#endif
|
||||
if (!vcards) {
|
||||
ms_error("Failed to parse the buffer");
|
||||
return -1;
|
||||
}
|
||||
if (!list) {
|
||||
ms_error("Can't import into a NULL list");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (vcards != NULL && vcards->data != NULL) {
|
||||
LinphoneVCard *vcard = (LinphoneVCard *)vcards->data;
|
||||
LinphoneFriend *lf = linphone_friend_new_from_vcard(vcard);
|
||||
if (lf) {
|
||||
if (LinphoneFriendListOK == linphone_friend_list_import_friend(list, lf, TRUE)) {
|
||||
count++;
|
||||
}
|
||||
linphone_friend_unref(lf);
|
||||
} else {
|
||||
linphone_vcard_free(vcard);
|
||||
}
|
||||
vcards = ms_list_next(vcards);
|
||||
}
|
||||
#ifndef FRIENDS_SQL_STORAGE_ENABLED
|
||||
linphone_core_write_friends_config(list->lc);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file) {
|
||||
FILE *file = NULL;
|
||||
const MSList *friends = linphone_friend_list_get_friends(list);
|
||||
|
||||
file = fopen(vcard_file, "w");
|
||||
if (file == NULL) {
|
||||
ms_warning("Could not write %s ! Maybe it is read-only. Contacts will not be saved.", vcard_file);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef VCARD_ENABLED
|
||||
ms_error("vCard support wasn't enabled at compilation time");
|
||||
#endif
|
||||
while (friends != NULL && friends->data != NULL) {
|
||||
LinphoneFriend *lf = (LinphoneFriend *)friends->data;
|
||||
LinphoneVCard *vcard = linphone_friend_get_vcard(lf);
|
||||
if (vcard) {
|
||||
const char *vcard_text = linphone_vcard_as_vcard4_string(vcard);
|
||||
fprintf(file, "%s", vcard_text);
|
||||
} else {
|
||||
ms_warning("Couldn't export friend %s because it doesn't have a vCard attached", linphone_address_as_string(linphone_friend_get_address(lf)));
|
||||
}
|
||||
friends = ms_list_next(friends);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,6 +375,29 @@ void linphone_friend_list_update_dirty_friends(LinphoneFriendList *list);
|
|||
*/
|
||||
LINPHONE_PUBLIC LinphoneCore* linphone_friend_list_get_core(LinphoneFriendList *list);
|
||||
|
||||
/**
|
||||
* Creates and adds LinphoneFriend objects to LinphoneFriendList from a file that contains the vCard(s) to parse
|
||||
* @param[in] list the LinphoneFriendList object
|
||||
* @param[in] vcard_file the path to a file that contains the vCard(s) to parse
|
||||
* @return the amount of linphone friends created
|
||||
*/
|
||||
LINPHONE_PUBLIC int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *list, const char *vcard_file);
|
||||
|
||||
/**
|
||||
* Creates and adds LinphoneFriend objects to LinphoneFriendList from a buffer that contains the vCard(s) to parse
|
||||
* @param[in] list the LinphoneFriendList object
|
||||
* @param[in] vcard_buffer the buffer that contains the vCard(s) to parse
|
||||
* @return the amount of linphone friends created
|
||||
*/
|
||||
LINPHONE_PUBLIC int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *list, const char *vcard_buffer);
|
||||
|
||||
/**
|
||||
* Creates and export LinphoneFriend objects from LinphoneFriendList to a file using vCard 4 format
|
||||
* @param[in] list the LinphoneFriendList object
|
||||
* @param[in] vcard_file the path to a file that will contain the vCards
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_friend_list_export_friends_as_vcard4_file(LinphoneFriendList *list, const char *vcard_file);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2031,23 +2031,23 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv* env
|
|||
linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
|
||||
}
|
||||
|
||||
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_importFriendsFromVCardFile(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) {
|
||||
extern "C" jint Java_org_linphone_core_LinphoneFriendListImpl_importFriendsFromVCardFile(JNIEnv* env, jobject thiz, jlong list, jstring jpath) {
|
||||
const char* path = env->GetStringUTFChars(jpath, NULL);
|
||||
int count = linphone_core_import_friends_from_vcard4_file((LinphoneCore*)lc, path);
|
||||
int count = linphone_friend_list_import_friends_from_vcard4_file((LinphoneFriendList*)list, path);
|
||||
env->ReleaseStringUTFChars(jpath, path);
|
||||
return count;
|
||||
}
|
||||
|
||||
extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_importFriendsFromVCardBuffer(JNIEnv* env, jobject thiz, jlong lc, jstring jbuffer) {
|
||||
extern "C" jint Java_org_linphone_core_LinphoneFriendListImpl_importFriendsFromVCardBuffer(JNIEnv* env, jobject thiz, jlong list, jstring jbuffer) {
|
||||
const char* buffer = env->GetStringUTFChars(jbuffer, NULL);
|
||||
int count = linphone_core_import_friends_from_vcard4_buffer((LinphoneCore*)lc, buffer);
|
||||
int count = linphone_friend_list_import_friends_from_vcard4_buffer((LinphoneFriendList*)list, buffer);
|
||||
env->ReleaseStringUTFChars(jbuffer, buffer);
|
||||
return count;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_exportFriendsToVCardFile(JNIEnv* env, jobject thiz, jlong lc, jstring jpath) {
|
||||
extern "C" void Java_org_linphone_core_LinphoneFriendListImpl_exportFriendsToVCardFile(JNIEnv* env, jobject thiz, jlong list, jstring jpath) {
|
||||
const char* path = env->GetStringUTFChars(jpath, NULL);
|
||||
linphone_core_export_friends_as_vcard4_file((LinphoneCore*)lc, path);
|
||||
linphone_friend_list_export_friends_as_vcard4_file((LinphoneFriendList*)list, path);
|
||||
env->ReleaseStringUTFChars(jpath, path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -459,29 +459,6 @@ LINPHONE_PUBLIC bool_t linphone_friend_create_vcard(LinphoneFriend *fr, const ch
|
|||
*/
|
||||
LINPHONE_PUBLIC LinphoneFriend *linphone_friend_new_from_vcard(LinphoneVCard *vcard);
|
||||
|
||||
/**
|
||||
* Creates and adds LinphoneFriend objects to LinphoneCore from a file that contains the vCard(s) to parse
|
||||
* @param[in] lc the LinphoneCore object
|
||||
* @param[in] vcard_file the path to a file that contains the vCard(s) to parse
|
||||
* @return the amount of linphone friends created
|
||||
*/
|
||||
LINPHONE_PUBLIC int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char *vcard_file);
|
||||
|
||||
/**
|
||||
* Creates and adds LinphoneFriend objects to LinphoneCore from a buffer that contains the vCard(s) to parse
|
||||
* @param[in] lc the LinphoneCore object
|
||||
* @param[in] vcard_buffer the buffer that contains the vCard(s) to parse
|
||||
* @return the amount of linphone friends created
|
||||
*/
|
||||
LINPHONE_PUBLIC int linphone_core_import_friends_from_vcard4_buffer(LinphoneCore *lc, const char *vcard_buffer);
|
||||
|
||||
/**
|
||||
* Creates and export LinphoneFriend objects from LinphoneCore to a file using vCard 4 format
|
||||
* @param[in] lc the LinphoneCore object
|
||||
* @param[in] vcard_file the path to a file that will contain the vCards
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_core_export_friends_as_vcard4_file(LinphoneCore *lc, const char *vcard_file);
|
||||
|
||||
/**
|
||||
* Sets the database filename where friends will be stored.
|
||||
* If the file does not exist, it will be created.
|
||||
|
|
|
|||
|
|
@ -1843,7 +1843,8 @@ void linphone_gtk_import_contacts(void) {
|
|||
if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
LinphoneCore *lc = linphone_gtk_get_core();
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
linphone_core_import_friends_from_vcard4_file(lc, filename);
|
||||
LinphoneFriendList *list = linphone_core_get_default_friend_list(lc);
|
||||
linphone_friend_list_import_friends_from_vcard4_file(list, filename);
|
||||
g_free(filename);
|
||||
linphone_gtk_show_friends();
|
||||
}
|
||||
|
|
@ -1858,7 +1859,8 @@ void linphone_gtk_export_contacts(void) {
|
|||
if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
LinphoneCore *lc = linphone_gtk_get_core();
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
linphone_core_export_friends_as_vcard4_file(lc, filename);
|
||||
LinphoneFriendList *list = linphone_core_get_default_friend_list(lc);
|
||||
linphone_friend_list_export_friends_as_vcard4_file(list, filename);
|
||||
g_free(filename);
|
||||
}
|
||||
gtk_widget_destroy(dialog);
|
||||
|
|
|
|||
|
|
@ -2270,23 +2270,6 @@ public interface LinphoneCore {
|
|||
*/
|
||||
public int getNortpTimeout();
|
||||
|
||||
/**
|
||||
* Imports LinphoneFriends from a vCard 4 file
|
||||
* @return the number of friend imported
|
||||
**/
|
||||
public int importFriendsFromVCardFile(String file);
|
||||
|
||||
/**
|
||||
* Imports LinphoneFriends from a vCard 4 buffer
|
||||
* @return the number of friend imported
|
||||
**/
|
||||
public int importFriendsFromVCardBuffer(String buffer);
|
||||
|
||||
/**
|
||||
* Exports LinphoneFriends to a vCard 4 file
|
||||
**/
|
||||
public void exportFriendsToVCardFile(String file);
|
||||
|
||||
/**
|
||||
* This method is called by the application to notify the linphone core library when the SIP network is reachable.
|
||||
* This is for advanced usage, when SIP and RTP layers are required to use different interfaces.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,24 @@ public interface LinphoneFriendList {
|
|||
public LinphoneFriend findFriendByUri(String uri);
|
||||
public void setUri(String uri);
|
||||
public void synchronizeFriendsFromServer();
|
||||
|
||||
/**
|
||||
* Imports LinphoneFriends from a vCard 4 file
|
||||
* @return the number of friend imported
|
||||
**/
|
||||
public int importFriendsFromVCardFile(String file);
|
||||
|
||||
/**
|
||||
* Imports LinphoneFriends from a vCard 4 buffer
|
||||
* @return the number of friend imported
|
||||
**/
|
||||
public int importFriendsFromVCardBuffer(String buffer);
|
||||
|
||||
/**
|
||||
* Exports LinphoneFriends to a vCard 4 file
|
||||
**/
|
||||
public void exportFriendsToVCardFile(String file);
|
||||
|
||||
long getNativePtr();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1625,24 +1625,6 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
public int getNortpTimeout(){
|
||||
return getNortpTimeout(nativePtr);
|
||||
}
|
||||
|
||||
private native int importFriendsFromVCardFile(long nativePtr, String file);
|
||||
@Override
|
||||
public int importFriendsFromVCardFile(String file) {
|
||||
return importFriendsFromVCardFile(nativePtr, file);
|
||||
}
|
||||
|
||||
private native int importFriendsFromVCardBuffer(long nativePtr, String buffer);
|
||||
@Override
|
||||
public int importFriendsFromVCardBuffer(String buffer) {
|
||||
return importFriendsFromVCardBuffer(nativePtr, buffer);
|
||||
}
|
||||
|
||||
private native void exportFriendsToVCardFile(long nativePtr, String file);
|
||||
@Override
|
||||
public void exportFriendsToVCardFile(String file) {
|
||||
exportFriendsToVCardFile(nativePtr, file);
|
||||
}
|
||||
|
||||
private native void setSipNetworkReachable(long nativePtr, boolean isReachable);
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -96,6 +96,24 @@ class LinphoneFriendListImpl implements LinphoneFriendList, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
private native int importFriendsFromVCardFile(long nativePtr, String file);
|
||||
@Override
|
||||
public int importFriendsFromVCardFile(String file) {
|
||||
return importFriendsFromVCardFile(nativePtr, file);
|
||||
}
|
||||
|
||||
private native int importFriendsFromVCardBuffer(long nativePtr, String buffer);
|
||||
@Override
|
||||
public int importFriendsFromVCardBuffer(String buffer) {
|
||||
return importFriendsFromVCardBuffer(nativePtr, buffer);
|
||||
}
|
||||
|
||||
private native void exportFriendsToVCardFile(long nativePtr, String file);
|
||||
@Override
|
||||
public void exportFriendsToVCardFile(String file) {
|
||||
exportFriendsToVCardFile(nativePtr, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListener(LinphoneFriendListListener listener) {
|
||||
setListener(nativePtr, listener);
|
||||
|
|
|
|||
|
|
@ -30,32 +30,26 @@ static char *create_filepath(const char *dir, const char *filename, const char *
|
|||
|
||||
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 MSList *friends = linphone_friend_list_get_friends(lfl);
|
||||
char *import_filepath = bc_tester_res("common/vcards.vcf");
|
||||
char *export_filepath = create_filepath(bc_tester_get_writable_dir_prefix(), "export_vcards", "vcf");
|
||||
const MSList *friends = linphone_core_get_friend_list(manager->lc);
|
||||
int count = 0;
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
BC_ASSERT_PTR_NOT_NULL_FATAL(linphone_core_get_default_friend_list(manager->lc));
|
||||
count = linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath);
|
||||
count = linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
|
||||
BC_ASSERT_EQUAL(count, 3, int, "%d");
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
friends = linphone_friend_list_get_friends(lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
|
||||
|
||||
linphone_core_export_friends_as_vcard4_file(manager->lc, export_filepath);
|
||||
linphone_friend_list_export_friends_as_vcard4_file(lfl, export_filepath);
|
||||
|
||||
linphone_core_remove_friend_list(manager->lc, linphone_core_get_default_friend_list(manager->lc));
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
linphone_core_add_friend_list(manager->lc, lfl);
|
||||
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);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
|
||||
linphone_friend_list_unref(lfl);
|
||||
lfl = NULL;
|
||||
count = linphone_core_import_friends_from_vcard4_file(manager->lc, export_filepath);
|
||||
BC_ASSERT_EQUAL(count, 3, int, "%d");
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
|
||||
|
||||
remove(export_filepath);
|
||||
ms_free(import_filepath);
|
||||
|
|
@ -65,16 +59,17 @@ static void linphone_vcard_import_export_friends_test(void) {
|
|||
|
||||
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("common/thousand_vcards.vcf");
|
||||
clock_t start, end;
|
||||
double elapsed = 0;
|
||||
const MSList *friends = NULL;
|
||||
|
||||
start = clock();
|
||||
linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath);
|
||||
linphone_friend_list_import_friends_from_vcard4_file(lfl, import_filepath);
|
||||
end = clock();
|
||||
|
||||
friends = linphone_core_get_friend_list(manager->lc);
|
||||
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
|
||||
|
||||
elapsed = (double)(end - start);
|
||||
|
|
@ -92,18 +87,20 @@ static void friends_if_no_db_set(void) {
|
|||
LinphoneFriend *lf = linphone_friend_new();
|
||||
LinphoneAddress *addr = linphone_address_new("sip:sylvain@sip.linphone.org");
|
||||
const MSList *friends = NULL;
|
||||
LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc);
|
||||
|
||||
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);
|
||||
linphone_friend_list_add_friend(lfl, lf);
|
||||
friends = linphone_friend_list_get_friends(lfl);
|
||||
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);
|
||||
linphone_friend_list_remove_friend(lfl, lf);
|
||||
linphone_friend_unref(lf);
|
||||
friends = linphone_friend_list_get_friends(lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
linphone_friend_list_unref(lfl);
|
||||
linphone_address_unref(addr);
|
||||
linphone_core_manager_destroy(manager);
|
||||
}
|
||||
|
|
@ -111,25 +108,26 @@ static void friends_if_no_db_set(void) {
|
|||
#ifdef FRIENDS_SQL_STORAGE_ENABLED
|
||||
static void friends_migration(void) {
|
||||
LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE);
|
||||
const MSList *friends = linphone_core_get_friend_list(manager->lc);
|
||||
LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc);
|
||||
const MSList *friends = linphone_friend_list_get_friends(lfl);
|
||||
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 = linphone_core_get_friend_list(manager->lc);
|
||||
friends = linphone_friend_list_get_friends(lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d");
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, linphone_core_get_default_friend_list(manager->lc));
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d");
|
||||
if (ms_list_size(friends_from_db) < 3) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
|
||||
unlink(friends_db);
|
||||
ms_free(friends_db);
|
||||
friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref);
|
||||
linphone_core_manager_destroy(manager);
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +163,7 @@ static void friends_sqlite_storage(void) {
|
|||
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);
|
||||
friends = linphone_core_get_friend_list(lc);
|
||||
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);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
|
@ -191,7 +189,7 @@ static void friends_sqlite_storage(void) {
|
|||
BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d");
|
||||
BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d");
|
||||
|
||||
friends = linphone_core_get_friend_list(lc);
|
||||
friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
|
||||
friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc);
|
||||
|
|
@ -228,8 +226,8 @@ static void friends_sqlite_storage(void) {
|
|||
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);
|
||||
|
||||
linphone_core_remove_friend(lc, lf);
|
||||
friends = linphone_core_get_friend_list(lc);
|
||||
linphone_friend_list_remove_friend(lfl, lf);
|
||||
friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc));
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d");
|
||||
friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl);
|
||||
BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue