From 1fa629b516de68db2b385ea2c2a0ed928a72e248 Mon Sep 17 00:00:00 2001 From: troy Date: Wed, 20 May 1998 05:29:56 +0000 Subject: [PATCH] Added more self-test code --- layout/base/tests/TestSpaceManager.cpp | 98 ++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/layout/base/tests/TestSpaceManager.cpp b/layout/base/tests/TestSpaceManager.cpp index 0408c8716900..93b1ec69765b 100644 --- a/layout/base/tests/TestSpaceManager.cpp +++ b/layout/base/tests/TestSpaceManager.cpp @@ -29,6 +29,8 @@ public: PRBool TestAddBandOverlap(); PRBool TestAddRectToBand(); PRBool TestRemoveRegion(); + PRBool TestOffsetRegion(); + PRBool TestResizeRectRegion(); protected: struct BandInfo { @@ -621,6 +623,91 @@ PRBool MySpaceManager::TestRemoveRegion() return PR_TRUE; } +// Test of offseting regions +// +// This tests the following: +// 1. simple test of offseting the one and only band rect +PRBool MySpaceManager::TestOffsetRegion() +{ + PRBool status; + BandsInfo bandsInfo; + BandRect* bandRect; + + // Clear any existing regions + ClearRegions(); + NS_ASSERTION(mBandList.IsEmpty(), "clear regions failed"); + + ///////////////////////////////////////////////////////////////////////////// + // #1. A simple test of offseting the one and only band rect + status = AddRectRegion((nsIFrame*)0x01, nsRect(10, 100, 100, 100)); + NS_ASSERTION(PR_TRUE == status, "unexpected status"); + status = OffsetRegion((nsIFrame*)0x01, 50, 50); + NS_ASSERTION(PR_TRUE == status, "unexpected status"); + + // Verify there is one band with one rect + GetBandsInfo(bandsInfo); + if (bandsInfo.numBands != 1) { + printf("TestOffsetRegion: wrong number of bands (#1): %i\n", bandsInfo.numBands); + return PR_FALSE; + } + if (bandsInfo.bands[0].numRects != 1) { + printf("TestOffsetRegion: wrong number of rects (#1): %i\n", bandsInfo.bands[0].numRects); + return PR_FALSE; + } + + // Verify the position + bandRect = bandsInfo.bands[0].firstRect; + if ((bandRect->left != 60) || (bandRect->top != 150)) { + printf("TestOffsetRegion: wrong rect origin (#1)\n"); + return PR_FALSE; + } + + return PR_TRUE; +} + +// Test of resizing rect regions +// +// This tests the following: +// 1. simple test of resizing the one and only band rect +PRBool MySpaceManager::TestResizeRectRegion() +{ + PRBool status; + BandsInfo bandsInfo; + BandRect* bandRect; + + // Clear any existing regions + ClearRegions(); + NS_ASSERTION(mBandList.IsEmpty(), "clear regions failed"); + + ///////////////////////////////////////////////////////////////////////////// + // #1. A simple test of resizing the right edge of the one and only band rect + status = AddRectRegion((nsIFrame*)0x01, nsRect(10, 100, 100, 100)); + NS_ASSERTION(PR_TRUE == status, "unexpected status"); + status = ResizeRectRegion((nsIFrame*)0x01, 50, 50, nsISpaceManager::RightEdge); + NS_ASSERTION(PR_TRUE == status, "unexpected status"); + + // Verify there is one band with one rect + GetBandsInfo(bandsInfo); + if (bandsInfo.numBands != 1) { + printf("TestResizeRectRegion: wrong number of bands (#1): %i\n", bandsInfo.numBands); + return PR_FALSE; + } + if (bandsInfo.bands[0].numRects != 1) { + printf("TestResizeRectRegion: wrong number of rects (#1): %i\n", bandsInfo.bands[0].numRects); + return PR_FALSE; + } + + // Verify the position and size of the rect + bandRect = bandsInfo.bands[0].firstRect; + if ((bandRect->left != 10) || (bandRect->top != 100) || + (bandRect->right != 160) || (bandRect->bottom != 250)) { + printf("TestResizeRectRegion: wrong rect shape (#1)\n"); + return PR_FALSE; + } + + return PR_TRUE; +} + /////////////////////////////////////////////////////////////////////////////// // @@ -649,10 +736,21 @@ int main(int argc, char** argv) return -1; } + // Test removing regions if (!spaceMgr->TestRemoveRegion()) { return -1; } + // Test offseting regions + if (!spaceMgr->TestOffsetRegion()) { + return -1; + } + + // Test resizing rect regions + if (!spaceMgr->TestResizeRectRegion()) { + return -1; + } + #if 0 if (!spaceMgr->TestGetBandData()) { return -1;