Back to index

lightning-sunbird  0.9+nobinonly
regression-component.c
Go to the documentation of this file.
00001 #include "ical.h"
00002 #include "regression.h"
00003 
00004 #include <string.h>
00005 extern int VERBOSE;
00006 
00007 void create_simple_component(void)
00008 {
00009 
00010     icalcomponent* calendar;
00011     icalproperty *version, *bogus;
00012       
00013     /* Create calendar and add properties */
00014     calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
00015 
00016     ok("create vcalendar component", (calendar!=NULL));
00017 
00018     icalcomponent_add_property(
00019        calendar,
00020        icalproperty_new_version("2.0")
00021        );
00022     
00023     version = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
00024     ok("version property added", (version!=NULL));
00025 
00026     bogus = icalcomponent_get_first_property(calendar,ICAL_DTSTART_PROPERTY);
00027     ok("bogus dtstart not found", (bogus == NULL));
00028 
00029     if (VERBOSE && calendar)
00030       printf("%s\n",icalcomponent_as_ical_string(calendar));
00031 
00032     icalcomponent_free(calendar);
00033 }
00034 
00035 
00036 static char* create_new_component_str = 
00037 "BEGIN:VCALENDAR\n"
00038 "VERSION:2.0\n"
00039 "PRODID:-//RDU Software//NONSGML HandCal//EN\n"
00040 "BEGIN:VTIMEZONE\n"
00041 "TZID:America/New_York\n"
00042 "BEGIN:DAYLIGHT\n"
00043 "DTSTART:20020606T212449\n"
00044 "RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n"
00045 "TZOFFSETFROM:-0500\n"
00046 "TZOFFSETTO:-0400\n"
00047 "TZNAME:EST\n"
00048 "END:DAYLIGHT\n"
00049 "BEGIN:STANDARD\n"
00050 "DTSTART:20020606T212449\n"
00051 "RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n"
00052 "TZOFFSETFROM:-0400\n"
00053 "TZOFFSETTO:-0500\n"
00054 "TZNAME:EST\n"
00055 "END:STANDARD\n"
00056 "END:VTIMEZONE\n"
00057 "BEGIN:VEVENT\n"
00058 "DTSTAMP:20020606T212449\n"
00059 "UID:guid-1.host1.com\n"
00060 "ORGANIZER;ROLE=CHAIR:mrbig@host.com\n"
00061 "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CUTYPE=GROUP:employee-A@host.com\n"
00062 "DESCRIPTION:Project XYZ Review Meeting\n"
00063 "CATEGORIES:MEETING\n"
00064 "CLASS:PRIVATE\n"
00065 "CREATED:20020606T212449\n"
00066 "SUMMARY:XYZ Project Review\n"
00067 "DTSTART;TZID=America/New_York:20020606T212449\n"
00068 "DTEND;TZID=America/New_York:20020606T212449\n"
00069 "LOCATION:1CP Conference Room 4350\n"
00070 "END:VEVENT\n"
00071 "END:VCALENDAR\n";
00072 
00073 
00074 /* Create a new component */
00075 void create_new_component()
00076 {
00077     icalcomponent* calendar;
00078     icalcomponent* timezone;
00079     icalcomponent* tzc;
00080     icalcomponent* event;
00081     struct icaltimetype atime = icaltime_from_timet( 1023398689, 0);
00082     struct icaldatetimeperiodtype rtime;
00083     icalproperty* property;
00084     char *calendar_as_string;
00085 
00086     rtime.period.start = icaltime_from_timet( 1023398689,0);
00087     rtime.period.end = icaltime_from_timet( 1023409689,0);
00088     rtime.period.end.hour++;
00089     rtime.time = icaltime_null_time();
00090 
00091     /* Create calendar and add properties */
00092     calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
00093 
00094     
00095     icalcomponent_add_property(
00096        calendar,
00097        icalproperty_new_version("2.0")
00098        );
00099     
00100     icalcomponent_add_property(
00101        calendar,
00102        icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN")
00103        );
00104     
00105     /* Create a timezone object and add it to the calendar */
00106 
00107     timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT);
00108 
00109     icalcomponent_add_property(
00110        timezone,
00111        icalproperty_new_tzid("America/New_York")
00112        );
00113 
00114     /* Add a sub-component of the timezone */
00115     tzc = icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT);
00116 
00117     icalcomponent_add_property(
00118        tzc, 
00119        icalproperty_new_dtstart(atime)
00120        );
00121 
00122     icalcomponent_add_property(
00123        tzc, 
00124        icalproperty_new_rdate(rtime)
00125        );
00126            
00127     icalcomponent_add_property(
00128        tzc, 
00129        icalproperty_new_tzoffsetfrom(-5*3600)
00130        );
00131 
00132     icalcomponent_add_property(
00133        tzc, 
00134        icalproperty_new_tzoffsetto(-4*3600)
00135        );
00136 
00137     icalcomponent_add_property(
00138        tzc, 
00139        icalproperty_new_tzname("EST")
00140        );
00141 
00142     icalcomponent_add_component(timezone,tzc);
00143 
00144     icalcomponent_add_component(calendar,timezone);
00145 
00146     /* Add a second subcomponent */
00147     tzc = icalcomponent_new(ICAL_XSTANDARD_COMPONENT);
00148 
00149     icalcomponent_add_property(
00150        tzc, 
00151        icalproperty_new_dtstart(atime)
00152        );
00153 
00154     icalcomponent_add_property(
00155        tzc, 
00156        icalproperty_new_rdate(rtime)
00157        );
00158            
00159     icalcomponent_add_property(
00160        tzc, 
00161        icalproperty_new_tzoffsetfrom(-4*3600)
00162        );
00163 
00164     icalcomponent_add_property(
00165        tzc, 
00166        icalproperty_new_tzoffsetto(-5*3600)
00167        );
00168 
00169     icalcomponent_add_property(
00170        tzc, 
00171        icalproperty_new_tzname("EST")
00172        );
00173 
00174     icalcomponent_add_component(timezone,tzc);
00175 
00176     /* Add an event */
00177 
00178     event = icalcomponent_new(ICAL_VEVENT_COMPONENT);
00179 
00180     icalcomponent_add_property(
00181        event,
00182        icalproperty_new_dtstamp(atime)
00183        );
00184 
00185     icalcomponent_add_property(
00186        event,
00187        icalproperty_new_uid("guid-1.host1.com")
00188        );
00189 
00190     /* add a property that has parameters */
00191     property = icalproperty_new_organizer("mrbig@host.com");
00192     
00193     icalproperty_add_parameter(
00194        property,
00195        icalparameter_new_role(ICAL_ROLE_CHAIR)
00196        );
00197 
00198     icalcomponent_add_property(event,property);
00199 
00200     /* add another property that has parameters */
00201     property = icalproperty_new_attendee("employee-A@host.com");
00202     
00203     icalproperty_add_parameter(
00204        property,
00205        icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT)
00206        );
00207 
00208     icalproperty_add_parameter(
00209        property,
00210        icalparameter_new_rsvp(ICAL_RSVP_TRUE)
00211        );
00212 
00213     icalproperty_add_parameter(
00214        property,
00215        icalparameter_new_cutype(ICAL_CUTYPE_GROUP)
00216        );
00217 
00218     icalcomponent_add_property(event,property);
00219 
00220 
00221     /* more properties */
00222 
00223     icalcomponent_add_property(
00224        event,
00225        icalproperty_new_description("Project XYZ Review Meeting")
00226        );
00227 
00228     icalcomponent_add_property(
00229        event,
00230        icalproperty_new_categories("MEETING")
00231        );
00232 
00233     icalcomponent_add_property(
00234        event,
00235        icalproperty_new_class(ICAL_CLASS_PRIVATE)
00236        );
00237     
00238     icalcomponent_add_property(
00239        event,
00240        icalproperty_new_created(atime)
00241        );
00242 
00243     icalcomponent_add_property(
00244        event,
00245        icalproperty_new_summary("XYZ Project Review")
00246        );
00247 
00248 
00249     property = icalproperty_new_dtstart(atime);
00250     
00251     icalproperty_add_parameter(
00252        property,
00253        icalparameter_new_tzid("America/New_York")
00254        );
00255 
00256     icalcomponent_add_property(event,property);
00257 
00258 
00259     property = icalproperty_new_dtend(atime);
00260     
00261     icalproperty_add_parameter(
00262        property,
00263        icalparameter_new_tzid("America/New_York")
00264        );
00265 
00266     icalcomponent_add_property(event,property);
00267 
00268     icalcomponent_add_property(
00269        event,
00270        icalproperty_new_location("1CP Conference Room 4350")
00271        );
00272 
00273     icalcomponent_add_component(calendar,event);
00274     
00275     calendar_as_string = icalcomponent_as_ical_string(calendar);
00276 
00277     is("build large, complex component", 
00278        calendar_as_string,
00279        create_new_component_str);
00280 
00281     if (VERBOSE && calendar)
00282       printf("%s\n",icalcomponent_as_ical_string(calendar));
00283 
00284 
00285     if (calendar)
00286       icalcomponent_free(calendar);
00287 
00288 }
00289 
00290 /* Create a new component, using the va_args list */
00291 
00292 void create_new_component_with_va_args()
00293 {
00294 
00295     icalcomponent* calendar;
00296     struct icaltimetype atime = icaltime_from_timet( time(0),0);
00297     struct icaldatetimeperiodtype rtime;
00298     
00299     rtime.period.start = icaltime_from_timet( time(0),0);
00300     rtime.period.end = icaltime_from_timet( time(0),0);
00301     rtime.period.end.hour++;
00302     rtime.time = icaltime_null_time();
00303 
00304     calendar = 
00305        icalcomponent_vanew(
00306            ICAL_VCALENDAR_COMPONENT,
00307            icalproperty_new_version("2.0"),
00308            icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"),
00309            icalcomponent_vanew(
00310               ICAL_VTIMEZONE_COMPONENT,
00311               icalproperty_new_tzid("America/New_York"),
00312               icalcomponent_vanew(
00313                   ICAL_XDAYLIGHT_COMPONENT,
00314                   icalproperty_new_dtstart(atime),
00315                   icalproperty_new_rdate(rtime),
00316                   icalproperty_new_tzoffsetfrom(-4.0),
00317                   icalproperty_new_tzoffsetto(-5.0),
00318                   icalproperty_new_tzname("EST"),
00319                   0
00320                   ),
00321               icalcomponent_vanew(
00322                   ICAL_XSTANDARD_COMPONENT,
00323                   icalproperty_new_dtstart(atime),
00324                   icalproperty_new_rdate(rtime),
00325                   icalproperty_new_tzoffsetfrom(-5.0),
00326                   icalproperty_new_tzoffsetto(-4.0),
00327                   icalproperty_new_tzname("EST"),
00328                   0
00329                   ),
00330               0
00331               ),
00332            icalcomponent_vanew(
00333               ICAL_VEVENT_COMPONENT,
00334               icalproperty_new_dtstamp(atime),
00335               icalproperty_new_uid("guid-1.host1.com"),
00336               icalproperty_vanew_organizer(
00337                   "mrbig@host.com",
00338                   icalparameter_new_role(ICAL_ROLE_CHAIR),
00339                   0
00340                   ),
00341               icalproperty_vanew_attendee(
00342                   "employee-A@host.com",
00343                   icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT),
00344                   icalparameter_new_rsvp(ICAL_RSVP_TRUE),
00345                   icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
00346                   0
00347                   ),
00348               icalproperty_new_description("Project XYZ Review Meeting"),
00349               icalproperty_new_categories("MEETING"),
00350               icalproperty_new_class(ICAL_CLASS_PUBLIC),
00351               icalproperty_new_created(atime),
00352               icalproperty_new_summary("XYZ Project Review"),
00353               icalproperty_vanew_dtstart(
00354                   atime,
00355                   icalparameter_new_tzid("America/New_York"),
00356                   0
00357                   ),
00358               icalproperty_vanew_dtend(
00359                   atime,
00360                   icalparameter_new_tzid("America/New_York"),
00361                   0
00362                   ),
00363               icalproperty_new_location("1CP Conference Room 4350"),
00364               0
00365               ),
00366            0
00367            );
00368 
00369     ok("creating a complex vcalendar", (calendar != NULL));
00370     if (VERBOSE && calendar)
00371       printf("%s\n",icalcomponent_as_ical_string(calendar));
00372 
00373     icalcomponent_free(calendar);
00374 
00375 }
00376 
00377 static void print_span(int c, struct icaltime_span span ){
00378   printf("span-->%d, %d\n", (int)span.start, (int)span.end);
00379     if (span.start == 0)
00380        printf("#%02d start: (empty)\n",c);
00381     else 
00382        printf("#%02d start: %s\n",c,ical_timet_string(span.start));
00383 
00384     if (span.end == 0)
00385        printf("    end  : (empty)\n");
00386     else 
00387        printf("    end  : %s\n",ical_timet_string(span.end));
00388 
00389 }
00390 
00394 void test_icalcomponent_get_span()
00395 {
00396     time_t tm1 = 973378800; /*Sat Nov  4 23:00:00 UTC 2000,
00397                            Sat Nov  4 15:00:00 PST 2000 */
00398     time_t tm2 = 973382400; /*Sat Nov  5 00:00:00 UTC 2000 
00399                            Sat Nov  4 16:00:00 PST 2000 */
00400     struct icaldurationtype dur;
00401     struct icaltime_span span;
00402     icalcomponent *c;
00403     icaltimezone *azone, *bzone; 
00404     int       tnum = 0;
00405 
00409     span.start = tm1;
00410     span.end = tm2;
00411     if (VERBOSE) print_span(tnum++,span);
00412 
00416     azone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
00417     c = icalcomponent_vanew(
00418            ICAL_VEVENT_COMPONENT,
00419               icalproperty_vanew_dtstart(
00420                   icaltime_from_timet_with_zone(tm1,0,azone),
00421                   icalparameter_new_tzid("America/Los_Angeles"),0),
00422               icalproperty_vanew_dtend(
00423                   icaltime_from_timet_with_zone(tm2,0,azone),
00424                   icalparameter_new_tzid("America/Los_Angeles"),0),
00425            0
00426            );
00427 
00428     span = icalcomponent_get_span(c);
00429     if (VERBOSE) print_span(tnum++,span);
00430     int_is("America/Los_Angeles", span.start, 973407600);
00431     icalcomponent_free(c);
00432 
00437     c = icalcomponent_vanew(
00438            ICAL_VEVENT_COMPONENT,
00439            icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0),0),
00440            icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0),
00441            0
00442            );
00443 
00444     span = icalcomponent_get_span(c);
00445     if (VERBOSE) print_span(tnum++,span);
00446     int_is("floating time", span.start, tm1);
00447 
00448     icalcomponent_free(c);
00449 
00453     azone = icaltimezone_get_builtin_timezone("America/New_York");
00454     c = icalcomponent_vanew(
00455            ICAL_VEVENT_COMPONENT,
00456               icalproperty_vanew_dtstart(
00457                   icaltime_from_timet_with_zone(tm1,0,azone),
00458                   icalparameter_new_tzid("America/New_York"),0),
00459               icalproperty_vanew_dtend(
00460                   icaltime_from_timet_with_zone(tm2,0,azone),
00461                   icalparameter_new_tzid("America/New_York"),0),
00462            0
00463            );
00464 
00465     span = icalcomponent_get_span(c);
00466     if (VERBOSE) print_span(tnum++,span);
00467     int_is("America/New_York", span.start, 973396800);
00468 
00469     icalcomponent_free(c);
00470 
00475     azone = icaltimezone_get_builtin_timezone("America/New_York");
00476     bzone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
00477     c = icalcomponent_vanew(
00478            ICAL_VEVENT_COMPONENT,
00479               icalproperty_vanew_dtstart(
00480                   icaltime_from_timet_with_zone(tm1,0,azone),
00481                   icalparameter_new_tzid("America/New_York"),0),
00482               icalproperty_vanew_dtend(
00483                   icaltime_from_timet_with_zone(tm2,0,bzone),
00484                   icalparameter_new_tzid("America/Los_Angeles"),0),
00485            0
00486            );
00487 
00488     span = icalcomponent_get_span(c);
00489     if (VERBOSE) print_span(tnum++,span);
00490     int_is("America/New_York", span.start, 973396800);
00491     
00492     icalcomponent_free(c);
00493 
00498     azone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
00499     memset(&dur,0,sizeof(dur));
00500     dur.minutes = 30;
00501     c = icalcomponent_vanew(
00502            ICAL_VEVENT_COMPONENT,
00503               icalproperty_vanew_dtstart(
00504                   icaltime_from_timet_with_zone(tm1,0,azone),
00505                   icalparameter_new_tzid("America/Los_Angeles"),0),
00506            icalproperty_new_duration(dur),
00507 
00508            0
00509            );
00510 
00511     span = icalcomponent_get_span(c);
00512     if (VERBOSE) print_span(tnum++,span);
00513     int_is("America/Los_Angeles w/ duration", span.end, 973409400);
00514 
00515     icalcomponent_free(c);
00516 
00517     icalerror_errors_are_fatal = 0;
00521     c = icalcomponent_vanew(
00522            ICAL_VEVENT_COMPONENT,
00523               icalproperty_new_dtstart(icaltime_from_timet(tm1,0)),
00524            0
00525            );
00526 
00527     span = icalcomponent_get_span(c);
00528     if (VERBOSE) print_span(tnum++,span);
00529     int_is("null span", span.start, 0);
00530     icalcomponent_free(c);
00531 
00535     c = icalcomponent_vanew(
00536            ICAL_VEVENT_COMPONENT,
00537               icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
00538               icalproperty_new_dtend(icaltime_from_timet(tm1,1)),
00539            0
00540            );
00541 
00542     span = icalcomponent_get_span(c);
00543     if (VERBOSE) print_span(tnum++,span);
00544     int_is("UTC", span.start, 973296000);
00545     icalcomponent_free(c);
00546 
00550     c = icalcomponent_vanew(
00551            ICAL_VEVENT_COMPONENT,
00552               icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
00553               icalproperty_new_dtend(icaltime_from_timet(tm2,1)),
00554            0
00555            );
00556 
00557     span = icalcomponent_get_span(c);
00558     int_is("UTC #2", span.start, 973296000);
00559     if (VERBOSE) print_span(tnum++,span);
00560 
00561     icalcomponent_free(c);
00562 
00566     c = icalcomponent_vanew(
00567            ICAL_VEVENT_COMPONENT,
00568               icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
00569            0
00570            );
00571 
00572     span = icalcomponent_get_span(c);
00573     if (VERBOSE) print_span(tnum++,span);
00574     int_is("start date only", span.end, 973382399);
00575 
00576     icalcomponent_free(c);
00577 
00578     /* assert(icalerrno == ICAL_MALFORMEDDATA_ERROR); */
00579     icalerror_errors_are_fatal = 1;
00580 }