summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-11 21:51:53 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-11 21:51:53 +0000
commit3a10ff2a85448881863e8d6f729c1abebdc8297a (patch)
treef64baf95757722d14ea0092c8ab9b5becfe4be4d /unittests
parent3309f5b6227559456b25bb9e5c4051ccb72b6a13 (diff)
downloadfpGUI-3a10ff2a85448881863e8d6f729c1abebdc8297a.tar.xz
* Fixed the recusion bug in Treeview when searching for a node.
* Minor improvements to the GUI Test Runner. * Extended the treeview unit tests.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/fpcunitproject.lpi3
-rw-r--r--unittests/treeview_test.pas77
2 files changed, 70 insertions, 10 deletions
diff --git a/unittests/fpcunitproject.lpi b/unittests/fpcunitproject.lpi
index cbfeec27..d3b90945 100644
--- a/unittests/fpcunitproject.lpi
+++ b/unittests/fpcunitproject.lpi
@@ -54,7 +54,8 @@
<Generate Value="Faster"/>
</CodeGeneration>
<Other>
- <CustomOptions Value="-FUunits"/>
+ <CustomOptions Value="-FUunits
+"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
diff --git a/unittests/treeview_test.pas b/unittests/treeview_test.pas
index 9abf5102..8a8257aa 100644
--- a/unittests/treeview_test.pas
+++ b/unittests/treeview_test.pas
@@ -21,6 +21,7 @@ type
procedure TestNext;
procedure TestPrev;
procedure TestAppendText;
+ procedure TestFindSubNode_Text;
end;
implementation
@@ -50,19 +51,28 @@ end;
procedure TTestTreeview.TestCountRecursive;
var
- n: TfpgTreeNode;
+ n1, n2: TfpgTreeNode;
begin
+ { root
+ |--n1
+ | |--n1.1
+ |--n2
+ |--n2.1
+ |--n2.2
+ }
AssertEquals('Failed on 1', 0, FTree.RootNode.CountRecursive);
- FTree.RootNode.AppendText('n1');
+ n1 := FTree.RootNode.AppendText('n1');
AssertEquals('Failed on 2', 1, FTree.RootNode.CountRecursive);
- n := FTree.RootNode.AppendText('n2');
+ n2 := FTree.RootNode.AppendText('n2');
AssertEquals('Failed on 3', 2, FTree.RootNode.CountRecursive);
- n.AppendText('n2.1');
+ n2.AppendText('n2.1');
AssertEquals('Failed on 4', 3, FTree.RootNode.CountRecursive);
- n.AppendText('n2.2');
+ n2.AppendText('n2.2');
AssertEquals('Failed on 5', 4, FTree.RootNode.CountRecursive);
-// FTree.RootNode.Remove(n);
-// AssertEquals('Failed on 6', 1, FTree.RootNode.Count);
+ n1.AppendText('n1.1');
+ AssertEquals('Failed on 6', 5, FTree.RootNode.CountRecursive);
+ FTree.RootNode.Remove(n2); // removing 3 nodes
+ AssertEquals('Failed on 6', 2, FTree.RootNode.CountRecursive);
end;
procedure TTestTreeview.TestNext;
@@ -102,8 +112,57 @@ begin
AssertEquals('Failed on 3', 2, FTree.RootNode.Count);
end;
-initialization
+procedure TTestTreeview.TestFindSubNode_Text;
+var
+ n1, n2, n3: TfpgTreeNode;
+ r: TfpgTreeNode;
+begin
+ { root
+ |--n1
+ | |--n1.1
+ |
+ |--n2
+ | |--n2.1
+ | | |--n2.1.1
+ | |
+ | |--n2.2
+ |
+ |--n3
+ }
+ AssertTrue('Failed on 1', FTree.RootNode.FindSubNode('n1', False) = nil);
+
+ n1 := FTree.RootNode.AppendText('n1');
+ AssertTrue('Failed on 2', FTree.RootNode.FindSubNode('n1', False) = n1);
+ AssertTrue('Failed on 3', FTree.RootNode.FindSubNode('n1', True) = n1);
+
+ n2 := FTree.RootNode.AppendText('n2');
+ AssertTrue('Failed on 4', FTree.RootNode.FindSubNode('n2', False) = n2);
+ AssertTrue('Failed on 5', FTree.RootNode.FindSubNode('n2', True) = n2);
+
+ r := n2.AppendText('n2.1');
+ AssertTrue('Failed on 6', FTree.RootNode.FindSubNode('n2.1', False) = nil);
+ AssertTrue('Failed on 7', FTree.RootNode.FindSubNode('n2.1', True) = r);
+
+ r := n2.AppendText('n2.2');
+ AssertTrue('Failed on 8', FTree.RootNode.FindSubNode('n2.2', False) = nil);
+ AssertTrue('Failed on 9', FTree.RootNode.FindSubNode('n2.2', True) = r);
+
+ n3 := FTree.RootNode.AppendText('n3');
+ AssertTrue('Failed on 10', FTree.RootNode.FindSubNode('n3', False) = n3);
+ AssertTrue('Failed on 11', FTree.RootNode.FindSubNode('n3', True) = n3);
+
+ r := n1.AppendText('n1.1');
+ AssertTrue('Failed on 12', FTree.RootNode.FindSubNode('n1.1', False) = nil);
+ AssertTrue('Failed on 13', FTree.RootNode.FindSubNode('n1.1', True) = r);
+
+ r := n2.FindSubNode('n2.1', True).AppendText('n2.1.1');
+ AssertTrue('Failed on 14', FTree.RootNode.FindSubNode('n2.1.1', False) = nil);
+ AssertTrue('Failed on 15', FTree.RootNode.FindSubNode('n2.1.1', True) = r);
+end;
- RegisterTest(TTestTreeview);
+
+initialization
+ RegisterTest(TTestTreeview);
+
end.