Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
regression-storage.c File Reference
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "ical.h"
#include "icalss.h"
#include "regression.h"

Go to the source code of this file.

Classes

struct  calendar

Defines

#define OUTPUT_FILE   "filesetout.ics"
#define NUMCOMP   4

Functions

int vcalendar_init (struct calendar **cal, char *vcalendar, char *title)
void test_fileset_extended (void)
void test_dirset_extended (void)

Variables

static char str []
char str2 []

Class Documentation

struct calendar

Definition at line 43 of file regression-storage.c.

Collaboration diagram for calendar:
Class Members
int ID
char * title
int title_offset
int title_size
int title_size_offset
int total_size
int total_size_offset
char * vcalendar
int vcalendar_offset
int vcalendar_size
int vcalendar_size_offset

Define Documentation

#define NUMCOMP   4
#define OUTPUT_FILE   "filesetout.ics"

Definition at line 40 of file regression-storage.c.


Function Documentation

Definition at line 656 of file regression-storage.c.

{

    icalcomponent *c;
    icalgauge *gauge;
    icalerrorenum error;
    icalcomponent *itr;
    icalset* cluster;
    struct icalperiodtype rtime;
    icalset *s = icaldirset_new("store");
    icalset *s2 = icaldirset_new("store-new");
    int i, count = 0;

    ok("Open dirset 'store'", (s!=0));
    assert(s != 0);

    rtime.start = icaltime_from_timet( time(0),0);

    cluster = icalfileset_new(OUTPUT_FILE);

    ok("Open fileset to duplicate 4 times", (cluster != 0));
    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);
            itr != 0;
            itr = icalfileset_get_next_component(cluster)){
           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);

           ok("Duplicating component...", 
              (icalerrno == ICAL_NO_ERROR)&&(inner!=0));

           assert(icalerrno == ICAL_NO_ERROR);
           assert(inner !=0);

           /* DTSTART*/
           p = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
           ok("Fetching DTSTART", (icalerrno == ICAL_NO_ERROR));
           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);
           }

           ok("Adding DTSTART property", (icalerrno == ICAL_NO_ERROR));
           assert(icalerrno  == ICAL_NO_ERROR);

           /* DTEND*/
           p = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY);
           ok("Fetching DTEND property", (icalerrno == ICAL_NO_ERROR));
           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);
           }
           ok("Setting DTEND property", (icalerrno == ICAL_NO_ERROR));
           assert(icalerrno  == ICAL_NO_ERROR);
           
           if (VERBOSE)
             printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner));

           error = icaldirset_add_component(s,
                                        icalcomponent_new_clone(itr));
           
           ok("Adding component to dirset", (icalerrno == ICAL_NO_ERROR));
           assert(icalerrno  == ICAL_NO_ERROR);
       }

    }
    
    gauge = icalgauge_new_from_sql("SELECT * FROM VEVENT WHERE VEVENT.SUMMARY = 'Submit Income Taxes' OR VEVENT.SUMMARY = 'Bastille Day Party'", 0);

    ok("Creating complex Gauge", (gauge!=0));

    icaldirset_select(s,gauge);

    for(c = icaldirset_get_first_component(s); c != 0; 
       c = icaldirset_get_next_component(s)){
       
       printf("Got one! (%d)\n", count++);
       
       if (c != 0){
           printf("%s", icalcomponent_as_ical_string(c));;
           if (icaldirset_add_component(s2,c) == 0){
              printf("Failed to write!\n");
           }
           icalcomponent_free(c);
       } else {
           printf("Failed to get component\n");
       }
    }

    icalset_free(s2);

    for(c = icaldirset_get_first_component(s); 
       c != 0; 
       c = icaldirset_get_next_component(s)){

       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);
    }
       

    icalset_free(s);
    icalset_free(cluster);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 137 of file regression-storage.c.

{
    icalset *cout;
    int month = 0;
    int count=0;
    struct icaltimetype start, end;
    icalcomponent *c,*clone, *itr;
    icalsetiter iter;

    start = icaltime_from_timet( time(0),0);
    end = start;
    end.hour++;

    cout = icalfileset_new(OUTPUT_FILE);
    ok("Opening output file", (cout != 0));
    assert(cout!=0);

    c = icalparser_parse_string(str2);
    ok("Parsing str2", (c!=0));
    assert(c != 0);

    icalset_free(cout);

    /* Add data to the file */

    for(month = 1; month < 10; month++){
       icalcomponent *event;
       icalproperty *dtstart, *dtend;

        cout = icalfileset_new(OUTPUT_FILE);
       ok("Opening output file", (cout != 0));
        assert(cout != 0);

       start.month = month; 
       end.month = month;
       
       clone = icalcomponent_new_clone(c);
       ok("Making clone of output file", (clone!=0));
       assert(clone !=0);

       event = icalcomponent_get_first_component(clone,ICAL_VEVENT_COMPONENT);
       ok("Getting first event from clone", (event!=0));
       assert(event != 0);

       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
       ok("find DTSTART", (dtstart !=0));
       assert(dtstart!=0);

       icalproperty_set_dtstart(dtstart,start);
        
       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
       ok("find DTEND", (dtend !=0));

       assert(dtend!=0);

       icalproperty_set_dtend(dtend,end);
       
       icalfileset_add_component(cout,clone);
       icalfileset_commit(cout);

        icalset_free(cout);
    }

    /* Print them out */

    cout = icalfileset_new(OUTPUT_FILE);

    ok("Opening output file", (cout != 0));
    assert(cout != 0);
    
    for (iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0);
         icalsetiter_deref(&iter) != 0; icalsetiter_next(&iter)) {
      icalcomponent *event;
      icalproperty *dtstart, *dtend;

      itr = icalsetiter_deref(&iter);
      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);
      
      if (VERBOSE)
       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
              icalproperty_as_ical_string(dtend));

    }

    /* Remove all of them */

    icalset_free(cout);

    cout = icalfileset_new(OUTPUT_FILE);
    ok("Opening output file", (cout!=0));
    assert(cout != 0);

    /* need to advance the iterator first before calling remove_componenet() */
    /* otherwise, iter will contain a "removed" component and icalsetiter_next(&iter) */
    /* will fail. */

    iter = icalfileset_begin_component(cout, ICAL_ANY_COMPONENT, 0);
    itr = icalsetiter_deref(&iter);
    while (itr != 0) {
        icalsetiter_next(&iter);
        icalfileset_remove_component(cout, itr);
       icalcomponent_free(itr);
        itr = icalsetiter_deref(&iter);
    }
    
    icalset_free(cout);

    /* Print them out again */

    cout = icalfileset_new(OUTPUT_FILE);
    ok("Opening output file", (cout != 0));
    assert(cout != 0);
    count =0;
    
    for (itr = icalfileset_get_first_component(cout);
         itr != 0;
         itr = icalfileset_get_next_component(cout)){

      icalcomponent *event;
      icalproperty *dtstart, *dtend;

      count++;

      event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);

      dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
      dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
      
      printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
             icalproperty_as_ical_string(dtend));

    }

    icalset_free(cout);
    icalcomponent_free(c);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int vcalendar_init ( struct calendar **  cal,
char *  vcalendar,
char *  title 
)

Definition at line 483 of file regression-storage.c.

{
  int vcalendar_size, title_size, total_size;
  struct calendar *cal;

  if(vcalendar) 
    vcalendar_size = strlen(vcalendar);
  else {
    vcalendar = "";
    vcalendar_size = strlen(vcalendar);
  }

  if(title) 
    title_size = strlen(title);
  else {
    title = "";
    title_size = strlen(title);
  }

  total_size = sizeof(struct calendar) + vcalendar_size + title_size;

  if((cal = (struct calendar *)malloc(total_size))==NULL)
    return 0;
  memset(cal, 0, total_size);

  /* offsets */
  cal->total_size_offset     = sizeof(int);
  cal->vcalendar_size_offset = (sizeof(int) * 7);
  cal->vcalendar_offset      = cal->vcalendar_size_offset + sizeof(int);
  cal->title_size_offset     = cal->vcalendar_offset + vcalendar_size;
  cal->title_offset          = cal->title_size_offset + sizeof(int);

  /* sizes */
  cal->total_size            = total_size;
  cal->vcalendar_size        = vcalendar_size;
  cal->title_size            = title_size;

  if (vcalendar && *vcalendar) 
    cal->vcalendar = strdup(vcalendar);

  if (title && *title)
    cal->title     = strdup(title);

  *rcal = cal;

  return 0;
}

Here is the call graph for this function:


Variable Documentation

char str[] [static]

Definition at line 74 of file regression-storage.c.

char str2[]
Initial value:
"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\
"

Definition at line 116 of file regression-storage.c.