tests: added tests for TScrollBox

git-svn-id: trunk@29030 -
This commit is contained in:
mattias 2011-01-15 12:44:44 +00:00
parent 98571c5b6e
commit bdde60c6de
2 changed files with 91 additions and 8 deletions

View File

@ -5,7 +5,7 @@ unit testpreferredsize;
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, fpcunit,
Classes, SysUtils, LCLProc, Forms, Controls, StdCtrls, ExtCtrls, fpcunit,
testglobals;
type
@ -15,6 +15,8 @@ type
TTestPreferredSize = class(TTestCase)
published
procedure TestGroupBoxPreferredSize1;
procedure TestScrollBoxEmpty;
procedure TestScrollBoxOneChildPanel;
end;
implementation
@ -60,6 +62,85 @@ begin
Application.ProcessMessages;
end;
procedure TTestPreferredSize.TestScrollBoxEmpty;
var
Form1: TForm;
ScrollBox1: TScrollBox;
begin
// create an empty scrollbox on a form
Form1:=TForm.Create(nil);
Form1.SetBounds(100,100,300,300);
ScrollBox1:=TScrollBox.Create(Form1);
ScrollBox1.SetBounds(10,10,100,100);
ScrollBox1.AutoScroll:=true;
ScrollBox1.Parent:=Form1;
Form1.Show;
Application.ProcessMessages;
AssertEquals('TScrollBox: Empty, AutoScroll=true, but HorzScrollBar.IsScrollBarVisible is true',false,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
AssertEquals('TScrollBox: Empty, AutoScroll=true, but VertScrollBar.IsScrollBarVisible is true',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
Form1.Free;
Application.ProcessMessages;
end;
procedure TTestPreferredSize.TestScrollBoxOneChildPanel;
var
Form1: TForm;
ScrollBox1: TScrollBox;
Panel1: TPanel;
begin
// create a scrollbox on a form and put a small panel into the box
Form1:=TForm.Create(nil);
Form1.SetBounds(100,100,300,300);
ScrollBox1:=TScrollBox.Create(Form1);
ScrollBox1.SetBounds(10,10,100,100);
ScrollBox1.AutoScroll:=true;
ScrollBox1.Parent:=Form1;
Panel1:=TPanel.Create(Form1);
Panel1.Caption:='Panel1';
Panel1.SetBounds(0,0,60,50);
Panel1.Constraints.MinWidth:=10;
Panel1.Constraints.MinHeight:=10;
Panel1.Parent:=ScrollBox1;
Form1.Show;
Application.ProcessMessages;
//writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Range=',ScrollBox1.HorzScrollBar.Range,' ',ScrollBox1.HorzScrollBar.Page,' ',ScrollBox1.HorzScrollBar.Visible);
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 60',60,ScrollBox1.HorzScrollBar.Range);
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',50,ScrollBox1.VertScrollBar.Range);
AssertEquals('ScrollBox shows HorzScrollBar without need',false,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
AssertEquals('ScrollBox shows VertScrollBar without need',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
// now enlarge the panel, so that a HorzScrollBar is needed
Panel1.Width:=150;
Application.ProcessMessages;
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs 150',150,ScrollBox1.HorzScrollBar.Range);
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs 50',50,ScrollBox1.VertScrollBar.Range);
AssertEquals('ScrollBox should show HorzScrollBar',true,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
AssertEquals('ScrollBox shows VertScrollBar without need',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
// now Align the panel, so that the panel fills the whole client area
// no scrollbars should be visible
Panel1.Align:=alClient;
Application.ProcessMessages;
writeln('TTestPreferredSize.TestScrollBoxOneChildPanel Panel1.BoundsRect=',dbgs(Panel1.BoundsRect),' ScrollBox1.ClientRect=',dbgs(ScrollBox1.ClientRect));
AssertEquals('Panel1.Align=alClient, Panel1.Left should be 0',0,Panel1.Left);
AssertEquals('Panel1.Align=alClient, Panel1.Top should be 0',0,Panel1.Top);
AssertEquals('Panel1.Align=alClient, Panel1.Right should be ScrollBox1.ClientWidth',ScrollBox1.ClientWidth,Panel1.Left+Panel1.Width);
AssertEquals('Panel1.Align=alClient, Panel1.Bottom should be ScrollBox1.ClientHeight',ScrollBox1.ClientHeight,Panel1.Top+Panel1.Height);
AssertEquals('ScrollBox shows HorzScrollBar without need',false,ScrollBox1.HorzScrollBar.IsScrollBarVisible);
AssertEquals('ScrollBox shows VertScrollBar without need',false,ScrollBox1.VertScrollBar.IsScrollBarVisible);
AssertEquals('ScrollBox1.HorzScrollBar.Range should be the needed Right of all childs',Panel1.Constraints.MinWidth,ScrollBox1.HorzScrollBar.Range);
AssertEquals('ScrollBox1.VertScrollBar.Range should be the needed Bottom of all childs',Panel1.Constraints.MinHeight,ScrollBox1.VertScrollBar.Range);
Form1.Free;
Application.ProcessMessages;
end;
initialization
AddToLCLTestSuite(TTestPreferredSize);

View File

@ -93,13 +93,15 @@
<CStyleOperator Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Debugging>
<UseLineInfoUnit Value="False"/>
<StripSymbols Value="True"/>
</Debugging>
<LinkSmart Value="True"/>
</Linking>
<CodeGeneration>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<VerifyObjMethodCallValidity Value="True"/>
</CodeGeneration>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>