]>
git.saurik.com Git - wxWidgets.git/blob - tests/geometry/rect.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/geometry/rect.cpp
3 // Purpose: wxRect unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 wxWindows
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
21 #include "wx/gdicmn.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class RectTestCase
: public CppUnit::TestCase
34 CPPUNIT_TEST_SUITE( RectTestCase
);
35 CPPUNIT_TEST( Operators
);
36 CPPUNIT_TEST( Union
);
37 CPPUNIT_TEST_SUITE_END();
42 DECLARE_NO_COPY_CLASS(RectTestCase
)
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase
);
48 // also include in it's own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase
, "RectTestCase" );
51 void RectTestCase::Operators()
53 // test + operator which works like Union but does not ignore empty rectangles
54 static const struct RectData
60 wxRect
GetFirst() const { return wxRect(x1
, y1
, w1
, h1
); }
61 wxRect
GetSecond() const { return wxRect(x2
, y2
, w2
, h2
); }
62 wxRect
GetResult() const { return wxRect(x
, y
, w
, h
); }
65 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
66 { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 2, 2 },
67 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
68 { 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 },
69 { 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 },
70 { 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 },
71 { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 }
74 for ( size_t n
= 0; n
< WXSIZEOF(s_rects
); n
++ )
76 const RectData
& data
= s_rects
[n
];
79 ( data
.GetFirst() + data
.GetSecond() ) == data
.GetResult()
83 ( data
.GetSecond() + data
.GetFirst() ) == data
.GetResult()
88 void RectTestCase::Union()
90 static const struct RectData
96 wxRect
GetFirst() const { return wxRect(x1
, y1
, w1
, h1
); }
97 wxRect
GetSecond() const { return wxRect(x2
, y2
, w2
, h2
); }
98 wxRect
GetResult() const { return wxRect(x
, y
, w
, h
); }
101 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
102 { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
103 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
104 { 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 },
105 { 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 },
106 { 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 },
107 { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 }
110 for ( size_t n
= 0; n
< WXSIZEOF(s_rects
); n
++ )
112 const RectData
& data
= s_rects
[n
];
115 data
.GetFirst().Union(data
.GetSecond()) == data
.GetResult()
119 data
.GetSecond().Union(data
.GetFirst()) == data
.GetResult()