]>
Commit | Line | Data |
---|---|---|
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 | ||
57 | // also include in its own registry so that these tests can be run alone | |
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 | EventCounter updated(m_spin, wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED); | |
74 | ||
75 | wxUIActionSimulator sim; | |
76 | ||
77 | m_spin->SetFocus(); | |
78 | wxYield(); | |
79 | ||
80 | sim.Char(WXK_UP); | |
81 | wxYield(); | |
82 | ||
83 | CPPUNIT_ASSERT_EQUAL(1, updated.GetCount()); | |
84 | CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetValue()); | |
85 | updated.Clear(); | |
86 | ||
87 | sim.Char(WXK_DOWN); | |
88 | wxYield(); | |
89 | ||
90 | CPPUNIT_ASSERT_EQUAL(1, updated.GetCount()); | |
91 | CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue()); | |
92 | #endif | |
93 | } | |
94 | ||
95 | void SpinCtrlDoubleTestCase::Wrap() | |
96 | { | |
97 | #if wxUSE_UIACTIONSIMULATOR | |
98 | wxDELETE(m_spin); | |
99 | m_spin = new wxSpinCtrlDouble(wxTheApp->GetTopWindow(), wxID_ANY, "", | |
100 | wxDefaultPosition, wxDefaultSize, | |
101 | wxSP_ARROW_KEYS | wxSP_WRAP); | |
102 | ||
103 | wxUIActionSimulator sim; | |
104 | ||
105 | m_spin->SetFocus(); | |
106 | ||
107 | sim.Char(WXK_DOWN); | |
108 | ||
109 | wxYield(); | |
110 | ||
111 | CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetValue()); | |
112 | ||
113 | sim.Char(WXK_UP); | |
114 | ||
115 | wxYield(); | |
116 | ||
117 | CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue()); | |
118 | #endif | |
119 | } | |
120 | ||
121 | void SpinCtrlDoubleTestCase::Range() | |
122 | { | |
123 | CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetMin()); | |
124 | CPPUNIT_ASSERT_EQUAL(100.0, m_spin->GetMax()); | |
125 | ||
126 | //Test neagtive ranges | |
127 | m_spin->SetRange(-10.0, 10.0); | |
128 | ||
129 | CPPUNIT_ASSERT_EQUAL(-10.0, m_spin->GetMin()); | |
130 | CPPUNIT_ASSERT_EQUAL(10.0, m_spin->GetMax()); | |
131 | ||
132 | //Test backwards ranges | |
133 | m_spin->SetRange(75.0, 50.0); | |
134 | ||
135 | CPPUNIT_ASSERT_EQUAL(75.0, m_spin->GetMin()); | |
136 | CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetMax()); | |
137 | } | |
138 | ||
139 | void SpinCtrlDoubleTestCase::Value() | |
140 | { | |
141 | m_spin->SetDigits(2); | |
142 | m_spin->SetIncrement(0.1); | |
143 | ||
144 | CPPUNIT_ASSERT_EQUAL(0.0, m_spin->GetValue()); | |
145 | ||
146 | m_spin->SetValue(50.0); | |
147 | ||
148 | CPPUNIT_ASSERT_EQUAL(50.0, m_spin->GetValue()); | |
149 | ||
150 | m_spin->SetValue(49.1); | |
151 | ||
152 | CPPUNIT_ASSERT_EQUAL(49.1, m_spin->GetValue()); | |
153 | } | |
154 | ||
155 | void SpinCtrlDoubleTestCase::Increment() | |
156 | { | |
157 | #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) | |
158 | CPPUNIT_ASSERT_EQUAL(1.0, m_spin->GetIncrement()); | |
159 | ||
160 | m_spin->SetIncrement(0.1); | |
161 | ||
162 | CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetIncrement()); | |
163 | ||
164 | wxUIActionSimulator sim; | |
165 | ||
166 | m_spin->SetFocus(); | |
167 | ||
168 | sim.Char(WXK_UP); | |
169 | ||
170 | wxYield(); | |
171 | ||
172 | CPPUNIT_ASSERT_EQUAL(0.1, m_spin->GetValue()); | |
173 | #endif | |
174 | } | |
175 | ||
176 | void SpinCtrlDoubleTestCase::Digits() | |
177 | { | |
178 | m_spin->SetDigits(5); | |
179 | ||
180 | CPPUNIT_ASSERT_EQUAL(5, m_spin->GetDigits()); | |
181 | } |