diff options
author | Hans Petter <hansp@src.gnome.org> | 2003-09-12 06:04:44 +0800 |
---|---|---|
committer | Hans Petter <hansp@src.gnome.org> | 2003-09-12 06:04:44 +0800 |
commit | 697761cc337aa77a47140c8df50ed84bc25e23f6 (patch) | |
tree | b785830f72e9938cceaa016a419c7b6d9892bada /libical/src/test/regression.c | |
parent | 733d77e657516f9a59b5c1a7b62acb87b03ec86f (diff) | |
download | gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.gz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.bz2 gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.lz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.xz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.zst gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.zip |
Import new libical from mainline HEAD and make appropriate changes to
Evolution.
svn path=/trunk/; revision=22538
Diffstat (limited to 'libical/src/test/regression.c')
-rw-r--r-- | libical/src/test/regression.c | 3026 |
1 files changed, 1544 insertions, 1482 deletions
diff --git a/libical/src/test/regression.c b/libical/src/test/regression.c index 08696207f2..1e9fc8e2c5 100644 --- a/libical/src/test/regression.c +++ b/libical/src/test/regression.c @@ -29,16 +29,27 @@ #include "ical.h" #include "icalss.h" +#include "icalvcal.h" + +#include "regression.h" #include <assert.h> #include <string.h> /* for strdup */ #include <stdlib.h> /* for malloc */ #include <stdio.h> /* for printf */ #include <time.h> /* for time() */ +#ifndef WIN32 #include <unistd.h> /* for unlink, fork */ #include <sys/wait.h> /* For waitpid */ -#include <sys/types.h> /* For wait pid */ #include <sys/time.h> /* for select */ +#else +#include <Windows.h> +#endif +#include <sys/types.h> /* For wait pid */ + +#ifdef WIN32 +typedef int pid_t; +#endif /* For GNU libc, strcmp appears to be a macro, so using strcmp in @@ -52,11 +63,11 @@ int regrstrcmp(const char* a, const char* b){ /* This example creates and minipulates the ical object that appears * in rfc 2445, page 137 */ -char str[] = "BEGIN:VCALENDAR\ +static char str[] = "BEGIN:VCALENDAR\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\ VERSION:2.0\ BEGIN:VTIMEZONE\ -TZID:US-Eastern\ +TZID:America/New_York\ BEGIN:STANDARD\ DTSTART:19981025T020000\ RDATE:19981025T020000\ @@ -82,8 +93,8 @@ CATEGORIES:MEETING\ CLASS:PUBLIC\ CREATED:19980309T130000Z\ SUMMARY:XYZ Project Review\ -DTSTART;TZID=US-Eastern:19980312T083000\ -DTEND;TZID=US-Eastern:19980312T093000\ +DTSTART;TZID=America/New_York:19980312T083000\ +DTEND;TZID=America/New_York:19980312T093000\ LOCATION:1CP Conference Room 4350\ END:VEVENT\ BEGIN:BOOGA\ @@ -95,336 +106,10 @@ END:BOOGA\ END:VCALENDAR"; -icalcomponent* create_simple_component() -{ - - icalcomponent* calendar; - struct icalperiodtype rtime; - - rtime.start = icaltime_from_timet( time(0),0); - rtime.end = icaltime_from_timet( time(0),0); - - rtime.end.hour++; - - - - /* Create calendar and add properties */ - calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - return calendar; - -} - -/* Create a new component */ -icalcomponent* create_new_component() -{ - - icalcomponent* calendar; - icalcomponent* timezone; - icalcomponent* tzc; - icalcomponent* event; - struct icaltimetype atime = icaltime_from_timet( time(0),0); - struct icaldatetimeperiodtype rtime; - icalproperty* property; - - rtime.period.start = icaltime_from_timet( time(0),0); - rtime.period.end = icaltime_from_timet( time(0),0); - rtime.period.end.hour++; - rtime.time = icaltime_null_time(); - - - - /* Create calendar and add properties */ - calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - icalcomponent_add_property( - calendar, - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN") - ); - - /* Create a timezone object and add it to the calendar */ - - timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT); - - icalcomponent_add_property( - timezone, - icalproperty_new_tzid("US_Eastern") - ); - - /* Add a sub-component of the timezone */ - tzc = icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - icalcomponent_add_component(calendar,timezone); - - /* Add a second subcomponent */ - tzc = icalcomponent_new(ICAL_XSTANDARD_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - /* Add an event */ - - event = icalcomponent_new(ICAL_VEVENT_COMPONENT); - - icalcomponent_add_property( - event, - icalproperty_new_dtstamp(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_uid("guid-1.host1.com") - ); - - /* add a property that has parameters */ - property = icalproperty_new_organizer("mrbig@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_CHAIR) - ); - - icalcomponent_add_property(event,property); - - /* add another property that has parameters */ - property = icalproperty_new_attendee("employee-A@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_rsvp(ICAL_RSVP_TRUE) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_cutype(ICAL_CUTYPE_GROUP) - ); - - icalcomponent_add_property(event,property); - - - /* more properties */ - - icalcomponent_add_property( - event, - icalproperty_new_description("Project XYZ Review Meeting") - ); - - icalcomponent_add_property( - event, - icalproperty_new_categories("MEETING") - ); - - icalcomponent_add_property( - event, - icalproperty_new_class("PUBLIC") - ); - - icalcomponent_add_property( - event, - icalproperty_new_created(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_summary("XYZ Project Review") - ); - - - property = icalproperty_new_dtstart(atime); - - icalproperty_add_parameter( - property, - icalparameter_new_tzid("US-Eastern") - ); - - icalcomponent_add_property(event,property); - - - property = icalproperty_new_dtend(atime); - - icalproperty_add_parameter( - property, - icalparameter_new_tzid("US-Eastern") - ); - - icalcomponent_add_property(event,property); - - icalcomponent_add_property( - event, - icalproperty_new_location("1CP Conference Room 4350") - ); - - icalcomponent_add_component(calendar,event); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - icalcomponent_free(calendar); - - return 0; -} - - -/* Create a new component, using the va_args list */ - -icalcomponent* create_new_component_with_va_args() -{ - - icalcomponent* calendar; - struct icaltimetype atime = icaltime_from_timet( time(0),0); - struct icaldatetimeperiodtype rtime; - - rtime.period.start = icaltime_from_timet( time(0),0); - rtime.period.end = icaltime_from_timet( time(0),0); - rtime.period.end.hour++; - rtime.time = icaltime_null_time(); - - calendar = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), - icalcomponent_vanew( - ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), - icalcomponent_vanew( - ICAL_XDAYLIGHT_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-4.0), - icalproperty_new_tzoffsetto(-5.0), - icalproperty_new_tzname("EST"), - 0 - ), - icalcomponent_vanew( - ICAL_XSTANDARD_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-5.0), - icalproperty_new_tzoffsetto(-4.0), - icalproperty_new_tzname("EST"), - 0 - ), - 0 - ), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_dtstamp(atime), - icalproperty_new_uid("guid-1.host1.com"), - icalproperty_vanew_organizer( - "mrbig@host.com", - icalparameter_new_role(ICAL_ROLE_CHAIR), - 0 - ), - icalproperty_vanew_attendee( - "employee-A@host.com", - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), - icalparameter_new_rsvp(ICAL_RSVP_TRUE), - icalparameter_new_cutype(ICAL_CUTYPE_GROUP), - 0 - ), - icalproperty_new_description("Project XYZ Review Meeting"), - icalproperty_new_categories("MEETING"), - icalproperty_new_class("PUBLIC"), - icalproperty_new_created(atime), - icalproperty_new_summary("XYZ Project Review"), - icalproperty_vanew_dtstart( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ), - icalproperty_vanew_dtend( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ), - icalproperty_new_location("1CP Conference Room 4350"), - 0 - ), - 0 - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - - icalcomponent_free(calendar); - - return 0; -} - /* Return a list of all attendees who are required. */ -char** get_required_attendees(icalproperty* event) +static char** get_required_attendees(icalcomponent* event) { icalproperty* p; icalparameter* parameter; @@ -435,8 +120,8 @@ char** get_required_attendees(icalproperty* event) attendees = malloc(max * (sizeof (char *))); - assert(event != 0); - assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); + ok("event is non null", (event != 0)); + int_is("event is a VEVENT", icalcomponent_isa(event), ICAL_VEVENT_COMPONENT); for( p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); @@ -464,7 +149,7 @@ char** get_required_attendees(icalproperty* event) /* If an attendee has a PARTSTAT of NEEDSACTION or has no PARTSTAT parameter, change it to TENTATIVE. */ -void update_attendees(icalproperty* event) +static void update_attendees(icalcomponent* event) { icalproperty* p; icalparameter* parameter; @@ -490,7 +175,7 @@ void update_attendees(icalproperty* event) } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) { - icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER); + icalproperty_remove_parameter_by_ref(p,parameter); icalparameter_free(parameter); @@ -510,75 +195,99 @@ void test_values() icalvalue *copy; v = icalvalue_new_caladdress("cap://value/1"); - printf("caladdress 1: %s\n",icalvalue_get_caladdress(v)); + + is("icalvalue_new_caladdress()", + icalvalue_get_caladdress(v), "cap://value/1"); + icalvalue_set_caladdress(v,"cap://value/2"); - printf("caladdress 2: %s\n",icalvalue_get_caladdress(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); - + + is("icalvalue_set_caladdress()", + icalvalue_get_caladdress(v), "cap://value/2"); + + is("icalvalue_as_ical_string()", + icalvalue_as_ical_string(v), "cap://value/2"); + copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + + is("icalvalue_new_clone()", + icalvalue_as_ical_string(copy), "cap://value/2"); icalvalue_free(v); icalvalue_free(copy); v = icalvalue_new_boolean(1); - printf("caladdress 1: %d\n",icalvalue_get_boolean(v)); + int_is("icalvalue_new_boolean(1)", icalvalue_get_boolean(v), 1); icalvalue_set_boolean(v,2); - printf("caladdress 2: %d\n",icalvalue_get_boolean(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); + ok("icalvalue_set_boolean(2)", (2 == icalvalue_get_boolean(v))); + is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "2"); copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "2"); + icalvalue_free(v); icalvalue_free(copy); - v = icalvalue_new_date(icaltime_from_timet( time(0),0)); - printf("date 1: %s\n",icalvalue_as_ical_string(v)); - icalvalue_set_date(v,icaltime_from_timet( time(0)+3600,0)); - printf("date 2: %s\n",icalvalue_as_ical_string(v)); + v = icalvalue_new_x("test"); + is("icalvalue_new_x(test)", icalvalue_get_x(v), "test"); + icalvalue_set_x(v, "test2"); + is("icalvalue_set_x(test2)", icalvalue_get_x(v), "test2"); + is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "test2"); copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); + is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "test2"); + + icalvalue_free(v); + icalvalue_free(copy); + + + v = icalvalue_new_date(icaltime_from_timet( 1023404802,0)); + is("icalvalue_new_date()", icalvalue_as_ical_string(v), "20020606T230642"); + icalvalue_set_date(v,icaltime_from_timet( 1023404802-3600,0)); + is("icalvalue_set_date()",icalvalue_as_ical_string(v), "20020606T220642"); + + copy = icalvalue_new_clone(v); + is("icalvalue_new_clone()",icalvalue_as_ical_string(v), "20020606T220642"); + icalvalue_free(v); icalvalue_free(copy); v = icalvalue_new(-1); - printf("Invalid type: %p\n",v); + ok("icalvalue_new(-1), Invalid type", (v == NULL)); if (v!=0) icalvalue_free(v); - assert(ICAL_BOOLEAN_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_BOOLEAN)); - assert(ICAL_UTCOFFSET_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_UTCOFFSET)); - assert(ICAL_RECUR_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_RECUR)); - assert(ICAL_CALADDRESS_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_CALADDRESS)); - assert(ICAL_PERIOD_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_PERIOD)); - assert(ICAL_BINARY_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_BINARY)); - assert(ICAL_TEXT_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_TEXT)); - assert(ICAL_DURATION_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DURATION)); - assert(ICAL_INTEGER_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_INTEGER)); - assert(ICAL_TIME_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_TIME)); - assert(ICAL_URI_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_URI)); - assert(ICAL_FLOAT_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_FLOAT)); - assert(ICAL_X_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_X)); - assert(ICAL_DATETIME_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DATETIME)); - assert(ICAL_DATE_VALUE == - icalparameter_value_to_value_kind(ICAL_VALUE_DATE)); + ok("ICAL_BOOLEAN_VALUE",(ICAL_BOOLEAN_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_BOOLEAN))); + ok("ICAL_UTCOFFSET_VALUE",(ICAL_UTCOFFSET_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_UTCOFFSET))); + ok("ICAL_RECUR_VALUE", (ICAL_RECUR_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_RECUR))); + ok("ICAL_CALADDRESS_VALUE",(ICAL_CALADDRESS_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_CALADDRESS))); + ok("ICAL_PERIOD_VALUE", (ICAL_PERIOD_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_PERIOD))); + ok("ICAL_BINARY_VALUE",(ICAL_BINARY_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_BINARY))); + ok("ICAL_TEXT_VALUE",(ICAL_TEXT_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_TEXT))); + ok("ICAL_DURATION_VALUE",(ICAL_DURATION_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DURATION))); + ok("ICAL_INTEGER_VALUE", + (ICAL_INTEGER_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_INTEGER))); + + ok("ICAL_URI_VALUE", + (ICAL_URI_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_URI))); + ok("ICAL_FLOAT_VALUE",(ICAL_FLOAT_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_FLOAT))); + ok("ICAL_X_VALUE",(ICAL_X_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_X))); + ok("ICAL_DATETIME_VALUE",(ICAL_DATETIME_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DATETIME))); + ok("ICAL_DATE_TIME",(ICAL_DATE_VALUE == + icalparameter_value_to_value_kind(ICAL_VALUE_DATE))); /* v = icalvalue_new_caladdress(0); @@ -586,14 +295,29 @@ void test_values() if (v!=0) icalvalue_free(v); */ + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL); + v = icalvalue_new_from_string(ICAL_RECUR_VALUE,"D2 #0"); + ok("illegal recur value", (v == 0)); + + v = icalvalue_new_from_string(ICAL_TRIGGER_VALUE,"Gonk"); + ok("illegal trigger value", (v == 0)); + + v = icalvalue_new_from_string(ICAL_REQUESTSTATUS_VALUE,"Gonk"); + ok("illegal requeststatus value", (v == 0)); + + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_DEFAULT); } + void test_properties() { icalproperty *prop; icalparameter *param; icalproperty *clone; + char test_cn_str[128] = ""; + char *test_cn_str_good = "A Common Name 1A Common Name 2A Common Name 3A Common Name 4"; + char *test_ical_str_good = "COMMENT;CN=A Common Name 1;CN=A Common Name 2;CN=A Common Name 3;CN=A \n Common Name 4:Another Comment\n"; prop = icalproperty_vanew_comment( "Another Comment", @@ -606,38 +330,56 @@ void test_properties() for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); param != 0; param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { - - printf("Prop parameter: %s\n",icalparameter_get_cn(param)); + const char *str = icalparameter_get_cn(param); + if (VERBOSE) printf("Prop parameter: %s\n",icalparameter_get_cn(param)); + strcat(test_cn_str, str); } + is("fetching parameters", test_cn_str, test_cn_str_good); - printf("Prop value: %s\n",icalproperty_get_comment(prop)); - + if (VERBOSE) printf("Prop value: %s\n",icalproperty_get_comment(prop)); + is("icalproperty_get_comment()", + icalproperty_get_comment(prop), "Another Comment"); - printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); + if (VERBOSE) printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); + + is("icalproperty_as_ical_string()", + icalproperty_as_ical_string(prop), test_ical_str_good); clone = icalproperty_new_clone(prop); - printf("Clone:\n %s\n",icalproperty_as_ical_string(prop)); + if (VERBOSE) printf("Clone:\n %s\n",icalproperty_as_ical_string(prop)); + is("icalproperty_new_clone()", + icalproperty_as_ical_string(prop), test_ical_str_good); icalproperty_free(clone); icalproperty_free(prop); prop = icalproperty_new(-1); - printf("Invalid type: %p\n",prop); + ok("test icalproperty_new() with invalid type (-1)", + (prop == NULL)); if (prop!=0) icalproperty_free(prop); +} - /* - prop = icalproperty_new_method(0); +void test_utf8() +{ + icalproperty *prop; + char *utf8text = "aáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaá"; + char *test_ical_str_good = "DESCRIPTION:\n" +" aáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaá\n" +" óaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóa\n" +" áóaáóaáóaáóaáóaáóaáóaáóaáóaá\n"; - printf("Bad string: %p\n",prop); - + prop = icalproperty_new_description(utf8text); - if (prop!=0) icalproperty_free(prop); - */ + is("icalproperty_as_ical_string()", + icalproperty_as_ical_string(prop), test_ical_str_good); + icalproperty_free(prop); } + + void test_parameters() { icalparameter *p; @@ -648,47 +390,55 @@ void test_parameters() p = icalparameter_new_cn(str1); - printf("Common Name: %s\n",icalparameter_get_cn(p)); - - assert(regrstrcmp(str1,icalparameter_get_cn(p)) == 0); - - printf("As String: %s\n",icalparameter_as_ical_string(p)); - - assert(regrstrcmp(icalparameter_as_ical_string(p),"CN=A Common Name")==0); - + is("icalparameter_new_cn()", icalparameter_get_cn(p), str1); + is("icalparameter_as_ical_string()" ,icalparameter_as_ical_string(p),"CN=A Common Name"); + icalparameter_free(p); - p = icalparameter_new_from_string("PARTSTAT=ACCEPTED"); - assert(icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_PARTSTAT_ACCEPTED); + ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER)); + ok("PARTSTAT_ACCEPTED", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_ACCEPTED)); + + icalparameter_free(p); p = icalparameter_new_from_string("ROLE=CHAIR"); - assert(icalparameter_isa(p) == ICAL_ROLE_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_ROLE_CHAIR); + + ok("ROLE_PARAMETER", (icalparameter_isa(p) == ICAL_ROLE_PARAMETER)); + ok("ROLE_CHAIR", (icalparameter_get_partstat(p) == ICAL_ROLE_CHAIR)); + + icalparameter_free(p); p = icalparameter_new_from_string("PARTSTAT=X-FOO"); - assert(icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER); - assert(icalparameter_get_partstat(p) == ICAL_PARTSTAT_X); + ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER)); + ok("PARTSTAT_X", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_X)); + + icalparameter_free(p); p = icalparameter_new_from_string("X-PARAM=X-FOO"); - assert(icalparameter_isa(p) == ICAL_X_PARAMETER); + ok("X_PARAMETER", (icalparameter_isa(p) == ICAL_X_PARAMETER)); + + icalparameter_free(p); for (i=0;enums[i] != -1; i++){ - - printf("%s\n",icalparameter_enum_to_string(enums[i])); - assert(icalparameter_string_to_enum( - icalparameter_enum_to_string(enums[i]))==enums[i]); + if (VERBOSE) printf("%s\n",icalparameter_enum_to_string(enums[i])); + ok("test paramter enums", + (icalparameter_string_to_enum(icalparameter_enum_to_string(enums[i]))==enums[i])); } - - } +char *good_child = +"BEGIN:VEVENT\n" +"VERSION:2.0\n" +"DESCRIPTION:This is an event\n" +"COMMENT;CN=A Common Name 1;CN=A Common Name 2;CN=A Common Name 3;CN=A \n" +" Common Name 4:Another Comment\n" +"X-LIC-ERROR;X-LIC-ERRORTYPE=COMPONENT-PARSE-ERROR:This is only a test\n" +"END:VEVENT\n"; + void test_components() { - icalcomponent* c; icalcomponent* child; @@ -721,16 +471,24 @@ void test_components() 0 ); - printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c)); + if (VERBOSE) + printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c)); child = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - - printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child)); - icalcomponent_free(c); + ok("test icalcomponent_get_first_component()", + (child != NULL)); + + if (VERBOSE) + printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child)); + is("test results of child component", + icalcomponent_as_ical_string(child), good_child); + + icalcomponent_free(c); } + void test_memory() { size_t bufsize = 256; @@ -792,19 +550,23 @@ void test_memory() icalmemory_append_string(&f, &p, &bufsize, b8); - printf("1: %p %s \n",b1,b1); - printf("2: %p %s\n",b2,b2); - printf("3: %p %s\n",b3,b3); - printf("4: %p %s\n",b4,b4); - printf("5: %p %s\n",b5,b5); - printf("6: %p %s\n",b6,b6); - printf("7: %p %s\n",b7,b7); - printf("8: %p %s\n",b8,b8); - - - printf("Final: %s\n", f); + if (VERBOSE) { + printf("1: %p %s \n",b1,b1); + printf("2: %p %s\n",b2,b2); + printf("3: %p %s\n",b3,b3); + printf("4: %p %s\n",b4,b4); + printf("5: %p %s\n",b5,b5); + printf("6: %p %s\n",b6,b6); + printf("7: %p %s\n",b7,b7); + printf("8: %p %s\n",b8,b8); + + + printf("Final: %s\n", f); + + printf("Final buffer size: %d\n",bufsize); + } - printf("Final buffer size: %d\n",bufsize); + ok("final buffer size == 806", (bufsize == 806)); free(f); @@ -816,46 +578,49 @@ void test_memory() p = f; icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); + icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); - + if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); + + free(f); + for(i=0; i<100; i++){ f = icalmemory_tmp_buffer(bufsize); @@ -867,16 +632,26 @@ void test_memory() } -int test_store() +void test_dirset() { - - icalcomponent *c, *gauge; + icalcomponent *c; + icalgauge *gauge; icalerrorenum error; icalcomponent *next, *itr; - icalfileset* cluster; + icalset* cluster; + icalset *s, *s2; struct icalperiodtype rtime; - icaldirset *s = icaldirset_new("store"); int i; + int count = 0; + + mkdir("store", 0755); + mkdir("store-new", 0755); + + s = icaldirset_new("store"); + s2 = icaldirset_new("store-new"); + + ok("opening 'store' dirset", s!=NULL); + ok("opening 'store-new' dirset", s2!=NULL); rtime.start = icaltime_from_timet( time(0),0); @@ -884,7 +659,6 @@ int test_store() if (cluster == 0){ printf("Failed to create cluster: %s\n",icalerror_strerror(icalerrno)); - return 0; } #define NUMCOMP 4 @@ -911,7 +685,6 @@ int test_store() continue; } - assert(itr != 0); /* Change the dtstart and dtend times in the component pointed to by Itr*/ @@ -949,42 +722,19 @@ int test_store() error = icaldirset_add_component(s,clone); assert(icalerrno == ICAL_NO_ERROR); - } - } - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Submit Income Taxes", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Bastille Day Party", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); - -#if 0 - + gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0); icaldirset_select(s,gauge); - for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ - + for(c = icaldirset_get_first_component(s); c != 0; c = icaldirset_get_next_component(s)){ printf("Got one! (%d)\n", count++); if (c != 0){ printf("%s", icalcomponent_as_ical_string(c));; - if (icaldirset_store(s2,c) == 0){ + if (icaldirset_add_component(s2,c) == 0){ printf("Failed to write!\n"); } icalcomponent_free(c); @@ -994,9 +744,7 @@ int test_store() } - icaldirset_free(s2); -#endif - + icalset_free(s2); for(c = icaldirset_get_first_component(s); c != 0; @@ -1010,51 +758,70 @@ int test_store() } else { printf("Failed to get component\n"); } - - } - icaldirset_free(s); - return 0; + icalset_free(s); + icalset_free(cluster); } -int test_compare() + +void test_compare() { icalvalue *v1, *v2; v1 = icalvalue_new_caladdress("cap://value/1"); v2 = icalvalue_new_clone(v1); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("compare value and clone", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_caladdress("A"); v2 = icalvalue_new_caladdress("B"); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of A and B results in LESS", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS)); + + ok("test compare of B and A results in GREATER", + (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_caladdress("B"); v2 = icalvalue_new_caladdress("A"); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of caladdress A and B results in GREATER", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_GREATER)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_integer(5); v2 = icalvalue_new_integer(5); - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of 5 and 5 results in EQUAL", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL)); + + icalvalue_free(v1); + icalvalue_free(v2); v1 = icalvalue_new_integer(5); v2 = icalvalue_new_integer(10); - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_integer(10); - v2 = icalvalue_new_integer(5); - - printf("%d\n",icalvalue_compare(v1,v2)); + ok("test compare of 5 and 10 results in LESS", + (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS)); + + ok("test compare of 10 and 5 results in GREATER", + (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER)); - return 0; + icalvalue_free(v1); + icalvalue_free(v2); } + void test_restriction() { icalcomponent *comp; @@ -1063,6 +830,8 @@ void test_restriction() struct icaldatetimeperiodtype rtime; + char *str; + rtime.period.start = icaltime_from_timet( time(0),0); rtime.period.end = icaltime_from_timet( time(0),0); rtime.period.end.hour++; @@ -1076,7 +845,7 @@ void test_restriction() icalproperty_new_method(ICAL_METHOD_REQUEST), icalcomponent_vanew( ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), + icalproperty_new_tzid("America/New_York"), icalcomponent_vanew( ICAL_XDAYLIGHT_COMPONENT, icalproperty_new_dtstart(atime), @@ -1115,17 +884,17 @@ void test_restriction() ), icalproperty_new_description("Project XYZ Review Meeting"), icalproperty_new_categories("MEETING"), - icalproperty_new_class("PUBLIC"), + icalproperty_new_class(ICAL_CLASS_PUBLIC), icalproperty_new_created(atime), icalproperty_new_summary("XYZ Project Review"), /* icalproperty_new_dtstart( atime, - icalparameter_new_tzid("US-Eastern"), + icalparameter_new_tzid("America/New_York"), 0 ),*/ icalproperty_vanew_dtend( atime, - icalparameter_new_tzid("US-Eastern"), + icalparameter_new_tzid("America/New_York"), 0 ), icalproperty_new_location("1CP Conference Room 4350"), @@ -1135,22 +904,31 @@ void test_restriction() ); valid = icalrestriction_check(comp); + + ok("icalrestriction_check() == 0", (valid==0)); + + str = icalcomponent_as_ical_string(comp); - printf("#### %d ####\n%s\n",valid, icalcomponent_as_ical_string(comp)); + icalcomponent_free(comp); } -#if 0 void test_calendar() { icalcomponent *comp; - icalfileset *c; - icaldirset *s; - icalcalendar* calendar = icalcalendar_new("calendar"); + icalset *c; + icalset *s; + icalcalendar* calendar; icalerrorenum error; struct icaltimetype atime = icaltime_from_timet( time(0),0); - comp = icalcomponent_vanew( + mkdir("calendar", 0755); + mkdir("calendar/booked", 0755); + + calendar = icalcalendar_new("calendar"); + + comp = icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_new_version("2.0"), icalproperty_new_description("This is an event"), @@ -1167,25 +945,25 @@ void test_calendar() icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), 0), - 0); - - + 0),0); + s = icalcalendar_get_booked(calendar); error = icaldirset_add_component(s,comp); - assert(error == ICAL_NO_ERROR); + ok("Adding Component to dirset", (error == ICAL_NO_ERROR)); c = icalcalendar_get_properties(calendar); error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); - assert(error == ICAL_NO_ERROR); + ok("Adding Clone Component to dirset", (error == ICAL_NO_ERROR)); icalcalendar_free(calendar); + ok("icalcalendar test", (1)); } -#endif + void test_increment(void); @@ -1223,9 +1001,9 @@ void test_recur() rt = icalrecurrencetype_from_string("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA"); start = icaltime_from_string("19970905T090000Z"); - print_occur(rt,start); + if (VERBOSE) print_occur(rt,start); - printf("\n Using icalrecur_expand_recurrence\n"); + if (VERBOSE) printf("\n Using icalrecur_expand_recurrence\n"); icalrecur_expand_recurrence("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA", icaltime_as_timet(start), @@ -1233,8 +1011,7 @@ void test_recur() array); for(i =0; array[i] != 0 && i < 25 ; i++){ - - printf(" %s",ctime(&(array[i]))); + if (VERBOSE) printf(" %s",ctime(&(array[i]))); } @@ -1242,20 +1019,22 @@ void test_recur() } + void test_expand_recurrence(){ time_t arr[10]; time_t now = 931057385; - int i; + int i, numfound = 0; icalrecur_expand_recurrence( "FREQ=MONTHLY;BYDAY=MO,WE", now, 5, arr ); - printf("Start %s",ctime(&now) ); - for (i=0; i<5; i++) - { - printf("i=%d %s\n", i, ctime(&arr[i]) ); - } - + if (VERBOSE) printf("Start %s",ctime(&now) ); + + for (i=0; i<5; i++) { + numfound++; + if (VERBOSE) printf("i=%d %s\n", i, ctime(&arr[i]) ); + } + int_is("Get an array of 5 items", numfound, 5); } @@ -1273,23 +1052,6 @@ enum byrule { BY_SET_POS }; -struct icalrecur_iterator_impl { - - struct icaltimetype dtstart; - struct icaltimetype last; /* last time return from _iterator_next*/ - int occurrence_no; /* number of step made on this iterator */ - struct icalrecurrencetype rule; - - short days[366]; - short days_index; - - enum byrule byrule; - short by_indices[9]; - - - short *by_ptrs[9]; /* Pointers into the by_* array elements of the rule */ -}; - void icalrecurrencetype_test() { icalvalue *v = icalvalue_new_from_string( @@ -1312,6 +1074,10 @@ void icalrecurrencetype_test() printf("%s",ctime(&tt )); } while( ! icaltime_is_null_time(next)); + + icalvalue_free(v); + + icalrecur_iterator_free(itr); } @@ -1327,26 +1093,27 @@ void test_recur_parameter_bug(){ #include <ical.h> static const char test_icalcomp_str[] = -"BEGIN:VEVENT\r\n" -"RRULE\r\n" -" ;X-EVOLUTION-ENDDATE=20030209T081500\r\n" -" :FREQ=DAILY;COUNT=10;INTERVAL=6\r\n" -"END:VEVENT\r\n"; +"BEGIN:VEVENT\n" +"RRULE;X-EVOLUTION-ENDDATE=20030209T081500:FREQ=DAILY;COUNT=10;INTERVAL=6\n" +"END:VEVENT\n"; icalcomponent *icalcomp; icalproperty *prop; struct icalrecurrencetype recur; int n_errors; - + char *str; + icalcomp = icalparser_parse_string ((char *) test_icalcomp_str); - if (!icalcomp) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + ok("icalparser_parse_string()",(icalcomp!=NULL)); + assert(icalcomp!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); + str = icalcomponent_as_ical_string(icalcomp); + is("parsed matches original", str, (char*)test_icalcomp_str); + if (VERBOSE) printf("%s\n\n",str); n_errors = icalcomponent_count_errors (icalcomp); + int_is("no parse errors", n_errors, 0); + if (n_errors) { icalproperty *p; @@ -1355,7 +1122,7 @@ void test_recur_parameter_bug(){ p; p = icalcomponent_get_next_property (icalcomp, ICAL_XLICERROR_PROPERTY)) { - char *str; + const char *str; str = icalproperty_as_ical_string (p); fprintf (stderr, "error: %s\n", str); @@ -1363,350 +1130,564 @@ void test_recur_parameter_bug(){ } prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY); - if (!prop) { - fprintf (stderr, "main(): could not get the RRULE property"); - exit (EXIT_FAILURE); - } + ok("get RRULE property", (prop!=NULL)); + assert(prop!=NULL); recur = icalproperty_get_rrule (prop); - printf("%s\n",icalrecurrencetype_as_string(&recur)); + if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur)); + icalcomponent_free(icalcomp); } void test_duration() { - - struct icaldurationtype d; d = icaldurationtype_from_string("PT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 30600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("PT8H30M", icaldurationtype_as_int(d), 30600); d = icaldurationtype_from_string("-PT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == -30600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("-PT8H30M", icaldurationtype_as_int(d), -30600); d = icaldurationtype_from_string("PT10H10M10S"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 36610); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("PT10H10M10S", icaldurationtype_as_int(d), 36610); d = icaldurationtype_from_string("P7W"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 4233600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P7W", icaldurationtype_as_int(d), 4233600); d = icaldurationtype_from_string("P2DT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 203400); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P2DT8H30M", icaldurationtype_as_int(d), 203400); icalerror_errors_are_fatal = 0; + /* Test conversion of bad input */ + + d = icaldurationtype_from_int(1314000); + if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d), + icaldurationtype_as_int(d)); + is("1314000", icaldurationtype_as_ical_string(d), "P15DT5H"); + + d = icaldurationtype_from_string("P2W1DT5H"); + if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d), + icaldurationtype_as_int(d)); + int_is("P15DT5H", icaldurationtype_as_int(d), 0); + d = icaldurationtype_from_string("P-2DT8H30M"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P-2DT8H30M", icaldurationtype_as_int(d), 0); d = icaldurationtype_from_string("P7W8H"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("P7W8H", icaldurationtype_as_int(d), 0); d = icaldurationtype_from_string("T10H"); - printf("%s\n",icaldurationtype_as_ical_string(d)); - assert(icaldurationtype_as_int(d) == 0); - + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + int_is("T10H", icaldurationtype_as_int(d), 0); icalerror_errors_are_fatal = 1; + d = icaldurationtype_from_int(4233600); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + is("P7W", + icaldurationtype_as_ical_string(d), "P7W"); + + d = icaldurationtype_from_int(4424400); + if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d)); + is("P51DT5H", + icaldurationtype_as_ical_string(d), "P51DT5H"); } + void test_period() { - struct icalperiodtype p; icalvalue *v; + char *str; + + str = "19971015T050000Z/PT8H30M"; + p = icalperiodtype_from_string(str); + is(str, icalperiodtype_as_ical_string(p),str); - p = icalperiodtype_from_string("19971015T050000Z/PT8H30M"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19971015T050000Z/PT8H30M") == 0); - p = icalperiodtype_from_string("19971015T050000Z/19971015T060000Z"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19971015T050000Z/19971015T060000Z") == 0); + str = "19971015T050000Z/19971015T060000Z"; + p = icalperiodtype_from_string(str); + is(str, icalperiodtype_as_ical_string(p),str); - p = icalperiodtype_from_string("19970101T120000/PT3H"); - printf("%s\n",icalperiodtype_as_ical_string(p)); - assert(strcmp(icalperiodtype_as_ical_string(p), - "19970101T120000/PT3H") == 0); - v = icalvalue_new_from_string(ICAL_PERIOD_VALUE,"19970101T120000/PT3H"); - printf("%s\n",icalvalue_as_ical_string(v)); - assert(strcmp(icalvalue_as_ical_string(v), - "19970101T120000/PT3H") == 0); + str = "19970101T120000/PT3H"; + v = icalvalue_new_from_string(ICAL_PERIOD_VALUE,str); + is(str, icalvalue_as_ical_string(v), str); + icalvalue_free(v); } -void test_strings(){ +void test_strings(){ icalvalue *v; v = icalvalue_new_text("foo;bar;bats"); - - printf("%s\n",icalvalue_as_ical_string(v)); + if (VERBOSE) + printf("%s\n",icalvalue_as_ical_string(v)); + + is("test encoding of 'foo;bar;bats'", + "foo\\;bar\\;bats", icalvalue_as_ical_string(v)); icalvalue_free(v); + v = icalvalue_new_text("foo\\;b\nar\\;ba\tts"); + if (VERBOSE) + printf("%s\n",icalvalue_as_ical_string(v)); - printf("%s\n",icalvalue_as_ical_string(v)); + is("test encoding of 'foo\\\\;b\\nar\\\\;ba\\tts'", + "foo\\\\\\;b\\nar\\\\\\;ba\\tts", icalvalue_as_ical_string(v)); icalvalue_free(v); - - } + void test_requeststat() { - icalrequeststatus s; - struct icalreqstattype st, st2; - char temp[1024]; - - s = icalenum_num_to_reqstat(2,1); - - assert(s == ICAL_2_1_FALLBACK_STATUS); - - assert(icalenum_reqstat_major(s) == 2); - assert(icalenum_reqstat_minor(s) == 1); - - printf("2.1: %s\n",icalenum_reqstat_desc(s)); - - st.code = s; - st.debug = "booga"; - st.desc = 0; - - printf("%s\n",icalreqstattype_as_string(st)); + icalproperty *p; + icalrequeststatus s; + struct icalreqstattype st, st2; + char temp[1024]; + + s = icalenum_num_to_reqstat(2,1); + + ok("icalenum_num_to_reqstat(2,1)",(s == ICAL_2_1_FALLBACK_STATUS)); + + ok("icalenum_reqstat_major()",(icalenum_reqstat_major(s) == 2)); + ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(s) == 1)); + + is ("icalenum_reqstat_desc() -> 2.1", icalenum_reqstat_desc(s), + "Success but fallback taken on one or more property values."); + + st.code = s; + st.debug = "booga"; + st.desc = 0; + + is("icalreqstattype_as_string()", + icalreqstattype_as_string(st), + "2.1;Success but fallback taken on one or more property values.;booga"); + + st.desc = " A non-standard description"; + + is("icalreqstattype_as_string() w/ non standard description", + icalreqstattype_as_string(st), + "2.1; A non-standard description;booga"); + + st.desc = 0; + + sprintf(temp,"%s\n",icalreqstattype_as_string(st)); + + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); + + /* printf("%d -- %d -- %s -- %s\n",*/ + ok("icalenum_reqstat_major()",(icalenum_reqstat_major(st2.code) == 2)); + ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(st2.code) == 1)); + is("icalenum_reqstat_desc", + icalenum_reqstat_desc(st2.code), + "Success but fallback taken on one or more property values."); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values."); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); + + st2 = icalreqstattype_from_string("2.1;"); + if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2)); - st.desc = " A non-standard description"; + is("st2 test again", + icalreqstattype_as_string(st2), + "2.1;Success but fallback taken on one or more property values."); + + st2 = icalreqstattype_from_string("2.1"); + is("st2 test #3", + icalreqstattype_as_string(st2), + "2.1;Success but fallback taken on one or more property values."); + + p = icalproperty_new_from_string("REQUEST-STATUS:2.1;Success but fallback taken on one or more property values.;booga"); - printf("%s\n",icalreqstattype_as_string(st)); + is("icalproperty_new_from_string()", + icalproperty_as_ical_string(p), + "REQUEST-STATUS:2.1;Success but fallback taken on one or more property \n values.;booga\n"); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); + st2 = icalreqstattype_from_string("16.4"); + + ok("test unknown code", (st2.code == ICAL_UNKNOWN_STATUS)); + + st2 = icalreqstattype_from_string("1."); + + ok("test malformed code", (st2.code == ICAL_UNKNOWN_STATUS)); + icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT); - st.desc = 0; + icalproperty_free(p); +} - sprintf(temp,"%s\n",icalreqstattype_as_string(st)); - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); +void test_dtstart(){ + + struct icaltimetype tt,tt2; + + icalproperty *p; + - printf("%d -- %d -- %s -- %s\n",icalenum_reqstat_major(st2.code), - icalenum_reqstat_minor(st2.code), - icalenum_reqstat_desc(st2.code), - st2.debug); + tt = icaltime_from_string("19970101"); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); - printf("%s\n",icalreqstattype_as_string(st2)); + int_is("19970101 is a date", tt.is_date, 1); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;"); - printf("%s\n",icalreqstattype_as_string(st2)); + p = icalproperty_new_dtstart(tt); - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values."); - printf("%s\n",icalreqstattype_as_string(st2)); + if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p)))); - st2 = icalreqstattype_from_string("2.1;"); - printf("%s\n",icalreqstattype_as_string(st2)); + ok("ICAL_DATE_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATE_VALUE)); - st2 = icalreqstattype_from_string("2.1"); - printf("%s\n",icalreqstattype_as_string(st2)); + tt2 = icalproperty_get_dtstart(p); + int_is("converted date is date", tt2.is_date, 1); -#ifndef ICAL_ERRORS_ARE_FATAL - st2 = icalreqstattype_from_string("16.4"); - assert(st2.code == ICAL_UNKNOWN_STATUS); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - st2 = icalreqstattype_from_string("1."); - assert(st2.code == ICAL_UNKNOWN_STATUS); -#endif -} + tt = icaltime_from_string("19970101T103000"); -char ictt_str[1024]; -char* ictt_as_string(struct icaltimetype t) -{ + int_is("19970101T103000 is not a date", tt.is_date, 0); - sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d%s",t.year,t.month,t.day, - t.hour,t.minute,t.second,t.is_utc?" Z":""); + icalproperty_free(p); - return ictt_str; -} + p = icalproperty_new_dtstart(tt); + if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p)))); + ok("ICAL_DATETIME_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATETIME_VALUE)); -char* ical_timet_string(time_t t) -{ - struct tm stm = *(gmtime(&t)); + tt2 = icalproperty_get_dtstart(p); + int_is("converted datetime is not date", tt2.is_date, 0); - sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z",stm.tm_year+1900, - stm.tm_mon+1,stm.tm_mday,stm.tm_hour,stm.tm_min,stm.tm_sec); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - return ictt_str; - + icalproperty_free(p); } void do_test_time(char* zone) { - struct icaltimetype ictt, icttutc, icttutczone, icttdayl, + struct icaltimetype ictt, icttutc, icttzone, icttdayl, icttla, icttny,icttphoenix, icttlocal, icttnorm; time_t tt,tt2, tt_p200; - int offset_la, offset_tz; + int offset_tz; icalvalue *v; short day_of_week,start_day_of_week, day_of_year; + icaltimezone *azone, *utczone; + char msg[256]; icalerror_errors_are_fatal = 0; + azone = icaltimezone_get_builtin_timezone(zone); + utczone = icaltimezone_get_utc_timezone(); + + /* Test new API */ + if (VERBOSE) printf("\n---> From time_t \n"); + + tt = 1025127869; /* stick with a constant... */ + + if (VERBOSE) printf("Orig : %s\n",ical_timet_string(tt)); + if (VERBOSE) printf("\nicaltime_from_timet(tt,0) (DEPRECATED)\n"); + + ictt = icaltime_from_timet(tt, 0); + + is("icaltime_from_timet(1025127869) as UTC", ictt_as_string(ictt), + "2002-06-26 21:44:29 (floating)"); + + ictt = icaltime_from_timet_with_zone(tt, 0, NULL); + is("Floating time from time_t", + ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); + + ictt = icaltime_from_timet_with_zone(tt, 0, azone); + ok("icaltime_from_timet_with_zone(tt,0,zone) as zone", + strncmp(ictt_as_string(ictt), "2002-06-26 21:44:29", 19)==0); + + ictt = icaltime_from_timet_with_zone(tt, 0, utczone); + + is("icaltime_from_timet_with_zone(tt,0,utc)", ictt_as_string(ictt), + "2002-06-26 21:44:29 Z UTC"); + + if (VERBOSE) printf("\n---> Convert from floating \n"); + + ictt = icaltime_from_timet_with_zone(tt, 0, NULL); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + is("Convert from floating to UTC", + ictt_as_string(icttutc), + "2002-06-26 21:44:29 Z UTC"); + + icttzone = icaltime_convert_to_zone(ictt, azone); + + ok("Convert from floating to zone", + (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 19)==0)); + + tt2 = icaltime_as_timet(icttzone); + + if (VERBOSE) printf("\n---> Convert from UTC \n"); + + ictt = icaltime_from_timet_with_zone(tt, 0, utczone); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + is("Convert from UTC to UTC", + ictt_as_string(icttutc), + "2002-06-26 21:44:29 Z UTC"); + + icttzone = icaltime_convert_to_zone(ictt, azone); + + ok("Convert from UTC to zone (test year/mon only..)", + (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 7)==0)); + + tt2 = icaltime_as_timet(icttzone); + + if (VERBOSE) printf("No conversion: %s\n", ical_timet_string(tt2)); + + ok("No conversion at all (test year/mon only)", + (strncmp(ical_timet_string(tt2), "2002-06-26 21:44:29 Z",7) == 0)); + + tt2 = icaltime_as_timet_with_zone(icttzone, utczone); + if (VERBOSE) printf("Back to UTC : %s\n", ical_timet_string(tt2)); + + ok("test time conversion routines",(tt==tt2)); + + if (VERBOSE) printf("\n---> Convert from zone \n"); + ictt = icaltime_from_timet_with_zone(tt, 0, azone); + icttzone = icaltime_convert_to_zone(ictt, azone); + + if (VERBOSE) + printf("To zone : %s\n", ictt_as_string(icttzone)); + icttutc = icaltime_convert_to_zone(ictt, utczone); + + if (VERBOSE) + printf("To UTC : %s\n", ictt_as_string(icttutc)); + tt2 = icaltime_as_timet(icttutc); + + if (VERBOSE) + printf("No conversion: %s\n", ical_timet_string(tt2)); + + tt2 = icaltime_as_timet_with_zone(icttutc, azone); + + if (VERBOSE) + printf("Back to zone : %s\n", ical_timet_string(tt2)); + + ok("test time conversion, round 2", (tt==tt2)); + ictt = icaltime_from_string("20001103T183030Z"); tt = icaltime_as_timet(ictt); - assert(tt==973276230); /* Fri Nov 3 10:30:30 PST 2000 in PST - Fri Nov 3 18:30:30 PST 2000 in UTC */ + ok("test icaltime -> time_t for 20001103T183030Z", (tt==973276230)); + /* Fri Nov 3 10:30:30 PST 2000 in PST + Fri Nov 3 18:30:30 PST 2000 in UTC */ - offset_la = icaltime_utc_offset(ictt,"America/Los_Angeles"); - offset_tz = icaltime_utc_offset(ictt, zone); - + if (VERBOSE) { printf(" Normalize \n"); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); + } icttnorm = ictt; icttnorm.second -= 60 * 60 * 24 * 5; icttnorm = icaltime_normalize(icttnorm); - printf("-5d in sec : %s\n", ictt_as_string(icttnorm)); + + if (VERBOSE) + printf("-5d in sec : %s\n", ictt_as_string(icttnorm)); icttnorm.day += 60; icttnorm = icaltime_normalize(icttnorm); - printf("+60 d : %s\n", ictt_as_string(icttnorm)); + if (VERBOSE) + printf("+60 d : %s\n", ictt_as_string(icttnorm)); + + /** add test case here.. **/ + if (VERBOSE) printf("\n As time_t \n"); tt2 = icaltime_as_timet(ictt); - printf("20001103T183030Z (timet): %s\n",ical_timet_string(tt2)); - printf("20001103T183030Z : %s\n",ictt_as_string(ictt)); - assert(tt2 == tt); - icttlocal = icaltime_from_string("20001103T183030"); + if (VERBOSE) { + printf("20001103T183030Z (timet): %s\n",ical_timet_string(tt2)); + printf("20001103T183030Z : %s\n",ictt_as_string(ictt)); + } + + /** this test is bogus **/ + ok("test normalization", (tt2 == tt)); + + icttlocal = icaltime_convert_to_zone(ictt, azone); tt2 = icaltime_as_timet(icttlocal); - printf("20001103T183030 (timet): %s\n",ical_timet_string(tt2)); - printf("20001103T183030 : %s\n",ictt_as_string(icttlocal)); - assert(tt-tt2 == offset_tz); + if (VERBOSE) { + printf("20001103T183030 (timet): %s\n",ical_timet_string(tt2)); + printf("20001103T183030 : %s\n",ictt_as_string(icttlocal)); + } - printf("\n From time_t \n"); + offset_tz = -icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0); /* FIXME */ + if (VERBOSE) + printf("offset_tz : %d\n",offset_tz); - printf("Orig : %s\n",ical_timet_string(tt)); - printf("As utc : %s\n", ictt_as_string(ictt)); + ok("test utc offset", (tt-tt2 == offset_tz)); - icttlocal = icaltime_as_zone(ictt,zone); - printf("As local : %s\n", ictt_as_string(icttlocal)); - + /* FIXME with the new API, it's not very useful */ + icttlocal = ictt; + icaltimezone_convert_time(&icttlocal, + icaltimezone_get_utc_timezone(), + icaltimezone_get_builtin_timezone(zone)); - printf("\n Convert to and from lib c \n"); + if (VERBOSE) + printf("As local : %s\n", ictt_as_string(icttlocal)); - printf("System time is: %s\n",ical_timet_string(tt)); + if (VERBOSE) printf("\n Convert to and from lib c \n"); + + if (VERBOSE) printf("System time is: %s\n",ical_timet_string(tt)); v = icalvalue_new_datetime(ictt); - printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); + if (VERBOSE) + printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); + + icalvalue_free(v); tt2 = icaltime_as_timet(ictt); + + if (VERBOSE) printf("Converted back to libc: %s\n",ical_timet_string(tt2)); - printf("\n Incrementing time \n"); + if (VERBOSE) printf("\n Incrementing time \n"); icttnorm = ictt; icttnorm.year++; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add a year: %s\n",ical_timet_string(tt2)); icttnorm.month+=13; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add 13 months: %s\n",ical_timet_string(tt2)); icttnorm.second+=90; tt2 = icaltime_as_timet(icttnorm); + if (VERBOSE) printf("Add 90 seconds: %s\n",ical_timet_string(tt2)); - printf("\n Day Of week \n"); + if (VERBOSE) printf("\n Day Of week \n"); day_of_week = icaltime_day_of_week(ictt); start_day_of_week = icaltime_start_doy_of_week(ictt); day_of_year = icaltime_day_of_year(ictt); + sprintf(msg, "Testing day of week %d", day_of_week); + int_is(msg, day_of_week, 6); - printf("Today is day of week %d, day of year %d\n",day_of_week,day_of_year); - printf("Week started n doy of %d\n",start_day_of_week); - assert(day_of_week == 6); - assert(day_of_year == 308); - assert(start_day_of_week == 303 ); + sprintf(msg, "Testing day of year %d",day_of_year); + int_is(msg, day_of_year, 308); + + sprintf(msg, "Week started on doy of %d", start_day_of_week); + int_is(msg, start_day_of_week , 303); + + if (VERBOSE) printf("\n TimeZone Conversions \n"); + +/* + icttla = ictt; + icaltimezone_convert_time(&icttla, + icaltimezone_get_utc_timezone(), + lazone); +*/ + icttla = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); - printf("\n TimeZone Conversions \n"); + int_is("Converted hour in America/Los_Angeles is 10", icttla.hour, 10); - icttla = icaltime_as_zone(ictt,"America/Los_Angeles"); - assert(icttla.hour == 10); + icttutc = icaltime_convert_to_zone(icttla,icaltimezone_get_utc_timezone()); - icttutc = icaltime_as_utc(icttla,"America/Los_Angeles"); - assert(icaltime_compare(icttla, - icaltime_from_string("20001103T103030"))==0); + ok("America/Los_Angeles local time is 2000-11-03 10:30:30", + (strncmp(ictt_as_string(icttla), "2000-11-03 10:30:30", 19)==0)); - icttutczone = icaltime_as_zone(ictt,"Etc/GMT0"); - icttutczone.is_utc = 1; - assert(icaltime_compare(icttutc, icttutczone) == 0); - assert(icaltime_compare(icttutc, ictt) == 0); + ok("Test conversion back to UTC",(icaltime_compare(icttutc, ictt) == 0)); - icttny = icaltime_as_zone(ictt,"America/New_York"); + icttny = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/New_York")); - icttphoenix = icaltime_as_zone(ictt,"America/Phoenix"); + icttphoenix = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Phoenix")); + if (VERBOSE) { printf("Orig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("UTC : %s\n", ictt_as_string(icttutc)); printf("Los Angeles : %s\n", ictt_as_string(icttla)); printf("Phoenix : %s\n", ictt_as_string(icttphoenix)); printf("New York : %s\n", ictt_as_string(icttny)); - + } + /** @todo Check results for Phoenix here?... **/ /* Daylight savings test for New York */ + if (VERBOSE) { printf("\n Daylight Savings \n"); printf("Orig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("NY : %s\n", ictt_as_string(icttny)); + } - assert(strcmp(ictt_as_string(icttny),"2000-11-03 13:30:30")==0); + ok("Converted time in zone America/New_York is 2000-11-03 13:30:30", + (strncmp(ictt_as_string(icttny),"2000-11-03 13:30:30",19)==0)); tt_p200 = tt + 200 * 24 * 60 * 60 ; /* Add 200 days */ - icttdayl = icaltime_from_timet(tt_p200,0); - icttny = icaltime_as_zone(icttdayl,"America/New_York"); - + icttdayl = icaltime_from_timet_with_zone(tt_p200,0, + icaltimezone_get_utc_timezone()); + icttny = icaltime_convert_to_zone(icttdayl, + icaltimezone_get_builtin_timezone("America/New_York")); + + if (VERBOSE) { printf("Orig +200d : %s\n", ical_timet_string(tt_p200) ); printf("NY+200D : %s\n", ictt_as_string(icttny)); + } + + ok("Converted time +200d in zone America/New_York is 2001-05-22 14:30:30", + (strncmp(ictt_as_string(icttny),"2001-05-22 14:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttny),"2001-05-22 14:30:30")==0); /* Daylight savings test for Los Angeles */ - icttla = icaltime_as_zone(ictt,"America/Los_Angeles"); + icttla = icaltime_convert_to_zone(ictt, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); + if (VERBOSE) { printf("\nOrig (ctime): %s\n", ical_timet_string(tt) ); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("LA : %s\n", ictt_as_string(icttla)); + } + + ok("Converted time in zone America/Los_Angeles is 2000-11-03 10:30:30", + (strncmp(ictt_as_string(icttla),"2000-11-03 10:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttla),"2000-11-03 10:30:30")==0); - - icttla = icaltime_as_zone(icttdayl,"America/Los_Angeles"); + icttla = icaltime_convert_to_zone(icttdayl, + icaltimezone_get_builtin_timezone("America/Los_Angeles")); + + if (VERBOSE) { printf("Orig +200d : %s\n", ical_timet_string(tt_p200) ); printf("LA+200D : %s\n", ictt_as_string(icttla)); + } + + ok("Converted time +200d in zone America/Los_Angeles is 2001-05-22 11:30:30", + (strncmp(ictt_as_string(icttla),"2001-05-22 11:30:30",19)==0)); - assert(strcmp(ictt_as_string(icttla),"2001-05-22 11:30:30")==0); icalerror_errors_are_fatal = 1; } @@ -1715,34 +1696,40 @@ void test_iterators() { icalcomponent *c,*inner,*next; icalcompiter i; + char vevent_list[64] = ""; + char remaining_list[64] = ""; + char *vevent_list_good = "12347"; + char *remaining_list_good = "568910"; + + int nomore = 1; + c= icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("1"),0), + icalproperty_new_version("1"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("2"),0), + icalproperty_new_version("2"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("3"),0), + icalproperty_new_version("3"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("4"),0), + icalproperty_new_version("4"),0), icalcomponent_vanew(ICAL_VTODO_COMPONENT, - icalproperty_vanew_version("5"),0), + icalproperty_new_version("5"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("6"),0), + icalproperty_new_version("6"),0), icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("7"),0), + icalproperty_new_version("7"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("8"),0), + icalproperty_new_version("8"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("9"),0), + icalproperty_new_version("9"),0), icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("10"),0), + icalproperty_new_version("10"),0), 0); - printf("1: "); - /* List all of the VEVENTS */ + for(i = icalcomponent_begin_component(c,ICAL_VEVENT_COMPONENT); icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ @@ -1753,24 +1740,10 @@ void test_iterators() ICAL_VERSION_PROPERTY); const char* s = icalproperty_get_version(p); - printf("%s ",s); - - } - - printf("\n2: "); - -#if 0 - for(inner = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - inner != 0; - inner = next){ - - next = icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); - - icalcomponent_remove_component(c,inner); - - icalcomponent_free(inner); + strcat(vevent_list, s); } -#endif + is("iterate through VEVENTS in a component", + vevent_list, vevent_list_good); /* Delete all of the VEVENTS */ /* reset iterator */ @@ -1779,12 +1752,11 @@ void test_iterators() while((inner=icalcomponent_get_current_component(c)) != 0 ){ if(icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT){ icalcomponent_remove_component(c,inner); + icalcomponent_free(inner); } else { icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); } } - - /* List all remaining components */ for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); @@ -1797,10 +1769,11 @@ void test_iterators() const char* s = icalproperty_get_version(p); - printf("%s ",s); + strcat(remaining_list, s); } - printf("\n3: "); + is("iterate through remaining components", + remaining_list, remaining_list_good); /* Remove all remaining components */ @@ -1815,7 +1788,6 @@ void test_iterators() p=icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); s = icalproperty_get_version(p); - printf("rem:%s ",s); icalcomponent_remove_component(c,inner); @@ -1824,14 +1796,11 @@ void test_iterators() if(this != 0){ p=icalcomponent_get_first_property(this,ICAL_VERSION_PROPERTY); s = icalproperty_get_version(p); - printf("next:%s; ",s); } icalcomponent_free(inner); } - printf("\n4: "); - /* List all remaining components */ for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); @@ -1843,95 +1812,33 @@ void test_iterators() const char* s = icalproperty_get_version(p); - printf("%s ",s); - } - - printf("\n"); -} - - - -char* test_set_tz(const char* tzid) -{ - char *tzstr = 0; - char *tmp; - - /* Put the new time zone into the environment */ - if(getenv("TZ") != 0){ - tzstr = (char*)icalmemory_strdup(getenv("TZ")); - - if(tzstr == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; - } - } - - tmp = (char*)malloc(1024); - - if(tmp == 0){ - icalerror_set_errno(ICAL_NEWFAILED_ERROR); - return 0; + if (s) + nomore = 0; } - snprintf(tmp,1024,"TZ=%s",tzid); - - /* HACK. In some libc versions, putenv gives the string to the - system and in some it gives a copy, so the following might be a - memory leak. THe linux man page says that glibc2.1.2 take - ownership ( no leak) while BSD4.4 uses a copy ( A leak ) */ - putenv(tmp); - - return tzstr; /* This will be zero if the TZ env var was not set */ -} - -void test_unset_tz(char* tzstr) -{ - /* restore the original environment */ - - if(tzstr!=0){ - char temp[1024]; - snprintf(temp,1024,"TZ=%s",tzstr); - putenv(temp); - free(tzstr); - } else { - putenv("TZ"); /* Delete from environment */ - } + ok("test if any components remain after deleting the rest", + nomore == 1); + + icalcomponent_free(c); } void test_time() { - char zones[6][40] = { "America/Los_Angeles","America/New_York","Europe/London","Asia/Shanghai", ""}; + char *zones[6] = { "America/Los_Angeles","America/New_York","Europe/London","Asia/Shanghai", NULL}; + int i; - char* old_tz; - int orig_month; - time_t tt; - struct tm stm; - - tt = time(0); - - stm = *(localtime(&tt)); - - orig_month = stm.tm_mon; do_test_time(0); - old_tz = test_set_tz(zones[0]); + for(i = 0; zones[i] != NULL; i++){ - for(i = 0; zones[i][0] != 0; i++){ - - if(zones[i][0] != 0){ - test_set_tz(zones[i]); - } - - printf(" ######### Timezone: %s ############\n",zones[i]); - + if (VERBOSE) printf(" ######### Timezone: %s ############\n",zones[i]); + do_test_time(zones[i]); } - test_unset_tz(old_tz); - } @@ -1958,168 +1865,16 @@ void test_icalset() printf(" class %d\n",icalclassify(c,0,"user")); } -} - -void test_classify() -{ - icalcomponent *c,*match; - icalset* f = icalset_new_file("../../test-data/classify.ics"); - - assert(f!=0); - - c = icalset_get_first_component(f); - match = icalset_get_next_component(f); - - printf("Class %d\n",icalclassify(c,match,"A@example.com")); - - + icalset_free(f); + icalset_free(d); } -void print_span(int c, struct icaltime_span span ){ - - printf("#%02d start: %s\n",c,ical_timet_string(span.start)); - printf(" end : %s\n",ical_timet_string(span.end)); - -} - -struct icaltimetype icaltime_as_local(struct icaltimetype tt) { - return icaltime_as_zone(tt,0); -} - -void test_span() -{ - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, - Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 - Sat Nov 4 16:00:00 PST 2000 */ - struct icaldurationtype dur; - struct icaltime_span span; - icalcomponent *c; - - memset(&dur,0,sizeof(dur)); - dur.minutes = 30; - - span.start = tm1; - span.end = tm2; - print_span(0,span); - - /* Specify save timezone as in commend above */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Pacific"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Pacific"),0), - 0 - ); - - printf("%s\n",icalcomponent_as_ical_string(c)); - - span = icalcomponent_get_span(c); - - print_span(1,span); - - icalcomponent_free(c); - - /* Use machine's local timezone. Same as above if run in US/Pacific */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0),0), - icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0), - 0 - ); - - span = icalcomponent_get_span(c); - - print_span(2,span); - - icalcomponent_free(c); - - /* Specify different timezone */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Eastern"),0), - 0 - ); - span = icalcomponent_get_span(c); - print_span(3,span); - - icalcomponent_free(c); - - - /* Specify different timezone for start and end*/ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend( - icaltime_as_local(icaltime_from_timet(tm2,0)), - icalparameter_new_tzid("US/Pacific"),0), - 0 - ); - span = icalcomponent_get_span(c); - print_span(4,span); - - icalcomponent_free(c); - - /* Use Duration */ - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart( - icaltime_as_local(icaltime_from_timet(tm1,0)), - icalparameter_new_tzid("US/Pacific"),0), - icalproperty_new_duration(dur), - - 0 - ); - span = icalcomponent_get_span(c); - print_span(5,span); - - icalcomponent_free(c); - - -#ifndef ICAL_ERRORS_ARE_FATAL - /* Both UTC and Timezone -- an error */ - icalerror_clear_errno(); - c = - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0), - icalparameter_new_tzid("US/Eastern"),0), - icalproperty_vanew_dtend(icaltime_from_timet(tm2,0), - icalparameter_new_tzid("US/Eastern"),0), - 0 - ); - - span = icalcomponent_get_span(c); - assert(icalerrno != ICAL_NO_ERROR); - - icalcomponent_free(c); - -#endif /*ICAL_ERRORS_ARE_FATAL*/ - -} icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp); void test_overlaps() { - -#if 0 /* Hack, not working right now */ icalcomponent *cset,*c; icalset *set; time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, @@ -2131,7 +1886,6 @@ void test_overlaps() set = icalset_new_file("../../test-data/overlaps.ics"); - printf("-- 1 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0), @@ -2140,10 +1894,14 @@ void test_overlaps() ); cset = icalclassify_find_overlaps(set,c); + ok("TODO find overlaps 1", (cset != NULL)); + + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); + + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); - printf("%s\n",icalcomponent_as_ical_string(cset)); - printf("-- 2 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0), @@ -2153,9 +1911,12 @@ void test_overlaps() cset = icalclassify_find_overlaps(set,c); - printf("%s\n",icalcomponent_as_ical_string(cset)); + ok("TODO find overlaps 1", cset != NULL); + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); + + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); - printf("-- 3 -- \n"); c = icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_vanew_dtstart(icaltime_from_timet(tm1+5*hh,0),0), @@ -2164,63 +1925,144 @@ void test_overlaps() ); cset = icalclassify_find_overlaps(set,c); + ok("TODO find overlaps 1", cset != NULL); + if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset)); - printf("%s\n",icalcomponent_as_ical_string(cset)); + if (set) icalset_free(set); + if (cset) icalcomponent_free(cset); + if (c) icalcomponent_free(c); +} -#endif -} void test_fblist() { - icalspanlist *sl; + icalspanlist *sl, *new_sl; icalset* set = icalset_new_file("../../test-data/spanlist.ics"); struct icalperiodtype period; + icalcomponent *comp; + int * foo; + int i; sl = icalspanlist_new(set, - icaltime_from_string("19970324T120000Z"), - icaltime_from_string("19990424T020000Z")); + icaltime_from_string("19980101T000000Z"), + icaltime_from_string("19980108T000000Z")); - printf("Restricted spanlist\n"); - icalspanlist_dump(sl); + ok("open ../../test-data/spanlist.ics", (set!=NULL)); + assert(set!=NULL); + + if (VERBOSE) printf("Restricted spanlist\n"); + if (VERBOSE) icalspanlist_dump(sl); period= icalspanlist_next_free_time(sl, - icaltime_from_string("19970801T120000Z")); + icaltime_from_string("19970801T120000")); + + is("Next Free time start 19970801T120000", icaltime_as_ical_string(period.start), "19970801T120000"); + is("Next Free time end 19980101T000000", icaltime_as_ical_string(period.end), "19980101T000000"); + + period= icalspanlist_next_free_time(sl, period.end); + + is("Next Free time start 19980101T010000", icaltime_as_ical_string(period.start), "19980101T010000"); + is("Next Free time end 19980102T010000", icaltime_as_ical_string(period.end), "19980102T010000"); + + if (VERBOSE) printf("%s\n", + icalcomponent_as_ical_string(icalspanlist_as_vfreebusy(sl, + "a@foo.com", + "b@foo.com") + )); + + foo = icalspanlist_as_freebusy_matrix(sl,3600); + + for (i=0; foo[i] != -1; i++); /* find number entries */ + + int_is("Calculating freebusy hourly matrix", i, (7*24)); + + if (VERBOSE) { + for (i=0; foo[i] != -1; i++) { + printf("%d", foo[i]); + if ((i % 24) == 23) + printf("\n"); + } + printf("\n\n"); + } + + + free(foo); + foo = icalspanlist_as_freebusy_matrix(sl,3600*24); - printf("Next Free time: %s\n",icaltime_as_ctime(period.start)); - printf(" %s\n",icaltime_as_ctime(period.end)); + ok("Calculating daily freebusy matrix", (foo!=NULL)); + { + char out_str[80] = ""; + char *strp = out_str; + + for (i=0; foo[i]!=-1; i++){ + sprintf(strp, "%d", foo[i]); + strp++; + } + is("Checking freebusy validity", out_str, "1121110"); + } + if (VERBOSE) { + for (i=0; foo[i] != -1; i++) { + printf("%d", foo[i]); + if ((i % 7) == 6) + printf("\n"); + } + printf("\n\n"); + } + free(foo); icalspanlist_free(sl); - printf("Unrestricted spanlist\n"); + + if (VERBOSE) printf("Unrestricted spanlist\n"); sl = icalspanlist_new(set, - icaltime_from_string("19970324T120000Z"), + icaltime_from_string("19970324T120000Z"), icaltime_null_time()); - - printf("Restricted spanlist\n"); - icalspanlist_dump(sl); + ok("add 19970324T120000Z to spanlist", (sl!=NULL)); + + if (VERBOSE) printf("Restricted spanlist\n"); + if (VERBOSE) icalspanlist_dump(sl); period= icalspanlist_next_free_time(sl, icaltime_from_string("19970801T120000Z")); - printf("Next Free time: %s\n",icaltime_as_ctime(period.start)); - printf(" %s\n",icaltime_as_ctime(period.end)); + is("Next Free time start 19980101T010000", + icaltime_as_ical_string(period.start), + "19980101T010000"); + is("Next Free time end 19980102T010000", + icaltime_as_ical_string(period.end), + "19980102T010000"); - icalspanlist_free(sl); + comp = icalspanlist_as_vfreebusy(sl, "a@foo.com", "b@foo.com"); + + ok("Calculating VFREEBUSY component", (comp != NULL)); + if (VERBOSE) printf("%s\n", icalcomponent_as_ical_string(comp)); + new_sl = icalspanlist_from_vfreebusy(comp); + ok("Calculating spanlist from generated VFREEBUSY component", + (new_sl != NULL)); + + if (VERBOSE) icalspanlist_dump(new_sl); + + if (sl) icalspanlist_free(sl); + if (new_sl) icalspanlist_free(new_sl); + if (comp) icalcomponent_free(comp); + + icalset_free(set); } + void test_convenience(){ - icalcomponent *c; int duration; + struct icaltimetype tt; c = icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, @@ -2232,14 +2074,15 @@ void test_convenience(){ ), 0); - printf("** 1 DTSTART and DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 (floating)"); + is("End is 1997-08-01 13:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:00:00 (floating)"); + ok("Duration is 60 m", (duration == 60)); icalcomponent_free(c); @@ -2253,17 +2096,20 @@ void test_convenience(){ ), 0); - printf("\n** 2 DTSTART and DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 Z UTC", + ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 Z UTC"); + is("End is 1997-08-01 13:30:00 Z UTC", + ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:30:00 Z UTC"); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); + icalerror_errors_are_fatal = 0; + c = icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, icalcomponent_vanew( @@ -2276,14 +2122,17 @@ void test_convenience(){ icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); - printf("** 3 DTSTART and DTEND, Set DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + is("Start is 1997-08-01 12:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtstart(c)), + "1997-08-01 12:00:00 (floating)"); + is("End is 1997-08-01 13:00:00 (floating)", + ictt_as_string(icalcomponent_get_dtend(c)), + "1997-08-01 13:00:00 (floating)"); + ok("Duration is 60 m", (duration == 60)); icalcomponent_free(c); @@ -2299,14 +2148,18 @@ void test_convenience(){ icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z")); - printf("\n** 4 DTSTART and DURATION, set DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); + duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); + + icalerror_errors_are_fatal = 1; icalcomponent_free(c); @@ -2321,15 +2174,16 @@ void test_convenience(){ icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z")); icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z")); - printf("\n** 5 Set DTSTART and DTEND **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); @@ -2345,18 +2199,44 @@ void test_convenience(){ icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z")); icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); - printf("\n** 6 Set DTSTART and DURATION **\n%s\n\n", - icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; - printf("Start: %s\n",ictt_as_string(icalcomponent_get_dtstart(c))); - printf("End: %s\n",ictt_as_string(icalcomponent_get_dtend(c))); - printf("Dur: %d m\n",duration); + ok("Start is 1997-08-01 12:00:00 Z UTC", + (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 Z UTC", + (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); icalcomponent_free(c); + c = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + 0 + ), + 0); + + tt = icaltime_from_string("19970801T120000"); + icaltime_set_timezone(&tt, + icaltimezone_get_builtin_timezone("Europe/Rome")); + icalcomponent_set_dtstart(c,tt); + + if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c)); + + icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M")); + duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60; + + ok("Start is 1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", + (0 == strcmp("1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtstart(c))))); + ok("End is 1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", + (0 == strcmp("1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtend(c))))); + ok("Duration is 90 m", (duration == 90)); + + icalcomponent_free(c); } void test_time_parser() @@ -2366,77 +2246,176 @@ void test_time_parser() icalerror_errors_are_fatal = 0; tt = icaltime_from_string("19970101T1000"); - assert(icaltime_is_null_time(tt)); + ok("19970101T1000 is null time", icaltime_is_null_time(tt)); tt = icaltime_from_string("19970101X100000"); - assert(icaltime_is_null_time(tt)); + ok("19970101X100000 is null time", icaltime_is_null_time(tt)); tt = icaltime_from_string("19970101T100000"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + ok("19970101T100000 is valid", !icaltime_is_null_time(tt)); + + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); tt = icaltime_from_string("19970101T100000Z"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + + ok("19970101T100000Z is valid" , !icaltime_is_null_time(tt)); + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); tt = icaltime_from_string("19970101"); - assert(!icaltime_is_null_time(tt)); - printf("%s\n",icaltime_as_ctime(tt)); + ok("19970101 is valid", (!icaltime_is_null_time(tt))); - icalerror_errors_are_fatal = 1; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt)); + icalerror_errors_are_fatal = 1; } void test_recur_parser() { - struct icalrecurrencetype rt; + struct icalrecurrencetype rt; + char *str; + + str = "FREQ=YEARLY;UNTIL=20000131T090000Z;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8"; + rt = icalrecurrencetype_from_string(str); + is(str, icalrecurrencetype_as_string(&rt), str); + + str = "FREQ=DAILY;COUNT=3;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8"; + + rt = icalrecurrencetype_from_string(str); + is(str, icalrecurrencetype_as_string(&rt), str); +} + +char* ical_strstr(const char *haystack, const char *needle){ + return strstr(haystack,needle); +} + +void test_start_of_week() +{ + struct icaltimetype tt2; + struct icaltimetype tt1 = icaltime_from_string("19900110"); + int dow, doy,start_dow; - printf("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA\n"); + do{ + tt1 = icaltime_normalize(tt1); - rt = icalrecurrencetype_from_string("FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA"); + doy = icaltime_start_doy_of_week(tt1); + dow = icaltime_day_of_week(tt1); - printf("%s\n\n",icalrecurrencetype_as_string(&rt)); + tt2 = icaltime_from_day_of_year(doy,tt1.year); + start_dow = icaltime_day_of_week(tt2); - printf("FREQ=DAILY;COUNT=3;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,S\n"); + if(doy == 1){ + char msg[128]; + sprintf(msg, "%s", ictt_as_string(tt1)); + int_is(msg, start_dow, 1); + } - rt = icalrecurrencetype_from_string("FREQ=DAILY;COUNT=3;BYMONTH=1,2,3,4,8;BYYEARDAY=34,65,76,78;BYDAY=-1TU,3WE,-4FR,SU,SA"); + if(start_dow != 1){ /* Sunday is 1 */ + printf("failed: Start of week (%s) is not a Sunday \n for %s (doy=%d,dow=%d)\n",ictt_as_string(tt2), ictt_as_string(tt1),dow,start_dow); + } - printf("%s\n",icalrecurrencetype_as_string(&rt)); -} + assert(start_dow == 1); -char* ical_strstr(const char *haystack, const char *needle){ - return strstr(haystack,needle); + + tt1.day+=1; + + } while(tt1.year < 2010); } void test_doy() { struct icaltimetype tt1, tt2; - short doy; + short doy,doy2; + char msg[128]; + + doy = -1; + + tt1 = icaltime_from_string("19900101"); + + if (VERBOSE) printf("Test icaltime_day_of_year() agreement with mktime\n"); + + do{ + struct tm stm; + + tt1 = icaltime_normalize(tt1); + + stm.tm_sec = tt1.second; + stm.tm_min = tt1.minute; + stm.tm_hour = tt1.hour; + stm.tm_mday = tt1.day; + stm.tm_mon = tt1.month-1; + stm.tm_year = tt1.year-1900; + stm.tm_isdst = -1; + + mktime(&stm); + + doy = icaltime_day_of_year(tt1); + + doy2 = stm.tm_yday+1; + + if (doy == 1) { + /** show some test cases **/ + sprintf(msg, "Year %d - mktime() compare", tt1.year); + int_is(msg, doy,doy2); + } + + if (doy != doy2){ + printf("Failed for %s (%d,%d)\n",ictt_as_string(tt1),doy,doy2); + } + assert(doy == doy2); + + tt1.day+=1; + + } while(tt1.year < 2010); + + if (VERBOSE) printf("\nTest icaltime_day_of_year() agreement with icaltime_from_day_of_year()\n"); + + tt1 = icaltime_from_string("19900101"); + + do{ + if(doy == 1){ + /** show some test cases **/ + sprintf(msg, "Year %d - icaltime_day_of_year() compare", tt1.year); + int_is(msg, doy,doy2); + } + + doy = icaltime_day_of_year(tt1); + tt2 = icaltime_from_day_of_year(doy,tt1.year); + doy2 = icaltime_day_of_year(tt2); + + assert(doy2 == doy); + assert(icaltime_compare(tt1,tt2) == 0); + + tt1.day+=1; + tt1 = icaltime_normalize(tt1); + + } while(tt1.year < 2010); + tt1 = icaltime_from_string("19950301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1995); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 60); + if(VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); + + ok("test 19950301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 60", (doy == 60)); tt1 = icaltime_from_string("19960301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1996); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 61); + if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); + ok("test 19960301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 61", (doy == 61)); tt1 = icaltime_from_string("19970301"); doy = icaltime_day_of_year(tt1); tt2 = icaltime_from_day_of_year(doy,1997); - printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); - assert(tt2.day == 1 && tt2.month == 3); - assert(doy == 60); + if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2)); -} + ok("test 19970301", (tt2.day == 1 && tt2.month == 3)); + ok("day of year == 60", (doy == 60)); +} void test_x(){ @@ -2462,15 +2441,15 @@ void test_x(){ int n_errors; icalcomp = icalparser_parse_string ((char *) test_icalcomp_str); - if (!icalcomp) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + assert(icalcomp!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); + if (VERBOSE) printf("%s\n\n",icalcomponent_as_ical_string(icalcomp)); n_errors = icalcomponent_count_errors (icalcomp); + int_is("icalparser_parse_string()", n_errors,0); + if (n_errors) { + /** NOT USED **/ icalproperty *p; for (p = icalcomponent_get_first_property (icalcomp, @@ -2478,7 +2457,7 @@ void test_x(){ p; p = icalcomponent_get_next_property (icalcomp, ICAL_XLICERROR_PROPERTY)) { - char *str; + const char *str; str = icalproperty_as_ical_string (p); fprintf (stderr, "error: %s\n", str); @@ -2486,44 +2465,67 @@ void test_x(){ } prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY); - if (!prop) { - fprintf (stderr, "main(): could not get the RRULE property"); - exit (EXIT_FAILURE); - } + ok("get RRULE property", (prop != NULL)); + assert(prop!=NULL); recur = icalproperty_get_rrule (prop); - printf("%s\n",icalrecurrencetype_as_string(&recur)); + if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur)); + + icalcomponent_free(icalcomp); } void test_gauge_sql() { - - icalgauge *g; + char* str; - printf("\nSELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5\n"); + str= "SELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5"; - g = icalgauge_new_from_sql("SELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5"); - - icalgauge_dump(g); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); icalgauge_free(g); - printf("\nSELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'\n"); + str="SELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'"; - g = icalgauge_new_from_sql("SELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'"); - - icalgauge_dump(g); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); + + str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); + + str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); icalgauge_free(g); + str="SELECT * FROM VEVENT WHERE LOCATION == '104 Forum'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=NULL)); + if (VERBOSE) icalgauge_dump(g); + + icalgauge_free(g); } -void test_gauge_compare() { +void test_gauge_compare() { icalgauge *g; icalcomponent *c; + char* str; /* Equality */ @@ -2533,35 +2535,35 @@ void test_gauge_compare() { icaltime_from_string("20000101T000002")),0),0); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", (c!=0 && g!=0)); assert(c!=0); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'\n", (c!=0 && g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); @@ -2569,47 +2571,48 @@ void test_gauge_compare() { /* Less than */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", (c!=0 && g!=0)); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); assert(g!=0); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); /* Greater than */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); + icalgauge_free(g); @@ -2617,53 +2620,117 @@ void test_gauge_compare() { /* Greater than or Equal to */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'"); + "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); /* Less than or Equal to */ g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'"); + "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'\n", (g!=0)); assert(g!=0); - assert(icalgauge_compare(g,c) == 1); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'"); + "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'", 0); - printf("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'\n"); + ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'\n", (g!=0)); - assert(g!=0); - assert(icalgauge_compare(g,c) == 0); + int_is("compare",icalgauge_compare(g,c), 0); icalgauge_free(g); icalcomponent_free(c); + /* Combinations */ + + c = icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart( + icaltime_from_string("20000102T000000")),0),0); + + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + + icalcomponent_free(c); + + /* Combinations, non-cannonical component */ + + c = icalcomponent_vanew(ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstart( + icaltime_from_string("20000102T000000")),0); + + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); + + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'"; + + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); + + icalgauge_free(g); + icalcomponent_free(c); + /* Complex comparisions */ @@ -2684,37 +2751,45 @@ void test_gauge_compare() { 0), 0); + + str = "SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'"; - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'"); - - printf("SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'\n"); - - assert(icalgauge_compare(g,c) == 1); + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE COMMENT = 'foo'"); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); - printf("SELECT * FROM VEVENT WHERE COMMENT = 'foo'\n"); - - assert(icalgauge_compare(g,c) == 1); + icalgauge_free(g); + + str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' AND VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 0); - g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'"); - - printf("SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND VALARM.DTSTART = '20000101T120000'\n"); + icalgauge_free(g); - assert(icalgauge_compare(g,c) == 1); + str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' or VALARM.DTSTART = '20000101T120000'"; + g = icalgauge_new_from_sql(str, 0); + ok(str, (g!=0)); + int_is("compare",icalgauge_compare(g,c), 1); icalgauge_free(g); icalcomponent_free(c); - + } icalcomponent* make_component(int i){ @@ -2743,18 +2818,21 @@ icalcomponent* make_component(int i){ } void test_fileset() { - icalfileset *fs; + icalset *fs; icalcomponent *c; int i; + int comp_count = 0; char *path = "test_fileset.ics"; icalgauge *g = icalgauge_new_from_sql( - "SELECT * FROM VEVENT WHERE DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z'"); + "SELECT * FROM VEVENT WHERE DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z'", 0); + ok("icalgauge_new_from_sql()", (g!=NULL)); unlink(path); fs = icalfileset_new(path); + ok("icalfileset_new()", (fs!=NULL)); assert(fs != 0); for (i = 0; i!= 10; i++){ @@ -2764,60 +2842,68 @@ void test_fileset() icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); + /** reopen fileset.ics **/ fs = icalfileset_new(path); + if (VERBOSE) printf("== No Selections \n"); - printf("== No Selections \n"); - + comp_count = 0; for (c = icalfileset_get_first_component(fs); c != 0; c = icalfileset_get_next_component(fs)){ struct icaltimetype t = icalcomponent_get_dtstart(c); - - printf("%s\n",icaltime_as_ctime(t)); + comp_count++; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(t)); } + int_is("icalfileset get components",comp_count, 10); icalfileset_select(fs,g); - printf("\n== DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z' \n"); + if (VERBOSE) printf("\n== DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z' \n"); + comp_count = 0; for (c = icalfileset_get_first_component(fs); c != 0; c = icalfileset_get_next_component(fs)){ struct icaltimetype t = icalcomponent_get_dtstart(c); - - printf("%s\n",icaltime_as_ctime(t)); + comp_count++; + if (VERBOSE) printf("%s\n",icaltime_as_ctime(t)); } + int_is("icalfileset get components with gauge",comp_count, 3); - icalfileset_free(fs); + icalset_free(fs); + + /*icalgauge_free(g);*/ } void microsleep(int us) { +#ifndef WIN32 struct timeval tv; tv.tv_sec = 0; tv.tv_usec = us; select(0,0,0,0,&tv); - +#else + Sleep(us); +#endif } void test_file_locks() { +#ifndef WIN32 pid_t pid; char *path = "test_fileset_locktest.ics"; - icalfileset *fs; + icalset *fs; icalcomponent *c, *c2; struct icaldurationtype d; int i; int final,sec; - icalfileset_safe_saves = 1; - icalerror_clear_errno(); unlink(path); @@ -2840,7 +2926,7 @@ void test_file_locks() icalfileset_commit(fs); } - icalfileset_free(fs); + icalset_free(fs); assert(icalerrno == ICAL_NO_ERROR); @@ -2877,7 +2963,7 @@ void test_file_locks() icalfileset_mark(fs); icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); microsleep(rand()/(RAND_MAX/20)); @@ -2911,7 +2997,7 @@ void test_file_locks() icalfileset_mark(fs); icalfileset_commit(fs); - icalfileset_free(fs); + icalset_free(fs); putc('.',stdout); fflush(stdout); @@ -2943,48 +3029,50 @@ void test_file_locks() assert(sec == final); +#endif } void test_action() { icalcomponent *c; icalproperty *p; - + char *str; + static const char test_icalcomp_str[] = "BEGIN:VEVENT\n" "ACTION:EMAIL\n" "ACTION:PROCEDURE\n" "ACTION:AUDIO\n" "ACTION:FUBAR\n" -"END:VEVENT\r\n"; +"END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); - if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + + ok("icalparser_parse_string(), ACTIONS", (c!=NULL)); + assert(c!=0); - printf("%s\n\n",icalcomponent_as_ical_string(c)); + str = icalcomponent_as_ical_string(c); + is("icalcomponent_as_ical_string()", str, ((char*) test_icalcomp_str)); + if (VERBOSE) printf("%s\n\n",str); p = icalcomponent_get_first_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_EMAIL); + ok("ICAL_ACTION_EMAIL", (icalproperty_get_action(p) == ICAL_ACTION_EMAIL)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_PROCEDURE); + ok("ICAL_ACTION_PROCEDURE", (icalproperty_get_action(p) == ICAL_ACTION_PROCEDURE)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_AUDIO); + ok("ICAL_ACTION_AUDIO", (icalproperty_get_action(p) == ICAL_ACTION_AUDIO)); p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY); - assert(icalproperty_get_action(p) == ICAL_ACTION_X); - assert(regrstrcmp(icalvalue_get_x(icalproperty_get_value(p)), "FUBAR")==0); - - + ok("ICAL_ACTION_X", (icalproperty_get_action(p) == ICAL_ACTION_X)); + is("ICAL_ACTION -> FUBAR", icalvalue_get_x(icalproperty_get_value(p)), "FUBAR"); + icalcomponent_free(c); } @@ -2995,24 +3083,22 @@ void test_trigger() struct icaltriggertype tr; icalcomponent *c; icalproperty *p; - char* str; + const char* str; static const char test_icalcomp_str[] = "BEGIN:VEVENT\n" "TRIGGER;VALUE=DATE-TIME:19980403T120000\n" -"TRIGGER:-PT15M\n" -"TRIGGER:19980403T120000\n" "TRIGGER;VALUE=DURATION:-PT15M\n" -"END:VEVENT\r\n"; +"TRIGGER;VALUE=DATE-TIME:19980403T120000\n" +"TRIGGER;VALUE=DURATION:-PT15M\n" +"END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); - if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); - exit (EXIT_FAILURE); - } + ok("icalparser_parse_string()", (c!= NULL)); + assert(c!=NULL); - printf("%s\n\n",icalcomponent_as_ical_string(c)); + is("parsed triggers", icalcomponent_as_ical_string(c), (char*)test_icalcomp_str); for(p = icalcomponent_get_first_property(c,ICAL_TRIGGER_PROPERTY); p != 0; @@ -3020,20 +3106,21 @@ void test_trigger() tr = icalproperty_get_trigger(p); if(!icaltime_is_null_time(tr.time)){ - printf("value=DATE-TIME:%s\n", icaltime_as_ical_string(tr.time)); + if (VERBOSE) printf("value=DATE-TIME:%s\n", icaltime_as_ical_string(tr.time)); } else { - printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration)); + if (VERBOSE) printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration)); } } + icalcomponent_free(c); + /* Trigger, as a DATETIME */ tr.duration = icaldurationtype_null_duration(); tr.time = icaltime_from_string("19970101T120000"); p = icalproperty_new_trigger(tr); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /* TRIGGER, as a DURATION */ @@ -3042,8 +3129,7 @@ void test_trigger() p = icalproperty_new_trigger(tr); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); /* TRIGGER, as a DATETIME, VALUE=DATETIME*/ @@ -3053,8 +3139,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=DATETIME */ @@ -3065,8 +3150,7 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); /* TRIGGER, as a DATETIME, VALUE=DURATION*/ @@ -3076,8 +3160,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=DURATION */ @@ -3088,8 +3171,7 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); @@ -3100,8 +3182,7 @@ void test_trigger() icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n"); icalproperty_free(p); /*TRIGGER, as a DURATION, VALUE=BINARY */ @@ -3112,20 +3193,17 @@ void test_trigger() str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("TRIGGER\n ;VALUE=DURATION\n :P3DT3H50M45S\n",str) == 0); + is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n"); icalproperty_free(p); - - - } + void test_rdate() { struct icaldatetimeperiodtype dtp; icalproperty *p; - char* str; + const char* str; struct icalperiodtype period; period.start = icaltime_from_string("19970101T120000"); @@ -3137,10 +3215,10 @@ void test_rdate() dtp.period = icalperiodtype_null_period(); p = icalproperty_new_rdate(dtp); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); - icalproperty_free(p); + is("RDATE as DATE-TIME", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); + icalproperty_free(p); /* RDATE, as PERIOD */ dtp.time = icaltime_null_time(); @@ -3148,8 +3226,7 @@ void test_rdate() p = icalproperty_new_rdate(dtp); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + is("RDATE, as PERIOD", "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); /* RDATE, as DATE-TIME, VALUE=DATE-TIME */ @@ -3158,8 +3235,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=DATE-TIME", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3169,8 +3247,8 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + is("RDATE, as PERIOD, VALUE=DATE-TIME", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); @@ -3180,8 +3258,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=PERIOD", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3191,8 +3270,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); + + is("RDATE, as PERIOD, VALUE=PERIOD", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); icalproperty_free(p); @@ -3202,8 +3282,9 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=DATE-TIME\n :19970101T120000\n",str) == 0); + + is("RDATE, as DATE-TIME, VALUE=BINARY", + "RDATE;VALUE=DATE-TIME:19970101T120000\n",str); icalproperty_free(p); @@ -3213,11 +3294,10 @@ void test_rdate() p = icalproperty_new_rdate(dtp); icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); str = icalproperty_as_ical_string(p); - printf("%s\n",str); - assert(regrstrcmp("RDATE\n ;VALUE=PERIOD\n :19970101T120000/PT3H10M15S\n",str) == 0); - icalproperty_free(p); - + is("RDAE, as PERIOD, VALUE=BINARY", + "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str); + icalproperty_free(p); } @@ -3225,11 +3305,12 @@ void test_langbind() { icalcomponent *c, *inner; icalproperty *p; - + char *test_str_parsed; static const char test_str[] = "BEGIN:VEVENT\n" "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n" "COMMENT: Comment that \n spans a line\n" +"COMMENT: Comment with \"quotable\" \'characters\' and other \t bad magic \n things \f Yeah.\n" "DTSTART:19970101T120000\n" "DTSTART:19970101T120000Z\n" "DTSTART:19970101\n" @@ -3237,13 +3318,37 @@ void test_langbind() "FREEBUSY:19970101T120000/19970101T120000\n" "FREEBUSY:19970101T120000/P3DT4H25M\n" "END:VEVENT\n"; - - printf("%s\n",test_str); + static const char *test_str_parsed_good = +"BEGIN:VEVENT\n" +"ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:\n" +" employee-A@host.com\n" +"COMMENT: Comment that spans a line\n" +"COMMENT: Comment with \\\"quotable\\\" 'characters' and other \\t bad magic \n" +" things \\f Yeah.\n" +"DTSTART:19970101T120000\n" +"DTSTART:19970101T120000Z\n" +"DTSTART;VALUE=DATE:19970101\n" +"DURATION:P3DT4H25M\n" +"FREEBUSY:19970101T120000/19970101T120000\n" +"FREEBUSY:19970101T120000/P3DT4H25M\n" +"END:VEVENT\n"; + + if (VERBOSE) printf("%s\n",test_str); c = icalparser_parse_string(test_str); - inner = icalcomponent_get_inner(c); + ok("icalparser_parse_string()", (c!=NULL)); + assert(c != NULL); + + test_str_parsed = icalcomponent_as_ical_string(c); + + is("parsed version with bad chars, etc", + test_str_parsed, + test_str_parsed_good); + + + inner = icalcomponent_get_inner(c); for( p = icallangbind_get_first_property(inner,"ANY"); @@ -3251,39 +3356,56 @@ void test_langbind() p = icallangbind_get_next_property(inner,"ANY") ) { - printf("%s\n",icallangbind_property_eval_string(p,":")); + const char *str = icallangbind_property_eval_string(p,":"); + /** TODO add tests **/ + if (VERBOSE) printf("%s\n",str); } - p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); icalproperty_set_parameter_from_string(p,"CUTYPE","INDIVIDUAL"); - printf("%s\n",icalproperty_as_ical_string(p)); - - + is ("Set attendee parameter", + icalproperty_as_ical_string(p), + "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:MAILTO:\n" + " employee-A@host.com\n"); + icalproperty_set_value_from_string(p,"mary@foo.org","TEXT"); - printf("%s\n",icalproperty_as_ical_string(p)); + is ("Set attendee parameter value", + icalproperty_as_ical_string(p), + "ATTENDEE;VALUE=TEXT;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:\n" +" mary@foo.org\n"); + icalcomponent_free(c); } void test_property_parse() { icalproperty *p; + const char *str; p= icalproperty_new_from_string( "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com"); + ok("icalproperty_from_string(), ATTENDEE", (p != 0)); assert (p != 0); - printf("%s\n",icalproperty_as_ical_string(p)); + str = icalproperty_as_ical_string(p); + if (VERBOSE) printf("%s\n",str); + + icalproperty_free(p); p= icalproperty_new_from_string("DTSTART:19970101T120000Z\n"); + ok("icalproperty_from_string(), simple DTSTART", (p != 0)); assert (p != 0); - printf("%s\n",icalproperty_as_ical_string(p)); + + str = icalproperty_as_ical_string(p); + if (VERBOSE) printf("%s\n",str); + + icalproperty_free(p); } @@ -3303,303 +3425,243 @@ void test_value_parameter() "END:VEVENT\n"; c = icalparser_parse_string ((char *) test_icalcomp_str); + ok("icalparser_parse_string()", (c != NULL)); if (!c) { - fprintf (stderr, "main(): could not parse the component\n"); exit (EXIT_FAILURE); } - printf("%s",icalcomponent_as_ical_string(c)); + if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c)); p = icalcomponent_get_first_property(c,ICAL_DTSTART_PROPERTY); param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER); - assert(icalparameter_get_value(param) == ICAL_VALUE_DATETIME); + + ok("icalproperty_get_value()", (icalparameter_get_value(param) == ICAL_VALUE_DATETIME)); p = icalcomponent_get_next_property(c,ICAL_DTSTART_PROPERTY); param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER); - assert(icalparameter_get_value(param) == ICAL_VALUE_DATE); + ok("icalproperty_get_first_parameter()",(icalparameter_get_value(param) == ICAL_VALUE_DATE)); + icalcomponent_free(c); } -void test_x_property() +void test_x_parameter() { icalproperty *p; - - p= icalproperty_new_from_string( - "X-LIC-PROPERTY: This is a note"); - - printf("%s\n",icalproperty_as_ical_string(p)); - - assert(icalproperty_isa(p) == ICAL_X_PROPERTY); - assert(regrstrcmp(icalproperty_get_x_name(p),"X-LIC-PROPERTY")==0); - assert(regrstrcmp(icalproperty_get_x(p)," This is a note")==0); - -} - -int main(int argc, char *argv[]) -{ - int c; - extern char *optarg; - extern int optopt; - int errflg=0; - char* program_name = strrchr(argv[0],'/'); - int ttime=0, trecur=0,tspan=0, tmisc=0, tgauge = 0, tfile = 0, - tbasic = 0; - - if(argc==1) { - ttime = trecur = tspan = tmisc = tgauge = tfile = tbasic = 1; - } - while ((c = getopt(argc, argv, "t:s:r:m:g:f:b:")) != -1) { - switch (c) { - - case 'b': { - tbasic = atoi(optarg); - break; - } + p= icalproperty_new_from_string( + "COMMENT;X-A=1;X-B=2: This is a note"); - case 't': { - ttime = atoi(optarg); - break; - } + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - case 's': { - tspan = atoi(optarg); - break; - } + ok("COMMENT property",(icalproperty_isa(p) == ICAL_COMMENT_PROPERTY)); + is("COMMENT parses param", icalproperty_get_comment(p)," This is a note"); - case 'r': { - trecur = atoi(optarg); - break; - } + icalproperty_set_parameter_from_string(p,"X-LIES", "no"); + icalproperty_set_parameter_from_string(p,"X-LAUGHS", "big"); + icalproperty_set_parameter_from_string(p,"X-TRUTH", "yes"); + icalproperty_set_parameter_from_string(p,"X-HUMOUR", "bad"); + if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p)); - case 'm': { - tmisc = atoi(optarg); - break; - } - + is("Check X-LIES", icalproperty_get_parameter_as_string(p, "X-LIES"), "no"); + is("Check X-LAUGHS", icalproperty_get_parameter_as_string(p, "X-LAUGHS"), "big"); + is("Check X-TRUTH", icalproperty_get_parameter_as_string(p, "X-TRUTH"), "yes"); + is("Check X-HUMOUR", icalproperty_get_parameter_as_string(p, "X-HUMOUR"), "bad"); - case 'g': { - tgauge = atoi(optarg); - break; - } - - case 'f': { - tfile = atoi(optarg); - break; - } - - case ':': {/* Option given without an operand */ - fprintf(stderr, - "%s: Option -%c requires an operand\n", - program_name,optopt); - errflg++; - break; - } - case '?': { - errflg++; - } - - } - - } - - - if(ttime==1 || ttime==2){ - printf("\n------------Test time parser ----------\n"); - test_time_parser(); - - } - - if(ttime==1 || ttime==3){ - printf("\n------------Test time----------------\n"); - test_time(); - } - - if(ttime==1 || ttime==4){ - printf("\n------------Test day of year---------\n"); - test_doy(); - } - - if(ttime==1 || ttime==5){ - printf("\n------------Test duration---------------\n"); - test_duration(); - } - - if(ttime==1 || ttime==6){ - printf("\n------------Test period ----------------\n"); - test_period(); - } - - - - if(trecur==1 || trecur==2){ - printf("\n------------Test recur parser ----------\n"); - test_recur_parser(); - } - - if(trecur==1 || trecur==3){ - printf("\n------------Test recur---------------\n"); - test_recur(); - } + icalproperty_free(p); +} - if(trecur==1 || trecur==4){ - printf("\n------------Test parameter bug---------\n"); - test_recur_parameter_bug(); - } - if(trecur==1 || trecur==5){ - printf("\n------------Test Array Expansion---------\n"); - test_expand_recurrence(); - } +void test_x_property() +{ + icalproperty *p; + p= icalproperty_new_from_string( + "X-LIC-PROPERTY: This is a note"); + if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p)); - if(tspan==1 || tspan==2){ - printf("\n------------Test FBlist------------\n"); - test_fblist(); - } - - if(tspan==1 || tspan==3){ - printf("\n------------Test Overlaps------------\n"); - test_overlaps(); - } - - if(tspan==1 || tspan==4){ - printf("\n------------Test Span----------------\n"); - test_span(); - } - - if(tgauge == 1 || tgauge == 2){ - printf("\n------------Test Gauge SQL----------------\n"); - test_gauge_sql(); - } - - if(tgauge == 1 || tgauge == 3){ - printf("\n------------Test Gauge Compare--------------\n"); - test_gauge_compare(); - } - - if(tfile ==1 || tfile == 2){ - printf("\n------------Test File Set--------------\n"); - test_fileset(); - } + ok("x-property is correct kind",(icalproperty_isa(p) == ICAL_X_PROPERTY)); + is("icalproperty_get_x_name() works", + icalproperty_get_x_name(p),"X-LIC-PROPERTY"); + is("icalproperty_get_x() works", + icalproperty_get_x(p)," This is a note"); - if(tfile ==1 || tfile == 3){ - printf("\n------------Test File Locks--------------\n"); - test_file_locks(); - } + icalproperty_free(p); +} +void test_utcoffset() +{ + icalproperty *p; + p = icalproperty_new_from_string("TZOFFSETFROM:-001608"); + ok("parse TZOOFSETFROM:-001608", (p!=NULL)); - if(tmisc == 1 || tmisc == 2){ - printf("\n------------Test X Props and Params--------\n"); - test_x(); - } + if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p)); - if(tmisc == 1 || tmisc == 3){ - printf("\n------------Test Trigger ------------------\n"); - test_trigger(); - } + if (p) icalproperty_free(p); +} - if(tmisc == 1 || tmisc == 4){ +void test_attach() +{ + icalcomponent *c; - printf("\n------------Test Restriction---------------\n"); - test_restriction(); - } + static const char test_icalcomp_str[] = +"BEGIN:VEVENT\n" +"ATTACH:CID:jsmith.part3.960817T083000.xyzMain@host1.com\n" +"ATTACH:FMTTYPE=application/postscript;ftp://xyzCorp.com/pub/reports/r-960812.ps\n" +"END:VEVENT\n"; - if(tmisc == 1 || tmisc == 5){ + c = icalparser_parse_string ((char *) test_icalcomp_str); + ok("parse simple attachment", (c != NULL)); - printf("\n------------Test RDATE---------------\n"); - test_rdate(); - } + if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c)); - if(tmisc == 1 || tmisc == 6){ + if (c) icalcomponent_free(c); +} - printf("\n------------Test language binding---------------\n"); - test_langbind(); - } +void test_vcal(void) +{ + VObject *vcal = 0; + icalcomponent *comp; + char* file = "../../test-data/user-cal.vcf"; - if(tmisc == 1 || tmisc == 7){ + vcal = Parse_MIME_FromFileName(file); + + ok("Parsing ../../test-data/user-cal.vcf", (vcal != 0)); - printf("\n------------Test property parser---------------\n"); - test_property_parse(); - } + comp = icalvcal_convert(vcal); - if(tmisc == 1 || tmisc == 8){ - printf("\n------------Test Action ------------------\n"); - test_action(); - } + ok("Converting to ical component", (comp != 0)); + + if (VERBOSE && comp) + printf("%s\n",icalcomponent_as_ical_string(comp)); - if(tmisc == 1 || tmisc == 9){ - printf("\n------------Test Value Parameter ------------------\n"); - test_value_parameter(); - } + if (comp) icalcomponent_free(comp); + if (vcal) deleteVObject(vcal); +} - if(tmisc == 1 || tmisc == 10){ - printf("\n------------Test X property ------------------\n"); - test_x_property(); +int main(int argc, char *argv[]) +{ + int c; + extern char *optarg; + extern int optopt; + int errflg=0; + char* program_name = strrchr(argv[0],'/'); + int do_test = 0; + int do_header = 0; + + set_zone_directory("../../zoneinfo"); + putenv("TZ="); + + test_start(0); + + +#ifndef WIN32 + while ((c = getopt(argc, argv, "lvq")) != -1) { + switch (c) { + case 'v': { + VERBOSE = 1; + break; + } + case 'q': { + QUIET = 1; + break; + } + case 'l': { + do_header = 1;; + } + case '?': { + errflg++; + } + } + } + if (optind < argc) { + do_test = atoi(argv[argc-1]); } +#else + if (argc>1) + do_test = atoi(argv[2]); - - if(tbasic == 1 || tbasic == 2){ - printf("\n------------Test Values---------------\n"); - test_values(); - } +#endif - if(tbasic == 1 || tbasic == 3){ - printf("\n------------Test Parameters-----------\n"); - test_parameters(); - } - - if(tbasic == 1 || tbasic == 4){ - printf("\n------------Test Properties-----------\n"); - test_properties(); - } + + test_run("Test time parser functions", test_time_parser, do_test, do_header); + test_run("Test time", test_time, do_test, do_header); + test_run("Test day of Year", test_doy, do_test, do_header); + test_run("Test duration", test_duration, do_test, do_header); + test_run("Test period", test_period, do_test, do_header); + test_run("Test DTSTART", test_dtstart, do_test, do_header); + test_run("Test day of year of week start", test_start_of_week, do_test, do_header); + test_run("Test recur parser", test_recur_parser, do_test, do_header); + test_run("Test recur", test_recur, do_test, do_header); + test_run("Test Recurring Events File", test_recur_file, do_test, do_header); + test_run("Test parameter bug", test_recur_parameter_bug, do_test, do_header); + test_run("Test Array Expansion", test_expand_recurrence, do_test, do_header); + test_run("Test Free/Busy lists", test_fblist, do_test, do_header); + test_run("Test Overlaps", test_overlaps, do_test, do_header); + + test_run("Test Span", test_icalcomponent_get_span, do_test, do_header); + test_run("Test Gauge SQL", test_gauge_sql, do_test, do_header); + test_run("Test Gauge Compare", test_gauge_compare, do_test, do_header); + test_run("Test File Set", test_fileset, do_test, do_header); + test_run("Test File Set (Extended)", test_fileset_extended, do_test, do_header); + test_run("Test Dir Set", test_dirset, do_test, do_header); + test_run("Test Dir Set (Extended)", test_dirset_extended, do_test, do_header); + + test_run("Test File Locks", test_file_locks, do_test, do_header); + test_run("Test X Props and Params", test_x, do_test, do_header); + test_run("Test Trigger", test_trigger, do_test, do_header); + test_run("Test Restriction", test_restriction, do_test, do_header); + test_run("Test RDATE", test_rdate, do_test, do_header); + test_run("Test language binding", test_langbind, do_test, do_header); + test_run("Test property parser", test_property_parse, do_test, do_header); + test_run("Test Action", test_action, do_test, do_header); + test_run("Test Value Parameter", test_value_parameter, do_test, do_header); + test_run("Test X property", test_x_property, do_test, do_header); + test_run("Test X parameter", test_x_parameter, do_test, do_header); + test_run("Test request status", test_requeststat, do_test, do_header); + test_run("Test UTC-OFFSET", test_utcoffset, do_test, do_header); + test_run("Test Values", test_values, do_test, do_header); + test_run("Test Parameters", test_parameters, do_test, do_header); + test_run("Test Properties", test_properties, do_test, do_header); + test_run("Test Components", test_components, do_test, do_header); + test_run("Test Convenience", test_convenience, do_test, do_header); + test_run("Test classify ", test_classify, do_test, do_header); + test_run("Test Iterators", test_iterators, do_test, do_header); + test_run("Test strings", test_strings, do_test, do_header); + test_run("Test Compare", test_compare, do_test, do_header); + test_run("Create Simple Component", create_simple_component, do_test, do_header); + test_run("Create Components", create_new_component, do_test, do_header); + test_run("Create Components with vaargs", create_new_component_with_va_args, do_test, do_header); + test_run("Test Memory", test_memory, do_test, do_header); + test_run("Test Attachment", test_attach, do_test, do_header); + test_run("Test icalcalendar", test_calendar, do_test, do_header); + test_run("Test Dirset", test_dirset, do_test, do_header); + test_run("Test vCal to iCal conversion", test_vcal, do_test, do_header); + test_run("Test UTF-8 Handling", test_utf8, do_test, do_header); + + /** OPTIONAL TESTS go here... **/ + +#ifdef WITH_CXX + test_run("Test C++ API", test_cxx, do_test, do_header); +#endif - if(tbasic == 1 || tbasic == 5){ - printf("\n------------Test Components ----------\n"); - test_components(); - } +#ifdef WITH_BDB + test_run("Test BDB Set", test_bdbset, do_test, do_header); +#endif - if(tmisc == 1){ - printf("\n------------Test Convenience ------------\n"); - test_convenience(); - - - printf("\n------------Test classify ---------------\n"); - test_classify(); - - - printf("\n------------Test Iterators-----------\n"); - test_iterators(); - - - printf("\n-----------Test request status-------\n"); - test_requeststat(); - - printf("\n------------Test strings---------------\n"); - test_strings(); - - printf("\n------------Test Compare---------------\n"); - test_compare(); - - printf("\n------------Create Components --------\n"); - create_new_component(); - - printf("\n----- Create Components with vaargs ---\n"); - create_new_component_with_va_args(); + icaltimezone_free_builtin_timezones(); + icalmemory_free_ring(); + free_zone_directory(); - printf("\n------------Test Memory---------------\n"); - test_memory(); - } + test_end(); return 0; } - |