]>
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
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 EventCounter
clicked(m_button
, wxEVT_TOGGLEBUTTON
);
69 wxUIActionSimulator sim
;
71 //We move in slightly to account for window decorations
72 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
78 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
79 CPPUNIT_ASSERT(m_button
->GetValue());
85 CPPUNIT_ASSERT_EQUAL(1, clicked
.GetCount());
86 CPPUNIT_ASSERT(!m_button
->GetValue());
90 void ToggleButtonTestCase::Value()
92 EventCounter
clicked(m_button
, wxEVT_BUTTON
);
94 m_button
->SetValue(true);
96 CPPUNIT_ASSERT(m_button
->GetValue());
98 m_button
->SetValue(false);
100 CPPUNIT_ASSERT(!m_button
->GetValue());
102 CPPUNIT_ASSERT_EQUAL( 0, clicked
.GetCount() );
105 #endif //wxUSE_TOGGLEBTN