]>
Commit | Line | Data |
---|---|---|
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 its 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 | EventCounter clicked(m_button, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED); | |
68 | ||
69 | wxUIActionSimulator sim; | |
70 | ||
71 | //We move in slightly to account for window decorations | |
72 | sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10)); | |
73 | wxYield(); | |
74 | ||
75 | sim.MouseClick(); | |
76 | wxYield(); | |
77 | ||
78 | CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount()); | |
79 | CPPUNIT_ASSERT(m_button->GetValue()); | |
80 | clicked.Clear(); | |
81 | ||
82 | sim.MouseClick(); | |
83 | wxYield(); | |
84 | ||
85 | CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount()); | |
86 | CPPUNIT_ASSERT(!m_button->GetValue()); | |
87 | #endif | |
88 | } | |
89 | ||
90 | void ToggleButtonTestCase::Value() | |
91 | { | |
92 | EventCounter clicked(m_button, wxEVT_COMMAND_BUTTON_CLICKED); | |
93 | ||
94 | m_button->SetValue(true); | |
95 | ||
96 | CPPUNIT_ASSERT(m_button->GetValue()); | |
97 | ||
98 | m_button->SetValue(false); | |
99 | ||
100 | CPPUNIT_ASSERT(!m_button->GetValue()); | |
101 | ||
102 | CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() ); | |
103 | } | |
104 | ||
105 | #endif //wxUSE_TOGGLEBTN |