-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarAPITest.pas
315 lines (284 loc) · 8.89 KB
/
CalendarAPITest.pas
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
unit CalendarAPITest;
interface
uses
DUnitX.TestFramework, iCalendarAPI, System.StrUtils, DateUtils, SysUtils, System.Types, System.Variants;
type
[TestFixture]
TCalendardTest = class(TObject)
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
[Test]
procedure TestTime1;
[Test]
procedure TestDate;
[Test]
procedure AttendeeExample1;
[Test]
procedure ParseLineTest1;
[Test]
procedure TestDateTime;
[Test]
procedure iCalendarExample1;
[Test]
procedure FoldingMethod;
[Test]
procedure AttendeeExample2;
[Test]
procedure DescriptionExample2;
[Test]
procedure DTStampExample1;
// Sample Methods
// Simple single Test
[Test]
procedure ProdIDExample1;
[Test]
procedure OrganizerExample1;
// Test with TestCase Attribute to supply parameters.
[Test]
[TestCase('TestA','1,2')]
[TestCase('TestB','3,4')]
procedure Test2(const AValue1 : Integer;const AValue2 : Integer);
end;
implementation
procedure TCalendardTest.Setup;
begin
end;
procedure TCalendardTest.TearDown;
begin
end;
procedure TCalendardTest.FoldingMethod;
begin
end;
procedure TCalendardTest.iCalendarExample1;
//https://icalendar.org/iCalendar-RFC-5545/4-icalendar-object-examples.html
var
lText: String;
Calendar: TCalendar;
begin
Calendar := TCalendar.Create;
Calendar.PRODID := '-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN';
Calendar.VERSION := '2.0';
lText := Calendar.VERSION;
Assert.AreEqual('2.0',lText);
Assert.AreEqual(2,Double(Calendar.VERSION),0.001);
with Calendar.Event_Add do begin
(ItemByName['DTSTAMP'] as TItemValue).Text := '19960704T120000Z';
UID.Value := '[email protected]';
ORGANIZER.Text:= ':mailto:[email protected]';
DTSTART_Add.Value := EncodeDateTime(1996,09,18,14,30,00,0);
DTEND_Add.Value := EncodeDateTime(1996,09,20,22,00,00,0);
STATUS.Value := 'CONFIRMED';
CATEGORIES_Add.Value := 'CONFERENCE';
SUMMARY.Value := 'Networld+Interop Conference';
DESCRIPTION.Text := 'Networld+Interop Conference'#13#10 +
' and Exhibit\nAtlanta World Congress Center\n'#13#10 +
' Atlanta\, Georgia';
end;
Assert.AreEqual('VCALENDAR',Calendar.Name);
Assert.AreEqual('VEVENT',Calendar.Events[0].Name);
lText :=
'BEGIN:VCALENDAR'#13#10 + //0
'PRODID:-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN'#13#10 + //1
'VERSION:2.0'#13#10 + //2
'BEGIN:VEVENT'#13#10 + //3
'DTSTAMP:19960704T120000Z'#13#10 + //4
'UID:[email protected]'#13#10 + //5
'ORGANIZER:mailto:[email protected]'#13#10 + //6
'DTSTART:19960918T143000Z'#13#10 + //7
'DTEND:19960920T220000Z'#13#10 + //8
'STATUS:CONFIRMED'#13#10 + //9
'CATEGORIES:CONFERENCE'#13#10 + //10
'SUMMARY:Networld+Interop Conference'#13#10 + //11
'DESCRIPTION:Networld+Interop Conference'#13#10 + //12
' and Exhibit\nAtlanta World Congress Center\n'#13#10 + //13
'Atlanta\, Georgia'#13#10 + //14
'END:VEVENT'#13#10 + //15
'END:VCALENDAR'#13#10 ; //16
Assert.AreEqual(lText,Calendar.AsText);
end;
procedure TCalendardTest.OrganizerExample1;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Item := Cal.Event_Add.ORGANIZER;
Item.Text:= ':mailto:[email protected]';
lText := Cal.Events[0].ORGANIZER.Value;
Assert.AreEqual('mailto:[email protected]',lText);
Cal.Free;
end;
procedure TCalendardTest.DTStampExample1;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Item := Cal.Event_Add['DTSTAMP'] as TItemValue;
Item.Text := '19960704T120000Z';
Assert.IsTrue(VarIsType(Item.Value,varDate));
Assert.AreEqual(EncodeDateTime(1996,07,04,12,00,00,0),TDateTime(Item.Value));
Cal.Free;
end;
procedure TCalendardTest.DescriptionExample2;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Item := Cal.Event_Add.DESCRIPTION;
Item.Text := 'Networld+Interop Conference'#13#10 +
' and Exhibit\nAtlanta World Congress Center\n'#13#10 +
' Atlanta\, Georgia';
lText := Cal.Events[0].DESCRIPTION.Value;
Assert.AreEqual('Networld+Interop Conference and Exhibit'#13'Atlanta World Congress Center'#13'Atlanta, Georgia', lText);
Cal.Free;
end;
procedure TCalendardTest.AttendeeExample1;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Item := Cal.Event_Add.ATTENDEE_Add;
Item.Text := ';RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:mailto:[email protected]';
lText := Item.Text;
Assert.AreEqual('ATTENDEE;RSVP=TRUE;CUTYPE=GROUP;ROLE=REQ-PARTICIPANT:mailto:[email protected]',lText);
lText := Cal.AsText;
Assert.AreEqual(
'BEGIN:VCALENDAR'#$D#$A
+'BEGIN:VEVENT'#$D#$A
+'ATTENDEE;RSVP=TRUE;CUTYPE=GROUP;ROLE=REQ-PARTICIPANT:mailto:[email protected]'#$D#$A
+'END:VEVENT'#$D#$A
+'END:VCALENDAR'#$D#$A
,lText);
Cal.Free;
end;
procedure TCalendardTest.AttendeeExample2;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Cal.AsText :=
'BEGIN:VCALENDAR'#13#10+
'BEGIN:VEVENT'#13#10+
'ORGANIZER;CN=John Smith:MAILTO:[email protected]'#13#10 + //0
'ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=TENTATIVE;DELEGATED-FROM='#13#10 + //1
' "MAILTO:[email protected]";CN=Henry Cabot:MAILTO:hcabot@'#13#10 + //2
' host2.com'#13#10 + //3
'ATTENDEE;ROLE=NON-PARTICIPANT;PARTSTAT=DELEGATED;DELEGATED-TO='#13#10 + //4
' "MAILTO:[email protected]";CN=The Big Cheese:MAILTO:iamboss'#13#10 + //5
' @host2.com'#13#10 + //6
'ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Jane Doe'#13#10 + //7
' :MAILTO:[email protected]'#13#10 + //8
'END:VEVENT'#13#10+
'END:VCALENDAR'#13#10;
Item := Cal.Events[0].ATTENDEE_Add;
Item.Text := ';RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:'#13#10+
' mailto:[email protected]';
Assert.IsTrue(VarIsType(Item.Value,varDate));
Assert.AreEqual(EncodeDateTime(1996,07,04,12,00,00,0),TDateTime(Item.Value));
Cal.Free;
end;
procedure TCalendardTest.ParseLineTest1;
var
lText: String;
lName: String;
lValue: String;
lParams: TItemValue.TParamRecDynArray;
begin
lText := 'ATTENDEE;PARTSTAT=ACCEPTED;PARTSTAT1="DENIED":mailto:[email protected]';
Assert.IsTrue(TItemValue._ParseLine(lText,lName,lValue,lParams));
Assert.AreEqual('ATTENDEE',lName);
Assert.AreEqual('mailto:[email protected]',lValue);
Assert.AreEqual(2,Length(lParams));
Assert.AreEqual('PARTSTAT',lParams[0].Name);
Assert.AreEqual('ACCEPTED',lParams[0].Value);
Assert.AreEqual('PARTSTAT1',lParams[1].Name);
Assert.AreEqual('DENIED',lParams[1].Value);
end;
procedure TCalendardTest.ProdIDExample1;
var
Cal: TCalendar;
Item: TItemValue;
lText: String;
begin
Cal:= TCalendar.Create;
Item := Cal['PRODID'] as TItemValue;
Item.Text := '-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN';
lText := Cal.PRODID.Value;
Assert.AreEqual('-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN',lText);
Cal.Free;
end;
procedure TCalendardTest.Test2(const AValue1 : Integer;const AValue2 : Integer);
begin
end;
procedure TCalendardTest.TestDateTime;
var
lDateTime: TDateTime;
lGMT: Boolean;
lText: String;
begin
//DTSTART:19970714T133000 ;Local time
Assert.IsTrue(TISO8601._StrToDateTime('19970714T133000',lDateTime,lGMT));
lText := varToStr(lDateTime);
Assert.IsFalse(lGMT);
Assert.AreEqual('7/14/1997 1:30:00 PM',lText);
// DTSTART:19970714T173000Z ;UTC time
Assert.IsTrue(TISO8601._StrToDateTime('19970714T173000Z',lDateTime,lGMT));
lText := varToStr(lDateTime);
Assert.IsTrue(lGMT);
Assert.AreEqual('7/14/1997 5:30:00 PM',lText);
// DTSTART;TZID=US-Eastern:19970714T133000 ;Local time and time
Assert.IsTrue(TISO8601._StrToDateTime('19970714T133000',lDateTime,lGMT));
lText := varToStr(lDateTime);
Assert.IsFalse(lGMT);
Assert.AreEqual('7/14/1997 1:30:00 PM',lText);
end;
procedure TCalendardTest.TestDate;
var
lDateTime: TDateTime;
lGMT: Boolean;
lText: String;
begin
//DTSTART:19970714 ;Local time
Assert.IsTrue(TISO8601._StrToDateTime('19970714',lDateTime,lGMT));
Assert.IsFalse(lGMT);
lText := varToStr(lDateTime);
Assert.AreEqual('7/14/1997',lText);
end;
procedure TCalendardTest.TestTime1;
var
lValue: Variant;
lText: String;
lDateTime: TDateTime;
lGMT: Boolean;
begin
// X-TIMEOFDAY:083000
Assert.IsTrue(TISO8601._StrToDateTime('083000',lDateTime,lGMT));
Assert.IsFalse(lGMT);
lText := varToStr(lDateTime);
Assert.AreEqual('8:30:00 AM',lText);
// X-TIMEOFDAY:133000Z
Assert.IsTrue(TISO8601._StrToDateTime('133000Z',lDateTime,lGMT));
Assert.IsTrue(lGMT);
lText := varToStr(lDateTime);
Assert.AreEqual('1:30:00 PM',lText);
// X-TIMEOFDAY;TZID=US-Eastern:083000
Assert.IsTrue(TISO8601._StrToDateTime('083000',lDateTime,lGMT));
Assert.IsFalse(lGMT);
lText := varToStr(lDateTime);
Assert.AreEqual('8:30:00 AM',lText);
end;
initialization
TDUnitX.RegisterTestFixture(TCalendardTest);
end.