]> git.saurik.com Git - wxWidgets.git/blob - tests/geometry/rect.cpp
85954dd277a95948cb2048123efa2235897ea53b
[wxWidgets.git] / tests / geometry / rect.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/geometry/rect.cpp
3 // Purpose: wxRect unit test
4 // Author: Vadim Zeitlin
5 // Created: 2004-12-11
6 // RCS-ID: $Id$
7 // Copyright: (c) 2004 wxWindows
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #endif // WX_PRECOMP
22
23 #include "wx/gdicmn.h"
24
25 // ----------------------------------------------------------------------------
26 // test class
27 // ----------------------------------------------------------------------------
28
29 class RectTestCase : public CppUnit::TestCase
30 {
31 public:
32 RectTestCase() { }
33
34 private:
35 CPPUNIT_TEST_SUITE( RectTestCase );
36 CPPUNIT_TEST( Union );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Union();
40
41 DECLARE_NO_COPY_CLASS(RectTestCase)
42 };
43
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase );
46
47 // also include in it's own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
49
50 void RectTestCase::Union()
51 {
52 static const struct RectData
53 {
54 int x1, y1, w1, h1;
55 int x2, y2, w2, h2;
56 int x, y, w, h;
57
58 wxRect GetFirst() const { return wxRect(x1, y1, w1, h1); }
59 wxRect GetSecond() const { return wxRect(x2, y2, w2, h2); }
60 wxRect GetResult() const { return wxRect(x, y, w, h); }
61 } s_rects[] =
62 {
63 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
64 { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
65 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
66 { 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 },
67 { 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 },
68 { 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 },
69 { 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 },
70 };
71
72 for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ )
73 {
74 const RectData& data = s_rects[n];
75
76 CPPUNIT_ASSERT(
77 data.GetFirst().Union(data.GetSecond()) == data.GetResult()
78 );
79
80 CPPUNIT_ASSERT(
81 data.GetSecond().Union(data.GetFirst()) == data.GetResult()
82 );
83 }
84 }
85