]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/togglebuttontest.cpp
XRC spec: relax requirements on some commonly omitted properties.
[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 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #if wxUSE_TOGGLEBTN
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #endif // WX_PRECOMP
20
21 #include "testableframe.h"
22 #include "wx/uiaction.h"
23 #include "wx/tglbtn.h"
24
25 class ToggleButtonTestCase : public CppUnit::TestCase
26 {
27 public:
28 ToggleButtonTestCase() { }
29
30 void setUp();
31 void tearDown();
32
33 private:
34 CPPUNIT_TEST_SUITE( ToggleButtonTestCase );
35 WXUISIM_TEST( Click );
36 CPPUNIT_TEST( Value );
37 CPPUNIT_TEST_SUITE_END();
38
39 void Click();
40 void Value();
41
42 wxToggleButton* m_button;
43
44 DECLARE_NO_COPY_CLASS(ToggleButtonTestCase)
45 };
46
47 // register in the unnamed registry so that these tests are run by default
48 CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase );
49
50 // also include in its own registry so that these tests can be run alone
51 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase, "ToggleButtonTestCase" );
52
53 void ToggleButtonTestCase::setUp()
54 {
55 m_button = new wxToggleButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxToggleButton");
56 }
57
58 void ToggleButtonTestCase::tearDown()
59 {
60 wxDELETE(m_button);
61 }
62
63 void ToggleButtonTestCase::Click()
64 {
65 #if wxUSE_UIACTIONSIMULATOR
66 EventCounter clicked(m_button, wxEVT_TOGGLEBUTTON);
67
68 wxUIActionSimulator sim;
69
70 //We move in slightly to account for window decorations
71 sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
72 wxYield();
73
74 sim.MouseClick();
75 wxYield();
76
77 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
78 CPPUNIT_ASSERT(m_button->GetValue());
79 clicked.Clear();
80
81 sim.MouseClick();
82 wxYield();
83
84 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
85 CPPUNIT_ASSERT(!m_button->GetValue());
86 #endif
87 }
88
89 void ToggleButtonTestCase::Value()
90 {
91 EventCounter clicked(m_button, wxEVT_BUTTON);
92
93 m_button->SetValue(true);
94
95 CPPUNIT_ASSERT(m_button->GetValue());
96
97 m_button->SetValue(false);
98
99 CPPUNIT_ASSERT(!m_button->GetValue());
100
101 CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
102 }
103
104 #endif //wxUSE_TOGGLEBTN