Last change
on this file since 93 was 91, checked in by chronos, 3 years ago |
- Added: A windows for showing log output for selected test case.
- Added: Various load-save tests.
- Modified: Improved parsing vCard format.
|
File size:
1.7 KB
|
Line | |
---|
1 | unit UTest;
|
---|
2 |
|
---|
3 | {$mode Delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, fgl;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TTestResult = (trNone, trPassed, trFailed);
|
---|
12 |
|
---|
13 | { TTestCase }
|
---|
14 |
|
---|
15 | TTestCase = class
|
---|
16 | public
|
---|
17 | Name: string;
|
---|
18 | Result: TTestResult;
|
---|
19 | Log: string;
|
---|
20 | procedure Run; virtual;
|
---|
21 | end;
|
---|
22 |
|
---|
23 | TTestCaseClass = class of TTestCase;
|
---|
24 |
|
---|
25 | { TTestCases }
|
---|
26 |
|
---|
27 | TTestCases = class(TFPGObjectList<TTestCase>)
|
---|
28 | function AddNew(Name: string; TestClass: TTestCaseClass): TTestCase;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | { TTestCaseLoadSave }
|
---|
32 |
|
---|
33 | TTestCaseLoadSave = class(TTestCase)
|
---|
34 | Input: string;
|
---|
35 | Output: string;
|
---|
36 | procedure Run; override;
|
---|
37 | procedure Evaluate(Passed: Boolean);
|
---|
38 | end;
|
---|
39 |
|
---|
40 | const
|
---|
41 | ResultText: array[TTestResult] of string = ('None', 'Passed', 'Failed');
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | uses
|
---|
47 | UContact;
|
---|
48 |
|
---|
49 | { TTestCaseLoadSave }
|
---|
50 |
|
---|
51 | procedure TTestCaseLoadSave.Run;
|
---|
52 | var
|
---|
53 | Lines: TStringList;
|
---|
54 | begin
|
---|
55 | Lines := TStringList.Create;
|
---|
56 | try
|
---|
57 | with TContactsFile.Create do
|
---|
58 | try
|
---|
59 | Lines.Text := Input;
|
---|
60 | LoadFromStrings(Lines);
|
---|
61 | Lines.Text := '';
|
---|
62 | SaveToStrings(Lines);
|
---|
63 | Evaluate(Lines.Text = Output);
|
---|
64 | if Result <> trPassed then begin
|
---|
65 | Log := 'Expected:' + LineEnding +
|
---|
66 | '"' + Output + '"' + LineEnding + LineEnding +
|
---|
67 | 'Output:' + LineEnding +
|
---|
68 | '"' + Lines.Text + '"';
|
---|
69 | end;
|
---|
70 | finally
|
---|
71 | Free;
|
---|
72 | end;
|
---|
73 | finally
|
---|
74 | Lines.Free;
|
---|
75 | end;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TTestCaseLoadSave.Evaluate(Passed: Boolean);
|
---|
79 | begin
|
---|
80 | if Passed then Result := trPassed
|
---|
81 | else Result := trFailed;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | { TTestCase }
|
---|
85 |
|
---|
86 | procedure TTestCase.Run;
|
---|
87 | begin
|
---|
88 |
|
---|
89 | end;
|
---|
90 |
|
---|
91 | { TTestCases }
|
---|
92 |
|
---|
93 | function TTestCases.AddNew(Name: string; TestClass: TTestCaseClass): TTestCase;
|
---|
94 | begin
|
---|
95 | Result := TestClass.Create;
|
---|
96 | Result.Name := Name;
|
---|
97 | Add(Result);
|
---|
98 | end;
|
---|
99 |
|
---|
100 | end.
|
---|
101 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.