From 5118221f06d570a9b05600fd456857be20fc75d6 Mon Sep 17 00:00:00 2001 From: horuga23 Date: Fri, 11 Jun 2010 14:30:25 +0200 Subject: [PATCH] Some unit test regarding the new fields. --- utests/contact_documentation.xml | 9 +++++++-- utests/supercontact.xml | 12 ++++++++++-- utests/utest_contact.c | 22 ++++++++++++++++++---- utests/utest_userapi.c | 15 +++++++++++++-- utests/utest_xmlmode.c | 15 +++++---------- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/utests/contact_documentation.xml b/utests/contact_documentation.xml index 5ffa9d6..a80b738 100644 --- a/utests/contact_documentation.xml +++ b/utests/contact_documentation.xml @@ -1,9 +1,13 @@ + xmlns:gd='http://schemas.google.com/g/2005' + xmlns:gContact='http://schemas.google.com/contact/2008'> - Elizabeth Bennet + + Elizabeth + Bennet + Notes @@ -19,6 +23,7 @@ + Carpenter 1600 Amphitheatre Parkway Mountain View diff --git a/utests/supercontact.xml b/utests/supercontact.xml index 4c89c92..c216874 100644 --- a/utests/supercontact.xml +++ b/utests/supercontact.xml @@ -1,7 +1,15 @@ - + - John 'Super' Doe + + John + 'Super' + Doe + + Carpenter diff --git a/utests/utest_contact.c b/utests/utest_contact.c index fcb559f..46c2459 100644 --- a/utests/utest_contact.c +++ b/utests/utest_contact.c @@ -153,6 +153,7 @@ START_TEST (test_contact_xml) 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,"fullName","Dr. John W. Doe"); contact.emails_field = malloc(sizeof(char*)); contact.emails_field[0] = "john.doe@foo.bar.com"; @@ -165,6 +166,7 @@ START_TEST (test_contact_xml) contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; + contact.occupation = "Programmer"; contact.phone_numbers_field = malloc(sizeof(char*)); contact.phone_numbers_field[0] = "+9977554422119900"; contact.emails_type = malloc(sizeof(char*)); @@ -209,8 +211,8 @@ START_TEST (test_contact_xml) fail_if(result == -1 || xml == NULL, "Failed creating XML for a new contact!"); -// ptr = strstr(xml, contact.common.title); -// fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.common.title); + ptr = strstr(xml, "Dr. John W. Doe"); + fail_if(ptr == NULL, "XML lacks a field: gd:name/gd:fullName\n"); ptr = strstr(xml, contact.emails_field[0]); fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.emails_field[0]); ptr = strstr(xml, contact.content); @@ -221,8 +223,18 @@ START_TEST (test_contact_xml) fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.org_title); ptr = strstr(xml, contact.phone_numbers_field[0]); fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.phone_numbers_field[0]); -// ptr = strstr(xml, contact.post_address); -// fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.post_address); + ptr = strstr(xml, "This One St, n 23"); + fail_if(ptr == NULL, "XML lacks a field: street\n"); + ptr = strstr(xml, "PO BOX 333 444 5"); + fail_if(ptr == NULL, "XML lacks a field: pobox\n"); + ptr = strstr(xml, "My Hometown"); + fail_if(ptr == NULL, "XML lacks a field: city\n"); + ptr = strstr(xml, "Hereorthere"); + fail_if(ptr == NULL, "XML lacks a field: region\n"); + ptr = strstr(xml, "XYZ 98765-C"); + fail_if(ptr == NULL, "XML lacks a field: postcode\n"); + ptr = strstr(xml, "Island"); + fail_if(ptr == NULL, "XML lacks a field: country\n"); ptr = strstr(xml, contact.birthday); fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.birthday); /* TODO: im requires a new field for service type (i.e. AIM, yahoo, @@ -270,6 +282,7 @@ START_TEST (test_contact_add) contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; + contact.occupation = "Programmer"; contact.im = "john"; contact.phone_numbers_field = malloc(sizeof(char*)); contact.phone_numbers_field[0] = "+9977554422119900"; @@ -409,6 +422,7 @@ START_TEST (test_contact_edit) contact.content = "A very interesting person"; contact.org_name = "Foo software"; contact.org_title = "Software engineer"; + contact.occupation = "Programmer"; contact.im = "johny"; contact.phone_numbers_field = malloc(sizeof(char*)); contact.phone_numbers_field[0] = "+9977554422119900"; diff --git a/utests/utest_userapi.c b/utests/utest_userapi.c index 813ccb7..75ae9a1 100644 --- a/utests/utest_userapi.c +++ b/utests/utest_userapi.c @@ -19,6 +19,7 @@ #include "utest_userapi.h" #include "gcalendar.h" #include "gcontact.h" +#include "gcal_parser.h" #include "utils.h" #include #include @@ -338,7 +339,12 @@ START_TEST (test_oper_contact) /* Create a new contact object */ contact = gcal_contact_new(NULL); fail_if (!contact, "Cannot construct contact object!"); - gcal_contact_set_title(contact, "John Doe"); +// gcal_contact_set_title(contact, "John Doe"); + + contact->structured_name_nr = 1; + gcal_contact_set_structured_entry(contact->structured_name,0,1,"givenName","John"); + gcal_contact_set_structured_entry(contact->structured_name,0,1,"familyName","Doe"); + gcal_contact_delete_email_addresses(contact); gcal_contact_add_email_address(contact, "john.doe@foo.bar.com", E_OTHER, 1); @@ -352,7 +358,12 @@ START_TEST (test_oper_contact) fail_if(result == -1, "Failed adding a new contact!"); /* Edit this contact */ - gcal_contact_set_title(contact, "John 'The Generic' Doe"); +// gcal_contact_set_title(contact, "John 'The Generic' Doe"); + + gcal_contact_set_structured_entry(contact->structured_name,0,1,"givenName","John"); + gcal_contact_set_structured_entry(contact->structured_name,0,1,"additionalName","'The Generic'"); + gcal_contact_set_structured_entry(contact->structured_name,0,1,"familyName","Doe"); + fail_if(result == -1, "Failed editing contact!"); gcal_contact_delete_email_addresses(contact); gcal_contact_add_email_address(contact, "john.super.doe@foo.bar.com", E_OTHER, 1); diff --git a/utests/utest_xmlmode.c b/utests/utest_xmlmode.c index d0f68b4..0bd7695 100644 --- a/utests/utest_xmlmode.c +++ b/utests/utest_xmlmode.c @@ -206,9 +206,9 @@ START_TEST (test_oper_purexml) { char *super_contact = NULL, *edit_url = NULL, *etag = NULL; char *updated1 = NULL, *updated2 = NULL, *updated3 = NULL; - char *temp; gcal_t gcal; gcal_contact_t contact; + gcal_structured_subvalues_t structured_entry; int result; gcal = gcal_new(GCONTACT); @@ -241,17 +241,12 @@ START_TEST (test_oper_purexml) * updated edit_url, id, etc. */ contact = gcal_contact_new(updated2); - gcal_structured_subvalues_t structured_entry; - structured_entry = gcal_contact_get_structured_name(contact); - temp = (char *)malloc(sizeof(char *)); - temp = gcal_contact_get_structured_entry(structured_entry,0,1,"fullName"); - fail_if(!contact, "Cannot create contact object!\n"); - - fail_if(strcmp("John 'Super' Doe", temp), + + structured_entry = gcal_contact_get_structured_name(contact); + fail_if(strcmp("John 'Super' Doe", gcal_contact_get_structured_entry(structured_entry,0,1,"fullName")), "Failure parsing contact XML: fullName!"); - if(temp) - free(temp); + /* update corner case where the new XML doesn't have the edit URL */ free(super_contact); if (find_load_file("/utests/contact_documentation.xml", &super_contact)) -- 2.11.4.GIT