]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/spinctrltest.cpp
Run some wxTextCtrl unit test cases for single and multi-line controls.
[wxWidgets.git] / tests / controls / spinctrltest.cpp
CommitLineData
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
26class SpinCtrlTestCase : public CppUnit::TestCase
27{
28public:
29 SpinCtrlTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
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
53CPPUNIT_TEST_SUITE_REGISTRATION( SpinCtrlTestCase );
54
e3778b4d 55// also include in its own registry so that these tests can be run alone
232fdc63
VZ
56CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SpinCtrlTestCase, "SpinCtrlTestCase" );
57
58void SpinCtrlTestCase::setUp()
59{
60 m_spin = new wxSpinCtrl(wxTheApp->GetTopWindow());
61}
62
63void SpinCtrlTestCase::tearDown()
64{
65 wxDELETE(m_spin);
66}
67
68void SpinCtrlTestCase::Arrows()
69{
70#if wxUSE_UIACTIONSIMULATOR
744d91d4 71 EventCounter updated(m_spin, wxEVT_COMMAND_SPINCTRL_UPDATED);
232fdc63
VZ
72
73 wxUIActionSimulator sim;
74
75 m_spin->SetFocus();
76
77 sim.Char(WXK_UP);
78
79 wxYield();
80
744d91d4 81 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
232fdc63 82 CPPUNIT_ASSERT_EQUAL(1, m_spin->GetValue());
744d91d4 83 updated.Clear();
232fdc63
VZ
84
85 sim.Char(WXK_DOWN);
86
87 wxYield();
88
744d91d4 89 CPPUNIT_ASSERT_EQUAL(1, updated.GetCount());
232fdc63
VZ
90 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
91#endif
92}
93
94void SpinCtrlTestCase::Wrap()
95{
96#if wxUSE_UIACTIONSIMULATOR
97 wxDELETE(m_spin);
98 m_spin = new wxSpinCtrl(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, m_spin->GetValue());
111
112 sim.Char(WXK_UP);
113
114 wxYield();
115
116 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
117#endif
118}
119
120void SpinCtrlTestCase::Range()
121{
122 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetMin());
123 CPPUNIT_ASSERT_EQUAL(100, m_spin->GetMax());
124
125 //Test neagtive ranges
126 m_spin->SetRange(-10, 10);
127
128 CPPUNIT_ASSERT_EQUAL(-10, m_spin->GetMin());
129 CPPUNIT_ASSERT_EQUAL(10, m_spin->GetMax());
130
131 //Test backwards ranges
132 m_spin->SetRange(75, 50);
133
134 CPPUNIT_ASSERT_EQUAL(75, m_spin->GetMin());
135 CPPUNIT_ASSERT_EQUAL(50, m_spin->GetMax());
136}
137
138void SpinCtrlTestCase::Value()
139{
140 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
141
142 m_spin->SetValue(50);
143
144 CPPUNIT_ASSERT_EQUAL(50, m_spin->GetValue());
145
146 m_spin->SetValue(-10);
147
148 CPPUNIT_ASSERT_EQUAL(0, m_spin->GetValue());
149
150 m_spin->SetValue(110);
151
152 CPPUNIT_ASSERT_EQUAL(100, m_spin->GetValue());
153}
154
155#endif