1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
#include <libical/ical.h>
#include "regression.h"
#include <string.h>
extern int VERBOSE;
void create_simple_component(void)
{
icalcomponent* calendar;
icalproperty *version, *bogus;
/* Create calendar and add properties */
calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
ok("create vcalendar component", (calendar!=NULL));
icalcomponent_add_property(
calendar,
icalproperty_new_version("2.0")
);
version = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
ok("version property added", (version!=NULL));
bogus = icalcomponent_get_first_property(calendar,ICAL_DTSTART_PROPERTY);
ok("bogus dtstart not found", (bogus == NULL));
if (VERBOSE && calendar)
printf("%s\n",icalcomponent_as_ical_string(calendar));
icalcomponent_free(calendar);
}
static char* create_new_component_str =
"BEGIN:VCALENDAR\n"
"VERSION:2.0\n"
"PRODID:-//RDU Software//NONSGML HandCal//EN\n"
"BEGIN:VTIMEZONE\n"
"TZID:America/New_York\n"
"BEGIN:DAYLIGHT\n"
"DTSTART:20020606T212449\n"
"RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n"
"TZOFFSETFROM:-0500\n"
"TZOFFSETTO:-0400\n"
"TZNAME:EST\n"
"END:DAYLIGHT\n"
"BEGIN:STANDARD\n"
"DTSTART:20020606T212449\n"
"RDATE;VALUE=PERIOD:20020606T212449/20020607T012809\n"
"TZOFFSETFROM:-0400\n"
"TZOFFSETTO:-0500\n"
"TZNAME:EST\n"
"END:STANDARD\n"
"END:VTIMEZONE\n"
"BEGIN:VEVENT\n"
"DTSTAMP:20020606T212449\n"
"UID:guid-1.host1.com\n"
"ORGANIZER;ROLE=CHAIR:mrbig@host.com\n"
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CUTYPE=GROUP:employee-A@host.com\n"
"DESCRIPTION:Project XYZ Review Meeting\n"
"CATEGORIES:MEETING\n"
"CLASS:PRIVATE\n"
"CREATED:20020606T212449\n"
"SUMMARY:XYZ Project Review\n"
"DTSTART;TZID=America/New_York:20020606T212449\n"
"DTEND;TZID=America/New_York:20020606T212449\n"
"LOCATION:1CP Conference Room 4350\n"
"END:VEVENT\n"
"END:VCALENDAR\n";
/* Create a new component */
void create_new_component()
{
icalcomponent* calendar;
icalcomponent* timezone;
icalcomponent* tzc;
icalcomponent* event;
struct icaltimetype atime = icaltime_from_timet( 1023398689, 0);
struct icaldatetimeperiodtype rtime;
icalproperty* property;
char *calendar_as_string;
rtime.period.start = icaltime_from_timet( 1023398689,0);
rtime.period.end = icaltime_from_timet( 1023409689,0);
rtime.period.end.hour++;
rtime.time = icaltime_null_time();
/* 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("America/New_York")
);
/* 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(-5*3600)
);
icalcomponent_add_property(
tzc,
icalproperty_new_tzoffsetto(-4*3600)
);
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*3600)
);
icalcomponent_add_property(
tzc,
icalproperty_new_tzoffsetto(-5*3600)
);
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(ICAL_RSVP_TRUE)
);
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(ICAL_CLASS_PRIVATE)
);
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("America/New_York")
);
icalcomponent_add_property(event,property);
property = icalproperty_new_dtend(atime);
icalproperty_add_parameter(
property,
icalparameter_new_tzid("America/New_York")
);
icalcomponent_add_property(event,property);
icalcomponent_add_property(
event,
icalproperty_new_location("1CP Conference Room 4350")
);
icalcomponent_add_component(calendar,event);
calendar_as_string = icalcomponent_as_ical_string(calendar);
is("build large, complex component",
calendar_as_string,
create_new_component_str);
if (VERBOSE && calendar)
printf("%s\n",icalcomponent_as_ical_string(calendar));
if (calendar)
icalcomponent_free(calendar);
}
/* Create a new component, using the va_args list */
void create_new_component_with_va_args()
{
icalcomponent* calendar;
struct icaltimetype atime = icaltime_from_timet( time(0),0);
struct icaldatetimeperiodtype rtime;
rtime.period.start = icaltime_from_timet( time(0),0);
rtime.period.end = icaltime_from_timet( time(0),0);
rtime.period.end.hour++;
rtime.time = icaltime_null_time();
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("America/New_York"),
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(ICAL_RSVP_TRUE),
icalparameter_new_cutype(ICAL_CUTYPE_GROUP),
0
),
icalproperty_new_description("Project XYZ Review Meeting"),
icalproperty_new_categories("MEETING"),
icalproperty_new_class(ICAL_CLASS_PUBLIC),
icalproperty_new_created(atime),
icalproperty_new_summary("XYZ Project Review"),
icalproperty_vanew_dtstart(
atime,
icalparameter_new_tzid("America/New_York"),
0
),
icalproperty_vanew_dtend(
atime,
icalparameter_new_tzid("America/New_York"),
0
),
icalproperty_new_location("1CP Conference Room 4350"),
0
),
0
);
ok("creating a complex vcalendar", (calendar != NULL));
if (VERBOSE && calendar)
printf("%s\n",icalcomponent_as_ical_string(calendar));
icalcomponent_free(calendar);
}
static void print_span(int c, struct icaltime_span span ){
printf("span-->%d, %d\n", (int)span.start, (int)span.end);
if (span.start == 0)
printf("#%02d start: (empty)\n",c);
else
printf("#%02d start: %s\n",c,ical_timet_string(span.start));
if (span.end == 0)
printf(" end : (empty)\n");
else
printf(" end : %s\n",ical_timet_string(span.end));
}
/** Test icalcomponent_get_span()
*
*/
void test_icalcomponent_get_span()
{
time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000,
Sat Nov 4 15:00:00 PST 2000 */
time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000
Sat Nov 4 16:00:00 PST 2000 */
struct icaldurationtype dur;
struct icaltime_span span;
icalcomponent *c;
icaltimezone *azone, *bzone;
int tnum = 0;
/** test 0
* Direct assigning time_t means they will be interpreted as UTC
*/
span.start = tm1;
span.end = tm2;
if (VERBOSE) print_span(tnum++,span);
/** test 1
* We specify times in a timezone, the returned span is in UTC
*/
azone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_vanew_dtstart(
icaltime_from_timet_with_zone(tm1,0,azone),
icalparameter_new_tzid("America/Los_Angeles"),0),
icalproperty_vanew_dtend(
icaltime_from_timet_with_zone(tm2,0,azone),
icalparameter_new_tzid("America/Los_Angeles"),0),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("America/Los_Angeles", span.start, 973407600);
icalcomponent_free(c);
/** test 2
* We specify times as floating, the returned span is in UTC
* with no conversion applied - so result should be as test 0
*/
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_vanew_dtstart(icaltime_from_timet(tm1,0),0),
icalproperty_vanew_dtend(icaltime_from_timet(tm2,0),0),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("floating time", span.start, tm1);
icalcomponent_free(c);
/** test 3
* We specify times in a timezone, the returned span is in UTC
*/
azone = icaltimezone_get_builtin_timezone("America/New_York");
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_vanew_dtstart(
icaltime_from_timet_with_zone(tm1,0,azone),
icalparameter_new_tzid("America/New_York"),0),
icalproperty_vanew_dtend(
icaltime_from_timet_with_zone(tm2,0,azone),
icalparameter_new_tzid("America/New_York"),0),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("America/New_York", span.start, 973396800);
icalcomponent_free(c);
/** test 4
* We specify times in two different timezones, the returned span
* is in UTC
*/
azone = icaltimezone_get_builtin_timezone("America/New_York");
bzone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_vanew_dtstart(
icaltime_from_timet_with_zone(tm1,0,azone),
icalparameter_new_tzid("America/New_York"),0),
icalproperty_vanew_dtend(
icaltime_from_timet_with_zone(tm2,0,bzone),
icalparameter_new_tzid("America/Los_Angeles"),0),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("America/New_York", span.start, 973396800);
icalcomponent_free(c);
/** test 5
* We specify start time in a timezone and a duration, the returned span
* is in UTC
*/
azone = icaltimezone_get_builtin_timezone("America/Los_Angeles");
memset(&dur,0,sizeof(dur));
dur.minutes = 30;
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_vanew_dtstart(
icaltime_from_timet_with_zone(tm1,0,azone),
icalparameter_new_tzid("America/Los_Angeles"),0),
icalproperty_new_duration(dur),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("America/Los_Angeles w/ duration", span.end, 973409400);
icalcomponent_free(c);
icalerror_errors_are_fatal = 0;
/** test 6
* We specify only start time, should return a null span with no error
*/
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_new_dtstart(icaltime_from_timet(tm1,0)),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("null span", span.start, 0);
icalcomponent_free(c);
/** test 7
* We specify start and end date
*/
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
icalproperty_new_dtend(icaltime_from_timet(tm1,1)),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("UTC", span.start, 973296000);
icalcomponent_free(c);
/** test 8
* We specify start and end date
*/
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
icalproperty_new_dtend(icaltime_from_timet(tm2,1)),
0
);
span = icalcomponent_get_span(c);
int_is("UTC #2", span.start, 973296000);
if (VERBOSE) print_span(tnum++,span);
icalcomponent_free(c);
/** test 9
* We specify start date
*/
c = icalcomponent_vanew(
ICAL_VEVENT_COMPONENT,
icalproperty_new_dtstart(icaltime_from_timet(tm1,1)),
0
);
span = icalcomponent_get_span(c);
if (VERBOSE) print_span(tnum++,span);
int_is("start date only", span.end, 973382399);
icalcomponent_free(c);
/* assert(icalerrno == ICAL_MALFORMEDDATA_ERROR); */
icalerror_errors_are_fatal = 1;
}
|