From ab66255754deb915fb314662e57598a24b233d15 Mon Sep 17 00:00:00 2001 From: horuga23 Date: Sun, 20 Jun 2010 12:59:03 +0200 Subject: [PATCH] Unit test stuff on new contact fields. --- src/gcal_parser.c | 2 +- utests/utest_contact.c | 12 +++++----- utests/utest_userapi.c | 62 +++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/gcal_parser.c b/src/gcal_parser.c index 78c1416..437d6ac 100644 --- a/src/gcal_parser.c +++ b/src/gcal_parser.c @@ -759,7 +759,7 @@ int xmlcontact_create(struct gcal_contact *contact, char **xml_contact, xmlAddChild(root, node); } - /* TODO: implement missing fields (im, geo location, what else?) + /* TODO: implement missing fields (which ones? geo location?) */ xmlDocDumpMemory(doc, &xml_str, length); diff --git a/utests/utest_contact.c b/utests/utest_contact.c index d884c57..82bf748 100644 --- a/utests/utest_contact.c +++ b/utests/utest_contact.c @@ -161,7 +161,7 @@ START_TEST (test_contact_xml) contact.common.id = contact.common.updated = contact.common.edit_uri = contact.common.etag = NULL; contact.photo = contact.photo_data = NULL; /* extra fields */ - contact.nickname = "The Fox"; + contact.nickname = "Johnny"; contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; @@ -288,7 +288,7 @@ START_TEST (test_contact_add) contact.common.id = contact.common.updated = contact.common.edit_uri = contact.common.etag = NULL; contact.photo = contact.photo_data = NULL; /* extra fields */ - contact.nickname = "The Fox"; + contact.nickname = "Doc Doe"; contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; @@ -399,8 +399,8 @@ START_TEST (test_contact_delete) fail_if(entry_index == -1, temp); free(temp); -// result = gcal_delete_contact(ptr_gcal, (contacts + entry_index)); -// fail_if(result == -1, "Failed deleting contact!"); + result = gcal_delete_contact(ptr_gcal, (contacts + entry_index)); + fail_if(result == -1, "Failed deleting contact!"); gcal_destroy_contacts(contacts, count); } @@ -424,7 +424,7 @@ START_TEST (test_contact_edit) gcal_contact_set_structured_entry(contact.structured_name,0,1,"givenName","John"); gcal_contact_set_structured_entry(contact.structured_name,0,1,"additionalName","W."); gcal_contact_set_structured_entry(contact.structured_name,0,1,"familyName","Doe"); - gcal_contact_set_structured_entry(contact.structured_name,0,1,"namePrefix","Dr."); + gcal_contact_set_structured_entry(contact.structured_name,0,1,"namePrefix","Prof."); contact.photo = contact.photo_data = NULL; contact.photo_length = 0; @@ -436,7 +436,7 @@ START_TEST (test_contact_edit) contact.emails_type[0] = "home"; contact.common.id = contact.common.updated = contact.common.edit_uri = contact.common.etag = NULL; /* extra fields */ - contact.nickname = "The Fox"; + contact.nickname = "Pro"; contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; diff --git a/utests/utest_userapi.c b/utests/utest_userapi.c index 793790d..c4ebc7d 100644 --- a/utests/utest_userapi.c +++ b/utests/utest_userapi.c @@ -610,11 +610,12 @@ START_TEST (test_contact_new_fields) { gcal_t gcal; - int result, length, address_nr, address_count; + int result, address_nr, address_count; struct gcal_contact_array contact_array; - gcal_contact_t contact; + gcal_contact_t contact, contact_temp; gcal_structured_subvalues_t structured_entry; - char *xml = NULL, *ptr; + char *temp; + size_t i; /* Create a new contact object */ contact = gcal_contact_new(NULL); @@ -668,12 +669,14 @@ START_TEST (test_contact_new_fields) gcal_contact_set_pref_structured_address(contact,1); gcal = gcal_new(GCONTACT); + gcal_set_store_xml(gcal, 1); result = gcal_get_authentication(gcal, "gcalntester", "77libgcal"); fail_if(result == -1, "Authentication should work."); result = gcal_add_contact(gcal, contact); fail_if(result == -1, "Failed adding a new contact!"); + /* Edit the new contact */ gcal_contact_set_structured_entry(contact->structured_name,0,1,"givenName","James"); gcal_contact_set_structured_entry(contact->structured_name,0,1,"familyName","Dont"); gcal_contact_set_structured_entry(contact->structured_name,0,1,"nameSuffix","Jr."); @@ -705,13 +708,7 @@ START_TEST (test_contact_new_fields) gcal_contact_set_structured_entry(contact->structured_address,address_nr,address_count,"postcode","QQQ 112233-WW"); gcal_contact_set_structured_entry(contact->structured_address,address_nr,address_count,"country","South Africa"); - result = xmlcontact_create(contact, &xml, &length); - fail_if((result == -1) || (xml == NULL), - "Failed creating XML for a new contact!"); - - ptr = strstr(xml, "Dont"); - fail_if(ptr == NULL, "XML lacks a field: gd:name/gd:familyName\n"); - + /* Update contact */ result = gcal_update_contact(gcal, contact); fail_if(result == -1, "Failed editing contact!"); @@ -719,6 +716,50 @@ START_TEST (test_contact_new_fields) result = gcal_get_updated_contacts(gcal, &contact_array, NULL); fail_if(result == -1, "Failed downloading updated contacts!"); + result = -1; + for (i = 0; i < contact_array.length; ++i) { + contact_temp = gcal_contact_element(&contact_array, i); + if( !strcmp("Dr. James W. Dont Jr.", + gcal_contact_get_structured_entry(contact_temp->structured_name,0,1,"fullName")) ) { + + temp = gcal_contact_get_nickname(contact); + fail_if(strcmp("The Fox",temp) != 0, + "Failed setting/getting right nickname: ---%s---!",temp); + + temp = gcal_contact_get_occupation(contact); + fail_if(strcmp("Programmer",temp) != 0, + "Failed setting/getting right occupation: ---%s---!",temp); + + temp = gcal_contact_get_birthday(contact); + fail_if(strcmp("1963-11-11",temp) != 0, + "Failed setting/getting right birthday: ---%s---!",temp); + + temp = gcal_contact_get_im_address(contact,1); + fail_if(strcmp("johnny_aim",temp) != 0, + "Failed setting/getting right im address: ---%s---!",temp); + + temp = gcal_contact_get_im_protocol(contact,1); + fail_if(strcmp("AIM",temp) != 0, + "Failed setting/getting right im protocol: ---%s---!",temp); + + temp = gcal_contact_get_homepage(contact); + fail_if(strcmp("www.homegage.com",temp) != 0, + "Failed setting/getting right homepage: ---%s---!",temp); + + temp = gcal_contact_get_blog(contact); + fail_if(strcmp("myblog.homegage.com",temp) != 0, + "Failed setting/getting right blog address: ---%s---!",temp); + + temp = gcal_contact_get_structured_entry(contact_temp->structured_address,0,2,"region"); + fail_if(strcmp("Hereorthere",temp) != 0, + "Failed setting/getting right region of first address: ---%s---!",temp); + + temp = gcal_contact_get_structured_entry(contact_temp->structured_address,1,2,"postcode"); + fail_if(strcmp("QQQ 112233-WW",temp) != 0, + "Failed setting/getting right postcode of second address: ---%s---!",temp); + } + } + /* Delete */ result = gcal_erase_contact(gcal, contact); fail_if(result == -1, "Failed deleting contact!"); @@ -726,7 +767,6 @@ START_TEST (test_contact_new_fields) /* Cleanup */ gcal_contact_delete(contact); gcal_delete(gcal); - gcal_cleanup_contacts(&contact_array); } -- 2.11.4.GIT