]> git.saurik.com Git - wxWidgets.git/blob - tests/geometry/rect.cpp
reset m_hDWP to NULL after calling EndDeferWindowPos()
[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 #include "wx/gdicmn.h"
22 #endif // WX_PRECOMP
23
24 // ----------------------------------------------------------------------------
25 // test class
26 // ----------------------------------------------------------------------------
27
28 class RectTestCase : public CppUnit::TestCase
29 {
30 public:
31 RectTestCase() { }
32
33 private:
34 CPPUNIT_TEST_SUITE( RectTestCase );
35 CPPUNIT_TEST( Operators );
36 CPPUNIT_TEST( Union );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Operators();
40 void Union();
41
42 DECLARE_NO_COPY_CLASS(RectTestCase)
43 };
44
45 // register in the unnamed registry so that these tests are run by default
46 CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase );
47
48 // also include in it's own registry so that these tests can be run alone
49 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
50
51 void RectTestCase::Operators()
52 {
53 // test + operator which works like Union but does not ignore empty rectangles
54 static const struct RectData
55 {
56 int x1, y1, w1, h1;
57 int x2, y2, w2, h2;
58 int x, y, w, h;
59
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); }
63 } s_rects[] =
64 {
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 }
72 };
73
74 for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ )
75 {
76 const RectData& data = s_rects[n];
77
78 CPPUNIT_ASSERT(
79 ( data.GetFirst() + data.GetSecond() ) == data.GetResult()
80 );
81
82 CPPUNIT_ASSERT(
83 ( data.GetSecond() + data.GetFirst() ) == data.GetResult()
84 );
85 }
86 }
87
88 void RectTestCase::Union()
89 {
90 static const struct RectData
91 {
92 int x1, y1, w1, h1;
93 int x2, y2, w2, h2;
94 int x, y, w, h;
95
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); }
99 } s_rects[] =
100 {
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 }
108 };
109
110 for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ )
111 {
112 const RectData& data = s_rects[n];
113
114 CPPUNIT_ASSERT(
115 data.GetFirst().Union(data.GetSecond()) == data.GetResult()
116 );
117
118 CPPUNIT_ASSERT(
119 data.GetSecond().Union(data.GetFirst()) == data.GetResult()
120 );
121 }
122 }