]>
Commit | Line | Data |
---|---|---|
232fdc63 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/controls/checkboxtest.cpp | |
3 | // Purpose: wCheckBox unit test | |
4 | // Author: Steven Lamerton | |
5 | // Created: 2010-07-14 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2010 Steven Lamerton | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "testprec.h" | |
11 | ||
12 | #if wxUSE_CHECKBOX | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/app.h" | |
20 | #include "wx/checkbox.h" | |
21 | #endif // WX_PRECOMP | |
22 | ||
23 | #include "testableframe.h" | |
24 | ||
25 | class CheckBoxTestCase : public CppUnit::TestCase | |
26 | { | |
27 | public: | |
28 | CheckBoxTestCase() { } | |
29 | ||
30 | void setUp(); | |
31 | void tearDown(); | |
32 | ||
33 | private: | |
34 | CPPUNIT_TEST_SUITE( CheckBoxTestCase ); | |
35 | CPPUNIT_TEST( Check ); | |
817b7b0e | 36 | #ifdef wxHAS_3STATE_CHECKBOX |
232fdc63 VZ |
37 | CPPUNIT_TEST( ThirdState ); |
38 | CPPUNIT_TEST( ThirdStateUser ); | |
f254e242 | 39 | CPPUNIT_TEST( InvalidStyles ); |
817b7b0e | 40 | #endif // wxHAS_3STATE_CHECKBOX |
232fdc63 VZ |
41 | CPPUNIT_TEST_SUITE_END(); |
42 | ||
43 | void Check(); | |
817b7b0e | 44 | #ifdef wxHAS_3STATE_CHECKBOX |
232fdc63 VZ |
45 | void ThirdState(); |
46 | void ThirdStateUser(); | |
f254e242 | 47 | void InvalidStyles(); |
817b7b0e | 48 | #endif // wxHAS_3STATE_CHECKBOX |
f254e242 VZ |
49 | |
50 | // Initialize m_check with a new checkbox with the specified style | |
51 | // | |
52 | // This function always returns false just to make it more convenient to | |
53 | // use inside WX_ASSERT_FAILS_WITH_ASSERT(), its return value doesn't have | |
54 | // any meaning otherwise. | |
55 | bool CreateCheckBox(long style) | |
56 | { | |
57 | m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box", | |
58 | wxDefaultPosition, wxDefaultSize, style); | |
59 | return false; | |
60 | } | |
61 | ||
232fdc63 VZ |
62 | |
63 | wxCheckBox* m_check; | |
64 | ||
65 | DECLARE_NO_COPY_CLASS(CheckBoxTestCase) | |
66 | }; | |
67 | ||
68 | // register in the unnamed registry so that these tests are run by default | |
69 | CPPUNIT_TEST_SUITE_REGISTRATION( CheckBoxTestCase ); | |
70 | ||
e3778b4d | 71 | // also include in its own registry so that these tests can be run alone |
232fdc63 VZ |
72 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckBoxTestCase, "CheckBoxTestCase" ); |
73 | ||
74 | void CheckBoxTestCase::setUp() | |
75 | { | |
76 | m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box"); | |
77 | } | |
78 | ||
79 | void CheckBoxTestCase::tearDown() | |
80 | { | |
81 | delete m_check; | |
82 | } | |
83 | ||
84 | void CheckBoxTestCase::Check() | |
85 | { | |
744d91d4 | 86 | EventCounter clicked(m_check, wxEVT_COMMAND_CHECKBOX_CLICKED); |
232fdc63 VZ |
87 | |
88 | //We should be unchecked by default | |
89 | CPPUNIT_ASSERT(!m_check->IsChecked()); | |
90 | ||
91 | m_check->SetValue(true); | |
92 | ||
93 | CPPUNIT_ASSERT(m_check->IsChecked()); | |
94 | ||
95 | m_check->SetValue(false); | |
96 | ||
97 | CPPUNIT_ASSERT(!m_check->IsChecked()); | |
98 | ||
99 | m_check->Set3StateValue(wxCHK_CHECKED); | |
100 | ||
101 | CPPUNIT_ASSERT(m_check->IsChecked()); | |
102 | ||
103 | m_check->Set3StateValue(wxCHK_UNCHECKED); | |
104 | ||
105 | CPPUNIT_ASSERT(!m_check->IsChecked()); | |
106 | ||
107 | //None of these should send events | |
744d91d4 | 108 | CPPUNIT_ASSERT_EQUAL(0, clicked.GetCount()); |
232fdc63 VZ |
109 | } |
110 | ||
817b7b0e | 111 | #ifdef wxHAS_3STATE_CHECKBOX |
232fdc63 VZ |
112 | void CheckBoxTestCase::ThirdState() |
113 | { | |
232fdc63 | 114 | wxDELETE(m_check); |
f254e242 | 115 | CreateCheckBox(wxCHK_3STATE); |
232fdc63 VZ |
116 | |
117 | CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue()); | |
118 | CPPUNIT_ASSERT(m_check->Is3State()); | |
119 | CPPUNIT_ASSERT(!m_check->Is3rdStateAllowedForUser()); | |
120 | ||
121 | m_check->SetValue(true); | |
122 | ||
123 | CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue()); | |
124 | ||
125 | m_check->Set3StateValue(wxCHK_UNDETERMINED); | |
126 | ||
127 | CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue()); | |
232fdc63 VZ |
128 | } |
129 | ||
130 | void CheckBoxTestCase::ThirdStateUser() | |
131 | { | |
232fdc63 | 132 | wxDELETE(m_check); |
f254e242 | 133 | CreateCheckBox(wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER); |
232fdc63 VZ |
134 | |
135 | CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue()); | |
136 | CPPUNIT_ASSERT(m_check->Is3State()); | |
137 | CPPUNIT_ASSERT(m_check->Is3rdStateAllowedForUser()); | |
138 | ||
139 | m_check->SetValue(true); | |
140 | ||
141 | CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue()); | |
142 | ||
143 | m_check->Set3StateValue(wxCHK_UNDETERMINED); | |
144 | ||
145 | CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue()); | |
232fdc63 VZ |
146 | } |
147 | ||
f254e242 VZ |
148 | void CheckBoxTestCase::InvalidStyles() |
149 | { | |
150 | // Check that using incompatible styles doesn't work. | |
151 | wxDELETE( m_check ); | |
152 | WX_ASSERT_FAILS_WITH_ASSERT( CreateCheckBox(wxCHK_2STATE | wxCHK_3STATE) ); | |
153 | #if !wxDEBUG_LEVEL | |
154 | CPPUNIT_ASSERT( !m_check->Is3State() ); | |
155 | CPPUNIT_ASSERT( !m_check->Is3rdStateAllowedForUser() ); | |
156 | #endif | |
157 | ||
158 | wxDELETE( m_check ); | |
159 | WX_ASSERT_FAILS_WITH_ASSERT( | |
160 | CreateCheckBox(wxCHK_2STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER) ); | |
161 | #if !wxDEBUG_LEVEL | |
162 | CPPUNIT_ASSERT( !m_check->Is3State() ); | |
163 | CPPUNIT_ASSERT( !m_check->Is3rdStateAllowedForUser() ); | |
164 | #endif | |
165 | ||
166 | // wxCHK_ALLOW_3RD_STATE_FOR_USER without wxCHK_3STATE doesn't work. | |
167 | wxDELETE( m_check ); | |
168 | WX_ASSERT_FAILS_WITH_ASSERT( CreateCheckBox(wxCHK_ALLOW_3RD_STATE_FOR_USER) ); | |
169 | } | |
170 | ||
817b7b0e VZ |
171 | #endif // wxHAS_3STATE_CHECKBOX |
172 | ||
173 | #endif // wxUSE_CHECKBOX |