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