1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/togglebuttontest.cpp
3 // Purpose: wxToggleButton unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
22 #include "testableframe.h"
23 #include "wx/uiaction.h"
24 #include "wx/tglbtn.h"
26 class ToggleButtonTestCase
: public CppUnit::TestCase
29 ToggleButtonTestCase() { }
35 CPPUNIT_TEST_SUITE( ToggleButtonTestCase
);
36 WXUISIM_TEST( Click
);
37 CPPUNIT_TEST( Value
);
38 CPPUNIT_TEST_SUITE_END();
43 wxToggleButton
* m_button
;
45 DECLARE_NO_COPY_CLASS(ToggleButtonTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase
);
51 // also include in its own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase
, "ToggleButtonTestCase" );
54 void ToggleButtonTestCase::setUp()
56 m_button
= new wxToggleButton(wxTheApp
->GetTopWindow(), wxID_ANY
, "wxToggleButton");
59 void ToggleButtonTestCase::tearDown()
64 void ToggleButtonTestCase::Click()
66 #if wxUSE_UIACTIONSIMULATOR
67 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
70 EventCounter
count(m_button
, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
);
72 wxUIActionSimulator sim
;
74 //We move in slightly to account for window decorations
75 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
81 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
82 CPPUNIT_ASSERT(m_button
->GetValue());
87 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
88 CPPUNIT_ASSERT(!m_button
->GetValue());
92 void ToggleButtonTestCase::Value()
94 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
97 EventCounter
count(m_button
, wxEVT_COMMAND_BUTTON_CLICKED
);
99 m_button
->SetValue(true);
101 CPPUNIT_ASSERT(m_button
->GetValue());
103 m_button
->SetValue(false);
105 CPPUNIT_ASSERT(!m_button
->GetValue());
107 CPPUNIT_ASSERT_EQUAL( 0, frame
->GetEventCount() );
110 #endif //wxUSE_TOGGLEBTN