forked from JAM-Software/Virtual-TreeView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVTWorkerThreadIssue1001Tests.pas
More file actions
91 lines (78 loc) · 2.08 KB
/
VTWorkerThreadIssue1001Tests.pas
File metadata and controls
91 lines (78 loc) · 2.08 KB
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
unit VTWorkerThreadIssue1001Tests;
interface
uses
DUnitX.TestFramework,
Classes,
Vcl.Forms,
VirtualTrees;
type
TTestBaseVirtualTree = class(TBaseVirtualTree)
public
property OnCompareNodes;
end;
[TestFixture]
TVTWorkerThreadIssue1001Tests = class
strict private
fTree: TTestBaseVirtualTree;
fForm: TForm;
procedure TreeCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode;
Column: TColumnIndex; var Result: Integer);
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
/// Test for CheckSynchronize when tree is destroyed
/// repeated 50 times because AVs are not realiable
[Test, RepeatTestAttribute(100)]
procedure TestDestroyWhileWorkerThreadBusy;
end;
implementation
uses
VirtualTrees.WorkerThread,
SysUtils;
procedure TVTWorkerThreadIssue1001Tests.Setup;
begin
TThread.Synchronize(nil, procedure
begin
fForm := TForm.Create(nil);
fTree := TTestBaseVirtualTree.Create(fForm);
fTree.TreeOptions.AutoOptions:= fTree.TreeOptions.AutoOptions - [toAutoSort];
fTree.OnCompareNodes:= TreeCompareNodes;
end);
end;
procedure TVTWorkerThreadIssue1001Tests.TearDown;
begin
TThread.Synchronize(nil, procedure
begin
FreeAndNil(fForm);
end);
end;
procedure TVTWorkerThreadIssue1001Tests.TestDestroyWhileWorkerThreadBusy;
begin
TThread.Synchronize(nil, procedure
begin
fTree.BeginUpdate;
try
fTree.SetChildCount(fTree.RootNode, 10000);
Assert.AreEqual(fTree.RootNode.ChildCount + 1, fTree.RootNode.TotalCount, 'TotalCount <> ChildCount + 1');
//fTree.SortTree(-1, sdAscending, false);
finally
fTree.EndUpdate;
end;
FreeAndNil(fTree);
FreeAndNil(fForm);
end);
end;
procedure TVTWorkerThreadIssue1001Tests.TreeCompareNodes(
Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex;
var Result: Integer);
begin
if Random(10) > 5 then
Result:= 1 else
Result:= -1;
end;
initialization
Randomize;
TDUnitX.RegisterTestFixture(TVTWorkerThreadIssue1001Tests);
end.