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