]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/checkboxtest.cpp
Fix wrong in wxListCtrl::SetItemColumnImage() in r74716.
[wxWidgets.git] / tests / controls / checkboxtest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/checkboxtest.cpp
3// Purpose: wCheckBox unit test
4// Author: Steven Lamerton
5// Created: 2010-07-14
232fdc63
VZ
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
24class CheckBoxTestCase : public CppUnit::TestCase
25{
26public:
27 CheckBoxTestCase() { }
28
29 void setUp();
30 void tearDown();
31
32private:
33 CPPUNIT_TEST_SUITE( CheckBoxTestCase );
34 CPPUNIT_TEST( Check );
817b7b0e 35#ifdef wxHAS_3STATE_CHECKBOX
232fdc63
VZ
36 CPPUNIT_TEST( ThirdState );
37 CPPUNIT_TEST( ThirdStateUser );
f254e242 38 CPPUNIT_TEST( InvalidStyles );
817b7b0e 39#endif // wxHAS_3STATE_CHECKBOX
232fdc63
VZ
40 CPPUNIT_TEST_SUITE_END();
41
42 void Check();
817b7b0e 43#ifdef wxHAS_3STATE_CHECKBOX
232fdc63
VZ
44 void ThirdState();
45 void ThirdStateUser();
f254e242 46 void InvalidStyles();
817b7b0e 47#endif // wxHAS_3STATE_CHECKBOX
f254e242
VZ
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
232fdc63
VZ
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
68CPPUNIT_TEST_SUITE_REGISTRATION( CheckBoxTestCase );
69
e3778b4d 70// also include in its own registry so that these tests can be run alone
232fdc63
VZ
71CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckBoxTestCase, "CheckBoxTestCase" );
72
73void CheckBoxTestCase::setUp()
74{
75 m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box");
76}
77
78void CheckBoxTestCase::tearDown()
79{
80 delete m_check;
81}
82
83void CheckBoxTestCase::Check()
84{
ce7fe42e 85 EventCounter clicked(m_check, wxEVT_CHECKBOX);
232fdc63
VZ
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
744d91d4 107 CPPUNIT_ASSERT_EQUAL(0, clicked.GetCount());
232fdc63
VZ
108}
109
817b7b0e 110#ifdef wxHAS_3STATE_CHECKBOX
232fdc63
VZ
111void CheckBoxTestCase::ThirdState()
112{
232fdc63 113 wxDELETE(m_check);
f254e242 114 CreateCheckBox(wxCHK_3STATE);
232fdc63
VZ
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());
232fdc63
VZ
127}
128
129void CheckBoxTestCase::ThirdStateUser()
130{
232fdc63 131 wxDELETE(m_check);
f254e242 132 CreateCheckBox(wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER);
232fdc63
VZ
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());
232fdc63
VZ
145}
146
f254e242
VZ
147void 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
817b7b0e
VZ
170#endif // wxHAS_3STATE_CHECKBOX
171
172#endif // wxUSE_CHECKBOX