]>
git.saurik.com Git - wxWidgets.git/blob - tests/controls/togglebuttontest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/togglebuttontest.cpp
3 // Purpose: wxToggleButton unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
21 #include "testableframe.h"
22 #include "wx/uiaction.h"
23 #include "wx/tglbtn.h"
25 class ToggleButtonTestCase
: public CppUnit::TestCase
28 ToggleButtonTestCase() { }
34 CPPUNIT_TEST_SUITE( ToggleButtonTestCase
);
35 WXUISIM_TEST( Click
);
36 CPPUNIT_TEST( Value
);
37 CPPUNIT_TEST_SUITE_END();
42 wxToggleButton
* m_button
;
44 DECLARE_NO_COPY_CLASS(ToggleButtonTestCase
)
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase
);
50 // also include in its own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase
, "ToggleButtonTestCase" );
53 void ToggleButtonTestCase::setUp()
55 m_button
= new wxToggleButton(wxTheApp
->GetTopWindow(), wxID_ANY
, "wxToggleButton");
58 void ToggleButtonTestCase::tearDown()
63 void ToggleButtonTestCase::Click()
65 #if wxUSE_UIACTIONSIMULATOR
66 EventCounter
clicked(m_button
, wxEVT_TOGGLEBUTTON
);
68 wxUIActionSimulator sim
;
70 //We move in slightly to account for window decorations
71 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
77 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
78 CPPUNIT_ASSERT(m_button
->GetValue());
84 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
85 CPPUNIT_ASSERT(!m_button
->GetValue());
89 void ToggleButtonTestCase::Value()
91 EventCounter
clicked(m_button
, wxEVT_BUTTON
);
93 m_button
->SetValue(true);
95 CPPUNIT_ASSERT(m_button
->GetValue());
97 m_button
->SetValue(false);
99 CPPUNIT_ASSERT(!m_button
->GetValue());
101 CPPUNIT_ASSERT_EQUAL( 0, clicked
.GetCount() );
104 #endif //wxUSE_TOGGLEBTN