-
Notifications
You must be signed in to change notification settings - Fork 17
/
sample_tests.pas
108 lines (81 loc) · 1.59 KB
/
sample_tests.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
unit sample_tests;
{$mode objfpc}{$H+}
interface
uses
TestFramework;
type
TTestCaseFirst = class(TTestCase)
published
procedure TestWarning;
procedure TestOne;
procedure TestTwo;
procedure TestThree;
end;
TClassA = class(TTestCase)
published
procedure TestClassA1;
procedure TestClassA2; virtual;
end;
TClassB = class(TClassA)
published
procedure TestClassA2; override;
procedure TestClassB1;
procedure TestError;
end;
procedure RegisterTests;
implementation
uses
sysutils;
procedure RegisterTests;
begin
TestFramework.RegisterTest(TTestCaseFirst.Suite);
TestFramework.RegisterTest(TClassB.Suite);
end;
{ TTestCaseFirst }
procedure TTestCaseFirst.TestWarning;
begin
// Do nothing here - should cause a Warning
end;
procedure TTestCaseFirst.TestOne;
begin
Check(1 + 1 = 3, 'Catastrophic arithmetic failure!');
end;
procedure TTestCaseFirst.TestTwo;
begin
Check(1 + 1 = 2, 'Catastrophic arithmetic failure!');
end;
procedure TTestCaseFirst.TestThree;
var
s: string;
begin
s := 'hello';
CheckEquals('Hello', s, 'Failed CheckEquals');
end;
{ TClassA }
procedure TClassA.TestClassA1;
begin
fail('TClassA.TestClassA1');
end;
procedure TClassA.TestClassA2;
begin
Fail('This virtual method should never appear.');
end;
{ TClassB }
procedure TClassB.TestClassA2;
begin
Fail('Test overridden method');
end;
procedure TClassB.TestClassB1;
begin
sleep(2264);
Fail('Test sleep() causing extra time');
end;
procedure TClassB.TestError;
var
x, y: integer;
begin
x := 10;
y := 0;
Check(x / y = 0, 'Failed on 1');
end;
end.