Commit 1d754ddf authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Automatically generate UID on PUT if not yet created + improved some tests

parent 06f9d69a
......@@ -492,8 +492,11 @@ static char* generate_url_from_server_address_and_uid(const char *server_url) {
void linphone_carddav_put_vcard(LinphoneCardDavContext *cdc, LinphoneFriend *lf) {
LinphoneVCard *lvc = linphone_friend_get_vcard(lf);
if (lvc && linphone_vcard_get_uid(lvc)) {
if (lvc) {
LinphoneCardDavQuery *query = NULL;
if (!linphone_vcard_get_uid(lvc)) {
linphone_vcard_generate_unique_id(lvc);
}
if (!linphone_vcard_get_url(lvc)) {
char *url = generate_url_from_server_address_and_uid(cdc->friend_list->uri);
......@@ -517,8 +520,6 @@ void linphone_carddav_put_vcard(LinphoneCardDavContext *cdc, LinphoneFriend *lf)
const char *msg = NULL;
if (!lvc) {
msg = "LinphoneVCard is NULL";
} else if (!linphone_vcard_get_uid(lvc)) {
msg = "LinphoneVCard doesn't have an UID";
} else {
msg = "Unknown error";
}
......
......@@ -125,14 +125,14 @@ LINPHONE_PUBLIC MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vC
* @param[in] vCard the LinphoneVCard
* @return TRUE if operation is successful, otherwise FALSE (for example if it already has an unique ID)
*/
LINPHONE_PUBLIC bool_t linphone_vcard_generate_unique_id(LinphoneVCard *vCard);
bool_t linphone_vcard_generate_unique_id(LinphoneVCard *vCard);
/**
* Sets the unique ID of the vCard
* @param[in] vCard the LinphoneVCard
* @param[in] uid the unique id
*/
LINPHONE_PUBLIC void linphone_vcard_set_uid(LinphoneVCard *vCard, const char *uid);
void linphone_vcard_set_uid(LinphoneVCard *vCard, const char *uid);
/**
* Gets the UID of the vCard
......
......@@ -408,11 +408,9 @@ static void carddav_sync_4(void) {
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));
BC_ASSERT_TRUE(linphone_vcard_generate_unique_id(lvc));
BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
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));
wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 2000);
BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i");
......@@ -461,12 +459,14 @@ static void carddav_integration(void) {
linphone_core_add_friend_list(manager->lc, lfl);
BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc));
BC_ASSERT_TRUE(linphone_vcard_generate_unique_id(lvc));
BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d");
BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%d");
BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 1, int, "%d");
wait_for_until(manager->lc, NULL, NULL, 1, 2000);
BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d");
BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc));
linphone_friend_list_remove_friend(lfl, lf);
wait_for_until(manager->lc, NULL, NULL, 1, 2000);
BC_ASSERT_EQUAL(ms_list_size(lfl->friends), 0, int, "%d");
linphone_friend_unref(lf);
lf = NULL;
......
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