diff options
Diffstat (limited to 'libical/src/test')
-rw-r--r-- | libical/src/test/.cvsignore | 18 | ||||
-rw-r--r-- | libical/src/test/Makefile.am | 23 | ||||
-rw-r--r-- | libical/src/test/copycluster.c | 113 | ||||
-rw-r--r-- | libical/src/test/findobj.c | 72 | ||||
-rw-r--r-- | libical/src/test/icaltestparser.c | 123 | ||||
-rw-r--r-- | libical/src/test/recur.c | 96 | ||||
-rw-r--r-- | libical/src/test/regression.c | 1568 | ||||
-rw-r--r-- | libical/src/test/storage.c | 465 | ||||
-rw-r--r-- | libical/src/test/stow.c | 849 | ||||
-rw-r--r-- | libical/src/test/testmime.c | 339 | ||||
-rw-r--r-- | libical/src/test/testvcal.c | 56 |
11 files changed, 0 insertions, 3722 deletions
diff --git a/libical/src/test/.cvsignore b/libical/src/test/.cvsignore deleted file mode 100644 index ed72bfe59f..0000000000 --- a/libical/src/test/.cvsignore +++ /dev/null @@ -1,18 +0,0 @@ -*.la -*.lo -.libs -Makefile -Makefile.in -.deps -.libs -copycluster -regression -parser -findobj -storage -stow -recur -testmime -testvcal - - diff --git a/libical/src/test/Makefile.am b/libical/src/test/Makefile.am deleted file mode 100644 index 7fc594ee84..0000000000 --- a/libical/src/test/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ - -noinst_PROGRAMS = copycluster regression parser findobj storage stow recur testmime testvcal - -LDADD = ../libical/libical.a ../libicalss/libicalss.a ../libicalvcal/libicalvcal.a -INCLUDES = \ - -I . \ - -I../libicalvcal \ - -I $(srcdir)/../libicalvcal \ - -I $(srcdir) \ - -I../libical \ - -I $(srcdir)/../libical \ - -I../libicalss \ - -I $(srcdir)/../libicalss - -findobj_SOURCES = findobj.c -copycluster_SOURCES = copycluster.c -regression_SOURCES = regression.c -parser_SOURCES = icaltestparser.c -storage_SOURCES = storage.c -stow_SOURCES = stow.c -testvcal_SOURCES = testvcal.c -recur_SOURCES = recur.c -test_mime = testmime.c diff --git a/libical/src/test/copycluster.c b/libical/src/test/copycluster.c deleted file mode 100644 index 11bd94c62d..0000000000 --- a/libical/src/test/copycluster.c +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: copycluster.c - CREATOR: eric 15 January 2000 - - $Id$ - $Locker$ - - (C) COPYRIGHT 2000 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 Code is eric. The Initial Developer of the Original - Code is Eric Busboom - - - ======================================================================*/ - -#include <stdio.h> /* for printf */ -#include "ical.h" -#include "icalfileset.h" -#include <errno.h> -#include <string.h> /* For strerror */ -#include "icalrestriction.h" - -/* This program copies a file that holds iCal components to an other file. */ - - -void usage(char* arg0) { - printf("usage: %s cluster-file1 cluster-file2\n",arg0); -} - -int main(int c, char *argv[]){ - - icalfileset *clusterin, *clusterout; - icalcomponent *itr; - int count=0; - int tostdout = 0; - - if(c < 2 || c > 3){ - usage(argv[0]); - exit(1); - } - - if (c == 2){ - tostdout = 1; - } - - clusterin = icalfileset_new(argv[1]); - - if (clusterin == 0){ - printf("Could not open input cluster \"%s\"",argv[1]); - - exit(1); - } - - if (!tostdout){ - clusterout = icalfileset_new(argv[2]); - if (clusterout == 0){ - printf("Could not open output cluster \"%s\"\n",argv[2]); - exit(1); - } - } - - - for (itr = icalfileset_get_first_component(clusterin, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(clusterin, - ICAL_ANY_COMPONENT)){ - - icalrestriction_check(itr); - - if (itr != 0){ - - if(tostdout){ - - printf("--------------\n%s\n",icalcomponent_as_ical_string(itr)); - } else { - - icalfileset_add_component(clusterout, - icalcomponent_new_clone(itr)); - } - - count++; - - } else { - printf("Got NULL component"); - } - } - - - printf("Transfered %d components\n",count); - - icalfileset_free(clusterin); - - if (!tostdout){ - icalfileset_mark(clusterout); - icalfileset_free(clusterout); - } - - return 0; -} - diff --git a/libical/src/test/findobj.c b/libical/src/test/findobj.c deleted file mode 100644 index c31101c33d..0000000000 --- a/libical/src/test/findobj.c +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: findobj.c - CREATOR: eric 11 February 2000 - - $Id$ - $Locker$ - - (C) COPYRIGHT 2000 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 Code is eric. The Initial Developer of the Original - Code is Eric Busboom - - - ======================================================================*/ - -#include <stdio.h> /* for printf */ -#include "ical.h" -#include "icalcalendar.h" -#include "icaldirset.h" -#include <errno.h> -#include <string.h> /* For strerror */ -#include "icalrestriction.h" - -/* This program finds an object stored in a calendar */ - -void usage(char* arg0) { - printf("usage: %s calendar-dir uid\n",arg0); -} - -int main(int c, char *argv[]){ - - icalcalendar *cal; - icaldirset *booked; - icalcomponent *itr; - - if(c < 2 || c > 3){ - usage(argv[0]); - exit(1); - } - - cal = icalcalendar_new(argv[1]); - - if(cal == 0){ - fprintf(stderr,"%s: error in opening calendar \"%s\": %s. errno is \"%s\"\n", - argv[0],argv[1],icalerror_strerror(icalerrno), - strerror(errno)); - } - - booked = icalcalendar_get_booked(cal); - - itr = icaldirset_fetch(booked,argv[2]); - - - if(itr != 0){ - printf("%s",icalcomponent_as_ical_string(itr)); - } - - return 0; -} - diff --git a/libical/src/test/icaltestparser.c b/libical/src/test/icaltestparser.c deleted file mode 100644 index 71f91b641f..0000000000 --- a/libical/src/test/icaltestparser.c +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: icaltestparser.c - CREATOR: eric 20 June 1999 - - $Id$ - $Locker$ - - 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 icaltestparser.c - - - (C) COPYRIGHT 1999 The Software Studio. - http://www.softwarestudio.org - - ======================================================================*/ - -#include <stdio.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include "ical.h" - -#include <stdlib.h> - -char str[] = "BEGIN:VCALENDAR\ -PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\ -VERSION:2.0\ -BEGIN:VTIMEZONE\ -TZID:US-Eastern\ -BEGIN:STANDARD\ -DTSTART:19990404T020000\ -RDATE:19990u404xT020000\ -TZOFFSETFROM:-0500\ -TZOFFSETTO:-0400\ -END:STANDARD\ -BEGIN:DAYLIGHT\ -DTSTART:19990404T020000\ -RDATE:19990404T020000\ -TZOFFSETFROM:-0500\ -TZOFFSETTO:-0400\ -TZNAME:EDT\ -Dkjhgri:derhvnv;\ -BEGIN:dfkjh\ -END:dfdfkjh\ -END:DAYLIGHT\ -END:VTIMEZONE\ -BEGIN:VEVENT\ -GEO:Bongo\ -DTSTAMP:19980309T231000Z\ -UID:guid-1.host1.com\ -ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\ -ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP\ - :MAILTO:employee-A@host.com\ -DESCRIPTION:Project XYZ Review Meeting\ -CATEGORIES:MEETING\ -CLASS:PUBLIC\ -CREATED:19980309T130000Z\ -SUMMARY:XYZ Project Review\ -DTSTART;TZID=US-Eastern:19980312T083000\ -DTEND;TZID=US-Eastern:19980312T093000\ -LOCATION:1CP Conference Room 4350\ -END:VEVENT\ -END:VCALENDAR\ -"; - -extern int yydebug; - -/* Have the parser fetch data from stdin */ - -char* read_stream(char *s, size_t size, void *d) -{ - char *c = fgets(s,size, (FILE*)d); - - return c; - -} - - - -int main(int argc, char* argv[]) -{ - - char* line; - FILE* stream; - icalcomponent *c; - icalparser *parser = icalparser_new(); - - stream = fopen(argv[1],"r"); - - assert(stream != 0); - - icalparser_set_gen_data(parser,stream); - - do{ - - line = icalparser_get_line(parser,read_stream); - - c = icalparser_add_line(parser,line); - - - if (c != 0){ - /*icalcomponent_convert_errors(c);*/ - printf("%s",icalcomponent_as_ical_string(c)); - icalparser_claim(parser); - printf("\n---------------\n"); - icalcomponent_free(c); - } - - } while ( line != 0); - - return 0; - } diff --git a/libical/src/test/recur.c b/libical/src/test/recur.c deleted file mode 100644 index 4d3188f9c2..0000000000 --- a/libical/src/test/recur.c +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: recur.c - CREATOR: ebusboom 8jun00 - - DESCRIPTION: - - Test program for expanding recurrences. Run as: - - ./recur ../../test-data/recur.txt - - - (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 <assert.h> -#include <string.h> /* for strdup */ -#include <stdlib.h> /* for malloc */ -#include <stdio.h> /* for printf */ -#include <time.h> /* for time() */ -#include "icalmemory.h" -#include "icaldirset.h" -#include "icalfileset.h" - -int main(int argc, char *argv[]) -{ - icalfileset *cin; - struct icaltimetype start, next; - icalcomponent *itr; - icalproperty *desc, *dtstart, *rrule; - struct icalrecurrencetype recur; - icalrecur_iterator* ritr; - time_t tt; - - cin = icalfileset_new(argv[1]); - assert(cin != 0); - - for (itr = icalfileset_get_first_component(cin, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cin, - ICAL_ANY_COMPONENT)){ - - desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); - assert(desc !=0); - - dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); - assert(dtstart !=0); - - rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); - assert(rrule !=0); - - - recur = icalproperty_get_rrule(rrule); - start = icalproperty_get_dtstart(dtstart); - - ritr = icalrecur_iterator_new(recur,start); - - tt = icaltime_as_timet(start); - - printf("\n\n#### %s\n",icalproperty_get_description(desc)); - printf("#### %s\n",icalvalue_as_ical_string(icalproperty_get_value(rrule))); - printf("#### %s\n",ctime(&tt )); - - for(ritr = icalrecur_iterator_new(recur,start), - next = icalrecur_iterator_next(ritr); - !icaltime_is_null_time(next); - next = icalrecur_iterator_next(ritr)){ - - tt = icaltime_as_timet(next); - - printf(" %s",ctime(&tt )); - - } - - } - - return 0; -} diff --git a/libical/src/test/regression.c b/libical/src/test/regression.c deleted file mode 100644 index dc6a5301f1..0000000000 --- a/libical/src/test/regression.c +++ /dev/null @@ -1,1568 +0,0 @@ -/* -*- 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 <assert.h> -#include <string.h> /* for strdup */ -#include <stdlib.h> /* for malloc */ -#include <stdio.h> /* for printf */ -#include <time.h> /* for time() */ -#include "icalmemory.h" -#include "icalerror.h" -#include "icalrestriction.h" -#include "icalcalendar.h" -#include "icalgauge.h" -#include "icaldirset.h" -#include "icalfileset.h" - -/* This example creates and minipulates the ical object that appears - * in rfc 2445, page 137 */ - -char str[] = "BEGIN:VCALENDAR\ -PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\ -VERSION:2.0\ -BEGIN:VTIMEZONE\ -TZID:US-Eastern\ -BEGIN:STANDARD\ -DTSTART:19981025T020000\ -RDATE:19981025T020000\ -TZOFFSETFROM:-0400\ -TZOFFSETTO:-0500\ -TZNAME:EST\ -END:STANDARD\ -BEGIN:DAYLIGHT\ -DTSTART:19990404T020000\ -RDATE:19990404T020000\ -TZOFFSETFROM:-0500\ -TZOFFSETTO:-0400\ -TZNAME:EDT\ -END:DAYLIGHT\ -END:VTIMEZONE\ -BEGIN:VEVENT\ -DTSTAMP:19980309T231000Z\ -UID:guid-1.host1.com\ -ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\ -ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\ -DESCRIPTION:Project XYZ Review Meeting\ -CATEGORIES:MEETING\ -CLASS:PUBLIC\ -CREATED:19980309T130000Z\ -SUMMARY:XYZ Project Review\ -DTSTART;TZID=US-Eastern:19980312T083000\ -DTEND;TZID=US-Eastern:19980312T093000\ -LOCATION:1CP Conference Room 4350\ -END:VEVENT\ -BEGIN:BOOGA\ -DTSTAMP:19980309T231000Z\ -X-LIC-FOO:Booga\ -DTSTOMP:19980309T231000Z\ -UID:guid-1.host1.com\ -END:BOOGA\ -END:VCALENDAR"; - - -icalcomponent* create_simple_component() -{ - - icalcomponent* calendar; - struct icalperiodtype rtime; - - rtime.start = icaltime_from_timet( time(0),0,0); - rtime.end = icaltime_from_timet( time(0),0,0); - - rtime.end.hour++; - - - - /* Create calendar and add properties */ - calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - return calendar; - -} - -/* Create a new component */ -icalcomponent* create_new_component() -{ - - icalcomponent* calendar; - icalcomponent* timezone; - icalcomponent* tzc; - icalcomponent* event; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); - struct icalperiodtype rtime; - icalproperty* property; - - rtime.start = icaltime_from_timet( time(0),0,0); - rtime.end = icaltime_from_timet( time(0),0,0); - - rtime.end.hour++; - - - - /* Create calendar and add properties */ - calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); - - - icalcomponent_add_property( - calendar, - icalproperty_new_version("2.0") - ); - - icalcomponent_add_property( - calendar, - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN") - ); - - /* Create a timezone object and add it to the calendar */ - - timezone = icalcomponent_new(ICAL_VTIMEZONE_COMPONENT); - - icalcomponent_add_property( - timezone, - icalproperty_new_tzid("US_Eastern") - ); - - /* Add a sub-component of the timezone */ - tzc = icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - icalcomponent_add_component(calendar,timezone); - - /* Add a second subcomponent */ - tzc = icalcomponent_new(ICAL_XSTANDARD_COMPONENT); - - icalcomponent_add_property( - tzc, - icalproperty_new_dtstart(atime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_rdate(rtime) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetfrom(-4.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzoffsetto(-5.0) - ); - - icalcomponent_add_property( - tzc, - icalproperty_new_tzname("EST") - ); - - icalcomponent_add_component(timezone,tzc); - - /* Add an event */ - - event = icalcomponent_new(ICAL_VEVENT_COMPONENT); - - icalcomponent_add_property( - event, - icalproperty_new_dtstamp(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_uid("guid-1.host1.com") - ); - - /* add a property that has parameters */ - property = icalproperty_new_organizer("mrbig@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_CHAIR) - ); - - icalcomponent_add_property(event,property); - - /* add another property that has parameters */ - property = icalproperty_new_attendee("employee-A@host.com"); - - icalproperty_add_parameter( - property, - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_rsvp(1) - ); - - icalproperty_add_parameter( - property, - icalparameter_new_cutype(ICAL_CUTYPE_GROUP) - ); - - icalcomponent_add_property(event,property); - - - /* more properties */ - - icalcomponent_add_property( - event, - icalproperty_new_description("Project XYZ Review Meeting") - ); - - icalcomponent_add_property( - event, - icalproperty_new_categories("MEETING") - ); - - icalcomponent_add_property( - event, - icalproperty_new_class("PUBLIC") - ); - - icalcomponent_add_property( - event, - icalproperty_new_created(atime) - ); - - icalcomponent_add_property( - event, - icalproperty_new_summary("XYZ Project Review") - ); - - - property = icalproperty_new_dtstart(atime); - - icalproperty_add_parameter( - property, - icalparameter_new_tzid("US-Eastern") - ); - - icalcomponent_add_property(event,property); - - - property = icalproperty_new_dtend(atime); - - icalproperty_add_parameter( - property, - icalparameter_new_tzid("US-Eastern") - ); - - icalcomponent_add_property(event,property); - - icalcomponent_add_property( - event, - icalproperty_new_location("1CP Conference Room 4350") - ); - - icalcomponent_add_component(calendar,event); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - icalcomponent_free(calendar); - - return 0; -} - - -/* Create a new component, using the va_args list */ - -icalcomponent* create_new_component_with_va_args() -{ - - icalcomponent* calendar; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); - struct icalperiodtype rtime; - - rtime.start = icaltime_from_timet( time(0),0,0); - rtime.end = icaltime_from_timet( time(0),0,0); - - rtime.end.hour++; - - calendar = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), - icalcomponent_vanew( - ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), - icalcomponent_vanew( - ICAL_XDAYLIGHT_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-4.0), - icalproperty_new_tzoffsetto(-5.0), - icalproperty_new_tzname("EST"), - 0 - ), - icalcomponent_vanew( - ICAL_XSTANDARD_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-5.0), - icalproperty_new_tzoffsetto(-4.0), - icalproperty_new_tzname("EST"), - 0 - ), - 0 - ), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_dtstamp(atime), - icalproperty_new_uid("guid-1.host1.com"), - icalproperty_vanew_organizer( - "mrbig@host.com", - icalparameter_new_role(ICAL_ROLE_CHAIR), - 0 - ), - icalproperty_vanew_attendee( - "employee-A@host.com", - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), - icalparameter_new_rsvp(1), - icalparameter_new_cutype(ICAL_CUTYPE_GROUP), - 0 - ), - icalproperty_new_description("Project XYZ Review Meeting"), - icalproperty_new_categories("MEETING"), - icalproperty_new_class("PUBLIC"), - icalproperty_new_created(atime), - icalproperty_new_summary("XYZ Project Review"), - icalproperty_vanew_dtstart( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ), - icalproperty_vanew_dtend( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ), - icalproperty_new_location("1CP Conference Room 4350"), - 0 - ), - 0 - ); - - printf("%s\n",icalcomponent_as_ical_string(calendar)); - - - icalcomponent_free(calendar); - - return 0; -} - - -/* Return a list of all attendees who are required. */ - -char** get_required_attendees(icalproperty* event) -{ - icalproperty* p; - icalparameter* parameter; - - char **attendees; - int max = 10; - int c = 0; - - attendees = malloc(max * (sizeof (char *))); - - assert(event != 0); - assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); - - for( - p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); - p != 0; - p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY) - ) { - - parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER); - - if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT) - { - attendees[c++] = strdup(icalproperty_get_attendee(p)); - - if (c >= max) { - max *= 2; - attendees = realloc(attendees, max * (sizeof (char *))); - } - - } - } - - return attendees; -} - -/* If an attendee has a PARTSTAT of NEEDSACTION or has no PARTSTAT - parameter, change it to TENTATIVE. */ - -void update_attendees(icalproperty* event) -{ - icalproperty* p; - icalparameter* parameter; - - - assert(event != 0); - assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); - - for( - p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); - p != 0; - p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY) - ) { - - parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER); - - if (parameter == 0) { - - icalproperty_add_parameter( - p, - icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE) - ); - - } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) { - - icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER); - - icalparameter_free(parameter); - - icalproperty_add_parameter( - p, - icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE) - ); - } - - } -} - - -void test_values() -{ - icalvalue *v; - icalvalue *copy; - - v = icalvalue_new_caladdress("cap://value/1"); - printf("caladdress 1: %s\n",icalvalue_get_caladdress(v)); - icalvalue_set_caladdress(v,"cap://value/2"); - printf("caladdress 2: %s\n",icalvalue_get_caladdress(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); - - copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); - icalvalue_free(v); - icalvalue_free(copy); - - - v = icalvalue_new_boolean(1); - printf("caladdress 1: %d\n",icalvalue_get_boolean(v)); - icalvalue_set_boolean(v,2); - printf("caladdress 2: %d\n",icalvalue_get_boolean(v)); - printf("String: %s\n",icalvalue_as_ical_string(v)); - - copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); - icalvalue_free(v); - icalvalue_free(copy); - - - v = icalvalue_new_date(icaltime_from_timet( time(0),0,0)); - printf("date 1: %s\n",icalvalue_as_ical_string(v)); - icalvalue_set_date(v,icaltime_from_timet( time(0)+3600,0,0)); - printf("date 2: %s\n",icalvalue_as_ical_string(v)); - - copy = icalvalue_new_clone(v); - printf("Clone: %s\n",icalvalue_as_ical_string(v)); - icalvalue_free(v); - icalvalue_free(copy); - - - v = icalvalue_new(-1); - - printf("Invalid type: %p\n",v); - - if (v!=0) icalvalue_free(v); - - - /* v = icalvalue_new_caladdress(0); - - printf("Bad string: %p\n",v); - - if (v!=0) icalvalue_free(v); */ - -} - -void test_properties() -{ - icalproperty *prop; - icalparameter *param; - - icalproperty *clone; - - prop = icalproperty_vanew_comment( - "Another Comment", - icalparameter_new_cn("A Common Name 1"), - icalparameter_new_cn("A Common Name 2"), - icalparameter_new_cn("A Common Name 3"), - icalparameter_new_cn("A Common Name 4"), - 0); - - for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); - param != 0; - param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { - - printf("Prop parameter: %s\n",icalparameter_get_cn(param)); - } - - printf("Prop value: %s\n",icalproperty_get_comment(prop)); - - - printf("As iCAL string:\n %s\n",icalproperty_as_ical_string(prop)); - - clone = icalproperty_new_clone(prop); - - printf("Clone:\n %s\n",icalproperty_as_ical_string(prop)); - - icalproperty_free(clone); - icalproperty_free(prop); - - prop = icalproperty_new(-1); - - printf("Invalid type: %p\n",prop); - - if (prop!=0) icalproperty_free(prop); - - /* - prop = icalproperty_new_method(0); - - printf("Bad string: %p\n",prop); - - - if (prop!=0) icalproperty_free(prop); - */ -} - -void test_parameters() -{ - icalparameter *p; - - p = icalparameter_new_cn("A Common Name"); - - printf("Common Name: %s\n",icalparameter_get_cn(p)); - - printf("As String: %s\n",icalparameter_as_ical_string(p)); - - icalparameter_free(p); -} - - -void test_components() -{ - - icalcomponent* c; - icalcomponent* child; - - c = icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), - icalproperty_vanew_comment( - "A Comment", - icalparameter_new_cn("A Common Name 1"), - 0), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_description("This is an event"), - icalproperty_vanew_comment( - "Another Comment", - icalparameter_new_cn("A Common Name 1"), - icalparameter_new_cn("A Common Name 2"), - icalparameter_new_cn("A Common Name 3"), - icalparameter_new_cn("A Common Name 4"), - 0), - icalproperty_vanew_xlicerror( - "This is only a test", - icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), - 0), - - 0 - ), - 0 - ); - - printf("Original Component:\n%s\n\n",icalcomponent_as_ical_string(c)); - - child = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - - printf("Child Component:\n%s\n\n",icalcomponent_as_ical_string(child)); - - icalcomponent_free(c); - -} - -void test_memory() -{ - size_t bufsize = 256; - int i; - char *p; - - char S1[] = "1) When in the Course of human events, "; - char S2[] = "2) it becomes necessary for one people to dissolve the political bands which have connected them with another, "; - char S3[] = "3) and to assume among the powers of the earth, "; - char S4[] = "4) the separate and equal station to which the Laws of Nature and of Nature's God entitle them, "; - char S5[] = "5) a decent respect to the opinions of mankind requires that they "; - char S6[] = "6) should declare the causes which impel them to the separation. "; - char S7[] = "7) We hold these truths to be self-evident, "; - char S8[] = "8) that all men are created equal, "; - -/* char S9[] = "9) that they are endowed by their Creator with certain unalienable Rights, "; - char S10[] = "10) that among these are Life, Liberty, and the pursuit of Happiness. "; - char S11[] = "11) That to secure these rights, Governments are instituted among Men, "; - char S12[] = "12) deriving their just powers from the consent of the governed. "; -*/ - - - char *f, *b1, *b2, *b3, *b4, *b5, *b6, *b7, *b8; - -#define BUFSIZE 1024 - - f = icalmemory_new_buffer(bufsize); - p = f; - b1 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b1, S1); - icalmemory_append_string(&f, &p, &bufsize, b1); - - b2 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b2, S2); - icalmemory_append_string(&f, &p, &bufsize, b2); - - b3 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b3, S3); - icalmemory_append_string(&f, &p, &bufsize, b3); - - b4 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b4, S4); - icalmemory_append_string(&f, &p, &bufsize, b4); - - b5 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b5, S5); - icalmemory_append_string(&f, &p, &bufsize, b5); - - b6 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b6, S6); - icalmemory_append_string(&f, &p, &bufsize, b6); - - b7 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b7, S7); - icalmemory_append_string(&f, &p, &bufsize, b7); - - b8 = icalmemory_tmp_buffer(BUFSIZE); - strcpy(b8, S8); - icalmemory_append_string(&f, &p, &bufsize, b8); - - - printf("1: %p %s \n",b1,b1); - printf("2: %p %s\n",b2,b2); - printf("3: %p %s\n",b3,b3); - printf("4: %p %s\n",b4,b4); - printf("5: %p %s\n",b5,b5); - printf("6: %p %s\n",b6,b6); - printf("7: %p %s\n",b7,b7); - printf("8: %p %s\n",b8,b8); - - - printf("Final: %s\n", f); - - printf("Final buffer size: %d\n",bufsize); - - free(f); - - bufsize = 4; - - f = icalmemory_new_buffer(bufsize); - - memset(f,0,bufsize); - p = f; - - icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'a'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'b'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'c'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'd'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'e'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'f'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'g'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'h'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'i'); - printf("Char-by-Char buffer: %s\n", f); - icalmemory_append_char(&f, &p, &bufsize, 'j'); - printf("Char-by-Char buffer: %s\n", f); - - for(i=0; i<100; i++){ - f = icalmemory_tmp_buffer(bufsize); - - assert(f!=0); - - memset(f,0,bufsize); - sprintf(f,"%d",i); - } -} - - -int test_store() -{ - - icalcomponent *c, *gauge; - icalerrorenum error; - icalcomponent *next, *itr; - icalfileset* cluster; - struct icalperiodtype rtime; - icaldirset *s = icaldirset_new("store"); - int i; - - rtime.start = icaltime_from_timet( time(0),0,0); - - cluster = icalfileset_new("clusterin.vcd"); - - if (cluster == 0){ - printf("Failed to create cluster: %s\n",icalerror_strerror(icalerrno)); - return 0; - } - -#define NUMCOMP 4 - - /* Duplicate every component in the cluster NUMCOMP times */ - - icalerror_clear_errno(); - - for (i = 1; i<NUMCOMP+1; i++){ - - /*rtime.start.month = i%12;*/ - rtime.start.month = i; - rtime.end = rtime.start; - rtime.end.hour++; - - for (itr = icalfileset_get_first_component(cluster, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cluster, - ICAL_ANY_COMPONENT)){ - icalcomponent *clone; - icalproperty *p; - - - if(icalcomponent_isa(itr) != ICAL_VEVENT_COMPONENT){ - continue; - } - - assert(itr != 0); - - /* Change the dtstart and dtend times in the component - pointed to by Itr*/ - - clone = icalcomponent_new_clone(itr); - assert(icalerrno == ICAL_NO_ERROR); - assert(clone !=0); - - /* DTSTART*/ - p = icalcomponent_get_first_property(clone,ICAL_DTSTART_PROPERTY); - assert(icalerrno == ICAL_NO_ERROR); - - if (p == 0){ - p = icalproperty_new_dtstart(rtime.start); - icalcomponent_add_property(clone,p); - } else { - icalproperty_set_dtstart(p,rtime.start); - } - assert(icalerrno == ICAL_NO_ERROR); - - /* DTEND*/ - p = icalcomponent_get_first_property(clone,ICAL_DTEND_PROPERTY); - assert(icalerrno == ICAL_NO_ERROR); - - if (p == 0){ - p = icalproperty_new_dtstart(rtime.end); - icalcomponent_add_property(clone,p); - } else { - icalproperty_set_dtstart(p,rtime.end); - } - assert(icalerrno == ICAL_NO_ERROR); - - printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(clone)); - - error = icaldirset_add_component(s,clone); - - assert(icalerrno == ICAL_NO_ERROR); - - } - - } - - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Submit Income Taxes", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Bastille Day Party", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); - -#if 0 - - - icaldirset_select(s,gauge); - - for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ - - printf("Got one! (%d)\n", count++); - - if (c != 0){ - printf("%s", icalcomponent_as_ical_string(c));; - if (icaldirset_store(s2,c) == 0){ - printf("Failed to write!\n"); - } - icalcomponent_free(c); - } else { - printf("Failed to get component\n"); - } - } - - - icaldirset_free(s2); -#endif - - - for(c = icaldirset_get_first_component(s,ICAL_ANY_COMPONENT); - c != 0; - c = next){ - - next = icaldirset_get_next_component(s,ICAL_ANY_COMPONENT); - - if (c != 0){ - /*icaldirset_remove_component(s,c);*/ - printf("%s", icalcomponent_as_ical_string(c));; - } else { - printf("Failed to get component\n"); - } - - - } - - icaldirset_free(s); - return 0; -} - -int test_compare() -{ - icalvalue *v1, *v2; - icalcomponent *c, *gauge; - - v1 = icalvalue_new_caladdress("cap://value/1"); - v2 = icalvalue_new_clone(v1); - - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_caladdress("A"); - v2 = icalvalue_new_caladdress("B"); - - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_caladdress("B"); - v2 = icalvalue_new_caladdress("A"); - - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_integer(5); - v2 = icalvalue_new_integer(5); - - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_integer(5); - v2 = icalvalue_new_integer(10); - - printf("%d\n",icalvalue_compare(v1,v2)); - - v1 = icalvalue_new_integer(10); - v2 = icalvalue_new_integer(5); - - printf("%d\n",icalvalue_compare(v1,v2)); - - - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_comment( - "Comment", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); - - c = icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_comment( - "Comment", - 0), - 0); - - printf("%s",icalcomponent_as_ical_string(gauge)); - - printf("%d\n",icalgauge_test(c,gauge)); - - return 0; -} - -void test_restriction() -{ - icalcomponent *comp; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); - int valid; - - struct icalperiodtype rtime; - - rtime.start = icaltime_from_timet( time(0),0,0); - rtime.end = icaltime_from_timet( time(0),0,0); - - rtime.end.hour++; - - - /* Property restrictions */ - assert(icalrestriction_get_property_restriction( - ICAL_METHOD_PUBLISH, - ICAL_VEVENT_COMPONENT, - ICAL_SEQUENCE_PROPERTY) == 5); /* ZEROORONE -> 5 */ - - assert(icalrestriction_get_property_restriction( - ICAL_METHOD_PUBLISH, - ICAL_VEVENT_COMPONENT, - ICAL_ATTACH_PROPERTY)==3); /* ZEROPLUS -> 3 */ - - assert(icalrestriction_get_property_restriction( - ICAL_METHOD_DECLINECOUNTER, - ICAL_VEVENT_COMPONENT, - ICAL_SEQUENCE_PROPERTY)==1); /* ZERO -> 1 */ - - /* Component restrictions */ - assert(icalrestriction_get_component_restriction( - ICAL_METHOD_PUBLISH, - ICAL_VJOURNAL_COMPONENT, - ICAL_X_COMPONENT) == 3); /* ZEROPLUS */ - - assert(icalrestriction_get_component_restriction( - ICAL_METHOD_CANCEL, - ICAL_VJOURNAL_COMPONENT, - ICAL_VEVENT_COMPONENT) == 1); /* ZERO */ - - comp = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), - icalproperty_new_method(ICAL_METHOD_REQUEST), - icalcomponent_vanew( - ICAL_VTIMEZONE_COMPONENT, - icalproperty_new_tzid("US_Eastern"), - icalcomponent_vanew( - ICAL_XDAYLIGHT_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-4.0), - icalproperty_new_tzoffsetto(-5.0), - icalproperty_new_tzname("EST"), - 0 - ), - icalcomponent_vanew( - ICAL_XSTANDARD_COMPONENT, - icalproperty_new_dtstart(atime), - icalproperty_new_rdate(rtime), - icalproperty_new_tzoffsetfrom(-5.0), - icalproperty_new_tzoffsetto(-4.0), - icalproperty_new_tzname("EST"), - 0 - ), - 0 - ), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_dtstamp(atime), - icalproperty_new_uid("guid-1.host1.com"), - icalproperty_vanew_organizer( - "mrbig@host.com", - icalparameter_new_role(ICAL_ROLE_CHAIR), - 0 - ), - icalproperty_vanew_attendee( - "employee-A@host.com", - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), - icalparameter_new_rsvp(1), - icalparameter_new_cutype(ICAL_CUTYPE_GROUP), - 0 - ), - icalproperty_new_description("Project XYZ Review Meeting"), - icalproperty_new_categories("MEETING"), - icalproperty_new_class("PUBLIC"), - icalproperty_new_created(atime), - icalproperty_new_summary("XYZ Project Review"), -/* icalproperty_vanew_dtstart( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ),*/ - icalproperty_vanew_dtend( - atime, - icalparameter_new_tzid("US-Eastern"), - 0 - ), - icalproperty_new_location("1CP Conference Room 4350"), - 0 - ), - 0 - ); - - valid = icalrestriction_check(comp); - - printf("#### %d ####\n%s\n",valid, icalcomponent_as_ical_string(comp)); - -} - -void test_calendar() -{ - icalcomponent *comp; - icalfileset *c; - icaldirset *s; - icalcalendar* calendar = icalcalendar_new("calendar"); - icalerrorenum error; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); - - comp = icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_description("This is an event"), - icalproperty_new_dtstart(atime), - icalproperty_vanew_comment( - "Another Comment", - icalparameter_new_cn("A Common Name 1"), - icalparameter_new_cn("A Common Name 2"), - icalparameter_new_cn("A Common Name 3"), - icalparameter_new_cn("A Common Name 4"), - 0), - icalproperty_vanew_xlicerror( - "This is only a test", - icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), - 0), - - 0); - - - s = icalcalendar_get_booked(calendar); - - error = icaldirset_add_component(s,comp); - - assert(error == ICAL_NO_ERROR); - - c = icalcalendar_get_properties(calendar); - - error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); - - assert(error == ICAL_NO_ERROR); - - icalcalendar_free(calendar); - -} - -void test_recur() -{ - icalvalue *v; - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=DAILY;COUNT=5;BYDAY=MO,TU,WE,TH,FR"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=YEARLY;UNTIL=123456T123456;BYSETPOS=-1,2"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=YEARLY;UNTIL=123456T123456;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=MONTHLY;BYDAY=-1MO,TU,WE,TH,FR"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=WEEKLY;INTERVAL=20;WKST=SU;BYDAY=TU"); - - printf("%s\n",icalvalue_as_ical_string(v)); - -} - -void test_recur_expansion() -{ - - icalvalue *v; - - v = icalvalue_new_from_string(ICAL_RECUR_VALUE, - "FREQ=YEARLY;UNTIL=123456T123456;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - icalrecurrencetype_test(); -} - -void test_duration() -{ - - icalvalue *v; - - v = icalvalue_new_from_string(ICAL_DURATION_VALUE, - "PT8H30M"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - icalvalue_free(v); - v = icalvalue_new_from_string(ICAL_PERIOD_VALUE, - "19971015T050000Z/PT8H30M"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - icalvalue_free(v); - v = icalvalue_new_from_string(ICAL_PERIOD_VALUE, - "19971015T050000Z/19971015T060000Z"); - - printf("%s\n",icalvalue_as_ical_string(v)); - icalvalue_free(v); - - -} - - -void test_strings(){ - - icalvalue *v; - - v = icalvalue_new_text("foo;bar;bats"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - icalvalue_free(v); - - v = icalvalue_new_text("foo\\;b\nar\\;ba\tts"); - - printf("%s\n",icalvalue_as_ical_string(v)); - - icalvalue_free(v); - - -} - -void test_requeststat() -{ - icalrequeststatus s; - struct icalreqstattype st, st2; - char temp[1024]; - - s = icalenum_num_to_reqstat(2,1); - - assert(s == ICAL_2_1_FALLBACK_STATUS); - - assert(icalenum_reqstat_major(s) == 2); - assert(icalenum_reqstat_minor(s) == 1); - - printf("2.1: %s\n",icalenum_reqstat_desc(s)); - - st.code = s; - st.debug = "booga"; - st.desc = 0; - - printf("%s\n",icalreqstattype_as_string(st)); - - st.desc = " A non-standard description"; - - printf("%s\n",icalreqstattype_as_string(st)); - - - st.desc = 0; - - sprintf(temp,"%s\n",icalreqstattype_as_string(st)); - - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); - - printf("%d -- %d -- %s -- %s\n",icalenum_reqstat_major(st2.code), - icalenum_reqstat_minor(st2.code), - icalenum_reqstat_desc(st2.code), - st2.debug); - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;booga"); - printf("%s\n",icalreqstattype_as_string(st2)); - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values.;"); - printf("%s\n",icalreqstattype_as_string(st2)); - - st2 = icalreqstattype_from_string("2.1;Success but fallback taken on one or more property values."); - printf("%s\n",icalreqstattype_as_string(st2)); - - st2 = icalreqstattype_from_string("2.1;"); - printf("%s\n",icalreqstattype_as_string(st2)); - - st2 = icalreqstattype_from_string("2.1"); - printf("%s\n",icalreqstattype_as_string(st2)); - - st2 = icalreqstattype_from_string("16.4"); - assert(st2.code == ICAL_UNKNOWN_STATUS); - - st2 = icalreqstattype_from_string("1."); - assert(st2.code == ICAL_UNKNOWN_STATUS); - -} - - -void test_time() -{ - struct icaltimetype ictt; - time_t tt,tt2; - icalvalue *v; - short day_of_week,start_day_of_week, day_of_year; - - - tt = time(0); - - printf("System time is: %s\n",ctime(&tt)); - - ictt = icaltime_from_timet(tt,0,0); - - v = icalvalue_new_datetime(ictt); - - printf("System time from libical: %s\n",icalvalue_as_ical_string(v)); - - tt2 = icaltime_as_timet(ictt); - printf("Converted back to libc: %s\n",ctime(&tt2)); - - - ictt.year++; - tt2 = icaltime_as_timet(ictt); - printf("Add a year: %s\n",ctime(&tt2)); - - ictt.month+=13; - tt2 = icaltime_as_timet(ictt); - printf("Add 13 months: %s\n",ctime(&tt2)); - - ictt.second+=90; - tt2 = icaltime_as_timet(ictt); - printf("Add 90 seconds: %s\n",ctime(&tt2)); - - ictt = icaltime_from_timet(tt,0,0); - - - day_of_week = icaltime_day_of_week(ictt); - start_day_of_week = icaltime_start_doy_of_week(ictt); - day_of_year = icaltime_day_of_year(ictt); - - printf("Today is day of week %d, day of year %d\n",day_of_week,day_of_year); - printf("Week started n doy of %d\n",start_day_of_week); - - -} - -void test_iterators() -{ - icalcomponent *c,*inner,*next; - icalcompiter i; - - c= icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("1"),0), - icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("2"),0), - icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("3"),0), - icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("4"),0), - icalcomponent_vanew(ICAL_VTODO_COMPONENT, - icalproperty_vanew_version("5"),0), - icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("6"),0), - icalcomponent_vanew(ICAL_VEVENT_COMPONENT, - icalproperty_vanew_version("7"),0), - icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("8"),0), - icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("9"),0), - icalcomponent_vanew(ICAL_VJOURNAL_COMPONENT, - icalproperty_vanew_version("10"),0), - 0); - - printf("1: "); - - /* List all of the VEVENTS */ - for(i = icalcomponent_begin_component(c,ICAL_VEVENT_COMPONENT); - icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){ - - icalcomponent *this = icalcompiter_deref(&i); - - icalproperty *p = - icalcomponent_get_first_property(this, - ICAL_VERSION_PROPERTY); - char* s = icalproperty_get_version(p); - - printf("%s ",s); - - } - - printf("\n2: "); - -#if 0 - for(inner = icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - inner != 0; - inner = next){ - - next = icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); - - icalcomponent_remove_component(c,inner); - - icalcomponent_free(inner); - } -#endif - - /* Delete all of the VEVENTS */ - /* reset iterator */ - icalcomponent_get_first_component(c,ICAL_VEVENT_COMPONENT); - - while((inner=icalcomponent_get_current_component(c)) != 0 ){ - if(icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT){ - icalcomponent_remove_component(c,inner); - } else { - icalcomponent_get_next_component(c,ICAL_VEVENT_COMPONENT); - } - } - - - - /* List all remaining components */ - for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); - inner != 0; - inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){ - - - icalproperty *p = - icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); - - char* s = icalproperty_get_version(p); - - printf("%s ",s); - } - - printf("\n3: "); - - - /* Remove all remaining components */ - for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); - inner != 0; - inner = next){ - - icalcomponent *this; - icalproperty *p; - char* s; - next = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT); - - p=icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); - s = icalproperty_get_version(p); - printf("rem:%s ",s); - - icalcomponent_remove_component(c,inner); - - this = icalcomponent_get_current_component(c); - - if(this != 0){ - p=icalcomponent_get_first_property(this,ICAL_VERSION_PROPERTY); - s = icalproperty_get_version(p); - printf("next:%s; ",s); - } - - icalcomponent_free(inner); - } - - printf("\n4: "); - - - /* List all remaining components */ - for(inner = icalcomponent_get_first_component(c,ICAL_ANY_COMPONENT); - inner != 0; - inner = icalcomponent_get_next_component(c,ICAL_ANY_COMPONENT)){ - - icalproperty *p = - icalcomponent_get_first_property(inner,ICAL_VERSION_PROPERTY); - - char* s = icalproperty_get_version(p); - - printf("%s ",s); - } - - printf("\n"); -} - -int main(int argc, char *argv[]) -{ - - printf("\n------------Test Memory---------------\n"); - test_memory(); - -exit(0); - - - printf("\n------------Test Iterators-----------\n"); - test_iterators(); - - - printf("\n------------Test time----------------\n"); - test_time(); - - printf("\n------------Test Restriction---------------\n"); - test_restriction(); - - printf("\n------------Test request status-------\n"); - test_requeststat(); - - printf("\n------------Test strings---------------\n"); - test_strings(); - - printf("\n------------Test recur---------------\n"); - test_recur(); - - printf("\n------------Test duration---------------\n"); - test_duration(); - - printf("\n------------Test Compare---------------\n"); - test_compare(); - - printf("\n------------Test Values---------------\n"); - test_values(); - - printf("\n------------Test Parameters-----------\n"); - test_parameters(); - - printf("\n------------Test Properties-----------\n"); - test_properties(); - - printf("\n------------Test Components ----------\n"); - test_components(); - - printf("\n------------Create Components --------\n"); - create_new_component(); - - printf("\n----- Create Components with vaargs ---\n"); - create_new_component_with_va_args(); - - - - - return 0; -} - - - diff --git a/libical/src/test/storage.c b/libical/src/test/storage.c deleted file mode 100644 index d53001b574..0000000000 --- a/libical/src/test/storage.c +++ /dev/null @@ -1,465 +0,0 @@ -/* -*- 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 <assert.h> -#include <string.h> /* for strdup */ -#include <stdlib.h> /* for malloc */ -#include <stdio.h> /* for printf */ -#include <time.h> /* 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,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, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cout, - ICAL_ANY_COMPONENT)){ - - 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, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cout, - ICAL_ANY_COMPONENT)){ - - - 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, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cout, - ICAL_ANY_COMPONENT)){ - - 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,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<NUMCOMP+1; i++){ - - /*rtime.start.month = i%12;*/ - rtime.start.month = i; - rtime.end = rtime.start; - rtime.end.hour++; - - for (itr = icalfileset_get_first_component(cluster, - ICAL_ANY_COMPONENT); - itr != 0; - itr = icalfileset_get_next_component(cluster, - ICAL_ANY_COMPONENT)){ - icalcomponent *clone, *inner; - icalproperty *p; - - inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); - if (inner == 0){ - continue; - } - - /* Change the dtstart and dtend times in the component - pointed to by Itr*/ - - clone = icalcomponent_new_clone(itr); - inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT); - - assert(icalerrno == ICAL_NO_ERROR); - assert(inner !=0); - - /* DTSTART*/ - p = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY); - assert(icalerrno == ICAL_NO_ERROR); - - if (p == 0){ - p = icalproperty_new_dtstart(rtime.start); - icalcomponent_add_property(inner,p); - } else { - icalproperty_set_dtstart(p,rtime.start); - } - assert(icalerrno == ICAL_NO_ERROR); - - /* DTEND*/ - p = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY); - assert(icalerrno == ICAL_NO_ERROR); - - if (p == 0){ - p = icalproperty_new_dtstart(rtime.end); - icalcomponent_add_property(inner,p); - } else { - icalproperty_set_dtstart(p,rtime.end); - } - assert(icalerrno == ICAL_NO_ERROR); - - printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner)); - - error = icaldirset_add_component(s, - icalcomponent_new_clone(itr)); - - assert(icalerrno == ICAL_NO_ERROR); - - } - - } - - gauge = - icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Submit Income Taxes", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_vanew_summary( - "Bastille Day Party", - icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL), - 0), - 0), - 0); - -#if 0 - - - icaldirset_select(s,gauge); - - for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){ - - printf("Got one! (%d)\n", count++); - - if (c != 0){ - printf("%s", icalcomponent_as_ical_string(c));; - if (icaldirset_store(s2,c) == 0){ - printf("Failed to write!\n"); - } - icalcomponent_free(c); - } else { - printf("Failed to get component\n"); - } - } - - - icaldirset_free(s2); -#endif - - - for(c = icaldirset_get_first_component(s,ICAL_ANY_COMPONENT); - c != 0; - c = icaldirset_get_next_component(s,ICAL_ANY_COMPONENT)){ - - if (c != 0){ - printf("%s", icalcomponent_as_ical_string(c));; - } else { - printf("Failed to get component\n"); - } - - } - - /* Remove all of the components */ - i=0; - while((c=icaldirset_get_current_component(s)) != 0 ){ - i++; - - icaldirset_remove_component(s,c); - } - - - icaldirset_free(s); - return 0; -} - -void test_calendar() -{ - icalcomponent *comp; - icalfileset *c; - icaldirset *s; - icalcalendar* calendar = icalcalendar_new("calendar"); - icalerrorenum error; - struct icaltimetype atime = icaltime_from_timet( time(0),0,0); - - comp = icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_version("2.0"), - icalproperty_new_description("This is an event"), - icalproperty_new_dtstart(atime), - icalproperty_vanew_comment( - "Another Comment", - icalparameter_new_cn("A Common Name 1"), - icalparameter_new_cn("A Common Name 2"), - icalparameter_new_cn("A Common Name 3"), - icalparameter_new_cn("A Common Name 4"), - 0), - icalproperty_vanew_xlicerror( - "This is only a test", - icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR), - 0), - - 0); - - - s = icalcalendar_get_booked(calendar); - - error = icaldirset_add_component(s,comp); - - assert(error == ICAL_NO_ERROR); - - c = icalcalendar_get_properties(calendar); - - error = icalfileset_add_component(c,icalcomponent_new_clone(comp)); - - assert(error == ICAL_NO_ERROR); - - icalcalendar_free(calendar); - -} - - -int main(int argc, char *argv[]) -{ - -/* printf("\n------------Test File Set---------------\n"); - test_fileset(); */ - - printf("\n------------Test Dir Set---------------\n"); - test_dirset(); - -#if 0 - - - printf("\n------------Test Calendar---------------\n"); - test_calendar(); - -#endif - - return 0; -} - - - diff --git a/libical/src/test/stow.c b/libical/src/test/stow.c deleted file mode 100644 index f742b417a5..0000000000 --- a/libical/src/test/stow.c +++ /dev/null @@ -1,849 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: stow.c - CREATOR: eric 29 April 2000 - - $Id$ - $Locker$ - - (C) COPYRIGHT 2000 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 Initial Developer of the Original Code is Eric Busboom - - ======================================================================*/ - - -#include <stdio.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <limits.h> /* for PATH_MAX */ -#include <assert.h> -#include <stdlib.h> -#include <sys/utsname.h> /* for uname */ -#include <sys/stat.h> /* for stat */ -#include <unistd.h> /* for stat, getpid, getopt */ -#include <pwd.h> /* For getpwent */ -#include <sys/types.h> /* For getpwent */ -#include <ctype.h> /* for tolower */ - -#include "ical.h" -#include "icalcalendar.h" -#include "icalfileset.h" -#include "icalmime.h" - -char* program_name; -#define TMPSIZE 2048 -#define SENDMAIL "/usr/lib/sendmail -t" - -enum options { - STORE_IN_FILE, - STORE_IN_DB, - INPUT_IS_MIME, - INPUT_IS_ICAL, - INPUT_FROM_STDIN, - INPUT_FROM_FILE, - ERRORS_TO_STDOUT, - ERRORS_TO_ORGANIZER -}; - -struct options_struct -{ - enum options storage; - enum options input_type; - enum options input_source; - enum options errors; - char* input_file; - char* calid; - char* output_file; -}; - - -enum file_type -{ - ERROR, - NO_FILE, - DIRECTORY, - REGULAR, - OTHER -}; - -enum file_type test_file(char *path) -{ - struct stat sbuf; - enum file_type type; - - errno = 0; - - /* Check if the path already exists and if it is a directory*/ - if (stat(path,&sbuf) != 0){ - - /* A file by the given name does not exist, or there was - another error */ - if(errno == ENOENT) - { - type = NO_FILE; - } else { - type = ERROR; - } - - } else { - /* A file by the given name exists, but is it a directory? */ - - if (S_ISDIR(sbuf.st_mode)){ - type = DIRECTORY; - } else if(S_ISREG(sbuf.st_mode)){ - type = REGULAR; - } else { - type = OTHER; - } - } - - return type; -} - -char* lowercase(char* str) -{ - char* p = 0; - char* new = strdup(str); - - if(str ==0){ - return 0; - } - - for(p = new; *p!=0; p++){ - *p = tolower(*p); - } - - return new; -} - -#if 0 -char* get_local_attendee(struct options_struct *opt) -{ - char attendee[PATH_MAX]; - - if(opt->calid){ - - strncpy(attendee,opt->calid,PATH_MAX); - - } else { - - char* user = getenv("USER"); - struct utsname uts; - uname(&utget_option); - /* HACK nodename may not be a fully qualified domain name */ - snprintf(attendee,PATH_MAX,"%s@%s",user,uts.nodename); - - } - - return lowercase(attendee); -} -#endif - -void usage(char *message) -{ - fprintf(stderr,"Usage: %s [-emdcn] [-i inputfile] [-o outputfile] [-u calid]\n",program_name); - -} - -icalcomponent* get_first_real_component(icalcomponent *comp) -{ - icalcomponent *c; - - for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT); - c != 0; - c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){ - if (icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT || - icalcomponent_isa(c) == ICAL_VTODO_COMPONENT || - icalcomponent_isa(c) == ICAL_VJOURNAL_COMPONENT ) - { - return c; - } - } - - return 0; -} - - - -char* make_mime(char* to, char* from, char* subject, - char* text_message, char* method, char* ical_message) -{ - size_t size = strlen(to)+strlen(from)+strlen(subject)+ - strlen(text_message)+ strlen(ical_message)+TMPSIZE; - - char mime_part_1[TMPSIZE]; - char mime_part_2[TMPSIZE]; - char content_id[TMPSIZE]; - char boundary[TMPSIZE]; - struct utsname uts; - char* m; - - - if ((m = malloc(sizeof(char)*size)) == 0){ - fprintf(stderr,"%s: Can't allocate memory: %s\n",program_name,strerror(errno)); - exit(1); - } - - uname(&uts); - - srand(time(0)<<getpid()); - sprintf(content_id,"%d-%d@%s",(int)time(0),rand(),uts.nodename); - sprintf(boundary,"%d-%d-%s",(int)time(0),rand(),uts.nodename); - - sprintf(mime_part_1,"Content-ID: %s\n\ -Content-type: text/plain\n\ -Content-Description: Text description of error message\n\n\ -%s\n\n--%s", - content_id,text_message,boundary); - - if(ical_message != 0 && method != 0){ - sprintf(mime_part_2,"Content-ID: %s\n\ -Content-type: text/calendar; method=%s\n\ -Content-Description: iCal component reply\n\n\ -%s\n\n--%s--", - content_id,method,ical_message,boundary); - } - - sprintf(m,"To: %s\n\ -From: %s\n\ -Subject: %s\n\ -MIME-Version: 1.0\n\ -Content-ID: %s\n\ -Content-Type: multipart/mixed; boundary=\"%s\"\n\ -\n\ - This is a multimedia message in MIME format\n\ -\n\ ---%s -%s -", - to,from,subject,content_id,boundary,boundary, - mime_part_1); - - if(ical_message != 0 && method != 0){ - strcat(m, mime_part_2); - } else { - strcat(m,"--\n"); - } - - return m; -} - -/* The incoming component had fatal errors */ -void return_failure(icalcomponent* comp, char* message, - struct options_struct *opt) -{ - char* local_attendee = opt->calid; - FILE* p; - - icalcomponent *inner = get_first_real_component(comp); - - icalproperty *organizer_prop = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); - char *organizer = icalproperty_get_organizer(organizer_prop); - - organizer += 7; - - if (opt->errors == ERRORS_TO_ORGANIZER){ - p = popen(SENDMAIL,"w"); - } else { - p = stdout; - } - - if(p == 0){ - fprintf(stderr, - "%s: fatal. Could not open pipe to sendmail (\"%s\") \n", - program_name,SENDMAIL); - exit(1); - } - - fputs(make_mime(organizer, local_attendee, "iMIP error", - message, "reply", - icalcomponent_as_ical_string(comp)),p); - - if (opt->errors == ERRORS_TO_ORGANIZER){ - pclose(p); - } -} - -/* The program had a fatal error and could not process the incoming component*/ -void return_error(icalcomponent* comp, char* message, struct options_struct *opt) -{ - - - fputs(make_mime("Dest", "Source", "iMIP system failure", - message, 0,0),stdout); - -} - -icalcomponent* make_reply(icalcomponent *comp, icalproperty *return_status, - struct options_struct *opt) - -{ - icalcomponent *reply, *rinner; - icalcomponent *inner = get_first_real_component(comp); - icalproperty *p=0; - char* local_attendee = opt->calid; - char attendee[TMPSIZE]; - - char prodid[TMPSIZE]; - - snprintf(attendee,TMPSIZE,"mailto:%s",local_attendee); - - snprintf(prodid,TMPSIZE,"-//Softwarestudio.org//%s version %s//EN",ICAL_PACKAGE,ICAL_VERSION); - - /* Create the base component */ - reply = icalcomponent_vanew( - ICAL_VCALENDAR_COMPONENT, - icalproperty_new_version(strdup("2.0")), - icalproperty_new_prodid(strdup(prodid)), - icalproperty_new_method(ICAL_METHOD_REPLY), - icalcomponent_vanew( - ICAL_VEVENT_COMPONENT, - icalproperty_new_clone( - icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY)), - icalproperty_new_clone( - icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY)), - icalproperty_new_clone( - icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY)), - icalproperty_new_attendee(attendee), - 0), - 0); - - - /* Convert errors into request-status properties and transfers - them to the reply component */ - - icalcomponent_convert_errors(comp); - - rinner = get_first_real_component(reply); - - for(p = icalcomponent_get_first_property(inner, - ICAL_REQUESTSTATUS_PROPERTY); - p != 0; - p = icalcomponent_get_next_property(inner, - ICAL_REQUESTSTATUS_PROPERTY)){ - - icalcomponent_add_property(rinner,icalproperty_new_clone(p)); - } - - if(return_status != 0){ - icalcomponent_add_property(rinner, return_status); - } - - return reply; - -} - -int check_attendee(icalproperty *p, struct options_struct *opt){ - char* s = icalproperty_get_attendee(p); - char* lower_attendee = lowercase(s); - char* local_attendee = opt->calid; - - /* Check that attendee begins with "mailto:" */ - if (strncmp(lower_attendee,"mailto:",7) == 0){ - /* skip over the mailto: part */ - lower_attendee += 7; - - if(strcmp(lower_attendee,local_attendee) == 0){ - return 1; - } - - lower_attendee -= 7; - - free(lower_attendee); - } - - return 0; -} - -char static_component_error_str[PATH_MAX]; -char* check_component(icalcomponent* comp, icalproperty **return_status, - struct options_struct *opt) -{ - char* component_error_str=0; - icalcomponent* inner; - int errors = 0; - icalproperty *p; - int found_attendee = 0; - - *return_status = 0; - - /* This do/while loop only executes once because it is being used - to fake exceptions */ - - do { - - /* Check that we actually got a component */ - if(comp == 0){ - strcpy(static_component_error_str, - "Did not find a component"); - component_error_str = static_component_error_str; - break; - } - - /* Check that the root component is a VCALENDAR */ - if(icalcomponent_isa(comp) != ICAL_VCALENDAR_COMPONENT){ - strcpy(static_component_error_str, - "Root component is not a VCALENDAR"); - component_error_str = static_component_error_str; - break; - } - - - /* Check that the component has a METHOD */ - - if (icalcomponent_get_first_property(comp,ICAL_METHOD_PROPERTY) == 0) - { - strcpy(static_component_error_str, - "Component does not have a METHOD property"); - component_error_str = static_component_error_str; - break; - } - - inner = get_first_real_component(comp); - - - /* Check that the compopnent has an organizer */ - if(icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY) == 0){ - fprintf(stderr,"%s: fatal. Component does not have an ORGANIZER property\n",program_name); - - exit(1); - } - - - /* Check for this user as an attendee or organizer */ - - for(p = icalcomponent_get_first_property(inner,ICAL_ATTENDEE_PROPERTY); - p != 0; - p = icalcomponent_get_next_property(inner,ICAL_ATTENDEE_PROPERTY)){ - - found_attendee += check_attendee(p,opt); - } - - for(p = icalcomponent_get_first_property(inner,ICAL_ORGANIZER_PROPERTY); - p != 0; - p = icalcomponent_get_next_property(inner,ICAL_ORGANIZER_PROPERTY)){ - - found_attendee += check_attendee(p,opt); - } - - if (found_attendee == 0){ - struct icalreqstattype rs; - char* rs_string; - memset(static_component_error_str,0,PATH_MAX); - - snprintf(static_component_error_str,PATH_MAX, - "This target user (%s) is not listed as an attendee or organizer", - opt->calid ); - component_error_str = static_component_error_str; - - rs.code = ICAL_3_7_INVCU_STATUS; - rs.desc = 0; - rs.debug = component_error_str; - rs_string = icalreqstattype_as_string(rs); - - *return_status = icalproperty_new_requeststatus(rs_string); - - break; - } - - - - /* Check that the component passes iTIP restrictions */ - - errors = icalcomponent_count_errors(comp); - icalrestriction_check(comp); - - if(errors != icalcomponent_count_errors(comp)){ - snprintf(static_component_error_str,PATH_MAX, - "The component does not conform to iTIP restrictions.\n Here is the original component; look at the X-LIC-ERROR properties\nfor details\n\n%s",icalcomponent_as_ical_string(comp)); - component_error_str = static_component_error_str; - break; - } - - - - } while(0); - - return component_error_str; -} - - -void get_options(int argc, char* argv[], struct options_struct *opt) -{ - int c; - extern char *optarg; - extern int optind, optopt; - int errflg=0; - - opt->storage = STORE_IN_FILE; - opt->input_source = INPUT_FROM_STDIN; - opt->input_type = INPUT_IS_ICAL; - opt->input_file = 0; - opt->errors = ERRORS_TO_ORGANIZER; - opt->calid = 0; - opt->output_file = 0; - - - while ((c = getopt(argc, argv, "nemu:o:d:b:c:i:")) != -1) { - switch (c) { - case 'e': { /* Input data is MIME encapsulated */ - opt->input_type = INPUT_IS_MIME; - break; - } - case 'm': { /* Input is iCal. Default*/ - opt->input_type = INPUT_IS_ICAL; - break; - } - case 'i': { /* Input comes from named file */ - opt->input_source = INPUT_FROM_FILE; - opt->input_file = strdup(optarg); - break; - } - case 'o': { /* Output goes to named file. Default*/ - opt->output_file = strdup(optarg); - opt->storage = STORE_IN_FILE; - break; - } - case 'd': { /* Output goes to database */ - fprintf(stderr,"%s: option -d is unimplmented\n",program_name); - opt->storage = STORE_IN_DB; - errflg++; - break; - } - case 'c': { - - break; - } - case 'u': { /* Set the calid for the output database or - file. Default is user name of user running - program */ - opt->calid = strdup(optarg); - break; - } - - case 'n': { /* Dump error to stdout. Default is to - send error to the organizer specified - in the iCal data */ - opt->errors = ERRORS_TO_STDOUT; - break; - } - - case ':': {/* Option given without an operand */ - fprintf(stderr, - "%s: Option -%c requires an operand\n", - program_name,optopt); - errflg++; - break; - } - case '?': { - errflg++; - } - - } - - if (errflg >0){ - usage(""); - exit(1); - } - } - - if(opt->calid == 0){ - /* If no calid specified, use username */ - char attendee[PATH_MAX]; - char* user = getenv("USER"); - struct utsname uts; - uname(&uts); - /* HACK nodename may not be a fully qualified domain name */ - snprintf(attendee,PATH_MAX,"%s@%s",user,uts.nodename); - - opt->calid = lowercase(attendee); - } - - if(opt->storage == STORE_IN_FILE && - opt->output_file ==0){ - char file[PATH_MAX]; - char* user = getenv("USER"); - struct passwd *pw; - - if(!user){ - fprintf(stderr,"%s: Can't get username. Try explicitly specifing the output file with -o", program_name); - exit(1); - } - - /* Find password entry for user */ - while( (pw = getpwent())!=0){ - if(strcmp(user,pw->pw_name)==0){ - break; - } - } - - if(pw==0){ - fprintf(stderr,"%s: Can't get get password entry for user \"%s\" Try explicitly specifing the output file with -o", - program_name,user); - exit(1); - } - - if(pw->pw_dir==0){ - fprintf(stderr,"%s: User \"%s\" has no home directory. Try explicitly specifing the output file with -o", - program_name, user); - exit(1); - } - - snprintf(file,PATH_MAX,"%s/.facs/%s",pw->pw_dir,opt->calid); - - opt->output_file = strdup(file); - } - - - /* Now try to create the calendar directory if it does - not exist */ - - if(opt->storage == STORE_IN_FILE ) { - char * p; - char* facspath = strdup(opt->output_file); - enum file_type type; - - /* Cut off the last slash to make it just a directoy */ - - p = strrchr(facspath,'/'); - - if (p == 0){ - fprintf(stderr,"%s: Invalid calendar filename \"%s\"", - program_name,facspath); - exit(1); - } - - *p='\0'; - - type = test_file(facspath); - - errno = 0; - if (type == NO_FILE){ - - if(mkdir(facspath,0775) != 0){ - fprintf(stderr, - "%s: Failed to create calendar directory %s: %s\n", - program_name,facspath, strerror(errno)); - exit(1); - } else { - fprintf(stderr,"%s: Creating calendar directory %s\n", - program_name,facspath); - } - - } else if(type==REGULAR || type == ERROR){ - fprintf(stderr,"%s: Cannot create calendar directory %s\n", - program_name,facspath); - exit(1); - } - } -} - -char* check_options(struct options_struct *opt) -{ - return 0; -} - -void store_component(icalcomponent *comp, struct options_struct *opt) -{ - icalerrorenum error; - - - if(opt->storage == STORE_IN_FILE){ - icalfileset *fs = icalfileset_new(opt->output_file); - - if (fs == 0){ - fprintf(stderr, - "%s: Failed to get incoming component directory: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); - } - - - error = icalfileset_add_component(fs,comp); - - if (error != ICAL_NO_ERROR){ - fprintf(stderr,"%s: Failed to write incoming component: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); - } - - error = icalfileset_commit(fs); - - if (error != ICAL_NO_ERROR){ - fprintf(stderr,"%s: Failed to commit incoming cluster: %s\n", - program_name, icalerror_strerror(icalerrno)); - exit(1); - } - - icalfileset_free(fs); - - return; - } else { - assert(0); - } -} - -char* read_stream(char *s, size_t size, void *d) -{ - char *c = fgets(s,size, (FILE*)d); - - return c; -} - -icalcomponent* read_nonmime_component(struct options_struct *opt) -{ - FILE *stream; - icalcomponent *comp; - icalparser* parser = icalparser_new(); - char* line; - - if(opt->input_source == INPUT_FROM_FILE){ - stream = fopen(opt->input_file,"r"); - - if (stream == 0){ - perror("Can't open input file"); - exit(1); - } - - } else { - stream = stdin; - } - - assert(stream != 0); - icalparser_set_gen_data(parser,stream); - - do { - line = icalparser_get_line(parser,read_stream); - - comp = icalparser_add_line(parser,line); - - if (comp != 0){ - icalparser_claim(parser); - return comp; - } - - } while ( line != 0); - - if(opt->input_source == INPUT_FROM_FILE){ - fclose(stream); - } - - - return comp; - } - -icalcomponent* find_vcalendar(icalcomponent* comp) -{ - icalcomponent *c,*rtrn; - - for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT); - c != 0; - c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){ - - if(icalcomponent_isa(c) == ICAL_VCALENDAR_COMPONENT){ - icalcomponent_remove_component(comp,c); - return c; - } - - if((rtrn=find_vcalendar(c)) != 0){ - return rtrn; - } - } - - return 0; -} - -icalcomponent* read_mime_component(struct options_struct *opt) -{ - icalcomponent *comp,*mimecomp; - FILE* stream; - - if(opt->input_source == INPUT_FROM_FILE){ - stream = fopen(opt->input_file,"r"); - - if (stream == 0){ - perror("Can't open input file"); - exit(1); - } - - } else { - stream = stdin; - } - - assert(stream != 0); - - mimecomp = icalmime_parse(read_stream,(void*)stream); - - /* now find the iCal component embedded within the mime component */ - comp = find_vcalendar(mimecomp); - - - if(comp == 0){ - return 0; - } - - return comp; -} - -icalcomponent* read_component(struct options_struct *opt) -{ - if(opt->input_type == INPUT_IS_MIME){ - return read_mime_component(opt); - } else if (opt->input_type == INPUT_IS_ICAL){ - return read_nonmime_component(opt); - } else { - fprintf(stderr,"%s: Internal Error; unknown option for input_type\n", - program_name); - exit(1); - } -} - -int main(int argc, char* argv[] ) -{ - char* options_error_str; - char* component_error_str; - icalcomponent* comp, *reply; - struct options_struct opt; - icalproperty *return_status; - - program_name = strrchr(argv[0],'/'); - - get_options(argc, argv, &opt); - - if ( (options_error_str = check_options(&opt)) != 0 ){ - usage(options_error_str); - exit(1); - } - - comp = read_component(&opt); - - if ( (component_error_str = - check_component(comp,&return_status,&opt)) != 0){ - reply = make_reply(comp,return_status,&opt); - return_failure(reply, component_error_str, &opt); - icalcomponent_free(reply); - exit(0); - } - - store_component(comp,&opt); - - - /* Don't free the component comp, since it is now part of the - store, and will be freed there */ - - exit(0); -} - diff --git a/libical/src/test/testmime.c b/libical/src/test/testmime.c deleted file mode 100644 index a912983f84..0000000000 --- a/libical/src/test/testmime.c +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: - CREATOR: eric 25 June 2000 - - $Id$ - $Locker$ - - 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. - - - This program is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: http://www.fsf.org/copyleft/lesser.html - - Or: - - The Mozilla Public License Version 1.0. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - The Initial Developer of the Original Code is Eric Busboom - - (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org - ======================================================================*/ - -#include "ical.h" -#include "sspm.h" -#include "icalmime.h" -#include <stdlib.h> /* For rand */ -#include <string.h> /* for strrchr, strdup*/ -#include <unistd.h> /* for getopt */ - -/*int sspm_parse_mime(struct sspm_part *parts, - size_t max_parts, - struct sspm_action_map *actions, - char* (*get_string)(char *s, size_t size, void* data), - void *get_string_data, - struct sspm_header *first_header - ); -*/ - - - -char* major_type_string[] = { - "TEXT", - "IMAGE", - "AUDIO", - "VIDEO", - "APPLICATION", - "MULTIPART", - "MESSAGE", - "UNKNOWN", - "NO" -}; - -char* minor_type_string[] = { - "ANY", - "PLAIN", - "RFC822", - "DIGEST", - "CALENDAR", - "MIXED", - "RELATED", - "ALTERNATIVE", - "PARALLEL", - "UNKNOWN", - "NO" -}; - - -char* read_stream(char *s, size_t size, void *d) -{ - char *c = fgets(s,size, (FILE*)d); - - return c; - -} - -int main(int argc, char* argv[]) { - - FILE *f; - int c; - extern char *optarg; - extern int optind, optopt; - int errflg=0; - char* program_name; - - struct options{ - int normal; - int stress; - int base64; - int qp; - int sleep; - int count; - char* input_file; - } opt; - - memset(&opt,0,sizeof(opt)); - - program_name = (char*)strrchr((char*)argv[0],'/'); - program_name++; - - while ((c = getopt(argc, argv, "nsbqi:S:c:")) != -1) { - switch (c) { - case 'i': { /* Input comes from named file */ - opt.input_file = strdup(optarg); - break; - } - case 'n':{ /* Normal */ - - if(opt.stress+opt.base64+opt.qp != 0){ - fprintf(stderr, - "%s: Use only one of n,s,b and q\n", - program_name); - } - opt.normal = 1; - break; - } - case 's':{ /* Stress-test*/ - if(opt.base64+opt.normal+opt.qp != 0){ - fprintf(stderr, - "%s: Use only one of n,s,b and q\n", - program_name); - } - opt.stress = 1; - break; - } - case 'b':{ /* test base64 encoding*/ - if(opt.stress+opt.normal+opt.qp != 0){ - fprintf(stderr, - "%s: Use only one of n,s,b and q\n", - program_name); - } - opt.base64 = 1; - break; - } - case 'q':{ /* test quoted-printable encoding*/ - if(opt.stress+opt.base64+opt.normal != 0){ - fprintf(stderr, - "%s: Use only one of n,s,b and q\n", - program_name); - } - opt.qp = 1; - break; - } - case 'S':{ /* sleep at end of run */ - opt.sleep = atoi(optarg); - break; - } - - case 'c':{ /* number of iterations of stress test */ - opt.count = atoi(optarg); - break; - } - - case ':': {/* Option given without an operand */ - fprintf(stderr, - "%s: Option -%c requires an operand\n", - program_name,optopt); - errflg++; - break; - } - case '?': { - errflg++; - } - } - } - - if (errflg >0){ - fprintf(stderr,"Usage: %s [-n|-s|-b|-q] [-i input_file]\n", - program_name); - exit(1); - } - - if(opt.stress+opt.base64+opt.normal+opt.qp == 0){ - fprintf(stderr, - "%s: Must have one of n,s,b or q\n", - program_name); - } - - if(opt.input_file){ - f = fopen(opt.input_file,"r"); - if (f == 0){ - fprintf(stderr,"Could not open input file \"%s\"\n", - opt.input_file); - exit(1); - } - } else { - f = stdin; - } - - - - if(opt.normal == 1){ - icalcomponent *c; - - c = icalmime_parse(read_stream,f); - - printf("%s\n",icalcomponent_as_ical_string(c)); - - icalcomponent_free(c); - - } else if (opt.stress==1 ){ - /* Read file in by lines, then randomize the lines into a - string buffer */ - - char *array[1024]; - char temp[1024]; - char *buf; - int i,last; - int size; - int non_rand; - int rand_lines; - int r; - int j; - icalcomponent *c; - struct slg_data { - char* pos; - char* str; - } d; - - for(i=0; !feof(f); i++){ - fgets(temp,1024,f); - array[i] = strdup(temp); - size += strlen(temp); - } - last = i; - - buf = malloc(size*2); - assert(buf != 0); - - - for(j=0; j<opt.count; j++){ - - srand(j); - memset(buf,0,size*2); - /* First insert some non-randomized lines */ - non_rand = ((float)rand()/(float)RAND_MAX) * last; - for(i=0;i<non_rand;i++){ - strcat(buf,array[i]); - } - - /* Then, insert some lines at random */ - - rand_lines = last - non_rand; - - for(i=0;i<rand_lines;i++){ - srand(i); - r = ((float)rand()/(float)RAND_MAX) * rand_lines; - strcat(buf,array[r+non_rand]); - - } - - d.pos = 0; - d.str = buf; - - c = icalmime_parse(string_line_generator,&d); - - printf("%s\n",icalcomponent_as_ical_string(c)); - - icalcomponent_free(c); - - } - - free(buf); - - for(i=0; i<last; i++){ - free(array[i]); - } - - } else if(opt.qp == 1){ - char str[4096]; - char conv[4096]; - - memset(str,0,4096); - - while(!feof(f) && fgets(str,4096,f)!=0){ - size_t size; - - size = strlen(str); - memset(conv,0,4096); - decode_quoted_printable(conv,str,&size); - - conv[size] = '\0'; - printf("%s",conv); - memset(str,0,4096); - - } - } else if (opt.base64 == 1) { - char str[4096]; - char conv[4096]; - - memset(str,0,4096); - - while(!feof(f) && fgets(str,4096,f)!=0){ - size_t size; - - size = strlen(str); - memset(conv,0,4096); - decode_base64(conv,str,&size); - - conv[size] = '\0'; - printf("%s",conv); - memset(str,0,4096); - - } - } - - if (opt.sleep != 0){ - sleep(opt.sleep); - } - - if( opt.input_file != 0){ - free(opt.input_file); - } - - icalmemory_free_ring(); - - return 0; - -} - - - - - - - - diff --git a/libical/src/test/testvcal.c b/libical/src/test/testvcal.c deleted file mode 100644 index 4777162623..0000000000 --- a/libical/src/test/testvcal.c +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C -*- - ====================================================================== - FILE: vcal.c - CREATOR: eric 26 May 2000 - - $Id$ - $Locker$ - - (C) COPYRIGHT 2000 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 Code is eric. The Initial Developer of the Original - Code is Eric Busboom - - - ======================================================================*/ - -#include "icalvcal.h" -#include <stdio.h> - -/* Given a vCal data file as its first argument, this program will - print out an equivalent iCal component. - - For instance: - - ./testvcal ../../test-data/user-cal.vcf - -*/ - -int main(int argc, char* argv[]) -{ - VObject *vcal = 0; - icalcomponent *comp; - - vcal = Parse_MIME_FromFileName(argv[1]); - - assert(vcal != 0); - - comp = icalvcal_convert(vcal); - - printf("%s\n",icalcomponent_as_ical_string(comp)); - - return 0; -} - - |