Skip to content

Commit fb60d6f

Browse files
committed
Add unit tests for core modules
1 parent 0ee8120 commit fb60d6f

5 files changed

Lines changed: 162 additions & 2 deletions

File tree

tests/console.lpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
{$mode objfpc}{$H+}
44

55
uses
6-
Classes, consoletestrunner, test_insertbuilder
6+
Classes, consoletestrunner,
7+
test_insertbuilder, test_dclasses, test_dopf, test_dutils
78
;
89
type
910

tests/gui.lpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
{$mode objfpc}{$H+}
44

55
uses
6-
Interfaces, Forms, GuiTestRunner, test_insertbuilder;
6+
Interfaces, Forms, GuiTestRunner,
7+
test_insertbuilder, test_dclasses, test_dopf, test_dutils;
78

89
{$R *.res}
910

tests/test_dclasses.pas

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
unit test_dclasses;
2+
3+
{$mode objfpc}{$H+}
4+
5+
interface
6+
7+
uses
8+
fpcunit, testregistry, dclasses, Classes;
9+
10+
type
11+
TTestDClasses = class(TTestCase)
12+
published
13+
procedure TestInheritances;
14+
end;
15+
16+
implementation
17+
18+
procedure TTestDClasses.TestInheritances;
19+
begin
20+
AssertTrue(EdException.InheritsFrom(Exception));
21+
AssertTrue(TdObject.InheritsFrom(TObject));
22+
AssertTrue(TdComponent.InheritsFrom(TComponent));
23+
end;
24+
25+
initialization
26+
RegisterTest(TTestDClasses);
27+
end.

tests/test_dopf.pas

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
unit test_dopf;
2+
3+
{$mode objfpc}{$H+}
4+
5+
interface
6+
7+
uses
8+
fpcunit, testregistry, dopf, Classes;
9+
10+
type
11+
TTestDOpf = class(TTestCase)
12+
published
13+
procedure TestConnectionBrokerConnect;
14+
procedure TestGConnectionCreate;
15+
end;
16+
17+
implementation
18+
19+
type
20+
TMyConnection = class(specialize TdGConnection<TdConnectionBroker, TdLogger>);
21+
22+
procedure TTestDOpf.TestConnectionBrokerConnect;
23+
var
24+
B: TdConnectionBroker;
25+
begin
26+
B := TdConnectionBroker.Create;
27+
try
28+
try
29+
B.Connect;
30+
Fail('Expected exception');
31+
except
32+
on E: EdNotImplemented do ;
33+
end;
34+
finally
35+
B.Free;
36+
end;
37+
end;
38+
39+
procedure TTestDOpf.TestGConnectionCreate;
40+
var
41+
C: TMyConnection;
42+
begin
43+
C := TMyConnection.Create(nil);
44+
try
45+
AssertTrue(Assigned(C.Broker));
46+
AssertTrue(Assigned(C.Logger));
47+
finally
48+
C.Free;
49+
end;
50+
end;
51+
52+
initialization
53+
RegisterTest(TTestDOpf);
54+
end.

tests/test_dutils.pas

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
unit test_dutils;
2+
3+
{$mode objfpc}{$H+}
4+
5+
interface
6+
7+
uses
8+
fpcunit, testregistry, dutils;
9+
10+
type
11+
TTestDUtils = class(TTestCase)
12+
published
13+
procedure TestParameterizeSQLNilParams;
14+
procedure TestGetFieldsNilObject;
15+
procedure TestSetFieldsNilObject;
16+
procedure TestGetParamsNilObject;
17+
procedure TestSetParamsNilObject;
18+
end;
19+
20+
implementation
21+
22+
procedure TTestDUtils.TestParameterizeSQLNilParams;
23+
var
24+
S: string;
25+
begin
26+
S := 'select * from t where id=:id';
27+
try
28+
dParameterizeSQL(S, nil);
29+
Fail('Expected exception');
30+
except
31+
on E: EdException do ;
32+
end;
33+
end;
34+
35+
procedure TTestDUtils.TestGetFieldsNilObject;
36+
begin
37+
try
38+
dGetFields(nil, nil);
39+
Fail('Expected exception');
40+
except
41+
on E: EdException do ;
42+
end;
43+
end;
44+
45+
procedure TTestDUtils.TestSetFieldsNilObject;
46+
begin
47+
try
48+
dSetFields(nil, nil);
49+
Fail('Expected exception');
50+
except
51+
on E: EdException do ;
52+
end;
53+
end;
54+
55+
procedure TTestDUtils.TestGetParamsNilObject;
56+
begin
57+
try
58+
dGetParams(nil, nil);
59+
Fail('Expected exception');
60+
except
61+
on E: EdException do ;
62+
end;
63+
end;
64+
65+
procedure TTestDUtils.TestSetParamsNilObject;
66+
begin
67+
try
68+
dSetParams(nil, nil);
69+
Fail('Expected exception');
70+
except
71+
on E: EdException do ;
72+
end;
73+
end;
74+
75+
initialization
76+
RegisterTest(TTestDUtils);
77+
end.

0 commit comments

Comments
 (0)