1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/checkboxtest.cpp
3 // Purpose: wCheckBox unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "wx/checkbox.h"
23 #include "testableframe.h"
25 class CheckBoxTestCase
: public CppUnit::TestCase
28 CheckBoxTestCase() { }
34 CPPUNIT_TEST_SUITE( CheckBoxTestCase
);
35 CPPUNIT_TEST( Check
);
36 CPPUNIT_TEST( ThirdState
);
37 CPPUNIT_TEST( ThirdStateUser
);
38 CPPUNIT_TEST_SUITE_END();
42 void ThirdStateUser();
46 DECLARE_NO_COPY_CLASS(CheckBoxTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( CheckBoxTestCase
);
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckBoxTestCase
, "CheckBoxTestCase" );
55 void CheckBoxTestCase::setUp()
57 m_check
= new wxCheckBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "Check box");
60 void CheckBoxTestCase::tearDown()
65 void CheckBoxTestCase::Check()
67 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
70 EventCounter
count(m_check
, wxEVT_COMMAND_CHECKBOX_CLICKED
);
72 //We should be unchecked by default
73 CPPUNIT_ASSERT(!m_check
->IsChecked());
75 m_check
->SetValue(true);
77 CPPUNIT_ASSERT(m_check
->IsChecked());
79 m_check
->SetValue(false);
81 CPPUNIT_ASSERT(!m_check
->IsChecked());
83 m_check
->Set3StateValue(wxCHK_CHECKED
);
85 CPPUNIT_ASSERT(m_check
->IsChecked());
87 m_check
->Set3StateValue(wxCHK_UNCHECKED
);
89 CPPUNIT_ASSERT(!m_check
->IsChecked());
91 //None of these should send events
92 CPPUNIT_ASSERT_EQUAL(0, frame
->GetEventCount());
95 void CheckBoxTestCase::ThirdState()
97 #if !defined(__WXMGL__) && !defined(__WXPM__) && !defined(__WXGTK12__)
99 m_check
= new wxCheckBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "Check box",
100 wxDefaultPosition
, wxDefaultSize
, wxCHK_3STATE
);
102 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED
, m_check
->Get3StateValue());
103 CPPUNIT_ASSERT(m_check
->Is3State());
104 CPPUNIT_ASSERT(!m_check
->Is3rdStateAllowedForUser());
106 m_check
->SetValue(true);
108 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED
, m_check
->Get3StateValue());
110 m_check
->Set3StateValue(wxCHK_UNDETERMINED
);
112 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED
, m_check
->Get3StateValue());
116 void CheckBoxTestCase::ThirdStateUser()
118 #if !defined(__WXMGL__) && !defined(__WXPM__) && !defined(__WXGTK12__)
120 m_check
= new wxCheckBox(wxTheApp
->GetTopWindow(), wxID_ANY
, "Check box",
121 wxDefaultPosition
, wxDefaultSize
,
122 wxCHK_3STATE
| wxCHK_ALLOW_3RD_STATE_FOR_USER
);
124 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED
, m_check
->Get3StateValue());
125 CPPUNIT_ASSERT(m_check
->Is3State());
126 CPPUNIT_ASSERT(m_check
->Is3rdStateAllowedForUser());
128 m_check
->SetValue(true);
130 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED
, m_check
->Get3StateValue());
132 m_check
->Set3StateValue(wxCHK_UNDETERMINED
);
134 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED
, m_check
->Get3StateValue());
138 #endif //wxUSE_CHECKBOX