]> git.saurik.com Git - wxWidgets.git/blob - tests/geometry/point.cpp
Fix horizontal mouse wheel scrolling in wxGTK.
[wxWidgets.git] / tests / geometry / point.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/geometry/point.cpp
3 // Purpose: wxPoint unit test
4 // Author: Wlodzimierz ABX Skiba
5 // Created: 2004-12-14
6 // Copyright: (c) 2004 wxWindows
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/gdicmn.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/math.h"
24
25 // ----------------------------------------------------------------------------
26 // test class
27 // ----------------------------------------------------------------------------
28
29 class PointTestCase : public CppUnit::TestCase
30 {
31 public:
32 PointTestCase() { }
33
34 private:
35 CPPUNIT_TEST_SUITE( PointTestCase );
36 CPPUNIT_TEST( Operators );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Operators();
40
41 DECLARE_NO_COPY_CLASS(PointTestCase)
42 };
43
44 class RealPointTestCase : public CppUnit::TestCase
45 {
46 public:
47 RealPointTestCase() { }
48
49 private:
50 CPPUNIT_TEST_SUITE( RealPointTestCase );
51 CPPUNIT_TEST( Operators );
52 CPPUNIT_TEST_SUITE_END();
53
54 void Operators();
55
56 DECLARE_NO_COPY_CLASS(RealPointTestCase)
57 };
58
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase );
61 CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase );
62
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" );
65 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" );
66
67 void PointTestCase::Operators()
68 {
69 wxPoint p1(1,2);
70 wxPoint p2(6,3);
71 wxPoint p3(7,5);
72 wxPoint p4(5,1);
73 wxPoint p5 = p2 + p1;
74 wxPoint p6 = p2 - p1;
75 CPPUNIT_ASSERT( p3.x == p5.x && p3.y == p5.y );
76 CPPUNIT_ASSERT( p4.x == p6.x && p4.y == p6.y );
77 CPPUNIT_ASSERT( p3 == p5 );
78 CPPUNIT_ASSERT( p4 == p6 );
79 CPPUNIT_ASSERT( p3 != p4 );
80 p5 = p2; p5 += p1;
81 p6 = p2; p6 -= p1;
82 CPPUNIT_ASSERT( p3 == p5 );
83 CPPUNIT_ASSERT( p4 == p6 );
84 wxSize s(p1.x,p1.y);
85 p5 = p2; p5 = p2 + s;
86 p6 = p2; p6 = p2 - s;
87 CPPUNIT_ASSERT( p3 == p5 );
88 CPPUNIT_ASSERT( p4 == p6 );
89 p5 = p2; p5 = s + p2;
90 p6 = p2; p6 = s - p2;
91 CPPUNIT_ASSERT( p3 == p5 );
92 CPPUNIT_ASSERT( p4 == -p6 );
93 p5 = p2; p5 += s;
94 p6 = p2; p6 -= s;
95 CPPUNIT_ASSERT( p3 == p5 );
96 CPPUNIT_ASSERT( p4 == p6 );
97 }
98
99 void RealPointTestCase::Operators()
100 {
101 const double EPSILON = 0.00001;
102 wxRealPoint p1(1.2,3.4);
103 wxRealPoint p2(8.7,5.4);
104 wxRealPoint p3(9.9,8.8);
105 wxRealPoint p4(7.5,2.0);
106 wxRealPoint p5 = p2 + p1;
107 wxRealPoint p6 = p2 - p1;
108 /*
109 CPPUNIT_ASSERT( p3 == p5 );
110 CPPUNIT_ASSERT( p4 == p6 );
111 CPPUNIT_ASSERT( p3 != p4 );
112 */
113 CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON && fabs( p3.y - p5.y ) < EPSILON );
114 CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON && fabs( p4.y - p6.y ) < EPSILON );
115 }