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