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