]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/togglebuttontest.cpp
make sure the quit item is only shown where appropriate on osx
[wxWidgets.git] / tests / controls / togglebuttontest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/togglebuttontest.cpp
3 // Purpose: wxToggleButton unit test
4 // Author: Steven Lamerton
5 // Created: 2010-07-14
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/tglbtn.h"
25
26 class ToggleButtonTestCase : public CppUnit::TestCase
27 {
28 public:
29 ToggleButtonTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34 private:
35 CPPUNIT_TEST_SUITE( ToggleButtonTestCase );
36 WXUISIM_TEST( Click );
37 CPPUNIT_TEST( Value );
38 CPPUNIT_TEST_SUITE_END();
39
40 void Click();
41 void Value();
42
43 wxToggleButton* m_button;
44
45 DECLARE_NO_COPY_CLASS(ToggleButtonTestCase)
46 };
47
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase );
50
51 // also include in it's own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase, "ToggleButtonTestCase" );
53
54 void ToggleButtonTestCase::setUp()
55 {
56 m_button = new wxToggleButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxToggleButton");
57 }
58
59 void ToggleButtonTestCase::tearDown()
60 {
61 wxDELETE(m_button);
62 }
63
64 void ToggleButtonTestCase::Click()
65 {
66 #if wxUSE_UIACTIONSIMULATOR
67 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
68 wxTestableFrame);
69
70 EventCounter count(m_button, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED);
71
72 wxUIActionSimulator sim;
73
74 //We move in slightly to account for window decorations
75 sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
76 wxYield();
77
78 sim.MouseClick();
79 wxYield();
80
81 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount());
82 CPPUNIT_ASSERT(m_button->GetValue());
83
84 sim.MouseClick();
85 wxYield();
86
87 CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount());
88 CPPUNIT_ASSERT(!m_button->GetValue());
89 #endif
90 }
91
92 void ToggleButtonTestCase::Value()
93 {
94 wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
95 wxTestableFrame);
96
97 EventCounter count(m_button, wxEVT_COMMAND_BUTTON_CLICKED);
98
99 m_button->SetValue(true);
100
101 CPPUNIT_ASSERT(m_button->GetValue());
102
103 m_button->SetValue(false);
104
105 CPPUNIT_ASSERT(!m_button->GetValue());
106
107 CPPUNIT_ASSERT_EQUAL( 0, frame->GetEventCount() );
108 }
109
110 #endif //wxUSE_TOGGLEBTN