From: Włodzimierz Skiba Date: Tue, 14 Dec 2004 20:29:20 +0000 (+0000) Subject: Geometry operators tests. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3e8f9a4980bb865cfc14e9e1d423181ee2efd17e?ds=inline Geometry operators tests. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31007 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/tests/geometry/point.cpp b/tests/geometry/point.cpp new file mode 100644 index 0000000000..b81e836efe --- /dev/null +++ b/tests/geometry/point.cpp @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/geometry/point.cpp +// Purpose: wxPoint unit test +// Author: Wlodzimierz ABX Skiba +// Created: 2004-12-14 +// RCS-ID: $Id$ +// Copyright: (c) 2004 wxWindows +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/gdicmn.h" +#endif // WX_PRECOMP + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class PointTestCase : public CppUnit::TestCase +{ +public: + PointTestCase() { } + +private: + CPPUNIT_TEST_SUITE( PointTestCase ); + CPPUNIT_TEST( Operators ); + CPPUNIT_TEST_SUITE_END(); + + void Operators(); + + DECLARE_NO_COPY_CLASS(PointTestCase) +}; + +class RealPointTestCase : public CppUnit::TestCase +{ +public: + RealPointTestCase() { } + +private: + CPPUNIT_TEST_SUITE( RealPointTestCase ); + CPPUNIT_TEST( Operators ); + CPPUNIT_TEST_SUITE_END(); + + void Operators(); + + DECLARE_NO_COPY_CLASS(RealPointTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase ); +CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" ); + +void PointTestCase::Operators() +{ + wxPoint p1(1,2); + wxPoint p2(6,3); + wxPoint p3(7,5); + wxPoint p4(5,1); + wxPoint p5 = p2 + p1; + wxPoint p6 = p2 - p1; + CPPUNIT_ASSERT( p3.x == p5.x && p3.y == p5.y ); + CPPUNIT_ASSERT( p4.x == p6.x && p4.y == p6.y ); + CPPUNIT_ASSERT( p3 == p5 ); + CPPUNIT_ASSERT( p4 == p6 ); + CPPUNIT_ASSERT( p3 != p4 ); + p5 = p2; p5 += p1; + p6 = p2; p6 -= p1; + CPPUNIT_ASSERT( p3 == p5 ); + CPPUNIT_ASSERT( p4 == p6 ); + wxSize s(p1.x,p1.y); + p5 = p2; p5 = p2 + s; + p6 = p2; p6 = p2 - s; + CPPUNIT_ASSERT( p3 == p5 ); + CPPUNIT_ASSERT( p4 == p6 ); + p5 = p2; p5 += s; + p6 = p2; p6 -= s; + CPPUNIT_ASSERT( p3 == p5 ); + CPPUNIT_ASSERT( p4 == p6 ); +} + +void RealPointTestCase::Operators() +{ + const double EPSILON = 0.00001; + wxRealPoint p1(1.2,3.4); + wxRealPoint p2(8.7,5.4); + wxRealPoint p3(9.9,8.8); + wxRealPoint p4(7.5,2.0); + wxRealPoint p5 = p2 + p1; + wxRealPoint p6 = p2 - p1; + /* + CPPUNIT_ASSERT( p3 == p5 ); + CPPUNIT_ASSERT( p4 == p6 ); + CPPUNIT_ASSERT( p3 != p4 ); + */ + CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON && fabs( p3.y - p5.y ) < EPSILON ); + CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON && fabs( p4.y - p6.y ) < EPSILON ); +} diff --git a/tests/geometry/rect.cpp b/tests/geometry/rect.cpp index 85954dd277..21568366f4 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,11 @@ public: private: CPPUNIT_TEST_SUITE( RectTestCase ); + CPPUNIT_TEST( Operators ); CPPUNIT_TEST( Union ); CPPUNIT_TEST_SUITE_END(); + void Operators(); void Union(); DECLARE_NO_COPY_CLASS(RectTestCase) @@ -47,6 +48,43 @@ 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::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 +104,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 +120,3 @@ void RectTestCase::Union() ); } } - diff --git a/tests/geometry/size.cpp b/tests/geometry/size.cpp new file mode 100644 index 0000000000..160f6241b1 --- /dev/null +++ b/tests/geometry/size.cpp @@ -0,0 +1,76 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/geometry/size.cpp +// Purpose: wxSize unit test +// Author: Vadim Zeitlin +// Created: 2004-12-14 +// RCS-ID: $Id$ +// Copyright: (c) 2004 wxWindows +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/gdicmn.h" +#endif // WX_PRECOMP + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class SizeTestCase : public CppUnit::TestCase +{ +public: + SizeTestCase() { } + +private: + CPPUNIT_TEST_SUITE( SizeTestCase ); + CPPUNIT_TEST( Operators ); + CPPUNIT_TEST_SUITE_END(); + + void Operators(); + + DECLARE_NO_COPY_CLASS(SizeTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( SizeTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SizeTestCase, "SizeTestCase" ); + +void SizeTestCase::Operators() +{ + wxSize s1(1,2); + wxSize s2(3,4); + wxSize s3; + + s3 = s1 + s2; + CPPUNIT_ASSERT( s3.GetWidth()==4 && s3.GetHeight()==6 ); + s3 = s2 - s1; + CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==2 ); + s3 = s1 * 2; + CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==4 ); + s3 = s3 / 2; + CPPUNIT_ASSERT( s3.GetWidth()==1 && s3.GetHeight()==2 ); + + s3 = s2; + CPPUNIT_ASSERT( s3 != s1 ); + s3 = s1; + CPPUNIT_ASSERT( s3 == s1 ); + s3 += s2; + CPPUNIT_ASSERT( s3.GetWidth()==4 && s3.GetHeight()==6 ); + s3 -= s2; + CPPUNIT_ASSERT( s3 == s1 ); + s3 *= 2; + CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==4 ); + s3 /= 2; + CPPUNIT_ASSERT( s3 == s1 ); +} diff --git a/tests/test.bkl b/tests/test.bkl index b18f3fb741..d11f4194eb 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -8,7 +8,7 @@