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