1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bitmaptogglebuttontest.cpp
3 // Purpose: wxBitmapToggleButton unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
20 #include "testableframe.h"
21 #include "wx/uiaction.h"
22 #include "wx/artprov.h"
23 #include "wx/tglbtn.h"
25 class BitmapToggleButtonTestCase
: public CppUnit::TestCase
28 BitmapToggleButtonTestCase() { }
34 CPPUNIT_TEST_SUITE( BitmapToggleButtonTestCase
);
35 WXUISIM_TEST( Click
);
36 CPPUNIT_TEST( Value
);
37 CPPUNIT_TEST_SUITE_END();
42 wxBitmapToggleButton
* m_button
;
44 DECLARE_NO_COPY_CLASS(BitmapToggleButtonTestCase
)
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapToggleButtonTestCase
);
50 // also include in it's own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapToggleButtonTestCase
,
52 "BitmapToggleButtonTestCase" );
54 void BitmapToggleButtonTestCase::setUp()
56 m_button
= new wxBitmapToggleButton(wxTheApp
->GetTopWindow(), wxID_ANY
,
57 wxArtProvider::GetIcon(wxART_INFORMATION
,
64 void BitmapToggleButtonTestCase::tearDown()
69 void BitmapToggleButtonTestCase::Click()
71 #if wxUSE_UIACTIONSIMULATOR
72 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
75 EventCounter
count(m_button
, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
);
77 wxUIActionSimulator sim
;
79 //We move in slightly to account for window decorations
80 sim
.MouseMove(m_button
->GetScreenPosition() + wxPoint(10, 10));
86 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
87 CPPUNIT_ASSERT(m_button
->GetValue());
94 CPPUNIT_ASSERT_EQUAL(1, frame
->GetEventCount());
95 CPPUNIT_ASSERT(!m_button
->GetValue());
96 #endif // wxUSE_UIACTIONSIMULATOR
99 void BitmapToggleButtonTestCase::Value()
101 wxTestableFrame
* frame
= wxStaticCast(wxTheApp
->GetTopWindow(),
104 EventCounter
count(m_button
, wxEVT_COMMAND_BUTTON_CLICKED
);
106 m_button
->SetValue(true);
108 CPPUNIT_ASSERT(m_button
->GetValue());
110 m_button
->SetValue(false);
112 CPPUNIT_ASSERT(!m_button
->GetValue());
114 CPPUNIT_ASSERT_EQUAL( 0, frame
->GetEventCount() );