]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/bitmaptogglebuttontest.cpp
reusing existing API
[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 EventCounter clicked(m_button, wxEVT_TOGGLEBUTTON);
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, clicked.GetCount());
89 CPPUNIT_ASSERT(m_button->GetValue());
90
91 clicked.Clear();
92 wxMilliSleep(1000);
93
94 sim.MouseClick();
95 wxYield();
96
97 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
98 CPPUNIT_ASSERT(!m_button->GetValue());
99 #endif // wxUSE_UIACTIONSIMULATOR
100 }
101
102 void BitmapToggleButtonTestCase::Value()
103 {
104 EventCounter clicked(m_button, wxEVT_BUTTON);
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, clicked.GetCount() );
115 }
116
117 #endif // wxHAS_BITMAPTOGGLEBUTTON
118
119 #endif // wxUSE_TOGGLEBTN