-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest.Profiler.ScopedTrace.pas
82 lines (63 loc) · 1.75 KB
/
Test.Profiler.ScopedTrace.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
unit Test.Profiler.ScopedTrace;
interface
uses
DUnitX.TestFramework,
Delphi.Mocks,
Profiler.Types;
type
[TestFixture]
TScopedTraceTest = class(TObject)
private
FTracer: TMock<ITracer>;
function Trace(const ScopeName: string; IsLongLived: Boolean): IInterface;
class function CheckTrace(Info: TTraceInfo): Boolean;
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
[Test]
[TestCase('Once', '1,False')]
[TestCase('Twice', '2,False')]
[TestCase('Hundred times', '100,False')]
[TestCase('Once (long-lived)', '1,True')]
[TestCase('Twice (long-lived', '2,True')]
[TestCase('Hundred times (long-lived', '100,True')]
procedure TestTrace(Times: Integer; IsLongLived: Boolean);
end;
implementation
uses
Profiler.ScopedTrace;
procedure TScopedTraceTest.Setup;
begin
FTracer := TMock<ITracer>.Create;
end;
procedure TScopedTraceTest.TearDown;
begin
FTracer.Free;
end;
function TScopedTraceTest.Trace(const ScopeName: string; IsLongLived: Boolean): IInterface;
begin
Result := TScopedTrace.Create(FTracer, ScopeName, IsLongLived);
end;
class function TScopedTraceTest.CheckTrace(Info: TTraceInfo): Boolean;
begin
Result := (Info.FTraceID > 0) and (Info.FScopeName = 'Test') and
((Info.FEventType = TTraceType.Enter) or (Info.FElapsedTicks < 10));
end;
procedure TScopedTraceTest.TestTrace(Times: Integer; IsLongLived: Boolean);
var
I: Integer;
begin
FTracer.Setup.Expect.Exactly(2 * Times).When.Log(It0.Matches<TTraceInfo>(CheckTrace));
for I := 1 to Times do
Trace('Test', IsLongLived);
Assert.WillNotRaise(
procedure
begin
FTracer.VerifyAll;
end);
end;
initialization
TDUnitX.RegisterTestFixture(TScopedTraceTest);
end.