1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bitmaptogglebuttontest.cpp
3 // Purpose: wxBitmapToggleButton 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/artprov.h"
25 #include "wx/tglbtn.h"
27 class BitmapToggleButtonTestCase
: public CppUnit::TestCase
30 BitmapToggleButtonTestCase() { }
36 CPPUNIT_TEST_SUITE( BitmapToggleButtonTestCase
);
37 WXUISIM_TEST( Click
);
38 CPPUNIT_TEST( Value
);
39 CPPUNIT_TEST_SUITE_END();
44 wxBitmapToggleButton
* m_button
;
46 DECLARE_NO_COPY_CLASS(BitmapToggleButtonTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapToggleButtonTestCase
);
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapToggleButtonTestCase
,
54 "BitmapToggleButtonTestCase" );
56 void BitmapToggleButtonTestCase::setUp()
58 m_button
= new wxBitmapToggleButton(wxTheApp
->GetTopWindow(), wxID_ANY
,
59 wxArtProvider::GetIcon(wxART_INFORMATION
,
66 void BitmapToggleButtonTestCase::tearDown()
71 void BitmapToggleButtonTestCase::Click()
73 #if wxUSE_UIACTIONSIMULATOR
74 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
77 EventCounter
count(m_button
, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
);
79 wxUIActionSimulator sim
;
81 //We move in slightly to account for window decorations
82 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
88 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
89 CPPUNIT_ASSERT(m_button
->GetValue());
96 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
97 CPPUNIT_ASSERT(!m_button
->GetValue());
98 #endif // wxUSE_UIACTIONSIMULATOR
101 void BitmapToggleButtonTestCase::Value()
103 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
106 EventCounter
count(m_button
, wxEVT_COMMAND_BUTTON_CLICKED
);
108 m_button
->SetValue(true);
110 CPPUNIT_ASSERT(m_button
->GetValue());
112 m_button
->SetValue(false);
114 CPPUNIT_ASSERT(!m_button
->GetValue());
116 CPPUNIT_ASSERT_EQUAL( 0, frame
->GetEventCount() );