-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.Profiler.ProfileReport.pas
96 lines (78 loc) · 2.25 KB
/
Test.Profiler.ProfileReport.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
unit Test.Profiler.ProfileReport;
interface
uses
DUnitX.TestFramework,
System.Classes,
Profiler.ProfileReport;
type
[TestFixture]
TProfileReportTest = class
private
FProfileReport: TProfileReport;
FStream: TStringStream;
FStrings: TStrings;
procedure FillReport(const DelimitedInput: string);
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
[Test]
[TestCase('Two inputs', 'abc,2|def,4;' +
'"Scope Name","Total Calls","Total Time (us)","Avg. Time (us)"', ';')]
procedure TestClear(const DelimitedInput, DelimitedExpected: string);
[Test]
[TestCase('Two inputs', 'abc,2|def,4;' +
'"Scope Name","Total Calls","Total Time (us)","Avg. Time (us)"|' +
'"def","1","0.40","0.40"|' +
'"abc","1","0.20","0.20"', ';')]
procedure TestSaveToStream(const DelimitedInput, DelimitedExpected: string);
end;
implementation
uses
System.SysUtils;
{ TProfileReportTest }
procedure TProfileReportTest.FillReport(const DelimitedInput: string);
var
Strings: TArray<string>;
S: string;
begin
for S in DelimitedInput.Split(['|']) do
begin
Strings := S.Split([',']);
FProfileReport.Add(Strings[0], Strings[1].ToInt64, True);
end;
end;
procedure TProfileReportTest.Setup;
begin
FProfileReport := TProfileReport.Create;
FStream := TStringStream.Create;
FStrings := TStringList.Create;
FStrings.Delimiter := '|';
FStrings.QuoteChar := #0;
FStrings.StrictDelimiter := True;
end;
procedure TProfileReportTest.TearDown;
begin
FProfileReport.Free;
FStream.Free;
FStrings.Free;
end;
procedure TProfileReportTest.TestClear(const DelimitedInput, DelimitedExpected: string);
begin
FillReport(DelimitedInput);
FProfileReport.Clear;
FStream.Clear;
FProfileReport.SaveProfileToStream(FStream);
FStrings.DelimitedText := DelimitedExpected;
Assert.AreEqual(FStrings.Text, FStream.DataString);
end;
procedure TProfileReportTest.TestSaveToStream(const DelimitedInput, DelimitedExpected: string);
begin
FillReport(DelimitedInput);
FStream.Clear;
FProfileReport.SaveProfileToStream(FStream);
FStrings.DelimitedText := DelimitedExpected;
Assert.AreEqual(FStrings.Text, FStream.DataString);
end;
end.