X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e07e8195ae9ab8f12ce91aed5e724ac80a8d09d3..c0bb586f5074be1fe579720f3c08ac76df44d90c:/tests/geometry/rect.cpp diff --git a/tests/geometry/rect.cpp b/tests/geometry/rect.cpp index 85954dd277..c7d73971f6 100644 --- a/tests/geometry/rect.cpp +++ b/tests/geometry/rect.cpp @@ -4,7 +4,7 @@ // Author: Vadim Zeitlin // Created: 2004-12-11 // RCS-ID: $Id$ -// Copyright: (c) 2004 wxWindows +// Copyright: (c) 2004 wxWindows /////////////////////////////////////////////////////////////////////////////// // ---------------------------------------------------------------------------- @@ -18,10 +18,9 @@ #endif #ifndef WX_PRECOMP + #include "wx/gdicmn.h" #endif // WX_PRECOMP -#include "wx/gdicmn.h" - // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -33,9 +32,13 @@ public: private: CPPUNIT_TEST_SUITE( RectTestCase ); + CPPUNIT_TEST( InflateDeflate ); + CPPUNIT_TEST( Operators ); CPPUNIT_TEST( Union ); CPPUNIT_TEST_SUITE_END(); + void InflateDeflate(); + void Operators(); void Union(); DECLARE_NO_COPY_CLASS(RectTestCase) @@ -47,6 +50,59 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase ); // also include in it's own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" ); +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 + static const struct RectData + { + int x1, y1, w1, h1; + int x2, y2, w2, h2; + int x, y, w, h; + + wxRect GetFirst() const { return wxRect(x1, y1, w1, h1); } + wxRect GetSecond() const { return wxRect(x2, y2, w2, h2); } + wxRect GetResult() const { return wxRect(x, y, w, h); } + } s_rects[] = + { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 2, 2 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 }, + { 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 }, + { 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 }, + { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 } + }; + + for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ ) + { + const RectData& data = s_rects[n]; + + CPPUNIT_ASSERT( + ( data.GetFirst() + data.GetSecond() ) == data.GetResult() + ); + + CPPUNIT_ASSERT( + ( data.GetSecond() + data.GetFirst() ) == data.GetResult() + ); + } +} + void RectTestCase::Union() { static const struct RectData @@ -66,7 +122,7 @@ void RectTestCase::Union() { 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 }, { 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 }, { 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 }, - { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 }, + { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 } }; for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ ) @@ -82,4 +138,3 @@ void RectTestCase::Union() ); } } -