]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/checkboxtest.cpp
Add tests for url and history support
[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
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
25class CheckBoxTestCase : public CppUnit::TestCase
26{
27public:
28 CheckBoxTestCase() { }
29
30 void setUp();
31 void tearDown();
32
33private:
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
69CPPUNIT_TEST_SUITE_REGISTRATION( CheckBoxTestCase );
70
e3778b4d 71// also include in its own registry so that these tests can be run alone
232fdc63
VZ
72CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckBoxTestCase, "CheckBoxTestCase" );
73
74void CheckBoxTestCase::setUp()
75{
76 m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box");
77}
78
79void CheckBoxTestCase::tearDown()
80{
81 delete m_check;
82}
83
84void CheckBoxTestCase::Check()
85{
86 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
87 wxTestableFrame);
88
89 EventCounter count(m_check, wxEVT_COMMAND_CHECKBOX_CLICKED);
90
91 //We should be unchecked by default
92 CPPUNIT_ASSERT(!m_check->IsChecked());
93
94 m_check->SetValue(true);
95
96 CPPUNIT_ASSERT(m_check->IsChecked());
97
98 m_check->SetValue(false);
99
100 CPPUNIT_ASSERT(!m_check->IsChecked());
101
102 m_check->Set3StateValue(wxCHK_CHECKED);
103
104 CPPUNIT_ASSERT(m_check->IsChecked());
105
106 m_check->Set3StateValue(wxCHK_UNCHECKED);
107
108 CPPUNIT_ASSERT(!m_check->IsChecked());
109
110 //None of these should send events
111 CPPUNIT_ASSERT_EQUAL(0, frame->GetEventCount());
112}
113
817b7b0e 114#ifdef wxHAS_3STATE_CHECKBOX
232fdc63
VZ
115void CheckBoxTestCase::ThirdState()
116{
232fdc63 117 wxDELETE(m_check);
f254e242 118 CreateCheckBox(wxCHK_3STATE);
232fdc63
VZ
119
120 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue());
121 CPPUNIT_ASSERT(m_check->Is3State());
122 CPPUNIT_ASSERT(!m_check->Is3rdStateAllowedForUser());
123
124 m_check->SetValue(true);
125
126 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue());
127
128 m_check->Set3StateValue(wxCHK_UNDETERMINED);
129
130 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue());
232fdc63
VZ
131}
132
133void CheckBoxTestCase::ThirdStateUser()
134{
232fdc63 135 wxDELETE(m_check);
f254e242 136 CreateCheckBox(wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER);
232fdc63
VZ
137
138 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue());
139 CPPUNIT_ASSERT(m_check->Is3State());
140 CPPUNIT_ASSERT(m_check->Is3rdStateAllowedForUser());
141
142 m_check->SetValue(true);
143
144 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue());
145
146 m_check->Set3StateValue(wxCHK_UNDETERMINED);
147
148 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue());
232fdc63
VZ
149}
150
f254e242
VZ
151void CheckBoxTestCase::InvalidStyles()
152{
153 // Check that using incompatible styles doesn't work.
154 wxDELETE( m_check );
155 WX_ASSERT_FAILS_WITH_ASSERT( CreateCheckBox(wxCHK_2STATE | wxCHK_3STATE) );
156#if !wxDEBUG_LEVEL
157 CPPUNIT_ASSERT( !m_check->Is3State() );
158 CPPUNIT_ASSERT( !m_check->Is3rdStateAllowedForUser() );
159#endif
160
161 wxDELETE( m_check );
162 WX_ASSERT_FAILS_WITH_ASSERT(
163 CreateCheckBox(wxCHK_2STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER) );
164#if !wxDEBUG_LEVEL
165 CPPUNIT_ASSERT( !m_check->Is3State() );
166 CPPUNIT_ASSERT( !m_check->Is3rdStateAllowedForUser() );
167#endif
168
169 // wxCHK_ALLOW_3RD_STATE_FOR_USER without wxCHK_3STATE doesn't work.
170 wxDELETE( m_check );
171 WX_ASSERT_FAILS_WITH_ASSERT( CreateCheckBox(wxCHK_ALLOW_3RD_STATE_FOR_USER) );
172}
173
817b7b0e
VZ
174#endif // wxHAS_3STATE_CHECKBOX
175
176#endif // wxUSE_CHECKBOX