From bdde60c6de624dcb795203f9ac1614fc6334a6cd Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 15 Jan 2011 12:44:44 +0000 Subject: [PATCH] tests: added tests for TScrollBox git-svn-id: trunk@29030 - --- test/lcltests/testpreferredsize.pas | 83 ++++++++++++++++++++++++++++- test/runtests.lpi | 16 +++--- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/test/lcltests/testpreferredsize.pas b/test/lcltests/testpreferredsize.pas index b00df64990..3e84cf520a 100644 --- a/test/lcltests/testpreferredsize.pas +++ b/test/lcltests/testpreferredsize.pas @@ -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); diff --git a/test/runtests.lpi b/test/runtests.lpi index be53ca153d..2c3c07bc09 100644 --- a/test/runtests.lpi +++ b/test/runtests.lpi @@ -93,13 +93,15 @@ - - - - - - - + + + + + + + + +