Back to index

lightning-sunbird  0.9+nobinonly
regression.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: regression.c
00004   CREATOR: eric 03 April 1999
00005   
00006   DESCRIPTION:
00007   
00008   $Id: regression.c,v 1.64 2003/02/17 15:26:18 acampi Exp $
00009   $Locker:  $
00010 
00011   (C) COPYRIGHT 1999 Eric Busboom 
00012   http://www.softwarestudio.org
00013 
00014   The contents of this file are subject to the Mozilla Public License
00015   Version 1.0 (the "License"); you may not use this file except in
00016   compliance with the License. You may obtain a copy of the License at
00017   http://www.mozilla.org/MPL/
00018  
00019   Software distributed under the License is distributed on an "AS IS"
00020   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00021   the License for the specific language governing rights and
00022   limitations under the License.
00023 
00024   The original author is Eric Busboom
00025   The original code is regression.c
00026 
00027     
00028   ======================================================================*/
00029 
00030 #include "ical.h"
00031 #include "icalss.h"
00032 #include "icalvcal.h"
00033 
00034 #include "regression.h"
00035 
00036 #include <assert.h>
00037 #include <string.h> /* for strdup */
00038 #include <stdlib.h> /* for malloc */
00039 #include <stdio.h> /* for printf */
00040 #include <time.h> /* for time() */
00041 #ifndef WIN32
00042 #include <unistd.h> /* for unlink, fork */
00043 #include <sys/wait.h> /* For waitpid */
00044 #include <sys/time.h> /* for select */
00045 #else
00046 #include <Windows.h>
00047 #endif
00048 #include <sys/types.h> /* For wait pid */
00049 
00050 #ifdef WIN32
00051 typedef int pid_t;
00052 #endif
00053 
00054 
00055 /* For GNU libc, strcmp appears to be a macro, so using strcmp in
00056  assert results in incomprehansible assertion messages. This
00057  eliminates the problem */
00058 
00059 int regrstrcmp(const char* a, const char* b){
00060     return strcmp(a,b);
00061 }
00062 
00063 /* This example creates and minipulates the ical object that appears
00064  * in rfc 2445, page 137 */
00065 
00066 static char str[] = "BEGIN:VCALENDAR\
00067 PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\
00068 VERSION:2.0\
00069 BEGIN:VTIMEZONE\
00070 TZID:America/New_York\
00071 BEGIN:STANDARD\
00072 DTSTART:19981025T020000\
00073 RDATE:19981025T020000\
00074 TZOFFSETFROM:-0400\
00075 TZOFFSETTO:-0500\
00076 TZNAME:EST\
00077 END:STANDARD\
00078 BEGIN:DAYLIGHT\
00079 DTSTART:19990404T020000\
00080 RDATE:19990404T020000\
00081 TZOFFSETFROM:-0500\
00082 TZOFFSETTO:-0400\
00083 TZNAME:EDT\
00084 END:DAYLIGHT\
00085 END:VTIMEZONE\
00086 BEGIN:VEVENT\
00087 DTSTAMP:19980309T231000Z\
00088 UID:guid-1.host1.com\
00089 ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\
00090 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\
00091 DESCRIPTION:Project XYZ Review Meeting\
00092 CATEGORIES:MEETING\
00093 CLASS:PUBLIC\
00094 CREATED:19980309T130000Z\
00095 SUMMARY:XYZ Project Review\
00096 DTSTART;TZID=America/New_York:19980312T083000\
00097 DTEND;TZID=America/New_York:19980312T093000\
00098 LOCATION:1CP Conference Room 4350\
00099 END:VEVENT\
00100 BEGIN:BOOGA\
00101 DTSTAMP:19980309T231000Z\
00102 X-LIC-FOO:Booga\
00103 DTSTOMP:19980309T231000Z\
00104 UID:guid-1.host1.com\
00105 END:BOOGA\
00106 END:VCALENDAR";
00107 
00108 
00109 
00110 /* Return a list of all attendees who are required. */
00111    
00112 static char** get_required_attendees(icalcomponent* event)
00113 {
00114     icalproperty* p;
00115     icalparameter* parameter;
00116 
00117     char **attendees;
00118     int max = 10;
00119     int c = 0;
00120 
00121     attendees = malloc(max * (sizeof (char *)));
00122 
00123     ok("event is non null", (event != 0));
00124     int_is("event is a VEVENT", icalcomponent_isa(event), ICAL_VEVENT_COMPONENT);
00125     
00126     for(
00127        p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
00128        p != 0;
00129        p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
00130        ) {
00131        
00132        parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER);
00133 
00134        if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT) 
00135        {
00136            attendees[c++] = icalmemory_strdup(icalproperty_get_attendee(p));
00137 
00138             if (c >= max) {
00139                 max *= 2; 
00140                 attendees = realloc(attendees, max * (sizeof (char *)));
00141             }
00142 
00143        }
00144     }
00145 
00146     return attendees;
00147 }
00148 
00149 /* If an attendee has a PARTSTAT of NEEDSACTION or has no PARTSTAT
00150    parameter, change it to TENTATIVE. */
00151    
00152 static void update_attendees(icalcomponent* event)
00153 {
00154     icalproperty* p;
00155     icalparameter* parameter;
00156 
00157 
00158     assert(event != 0);
00159     assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);
00160     
00161     for(
00162        p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
00163        p != 0;
00164        p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
00165        ) {
00166        
00167        parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);
00168 
00169        if (parameter == 0) {
00170 
00171            icalproperty_add_parameter(
00172               p,
00173               icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
00174               );
00175 
00176        } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) {
00177 
00178            icalproperty_remove_parameter_by_ref(p,parameter);
00179            
00180            icalparameter_free(parameter);
00181 
00182            icalproperty_add_parameter(
00183               p,
00184               icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
00185               );
00186        }
00187 
00188     }
00189 }
00190 
00191 
00192 void test_values()
00193 {
00194     icalvalue *v; 
00195     icalvalue *copy; 
00196 
00197     v = icalvalue_new_caladdress("cap://value/1");
00198 
00199     is("icalvalue_new_caladdress()", 
00200        icalvalue_get_caladdress(v), "cap://value/1");
00201 
00202     icalvalue_set_caladdress(v,"cap://value/2");
00203 
00204     is("icalvalue_set_caladdress()",
00205        icalvalue_get_caladdress(v), "cap://value/2");
00206 
00207     is("icalvalue_as_ical_string()",
00208        icalvalue_as_ical_string(v), "cap://value/2");
00209 
00210     copy = icalvalue_new_clone(v);
00211 
00212     is("icalvalue_new_clone()",
00213        icalvalue_as_ical_string(copy), "cap://value/2");
00214     icalvalue_free(v);
00215     icalvalue_free(copy);
00216 
00217 
00218     v = icalvalue_new_boolean(1);
00219     int_is("icalvalue_new_boolean(1)", icalvalue_get_boolean(v), 1);
00220     icalvalue_set_boolean(v,2);
00221     ok("icalvalue_set_boolean(2)", (2 == icalvalue_get_boolean(v)));
00222     is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "2");
00223 
00224     copy = icalvalue_new_clone(v);
00225     is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "2");
00226 
00227     icalvalue_free(v);
00228     icalvalue_free(copy);
00229 
00230 
00231     v = icalvalue_new_x("test");
00232     is("icalvalue_new_x(test)", icalvalue_get_x(v), "test");
00233     icalvalue_set_x(v, "test2");
00234     is("icalvalue_set_x(test2)", icalvalue_get_x(v), "test2");
00235     is("icalvalue_as_ical_string()", icalvalue_as_ical_string(v), "test2");
00236 
00237     copy = icalvalue_new_clone(v);
00238     is("icalvalue_new_clone()", icalvalue_as_ical_string(copy), "test2");
00239 
00240     icalvalue_free(v);
00241     icalvalue_free(copy);
00242 
00243 
00244     v = icalvalue_new_date(icaltime_from_timet( 1023404802,0));
00245     is("icalvalue_new_date()", icalvalue_as_ical_string(v), "20020606T230642");
00246     icalvalue_set_date(v,icaltime_from_timet( 1023404802-3600,0));
00247     is("icalvalue_set_date()",icalvalue_as_ical_string(v), "20020606T220642");
00248 
00249     copy = icalvalue_new_clone(v);
00250     is("icalvalue_new_clone()",icalvalue_as_ical_string(v), "20020606T220642");
00251 
00252     icalvalue_free(v);
00253     icalvalue_free(copy);
00254 
00255 
00256     v = icalvalue_new(-1);
00257 
00258     ok("icalvalue_new(-1), Invalid type", (v == NULL));
00259 
00260     if (v!=0) icalvalue_free(v);
00261 
00262     ok("ICAL_BOOLEAN_VALUE",(ICAL_BOOLEAN_VALUE == 
00263            icalparameter_value_to_value_kind(ICAL_VALUE_BOOLEAN)));
00264     ok("ICAL_UTCOFFSET_VALUE",(ICAL_UTCOFFSET_VALUE == 
00265            icalparameter_value_to_value_kind(ICAL_VALUE_UTCOFFSET)));
00266     ok("ICAL_RECUR_VALUE", (ICAL_RECUR_VALUE == 
00267            icalparameter_value_to_value_kind(ICAL_VALUE_RECUR)));
00268     ok("ICAL_CALADDRESS_VALUE",(ICAL_CALADDRESS_VALUE == 
00269            icalparameter_value_to_value_kind(ICAL_VALUE_CALADDRESS)));
00270     ok("ICAL_PERIOD_VALUE", (ICAL_PERIOD_VALUE == 
00271            icalparameter_value_to_value_kind(ICAL_VALUE_PERIOD)));
00272     ok("ICAL_BINARY_VALUE",(ICAL_BINARY_VALUE == 
00273            icalparameter_value_to_value_kind(ICAL_VALUE_BINARY)));
00274     ok("ICAL_TEXT_VALUE",(ICAL_TEXT_VALUE == 
00275            icalparameter_value_to_value_kind(ICAL_VALUE_TEXT)));
00276     ok("ICAL_DURATION_VALUE",(ICAL_DURATION_VALUE == 
00277            icalparameter_value_to_value_kind(ICAL_VALUE_DURATION)));
00278     ok("ICAL_INTEGER_VALUE",
00279        (ICAL_INTEGER_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_INTEGER)));
00280 
00281     ok("ICAL_URI_VALUE",
00282        (ICAL_URI_VALUE == icalparameter_value_to_value_kind(ICAL_VALUE_URI)));
00283     ok("ICAL_FLOAT_VALUE",(ICAL_FLOAT_VALUE == 
00284            icalparameter_value_to_value_kind(ICAL_VALUE_FLOAT)));
00285     ok("ICAL_X_VALUE",(ICAL_X_VALUE == 
00286            icalparameter_value_to_value_kind(ICAL_VALUE_X)));
00287     ok("ICAL_DATETIME_VALUE",(ICAL_DATETIME_VALUE == 
00288            icalparameter_value_to_value_kind(ICAL_VALUE_DATETIME)));
00289     ok("ICAL_DATE_TIME",(ICAL_DATE_VALUE == 
00290            icalparameter_value_to_value_kind(ICAL_VALUE_DATE)));
00291 
00292     /*    v = icalvalue_new_caladdress(0);
00293 
00294     printf("Bad string: %p\n",v);
00295 
00296     if (v!=0) icalvalue_free(v); */
00297 
00298     icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL);
00299     v = icalvalue_new_from_string(ICAL_RECUR_VALUE,"D2 #0");
00300     ok("illegal recur value", (v == 0));
00301 
00302     v = icalvalue_new_from_string(ICAL_TRIGGER_VALUE,"Gonk");
00303     ok("illegal trigger value", (v == 0));
00304 
00305     v = icalvalue_new_from_string(ICAL_REQUESTSTATUS_VALUE,"Gonk");
00306     ok("illegal requeststatus value", (v == 0));
00307 
00308     icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_DEFAULT);
00309 }
00310 
00311 
00312 void test_properties()
00313 {
00314     icalproperty *prop;
00315     icalparameter *param;
00316 
00317     icalproperty *clone;
00318     char test_cn_str[128] = "";
00319     char *test_cn_str_good = "A Common Name 1A Common Name 2A Common Name 3A Common Name 4";
00320     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";
00321 
00322     prop = icalproperty_vanew_comment(
00323        "Another Comment",
00324        icalparameter_new_cn("A Common Name 1"),
00325        icalparameter_new_cn("A Common Name 2"),
00326        icalparameter_new_cn("A Common Name 3"),
00327               icalparameter_new_cn("A Common Name 4"),
00328        0); 
00329 
00330     for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER);
00331        param != 0; 
00332        param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) {
00333       const char *str = icalparameter_get_cn(param);
00334       if (VERBOSE) printf("Prop parameter: %s\n",icalparameter_get_cn(param));
00335       strcat(test_cn_str, str);
00336     }    
00337     is("fetching parameters", test_cn_str, test_cn_str_good);
00338 
00339     if (VERBOSE) printf("Prop value: %s\n",icalproperty_get_comment(prop));
00340     is("icalproperty_get_comment()", 
00341        icalproperty_get_comment(prop), "Another Comment");
00342 
00343     if (VERBOSE) printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop));
00344     
00345     is("icalproperty_as_ical_string()",
00346        icalproperty_as_ical_string(prop), test_ical_str_good);
00347     
00348     clone = icalproperty_new_clone(prop);
00349 
00350     if (VERBOSE) printf("Clone:\n %s\n",icalproperty_as_ical_string(prop));
00351     is("icalproperty_new_clone()",
00352        icalproperty_as_ical_string(prop), test_ical_str_good);
00353     
00354     icalproperty_free(clone);
00355     icalproperty_free(prop);
00356 
00357     prop = icalproperty_new(-1);
00358 
00359     ok("test icalproperty_new() with invalid type (-1)",
00360        (prop == NULL));
00361 
00362     if (prop!=0) icalproperty_free(prop);
00363 }
00364 
00365 void test_utf8()
00366 {
00367     icalproperty *prop;
00368     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á";
00369     char *test_ical_str_good = "DESCRIPTION:\n"
00370 " aáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaá\n"
00371 " óaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóaáóa\n"
00372 " áóaáóaáóaáóaáóaáóaáóaáóaáóaá\n";
00373 
00374     prop = icalproperty_new_description(utf8text);
00375 
00376     is("icalproperty_as_ical_string()",
00377        icalproperty_as_ical_string(prop), test_ical_str_good);
00378     icalproperty_free(prop);
00379 }
00380 
00381 
00382 
00383 void test_parameters()
00384 {
00385     icalparameter *p;
00386     int i;
00387     int enums[] = {ICAL_CUTYPE_INDIVIDUAL,ICAL_CUTYPE_RESOURCE,ICAL_FBTYPE_BUSY,ICAL_PARTSTAT_NEEDSACTION,ICAL_ROLE_NONPARTICIPANT,ICAL_XLICCOMPARETYPE_LESSEQUAL,ICAL_XLICERRORTYPE_MIMEPARSEERROR,-1};
00388 
00389     char* str1 = "A Common Name";
00390 
00391     p = icalparameter_new_cn(str1);
00392 
00393     is("icalparameter_new_cn()", icalparameter_get_cn(p), str1);
00394     is("icalparameter_as_ical_string()" ,icalparameter_as_ical_string(p),"CN=A Common Name");
00395     
00396     icalparameter_free(p);
00397 
00398     p = icalparameter_new_from_string("PARTSTAT=ACCEPTED");
00399     ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER));
00400     ok("PARTSTAT_ACCEPTED", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_ACCEPTED));
00401  
00402     icalparameter_free(p);
00403 
00404     p = icalparameter_new_from_string("ROLE=CHAIR");
00405 
00406     ok("ROLE_PARAMETER", (icalparameter_isa(p) == ICAL_ROLE_PARAMETER));
00407     ok("ROLE_CHAIR", (icalparameter_get_partstat(p) == ICAL_ROLE_CHAIR));
00408  
00409     icalparameter_free(p);
00410 
00411     p = icalparameter_new_from_string("PARTSTAT=X-FOO");
00412     ok("PARTSTAT_PARAMETER", (icalparameter_isa(p) == ICAL_PARTSTAT_PARAMETER));
00413     ok("PARTSTAT_X", (icalparameter_get_partstat(p) == ICAL_PARTSTAT_X));
00414  
00415     icalparameter_free(p);
00416 
00417     p = icalparameter_new_from_string("X-PARAM=X-FOO");
00418     ok("X_PARAMETER", (icalparameter_isa(p) == ICAL_X_PARAMETER));
00419  
00420     icalparameter_free(p);
00421 
00422 
00423     for (i=0;enums[i] != -1; i++){
00424       if (VERBOSE) printf("%s\n",icalparameter_enum_to_string(enums[i]));
00425       ok("test paramter enums", 
00426         (icalparameter_string_to_enum(icalparameter_enum_to_string(enums[i]))==enums[i]));
00427     }
00428 }
00429 
00430 
00431 char *good_child = 
00432 "BEGIN:VEVENT\n"
00433 "VERSION:2.0\n"
00434 "DESCRIPTION:This is an event\n"
00435 "COMMENT;CN=A Common Name 1;CN=A Common Name 2;CN=A Common Name 3;CN=A \n"
00436 " Common Name 4:Another Comment\n"
00437 "X-LIC-ERROR;X-LIC-ERRORTYPE=COMPONENT-PARSE-ERROR:This is only a test\n"
00438 "END:VEVENT\n";
00439 
00440 void test_components()
00441 {
00442     icalcomponent* c;
00443     icalcomponent* child;
00444 
00445     c = icalcomponent_vanew(
00446        ICAL_VCALENDAR_COMPONENT,
00447        icalproperty_new_version("2.0"),
00448        icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"),
00449        icalproperty_vanew_comment(
00450            "A Comment",
00451            icalparameter_new_cn("A Common Name 1"),
00452            0),
00453        icalcomponent_vanew(
00454            ICAL_VEVENT_COMPONENT,
00455            icalproperty_new_version("2.0"),
00456            icalproperty_new_description("This is an event"),
00457            icalproperty_vanew_comment(
00458               "Another Comment",
00459               icalparameter_new_cn("A Common Name 1"),
00460               icalparameter_new_cn("A Common Name 2"),
00461               icalparameter_new_cn("A Common Name 3"),
00462               icalparameter_new_cn("A Common Name 4"),
00463               0),
00464            icalproperty_vanew_xlicerror(
00465               "This is only a test",
00466               icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR),
00467               0),
00468            
00469            0
00470            ),
00471        0
00472        );
00473 
00474     if (VERBOSE) 
00475       printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c));
00476 
00477     child = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT);
00478     
00479     ok("test icalcomponent_get_first_component()",
00480        (child != NULL));
00481 
00482     if (VERBOSE)
00483       printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child));
00484 
00485     is("test results of child component", 
00486        icalcomponent_as_ical_string(child), good_child);
00487 
00488     icalcomponent_free(c);
00489 }
00490 
00491 
00492 void test_memory()
00493 {
00494     size_t bufsize = 256;
00495     int i;
00496     char *p;
00497 
00498     char S1[] = "1) When in the Course of human events, ";
00499     char S2[] = "2) it becomes necessary for one people to dissolve the political bands which have connected them with another, ";
00500     char S3[] = "3) and to assume among the powers of the earth, ";
00501     char S4[] = "4) the separate and equal station to which the Laws of Nature and of Nature's God entitle them, ";
00502     char S5[] = "5) a decent respect to the opinions of mankind requires that they ";
00503     char S6[] = "6) should declare the causes which impel them to the separation. ";
00504     char S7[] = "7) We hold these truths to be self-evident, ";
00505     char S8[] = "8) that all men are created equal, ";
00506 
00507 /*    char S9[] = "9) that they are endowed by their Creator with certain unalienable Rights, ";
00508     char S10[] = "10) that among these are Life, Liberty, and the pursuit of Happiness. ";
00509     char S11[] = "11) That to secure these rights, Governments are instituted among Men, ";
00510     char S12[] = "12) deriving their just powers from the consent of the governed. "; 
00511 */
00512 
00513 
00514     char *f, *b1, *b2, *b3, *b4, *b5, *b6, *b7, *b8;
00515 
00516 #define BUFSIZE 1024
00517 
00518     f = icalmemory_new_buffer(bufsize);
00519     p = f;
00520     b1 = icalmemory_tmp_buffer(BUFSIZE);
00521     strcpy(b1, S1);
00522     icalmemory_append_string(&f, &p, &bufsize, b1);
00523 
00524     b2 = icalmemory_tmp_buffer(BUFSIZE);
00525     strcpy(b2, S2);
00526     icalmemory_append_string(&f, &p, &bufsize, b2);
00527 
00528     b3 = icalmemory_tmp_buffer(BUFSIZE);
00529     strcpy(b3, S3);
00530     icalmemory_append_string(&f, &p, &bufsize, b3);
00531 
00532     b4 = icalmemory_tmp_buffer(BUFSIZE);
00533     strcpy(b4, S4);
00534     icalmemory_append_string(&f, &p, &bufsize, b4);
00535 
00536     b5 = icalmemory_tmp_buffer(BUFSIZE);
00537     strcpy(b5, S5);
00538     icalmemory_append_string(&f, &p, &bufsize, b5);
00539 
00540     b6 = icalmemory_tmp_buffer(BUFSIZE);
00541     strcpy(b6, S6);
00542     icalmemory_append_string(&f, &p, &bufsize, b6);
00543 
00544     b7 = icalmemory_tmp_buffer(BUFSIZE);
00545     strcpy(b7, S7);
00546     icalmemory_append_string(&f, &p, &bufsize, b7);
00547 
00548     b8 = icalmemory_tmp_buffer(BUFSIZE);
00549     strcpy(b8, S8);
00550     icalmemory_append_string(&f, &p, &bufsize, b8);
00551 
00552 
00553     if (VERBOSE) {
00554       printf("1: %p %s \n",b1,b1);
00555       printf("2: %p %s\n",b2,b2);
00556       printf("3: %p %s\n",b3,b3);
00557       printf("4: %p %s\n",b4,b4);
00558       printf("5: %p %s\n",b5,b5);
00559       printf("6: %p %s\n",b6,b6);
00560       printf("7: %p %s\n",b7,b7);
00561       printf("8: %p %s\n",b8,b8);
00562       
00563       
00564       printf("Final: %s\n", f);
00565       
00566       printf("Final buffer size: %d\n",bufsize);
00567     }
00568 
00569     ok("final buffer size == 806", (bufsize == 806));
00570 
00571     free(f);
00572     
00573     bufsize = 4;
00574 
00575     f = icalmemory_new_buffer(bufsize);
00576 
00577     memset(f,0,bufsize);
00578     p = f;
00579 
00580     icalmemory_append_char(&f, &p, &bufsize, 'a');
00581     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00582 
00583     icalmemory_append_char(&f, &p, &bufsize, 'b');
00584     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00585     icalmemory_append_char(&f, &p, &bufsize, 'c');
00586     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00587     icalmemory_append_char(&f, &p, &bufsize, 'd');
00588     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00589     icalmemory_append_char(&f, &p, &bufsize, 'e');
00590     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00591     icalmemory_append_char(&f, &p, &bufsize, 'f');
00592     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00593     icalmemory_append_char(&f, &p, &bufsize, 'g');
00594     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00595     icalmemory_append_char(&f, &p, &bufsize, 'h');
00596     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00597     icalmemory_append_char(&f, &p, &bufsize, 'i');
00598     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00599     icalmemory_append_char(&f, &p, &bufsize, 'j');
00600     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00601     icalmemory_append_char(&f, &p, &bufsize, 'a');
00602     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00603     icalmemory_append_char(&f, &p, &bufsize, 'b');
00604     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00605     icalmemory_append_char(&f, &p, &bufsize, 'c');
00606     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00607     icalmemory_append_char(&f, &p, &bufsize, 'd');
00608     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00609     icalmemory_append_char(&f, &p, &bufsize, 'e');
00610     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00611     icalmemory_append_char(&f, &p, &bufsize, 'f');
00612     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00613     icalmemory_append_char(&f, &p, &bufsize, 'g');
00614     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00615     icalmemory_append_char(&f, &p, &bufsize, 'h');
00616     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00617     icalmemory_append_char(&f, &p, &bufsize, 'i');
00618     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00619     icalmemory_append_char(&f, &p, &bufsize, 'j');
00620     if (VERBOSE) printf("Char-by-Char buffer: %s\n", f);
00621  
00622        free(f);
00623   
00624     for(i=0; i<100; i++){
00625        f = icalmemory_tmp_buffer(bufsize);
00626        
00627        assert(f!=0);
00628 
00629        memset(f,0,bufsize);
00630        sprintf(f,"%d",i);
00631     }
00632 }
00633 
00634 
00635 void test_dirset()
00636 {
00637     icalcomponent *c;
00638     icalgauge *gauge;
00639     icalerrorenum error;
00640     icalcomponent *next, *itr;
00641     icalset* cluster;
00642     icalset *s, *s2;
00643     struct icalperiodtype rtime;
00644     int i;
00645     int count = 0;
00646 
00647     mkdir("store", 0755);
00648     mkdir("store-new", 0755);
00649 
00650     s = icaldirset_new("store");
00651     s2 = icaldirset_new("store-new");
00652 
00653     ok("opening 'store' dirset", s!=NULL);
00654     ok("opening 'store-new' dirset", s2!=NULL);
00655 
00656     rtime.start = icaltime_from_timet( time(0),0);
00657 
00658     cluster = icalfileset_new("clusterin.vcd");
00659 
00660     if (cluster == 0){
00661        printf("Failed to create cluster: %s\n",icalerror_strerror(icalerrno));
00662     }
00663 
00664 #define NUMCOMP 4
00665 
00666     /* Duplicate every component in the cluster NUMCOMP times */
00667 
00668     icalerror_clear_errno();
00669 
00670     for (i = 1; i<NUMCOMP+1; i++){
00671 
00672        /*rtime.start.month = i%12;*/
00673        rtime.start.month = i;
00674        rtime.end = rtime.start;
00675        rtime.end.hour++;
00676        
00677        for (itr = icalfileset_get_first_component(cluster);
00678             itr != 0;
00679             itr = icalfileset_get_next_component(cluster)){
00680            icalcomponent *clone;
00681            icalproperty *p;
00682 
00683            
00684            if(icalcomponent_isa(itr) != ICAL_VEVENT_COMPONENT){
00685               continue;
00686            }
00687 
00688            
00689            /* Change the dtstart and dtend times in the component
00690                pointed to by Itr*/
00691 
00692            clone = icalcomponent_new_clone(itr);
00693            assert(icalerrno == ICAL_NO_ERROR);
00694            assert(clone !=0);
00695 
00696            /* DTSTART*/
00697            p = icalcomponent_get_first_property(clone,ICAL_DTSTART_PROPERTY);
00698            assert(icalerrno  == ICAL_NO_ERROR);
00699 
00700            if (p == 0){
00701               p = icalproperty_new_dtstart(rtime.start);
00702               icalcomponent_add_property(clone,p);
00703            } else {
00704               icalproperty_set_dtstart(p,rtime.start);
00705            }
00706            assert(icalerrno  == ICAL_NO_ERROR);
00707 
00708            /* DTEND*/
00709            p = icalcomponent_get_first_property(clone,ICAL_DTEND_PROPERTY);
00710            assert(icalerrno  == ICAL_NO_ERROR);
00711 
00712            if (p == 0){
00713               p = icalproperty_new_dtstart(rtime.end);
00714               icalcomponent_add_property(clone,p);
00715            } else {
00716               icalproperty_set_dtstart(p,rtime.end);
00717            }
00718            assert(icalerrno  == ICAL_NO_ERROR);
00719            
00720            printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(clone));
00721 
00722            error = icaldirset_add_component(s,clone);
00723            
00724            assert(icalerrno  == ICAL_NO_ERROR);
00725        }
00726     }
00727     
00728     gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0);
00729 
00730     icaldirset_select(s,gauge);
00731 
00732     for(c = icaldirset_get_first_component(s); c != 0; c = icaldirset_get_next_component(s)){
00733        printf("Got one! (%d)\n", count++);
00734        
00735        if (c != 0){
00736            printf("%s", icalcomponent_as_ical_string(c));;
00737            if (icaldirset_add_component(s2,c) == 0){
00738               printf("Failed to write!\n");
00739            }
00740            icalcomponent_free(c);
00741        } else {
00742            printf("Failed to get component\n");
00743        }
00744     }
00745 
00746 
00747     icalset_free(s2);
00748 
00749     for(c = icaldirset_get_first_component(s); 
00750        c != 0; 
00751        c =  next){
00752        
00753        next = icaldirset_get_next_component(s);
00754 
00755        if (c != 0){
00756            /*icaldirset_remove_component(s,c);*/
00757            printf("%s", icalcomponent_as_ical_string(c));;
00758        } else {
00759            printf("Failed to get component\n");
00760        }
00761     }
00762 
00763     icalset_free(s);
00764     icalset_free(cluster);
00765 }
00766 
00767 
00768 void test_compare()
00769 {
00770     icalvalue *v1, *v2;
00771 
00772     v1 = icalvalue_new_caladdress("cap://value/1");
00773     v2 = icalvalue_new_clone(v1);
00774 
00775     ok("compare value and clone", 
00776        (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL));
00777 
00778     icalvalue_free(v1);
00779     icalvalue_free(v2);
00780 
00781     v1 = icalvalue_new_caladdress("A");
00782     v2 = icalvalue_new_caladdress("B");
00783 
00784     ok("test compare of A and B results in LESS",
00785        (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS));
00786           
00787     ok("test compare of B and A results in GREATER",
00788        (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER));
00789 
00790     icalvalue_free(v1);
00791     icalvalue_free(v2);
00792 
00793     v1 = icalvalue_new_caladdress("B");
00794     v2 = icalvalue_new_caladdress("A");
00795 
00796     ok("test compare of caladdress A and B results in GREATER",
00797        (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_GREATER));
00798     
00799     icalvalue_free(v1);
00800     icalvalue_free(v2);
00801 
00802     v1 = icalvalue_new_integer(5);
00803     v2 = icalvalue_new_integer(5);
00804 
00805     ok("test compare of 5 and 5 results in EQUAL", 
00806        (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_EQUAL));
00807 
00808     icalvalue_free(v1);
00809     icalvalue_free(v2);
00810 
00811     v1 = icalvalue_new_integer(5);
00812     v2 = icalvalue_new_integer(10);
00813 
00814     ok("test compare of 5 and 10 results in LESS",
00815        (icalvalue_compare(v1,v2) == ICAL_XLICCOMPARETYPE_LESS));
00816           
00817     ok("test compare of 10 and 5 results in GREATER",
00818        (icalvalue_compare(v2,v1) == ICAL_XLICCOMPARETYPE_GREATER));
00819 
00820     icalvalue_free(v1);
00821     icalvalue_free(v2);
00822 }
00823 
00824 
00825 void test_restriction()
00826 {
00827     icalcomponent *comp;
00828     struct icaltimetype atime = icaltime_from_timet( time(0),0);
00829     int valid; 
00830 
00831     struct icaldatetimeperiodtype rtime;
00832 
00833     char *str;
00834 
00835     rtime.period.start = icaltime_from_timet( time(0),0);
00836     rtime.period.end = icaltime_from_timet( time(0),0);
00837     rtime.period.end.hour++;
00838     rtime.time = icaltime_null_time();
00839 
00840     comp = 
00841        icalcomponent_vanew(
00842            ICAL_VCALENDAR_COMPONENT,
00843            icalproperty_new_version("2.0"),
00844            icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"),
00845            icalproperty_new_method(ICAL_METHOD_REQUEST),
00846            icalcomponent_vanew(
00847               ICAL_VTIMEZONE_COMPONENT,
00848               icalproperty_new_tzid("America/New_York"),
00849               icalcomponent_vanew(
00850                   ICAL_XDAYLIGHT_COMPONENT,
00851                   icalproperty_new_dtstart(atime),
00852                   icalproperty_new_rdate(rtime),
00853                   icalproperty_new_tzoffsetfrom(-4.0),
00854                   icalproperty_new_tzoffsetto(-5.0),
00855                   icalproperty_new_tzname("EST"),
00856                   0
00857                   ),
00858               icalcomponent_vanew(
00859                   ICAL_XSTANDARD_COMPONENT,
00860                   icalproperty_new_dtstart(atime),
00861                   icalproperty_new_rdate(rtime),
00862                   icalproperty_new_tzoffsetfrom(-5.0),
00863                   icalproperty_new_tzoffsetto(-4.0),
00864                   icalproperty_new_tzname("EST"),
00865                   0
00866                   ),
00867               0
00868               ),
00869            icalcomponent_vanew(
00870               ICAL_VEVENT_COMPONENT,
00871               icalproperty_new_dtstamp(atime),
00872               icalproperty_new_uid("guid-1.host1.com"),
00873               icalproperty_vanew_organizer(
00874                   "mrbig@host.com",
00875                   icalparameter_new_role(ICAL_ROLE_CHAIR),
00876                   0
00877                   ),
00878               icalproperty_vanew_attendee(
00879                   "employee-A@host.com",
00880                   icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT),
00881                   icalparameter_new_rsvp(ICAL_RSVP_TRUE),
00882                   icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
00883                   0
00884                   ),
00885               icalproperty_new_description("Project XYZ Review Meeting"),
00886               icalproperty_new_categories("MEETING"),
00887               icalproperty_new_class(ICAL_CLASS_PUBLIC),
00888               icalproperty_new_created(atime),
00889               icalproperty_new_summary("XYZ Project Review"),
00890                 /*          icalproperty_new_dtstart(
00891                   atime,
00892                   icalparameter_new_tzid("America/New_York"),
00893                   0
00894                   ),*/
00895               icalproperty_vanew_dtend(
00896                   atime,
00897                   icalparameter_new_tzid("America/New_York"),
00898                   0
00899                   ),
00900               icalproperty_new_location("1CP Conference Room 4350"),
00901               0
00902               ),
00903            0
00904            );
00905 
00906     valid = icalrestriction_check(comp);
00907     
00908     ok("icalrestriction_check() == 0", (valid==0));
00909     
00910     str = icalcomponent_as_ical_string(comp);
00911 
00912     icalcomponent_free(comp);
00913 
00914 }
00915 
00916 void test_calendar()
00917 {
00918     icalcomponent *comp;
00919     icalset *c;
00920     icalset *s;
00921     icalcalendar* calendar;
00922     icalerrorenum error;
00923     struct icaltimetype atime = icaltime_from_timet( time(0),0);
00924 
00925     mkdir("calendar", 0755);
00926     mkdir("calendar/booked", 0755);
00927 
00928     calendar = icalcalendar_new("calendar");
00929 
00930     comp = icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT,
00931        icalcomponent_vanew(
00932        ICAL_VEVENT_COMPONENT,
00933        icalproperty_new_version("2.0"),
00934        icalproperty_new_description("This is an event"),
00935        icalproperty_new_dtstart(atime),
00936        icalproperty_vanew_comment(
00937            "Another Comment",
00938            icalparameter_new_cn("A Common Name 1"),
00939            icalparameter_new_cn("A Common Name 2"),
00940            icalparameter_new_cn("A Common Name 3"),
00941               icalparameter_new_cn("A Common Name 4"),
00942            0),
00943        icalproperty_vanew_xlicerror(
00944            "This is only a test",
00945            icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR),
00946            0),
00947        
00948        0),0);
00949     
00950     s = icalcalendar_get_booked(calendar);
00951 
00952     error = icaldirset_add_component(s,comp);
00953     
00954     ok("Adding Component to dirset", (error == ICAL_NO_ERROR));
00955 
00956     c = icalcalendar_get_properties(calendar);
00957 
00958     error = icalfileset_add_component(c,icalcomponent_new_clone(comp));
00959 
00960     ok("Adding Clone Component to dirset", (error == ICAL_NO_ERROR));
00961 
00962     icalcalendar_free(calendar);
00963 
00964     ok("icalcalendar test", (1));
00965 }
00966 
00967 
00968 void test_increment(void);
00969 
00970 void print_occur(struct icalrecurrencetype recur, struct icaltimetype start)
00971 {
00972     struct icaltimetype next;
00973     icalrecur_iterator* ritr;
00974        
00975     time_t tt = icaltime_as_timet(start);
00976 
00977     printf("#### %s\n",icalrecurrencetype_as_string(&recur));
00978     printf("#### %s\n",ctime(&tt ));
00979     
00980     for(ritr = icalrecur_iterator_new(recur,start),
00981            next = icalrecur_iterator_next(ritr); 
00982        !icaltime_is_null_time(next);
00983        next = icalrecur_iterator_next(ritr)){
00984        
00985        tt = icaltime_as_timet(next);
00986        
00987        printf("  %s",ctime(&tt ));        
00988        
00989     }
00990 
00991     icalrecur_iterator_free(ritr);
00992 }
00993 
00994 void test_recur()
00995 {
00996    struct icalrecurrencetype rt;
00997    struct icaltimetype start;
00998    time_t array[25];
00999    int i;
01000 
01001    rt = icalrecurrencetype_from_string("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA");
01002    start = icaltime_from_string("19970905T090000Z");
01003 
01004    if (VERBOSE) print_occur(rt,start);   
01005 
01006    if (VERBOSE) printf("\n  Using icalrecur_expand_recurrence\n");
01007 
01008    icalrecur_expand_recurrence("FREQ=MONTHLY;UNTIL=19971224T000000Z;INTERVAL=1;BYDAY=TU,2FR,3SA",
01009                             icaltime_as_timet(start),
01010                             25,
01011                             array);
01012 
01013    for(i =0; array[i] != 0 && i < 25 ; i++){
01014      if (VERBOSE) printf("  %s",ctime(&(array[i])));
01015    }
01016 
01017    
01018 /*    test_increment();*/
01019 
01020 }
01021 
01022 
01023 void test_expand_recurrence(){
01024 
01025     time_t arr[10];
01026     time_t now = 931057385;
01027     int i, numfound = 0;
01028     icalrecur_expand_recurrence( "FREQ=MONTHLY;BYDAY=MO,WE", now,
01029                                  5, arr );
01030 
01031     if (VERBOSE) printf("Start %s",ctime(&now) );
01032 
01033     for (i=0; i<5; i++) {
01034       numfound++;
01035       if (VERBOSE) printf("i=%d  %s\n", i, ctime(&arr[i]) );
01036     }
01037     int_is("Get an array of 5 items", numfound, 5);
01038 }
01039 
01040 
01041 
01042 enum byrule {
01043     NO_CONTRACTION = -1,
01044     BY_SECOND = 0,
01045     BY_MINUTE = 1,
01046     BY_HOUR = 2,
01047     BY_DAY = 3,
01048     BY_MONTH_DAY = 4,
01049     BY_YEAR_DAY = 5,
01050     BY_WEEK_NO = 6,
01051     BY_MONTH = 7,
01052     BY_SET_POS
01053 };
01054 
01055 void icalrecurrencetype_test()
01056 {
01057     icalvalue *v = icalvalue_new_from_string(
01058        ICAL_RECUR_VALUE,
01059        "FREQ=YEARLY;UNTIL=20060101T000000;INTERVAL=2;BYDAY=SU,WE;BYSECOND=15,30; BYMONTH=1,6,11");
01060 
01061     struct icalrecurrencetype r = icalvalue_get_recur(v);
01062     struct icaltimetype t = icaltime_from_timet( time(0), 0);
01063     struct icaltimetype next;
01064     time_t tt;
01065 
01066     struct icalrecur_iterator_impl* itr 
01067        = (struct icalrecur_iterator_impl*) icalrecur_iterator_new(r,t);
01068 
01069     do {
01070 
01071        next = icalrecur_iterator_next(itr);
01072        tt = icaltime_as_timet(next);
01073 
01074        printf("%s",ctime(&tt ));          
01075 
01076     } while( ! icaltime_is_null_time(next));
01077 
01078     icalvalue_free(v);
01079 
01080     icalrecur_iterator_free(itr);
01081  
01082 }
01083 
01084 /* From Federico Mena Quintero <federico@ximian.com>    */
01085 void test_recur_parameter_bug(){
01086 
01087 #ifdef HAVE_CONFIG_H
01088 #include <config.h>
01089 #endif
01090  
01091 #include <stdio.h>
01092 #include <stdlib.h>
01093 #include <ical.h>
01094  
01095     static const char test_icalcomp_str[] =
01096 "BEGIN:VEVENT\n"
01097 "RRULE;X-EVOLUTION-ENDDATE=20030209T081500:FREQ=DAILY;COUNT=10;INTERVAL=6\n"
01098 "END:VEVENT\n";
01099   
01100     icalcomponent *icalcomp;
01101     icalproperty *prop;
01102     struct icalrecurrencetype recur;
01103     int n_errors;
01104     char *str;
01105 
01106     icalcomp = icalparser_parse_string ((char *) test_icalcomp_str);
01107     ok("icalparser_parse_string()",(icalcomp!=NULL));
01108     assert(icalcomp!=NULL);
01109     
01110     str = icalcomponent_as_ical_string(icalcomp);
01111     is("parsed matches original", str, (char*)test_icalcomp_str);
01112     if (VERBOSE) printf("%s\n\n",str);
01113 
01114     n_errors = icalcomponent_count_errors (icalcomp);
01115     int_is("no parse errors", n_errors, 0);
01116 
01117     if (n_errors) {
01118        icalproperty *p;
01119        
01120        for (p = icalcomponent_get_first_property (icalcomp,
01121                                              ICAL_XLICERROR_PROPERTY);
01122             p;
01123             p = icalcomponent_get_next_property (icalcomp,
01124                                             ICAL_XLICERROR_PROPERTY)) {
01125            const char *str;
01126            
01127            str = icalproperty_as_ical_string (p);
01128            fprintf (stderr, "error: %s\n", str);
01129        }
01130     }
01131     
01132     prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY);
01133     ok("get RRULE property", (prop!=NULL));
01134     assert(prop!=NULL);
01135     
01136     recur = icalproperty_get_rrule (prop);
01137     
01138     if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur));
01139 
01140     icalcomponent_free(icalcomp);
01141 }
01142 
01143 
01144 void test_duration()
01145 {
01146     struct icaldurationtype d;
01147 
01148     d = icaldurationtype_from_string("PT8H30M");
01149     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01150     int_is("PT8H30M", icaldurationtype_as_int(d), 30600);
01151     
01152     d = icaldurationtype_from_string("-PT8H30M");
01153     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01154     int_is("-PT8H30M", icaldurationtype_as_int(d), -30600);
01155 
01156     d = icaldurationtype_from_string("PT10H10M10S");
01157     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01158     int_is("PT10H10M10S", icaldurationtype_as_int(d), 36610);
01159 
01160     d = icaldurationtype_from_string("P7W");
01161     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01162     int_is("P7W", icaldurationtype_as_int(d), 4233600);
01163 
01164     d = icaldurationtype_from_string("P2DT8H30M");
01165     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01166     int_is("P2DT8H30M", icaldurationtype_as_int(d), 203400);
01167 
01168     icalerror_errors_are_fatal = 0;
01169 
01170     /* Test conversion of bad input */
01171 
01172     d = icaldurationtype_from_int(1314000);
01173     if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d),
01174                      icaldurationtype_as_int(d));
01175     is("1314000", icaldurationtype_as_ical_string(d), "P15DT5H");
01176 
01177     d = icaldurationtype_from_string("P2W1DT5H");
01178     if (VERBOSE) printf("%s %d\n",icaldurationtype_as_ical_string(d),
01179                      icaldurationtype_as_int(d));
01180     int_is("P15DT5H", icaldurationtype_as_int(d), 0);
01181 
01182     d = icaldurationtype_from_string("P-2DT8H30M");
01183     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01184     int_is("P-2DT8H30M", icaldurationtype_as_int(d), 0);
01185 
01186     d = icaldurationtype_from_string("P7W8H");
01187     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01188     int_is("P7W8H", icaldurationtype_as_int(d), 0);
01189 
01190     d = icaldurationtype_from_string("T10H");
01191     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01192     int_is("T10H", icaldurationtype_as_int(d), 0);
01193 
01194     icalerror_errors_are_fatal = 1;
01195 
01196     d = icaldurationtype_from_int(4233600);
01197     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01198     is("P7W",
01199        icaldurationtype_as_ical_string(d), "P7W");
01200 
01201     d = icaldurationtype_from_int(4424400);
01202     if (VERBOSE) printf("%s\n",icaldurationtype_as_ical_string(d));
01203     is("P51DT5H",
01204        icaldurationtype_as_ical_string(d), "P51DT5H");
01205 }
01206 
01207 
01208 void test_period()
01209 {
01210     struct icalperiodtype p;
01211     icalvalue *v;
01212     char *str;
01213 
01214     str = "19971015T050000Z/PT8H30M";
01215     p = icalperiodtype_from_string(str);
01216     is(str, icalperiodtype_as_ical_string(p),str);
01217 
01218 
01219     str = "19971015T050000Z/19971015T060000Z";
01220     p = icalperiodtype_from_string(str);
01221     is(str, icalperiodtype_as_ical_string(p),str);
01222 
01223 
01224     str = "19970101T120000/PT3H";
01225 
01226     v = icalvalue_new_from_string(ICAL_PERIOD_VALUE,str);
01227     is(str, icalvalue_as_ical_string(v), str);
01228 
01229     icalvalue_free(v);
01230 }
01231 
01232 
01233 void test_strings(){
01234     icalvalue *v;
01235 
01236     v = icalvalue_new_text("foo;bar;bats");
01237     if (VERBOSE)
01238       printf("%s\n",icalvalue_as_ical_string(v));
01239 
01240     is("test encoding of 'foo;bar;bats'", 
01241        "foo\\;bar\\;bats", icalvalue_as_ical_string(v));
01242 
01243     icalvalue_free(v);
01244 
01245 
01246     v = icalvalue_new_text("foo\\;b\nar\\;ba\tts");
01247     if (VERBOSE)
01248       printf("%s\n",icalvalue_as_ical_string(v));
01249     
01250     is("test encoding of 'foo\\\\;b\\nar\\\\;ba\\tts'", 
01251        "foo\\\\\\;b\\nar\\\\\\;ba\\tts", icalvalue_as_ical_string(v));
01252     
01253     icalvalue_free(v);
01254 }
01255 
01256 
01257 void test_requeststat()
01258 {
01259     icalproperty *p;
01260     icalrequeststatus s;
01261     struct icalreqstattype st, st2;
01262     char temp[1024];
01263     
01264     s = icalenum_num_to_reqstat(2,1);
01265     
01266     ok("icalenum_num_to_reqstat(2,1)",(s == ICAL_2_1_FALLBACK_STATUS));
01267     
01268     ok("icalenum_reqstat_major()",(icalenum_reqstat_major(s) == 2));
01269     ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(s) == 1));
01270     
01271     is ("icalenum_reqstat_desc() -> 2.1", icalenum_reqstat_desc(s),
01272        "Success but fallback taken  on one or more property  values.");
01273     
01274     st.code = s;
01275     st.debug = "booga";
01276     st.desc = 0;
01277     
01278     is("icalreqstattype_as_string()",
01279        icalreqstattype_as_string(st), 
01280        "2.1;Success but fallback taken  on one or more property  values.;booga");
01281     
01282     st.desc = " A non-standard description";
01283     
01284     is("icalreqstattype_as_string() w/ non standard description",
01285        icalreqstattype_as_string(st),
01286        "2.1; A non-standard description;booga");
01287     
01288     st.desc = 0;
01289     
01290     sprintf(temp,"%s\n",icalreqstattype_as_string(st));
01291     
01292     
01293     st2 = icalreqstattype_from_string("2.1;Success but fallback taken  on one or more property  values.;booga");
01294     
01295     /*    printf("%d --  %d --  %s -- %s\n",*/
01296     ok("icalenum_reqstat_major()",(icalenum_reqstat_major(st2.code) == 2));
01297     ok("icalenum_reqstat_minor()",(icalenum_reqstat_minor(st2.code) == 1));
01298     is("icalenum_reqstat_desc",
01299        icalenum_reqstat_desc(st2.code),
01300        "Success but fallback taken  on one or more property  values.");
01301     
01302     st2 = icalreqstattype_from_string("2.1;Success but fallback taken  on one or more property  values.;booga");
01303     if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2));
01304     
01305     st2 = icalreqstattype_from_string("2.1;Success but fallback taken  on one or more property  values.;");
01306     if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2));
01307     
01308     st2 = icalreqstattype_from_string("2.1;Success but fallback taken  on one or more property  values.");
01309     if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2));
01310     
01311     st2 = icalreqstattype_from_string("2.1;");
01312     if (VERBOSE) printf("%s\n",icalreqstattype_as_string(st2));
01313 
01314     is("st2 test again",
01315        icalreqstattype_as_string(st2),
01316        "2.1;Success but fallback taken  on one or more property  values.");
01317     
01318     st2 = icalreqstattype_from_string("2.1");
01319     is("st2 test #3",
01320        icalreqstattype_as_string(st2),
01321        "2.1;Success but fallback taken  on one or more property  values.");
01322     
01323     p = icalproperty_new_from_string("REQUEST-STATUS:2.1;Success but fallback taken  on one or more property  values.;booga");
01324 
01325     is("icalproperty_new_from_string()",
01326        icalproperty_as_ical_string(p),
01327        "REQUEST-STATUS:2.1;Success but fallback taken  on one or more property  \n values.;booga\n");
01328 
01329     icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);
01330     st2 = icalreqstattype_from_string("16.4");
01331     
01332     ok("test unknown code", (st2.code == ICAL_UNKNOWN_STATUS));
01333     
01334     st2 = icalreqstattype_from_string("1.");
01335     
01336     ok("test malformed code", (st2.code == ICAL_UNKNOWN_STATUS));
01337     icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT);
01338 
01339     icalproperty_free(p);
01340 }
01341 
01342 
01343 void test_dtstart(){
01344     
01345     struct icaltimetype tt,tt2;
01346     
01347     icalproperty *p;
01348     
01349 
01350     tt = icaltime_from_string("19970101");
01351 
01352     int_is("19970101 is a date", tt.is_date, 1);
01353 
01354     p = icalproperty_new_dtstart(tt);
01355 
01356     if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p))));
01357 
01358     ok("ICAL_DATE_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATE_VALUE));
01359 
01360     tt2 = icalproperty_get_dtstart(p);
01361     int_is("converted date is date", tt2.is_date, 1);
01362 
01363     if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p));
01364 
01365     tt = icaltime_from_string("19970101T103000");
01366 
01367     int_is("19970101T103000 is not a date", tt.is_date, 0);
01368 
01369     icalproperty_free(p);
01370 
01371     p = icalproperty_new_dtstart(tt);
01372 
01373     if (VERBOSE) printf("%s\n",icalvalue_kind_to_string(icalvalue_isa(icalproperty_get_value(p))));
01374     ok("ICAL_DATETIME_VALUE", (icalvalue_isa(icalproperty_get_value(p))==ICAL_DATETIME_VALUE));
01375 
01376     tt2 = icalproperty_get_dtstart(p);
01377     int_is("converted datetime is not date", tt2.is_date, 0);
01378 
01379     if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p));
01380 
01381     icalproperty_free(p);
01382 }
01383 
01384 void do_test_time(char* zone)
01385 {
01386     struct icaltimetype ictt, icttutc, icttzone, icttdayl, 
01387        icttla, icttny,icttphoenix, icttlocal, icttnorm;
01388     time_t tt,tt2, tt_p200;
01389     int offset_tz;
01390     icalvalue *v;
01391     short day_of_week,start_day_of_week, day_of_year;
01392     icaltimezone *azone, *utczone;
01393     char msg[256];
01394 
01395     icalerror_errors_are_fatal = 0;
01396 
01397     azone = icaltimezone_get_builtin_timezone(zone);
01398     utczone = icaltimezone_get_utc_timezone();
01399 
01400     /* Test new API */
01401     if (VERBOSE) printf("\n---> From time_t \n");
01402 
01403     tt = 1025127869;        /* stick with a constant... */
01404 
01405     if (VERBOSE) printf("Orig        : %s\n",ical_timet_string(tt));
01406     if (VERBOSE) printf("\nicaltime_from_timet(tt,0) (DEPRECATED)\n");
01407 
01408     ictt = icaltime_from_timet(tt, 0);
01409 
01410     is("icaltime_from_timet(1025127869) as UTC", ictt_as_string(ictt),
01411        "2002-06-26 21:44:29 (floating)");
01412 
01413     ictt = icaltime_from_timet_with_zone(tt, 0, NULL);
01414     is("Floating time from time_t",
01415        ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)");
01416 
01417     ictt = icaltime_from_timet_with_zone(tt, 0, azone);
01418     ok("icaltime_from_timet_with_zone(tt,0,zone) as zone", 
01419        strncmp(ictt_as_string(ictt), "2002-06-26 21:44:29", 19)==0);
01420 
01421     ictt = icaltime_from_timet_with_zone(tt, 0, utczone);
01422 
01423     is("icaltime_from_timet_with_zone(tt,0,utc)", ictt_as_string(ictt),
01424        "2002-06-26 21:44:29 Z UTC");
01425 
01426     if (VERBOSE) printf("\n---> Convert from floating \n");
01427 
01428     ictt = icaltime_from_timet_with_zone(tt, 0, NULL);
01429     icttutc = icaltime_convert_to_zone(ictt, utczone);
01430 
01431     is("Convert from floating to UTC",
01432        ictt_as_string(icttutc),
01433        "2002-06-26 21:44:29 Z UTC");
01434           
01435     icttzone = icaltime_convert_to_zone(ictt, azone);
01436 
01437     ok("Convert from floating to zone",
01438        (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 19)==0));
01439 
01440     tt2 = icaltime_as_timet(icttzone);
01441 
01442     if (VERBOSE) printf("\n---> Convert from UTC \n");
01443 
01444     ictt = icaltime_from_timet_with_zone(tt, 0, utczone);
01445     icttutc = icaltime_convert_to_zone(ictt, utczone);
01446 
01447     is("Convert from UTC to UTC",
01448        ictt_as_string(icttutc),
01449        "2002-06-26 21:44:29 Z UTC");
01450 
01451     icttzone = icaltime_convert_to_zone(ictt, azone);
01452 
01453     ok("Convert from UTC to zone (test year/mon only..)",
01454        (strncmp(ictt_as_string(icttzone), "2002-06-26 21:44:29", 7)==0));
01455 
01456     tt2 = icaltime_as_timet(icttzone);
01457 
01458     if (VERBOSE) printf("No conversion: %s\n", ical_timet_string(tt2));
01459 
01460     ok("No conversion at all (test year/mon only)",
01461        (strncmp(ical_timet_string(tt2), "2002-06-26 21:44:29 Z",7) == 0));
01462 
01463     tt2 = icaltime_as_timet_with_zone(icttzone, utczone);
01464     if (VERBOSE) printf("Back to UTC  : %s\n", ical_timet_string(tt2));
01465 
01466     ok("test time conversion routines",(tt==tt2));
01467 
01468     if (VERBOSE) printf("\n---> Convert from zone \n");
01469     ictt = icaltime_from_timet_with_zone(tt, 0, azone);
01470     icttzone = icaltime_convert_to_zone(ictt, azone);
01471 
01472     if (VERBOSE)
01473     printf("To zone      : %s\n", ictt_as_string(icttzone));
01474     icttutc = icaltime_convert_to_zone(ictt, utczone);
01475 
01476     if (VERBOSE)
01477     printf("To UTC      : %s\n", ictt_as_string(icttutc));
01478     tt2 = icaltime_as_timet(icttutc);
01479 
01480     if (VERBOSE)
01481     printf("No conversion: %s\n", ical_timet_string(tt2));
01482 
01483     tt2 = icaltime_as_timet_with_zone(icttutc, azone);
01484 
01485     if (VERBOSE)
01486     printf("Back to zone  : %s\n", ical_timet_string(tt2));
01487 
01488     ok("test time conversion, round 2", (tt==tt2));
01489 
01490     ictt = icaltime_from_string("20001103T183030Z");
01491 
01492     tt = icaltime_as_timet(ictt);
01493 
01494     ok("test icaltime -> time_t for 20001103T183030Z", (tt==973276230)); 
01495     /* Fri Nov  3 10:30:30 PST 2000 in PST 
01496        Fri Nov  3 18:30:30 PST 2000 in UTC */
01497     
01498     if (VERBOSE) {
01499     printf(" Normalize \n");
01500     printf("Orig (ical) : %s\n", ictt_as_string(ictt));
01501     }
01502     icttnorm = ictt;
01503     icttnorm.second -= 60 * 60 * 24 * 5;
01504     icttnorm = icaltime_normalize(icttnorm);
01505 
01506     if (VERBOSE) 
01507       printf("-5d in sec  : %s\n", ictt_as_string(icttnorm));
01508     icttnorm.day += 60;
01509     icttnorm = icaltime_normalize(icttnorm);
01510 
01511     if (VERBOSE) 
01512       printf("+60 d       : %s\n", ictt_as_string(icttnorm));
01513 
01516     if (VERBOSE) 
01517     printf("\n As time_t \n");
01518 
01519     tt2 = icaltime_as_timet(ictt);
01520 
01521     if (VERBOSE) {
01522       printf("20001103T183030Z (timet): %s\n",ical_timet_string(tt2));
01523       printf("20001103T183030Z        : %s\n",ictt_as_string(ictt));
01524     }
01525 
01527     ok("test normalization", (tt2 == tt));
01528 
01529     icttlocal = icaltime_convert_to_zone(ictt, azone);
01530     tt2 = icaltime_as_timet(icttlocal);
01531     if (VERBOSE) {
01532       printf("20001103T183030  (timet): %s\n",ical_timet_string(tt2));
01533       printf("20001103T183030         : %s\n",ictt_as_string(icttlocal));
01534     }
01535 
01536     offset_tz = -icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0); /* FIXME */
01537     if (VERBOSE)
01538       printf("offset_tz               : %d\n",offset_tz);
01539 
01540     ok("test utc offset", (tt-tt2 == offset_tz));
01541 
01542     /* FIXME with the new API, it's not very useful */
01543     icttlocal = ictt;
01544     icaltimezone_convert_time(&icttlocal,
01545        icaltimezone_get_utc_timezone(),
01546        icaltimezone_get_builtin_timezone(zone));
01547 
01548     if (VERBOSE)
01549       printf("As local    : %s\n", ictt_as_string(icttlocal));
01550 
01551     if (VERBOSE) printf("\n Convert to and from lib c \n");
01552 
01553     if (VERBOSE) printf("System time is: %s\n",ical_timet_string(tt));
01554 
01555     v = icalvalue_new_datetime(ictt);
01556 
01557     if (VERBOSE) 
01558       printf("System time from libical: %s\n",icalvalue_as_ical_string(v));
01559 
01560     icalvalue_free(v);
01561 
01562     tt2 = icaltime_as_timet(ictt);
01563 
01564     if (VERBOSE)
01565     printf("Converted back to libc: %s\n",ical_timet_string(tt2));
01566     
01567     if (VERBOSE) printf("\n Incrementing time  \n");
01568 
01569     icttnorm = ictt;
01570 
01571     icttnorm.year++;
01572     tt2 = icaltime_as_timet(icttnorm);
01573     if (VERBOSE)
01574     printf("Add a year: %s\n",ical_timet_string(tt2));
01575 
01576     icttnorm.month+=13;
01577     tt2 = icaltime_as_timet(icttnorm);
01578     if (VERBOSE)
01579     printf("Add 13 months: %s\n",ical_timet_string(tt2));
01580 
01581     icttnorm.second+=90;
01582     tt2 = icaltime_as_timet(icttnorm);
01583     if (VERBOSE)
01584     printf("Add 90 seconds: %s\n",ical_timet_string(tt2));
01585 
01586     if (VERBOSE) printf("\n Day Of week \n");
01587 
01588     day_of_week = icaltime_day_of_week(ictt);
01589     start_day_of_week = icaltime_start_doy_of_week(ictt);
01590     day_of_year = icaltime_day_of_year(ictt);
01591 
01592     sprintf(msg, "Testing day of week %d", day_of_week);
01593     int_is(msg, day_of_week, 6);
01594 
01595     sprintf(msg, "Testing day of year %d",day_of_year);
01596     int_is(msg, day_of_year, 308);
01597 
01598     sprintf(msg, "Week started on doy of %d", start_day_of_week);
01599     int_is(msg, start_day_of_week , 303);
01600 
01601     if (VERBOSE) printf("\n TimeZone Conversions \n");
01602 
01603 /*
01604     icttla = ictt;
01605     icaltimezone_convert_time(&icttla,
01606                            icaltimezone_get_utc_timezone(),
01607                            lazone);
01608 */
01609     icttla = icaltime_convert_to_zone(ictt,
01610        icaltimezone_get_builtin_timezone("America/Los_Angeles"));
01611 
01612     int_is("Converted hour in America/Los_Angeles is 10", icttla.hour, 10);
01613 
01614     icttutc = icaltime_convert_to_zone(icttla,icaltimezone_get_utc_timezone());
01615 
01616     ok("America/Los_Angeles local time is 2000-11-03 10:30:30",
01617        (strncmp(ictt_as_string(icttla), "2000-11-03 10:30:30", 19)==0));
01618 
01619     ok("Test conversion back to UTC",(icaltime_compare(icttutc, ictt) == 0)); 
01620 
01621     icttny  = icaltime_convert_to_zone(ictt,
01622        icaltimezone_get_builtin_timezone("America/New_York"));
01623 
01624     icttphoenix = icaltime_convert_to_zone(ictt,
01625        icaltimezone_get_builtin_timezone("America/Phoenix"));
01626 
01627     if (VERBOSE) {
01628     printf("Orig (ctime): %s\n", ical_timet_string(tt) );
01629     printf("Orig (ical) : %s\n", ictt_as_string(ictt));
01630     printf("UTC         : %s\n", ictt_as_string(icttutc));
01631     printf("Los Angeles : %s\n", ictt_as_string(icttla));
01632     printf("Phoenix     : %s\n", ictt_as_string(icttphoenix));
01633     printf("New York    : %s\n", ictt_as_string(icttny));
01634     }
01637     /* Daylight savings test for New York */
01638     if (VERBOSE) {
01639     printf("\n Daylight Savings \n");
01640 
01641     printf("Orig (ctime): %s\n", ical_timet_string(tt) );
01642     printf("Orig (ical) : %s\n", ictt_as_string(ictt));
01643     printf("NY          : %s\n", ictt_as_string(icttny));
01644     }
01645 
01646     ok("Converted time in zone America/New_York is 2000-11-03 13:30:30",
01647        (strncmp(ictt_as_string(icttny),"2000-11-03 13:30:30",19)==0));
01648 
01649     tt_p200 = tt +  200 * 24 * 60 * 60 ; /* Add 200 days */
01650 
01651     icttdayl = icaltime_from_timet_with_zone(tt_p200,0,
01652        icaltimezone_get_utc_timezone());
01653     icttny = icaltime_convert_to_zone(icttdayl,
01654        icaltimezone_get_builtin_timezone("America/New_York"));
01655 
01656     if (VERBOSE) {
01657     printf("Orig +200d  : %s\n", ical_timet_string(tt_p200) );
01658     printf("NY+200D     : %s\n", ictt_as_string(icttny));
01659     }
01660 
01661     ok("Converted time +200d in zone America/New_York is 2001-05-22 14:30:30",
01662        (strncmp(ictt_as_string(icttny),"2001-05-22 14:30:30",19)==0));
01663 
01664 
01665     /* Daylight savings test for Los Angeles */
01666 
01667     icttla = icaltime_convert_to_zone(ictt,
01668        icaltimezone_get_builtin_timezone("America/Los_Angeles"));
01669 
01670     if (VERBOSE) {
01671     printf("\nOrig (ctime): %s\n", ical_timet_string(tt) );
01672     printf("Orig (ical) : %s\n", ictt_as_string(ictt));
01673     printf("LA          : %s\n", ictt_as_string(icttla));
01674     }
01675 
01676     ok("Converted time in zone America/Los_Angeles is 2000-11-03 10:30:30",
01677        (strncmp(ictt_as_string(icttla),"2000-11-03 10:30:30",19)==0));
01678 
01679     
01680     icttla = icaltime_convert_to_zone(icttdayl,
01681        icaltimezone_get_builtin_timezone("America/Los_Angeles"));
01682 
01683     if (VERBOSE) {
01684     printf("Orig +200d  : %s\n", ical_timet_string(tt_p200) );
01685     printf("LA+200D     : %s\n", ictt_as_string(icttla));
01686     }
01687 
01688     ok("Converted time +200d in zone America/Los_Angeles is 2001-05-22 11:30:30",
01689        (strncmp(ictt_as_string(icttla),"2001-05-22 11:30:30",19)==0));
01690 
01691 
01692     icalerror_errors_are_fatal = 1;
01693 }
01694 
01695 void test_iterators()
01696 {
01697     icalcomponent *c,*inner,*next;
01698     icalcompiter i;
01699     char vevent_list[64] = "";
01700     char remaining_list[64] = "";
01701 
01702     char *vevent_list_good = "12347";
01703     char *remaining_list_good = "568910";
01704 
01705     int nomore = 1;
01706     
01707     c= icalcomponent_vanew(
01708        ICAL_VCALENDAR_COMPONENT,
01709        icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
01710                          icalproperty_new_version("1"),0),
01711        icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
01712                          icalproperty_new_version("2"),0),
01713        icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
01714                          icalproperty_new_version("3"),0),
01715        icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
01716                          icalproperty_new_version("4"),0),
01717        icalcomponent_vanew(ICAL_VTODO_COMPONENT,
01718                          icalproperty_new_version("5"),0),
01719        icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT,
01720                          icalproperty_new_version("6"),0),
01721        icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
01722                          icalproperty_new_version("7"),0),
01723        icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT,
01724                          icalproperty_new_version("8"),0),
01725        icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT,
01726                          icalproperty_new_version("9"),0),
01727        icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT,
01728                          icalproperty_new_version("10"),0),
01729        0);
01730    
01731     /* List all of the VEVENTS */
01732 
01733     for(i = icalcomponent_begin_component(c,ICAL_VEVENT_COMPONENT);
01734        icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){
01735        
01736        icalcomponent *this = icalcompiter_deref(&i);
01737 
01738        icalproperty *p = 
01739            icalcomponent_get_first_property(this,
01740                                         ICAL_VERSION_PROPERTY);
01741        const char* s = icalproperty_get_version(p);
01742 
01743        strcat(vevent_list, s);
01744     }
01745     is("iterate through VEVENTS in a component", 
01746        vevent_list, vevent_list_good);
01747 
01748     /* Delete all of the VEVENTS */
01749     /* reset iterator */
01750     icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT);
01751 
01752     while((inner=icalcomponent_get_current_component(c)) != 0 ){
01753        if(icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT){
01754            icalcomponent_remove_component(c,inner);
01755               icalcomponent_free(inner);
01756        } else {
01757            icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT);
01758        }
01759     }
01760 
01761     /* List all remaining components */
01762     for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); 
01763        inner != 0; 
01764        inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){
01765        
01766 
01767        icalproperty *p = 
01768            icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY);
01769 
01770        const char* s = icalproperty_get_version(p);     
01771 
01772        strcat(remaining_list, s);
01773     }
01774 
01775     is("iterate through remaining components", 
01776        remaining_list, remaining_list_good);
01777 
01778     
01779     /* Remove all remaining components */
01780     for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); 
01781        inner != 0; 
01782        inner = next){
01783 
01784        icalcomponent *this;
01785        icalproperty *p;
01786        const char* s;
01787        next = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT);
01788 
01789        p=icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY);
01790        s = icalproperty_get_version(p);   
01791 
01792        icalcomponent_remove_component(c,inner);
01793 
01794        this = icalcomponent_get_current_component(c);
01795 
01796        if(this != 0){
01797            p=icalcomponent_get_first_property(this,ICAL_VERSION_PROPERTY);
01798            s = icalproperty_get_version(p);      
01799        }
01800 
01801        icalcomponent_free(inner);
01802     }
01803 
01804 
01805     /* List all remaining components */
01806     for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); 
01807        inner != 0; 
01808        inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){
01809        
01810        icalproperty *p = 
01811            icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY);
01812 
01813        const char* s = icalproperty_get_version(p);     
01814 
01815        if (s)
01816          nomore = 0;
01817     }
01818 
01819     ok("test if any components remain after deleting the rest", 
01820        nomore == 1);
01821     
01822        icalcomponent_free(c);
01823 }
01824 
01825 
01826 void test_time()
01827 {
01828     char  *zones[6] = { "America/Los_Angeles","America/New_York","Europe/London","Asia/Shanghai", NULL};
01829     
01830     int i;
01831 
01832     do_test_time(0);
01833 
01834     for(i = 0; zones[i] != NULL; i++){
01835 
01836       if (VERBOSE) printf(" ######### Timezone: %s ############\n",zones[i]);
01837         
01838        do_test_time(zones[i]);
01839 
01840     } 
01841 
01842 }
01843 
01844 
01845 void test_icalset()
01846 {
01847     icalcomponent *c; 
01848 
01849     icalset* f = icalset_new_file("2446.ics");
01850     icalset* d = icalset_new_dir("outdir");
01851 
01852     assert(f!=0);
01853     assert(d!=0);
01854 
01855     for(c = icalset_get_first_component(f);
01856        c != 0;
01857        c = icalset_get_next_component(f)){
01858 
01859        icalcomponent *clone; 
01860 
01861        clone = icalcomponent_new_clone(c);
01862 
01863        icalset_add_component(d,clone);
01864 
01865        printf(" class %d\n",icalclassify(c,0,"user"));
01866 
01867     }
01868 
01869        icalset_free(f);
01870        icalset_free(d);
01871 }
01872 
01873 
01874 icalcomponent* icalclassify_find_overlaps(icalset* set, icalcomponent* comp);
01875 
01876 void test_overlaps()
01877 {
01878     icalcomponent *cset,*c;
01879     icalset *set;
01880     time_t tm1 = 973378800; /*Sat Nov  4 23:00:00 UTC 2000,
01881                            Sat Nov  4 15:00:00 PST 2000 */
01882     time_t tm2 = 973382400; /*Sat Nov  5 00:00:00 UTC 2000 
01883                            Sat Nov  4 16:00:00 PST 2000 */
01884 
01885     time_t hh = 1800; /* one half hour */
01886 
01887     set = icalset_new_file("../../test-data/overlaps.ics");
01888 
01889     c = icalcomponent_vanew(
01890        ICAL_VEVENT_COMPONENT,
01891        icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0),
01892        icalproperty_vanew_dtend(icaltime_from_timet(tm2-hh,0),0),
01893        0
01894        );
01895 
01896     cset =  icalclassify_find_overlaps(set,c);
01897     ok("TODO find overlaps 1", (cset != NULL));
01898 
01899     if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset));
01900 
01901     if (cset) icalcomponent_free(cset);
01902     if (c)    icalcomponent_free(c);
01903 
01904 
01905     c = icalcomponent_vanew(
01906        ICAL_VEVENT_COMPONENT,
01907        icalproperty_vanew_dtstart(icaltime_from_timet(tm1-hh,0),0),
01908        icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0),
01909        0
01910        );
01911 
01912     cset =  icalclassify_find_overlaps(set,c);
01913 
01914     ok("TODO find overlaps 1", cset != NULL);
01915     if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset));
01916 
01917     if (cset) icalcomponent_free(cset);
01918     if (c)    icalcomponent_free(c);
01919 
01920     c = icalcomponent_vanew(
01921        ICAL_VEVENT_COMPONENT,
01922        icalproperty_vanew_dtstart(icaltime_from_timet(tm1+5*hh,0),0),
01923        icalproperty_vanew_dtend(icaltime_from_timet(tm2+5*hh,0),0),
01924        0
01925        );
01926 
01927     cset =  icalclassify_find_overlaps(set,c);
01928     ok("TODO find overlaps 1", cset != NULL);
01929     if (VERBOSE && cset) printf("%s\n",icalcomponent_as_ical_string(cset));
01930 
01931     if (set)  icalset_free(set);
01932     if (cset) icalcomponent_free(cset);
01933     if (c)    icalcomponent_free(c);
01934 }
01935 
01936 
01937 
01938 void test_fblist()
01939 {
01940     icalspanlist *sl, *new_sl;
01941     icalset* set = icalset_new_file("../../test-data/spanlist.ics");
01942     struct icalperiodtype period;
01943     icalcomponent *comp;
01944     int * foo;
01945     int i;
01946 
01947     sl = icalspanlist_new(set,
01948                    icaltime_from_string("19980101T000000Z"),
01949                    icaltime_from_string("19980108T000000Z"));
01950               
01951     ok("open ../../test-data/spanlist.ics", (set!=NULL));
01952     assert(set!=NULL);
01953 
01954     if (VERBOSE) printf("Restricted spanlist\n");
01955     if (VERBOSE) icalspanlist_dump(sl);
01956 
01957     period= icalspanlist_next_free_time(sl,
01958                   icaltime_from_string("19970801T120000"));
01959 
01960     is("Next Free time start 19970801T120000", icaltime_as_ical_string(period.start), "19970801T120000");
01961     is("Next Free time end   19980101T000000", icaltime_as_ical_string(period.end), "19980101T000000");
01962 
01963     period= icalspanlist_next_free_time(sl, period.end);
01964 
01965     is("Next Free time start 19980101T010000", icaltime_as_ical_string(period.start), "19980101T010000");
01966     is("Next Free time end   19980102T010000", icaltime_as_ical_string(period.end), "19980102T010000");
01967  
01968     if (VERBOSE) printf("%s\n",
01969           icalcomponent_as_ical_string(icalspanlist_as_vfreebusy(sl,
01970                                                           "a@foo.com",
01971                                                           "b@foo.com")
01972                                    ));
01973 
01974     foo = icalspanlist_as_freebusy_matrix(sl,3600);
01975     
01976     for (i=0; foo[i] != -1; i++); /* find number entries */
01977 
01978     int_is("Calculating freebusy hourly matrix", i, (7*24));
01979 
01980     if (VERBOSE) {
01981       for (i=0; foo[i] != -1; i++) {
01982        printf("%d", foo[i]);
01983        if ((i % 24) == 23)
01984          printf("\n");
01985       }
01986       printf("\n\n");
01987     }
01988 
01989 
01990     free(foo);
01991 
01992     foo = icalspanlist_as_freebusy_matrix(sl,3600*24);
01993 
01994     ok("Calculating daily freebusy matrix", (foo!=NULL));
01995 
01996     {
01997       char out_str[80] = "";
01998       char *strp = out_str;
01999 
02000       for (i=0; foo[i]!=-1; i++){
02001        sprintf(strp, "%d", foo[i]);
02002        strp++;
02003       }
02004       is("Checking freebusy validity", out_str, "1121110");
02005     }
02006     if (VERBOSE) {
02007       for (i=0; foo[i] != -1; i++) {
02008        printf("%d", foo[i]);
02009        if ((i % 7) == 6)
02010          printf("\n");
02011       }
02012       printf("\n\n");
02013     }
02014     free(foo);
02015 
02016     icalspanlist_free(sl);
02017 
02018 
02019     if (VERBOSE) printf("Unrestricted spanlist\n");
02020 
02021     sl = icalspanlist_new(set,
02022                        icaltime_from_string("19970324T120000Z"),
02023                        icaltime_null_time());
02024 
02025     ok("add 19970324T120000Z to spanlist", (sl!=NULL));
02026 
02027     if (VERBOSE) printf("Restricted spanlist\n");
02028     if (VERBOSE) icalspanlist_dump(sl);
02029 
02030     period= icalspanlist_next_free_time(sl,
02031                                   icaltime_from_string("19970801T120000Z"));
02032 
02033 
02034     is("Next Free time start 19980101T010000", 
02035        icaltime_as_ical_string(period.start),
02036        "19980101T010000");
02037 
02038     is("Next Free time end   19980102T010000", 
02039        icaltime_as_ical_string(period.end), 
02040        "19980102T010000");
02041 
02042     comp = icalspanlist_as_vfreebusy(sl, "a@foo.com", "b@foo.com");
02043 
02044     ok("Calculating VFREEBUSY component", (comp != NULL));
02045     if (VERBOSE) printf("%s\n", icalcomponent_as_ical_string(comp));
02046 
02047     new_sl = icalspanlist_from_vfreebusy(comp);
02048 
02049     ok("Calculating spanlist from generated VFREEBUSY component", 
02050        (new_sl != NULL));
02051 
02052     if (VERBOSE) icalspanlist_dump(new_sl);
02053 
02054     if (sl) icalspanlist_free(sl);
02055     if (new_sl) icalspanlist_free(new_sl);
02056     if (comp) icalcomponent_free(comp);
02057 
02058     icalset_free(set);
02059 }
02060 
02061 
02062 void test_convenience(){
02063     icalcomponent *c;
02064     int duration;
02065     struct icaltimetype tt;
02066 
02067     c = icalcomponent_vanew(
02068        ICAL_VCALENDAR_COMPONENT,
02069        icalcomponent_vanew(
02070            ICAL_VEVENT_COMPONENT,
02071            icalproperty_new_dtstart(icaltime_from_string("19970801T120000")),
02072            icalproperty_new_dtend(icaltime_from_string("19970801T130000")),
02073            0
02074            ),
02075        0);
02076 
02077     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02078 
02079     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02080 
02081     is("Start is 1997-08-01 12:00:00 (floating)",
02082        ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 (floating)");
02083     is("End is 1997-08-01 13:00:00 (floating)",
02084        ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:00:00 (floating)");
02085     ok("Duration is 60 m", (duration == 60));
02086 
02087     icalcomponent_free(c);
02088 
02089     c = icalcomponent_vanew(
02090        ICAL_VCALENDAR_COMPONENT,
02091        icalcomponent_vanew(
02092            ICAL_VEVENT_COMPONENT,
02093            icalproperty_new_dtstart(icaltime_from_string("19970801T120000Z")),
02094            icalproperty_new_duration(icaldurationtype_from_string("PT1H30M")),
02095            0
02096            ),
02097        0);
02098 
02099     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02100 
02101     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02102 
02103     is("Start is 1997-08-01 12:00:00 Z UTC",
02104        ictt_as_string(icalcomponent_get_dtstart(c)), "1997-08-01 12:00:00 Z UTC");
02105     is("End is 1997-08-01 13:30:00 Z UTC",
02106        ictt_as_string(icalcomponent_get_dtend(c)), "1997-08-01 13:30:00 Z UTC");
02107     ok("Duration is 90 m", (duration == 90));
02108 
02109     icalcomponent_free(c);
02110 
02111     icalerror_errors_are_fatal = 0;
02112 
02113     c = icalcomponent_vanew(
02114        ICAL_VCALENDAR_COMPONENT,
02115        icalcomponent_vanew(
02116            ICAL_VEVENT_COMPONENT,
02117            icalproperty_new_dtstart(icaltime_from_string("19970801T120000")),
02118            icalproperty_new_dtend(icaltime_from_string("19970801T130000")),
02119            0
02120            ),
02121        0);
02122 
02123     icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M"));
02124 
02125     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02126 
02127     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02128 
02129     is("Start is 1997-08-01 12:00:00 (floating)",
02130        ictt_as_string(icalcomponent_get_dtstart(c)),
02131        "1997-08-01 12:00:00 (floating)");
02132     is("End is 1997-08-01 13:00:00 (floating)",
02133        ictt_as_string(icalcomponent_get_dtend(c)),
02134        "1997-08-01 13:00:00 (floating)");
02135     ok("Duration is 60 m", (duration == 60));
02136 
02137     icalcomponent_free(c);
02138 
02139     c = icalcomponent_vanew(
02140        ICAL_VCALENDAR_COMPONENT,
02141        icalcomponent_vanew(
02142            ICAL_VEVENT_COMPONENT,
02143            icalproperty_new_dtstart(icaltime_from_string("19970801T120000Z")),
02144            icalproperty_new_duration(icaldurationtype_from_string("PT1H30M")),
02145            0
02146            ),
02147        0);
02148 
02149     icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z"));
02150 
02151     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02152 
02153 
02154     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02155 
02156     ok("Start is 1997-08-01 12:00:00 Z UTC",
02157        (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c)))));
02158     ok("End is 1997-08-01 13:30:00 Z UTC",
02159        (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c)))));
02160     ok("Duration is 90 m", (duration == 90));
02161 
02162     icalerror_errors_are_fatal = 1;
02163 
02164     icalcomponent_free(c);
02165 
02166     c = icalcomponent_vanew(
02167        ICAL_VCALENDAR_COMPONENT,
02168        icalcomponent_vanew(
02169            ICAL_VEVENT_COMPONENT,
02170            0
02171            ),
02172        0);
02173 
02174     icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z"));
02175     icalcomponent_set_dtend(c,icaltime_from_string("19970801T133000Z"));
02176 
02177     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02178 
02179 
02180     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02181 
02182     ok("Start is 1997-08-01 12:00:00 Z UTC",
02183        (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c)))));
02184     ok("End is 1997-08-01 13:30:00 Z UTC",
02185        (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c)))));
02186     ok("Duration is 90 m", (duration == 90));
02187 
02188     icalcomponent_free(c);
02189 
02190     c = icalcomponent_vanew(
02191        ICAL_VCALENDAR_COMPONENT,
02192        icalcomponent_vanew(
02193            ICAL_VEVENT_COMPONENT,
02194            0
02195            ),
02196        0);
02197 
02198 
02199     icalcomponent_set_dtstart(c,icaltime_from_string("19970801T120000Z"));
02200     icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M"));
02201 
02202     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02203 
02204 
02205     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02206 
02207     ok("Start is 1997-08-01 12:00:00 Z UTC",
02208        (0 == strcmp("1997-08-01 12:00:00 Z UTC", ictt_as_string(icalcomponent_get_dtstart(c)))));
02209     ok("End is 1997-08-01 13:30:00 Z UTC",
02210        (0 == strcmp("1997-08-01 13:30:00 Z UTC", ictt_as_string(icalcomponent_get_dtend(c)))));
02211     ok("Duration is 90 m", (duration == 90));
02212 
02213     icalcomponent_free(c);
02214 
02215     c = icalcomponent_vanew(
02216        ICAL_VCALENDAR_COMPONENT,
02217        icalcomponent_vanew(
02218            ICAL_VEVENT_COMPONENT,
02219            0
02220            ),
02221     0);
02222 
02223     tt = icaltime_from_string("19970801T120000");
02224     icaltime_set_timezone(&tt,
02225        icaltimezone_get_builtin_timezone("Europe/Rome"));
02226     icalcomponent_set_dtstart(c,tt);
02227 
02228     if (VERBOSE) printf("\n%s\n", icalcomponent_as_ical_string(c));
02229 
02230     icalcomponent_set_duration(c,icaldurationtype_from_string("PT1H30M"));
02231     duration = icaldurationtype_as_int(icalcomponent_get_duration(c))/60;
02232 
02233     ok("Start is 1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome",
02234        (0 == strcmp("1997-08-01 12:00:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtstart(c)))));
02235     ok("End is 1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome",
02236        (0 == strcmp("1997-08-01 13:30:00 /softwarestudio.org/Olson_20010626_2/Europe/Rome", ictt_as_string(icalcomponent_get_dtend(c)))));
02237     ok("Duration is 90 m", (duration == 90));
02238 
02239     icalcomponent_free(c);
02240 }
02241 
02242 void test_time_parser()
02243 {
02244     struct icaltimetype tt;
02245 
02246     icalerror_errors_are_fatal = 0;
02247 
02248     tt = icaltime_from_string("19970101T1000");
02249     ok("19970101T1000 is null time", icaltime_is_null_time(tt));
02250 
02251     tt = icaltime_from_string("19970101X100000");
02252     ok("19970101X100000 is null time", icaltime_is_null_time(tt));
02253 
02254     tt = icaltime_from_string("19970101T100000");
02255     ok("19970101T100000 is valid", !icaltime_is_null_time(tt));
02256 
02257     if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt));
02258 
02259     tt = icaltime_from_string("19970101T100000Z");
02260 
02261     ok("19970101T100000Z is valid" , !icaltime_is_null_time(tt));
02262     if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt));
02263 
02264     tt = icaltime_from_string("19970101");
02265     ok("19970101 is valid", (!icaltime_is_null_time(tt)));
02266 
02267     if (VERBOSE) printf("%s\n",icaltime_as_ctime(tt));
02268 
02269     icalerror_errors_are_fatal = 1;
02270 }
02271 
02272 void test_recur_parser()
02273 {
02274   struct icalrecurrencetype rt; 
02275   char *str;
02276 
02277   str = "FREQ=YEARLY;UNTIL=20000131T090000Z;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8";
02278   rt = icalrecurrencetype_from_string(str);
02279   is(str, icalrecurrencetype_as_string(&rt), str);
02280 
02281   str = "FREQ=DAILY;COUNT=3;INTERVAL=1;BYDAY=-1TU,3WE,-4FR,SA,SU;BYYEARDAY=34,65,76,78;BYMONTH=1,2,3,4,8";
02282   
02283   rt = icalrecurrencetype_from_string(str);
02284   is(str, icalrecurrencetype_as_string(&rt), str);
02285 }
02286 
02287 char* ical_strstr(const char *haystack, const char *needle){
02288     return strstr(haystack,needle);
02289 }
02290 
02291 void test_start_of_week()
02292 {
02293     struct icaltimetype tt2;
02294     struct icaltimetype tt1 = icaltime_from_string("19900110");
02295     int dow, doy,start_dow;
02296 
02297     do{
02298         tt1 = icaltime_normalize(tt1);
02299 
02300         doy = icaltime_start_doy_of_week(tt1);
02301         dow = icaltime_day_of_week(tt1);
02302 
02303         tt2 = icaltime_from_day_of_year(doy,tt1.year);
02304         start_dow = icaltime_day_of_week(tt2);
02305 
02306         if(doy == 1){
02307          char msg[128];
02308          sprintf(msg, "%s", ictt_as_string(tt1));
02309          int_is(msg, start_dow, 1);
02310         }
02311 
02312         if(start_dow != 1){ /* Sunday is 1 */
02313             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);
02314         }
02315 
02316 
02317         assert(start_dow == 1);
02318 
02319 
02320         tt1.day+=1;
02321         
02322     } while(tt1.year < 2010);
02323 }
02324 
02325 void test_doy()
02326 {
02327     struct icaltimetype tt1, tt2;
02328     short doy,doy2;
02329     char msg[128];
02330 
02331     doy = -1;
02332 
02333     tt1 = icaltime_from_string("19900101");
02334 
02335     if (VERBOSE) printf("Test icaltime_day_of_year() agreement with mktime\n");
02336 
02337     do{
02338         struct tm stm;
02339 
02340         tt1 = icaltime_normalize(tt1);
02341 
02342         stm.tm_sec = tt1.second;
02343         stm.tm_min = tt1.minute;
02344         stm.tm_hour = tt1.hour;
02345         stm.tm_mday = tt1.day;
02346         stm.tm_mon = tt1.month-1;
02347         stm.tm_year = tt1.year-1900;
02348         stm.tm_isdst = -1;
02349 
02350         mktime(&stm);
02351 
02352         doy = icaltime_day_of_year(tt1);
02353 
02354         doy2 = stm.tm_yday+1;
02355 
02356        if (doy == 1) {
02358          sprintf(msg, "Year %d - mktime() compare", tt1.year);
02359          int_is(msg, doy,doy2);
02360        }
02361 
02362         if (doy != doy2){
02363          printf("Failed for %s (%d,%d)\n",ictt_as_string(tt1),doy,doy2);
02364         }
02365        assert(doy == doy2);
02366 
02367         tt1.day+=1;
02368         
02369     } while(tt1.year < 2010);
02370     
02371     if (VERBOSE) printf("\nTest icaltime_day_of_year() agreement with icaltime_from_day_of_year()\n");
02372 
02373     tt1 = icaltime_from_string("19900101");
02374 
02375     do{      
02376         if(doy == 1){
02378          sprintf(msg, "Year %d - icaltime_day_of_year() compare", tt1.year);
02379          int_is(msg, doy,doy2);
02380         }
02381 
02382         doy = icaltime_day_of_year(tt1);
02383         tt2 = icaltime_from_day_of_year(doy,tt1.year);
02384         doy2 = icaltime_day_of_year(tt2);
02385 
02386         assert(doy2 == doy);
02387         assert(icaltime_compare(tt1,tt2) == 0);
02388 
02389         tt1.day+=1;
02390         tt1 = icaltime_normalize(tt1);
02391         
02392     } while(tt1.year < 2010);
02393 
02394 
02395     tt1 = icaltime_from_string("19950301");
02396     doy = icaltime_day_of_year(tt1);
02397     tt2 = icaltime_from_day_of_year(doy,1995);
02398     if(VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2));
02399 
02400     ok("test 19950301", (tt2.day == 1 && tt2.month == 3));
02401     ok("day of year == 60", (doy == 60));
02402 
02403     tt1 = icaltime_from_string("19960301");
02404     doy = icaltime_day_of_year(tt1);
02405     tt2 = icaltime_from_day_of_year(doy,1996);
02406     if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2));
02407     ok("test 19960301", (tt2.day == 1 && tt2.month == 3));
02408     ok("day of year == 61", (doy == 61));
02409 
02410     tt1 = icaltime_from_string("19970301");
02411     doy = icaltime_day_of_year(tt1);
02412     tt2 = icaltime_from_day_of_year(doy,1997);
02413     if (VERBOSE) printf("%d %s %s\n",doy, icaltime_as_ctime(tt1),icaltime_as_ctime(tt2));
02414 
02415     ok("test 19970301", (tt2.day == 1 && tt2.month == 3));
02416     ok("day of year == 60", (doy == 60));
02417 
02418 }
02419 
02420 void test_x(){
02421 
02422 #ifdef HAVE_CONFIG_H
02423 #include <config.h>
02424 #endif
02425  
02426 #include <stdio.h>
02427 #include <stdlib.h>
02428 #include <ical.h>
02429  
02430     static const char test_icalcomp_str[] =
02431 "BEGIN:VEVENT\r\n"
02432 "RRULE\r\n"
02433 " ;X-EVOLUTION-ENDDATE=20030209T081500\r\n"
02434 " :FREQ=DAILY;COUNT=10;INTERVAL=6\r\n"
02435 "X-COMMENT;X-FOO=BAR: Booga\r\n"
02436 "END:VEVENT\r\n";
02437   
02438     icalcomponent *icalcomp;
02439     icalproperty *prop;
02440     struct icalrecurrencetype recur;
02441     int n_errors;
02442     
02443     icalcomp = icalparser_parse_string ((char *) test_icalcomp_str);
02444     assert(icalcomp!=NULL);
02445     
02446     if (VERBOSE) printf("%s\n\n",icalcomponent_as_ical_string(icalcomp));
02447 
02448     n_errors = icalcomponent_count_errors (icalcomp);
02449     int_is("icalparser_parse_string()", n_errors,0);
02450 
02451     if (n_errors) {
02453        icalproperty *p;
02454        
02455        for (p = icalcomponent_get_first_property (icalcomp,
02456                                              ICAL_XLICERROR_PROPERTY);
02457             p;
02458             p = icalcomponent_get_next_property (icalcomp,
02459                                             ICAL_XLICERROR_PROPERTY)) {
02460            const char *str;
02461            
02462            str = icalproperty_as_ical_string (p);
02463            fprintf (stderr, "error: %s\n", str);
02464        }
02465     }
02466     
02467     prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY);
02468     ok("get RRULE property", (prop != NULL));
02469     assert(prop!=NULL);
02470     
02471     recur = icalproperty_get_rrule (prop);
02472     
02473     if (VERBOSE) printf("%s\n",icalrecurrencetype_as_string(&recur));
02474 
02475     icalcomponent_free(icalcomp);
02476 
02477 }
02478 
02479 void test_gauge_sql() {
02480     icalgauge *g;
02481     char* str;
02482     
02483     str= "SELECT DTSTART,DTEND,COMMENT FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5";
02484 
02485     g = icalgauge_new_from_sql(str, 0);
02486     ok(str, (g!=NULL));
02487     if (VERBOSE) icalgauge_dump(g);
02488 
02489     icalgauge_free(g);
02490 
02491     str="SELECT * FROM VEVENT,VTODO WHERE VEVENT.SUMMARY = 'Bongoa' AND SEQUENCE < 5 OR METHOD != 'CREATE'";
02492 
02493     g = icalgauge_new_from_sql(str, 0);
02494     ok(str, (g!=NULL));
02495     if (VERBOSE) icalgauge_dump(g);
02496 
02497     icalgauge_free(g);
02498 
02499     str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'";
02500 
02501     g = icalgauge_new_from_sql(str, 0);
02502     ok(str, (g!=NULL));    
02503     if (VERBOSE) icalgauge_dump(g);
02504 
02505     icalgauge_free(g);
02506 
02507     str="SELECT * FROM VEVENT WHERE SUMMARY == 'BA301'";
02508 
02509     g = icalgauge_new_from_sql(str, 0);
02510     ok(str, (g!=NULL));    
02511     if (VERBOSE) icalgauge_dump(g);
02512 
02513     icalgauge_free(g);
02514 
02515     str="SELECT * FROM VEVENT WHERE LOCATION == '104 Forum'";
02516 
02517     g = icalgauge_new_from_sql(str, 0);
02518     ok(str, (g!=NULL));    
02519     if (VERBOSE) icalgauge_dump(g);
02520 
02521     icalgauge_free(g);
02522 }
02523 
02524 
02525 void test_gauge_compare() {
02526     icalgauge *g;
02527     icalcomponent *c;
02528     char* str;
02529 
02530     /* Equality */
02531 
02532     c =  icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT,
02533              icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
02534                 icalproperty_new_dtstart(
02535                     icaltime_from_string("20000101T000002")),0),0);
02536 
02537     g = icalgauge_new_from_sql(
02538        "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", 0);
02539 
02540     ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000002'", (c!=0 && g!=0));
02541     assert(c!=0);
02542     assert(g!=0);
02543 
02544     int_is("compare",icalgauge_compare(g,c), 1);
02545 
02546     icalgauge_free(g);
02547 
02548 
02549     g = icalgauge_new_from_sql(
02550        "SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'", 0);
02551 
02552     ok("SELECT * FROM VEVENT WHERE DTSTART = '20000101T000001'\n", (g!=0));
02553 
02554     assert(g!=0);
02555     int_is("compare",icalgauge_compare(g,c), 0);
02556 
02557     icalgauge_free(g);
02558 
02559     g = icalgauge_new_from_sql(
02560        "SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'", 0);
02561 
02562     ok("SELECT * FROM VEVENT WHERE DTSTART != '20000101T000003'\n", (c!=0 && g!=0));
02563 
02564 
02565     assert(g!=0);
02566     int_is("compare",icalgauge_compare(g,c), 1);
02567 
02568     icalgauge_free(g);
02569 
02570 
02571     /* Less than */
02572 
02573     g = icalgauge_new_from_sql(
02574        "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", 0);
02575 
02576     ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000003'", (c!=0 && g!=0));
02577 
02578     int_is("compare",icalgauge_compare(g,c), 1);
02579 
02580     assert(g!=0);
02581     icalgauge_free(g);
02582 
02583     g = icalgauge_new_from_sql(
02584        "SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'", 0);
02585 
02586     ok("SELECT * FROM VEVENT WHERE DTSTART < '20000101T000002'\n", (g!=0));
02587 
02588 
02589     assert(g!=0);
02590     int_is("compare",icalgauge_compare(g,c), 0);
02591 
02592     icalgauge_free(g);
02593 
02594     /* Greater than */
02595 
02596     g = icalgauge_new_from_sql(
02597        "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'", 0);
02598 
02599     ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000001'\n", (g!=0));
02600 
02601 
02602     assert(g!=0);
02603     int_is("compare",icalgauge_compare(g,c), 1);
02604 
02605     icalgauge_free(g);
02606 
02607     g = icalgauge_new_from_sql(
02608        "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'", 0);
02609 
02610     ok("SELECT * FROM VEVENT WHERE DTSTART > '20000101T000002'\n", (g!=0));
02611 
02612 
02613     assert(g!=0);
02614     int_is("compare",icalgauge_compare(g,c), 0);
02615 
02616 
02617     icalgauge_free(g);
02618 
02619 
02620     /* Greater than or Equal to */
02621 
02622     g = icalgauge_new_from_sql(
02623        "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'", 0);
02624 
02625     ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000002'\n", (g!=0));
02626 
02627 
02628     int_is("compare",icalgauge_compare(g,c), 1);
02629 
02630     icalgauge_free(g);
02631 
02632     g = icalgauge_new_from_sql(
02633        "SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'", 0);
02634 
02635     ok("SELECT * FROM VEVENT WHERE DTSTART >= '20000101T000003'\n", (g!=0));
02636 
02637 
02638     int_is("compare",icalgauge_compare(g,c), 0);
02639 
02640     icalgauge_free(g);
02641 
02642     /* Less than or Equal to */
02643 
02644     g = icalgauge_new_from_sql(
02645        "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'", 0);
02646 
02647     ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000002'\n", (g!=0));
02648 
02649 
02650     assert(g!=0);
02651     int_is("compare",icalgauge_compare(g,c), 1);
02652 
02653     icalgauge_free(g);
02654 
02655     g = icalgauge_new_from_sql(
02656        "SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'", 0);
02657 
02658     ok("SELECT * FROM VEVENT WHERE DTSTART <= '20000101T000001'\n", (g!=0));
02659 
02660 
02661     int_is("compare",icalgauge_compare(g,c), 0);
02662 
02663     icalgauge_free(g);
02664 
02665     icalcomponent_free(c);
02666 
02667     /* Combinations */
02668 
02669     c =  icalcomponent_vanew(ICAL_VCALENDAR_COMPONENT,
02670              icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
02671                 icalproperty_new_dtstart(
02672                     icaltime_from_string("20000102T000000")),0),0);
02673 
02674 
02675     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'";
02676 
02677     g = icalgauge_new_from_sql(str, 0);
02678     ok(str, (g!=0));
02679     int_is("compare",icalgauge_compare(g,c), 1);
02680 
02681     icalgauge_free(g);
02682 
02683     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'";
02684 
02685     g = icalgauge_new_from_sql(str, 0);
02686     ok(str, (g!=0));
02687     int_is("compare",icalgauge_compare(g,c), 0);
02688 
02689     icalgauge_free(g);
02690 
02691     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'";
02692 
02693     g = icalgauge_new_from_sql(str, 0);
02694     ok(str, (g!=0));
02695     int_is("compare",icalgauge_compare(g,c), 1);
02696 
02697     icalgauge_free(g);
02698 
02699 
02700     icalcomponent_free(c);
02701 
02702     /* Combinations, non-cannonical component */
02703 
02704     c = icalcomponent_vanew(ICAL_VEVENT_COMPONENT,
02705                 icalproperty_new_dtstart(
02706                     icaltime_from_string("20000102T000000")),0);
02707 
02708 
02709     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000103T000000'";
02710 
02711     g = icalgauge_new_from_sql(str, 0);
02712     ok(str, (g!=0));
02713     int_is("compare",icalgauge_compare(g,c), 1);
02714 
02715     icalgauge_free(g);
02716 
02717     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' and DTSTART < '20000102T000000'";
02718 
02719     g = icalgauge_new_from_sql(str, 0);
02720     ok(str, (g!=0));
02721     int_is("compare",icalgauge_compare(g,c), 0);
02722 
02723     icalgauge_free(g);
02724 
02725     str =  "SELECT * FROM VEVENT WHERE DTSTART > '20000101T000000' or DTSTART < '20000102T000000'";
02726 
02727     g = icalgauge_new_from_sql(str, 0);
02728     ok(str, (g!=0));
02729     int_is("compare",icalgauge_compare(g,c), 1);
02730 
02731     icalgauge_free(g);
02732     icalcomponent_free(c);
02733 
02734 
02735     /* Complex comparisions */
02736 
02737     c =  icalcomponent_vanew(
02738        ICAL_VCALENDAR_COMPONENT,
02739        icalproperty_new_method(ICAL_METHOD_REQUEST),
02740        icalcomponent_vanew(
02741            ICAL_VEVENT_COMPONENT,
02742            icalproperty_new_dtstart(
02743               icaltime_from_string("20000101T000002")),
02744            icalproperty_new_comment("foo"),
02745            icalcomponent_vanew(
02746               ICAL_VALARM_COMPONENT,
02747               icalproperty_new_dtstart(
02748                   icaltime_from_string("20000101T120000")),
02749               
02750               0),
02751            0),
02752        0);
02753     
02754     
02755     str = "SELECT * FROM VEVENT WHERE VALARM.DTSTART = '20000101T120000'";
02756 
02757     g = icalgauge_new_from_sql(str, 0);
02758     ok(str, (g!=0));
02759     int_is("compare",icalgauge_compare(g,c), 1);
02760 
02761     icalgauge_free(g);
02762 
02763     str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo'";
02764     g = icalgauge_new_from_sql(str, 0);
02765     ok(str, (g!=0));
02766     int_is("compare",icalgauge_compare(g,c), 1);
02767 
02768     icalgauge_free(g);
02769        
02770     str = "SELECT * FROM VEVENT WHERE COMMENT = 'foo' AND  VALARM.DTSTART = '20000101T120000'";
02771     g = icalgauge_new_from_sql(str, 0);
02772     ok(str, (g!=0));
02773     int_is("compare",icalgauge_compare(g,c), 1);
02774 
02775     icalgauge_free(g);
02776 
02777     str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' AND  VALARM.DTSTART = '20000101T120000'";
02778     g = icalgauge_new_from_sql(str, 0);
02779     ok(str, (g!=0));
02780     int_is("compare",icalgauge_compare(g,c), 0);
02781 
02782     icalgauge_free(g);
02783 
02784     str = "SELECT * FROM VEVENT WHERE COMMENT = 'bar' or  VALARM.DTSTART = '20000101T120000'";
02785     g = icalgauge_new_from_sql(str, 0);
02786     ok(str, (g!=0));
02787     int_is("compare",icalgauge_compare(g,c), 1);
02788 
02789     icalgauge_free(g);
02790 
02791     icalcomponent_free(c);
02792 
02793 }
02794 
02795 icalcomponent* make_component(int i){
02796 
02797     icalcomponent *c;
02798 
02799     struct icaltimetype t = icaltime_from_string("20000101T120000Z");
02800 
02801     t.day += i;
02802 
02803     icaltime_normalize(t);
02804 
02805     c =  icalcomponent_vanew(
02806        ICAL_VCALENDAR_COMPONENT,
02807        icalproperty_new_method(ICAL_METHOD_REQUEST),
02808        icalcomponent_vanew(
02809            ICAL_VEVENT_COMPONENT,
02810            icalproperty_new_dtstart(t),
02811            0),
02812        0);
02813 
02814     assert(c != 0);
02815 
02816     return c;
02817 
02818 }
02819 void test_fileset()
02820 {
02821     icalset *fs;
02822     icalcomponent *c;
02823     int i;
02824     int comp_count = 0;
02825     char *path = "test_fileset.ics";
02826     icalgauge  *g = icalgauge_new_from_sql(
02827        "SELECT * FROM VEVENT WHERE DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z'", 0);
02828 
02829     ok("icalgauge_new_from_sql()", (g!=NULL));
02830 
02831     unlink(path);
02832 
02833     fs = icalfileset_new(path);
02834     
02835     ok("icalfileset_new()", (fs!=NULL));
02836     assert(fs != 0);
02837 
02838     for (i = 0; i!= 10; i++){
02839        c = make_component(i);
02840        icalfileset_add_component(fs,c);
02841     }
02842 
02843     icalfileset_commit(fs);
02844 
02845     icalset_free(fs);
02847     fs = icalfileset_new(path);
02848 
02849     if (VERBOSE) printf("== No Selections \n");
02850 
02851     comp_count = 0;
02852     for (c = icalfileset_get_first_component(fs);
02853         c != 0;
02854         c = icalfileset_get_next_component(fs)){
02855        struct icaltimetype t = icalcomponent_get_dtstart(c);
02856        comp_count++;
02857        if (VERBOSE) printf("%s\n",icaltime_as_ctime(t));
02858     }
02859     int_is("icalfileset get components",comp_count, 10);
02860 
02861     icalfileset_select(fs,g);
02862 
02863     if (VERBOSE) printf("\n== DTSTART > '20000103T120000Z' AND DTSTART <= '20000106T120000Z' \n");
02864 
02865     comp_count = 0;
02866     for (c = icalfileset_get_first_component(fs);
02867         c != 0;
02868         c = icalfileset_get_next_component(fs)){
02869        struct icaltimetype t = icalcomponent_get_dtstart(c);
02870        comp_count++;
02871        if (VERBOSE) printf("%s\n",icaltime_as_ctime(t));
02872     }
02873     int_is("icalfileset get components with gauge",comp_count, 3);
02874 
02875     icalset_free(fs);
02876 
02877        /*icalgauge_free(g);*/
02878     
02879 }
02880 
02881 void microsleep(int us)
02882 {
02883 #ifndef WIN32
02884     struct timeval tv;
02885 
02886     tv.tv_sec = 0;
02887     tv.tv_usec = us;
02888 
02889     select(0,0,0,0,&tv);
02890 #else
02891        Sleep(us);
02892 #endif
02893 }
02894 
02895 
02896 void test_file_locks()
02897 {
02898 #ifndef WIN32
02899     pid_t pid;
02900     char *path = "test_fileset_locktest.ics";
02901     icalset *fs;
02902     icalcomponent *c, *c2;
02903     struct icaldurationtype d;
02904     int i;
02905     int final,sec;
02906 
02907     icalerror_clear_errno();
02908 
02909     unlink(path);
02910 
02911     fs = icalfileset_new(path);
02912 
02913     if(icalfileset_get_first_component(fs)==0){
02914        c = make_component(0);
02915        
02916        d = icaldurationtype_from_int(1);
02917        
02918        icalcomponent_set_duration(c,d);
02919        
02920        icalfileset_add_component(fs,c);
02921        
02922        c2 = icalcomponent_new_clone(c);
02923        
02924        icalfileset_add_component(fs,c2);
02925        
02926        icalfileset_commit(fs);
02927     }
02928     
02929     icalset_free(fs);
02930     
02931     assert(icalerrno == ICAL_NO_ERROR);
02932     
02933     pid = fork();
02934     
02935     assert(pid >= 0);
02936     
02937     if(pid == 0){
02938        /*child*/
02939        int i;
02940 
02941        microsleep(rand()/(RAND_MAX/100));
02942 
02943        for(i = 0; i< 50; i++){
02944            fs = icalfileset_new(path);
02945 
02946 
02947            assert(fs != 0);
02948 
02949            c = icalfileset_get_first_component(fs);
02950 
02951            assert(c!=0);
02952           
02953            d = icalcomponent_get_duration(c);
02954            d = icaldurationtype_from_int(icaldurationtype_as_int(d)+1);
02955            
02956            icalcomponent_set_duration(c,d);
02957            icalcomponent_set_summary(c,"Child");   
02958   
02959            c2 = icalcomponent_new_clone(c);
02960            icalcomponent_set_summary(c2,"Child");
02961            icalfileset_add_component(fs,c2);
02962 
02963            icalfileset_mark(fs);
02964            icalfileset_commit(fs);
02965 
02966            icalset_free(fs);
02967 
02968            microsleep(rand()/(RAND_MAX/20));
02969 
02970 
02971        }
02972 
02973        exit(0);
02974 
02975     } else {
02976        /* parent */
02977        int i;
02978        
02979        for(i = 0; i< 50; i++){
02980            fs = icalfileset_new(path);
02981 
02982            assert(fs != 0);
02983 
02984            c = icalfileset_get_first_component(fs);
02985            
02986            assert(c!=0);
02987 
02988            d = icalcomponent_get_duration(c);
02989            d = icaldurationtype_from_int(icaldurationtype_as_int(d)+1);
02990            
02991            icalcomponent_set_duration(c,d);
02992            icalcomponent_set_summary(c,"Parent");
02993 
02994            c2 = icalcomponent_new_clone(c);
02995            icalcomponent_set_summary(c2,"Parent");
02996            icalfileset_add_component(fs,c2);
02997 
02998            icalfileset_mark(fs);
02999            icalfileset_commit(fs);
03000            icalset_free(fs);
03001 
03002            putc('.',stdout);
03003            fflush(stdout);
03004 
03005        }
03006     }
03007 
03008     assert(waitpid(pid,0,0)==pid);
03009        
03010 
03011     fs = icalfileset_new(path);
03012     
03013     i=1;
03014 
03015     c = icalfileset_get_first_component(fs);
03016     final = icaldurationtype_as_int(icalcomponent_get_duration(c));
03017     for (c = icalfileset_get_next_component(fs);
03018         c != 0;
03019         c = icalfileset_get_next_component(fs)){
03020        struct icaldurationtype d = icalcomponent_get_duration(c);
03021        sec = icaldurationtype_as_int(d);
03022 
03023        /*printf("%d,%d ",i,sec);*/
03024        assert(i == sec);
03025        i++;
03026     }
03027 
03028     printf("\nFinal: %d\n",final);
03029 
03030     
03031     assert(sec == final);
03032 #endif
03033 }
03034 
03035 void test_action()
03036 {
03037     icalcomponent *c;
03038     icalproperty *p;
03039     char *str;
03040 
03041     static const char test_icalcomp_str[] =
03042 "BEGIN:VEVENT\n"
03043 "ACTION:EMAIL\n"
03044 "ACTION:PROCEDURE\n"
03045 "ACTION:AUDIO\n"
03046 "ACTION:FUBAR\n"
03047 "END:VEVENT\n";
03048 
03049      
03050     c = icalparser_parse_string ((char *) test_icalcomp_str);
03051 
03052     ok("icalparser_parse_string(), ACTIONS", (c!=NULL));
03053     assert(c!=0);
03054     
03055     str = icalcomponent_as_ical_string(c);
03056     is("icalcomponent_as_ical_string()", str, ((char*) test_icalcomp_str));
03057     if (VERBOSE) printf("%s\n\n",str);
03058 
03059     p = icalcomponent_get_first_property(c,ICAL_ACTION_PROPERTY);
03060 
03061     ok("ICAL_ACTION_EMAIL", (icalproperty_get_action(p) == ICAL_ACTION_EMAIL));
03062 
03063     p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY);
03064 
03065     ok("ICAL_ACTION_PROCEDURE", (icalproperty_get_action(p) == ICAL_ACTION_PROCEDURE));
03066 
03067     p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY);
03068 
03069     ok("ICAL_ACTION_AUDIO", (icalproperty_get_action(p) == ICAL_ACTION_AUDIO));
03070 
03071     p = icalcomponent_get_next_property(c,ICAL_ACTION_PROPERTY);
03072 
03073     ok("ICAL_ACTION_X", (icalproperty_get_action(p) == ICAL_ACTION_X));
03074     is("ICAL_ACTION -> FUBAR", icalvalue_get_x(icalproperty_get_value(p)), "FUBAR");
03075     icalcomponent_free(c);
03076 }
03077 
03078         
03079 
03080 void test_trigger()
03081 {
03082 
03083     struct icaltriggertype tr;
03084     icalcomponent *c;
03085     icalproperty *p;
03086     const char* str;
03087     
03088     static const char test_icalcomp_str[] =
03089 "BEGIN:VEVENT\n"
03090 "TRIGGER;VALUE=DATE-TIME:19980403T120000\n"
03091 "TRIGGER;VALUE=DURATION:-PT15M\n"
03092 "TRIGGER;VALUE=DATE-TIME:19980403T120000\n"
03093 "TRIGGER;VALUE=DURATION:-PT15M\n"
03094 "END:VEVENT\n";
03095   
03096     
03097     c = icalparser_parse_string ((char *) test_icalcomp_str);
03098     ok("icalparser_parse_string()", (c!= NULL));
03099     assert(c!=NULL);
03100     
03101     is("parsed triggers", icalcomponent_as_ical_string(c), (char*)test_icalcomp_str);
03102 
03103     for(p = icalcomponent_get_first_property(c,ICAL_TRIGGER_PROPERTY);
03104        p != 0;
03105        p = icalcomponent_get_next_property(c,ICAL_TRIGGER_PROPERTY)){
03106        tr = icalproperty_get_trigger(p);
03107 
03108        if(!icaltime_is_null_time(tr.time)){
03109          if (VERBOSE) printf("value=DATE-TIME:%s\n", icaltime_as_ical_string(tr.time));
03110        } else {
03111          if (VERBOSE) printf("value=DURATION:%s\n", icaldurationtype_as_ical_string(tr.duration));
03112        }   
03113     }
03114 
03115     icalcomponent_free(c);
03116 
03117     /* Trigger, as a DATETIME */
03118     tr.duration = icaldurationtype_null_duration();
03119     tr.time = icaltime_from_string("19970101T120000");
03120     p = icalproperty_new_trigger(tr);
03121     str = icalproperty_as_ical_string(p);
03122 
03123     is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n");
03124     icalproperty_free(p);
03125 
03126     /* TRIGGER, as a DURATION */
03127     tr.time = icaltime_null_time();
03128     tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
03129     p = icalproperty_new_trigger(tr);
03130     str = icalproperty_as_ical_string(p);
03131     
03132     is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n");
03133     icalproperty_free(p);
03134 
03135     /* TRIGGER, as a DATETIME, VALUE=DATETIME*/
03136     tr.duration = icaldurationtype_null_duration();
03137     tr.time = icaltime_from_string("19970101T120000");
03138     p = icalproperty_new_trigger(tr);
03139     icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME));
03140     str = icalproperty_as_ical_string(p);
03141 
03142     is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n");
03143     icalproperty_free(p);
03144 
03145     /*TRIGGER, as a DURATION, VALUE=DATETIME */
03146     tr.time = icaltime_null_time();
03147     tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
03148     p = icalproperty_new_trigger(tr);
03149     icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DATETIME ));
03150 
03151     str = icalproperty_as_ical_string(p);
03152     
03153     is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n");
03154     icalproperty_free(p);
03155 
03156     /* TRIGGER, as a DATETIME, VALUE=DURATION*/
03157     tr.duration = icaldurationtype_null_duration();
03158     tr.time = icaltime_from_string("19970101T120000");
03159     p = icalproperty_new_trigger(tr);
03160     icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION));
03161     str = icalproperty_as_ical_string(p);
03162 
03163     is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n");
03164     icalproperty_free(p);
03165 
03166     /*TRIGGER, as a DURATION, VALUE=DURATION */
03167     tr.time = icaltime_null_time();
03168     tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
03169     p = icalproperty_new_trigger(tr);
03170     icalproperty_add_parameter(p,icalparameter_new_value( ICAL_VALUE_DURATION));
03171 
03172     str = icalproperty_as_ical_string(p);
03173     
03174     is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n");
03175     icalproperty_free(p);
03176 
03177 
03178    /* TRIGGER, as a DATETIME, VALUE=BINARY  */
03179     tr.duration = icaldurationtype_null_duration();
03180     tr.time = icaltime_from_string("19970101T120000");
03181     p = icalproperty_new_trigger(tr);
03182     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
03183     str = icalproperty_as_ical_string(p);
03184 
03185     is("TRIGGER;VALUE=DATE-TIME:19970101T120000", str, "TRIGGER;VALUE=DATE-TIME:19970101T120000\n");
03186     icalproperty_free(p);
03187 
03188     /*TRIGGER, as a DURATION, VALUE=BINARY   */
03189     tr.time = icaltime_null_time();
03190     tr.duration = icaldurationtype_from_string("P3DT3H50M45S");
03191     p = icalproperty_new_trigger(tr);
03192     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
03193 
03194     str = icalproperty_as_ical_string(p);
03195     
03196     is("TRIGGER;VALUE=DURATION:P3DT3H50M45S", str, "TRIGGER;VALUE=DURATION:P3DT3H50M45S\n");
03197     icalproperty_free(p);
03198 }
03199 
03200 
03201 void test_rdate()
03202 {
03203 
03204     struct icaldatetimeperiodtype dtp;
03205     icalproperty *p;
03206     const char* str;
03207     struct icalperiodtype period;
03208 
03209     period.start = icaltime_from_string("19970101T120000");
03210     period.end = icaltime_null_time();
03211     period.duration = icaldurationtype_from_string("PT3H10M15S");
03212 
03213     /* RDATE, as DATE-TIME */
03214     dtp.time = icaltime_from_string("19970101T120000");
03215     dtp.period = icalperiodtype_null_period();
03216     p = icalproperty_new_rdate(dtp);
03217     str = icalproperty_as_ical_string(p);
03218 
03219     is("RDATE as DATE-TIME",
03220        "RDATE;VALUE=DATE-TIME:19970101T120000\n",str);
03221     icalproperty_free(p); 
03222 
03223     /* RDATE, as PERIOD */
03224     dtp.time = icaltime_null_time();
03225     dtp.period = period;
03226     p = icalproperty_new_rdate(dtp);
03227 
03228     str = icalproperty_as_ical_string(p);
03229     is("RDATE, as PERIOD", "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str);
03230     icalproperty_free(p); 
03231 
03232     /* RDATE, as DATE-TIME, VALUE=DATE-TIME */
03233     dtp.time = icaltime_from_string("19970101T120000");
03234     dtp.period = icalperiodtype_null_period();
03235     p = icalproperty_new_rdate(dtp);
03236     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME));
03237     str = icalproperty_as_ical_string(p);
03238 
03239     is("RDATE, as DATE-TIME, VALUE=DATE-TIME",
03240        "RDATE;VALUE=DATE-TIME:19970101T120000\n",str);
03241     icalproperty_free(p); 
03242 
03243 
03244     /* RDATE, as PERIOD, VALUE=DATE-TIME */
03245     dtp.time = icaltime_null_time();
03246     dtp.period = period;
03247     p = icalproperty_new_rdate(dtp);
03248     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_DATETIME));
03249     str = icalproperty_as_ical_string(p);
03250     is("RDATE, as PERIOD, VALUE=DATE-TIME",
03251        "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str);
03252     icalproperty_free(p); 
03253 
03254 
03255     /* RDATE, as DATE-TIME, VALUE=PERIOD */
03256     dtp.time = icaltime_from_string("19970101T120000");
03257     dtp.period = icalperiodtype_null_period();
03258     p = icalproperty_new_rdate(dtp);
03259     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD));
03260     str = icalproperty_as_ical_string(p);
03261 
03262     is("RDATE, as DATE-TIME, VALUE=PERIOD",
03263        "RDATE;VALUE=DATE-TIME:19970101T120000\n",str);
03264     icalproperty_free(p); 
03265 
03266 
03267     /* RDATE, as PERIOD, VALUE=PERIOD */
03268     dtp.time = icaltime_null_time();
03269     dtp.period = period;
03270     p = icalproperty_new_rdate(dtp);
03271     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_PERIOD));
03272     str = icalproperty_as_ical_string(p);
03273 
03274     is("RDATE, as PERIOD, VALUE=PERIOD",
03275        "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str);
03276     icalproperty_free(p); 
03277 
03278 
03279     /* RDATE, as DATE-TIME, VALUE=BINARY */
03280     dtp.time = icaltime_from_string("19970101T120000");
03281     dtp.period = icalperiodtype_null_period();
03282     p = icalproperty_new_rdate(dtp);
03283     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
03284     str = icalproperty_as_ical_string(p);
03285     
03286     is("RDATE, as DATE-TIME, VALUE=BINARY",
03287        "RDATE;VALUE=DATE-TIME:19970101T120000\n",str);
03288     icalproperty_free(p); 
03289 
03290 
03291     /* RDATE, as PERIOD, VALUE=BINARY */
03292     dtp.time = icaltime_null_time();
03293     dtp.period = period;
03294     p = icalproperty_new_rdate(dtp);
03295     icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
03296     str = icalproperty_as_ical_string(p);
03297 
03298     is("RDAE, as PERIOD, VALUE=BINARY",
03299        "RDATE;VALUE=PERIOD:19970101T120000/PT3H10M15S\n",str);
03300     icalproperty_free(p); 
03301 }
03302 
03303 
03304 void test_langbind()
03305 {
03306     icalcomponent *c, *inner; 
03307     icalproperty *p;
03308     char *test_str_parsed;
03309     static const char test_str[] =
03310 "BEGIN:VEVENT\n"
03311 "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n"
03312 "COMMENT: Comment that \n spans a line\n"
03313 "COMMENT: Comment with \"quotable\" \'characters\' and other \t bad magic \n things \f Yeah.\n"
03314 "DTSTART:19970101T120000\n"
03315 "DTSTART:19970101T120000Z\n"
03316 "DTSTART:19970101\n"
03317 "DURATION:P3DT4H25M\n"
03318 "FREEBUSY:19970101T120000/19970101T120000\n"
03319 "FREEBUSY:19970101T120000/P3DT4H25M\n"
03320 "END:VEVENT\n";
03321 
03322     static const char *test_str_parsed_good = 
03323 "BEGIN:VEVENT\n"
03324 "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:\n"
03325 " employee-A@host.com\n"
03326 "COMMENT: Comment that spans a line\n"
03327 "COMMENT: Comment with \\\"quotable\\\" 'characters' and other \\t bad magic \n"
03328 " things \\f Yeah.\n"
03329 "DTSTART:19970101T120000\n"
03330 "DTSTART:19970101T120000Z\n"
03331 "DTSTART;VALUE=DATE:19970101\n"
03332 "DURATION:P3DT4H25M\n"
03333 "FREEBUSY:19970101T120000/19970101T120000\n"
03334 "FREEBUSY:19970101T120000/P3DT4H25M\n"
03335 "END:VEVENT\n";
03336 
03337     if (VERBOSE) printf("%s\n",test_str);
03338 
03339     c = icalparser_parse_string(test_str);
03340 
03341     ok("icalparser_parse_string()", (c!=NULL));
03342     assert(c != NULL);
03343 
03344     test_str_parsed = icalcomponent_as_ical_string(c);
03345 
03346     is("parsed version with bad chars, etc",
03347        test_str_parsed,
03348        test_str_parsed_good);
03349 
03350     
03351     inner = icalcomponent_get_inner(c);
03352 
03353     for(
03354        p = icallangbind_get_first_property(inner,"ANY");
03355        p != 0;
03356        p = icallangbind_get_next_property(inner,"ANY")
03357        ) { 
03358 
03359       const char *str = icallangbind_property_eval_string(p,":");
03361       if (VERBOSE) printf("%s\n",str);
03362     }
03363 
03364 
03365     p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY);
03366 
03367     icalproperty_set_parameter_from_string(p,"CUTYPE","INDIVIDUAL");
03368 
03369     is ("Set attendee parameter",
03370        icalproperty_as_ical_string(p),
03371        "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:MAILTO:\n"
03372        " employee-A@host.com\n");
03373  
03374     icalproperty_set_value_from_string(p,"mary@foo.org","TEXT");
03375 
03376     is ("Set attendee parameter value",
03377        icalproperty_as_ical_string(p),
03378        "ATTENDEE;VALUE=TEXT;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=INDIVIDUAL:\n"
03379 " mary@foo.org\n");
03380 
03381        icalcomponent_free(c);
03382 }
03383 
03384 void test_property_parse()
03385 {
03386     icalproperty *p;
03387     const char *str;
03388 
03389     p= icalproperty_new_from_string(
03390                          "ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com");
03391 
03392     ok("icalproperty_from_string(), ATTENDEE", (p != 0));
03393     assert (p !=  0);
03394 
03395     str = icalproperty_as_ical_string(p);
03396     if (VERBOSE) printf("%s\n",str);
03397 
03398     icalproperty_free(p);
03399 
03400     p= icalproperty_new_from_string("DTSTART:19970101T120000Z\n");
03401 
03402     ok("icalproperty_from_string(), simple DTSTART", (p != 0));
03403     assert (p !=  0);
03404 
03405     str = icalproperty_as_ical_string(p);
03406     if (VERBOSE) printf("%s\n",str);
03407     
03408     icalproperty_free(p);
03409 
03410 }
03411 
03412 
03413 void test_value_parameter() 
03414 {
03415 
03416     icalcomponent *c;
03417     icalproperty *p;
03418     icalparameter *param;
03419     
03420     static const char test_icalcomp_str[] =
03421 "BEGIN:VEVENT\n"
03422 "DTSTART;VALUE=DATE-TIME:19971123T123000\n"
03423 "DTSTART;VALUE=DATE:19971123\n"
03424 "DTSTART;VALUE=FOO:19971123T123000\n"
03425 "END:VEVENT\n";
03426      
03427     c = icalparser_parse_string ((char *) test_icalcomp_str);
03428     ok("icalparser_parse_string()", (c != NULL));
03429     if (!c) {
03430        exit (EXIT_FAILURE);
03431     }
03432 
03433     if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c));
03434 
03435     p = icalcomponent_get_first_property(c,ICAL_DTSTART_PROPERTY);
03436     param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER);
03437     
03438     ok("icalproperty_get_value()", (icalparameter_get_value(param) == ICAL_VALUE_DATETIME));
03439 
03440     p = icalcomponent_get_next_property(c,ICAL_DTSTART_PROPERTY);
03441     param = icalproperty_get_first_parameter(p,ICAL_VALUE_PARAMETER);
03442     ok("icalproperty_get_first_parameter()",(icalparameter_get_value(param) == ICAL_VALUE_DATE));
03443 
03444     icalcomponent_free(c);
03445 }
03446 
03447 
03448 void test_x_parameter()
03449 {
03450     icalproperty *p;
03451 
03452     p= icalproperty_new_from_string(
03453        "COMMENT;X-A=1;X-B=2: This is a note");
03454 
03455     if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p));
03456 
03457     ok("COMMENT property",(icalproperty_isa(p) == ICAL_COMMENT_PROPERTY));
03458     is("COMMENT parses param", icalproperty_get_comment(p)," This is a note");
03459 
03460     icalproperty_set_parameter_from_string(p,"X-LIES", "no");
03461     icalproperty_set_parameter_from_string(p,"X-LAUGHS", "big");
03462     icalproperty_set_parameter_from_string(p,"X-TRUTH", "yes");
03463     icalproperty_set_parameter_from_string(p,"X-HUMOUR", "bad");
03464 
03465     if (VERBOSE) printf("%s\n",icalproperty_as_ical_string(p));
03466 
03467     is("Check X-LIES", icalproperty_get_parameter_as_string(p, "X-LIES"), "no");
03468     is("Check X-LAUGHS", icalproperty_get_parameter_as_string(p, "X-LAUGHS"), "big");
03469     is("Check X-TRUTH", icalproperty_get_parameter_as_string(p, "X-TRUTH"), "yes");
03470     is("Check X-HUMOUR", icalproperty_get_parameter_as_string(p, "X-HUMOUR"), "bad");
03471 
03472     icalproperty_free(p);
03473 }
03474 
03475 
03476 
03477 void test_x_property() 
03478 {
03479     icalproperty *p;
03480     
03481     p= icalproperty_new_from_string(
03482        "X-LIC-PROPERTY: This is a note");
03483 
03484     if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p));
03485 
03486     ok("x-property is correct kind",(icalproperty_isa(p) == ICAL_X_PROPERTY));
03487     is("icalproperty_get_x_name() works",
03488        icalproperty_get_x_name(p),"X-LIC-PROPERTY");
03489     is("icalproperty_get_x() works",
03490        icalproperty_get_x(p)," This is a note");
03491 
03492     icalproperty_free(p);
03493 }
03494 
03495 void test_utcoffset()
03496 {
03497     icalproperty *p;
03498 
03499     p = icalproperty_new_from_string("TZOFFSETFROM:-001608");
03500     ok("parse TZOOFSETFROM:-001608", (p!=NULL));
03501 
03502     if (VERBOSE && p) printf("%s\n",icalproperty_as_ical_string(p));
03503 
03504     if (p) icalproperty_free(p);
03505 }
03506 
03507 void test_attach()
03508 {
03509     icalcomponent *c;
03510 
03511     static const char test_icalcomp_str[] =
03512 "BEGIN:VEVENT\n"
03513 "ATTACH:CID:jsmith.part3.960817T083000.xyzMain@host1.com\n"
03514 "ATTACH:FMTTYPE=application/postscript;ftp://xyzCorp.com/pub/reports/r-960812.ps\n"
03515 "END:VEVENT\n";
03516 
03517     c = icalparser_parse_string ((char *) test_icalcomp_str);
03518     ok("parse simple attachment", (c != NULL));
03519 
03520     if (VERBOSE) printf("%s",icalcomponent_as_ical_string(c));
03521 
03522     if (c) icalcomponent_free(c);
03523 }
03524 
03525 
03526 void test_vcal(void)
03527 {
03528   VObject *vcal = 0;
03529   icalcomponent *comp;
03530   char* file = "../../test-data/user-cal.vcf";
03531 
03532   vcal = Parse_MIME_FromFileName(file);
03533     
03534   ok("Parsing ../../test-data/user-cal.vcf", (vcal != 0));
03535 
03536   comp = icalvcal_convert(vcal);
03537 
03538   ok("Converting to ical component", (comp != 0));
03539   
03540   if (VERBOSE && comp)
03541     printf("%s\n",icalcomponent_as_ical_string(comp));
03542 
03543   if (comp) icalcomponent_free(comp);
03544   if (vcal) deleteVObject(vcal);
03545 }
03546 
03547 int main(int argc, char *argv[])
03548 {
03549     int c;
03550     extern char *optarg;
03551     extern int optopt;
03552     int errflg=0;
03553     char* program_name = strrchr(argv[0],'/');
03554     int do_test = 0;
03555     int do_header = 0;
03556 
03557     set_zone_directory("../../zoneinfo");
03558     putenv("TZ=");
03559 
03560     test_start(0);
03561 
03562 
03563 #ifndef WIN32
03564     while ((c = getopt(argc, argv, "lvq")) != -1) {
03565       switch (c) {
03566       case 'v': {
03567        VERBOSE = 1;
03568        break;
03569       }
03570       case 'q': {
03571        QUIET = 1;
03572        break;
03573       }
03574       case 'l': {
03575        do_header = 1;;
03576       }
03577       case '?': {
03578        errflg++;
03579       }
03580       }
03581     } 
03582     if (optind < argc) {
03583       do_test = atoi(argv[argc-1]);
03584     }
03585 #else
03586     if (argc>1)
03587       do_test = atoi(argv[2]);
03588 
03589 #endif
03590     
03591     
03592     test_run("Test time parser functions", test_time_parser, do_test, do_header);
03593     test_run("Test time", test_time, do_test, do_header);
03594     test_run("Test day of Year", test_doy, do_test, do_header);
03595     test_run("Test duration", test_duration, do_test, do_header);
03596     test_run("Test period",      test_period, do_test, do_header);
03597     test_run("Test DTSTART",      test_dtstart, do_test, do_header);
03598     test_run("Test day of year of week start",      test_start_of_week, do_test, do_header);
03599     test_run("Test recur parser",      test_recur_parser, do_test, do_header);
03600     test_run("Test recur", test_recur, do_test, do_header);
03601     test_run("Test Recurring Events File", test_recur_file, do_test, do_header);
03602     test_run("Test parameter bug", test_recur_parameter_bug, do_test, do_header);
03603     test_run("Test Array Expansion", test_expand_recurrence, do_test, do_header);
03604     test_run("Test Free/Busy lists", test_fblist, do_test, do_header);
03605     test_run("Test Overlaps", test_overlaps, do_test, do_header);
03606     
03607     test_run("Test Span", test_icalcomponent_get_span, do_test, do_header);
03608     test_run("Test Gauge SQL", test_gauge_sql, do_test, do_header);
03609     test_run("Test Gauge Compare", test_gauge_compare, do_test, do_header);
03610     test_run("Test File Set", test_fileset, do_test, do_header);
03611     test_run("Test File Set (Extended)", test_fileset_extended, do_test, do_header);
03612     test_run("Test Dir Set", test_dirset, do_test, do_header);
03613     test_run("Test Dir Set (Extended)", test_dirset_extended, do_test, do_header);
03614     
03615     test_run("Test File Locks", test_file_locks, do_test, do_header);
03616     test_run("Test X Props and Params", test_x, do_test, do_header);
03617     test_run("Test Trigger", test_trigger, do_test, do_header);
03618     test_run("Test Restriction", test_restriction, do_test, do_header);
03619     test_run("Test RDATE", test_rdate, do_test, do_header);
03620     test_run("Test language binding", test_langbind, do_test, do_header);
03621     test_run("Test property parser", test_property_parse, do_test, do_header);
03622     test_run("Test Action", test_action, do_test, do_header);
03623     test_run("Test Value Parameter", test_value_parameter, do_test, do_header);
03624     test_run("Test X property", test_x_property, do_test, do_header);
03625     test_run("Test X parameter", test_x_parameter, do_test, do_header);
03626     test_run("Test request status", test_requeststat, do_test, do_header);
03627     test_run("Test UTC-OFFSET", test_utcoffset, do_test, do_header);
03628     test_run("Test Values", test_values, do_test, do_header);
03629     test_run("Test Parameters", test_parameters, do_test, do_header);
03630     test_run("Test Properties", test_properties, do_test, do_header);
03631     test_run("Test Components", test_components, do_test, do_header);
03632     test_run("Test Convenience", test_convenience, do_test, do_header);
03633     test_run("Test classify ", test_classify, do_test, do_header);
03634     test_run("Test Iterators", test_iterators, do_test, do_header);
03635     test_run("Test strings", test_strings, do_test, do_header);
03636     test_run("Test Compare", test_compare, do_test, do_header);
03637     test_run("Create Simple Component", create_simple_component, do_test, do_header);
03638     test_run("Create Components", create_new_component, do_test, do_header);
03639     test_run("Create Components with vaargs", create_new_component_with_va_args, do_test, do_header);
03640     test_run("Test Memory", test_memory, do_test, do_header);
03641     test_run("Test Attachment", test_attach, do_test, do_header);
03642     test_run("Test icalcalendar", test_calendar, do_test, do_header);
03643     test_run("Test Dirset", test_dirset, do_test, do_header);
03644     test_run("Test vCal to iCal conversion", test_vcal, do_test, do_header);
03645     test_run("Test UTF-8 Handling", test_utf8, do_test, do_header);
03646 
03649 #ifdef WITH_CXX
03650     test_run("Test C++ API", test_cxx, do_test, do_header);
03651 #endif
03652 
03653 #ifdef WITH_BDB
03654     test_run("Test BDB Set", test_bdbset, do_test, do_header);
03655 #endif
03656 
03657 
03658     icaltimezone_free_builtin_timezones();
03659     icalmemory_free_ring();
03660     free_zone_directory();
03661 
03662     test_end();
03663 
03664     return 0;
03665 }
03666 
03667