-
Notifications
You must be signed in to change notification settings - Fork 5
/
commoninterfacetests.lpr
105 lines (92 loc) · 4.33 KB
/
commoninterfacetests.lpr
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
program commoninterfacetests;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, commoninterface, commontestutils
{ you can add units after this };
var fi, fi2: TFormInput;
fp, fp2: TFormParams;
fs, fs2: TFormSelect;
nc: TNotificationConfig;
begin
writeln('Test auto generated JSON serialization');
writeln();
fi := TFormInput.Create;
fi.name := 'foo';
fi.caption := 'labeling';
writeln(fi.toJSON());
test(fi.toJSON(), '{"name": "foo", "caption": "labeling", "value": ""}');
fi2 := TFormInput.fromJSON(fi.toJSON());
writeln(fi2.name);
test(fi.name, fi2.name);
writeln(fi2.caption);
test(fi.caption, fi2.caption);
writeln(fi2.toJSON());
test(fi2.toJSON(), '{"name": "foo", "caption": "labeling", "value": ""}');
writeln;
fs := TFormSelect.Create;
fs.name := 'fs';
fs.caption := 'kirk';
writeln(fs.toJSON());
test(fs.toJSON(), '{"name": "fs", "caption": "kirk", "value": "", "optionCaptions": [], "optionValues": []}');
setlength(fs.optionCaptions, 3);
setlength(fs.optionValues, 3);
fs.optionCaptions[0] := 'N1';
fs.optionValues[0] := 'V1';
fs.optionCaptions[1] := 'Na2';
fs.optionValues[1] := 'Va2';
fs.optionCaptions[2] := 'Na3';
fs.optionValues[2] := 'Va3';
writeln(fs.toJSON());
test(fs.toJSON(), '{"name": "fs", "caption": "kirk", "value": "", "optionCaptions": ["N1", "Na2", "Na3"], "optionValues": ["V1", "Va2", "Va3"]}');
fs2 := TFormSelect.fromJSON(fs.toJSON());
writeln(fs2.toJSON());
test(fs2.toJSON(), '{"name": "fs", "caption": "kirk", "value": "", "optionCaptions": ["N1", "Na2", "Na3"], "optionValues": ["V1", "Va2", "Va3"]}');
fs2.free;
writeln;
fp := TFormParams.Create;
SetLength(fp.inputs, 1);
fp.inputs[0] := fi;
writeln(fp.toJSON());
test(fp.toJSON(), '{"inputs": ["FormInput", {"name": "foo", "caption": "labeling", "value": ""}]}');
SetLength(fp.inputs, 2);
fp.inputs[1] := fi2;
writeln(fp.toJSON());
test(fp.toJSON(), '{"inputs": ["FormInput", {"name": "foo", "caption": "labeling", "value": ""}, "FormInput", {"name": "foo", "caption": "labeling", "value": ""}]}');
SetLength(fp.inputs, 3);
fp.inputs[2] := fs;
writeln(fp.toJSON());
test(fp.toJSON(), '{"inputs": ["FormInput", {"name": "foo", "caption": "labeling", "value": ""}, "FormInput", {"name": "foo", "caption": "labeling", "value": ""}, "FormSelect", {"name": "fs", "caption": "kirk", "value": "", "optionCaptions": ["N1", "Na2", "Na3"], "optionValues": ["V1", "Va2", "Va3"]}]}');
fp2 := TFormParams.fromJSON(fp.toJSON());
writeln(fp2.toJSON());
test(fp2.toJSON(), '{"inputs": ["FormInput", {"name": "foo", "caption": "labeling", "value": ""}, "FormInput", {"name": "foo", "caption": "labeling", "value": ""}, "FormSelect", {"name": "fs", "caption": "kirk", "value": "", "optionCaptions": ["N1", "Na2", "Na3"], "optionValues": ["V1", "Va2", "Va3"]}]}');
writeln;
fp2.free;
fp.free;
nc := TNotificationConfig.fromJSON('{"lastTime": 123}');
test(nc.lastTime, 123);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": 123, "lastTitle": "", "lastText": ""}');
nc.free;
nc := TNotificationConfig.fromJSON('{"lastTime": 1599549012000}');
test(nc.lastTime, 1599549012000);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": 1599549012000, "lastTitle": "", "lastText": ""}');
nc.free;
nc := TNotificationConfig.fromJSON('{"lastTime": 9223372036854775807}');
test(nc.lastTime, 9223372036854775807);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": 9223372036854775807, "lastTitle": "", "lastText": ""}');
nc.free;
nc := TNotificationConfig.fromJSON('{"lastTime": -9223372036854775808}');
test(nc.lastTime, -9223372036854775808);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": -9223372036854775808, "lastTitle": "", "lastText": ""}');
nc.free;
nc := TNotificationConfig.fromJSON('{"lastTime": "9223372036854775807"}');
test(nc.lastTime, 9223372036854775807);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": 9223372036854775807, "lastTitle": "", "lastText": ""}');
nc.free;
nc := TNotificationConfig.fromJSON('{"lastTime": "-9223372036854775808"}');
test(nc.lastTime, -9223372036854775808);
test(nc.toJSON(), '{"enabled": false, "serviceDelay": 0, "lastTime": -9223372036854775808, "lastTitle": "", "lastText": ""}');
nc.free;
end.