source: trunk/Test.pas

Last change on this file was 199, checked in by chronos, 7 weeks ago
  • Fixed: Handling escaped semicolon in indexed property values.
File size: 5.0 KB
Line 
1unit Test;
2
3interface
4
5uses
6 Classes, SysUtils, VCard, VCardProcessor, TestCase, Table;
7
8type
9
10 TTestCaseActionKind = (akNone, akRemoveExactDuplicates);
11
12 { TTestCaseLoadSave }
13
14 TTestCaseLoadSave = class(TTestCase)
15 Input: string;
16 Output: string;
17 Action: TTestCaseActionKind;
18 procedure Run; override;
19 end;
20
21 { TTestCasePropertyRead }
22
23 TTestCasePropertyRead = class(TTestCase)
24 Input: string;
25 ContactIndex: Integer;
26 Index: TContactFieldIndex;
27 Value: string;
28 procedure Run; override;
29 end;
30
31 { TTestCasePropertyWrite }
32
33 TTestCasePropertyWrite = class(TTestCase)
34 Input: string;
35 Output: string;
36 ContactIndex: Integer;
37 Index: TContactFieldIndex;
38 Value: string;
39 procedure Run; override;
40 end;
41
42 { TTestCaseVCardProcessor }
43
44 TTestCaseVCardProcessor = class(TTestCase)
45 Input: string;
46 Output: string;
47 Processor: TVCardProcessor;
48 procedure Run; override;
49 constructor Create; override;
50 destructor Destroy; override;
51 end;
52
53 { TTestCaseVCardExportImport }
54
55 TTestCaseVCardExportImport = class(TTestCase)
56 Input: string;
57 Output: string;
58 Format: TTableFormat;
59 HumanReadableHeader: Boolean;
60 procedure Run; override;
61 end;
62
63
64implementation
65
66uses
67 VCardFile;
68
69resourcestring
70 SExpected = 'Expected:';
71 SOutput = 'Output:';
72 SExport = 'Export:';
73
74{ TTestCaseVCardExportImport }
75
76procedure TTestCaseVCardExportImport.Run;
77var
78 Lines: TStringList;
79 ExportedLines: TStringList;
80begin
81 Lines := TStringList.Create;
82 ExportedLines := TStringList.Create;
83 try
84 with TVCardFile.Create(nil) do
85 try
86 Lines.Text := Input;
87 VCard.LoadFromStrings(Lines);
88
89 VCard.ExportToStrings(ExportedLines, Format, HumanReadableHeader);
90 VCard.Contacts.Clear;
91 VCard.ImportFromStrings(ExportedLines, Format, HumanReadableHeader);
92
93 Lines.Text := '';
94 VCard.SaveToStrings(Lines);
95 Evaluate(Lines.Text = Output);
96 Log := SExpected + LineEnding +
97 '"' + Output + '"' + LineEnding + LineEnding +
98 SExport + LineEnding +
99 '"' + ExportedLines.Text + '"' + LineEnding + LineEnding +
100 SOutput + LineEnding +
101 '"' + Lines.Text + '"';
102 finally
103 Free;
104 end;
105 finally
106 FreeAndNil(Lines);
107 FreeAndNil(ExportedLines);
108 end;
109end;
110
111{ TTestCaseVCardProcessor }
112
113procedure TTestCaseVCardProcessor.Run;
114var
115 Lines: TStringList;
116begin
117 Lines := TStringList.Create;
118 try
119 with TVCardFile.Create(nil) do
120 try
121 Lines.Text := Input;
122 VCard.LoadFromStrings(Lines);
123
124 Processor.Process(VCard);
125
126 Lines.Text := '';
127 VCard.SaveToStrings(Lines);
128 Evaluate(Lines.Text = Output);
129 Log := SExpected + LineEnding +
130 '"' + Output + '"' + LineEnding + LineEnding +
131 SOutput + LineEnding +
132 '"' + Lines.Text + '"';
133 finally
134 Free;
135 end;
136 finally
137 Lines.Free;
138 end;
139end;
140
141constructor TTestCaseVCardProcessor.Create;
142begin
143 inherited;
144 Processor := TVCardProcessor.Create(nil);
145end;
146
147destructor TTestCaseVCardProcessor.Destroy;
148begin
149 FreeAndNil(Processor);
150 inherited;
151end;
152
153{ TTestCasePropertyRead }
154
155procedure TTestCasePropertyRead.Run;
156var
157 Lines: TStringList;
158 PropertyValue: string;
159begin
160 Lines := TStringList.Create;
161 try
162 with TVCardFile.Create(nil) do
163 try
164 Lines.Text := Input;
165 VCard.LoadFromStrings(Lines);
166 if ContactIndex < VCard.Contacts.Count then begin
167 PropertyValue := VCard.Contacts[ContactIndex].Fields[Index];
168 Evaluate(PropertyValue = Value);
169 end else Fail;
170 Log := SExpected + LineEnding +
171 '"' + Value + '"' + LineEnding + LineEnding +
172 SOutput + LineEnding +
173 '"' + PropertyValue + '"';
174 finally
175 Free;
176 end;
177 finally
178 Lines.Free;
179 end;
180end;
181
182{ TTestCasePropertyWrite }
183
184procedure TTestCasePropertyWrite.Run;
185var
186 Lines: TStringList;
187begin
188 Lines := TStringList.Create;
189 try
190 with TVCardFile.Create(nil) do
191 try
192 Lines.Text := Input;
193 VCard.LoadFromStrings(Lines);
194 if ContactIndex < VCard.Contacts.Count then begin
195 VCard.Contacts[ContactIndex].Fields[Index] := Value;
196 end else Fail;
197 Lines.Clear;
198 VCard.SaveToStrings(Lines);
199 Log := SExpected + LineEnding +
200 '"' + Output + '"' + LineEnding + LineEnding +
201 SOutput + LineEnding +
202 '"' + Lines.Text + '"';
203 Evaluate(Lines.Text = Output);
204 finally
205 Free;
206 end;
207 finally
208 Lines.Free;
209 end;
210end;
211
212{ TTestCaseLoadSave }
213
214procedure TTestCaseLoadSave.Run;
215var
216 Lines: TStringList;
217begin
218 Lines := TStringList.Create;
219 try
220 with TVCardFile.Create(nil) do
221 try
222 Lines.Text := Input;
223 VCard.LoadFromStrings(Lines);
224
225 if Action = akRemoveExactDuplicates then
226 VCard.Contacts.RemoveExactDuplicates;
227
228 Lines.Text := '';
229 VCard.SaveToStrings(Lines);
230 Evaluate(Lines.Text = Output);
231 Log := SExpected + LineEnding +
232 '"' + Output + '"' + LineEnding + LineEnding +
233 SOutput + LineEnding +
234 '"' + Lines.Text + '"';
235 finally
236 Free;
237 end;
238 finally
239 Lines.Free;
240 end;
241end;
242
243end.
244
Note: See TracBrowser for help on using the repository browser.