]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/spinctrldbltest.cpp
Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / tests / controls / spinctrldbltest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/spinctrldbltest.cpp
3 // Purpose: wxSpinCtrlDouble unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-22
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14
15 #ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #endif // WX_PRECOMP
18
19 #include "testableframe.h"
20 #include "wx/uiaction.h"
21 #include "wx/spinctrl.h"
22
23 class SpinCtrlDoubleTestCase : public CppUnit::TestCase
24 {
25 public:
26 SpinCtrlDoubleTestCase() { }
27
28 void setUp();
29 void tearDown();
30
31 private:
32 CPPUNIT_TEST_SUITE( SpinCtrlDoubleTestCase );
33 WXUISIM_TEST( Arrows );
34 WXUISIM_TEST( Wrap );
35 CPPUNIT_TEST( Range );
36 CPPUNIT_TEST( Value );
37 WXUISIM_TEST( Increment );
38 CPPUNIT_TEST( Digits );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Arrows();
42 void Wrap();
43 void Range();
44 void Value();
45 void Increment();
46 void Digits();
47
48 wxSpinCtrlDouble* m_spin;
49
50 DECLARE_NO_COPY_CLASS(SpinCtrlDoubleTestCase)
51 };
52
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlDoubleTestCase );
55
56 // also include in its own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlDoubleTestCase, "SpinCtrlDoubleTestCase" );
58
59 void SpinCtrlDoubleTestCase::setUp()
60 {
61 m_spin = new wxSpinCtrlDouble(wxTheApp->GetTopWindow());
62 }
63
64 void SpinCtrlDoubleTestCase::tearDown()
65 {
66 wxDELETE(m_spin);
67 }
68
69 void SpinCtrlDoubleTestCase::Arrows()
70 {
71 #ifndef __WXGTK__
72 EventCounter updated(m_spin, wxEVT_SPINCTRLDOUBLE);
73
74 wxUIActionSimulator sim;
75
76 m_spin->SetFocus();
77 wxYield();
78
79 sim.Char(WXK_UP);
80 wxYield();
81
82 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
83 CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetValue());
84 updated.Clear();
85
86 sim.Char(WXK_DOWN);
87 wxYield();
88
89 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
90 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
91 #endif
92 }
93
94 void SpinCtrlDoubleTestCase::Wrap()
95 {
96 #if wxUSE_UIACTIONSIMULATOR
97 wxDELETE(m_spin);
98 m_spin = new wxSpinCtrlDouble(wxTheApp->GetTopWindow(), wxID_ANY, "",
99 wxDefaultPosition, wxDefaultSize,
100 wxSP_ARROW_KEYS | wxSP_WRAP);
101
102 wxUIActionSimulator sim;
103
104 m_spin->SetFocus();
105
106 sim.Char(WXK_DOWN);
107
108 wxYield();
109
110 CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetValue());
111
112 sim.Char(WXK_UP);
113
114 wxYield();
115
116 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
117 #endif
118 }
119
120 void SpinCtrlDoubleTestCase::Range()
121 {
122 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetMin());
123 CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetMax());
124
125 //Test neagtive ranges
126 m_spin->SetRange(-10.0, 10.0);
127
128 CPPUNIT_ASSERT_EQUAL(-10.0, m_spin->GetMin());
129 CPPUNIT_ASSERT_EQUAL(10.0, m_spin->GetMax());
130
131 //Test backwards ranges
132 m_spin->SetRange(75.0, 50.0);
133
134 CPPUNIT_ASSERT_EQUAL(75.0, m_spin->GetMin());
135 CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetMax());
136 }
137
138 void SpinCtrlDoubleTestCase::Value()
139 {
140 m_spin->SetDigits(2);
141 m_spin->SetIncrement(0.1);
142
143 CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue());
144
145 m_spin->SetValue(50.0);
146
147 CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetValue());
148
149 m_spin->SetValue(49.1);
150
151 CPPUNIT_ASSERT_EQUAL(49.1, m_spin->GetValue());
152 }
153
154 void SpinCtrlDoubleTestCase::Increment()
155 {
156 #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
157 CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetIncrement());
158
159 m_spin->SetIncrement(0.1);
160
161 CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetIncrement());
162
163 wxUIActionSimulator sim;
164
165 m_spin->SetFocus();
166
167 sim.Char(WXK_UP);
168
169 wxYield();
170
171 CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetValue());
172 #endif
173 }
174
175 void SpinCtrlDoubleTestCase::Digits()
176 {
177 m_spin->SetDigits(5);
178
179 CPPUNIT_ASSERT_EQUAL(5, m_spin->GetDigits());
180 }