/* -*- Mode: C -*- ====================================================================== FILE: usecases.c CREATOR: eric 03 April 1999 DESCRIPTION: $Id$ $Locker$ (C) COPYRIGHT 1999 Eric Busboom http://www.softwarestudio.org The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The original author is Eric Busboom The original code is usecases.c ======================================================================*/ #include "ical.h" #include #include /* for strdup */ #include /* for malloc */ #include /* for printf */ #include /* for time() */ #include "icalmemory.h" #include "icaldirset.h" #include "icalfileset.h" #include "icalerror.h" #include "icalrestriction.h" #include "icalcalendar.h" #define OUTPUT_FILE "filesetout.ics" char str[] = "BEGIN:VCALENDAR\n\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ VERSION:2.0\n\ BEGIN:VTIMEZONE\n\ TZID:US-Eastern\n\ BEGIN:STANDARD\n\ DTSTART:19981025T020000\n\ RDATE:19981025T020000\n\ TZOFFSETFROM:-0400\n\ TZOFFSETTO:-0500\n\ TZNAME:EST\n\ END:STANDARD\n\ BEGIN:DAYLIGHT\n\ DTSTART:19990404T020000\n\ RDATE:19990404T020000\n\ TZOFFSETFROM:-0500\n\ TZOFFSETTO:-0400\n\ TZNAME:EDT\n\ END:DAYLIGHT\n\ END:VTIMEZONE\n\ BEGIN:VEVENT\n\ DTSTAMP:19980309T231000Z\n\ UID:guid-1.host1.com\n\ ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\ ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\ DESCRIPTION:Project XYZ Review Meeting\n\ CATEGORIES:MEETING\n\ CLASS:PUBLIC\n\ CREATED:19980309T130000Z\n\ SUMMARY:XYZ Project Review\n\ DTSTART;TZID=US-Eastern:19980312T083000\n\ DTEND;TZID=US-Eastern:19980312T093000\n\ LOCATION:1CP Conference Room 4350\n\ END:VEVENT\n\ BEGIN:BOOGA\n\ DTSTAMP:19980309T231000Z\n\ X-LIC-FOO:Booga\n\ DTSTOMP:19980309T231000Z\n\ UID:guid-1.host1.com\n\ END:BOOGA\n\ END:VCALENDAR"; char str2[] = "BEGIN:VCALENDAR\n\ PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\ VERSION:2.0\n\ BEGIN:VEVENT\n\ DTSTAMP:19980309T231000Z\n\ UID:guid-1.host1.com\n\ ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\ ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\ DESCRIPTION:Project XYZ Review Meeting\n\ CATEGORIES:MEETING\n\ CLASS:PUBLIC\n\ CREATED:19980309T130000Z\n\ SUMMARY:XYZ Project Review\n\ DTSTART;TZID=US-Eastern:19980312T083000\n\ DTEND;TZID=US-Eastern:19980312T093000\n\ LOCATION:1CP Conference Room 4350\n\ END:VEVENT\n\ END:VCALENDAR\n\ "; void test_fileset() { icalfileset *cout; int month = 0; int count=0; struct icaltimetype start, end; icalcomponent *c,*clone, *itr; start = icaltime_from_timet( time(0),0); end = start; end.hour++; cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); c = icalparser_parse_string(str2); assert(c != 0); /* Add data to the file */ for(month = 1; month < 10; month++){ icalcomponent *event; icalproperty *dtstart, *dtend; cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); start.month = month; end.month = month; clone = icalcomponent_new_clone(c); assert(clone !=0); event = icalcomponent_get_first_component(clone,ICAL_VEVENT_COMPONENT); assert(event != 0); dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); assert(dtstart!=0); icalproperty_set_dtstart(dtstart,start); dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); assert(dtend!=0); icalproperty_set_dtend(dtend,end); icalfileset_add_component(cout,clone); icalfileset_commit(cout); icalfileset_free(cout); } /* Print them out */ cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); for (itr = icalfileset_get_first_component(cout); itr != 0; itr = icalfileset_get_next_component(cout)){ icalcomponent *event; icalproperty *dtstart, *dtend; count++; event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), icalproperty_as_ical_string(dtend)); } /* Remove all of them */ icalfileset_free(cout); cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); for (itr = icalfileset_get_first_component(cout); itr != 0; itr = icalfileset_get_next_component(cout)){ icalfileset_remove_component(cout, itr); } icalfileset_free(cout); /* Print them out again */ cout = icalfileset_new(OUTPUT_FILE); assert(cout != 0); count =0; for (itr = icalfileset_get_first_component(cout); itr != 0; itr = icalfileset_get_next_component(cout)){ icalcomponent *event; icalproperty *dtstart, *dtend; count++; event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY); dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY); printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart), icalproperty_as_ical_string(dtend)); } icalfileset_free(cout); } int test_dirset() { icalcomponent *c, *gauge; icalerrorenum error; icalcomponent *itr; icalfileset* cluster; struct icalperiodtype rtime; icaldirset *s = icaldirset_new("store"); int i; assert(s != 0); rtime.start = icaltime_from_timet( time(0),0); cluster = icalfileset_new(OUTPUT_FILE); assert(cluster != 0); #define NUMCOMP 4 /* Duplicate every component in the cluster NUMCOMP times */ icalerror_clear_errno(); for (i = 1; i