1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bitmaptogglebuttontest.cpp
3 // Purpose: wxBitmapToggleButton unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
18 #include "wx/tglbtn.h"
20 #ifdef wxHAS_BITMAPTOGGLEBUTTON
26 #include "testableframe.h"
27 #include "wx/uiaction.h"
28 #include "wx/artprov.h"
30 class BitmapToggleButtonTestCase
: public CppUnit::TestCase
33 BitmapToggleButtonTestCase() { }
39 CPPUNIT_TEST_SUITE( BitmapToggleButtonTestCase
);
40 WXUISIM_TEST( Click
);
41 CPPUNIT_TEST( Value
);
42 CPPUNIT_TEST_SUITE_END();
47 wxBitmapToggleButton
* m_button
;
49 DECLARE_NO_COPY_CLASS(BitmapToggleButtonTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapToggleButtonTestCase
);
55 // also include in its own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapToggleButtonTestCase
,
57 "BitmapToggleButtonTestCase" );
59 void BitmapToggleButtonTestCase::setUp()
61 m_button
= new wxBitmapToggleButton(wxTheApp
->GetTopWindow(), wxID_ANY
,
62 wxArtProvider::GetIcon(wxART_INFORMATION
,
69 void BitmapToggleButtonTestCase::tearDown()
74 void BitmapToggleButtonTestCase::Click()
76 #if wxUSE_UIACTIONSIMULATOR
77 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
80 EventCounter
count(m_button
, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
);
82 wxUIActionSimulator sim
;
84 //We move in slightly to account for window decorations
85 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
91 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
92 CPPUNIT_ASSERT(m_button
->GetValue());
99 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
100 CPPUNIT_ASSERT(!m_button
->GetValue());
101 #endif // wxUSE_UIACTIONSIMULATOR
104 void BitmapToggleButtonTestCase::Value()
106 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
109 EventCounter
count(m_button
, wxEVT_COMMAND_BUTTON_CLICKED
);
111 m_button
->SetValue(true);
113 CPPUNIT_ASSERT(m_button
->GetValue());
115 m_button
->SetValue(false);
117 CPPUNIT_ASSERT(!m_button
->GetValue());
119 CPPUNIT_ASSERT_EQUAL( 0, frame
->GetEventCount() );
122 #endif // wxHAS_BITMAPTOGGLEBUTTON
124 #endif // wxUSE_TOGGLEBTN