source: tags/1.5.0/TestCases.pas

Last change on this file was 169, checked in by chronos, 17 months ago
  • Added: JSON data export and import.
File size: 14.5 KB
Line 
1unit TestCases;
2
3interface
4
5uses
6 Classes, SysUtils, Test, TestCase;
7
8function InitTestCases: TTestCases;
9
10
11implementation
12
13uses
14 VCard, Table;
15
16const
17 VCardVersion = 'VERSION:2.1';
18 UnixLineEnding = #10;
19 MacLineEnding = #13;
20
21function BeginEnd(Text: string; WithVersion: Boolean = True): string;
22begin
23 Result := VCardBegin + VCardLineEnding;
24 if WithVersion then Result := Result + VCardVersion + VCardLineEnding;
25 Result := Result + Text + VCardEnd + VCardLineEnding;
26end;
27
28function InitTestCases: TTestCases;
29begin
30 Result := TTestCases.Create;
31 with Result do begin
32 with TTestCaseLoadSave(AddNew('Load and save', TTestCaseLoadSave)) do begin
33 Input := BeginEnd(
34 'N:Surname;Name' + VCardLineEnding +
35 'FN:Name Surname' + VCardLineEnding);
36 Output := Input;
37 end;
38 with TTestCaseLoadSave(AddNew('Long text', TTestCaseLoadSave)) do begin
39 Input := BeginEnd(
40 'NOTE:This is some long test which is really multi-lined each line is on dif' + VCardLineEnding +
41 ' ferent line so it is on multiple lines.' + VCardLineEnding +
42 VCardLineEnding);
43 Output := Input;
44 end;
45 with TTestCaseLoadSave(AddNew('Multi-line', TTestCaseLoadSave)) do begin
46 Input := BeginEnd(
47 'NOTE:First line\nsecond line\nempty line\n\nlast line' + VCardLineEnding);
48 Output := Input;
49 end;
50 with TTestCaseLoadSave(AddNew('Quoted-printable load-save', TTestCaseLoadSave)) do begin
51 Input := BeginEnd(
52 'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
53 Output := Input;
54 end;
55 with TTestCaseLoadSave(AddNew('Quoted-printable load-save multi-line', TTestCaseLoadSave)) do begin
56 Input := BeginEnd(
57 'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=ADJm=C3=A9n=' + VCardLineEnding +
58 'o=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding +
59 VCardLineEnding);
60 Output := Input;
61 end;
62 with TTestCaseLoadSave(AddNew('Base64 load-save (encoding=base64)', TTestCaseLoadSave)) do begin
63 Input := BeginEnd(
64 'FN;ENCODING=BASE64:VGVzdCBzdHJpbmc=' + VCardLineEnding);
65 Output := Input;
66 end;
67 with TTestCaseLoadSave(AddNew('Base64 load-save (base64)', TTestCaseLoadSave)) do begin
68 Input := BeginEnd(
69 'FN;BASE64:VGVzdCBzdHJpbmc=' + VCardLineEnding);
70 Output := Input;
71 end;
72 with TTestCaseLoadSave(AddNew('Base64 load-save (encoding=b)', TTestCaseLoadSave)) do begin
73 Input := BeginEnd(
74 'FN;ENCODING=B:VGVzdCBzdHJpbmc=' + VCardLineEnding);
75 Output := Input;
76 end;
77 with TTestCaseLoadSave(AddNew('Base64 load-save multi-line', TTestCaseLoadSave)) do begin
78 Input := BeginEnd(
79 'FN;ENCODING=BASE64:U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIFNvbWUgdmVyeSBsb25nIHN0cmlu' + VCardLineEnding +
80 ' ZyBTb21lIHZlcnkgbG9uZyBzdHJpbmcgU29tZSB2ZXJ5IGxvbmcgc3RyaW5n' + VCardLineEnding +
81 VCardLineEnding);
82 Output := Input;
83 end;
84 //AddNew('Image format', TTestCaseLoadSave);
85 with TTestCaseLoadSave(AddNew('Empty', TTestCaseLoadSave)) do begin
86 Input := '';
87 Output := '';
88 end;
89 with TTestCaseLoadSave(AddNew('Begin only', TTestCaseLoadSave)) do begin
90 Input := VCardBegin;
91 Output := '';
92 end;
93 with TTestCaseLoadSave(AddNew('Missing end', TTestCaseLoadSave)) do begin
94 Input := VCardBegin + VCardLineEnding +
95 VCardVersion + VCardLineEnding +
96 'N:Surname;Name' + VCardLineEnding +
97 'FN:Name Surname' + VCardLineEnding;
98 Output := '';
99 end;
100 with TTestCaseLoadSave(AddNew('Missing start', TTestCaseLoadSave)) do begin
101 Input := VCardVersion + VCardLineEnding +
102 'N:Surname;Name' + VCardLineEnding +
103 'FN:Name Surname' + VCardLineEnding +
104 VCardEnd + VCardLineEnding;
105 Output := '';
106 end;
107 with TTestCaseCheckProperty(AddNew('Property FN', TTestCaseCheckProperty)) do begin
108 Index := cfFullName;
109 Value := 'Name Surname';
110 Input := BeginEnd('FN:' + Value + VCardLineEnding);
111 end;
112 with TTestCaseCheckProperty(AddNew('Escaped new lines in text', TTestCaseCheckProperty)) do begin
113 Index := cfNote;
114 Value := 'Line' + #13#10 + 'Line';
115 Input := BeginEnd('NOTE:Line\nLine' + VCardLineEnding);
116 end;
117 with TTestCaseCheckProperty(AddNew('Compound value', TTestCaseCheckProperty)) do begin
118 Index := cfFirstName;
119 Value := 'FirstName';
120 Input := BeginEnd('N:Surname;FirstName;;;' + VCardLineEnding);
121 end;
122 with TTestCaseCheckProperty(AddNew('Quoted-printable special symbols', TTestCaseCheckProperty)) do begin
123 Index := cfFullName;
124 Value := 'Jméno Příjmení';
125 Input := BeginEnd(
126 'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
127 end;
128 with TTestCaseCheckProperty(AddNew('Base64 special symbols', TTestCaseCheckProperty)) do begin
129 Index := cfFullName;
130 Value := 'Jméno Příjmení';
131 Input := BeginEnd('FN;ENCODING=BASE64:Sm3DqW5vIFDFmcOtam1lbsOt' + VCardLineEnding);
132 end;
133 with TTestCaseLoadSave(AddNew('Remove exact duplicates', TTestCaseLoadSave)) do begin
134 Input := BeginEnd(
135 'N:Surname;Name' + VCardLineEnding +
136 'FN:Name Surname' + VCardLineEnding) +
137 BeginEnd(
138 'N:Surname2;Name2' + VCardLineEnding +
139 'FN:Name2 Surname2' + VCardLineEnding) +
140 BeginEnd(
141 'N:Surname;Name' + VCardLineEnding +
142 'FN:Name Surname' + VCardLineEnding) +
143 BeginEnd(
144 'N:Surname;Name' + VCardLineEnding +
145 'FN:Name Surname' + VCardLineEnding +
146 'NOTE:Note' + VCardLineEnding) +
147 BeginEnd(
148 'N:Surname;Name' + VCardLineEnding +
149 'FN:Name Surname' + VCardLineEnding);
150 Action := akRemoveExactDuplicates;
151 Output := BeginEnd(
152 'N:Surname;Name' + VCardLineEnding +
153 'FN:Name Surname' + VCardLineEnding) +
154 BeginEnd(
155 'N:Surname2;Name2' + VCardLineEnding +
156 'FN:Name2 Surname2' + VCardLineEnding) +
157 BeginEnd(
158 'N:Surname;Name' + VCardLineEnding +
159 'FN:Name Surname' + VCardLineEnding +
160 'NOTE:Note' + VCardLineEnding);
161 end;
162 with TTestCaseLoadSave(AddNew('Normalize Unix line endings', TTestCaseLoadSave)) do begin
163 Input := VCardBegin + UnixLineEnding +
164 VCardVersion + UnixLineEnding +
165 'N:Surname;Name' + UnixLineEnding +
166 'FN:Name Surname' + UnixLineEnding +
167 VCardEnd + UnixLineEnding;
168 Output := VCardBegin + VCardLineEnding +
169 VCardVersion + VCardLineEnding +
170 'N:Surname;Name' + VCardLineEnding +
171 'FN:Name Surname' + VCardLineEnding +
172 VCardEnd + VCardLineEnding;
173 end;
174 with TTestCaseLoadSave(AddNew('Normalize Mac line endings', TTestCaseLoadSave)) do begin
175 Input := VCardBegin + MacLineEnding +
176 VCardVersion + MacLineEnding +
177 'N:Surname;Name' + MacLineEnding +
178 'FN:Name Surname' + MacLineEnding +
179 VCardEnd + MacLineEnding;
180 Output := VCardBegin + VCardLineEnding +
181 VCardVersion + VCardLineEnding +
182 'N:Surname;Name' + VCardLineEnding +
183 'FN:Name Surname' + VCardLineEnding +
184 VCardEnd + VCardLineEnding;
185 end;
186
187 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove exact duplicates', TTestCaseVCardProcessor)) do begin
188 Processor.RemoveExactDuplicates := True;
189 Input := BeginEnd(
190 'N:Surname;Name' + VCardLineEnding +
191 'FN:Name Surname' + VCardLineEnding) +
192 BeginEnd(
193 'N:Surname2;Name2' + VCardLineEnding +
194 'FN:Name2 Surname2' + VCardLineEnding) +
195 BeginEnd(
196 'N:Surname;Name' + VCardLineEnding +
197 'FN:Name Surname' + VCardLineEnding) +
198 BeginEnd(
199 'N:Surname;Name' + VCardLineEnding +
200 'FN:Name Surname' + VCardLineEnding +
201 'NOTE:Note' + VCardLineEnding) +
202 BeginEnd(
203 'N:Surname;Name' + VCardLineEnding +
204 'FN:Name Surname' + VCardLineEnding);
205 Output := BeginEnd(
206 'N:Surname;Name' + VCardLineEnding +
207 'FN:Name Surname' + VCardLineEnding) +
208 BeginEnd(
209 'N:Surname2;Name2' + VCardLineEnding +
210 'FN:Name2 Surname2' + VCardLineEnding) +
211 BeginEnd(
212 'N:Surname;Name' + VCardLineEnding +
213 'FN:Name Surname' + VCardLineEnding +
214 'NOTE:Note' + VCardLineEnding);
215 end;
216 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove phone spaces', TTestCaseVCardProcessor)) do begin
217 Processor.RemovePhoneSpaces := True;
218 Input := BeginEnd('TEL: 123 456 789 ' + VCardLineEnding) +
219 BeginEnd('TEL;CELL:919 191 919' + VCardLineEnding);
220 Output := BeginEnd('TEL:123456789' + VCardLineEnding) +
221 BeginEnd('TEL;CELL:919191919' + VCardLineEnding);
222 end;
223 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove photos', TTestCaseVCardProcessor)) do begin
224 Processor.RemovePhotos := True;
225 Input := BeginEnd('N:Surname;Name' + VCardLineEnding +
226 'FN:Name Surname' + VCardLineEnding +
227 'PHOTO:dadsa' + VCardLineEnding) +
228 BeginEnd('N:Surname;Name' + VCardLineEnding +
229 'FN:Name Surname' + VCardLineEnding +
230 'PHOTO:dadsa' + VCardLineEnding +
231 'PHOTO:adsadadsa' + VCardLineEnding);
232 Output := BeginEnd('N:Surname;Name' + VCardLineEnding +
233 'FN:Name Surname' + VCardLineEnding) +
234 BeginEnd('N:Surname;Name' + VCardLineEnding +
235 'FN:Name Surname' + VCardLineEnding);
236 end;
237 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Order', TTestCaseVCardProcessor)) do begin
238 Processor.Order := True;
239 Input := BeginEnd('N:Surname2;Name2' + VCardLineEnding +
240 'FN:Name2 Surname2' + VCardLineEnding) +
241 BeginEnd('N:Surname1;Name1' + VCardLineEnding +
242 'FN:Name1 Surname1' + VCardLineEnding) +
243 BeginEnd('N:Surname3;Name3' + VCardLineEnding +
244 'FN:Name3 Surname3' + VCardLineEnding);
245 Output := BeginEnd('FN:Name1 Surname1' + VCardLineEnding +
246 'N:Surname1;Name1' + VCardLineEnding) +
247 BeginEnd('FN:Name2 Surname2' + VCardLineEnding +
248 'N:Surname2;Name2'+ VCardLineEnding) +
249 BeginEnd('FN:Name3 Surname3' + VCardLineEnding +
250 'N:Surname3;Name3' + VCardLineEnding);
251 end;
252 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Add phone country code', TTestCaseVCardProcessor)) do begin
253 Processor.AddDefaultPhoneCountryPrefix := True;
254 Processor.DefaultPhoneCountryCode := '+470';
255 Processor.NonPrefixedPhoneLength := 9;
256 Input := BeginEnd('TEL: 123 456 789 ' + VCardLineEnding) +
257 BeginEnd('TEL;CELL:919 191 919' + VCardLineEnding) +
258 BeginEnd('TEL;CELL:+421 919 191 919' + VCardLineEnding) +
259 BeginEnd('TEL;CELL:*#1234' + VCardLineEnding);
260 Output := BeginEnd('TEL:+470 123 456 789 ' + VCardLineEnding) +
261 BeginEnd('TEL;CELL:+470919 191 919' + VCardLineEnding) +
262 BeginEnd('TEL;CELL:+421 919 191 919' + VCardLineEnding) +
263 BeginEnd('TEL;CELL:*#1234' + VCardLineEnding);
264 end;
265 with TTestCaseVCardProcessor(AddNew('VCardProcessor - Convert international call prefix to country code', TTestCaseVCardProcessor)) do begin
266 Processor.ConvertInternationalCallPrefixToCountryCode := True;
267 Processor.DefaultInternationalCallPrefix := '00420';
268 Processor.DefaultPhoneCountryCode := '+470';
269 Input := BeginEnd('TEL:00420123456789' + VCardLineEnding) +
270 BeginEnd('TEL;CELL:00420 919 191 919 ' + VCardLineEnding) +
271 BeginEnd('TEL;CELL:00421919191919' + VCardLineEnding);
272 Output := BeginEnd('TEL:+470123456789' + VCardLineEnding) +
273 BeginEnd('TEL;CELL:+470 919 191 919 ' + VCardLineEnding) +
274 BeginEnd('TEL;CELL:00421919191919' + VCardLineEnding);
275 end;
276
277 with TTestCaseVCardExportImport(AddNew('Export/Import CSV', TTestCaseVCardExportImport)) do begin
278 Format := tfCsv;
279 HumanReadableHeader := False;
280 Input := BeginEnd(
281 'N:Surname;Name' + VCardLineEnding +
282 'FN:Name Surname' + VCardLineEnding) +
283 BeginEnd(
284 'N:Surname2;Name2' + VCardLineEnding +
285 'FN:Name2 Surname2' + VCardLineEnding);
286 Output := Input;
287 end;
288 with TTestCaseVCardExportImport(AddNew('Export/Import CSV human header', TTestCaseVCardExportImport)) do begin
289 Format := tfCsv;
290 HumanReadableHeader := True;
291 Input := BeginEnd(
292 'N:Surname;Name' + VCardLineEnding +
293 'FN:Name Surname' + VCardLineEnding) +
294 BeginEnd(
295 'N:Surname2;Name2' + VCardLineEnding +
296 'FN:Name2 Surname2' + VCardLineEnding);
297 Output := Input;
298 end;
299 with TTestCaseVCardExportImport(AddNew('Export/Import MediaWiki', TTestCaseVCardExportImport)) do begin
300 Format := tfMediaWiki;
301 HumanReadableHeader := False;
302 Input := BeginEnd(
303 'N:Surname;Name' + VCardLineEnding +
304 'FN:Name Surname' + VCardLineEnding) +
305 BeginEnd(
306 'N:Surname2;Name2' + VCardLineEnding +
307 'FN:Name2 Surname2' + VCardLineEnding);
308 Output := Input;
309 end;
310 with TTestCaseVCardExportImport(AddNew('Export/Import XML', TTestCaseVCardExportImport)) do begin
311 Format := tfXml;
312 HumanReadableHeader := False;
313 Input := BeginEnd(
314 'N:Surname;Name' + VCardLineEnding +
315 'FN:Name Surname' + VCardLineEnding) +
316 BeginEnd(
317 'N:Surname2;Name2' + VCardLineEnding +
318 'FN:Name2 Surname2' + VCardLineEnding);
319 Output := Input;
320 end;
321 with TTestCaseVCardExportImport(AddNew('Export/Import JSON', TTestCaseVCardExportImport)) do begin
322 Format := tfJSON;
323 HumanReadableHeader := False;
324 Input := BeginEnd(
325 'N:Surname;Name' + VCardLineEnding +
326 'FN:Name Surname' + VCardLineEnding) +
327 BeginEnd(
328 'N:Surname2;Name2' + VCardLineEnding +
329 'FN:Name2 Surname2' + VCardLineEnding);
330 Output := Input;
331 end;
332
333 with TTestCaseLoadSave(AddNew('Merge same cell phone', TTestCaseLoadSave)) do begin
334 Input := VCardBegin + MacLineEnding +
335 VCardVersion + MacLineEnding +
336 'N:Surname;Name' + MacLineEnding +
337 'FN:Name Surname' + MacLineEnding +
338 'TEL;CELL:123456789' + MacLineEnding +
339 VCardEnd + MacLineEnding +
340
341 VCardBegin + MacLineEnding +
342 VCardVersion + MacLineEnding +
343 'N:Surname2;Name' + MacLineEnding +
344 'FN:Name Surname2' + MacLineEnding +
345 'TEL;CELL:123456789' + MacLineEnding +
346 VCardEnd + MacLineEnding;
347 Output := VCardBegin + VCardLineEnding +
348 VCardVersion + VCardLineEnding +
349 'N:Surname;Name' + VCardLineEnding +
350 'FN:Name Surname' + VCardLineEnding +
351 'TEL;CELL:123456789' + MacLineEnding +
352 VCardEnd + VCardLineEnding;
353 end;
354 end;
355end;
356
357end.
358
Note: See TracBrowser for help on using the repository browser.