Back to index

lightning-sunbird  0.9+nobinonly
regression-cxx.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include "icalparameter_cxx.h"
00005 #include "icalproperty_cxx.h"
00006 #include "vcomponent.h"
00007 #include "regression.h"
00008 
00009 char content[] = "BEGIN:VCALENDAR\n\
00010 VERSION:2.1\n\
00011 BEGIN:VEVENT\n\
00012 UID:abcd12345\n\
00013 DTSTART:20020307T180000Z\n\
00014 DTEND:20020307T190000Z\n\
00015 SUMMARY:Important Meeting\n\
00016 END:VEVENT\n\
00017 END:VCALENDAR";
00018 
00019 void test_cxx(void)
00020 {
00021     ICalProperty            *summProp  = new ICalProperty(ICAL_SUMMARY_PROPERTY);
00022     ICalProperty            *startProp = new ICalProperty(ICAL_DTSTART_PROPERTY);
00023     ICalProperty            *endProp   = new ICalProperty(ICAL_DTEND_PROPERTY);
00024     ICalProperty         *locationProp = new ICalProperty(ICAL_LOCATION_PROPERTY);
00025     ICalProperty            *descProp = new ICalProperty(ICAL_DESCRIPTION_PROPERTY);
00026 
00027     ok("Valid SUMMARY     Property", (summProp != 0));
00028     ok("Valid DTSTART     Property", (startProp != 0));
00029     ok("Valid DTEND       Property", (endProp != 0));
00030     ok("Valid LOCATION    Property", (locationProp != 0));
00031     ok("Valid DESCRIPTION Property", (descProp != 0));
00032 
00033     struct icaltimetype     starttime  = icaltime_from_string("20011221T180000Z");   // UTC time ends in Z
00034     struct icaltimetype     endtime    = icaltime_from_string("20020101T080000Z");   // UTC time ends in Z
00035 
00036     summProp->set_summary("jon said: change dir to c:\\rest\\test\\nest to get the file called <foo.dat>\nthis should be in the next line.");
00037     startProp->set_dtstart(starttime);
00038     endProp->set_dtend(endtime);
00039     locationProp->set_location("SF, California; Seattle, Washington");
00040     descProp->set_description("The best cities on the west coast, hit 'NO' if you don't agree!\n");
00041 
00042     VEvent *vEvent = new VEvent();
00043 
00044     ok("Create a new VEvent", (vEvent!=0));
00045 
00046     vEvent->add_property(summProp);
00047     vEvent->add_property(startProp);
00048     vEvent->add_property(endProp);
00049     vEvent->add_property(locationProp);
00050     vEvent->add_property(descProp);
00051  
00052     // 
00053     is ("vEvent->get_summary()", 
00054        vEvent->get_summary(), 
00055        "jon said: change dir to c:\\rest\\test\\nest to get the file called <foo.dat>\nthis should be in the next line.");
00056 
00057     is ("vEvent->get_dtstart()",
00058        icaltime_as_ical_string(vEvent->get_dtstart()),
00059        "20011221T180000Z");
00060 
00061     is ("vEvent->get_dtend()",
00062        icaltime_as_ical_string(vEvent->get_dtend()),
00063        "20020101T080000Z");
00064 
00065     ok ("vEvent->as_ical_string()",
00066        (vEvent->as_ical_string() != 0));
00067 
00068     if (VERBOSE) {
00069       printf("Summary: %s\n", vEvent->get_summary());
00070       printf("DTSTART: %s\n",  icaltime_as_ical_string(vEvent->get_dtstart()));
00071       printf("DTEND: %s\n",   icaltime_as_ical_string(vEvent->get_dtend()));
00072       printf("LOCATION: %s\n", vEvent->get_location());
00073       printf("DESCRIPTION: %s\n", vEvent->get_description());
00074       
00075       printf("vcomponent: %s", vEvent->as_ical_string());
00076     }
00077 
00078     VComponent ic(icalparser_parse_string((const char*)content));
00079     ok("Parsing component", (ic.is_valid()));
00080 
00081     if (VERBOSE)
00082       printf("%s\n", ic.as_ical_string());
00083 
00084     // component is wrapped within BEGIN:VCALENDAR END:VCALENDAR
00085     // we need to unwrap it.
00086 
00087     VEvent* sub_ic = dynamic_cast<VEvent*>(ic.get_first_component(ICAL_VEVENT_COMPONENT));
00088 
00089     int_is("Getting VEvent subcomponent", 
00090        sub_ic->isa(),
00091        ICAL_VEVENT_COMPONENT);
00092 
00093     while (sub_ic != NULL) {
00094       if (VERBOSE)
00095        printf("subcomponent: %s\n", sub_ic->as_ical_string());
00096       
00097       sub_ic = dynamic_cast<VEvent*>(ic.get_next_component(ICAL_VEVENT_COMPONENT));
00098     }
00099 
00100     VCalendar* cal = new VCalendar();
00101     VAgenda* vAgenda = new VAgenda();
00102 
00103     ok("Create a new VCalendar object", (cal != 0));
00104     ok("Create a new VAgenda object", (vAgenda != 0));
00105 
00106     ICalProperty* prop = new ICalProperty(ICAL_OWNER_PROPERTY);
00107     prop->set_owner("fred@flintstone.net");
00108     vAgenda->add_property(prop);
00109 
00110     prop = new ICalProperty(ICAL_SUMMARY_PROPERTY);
00111     prop->set_summary("CPMain");
00112     vAgenda->add_property(prop);
00113 
00114     prop = new ICalProperty(ICAL_TZID_PROPERTY);
00115     prop->set_tzid("America/Los_Angeles");
00116     vAgenda->add_property(prop);
00117 
00118     cal->add_component(vAgenda);
00119 
00120     ok("Complex VCALENDAR/VAGENDA", (cal->as_ical_string() != 0));
00121 
00122     if (VERBOSE)
00123       printf("vAgenda: %s\n", cal->as_ical_string());
00124 
00125     int caughtException = 0;
00126     try {
00127       string foo = "HFHFHFHF";
00128       VComponent v = VComponent(foo);
00129     } catch (icalerrorenum err) {
00130            if (err == ICAL_BADARG_ERROR) {
00131                   caughtException = 1;
00132             }
00133     }
00134     int_is("Testing exception handling", caughtException, 1);
00135 
00136 }
00137