]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/togglebuttontest.cpp
Don't follow symlinks in wxFileName::Rmdir(wxPATH_RMDIR_RECURSIVE).
[wxWidgets.git] / tests / controls / togglebuttontest.cpp
CommitLineData
232fdc63
VZ
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
26class ToggleButtonTestCase : public CppUnit::TestCase
27{
28public:
29 ToggleButtonTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
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
49CPPUNIT_TEST_SUITE_REGISTRATION( ToggleButtonTestCase );
50
e3778b4d 51// also include in its own registry so that these tests can be run alone
232fdc63
VZ
52CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ToggleButtonTestCase, "ToggleButtonTestCase" );
53
54void ToggleButtonTestCase::setUp()
55{
56 m_button = new wxToggleButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxToggleButton");
57}
58
59void ToggleButtonTestCase::tearDown()
60{
61 wxDELETE(m_button);
62}
63
64void ToggleButtonTestCase::Click()
65{
66#if wxUSE_UIACTIONSIMULATOR
744d91d4 67 EventCounter clicked(m_button, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED);
232fdc63
VZ
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
744d91d4 78 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63 79 CPPUNIT_ASSERT(m_button->GetValue());
744d91d4 80 clicked.Clear();
232fdc63
VZ
81
82 sim.MouseClick();
83 wxYield();
84
744d91d4 85 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63
VZ
86 CPPUNIT_ASSERT(!m_button->GetValue());
87#endif
88}
89
90void ToggleButtonTestCase::Value()
91{
744d91d4 92 EventCounter clicked(m_button, wxEVT_COMMAND_BUTTON_CLICKED);
232fdc63
VZ
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
744d91d4 102 CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
232fdc63
VZ
103}
104
105#endif //wxUSE_TOGGLEBTN