Back to index

lightning-sunbird  0.9+nobinonly
regression-storage.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: regression-storage.c
00004   CREATOR: eric 03 April 1999
00005   
00006   DESCRIPTION:
00007   
00008   $Id: regression-storage.c,v 1.3 2002/08/07 17:19:55 acampi Exp $
00009   $Locker:  $
00010 
00011   (C) COPYRIGHT 1999 Eric Busboom 
00012   http://www.softwarestudio.org
00013 
00014   The contents of this file are subject to the Mozilla Public License
00015   Version 1.0 (the "License"); you may not use this file except in
00016   compliance with the License. You may obtain a copy of the License at
00017   http://www.mozilla.org/MPL/
00018  
00019   Software distributed under the License is distributed on an "AS IS"
00020   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00021   the License for the specific language governing rights and
00022   limitations under the License.
00023 
00024   The original author is Eric Busboom
00025   The original code is usecases.c
00026 
00027     
00028   ======================================================================*/
00029 
00030 #include <assert.h>
00031 #include <string.h> /* for strdup */
00032 #include <stdlib.h> /* for malloc */
00033 #include <stdio.h> /* for printf */
00034 #include <time.h> /* for time() */
00035 
00036 #include "ical.h"
00037 #include "icalss.h"
00038 #include "regression.h"
00039 
00040 #define OUTPUT_FILE "filesetout.ics"
00041 
00042 /* define sample calendar struct */
00043 struct calendar {
00044   int ID;
00045   int total_size;
00046 
00047   /* offsets */
00048   int total_size_offset;
00049   int vcalendar_size_offset;
00050   int vcalendar_offset;
00051   int title_size_offset;
00052   int title_offset;
00053 
00054   /* data */
00055   int vcalendar_size;
00056   char *vcalendar;
00057 
00058   int title_size;
00059   char *title;
00060 
00061 };
00062 
00063 int vcalendar_init(struct calendar **cal, char *vcalendar, char *title);
00064 
00065 #ifdef WITH_BDB
00066 #include <db.h>
00067 
00068 int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey);
00069 char * parse_vcalendar(const DBT *dbt) ;
00070 char * pack_calendar(struct calendar *cal, int size);
00071 struct calendar * unpack_calendar(char *str, int size);
00072 #endif
00073 
00074 static char str[] = "BEGIN:VCALENDAR\n\
00075 PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\
00076 VERSION:2.0\n\
00077 BEGIN:VTIMEZONE\n\
00078 TZID:US-Eastern\n\
00079 BEGIN:STANDARD\n\
00080 DTSTART:19981025T020000\n\
00081 RDATE:19981025T020000\n\
00082 TZOFFSETFROM:-0400\n\
00083 TZOFFSETTO:-0500\n\
00084 TZNAME:EST\n\
00085 END:STANDARD\n\
00086 BEGIN:DAYLIGHT\n\
00087 DTSTART:19990404T020000\n\
00088 RDATE:19990404T020000\n\
00089 TZOFFSETFROM:-0500\n\
00090 TZOFFSETTO:-0400\n\
00091 TZNAME:EDT\n\
00092 END:DAYLIGHT\n\
00093 END:VTIMEZONE\n\
00094 BEGIN:VEVENT\n\
00095 DTSTAMP:19980309T231000Z\n\
00096 UID:guid-1.host1.com\n\
00097 ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\
00098 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\
00099 DESCRIPTION:Project XYZ Review Meeting\n\
00100 CATEGORIES:MEETING\n\
00101 CLASS:PUBLIC\n\
00102 CREATED:19980309T130000Z\n\
00103 SUMMARY:XYZ Project Review\n\
00104 DTSTART;TZID=US-Eastern:19980312T083000\n\
00105 DTEND;TZID=US-Eastern:19980312T093000\n\
00106 LOCATION:1CP Conference Room 4350\n\
00107 END:VEVENT\n\
00108 BEGIN:BOOGA\n\
00109 DTSTAMP:19980309T231000Z\n\
00110 X-LIC-FOO:Booga\n\
00111 DTSTOMP:19980309T231000Z\n\
00112 UID:guid-1.host1.com\n\
00113 END:BOOGA\n\
00114 END:VCALENDAR";
00115 
00116 char str2[] = "BEGIN:VCALENDAR\n\
00117 PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\
00118 VERSION:2.0\n\
00119 BEGIN:VEVENT\n\
00120 DTSTAMP:19980309T231000Z\n\
00121 UID:guid-1.host1.com\n\
00122 ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\
00123 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\
00124 DESCRIPTION:Project XYZ Review Meeting\n\
00125 CATEGORIES:MEETING\n\
00126 CLASS:PUBLIC\n\
00127 CREATED:19980309T130000Z\n\
00128 SUMMARY:XYZ Project Review\n\
00129 DTSTART;TZID=US-Eastern:19980312T083000\n\
00130 DTEND;TZID=US-Eastern:19980312T093000\n\
00131 LOCATION:1CP Conference Room 4350\n\
00132 END:VEVENT\n\
00133 END:VCALENDAR\n\
00134 ";
00135 
00136 
00137 void test_fileset_extended(void)
00138 {
00139     icalset *cout;
00140     int month = 0;
00141     int count=0;
00142     struct icaltimetype start, end;
00143     icalcomponent *c,*clone, *itr;
00144     icalsetiter iter;
00145 
00146     start = icaltime_from_timet( time(0),0);
00147     end = start;
00148     end.hour++;
00149 
00150     cout = icalfileset_new(OUTPUT_FILE);
00151     ok("Opening output file", (cout != 0));
00152     assert(cout!=0);
00153 
00154     c = icalparser_parse_string(str2);
00155     ok("Parsing str2", (c!=0));
00156     assert(c != 0);
00157 
00158     icalset_free(cout);
00159 
00160     /* Add data to the file */
00161 
00162     for(month = 1; month < 10; month++){
00163        icalcomponent *event;
00164        icalproperty *dtstart, *dtend;
00165 
00166         cout = icalfileset_new(OUTPUT_FILE);
00167        ok("Opening output file", (cout != 0));
00168         assert(cout != 0);
00169 
00170        start.month = month; 
00171        end.month = month;
00172        
00173        clone = icalcomponent_new_clone(c);
00174        ok("Making clone of output file", (clone!=0));
00175        assert(clone !=0);
00176 
00177        event = icalcomponent_get_first_component(clone,ICAL_VEVENT_COMPONENT);
00178        ok("Getting first event from clone", (event!=0));
00179        assert(event != 0);
00180 
00181        dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00182        ok("find DTSTART", (dtstart !=0));
00183        assert(dtstart!=0);
00184 
00185        icalproperty_set_dtstart(dtstart,start);
00186         
00187        dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00188        ok("find DTEND", (dtend !=0));
00189 
00190        assert(dtend!=0);
00191 
00192        icalproperty_set_dtend(dtend,end);
00193        
00194        icalfileset_add_component(cout,clone);
00195        icalfileset_commit(cout);
00196 
00197         icalset_free(cout);
00198     }
00199 
00200     /* Print them out */
00201 
00202     cout = icalfileset_new(OUTPUT_FILE);
00203 
00204     ok("Opening output file", (cout != 0));
00205     assert(cout != 0);
00206     
00207     for (iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0);
00208          icalsetiter_deref(&iter) != 0; icalsetiter_next(&iter)) {
00209       icalcomponent *event;
00210       icalproperty *dtstart, *dtend;
00211 
00212       itr = icalsetiter_deref(&iter);
00213       count++;
00214 
00215       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00216 
00217       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00218       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00219       
00220       if (VERBOSE)
00221        printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00222               icalproperty_as_ical_string(dtend));
00223 
00224     }
00225 
00226     /* Remove all of them */
00227 
00228     icalset_free(cout);
00229 
00230     cout = icalfileset_new(OUTPUT_FILE);
00231     ok("Opening output file", (cout!=0));
00232     assert(cout != 0);
00233 
00234     /* need to advance the iterator first before calling remove_componenet() */
00235     /* otherwise, iter will contain a "removed" component and icalsetiter_next(&iter) */
00236     /* will fail. */
00237 
00238     iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0);
00239     itr = icalsetiter_deref(&iter);
00240     while (itr != 0) {
00241         icalsetiter_next(&iter);
00242         icalfileset_remove_component(cout, itr);
00243        icalcomponent_free(itr);
00244         itr = icalsetiter_deref(&iter);
00245     }
00246     
00247     icalset_free(cout);
00248 
00249     /* Print them out again */
00250 
00251     cout = icalfileset_new(OUTPUT_FILE);
00252     ok("Opening output file", (cout != 0));
00253     assert(cout != 0);
00254     count =0;
00255     
00256     for (itr = icalfileset_get_first_component(cout);
00257          itr != 0;
00258          itr = icalfileset_get_next_component(cout)){
00259 
00260       icalcomponent *event;
00261       icalproperty *dtstart, *dtend;
00262 
00263       count++;
00264 
00265       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00266 
00267       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00268       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00269       
00270       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00271              icalproperty_as_ical_string(dtend));
00272 
00273     }
00274 
00275     icalset_free(cout);
00276     icalcomponent_free(c);
00277 }
00278 
00279 
00280 #ifdef WITH_BDB
00281 
00282 /*
00283    In this example, we're storing a calendar with several components
00284    under the reference id "calendar_7286" and retrieving records based
00285    on title, "month_1" through "month_10".  We use a number of the 
00286    "optional" arguments to specify secondary indices, sub-databases
00287    (i.e. having multiple databases residing within a single Berkeley
00288    DB file), and keys for storage and retrieval.
00289 */
00290 
00291 void test_bdbset()
00292 {
00293     icalset *cout;
00294     int month = 0;
00295     int count=0;
00296     int num_components=0;
00297     int szdata_len=0;
00298     int ret=0;
00299     char *subdb, *szdata, *szpacked_data;
00300     char uid[255];
00301     struct icaltimetype start, end;
00302     icalcomponent *c,*clone, *itr;
00303     DBT key, data;
00304     DBC *dbcp;
00305 
00306     struct calendar *cal;
00307     int cal_size;
00308 
00309     return; // for now... TODO fix these broken tests..
00310 
00311 
00312 
00313     start = icaltime_from_timet( time(0),0);
00314     end = start;
00315     end.hour++;
00316 
00317     /* Note: as per the Berkeley DB ref pages: 
00318      *
00319      * The database argument is optional, and allows applications to
00320      * have multiple databases in a single file. Although no database
00321      * argument needs to be specified, it is an error to attempt to
00322      * open a second database in a file that was not initially created
00323      * using a database name. 
00324      *
00325      */
00326 
00327     subdb = "calendar_id";
00328 
00329     /* open database, using subdb */
00330     cout = icalbdbset_new("calendar.db", ICALBDB_EVENTS, DB_HASH, 0);
00331     /*
00332     sdbp = icalbdbset_secondary_open(dbp, 
00333                                  DATABASE, 
00334                                  "title", 
00335                                  get_title, 
00336                                  DB_HASH); 
00337     */
00338 
00339     c = icalparser_parse_string(str2);
00340 
00341     assert(c != 0);
00342 
00343     /* Add data to the file */
00344 
00345     for(month = 1; month < 10; month++){
00346       icalcomponent *event;
00347       icalproperty *dtstart, *dtend, *location;
00348 
00349       /* retrieve data */
00350       //      cout = icalbdbset_new(dbp, sdbp, NULL);  
00351       //      assert(cout != 0);
00352 
00353       start.month = month; 
00354       end.month = month;
00355               
00356       clone = icalcomponent_new_clone(c);
00357       assert(clone !=0);
00358       event = icalcomponent_get_first_component(clone,
00359                                           ICAL_VEVENT_COMPONENT);
00360       assert(event != 0);
00361 
00362       dtstart = icalcomponent_get_first_property(event,
00363                                            ICAL_DTSTART_PROPERTY);
00364       assert(dtstart!=0);
00365       icalproperty_set_dtstart(dtstart,start);
00366         
00367       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00368       assert(dtend!=0);
00369       icalproperty_set_dtend(dtend,end);
00370 
00371       location = icalcomponent_get_first_property(event, ICAL_LOCATION_PROPERTY);
00372       assert(location!=0);
00373 
00374 #if 0
00375       /* change the uid to include the month */
00376       sprintf(uid, "%s_%d", icalcomponent_get_uid(clone), month);
00377       icalcomponent_set_uid(clone, uid);
00378 #endif
00379 
00380       icalbdbset_add_component(cout,clone);
00381 
00382       /* commit changes */
00383       icalbdbset_commit(cout);
00384 
00385       num_components = icalcomponent_count_components(clone, ICAL_ANY_COMPONENT);
00386 
00387       icalset_free(cout); 
00388 
00389     }
00390 
00391     /* try out the cursor operations */
00392     memset(&key, 0, sizeof(DBT));
00393     memset(&data, 0, sizeof(DBT));
00394 
00395 #if 0    
00396     ret = icalbdbset_acquire_cursor(dbp, &dbcp);
00397     ret = icalbdbset_get_first(dbcp, &key, &data);
00398     ret = icalbdbset_get_next(dbcp, &key, &data);
00399     ret = icalbdbset_get_last(dbcp, &key, &data);
00400 #endif
00401     /* Print them out */
00402 
00403     for(month = 1, count=0; month < 10; month++){
00404       char *title;
00405 
00406       icalcomponent *event;
00407       icalproperty *dtstart, *dtend;
00408 
00409       for (itr = icalbdbset_get_first_component(cout);
00410           itr != 0;
00411           itr = icalbdbset_get_next_component(cout)){
00412 
00413        icalcomponent *event;
00414        icalproperty *dtstart, *dtend;
00415 
00416        count++;
00417 
00418       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00419 
00420       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00421       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00422       
00423       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00424              icalproperty_as_ical_string(dtend));
00425 
00426       }
00427       icalset_free(cout);
00428     }
00429 
00430     /* open database */
00431     //    cout = icalbdbset_bdb_open("calendar.db", "title", DB_HASH, 0644);
00432     /*    sdbp = icalbdbset_secondary_open(dbp, 
00433                                  DATABASE, 
00434                                  "title", 
00435                                  get_title, 
00436                                  DB_HASH); 
00437     */
00438     /* Remove all of them */
00439     for(month = 1; month < 10; month++){
00440       for (itr = icalbdbset_get_first_component(cout);
00441           itr != 0;
00442           itr = icalbdbset_get_next_component(cout)){
00443        
00444        icalbdbset_remove_component(cout, itr);
00445       }
00446 
00447       icalbdbset_commit(cout);
00448       icalset_free(cout);
00449 
00450     }
00451 
00452     /* Print them out again */
00453 
00454     for(month = 1, count=0; month < 10; month++){
00455       char *title;
00456 
00457       icalcomponent *event;
00458       icalproperty *dtstart, *dtend;
00459 
00460       for (itr = icalbdbset_get_first_component(cout);
00461           itr != 0;
00462           itr = icalbdbset_get_next_component(cout)){
00463 
00464        icalcomponent *event;
00465        icalproperty *dtstart, *dtend;
00466 
00467        count++;
00468 
00469       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00470 
00471       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00472       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00473       
00474       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00475              icalproperty_as_ical_string(dtend));
00476 
00477       }
00478       icalset_free(cout);
00479     }
00480 }
00481 #endif
00482 
00483 int vcalendar_init(struct calendar **rcal, char *vcalendar, char *title) 
00484 {
00485   int vcalendar_size, title_size, total_size;
00486   struct calendar *cal;
00487 
00488   if(vcalendar) 
00489     vcalendar_size = strlen(vcalendar);
00490   else {
00491     vcalendar = "";
00492     vcalendar_size = strlen(vcalendar);
00493   }
00494 
00495   if(title) 
00496     title_size = strlen(title);
00497   else {
00498     title = "";
00499     title_size = strlen(title);
00500   }
00501 
00502   total_size = sizeof(struct calendar) + vcalendar_size + title_size;
00503 
00504   if((cal = (struct calendar *)malloc(total_size))==NULL)
00505     return 0;
00506   memset(cal, 0, total_size);
00507 
00508   /* offsets */
00509   cal->total_size_offset     = sizeof(int);
00510   cal->vcalendar_size_offset = (sizeof(int) * 7);
00511   cal->vcalendar_offset      = cal->vcalendar_size_offset + sizeof(int);
00512   cal->title_size_offset     = cal->vcalendar_offset + vcalendar_size;
00513   cal->title_offset          = cal->title_size_offset + sizeof(int);
00514 
00515   /* sizes */
00516   cal->total_size            = total_size;
00517   cal->vcalendar_size        = vcalendar_size;
00518   cal->title_size            = title_size;
00519 
00520   if (vcalendar && *vcalendar) 
00521     cal->vcalendar = strdup(vcalendar);
00522 
00523   if (title && *title)
00524     cal->title     = strdup(title);
00525 
00526   *rcal = cal;
00527 
00528   return 0;
00529 }
00530 
00531 /* get_title -- extracts a secondary key (the vcalendar)
00532  * from a primary key/data pair */
00533 
00534 /* just create a random title for now */
00535 #ifdef WITH_BDB
00536 
00537 int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey)
00538 {
00539   icalcomponent *cl;
00540   char title[255];
00541 
00542   memset(skey, 0, sizeof(DBT)); 
00543 
00544   cl = icalparser_parse_string((char *)pdata->data);
00545   sprintf(title, "title_%s", icalcomponent_get_uid(cl));
00546 
00547   skey->data = strdup(title);
00548   skey->size = strlen(skey->data);
00549   return (0); 
00550 }
00551 
00552 char * pack_calendar(struct calendar *cal, int size) 
00553 {
00554   char *str;
00555 
00556   if((str = (char *)malloc(sizeof(char) * size))==NULL)
00557     return 0;
00558 
00559   /* ID */
00560   memcpy(str, &cal->ID, sizeof(cal->ID));
00561 
00562   /* total_size */
00563   memcpy(str + cal->total_size_offset,
00564         &cal->total_size,
00565         sizeof(cal->total_size));
00566 
00567   /* vcalendar_size */
00568   memcpy(str + cal->vcalendar_size_offset, 
00569          &cal->vcalendar_size, 
00570          sizeof(cal->vcalendar_size));
00571 
00572   /* vcalendar */
00573   memcpy(str + cal->vcalendar_offset, 
00574          cal->vcalendar, 
00575          cal->vcalendar_size);
00576 
00577   /* title_size */
00578   memcpy(str + cal->title_size_offset,
00579         &cal->title_size,
00580         sizeof(cal->title_size));
00581 
00582   /* title */
00583   memcpy(str + cal->title_offset,
00584         cal->title,
00585         cal->title_size);
00586 
00587   return str;
00588 }
00589 
00590 struct calendar * unpack_calendar(char *str, int size)
00591 {
00592   struct calendar *cal;
00593   if((cal = (struct calendar *) malloc(size))==NULL)
00594     return 0;
00595   memset(cal, 0, size);
00596 
00597   /* offsets */
00598   cal->total_size_offset     = sizeof(int);
00599   cal->vcalendar_size_offset = (sizeof(int) * 7);
00600   cal->vcalendar_offset      = cal->vcalendar_size_offset + sizeof(int);
00601 
00602   /* ID */
00603   memcpy(&cal->ID, str, sizeof(cal->ID));
00604 
00605   /* total_size */
00606   memcpy(&cal->total_size,
00607         str + cal->total_size_offset,
00608         sizeof(cal->total_size));
00609 
00610   /* vcalendar_size */
00611   memcpy(&cal->vcalendar_size, 
00612         str + cal->vcalendar_size_offset, 
00613         sizeof(cal->vcalendar_size));
00614 
00615   if((cal->vcalendar = (char *)malloc(sizeof(char) * 
00616                                   cal->vcalendar_size))==NULL)
00617     return 0;
00618 
00619   /* vcalendar */
00620   memcpy(cal->vcalendar, 
00621         (char *)(str + cal->vcalendar_offset), 
00622         cal->vcalendar_size);
00623 
00624   cal->title_size_offset     = cal->vcalendar_offset + cal->vcalendar_size;
00625   cal->title_offset          = cal->title_size_offset + sizeof(int);
00626 
00627   /* title_size */
00628   memcpy(&cal->title_size,
00629         str + cal->title_size_offset,
00630         sizeof(cal->title_size));
00631 
00632   if((cal->title = (char *)malloc(sizeof(char) *
00633                               cal->title_size))==NULL)
00634     return 0;
00635 
00636   /* title*/
00637   memcpy(cal->title,
00638         (char *)(str + cal->title_offset),
00639         cal->title_size);
00640 
00641   return cal;
00642 }
00643 
00644 char * parse_vcalendar(const DBT *dbt) 
00645 {
00646   char *str;
00647   struct calendar *cal;
00648 
00649   str = (char *)dbt->data;
00650   cal = unpack_calendar(str, dbt->size);
00651 
00652   return cal->vcalendar;
00653 }
00654 #endif
00655 
00656 void test_dirset_extended(void)
00657 {
00658 
00659     icalcomponent *c;
00660     icalgauge *gauge;
00661     icalerrorenum error;
00662     icalcomponent *itr;
00663     icalset* cluster;
00664     struct icalperiodtype rtime;
00665     icalset *s = icaldirset_new("store");
00666     icalset *s2 = icaldirset_new("store-new");
00667     int i, count = 0;
00668 
00669     ok("Open dirset 'store'", (s!=0));
00670     assert(s != 0);
00671 
00672     rtime.start = icaltime_from_timet( time(0),0);
00673 
00674     cluster = icalfileset_new(OUTPUT_FILE);
00675 
00676     ok("Open fileset to duplicate 4 times", (cluster != 0));
00677     assert(cluster != 0);
00678 
00679 #define NUMCOMP 4
00680 
00681     /* Duplicate every component in the cluster NUMCOMP times */
00682 
00683     icalerror_clear_errno();
00684 
00685     for (i = 1; i<NUMCOMP+1; i++){
00686 
00687        /*rtime.start.month = i%12;*/
00688        rtime.start.month = i;
00689        rtime.end = rtime.start;
00690        rtime.end.hour++;
00691        
00692        for (itr = icalfileset_get_first_component(cluster);
00693             itr != 0;
00694             itr = icalfileset_get_next_component(cluster)){
00695            icalcomponent *clone, *inner;
00696            icalproperty *p;
00697 
00698            inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00699             if (inner == 0){
00700               continue;
00701             }
00702 
00703            /* Change the dtstart and dtend times in the component
00704                pointed to by Itr*/
00705 
00706            clone = icalcomponent_new_clone(itr);
00707            inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00708 
00709            ok("Duplicating component...", 
00710               (icalerrno == ICAL_NO_ERROR)&&(inner!=0));
00711 
00712            assert(icalerrno == ICAL_NO_ERROR);
00713            assert(inner !=0);
00714 
00715            /* DTSTART*/
00716            p = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
00717            ok("Fetching DTSTART", (icalerrno == ICAL_NO_ERROR));
00718            assert(icalerrno  == ICAL_NO_ERROR);
00719 
00720            if (p == 0){
00721               p = icalproperty_new_dtstart(rtime.start);
00722               icalcomponent_add_property(inner,p);
00723            } else {
00724               icalproperty_set_dtstart(p,rtime.start);
00725            }
00726 
00727            ok("Adding DTSTART property", (icalerrno == ICAL_NO_ERROR));
00728            assert(icalerrno  == ICAL_NO_ERROR);
00729 
00730            /* DTEND*/
00731            p = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY);
00732            ok("Fetching DTEND property", (icalerrno == ICAL_NO_ERROR));
00733            assert(icalerrno  == ICAL_NO_ERROR);
00734 
00735            if (p == 0){
00736               p = icalproperty_new_dtstart(rtime.end);
00737               icalcomponent_add_property(inner,p);
00738            } else {
00739               icalproperty_set_dtstart(p,rtime.end);
00740            }
00741            ok("Setting DTEND property", (icalerrno == ICAL_NO_ERROR));
00742            assert(icalerrno  == ICAL_NO_ERROR);
00743            
00744            if (VERBOSE)
00745              printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner));
00746 
00747            error = icaldirset_add_component(s,
00748                                         icalcomponent_new_clone(itr));
00749            
00750            ok("Adding component to dirset", (icalerrno == ICAL_NO_ERROR));
00751            assert(icalerrno  == ICAL_NO_ERROR);
00752        }
00753 
00754     }
00755     
00756     gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0);
00757 
00758     ok("Creating complex Gauge", (gauge!=0));
00759 
00760     icaldirset_select(s,gauge);
00761 
00762     for(c = icaldirset_get_first_component(s); c != 0; 
00763        c = icaldirset_get_next_component(s)){
00764        
00765        printf("Got one! (%d)\n", count++);
00766        
00767        if (c != 0){
00768            printf("%s", icalcomponent_as_ical_string(c));;
00769            if (icaldirset_add_component(s2,c) == 0){
00770               printf("Failed to write!\n");
00771            }
00772            icalcomponent_free(c);
00773        } else {
00774            printf("Failed to get component\n");
00775        }
00776     }
00777 
00778     icalset_free(s2);
00779 
00780     for(c = icaldirset_get_first_component(s); 
00781        c != 0; 
00782        c = icaldirset_get_next_component(s)){
00783 
00784        if (c != 0){
00785            printf("%s", icalcomponent_as_ical_string(c));;
00786        } else {
00787            printf("Failed to get component\n");
00788        }
00789 
00790     }
00791 
00792     /* Remove all of the components */
00793     i=0;
00794     while((c=icaldirset_get_current_component(s)) != 0 ){
00795        i++;
00796 
00797        icaldirset_remove_component(s,c);
00798     }
00799        
00800 
00801     icalset_free(s);
00802     icalset_free(cluster);
00803 }
00804