]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/controls/checkboxtest.cpp
using button impl
[wxWidgets.git] / tests / controls / checkboxtest.cpp
... / ...
CommitLineData
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 );
36#ifdef wxHAS_3STATE_CHECKBOX
37 CPPUNIT_TEST( ThirdState );
38 CPPUNIT_TEST( ThirdStateUser );
39 CPPUNIT_TEST( InvalidStyles );
40#endif // wxHAS_3STATE_CHECKBOX
41 CPPUNIT_TEST_SUITE_END();
42
43 void Check();
44#ifdef wxHAS_3STATE_CHECKBOX
45 void ThirdState();
46 void ThirdStateUser();
47 void InvalidStyles();
48#endif // wxHAS_3STATE_CHECKBOX
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
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
71// also include in its own registry so that these tests can be run alone
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 EventCounter clicked(m_check, wxEVT_COMMAND_CHECKBOX_CLICKED);
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
108 CPPUNIT_ASSERT_EQUAL(0, clicked.GetCount());
109}
110
111#ifdef wxHAS_3STATE_CHECKBOX
112void CheckBoxTestCase::ThirdState()
113{
114 wxDELETE(m_check);
115 CreateCheckBox(wxCHK_3STATE);
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());
128}
129
130void CheckBoxTestCase::ThirdStateUser()
131{
132 wxDELETE(m_check);
133 CreateCheckBox(wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER);
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());
146}
147
148void 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
171#endif // wxHAS_3STATE_CHECKBOX
172
173#endif // wxUSE_CHECKBOX