Wrap BitmapToggleButtonTestCase in a preprocessor check so compilation shouldn't...
[wxWidgets.git] / tests / controls / bitmaptogglebuttontest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/bitmaptogglebuttontest.cpp
3 // Purpose: wxBitmapToggleButton unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-17
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_TOGGLEBTN
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #endif // WX_PRECOMP
21
22 #include "testableframe.h"
23 #include "wx/uiaction.h"
24 #include "wx/artprov.h"
25 #include "wx/tglbtn.h"
26
27 class BitmapToggleButtonTestCase : public CppUnit::TestCase
28 {
29 public:
30 BitmapToggleButtonTestCase() { }
31
32 void setUp();
33 void tearDown();
34
35 private:
36 CPPUNIT_TEST_SUITE( BitmapToggleButtonTestCase );
37 WXUISIM_TEST( Click );
38 CPPUNIT_TEST( Value );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Click();
42 void Value();
43
44 wxBitmapToggleButton* m_button;
45
46 DECLARE_NO_COPY_CLASS(BitmapToggleButtonTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( BitmapToggleButtonTestCase );
51
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" );
55
56 void BitmapToggleButtonTestCase::setUp()
57 {
58 m_button = new wxBitmapToggleButton(wxTheApp->GetTopWindow(), wxID_ANY,
59 wxArtProvider::GetIcon(wxART_INFORMATION,
60 wxART_OTHER,
61 wxSize(32, 32)));
62 m_button->Update();
63 m_button->Refresh();
64 }
65
66 void BitmapToggleButtonTestCase::tearDown()
67 {
68 wxDELETE(m_button);
69 }
70
71 void BitmapToggleButtonTestCase::Click()
72 {
73 #if wxUSE_UIACTIONSIMULATOR
74 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
75 wxTestableFrame);
76
77 EventCounter count(m_button, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED);
78
79 wxUIActionSimulator sim;
80
81 //We move in slightly to account for window decorations
82 sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
83 wxYield();
84
85 sim.MouseClick();
86 wxYield();
87
88 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount());
89 CPPUNIT_ASSERT(m_button->GetValue());
90
91 wxMilliSleep(1000);
92
93 sim.MouseClick();
94 wxYield();
95
96 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount());
97 CPPUNIT_ASSERT(!m_button->GetValue());
98 #endif // wxUSE_UIACTIONSIMULATOR
99 }
100
101 void BitmapToggleButtonTestCase::Value()
102 {
103 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
104 wxTestableFrame);
105
106 EventCounter count(m_button, wxEVT_COMMAND_BUTTON_CLICKED);
107
108 m_button->SetValue(true);
109
110 CPPUNIT_ASSERT(m_button->GetValue());
111
112 m_button->SetValue(false);
113
114 CPPUNIT_ASSERT(!m_button->GetValue());
115
116 CPPUNIT_ASSERT_EQUAL( 0, frame->GetEventCount() );
117 }
118
119 #endif