X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e8f9a4980bb865cfc14e9e1d423181ee2efd17e..eb6b14dc71402c42e0474779bfcd6e878383071e:/tests/geometry/rect.cpp diff --git a/tests/geometry/rect.cpp b/tests/geometry/rect.cpp index 21568366f4..55420342f4 100644 --- a/tests/geometry/rect.cpp +++ b/tests/geometry/rect.cpp @@ -3,7 +3,6 @@ // Purpose: wxRect unit test // Author: Vadim Zeitlin // Created: 2004-12-11 -// RCS-ID: $Id$ // Copyright: (c) 2004 wxWindows /////////////////////////////////////////////////////////////////////////////// @@ -21,6 +20,21 @@ #include "wx/gdicmn.h" #endif // WX_PRECOMP +#include "wx/iosfwrap.h" + +// ---------------------------------------------------------------------------- +// helper functions +// ---------------------------------------------------------------------------- + +// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxRects +std::ostream& operator<<(std::ostream& os, const wxRect& r) +{ + os << "{" + << r.x << ", " << r.y << ", " << r.width << ", " << r.height + << "}"; + return os; +} + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -32,10 +46,14 @@ public: private: CPPUNIT_TEST_SUITE( RectTestCase ); + CPPUNIT_TEST( CentreIn ); + CPPUNIT_TEST( InflateDeflate ); CPPUNIT_TEST( Operators ); CPPUNIT_TEST( Union ); CPPUNIT_TEST_SUITE_END(); + void CentreIn(); + void InflateDeflate(); void Operators(); void Union(); @@ -45,9 +63,36 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase ); -// also include in it's own registry so that these tests can be run alone +// also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" ); +void RectTestCase::CentreIn() +{ + typedef wxRect R; + + CPPUNIT_ASSERT_EQUAL( R(45, 45, 10, 10), + R(0, 0, 10, 10).CentreIn(R(0, 0, 100, 100))); + + CPPUNIT_ASSERT_EQUAL( R(-5, -5, 20, 20), + R(0, 0, 20, 20).CentreIn(R(0, 0, 10, 10))); +} + +void RectTestCase::InflateDeflate() +{ + // This is the rectangle from the example in the documentation of wxRect::Inflate(). + const wxRect r1(10, 10, 20, 40); + + CPPUNIT_ASSERT(r1.Inflate( 10, 10)==wxRect( 0, 0, 40, 60)); + CPPUNIT_ASSERT(r1.Inflate( 20, 30)==wxRect(-10, -20, 60, 100)); + CPPUNIT_ASSERT(r1.Inflate(-10, -10)==wxRect( 20, 20, 0, 20)); + CPPUNIT_ASSERT(r1.Inflate(-15, -15)==wxRect( 20, 25, 0, 10)); + + CPPUNIT_ASSERT(r1.Inflate( 10, 10)==r1.Deflate(-10, -10)); + CPPUNIT_ASSERT(r1.Inflate( 20, 30)==r1.Deflate(-20, -30)); + CPPUNIT_ASSERT(r1.Inflate(-10, -10)==r1.Deflate( 10, 10)); + CPPUNIT_ASSERT(r1.Inflate(-15, -15)==r1.Deflate( 15, 15)); +} + void RectTestCase::Operators() { // test + operator which works like Union but does not ignore empty rectangles @@ -83,6 +128,14 @@ void RectTestCase::Operators() ( data.GetSecond() + data.GetFirst() ) == data.GetResult() ); } + + // test operator*() which returns the intersection of two rectangles + wxRect r1 = wxRect(0, 2, 3, 4); + wxRect r2 = wxRect(1, 2, 7, 8); + r1 *= r2; + CPPUNIT_ASSERT(wxRect(1, 2, 2, 4) == r1); + + CPPUNIT_ASSERT( (r1 * wxRect()).IsEmpty() ); } void RectTestCase::Union()