]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/checkboxtest.cpp
More compilation fixes for new wxRTC image code without PCH.
[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 // 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
25 class CheckBoxTestCase : public CppUnit::TestCase
26 {
27 public:
28 CheckBoxTestCase() { }
29
30 void setUp();
31 void tearDown();
32
33 private:
34 CPPUNIT_TEST_SUITE( CheckBoxTestCase );
35 CPPUNIT_TEST( Check );
36 CPPUNIT_TEST( ThirdState );
37 CPPUNIT_TEST( ThirdStateUser );
38 CPPUNIT_TEST_SUITE_END();
39
40 void Check();
41 void ThirdState();
42 void ThirdStateUser();
43
44 wxCheckBox* m_check;
45
46 DECLARE_NO_COPY_CLASS(CheckBoxTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( CheckBoxTestCase );
51
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckBoxTestCase, "CheckBoxTestCase" );
54
55 void CheckBoxTestCase::setUp()
56 {
57 m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box");
58 }
59
60 void CheckBoxTestCase::tearDown()
61 {
62 delete m_check;
63 }
64
65 void CheckBoxTestCase::Check()
66 {
67 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
68 wxTestableFrame);
69
70 EventCounter count(m_check, wxEVT_COMMAND_CHECKBOX_CLICKED);
71
72 //We should be unchecked by default
73 CPPUNIT_ASSERT(!m_check->IsChecked());
74
75 m_check->SetValue(true);
76
77 CPPUNIT_ASSERT(m_check->IsChecked());
78
79 m_check->SetValue(false);
80
81 CPPUNIT_ASSERT(!m_check->IsChecked());
82
83 m_check->Set3StateValue(wxCHK_CHECKED);
84
85 CPPUNIT_ASSERT(m_check->IsChecked());
86
87 m_check->Set3StateValue(wxCHK_UNCHECKED);
88
89 CPPUNIT_ASSERT(!m_check->IsChecked());
90
91 //None of these should send events
92 CPPUNIT_ASSERT_EQUAL(0, frame->GetEventCount());
93 }
94
95 void CheckBoxTestCase::ThirdState()
96 {
97 #if !defined(__WXMGL__) && !defined(__WXPM__) && !defined(__WXGTK12__)
98 wxDELETE(m_check);
99 m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box",
100 wxDefaultPosition, wxDefaultSize, wxCHK_3STATE);
101
102 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue());
103 CPPUNIT_ASSERT(m_check->Is3State());
104 CPPUNIT_ASSERT(!m_check->Is3rdStateAllowedForUser());
105
106 m_check->SetValue(true);
107
108 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue());
109
110 m_check->Set3StateValue(wxCHK_UNDETERMINED);
111
112 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue());
113 #endif
114 }
115
116 void CheckBoxTestCase::ThirdStateUser()
117 {
118 #if !defined(__WXMGL__) && !defined(__WXPM__) && !defined(__WXGTK12__)
119 wxDELETE(m_check);
120 m_check = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, "Check box",
121 wxDefaultPosition, wxDefaultSize,
122 wxCHK_3STATE | wxCHK_ALLOW_3RD_STATE_FOR_USER);
123
124 CPPUNIT_ASSERT_EQUAL(wxCHK_UNCHECKED, m_check->Get3StateValue());
125 CPPUNIT_ASSERT(m_check->Is3State());
126 CPPUNIT_ASSERT(m_check->Is3rdStateAllowedForUser());
127
128 m_check->SetValue(true);
129
130 CPPUNIT_ASSERT_EQUAL(wxCHK_CHECKED, m_check->Get3StateValue());
131
132 m_check->Set3StateValue(wxCHK_UNDETERMINED);
133
134 CPPUNIT_ASSERT_EQUAL(wxCHK_UNDETERMINED, m_check->Get3StateValue());
135 #endif
136 }
137
138 #endif //wxUSE_CHECKBOX