source: trunk/Test.pas

Last change on this file was 168, checked in by chronos, 17 months ago
File size: 4.1 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 { TTestCaseCheckProperty }
22
23 TTestCaseCheckProperty = class(TTestCase)
24 Input: string;
25 ContactIndex: Integer;
26 Index: TContactFieldIndex;
27 Value: string;
28 procedure Run; override;
29 end;
30
31 { TTestCaseVCardProcessor }
32
33 TTestCaseVCardProcessor = class(TTestCase)
34 Input: string;
35 Output: string;
36 Processor: TVCardProcessor;
37 procedure Run; override;
38 constructor Create; override;
39 destructor Destroy; override;
40 end;
41
42 { TTestCaseVCardExportImport }
43
44 TTestCaseVCardExportImport = class(TTestCase)
45 Input: string;
46 Output: string;
47 Format: TTableFormat;
48 HumanReadableHeader: Boolean;
49 procedure Run; override;
50 end;
51
52
53implementation
54
55uses
56 VCardFile;
57
58resourcestring
59 SExpected = 'Expected:';
60 SOutput = 'Output:';
61 SExport = 'Export:';
62
63{ TTestCaseVCardExportImport }
64
65procedure TTestCaseVCardExportImport.Run;
66var
67 Lines: TStringList;
68 ExportedLines: TStringList;
69begin
70 Lines := TStringList.Create;
71 ExportedLines := TStringList.Create;
72 try
73 with TVCardFile.Create(nil) do
74 try
75 Lines.Text := Input;
76 VCard.LoadFromStrings(Lines);
77
78 VCard.ExportToStrings(ExportedLines, Format, HumanReadableHeader);
79 VCard.Contacts.Clear;
80 VCard.ImportFromStrings(ExportedLines, Format, HumanReadableHeader);
81
82 Lines.Text := '';
83 VCard.SaveToStrings(Lines);
84 Evaluate(Lines.Text = Output);
85 Log := SExpected + LineEnding +
86 '"' + Output + '"' + LineEnding + LineEnding +
87 SExport + LineEnding +
88 '"' + ExportedLines.Text + '"' + LineEnding + LineEnding +
89 SOutput + LineEnding +
90 '"' + Lines.Text + '"';
91 finally
92 Free;
93 end;
94 finally
95 FreeAndNil(Lines);
96 FreeAndNil(ExportedLines);
97 end;
98end;
99
100{ TTestCaseVCardProcessor }
101
102procedure TTestCaseVCardProcessor.Run;
103var
104 Lines: TStringList;
105begin
106 Lines := TStringList.Create;
107 try
108 with TVCardFile.Create(nil) do
109 try
110 Lines.Text := Input;
111 VCard.LoadFromStrings(Lines);
112
113 Processor.Process(VCard);
114
115 Lines.Text := '';
116 VCard.SaveToStrings(Lines);
117 Evaluate(Lines.Text = Output);
118 Log := SExpected + LineEnding +
119 '"' + Output + '"' + LineEnding + LineEnding +
120 SOutput + LineEnding +
121 '"' + Lines.Text + '"';
122 finally
123 Free;
124 end;
125 finally
126 Lines.Free;
127 end;
128end;
129
130constructor TTestCaseVCardProcessor.Create;
131begin
132 inherited;
133 Processor := TVCardProcessor.Create(nil);
134end;
135
136destructor TTestCaseVCardProcessor.Destroy;
137begin
138 FreeAndNil(Processor);
139 inherited;
140end;
141
142{ TTestCaseCheckProperty }
143
144procedure TTestCaseCheckProperty.Run;
145var
146 Lines: TStringList;
147 PropertyValue: string;
148begin
149 Lines := TStringList.Create;
150 try
151 with TVCardFile.Create(nil) do
152 try
153 Lines.Text := Input;
154 VCard.LoadFromStrings(Lines);
155 if ContactIndex < VCard.Contacts.Count then begin
156 PropertyValue := VCard.Contacts[ContactIndex].Fields[Index];
157 Evaluate(PropertyValue = Value);
158 end else Fail;
159 Log := SExpected + LineEnding +
160 '"' + Value + '"' + LineEnding + LineEnding +
161 SOutput + LineEnding +
162 '"' + PropertyValue + '"';
163 finally
164 Free;
165 end;
166 finally
167 Lines.Free;
168 end;
169end;
170
171{ TTestCaseLoadSave }
172
173procedure TTestCaseLoadSave.Run;
174var
175 Lines: TStringList;
176begin
177 Lines := TStringList.Create;
178 try
179 with TVCardFile.Create(nil) do
180 try
181 Lines.Text := Input;
182 VCard.LoadFromStrings(Lines);
183
184 if Action = akRemoveExactDuplicates then
185 VCard.Contacts.RemoveExactDuplicates;
186
187 Lines.Text := '';
188 VCard.SaveToStrings(Lines);
189 Evaluate(Lines.Text = Output);
190 Log := SExpected + LineEnding +
191 '"' + Output + '"' + LineEnding + LineEnding +
192 SOutput + LineEnding +
193 '"' + Lines.Text + '"';
194 finally
195 Free;
196 end;
197 finally
198 Lines.Free;
199 end;
200end;
201
202end.
203
Note: See TracBrowser for help on using the repository browser.