-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathVirtualStringTreeTests.pas
93 lines (77 loc) · 2.8 KB
/
VirtualStringTreeTests.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
unit VirtualStringTreeTests;
interface
uses
DUnitX.TestFramework,
Vcl.Forms,
VirtualTrees;
type
[TestFixture]
TVirtualStringTreeTests = class(TObject)
strict private
fTree: TVirtualStringTree;
fForm: TForm;
procedure FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
/// Test for helper function VirtualTrees.Utils.OrderRect()
[Test]
procedure TestNodeData;
end;
implementation
uses
Vcl.Controls;
type
TMyObject = class
public
Value : String;
end;
{ TVirtualStringTreeTests }
procedure TVirtualStringTreeTests.FreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
Node.GetData<TMyObject>.Free();
end;
procedure TVirtualStringTreeTests.Setup;
begin
fForm := TForm.Create(nil);
fTree := TVirtualStringTree.Create(fForm);
fTree.OnFreeNode := FreeNode;
fTree.Parent := fForm;
fTree.Align := alClient;
end;
procedure TVirtualStringTreeTests.TearDown;
begin
fForm.Release();
fForm := nil;
Application.ProcessMessages;
end;
procedure TVirtualStringTreeTests.TestNodeData;
var
pL_Node : PVirtualNode;
lMyObj1,
lMyObj2 : TMyObject;
begin
Assert.IsNotNull(fTree, 'The Virtual TreeView controls was not created successfully');
fTree.BeginUpdate;
try
lMyObj1 := TMyObject.Create();
lMyObj1.Value := 'Hello World';
pL_Node := fTree.AddChild(nil, lMyObj1);
finally
fTree.EndUpdate;
end;
lMyObj2 := TMyObject(pL_Node.GetData()^);
Assert.AreEqual(lMyObj1, lMyObj2, 'The object that was set as node data should equal the object that was retrieved from the node using TVirtualNode.GetData()');
Assert.AreEqual(lMyObj1.Value, lMyObj2.Value, 'The object''s vlaue which was set as node data should equal the object that was retrieved from the node using TVirtualNode.GetData()');
lMyObj2 := TMyObject(fTree.GetNodeData(pL_Node)^);
Assert.AreEqual(lMyObj1, lMyObj2, 'The object that was set as node data should equal the object that was retrieved from the node using TBaseVirtualTree.GetNodeData()');
Assert.AreEqual(lMyObj1.Value, lMyObj2.Value, 'The object''s value which was set as node data should equal the object that was retrieved from the node using TBaseVirtualTree.GetNodeData()');
lMyObj2 := pL_Node.GetData<TMyObject>();
Assert.AreEqual(lMyObj1, lMyObj2, 'The object that was set as node data should equal the object that was retrieved from the node using TVirtualNode.GetData<T>()');
Assert.AreEqual(lMyObj1.Value, lMyObj2.Value, 'The object''s value which was set as node data should equal the object that was retrieved from the node using TVirtualNode.GetData<T>()');
end;
initialization
TDUnitX.RegisterTestFixture(TVirtualStringTreeTests);
end.