]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/radiobuttontest.cpp
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / tests / controls / radiobuttontest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/radiobuttontest.cpp
3// Purpose: wxRadioButton unit test
4// Author: Steven Lamerton
5// Created: 2010-07-30
6// RCS-ID: $Id$
7// Copyright: (c) 2010 Steven Lamerton
8///////////////////////////////////////////////////////////////////////////////
9
10#include "testprec.h"
11
12#if wxUSE_RADIOBTN
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/radiobut.h"
21#endif // WX_PRECOMP
22
23#include "wx/uiaction.h"
24#include "testableframe.h"
25
26class RadioButtonTestCase : public CppUnit::TestCase
27{
28public:
29 RadioButtonTestCase() { }
30
31 void setUp();
32 void tearDown();
33
34private:
35 CPPUNIT_TEST_SUITE( RadioButtonTestCase );
36 WXUISIM_TEST( Click );
37 CPPUNIT_TEST( Value );
38 CPPUNIT_TEST( Group );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Click();
42 void Value();
43 void Group();
44
45 wxRadioButton* m_radio;
46
47 DECLARE_NO_COPY_CLASS(RadioButtonTestCase)
48};
49
50// register in the unnamed registry so that these tests are run by default
51CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase );
52
e3778b4d 53// also include in its own registry so that these tests can be run alone
232fdc63
VZ
54CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioButtonTestCase,
55 "RadioButtonTestCase" );
56
57void RadioButtonTestCase::setUp()
58{
59 m_radio = new wxRadioButton(wxTheApp->GetTopWindow(), wxID_ANY,
60 "wxRadioButton");
61 m_radio->Update();
62 m_radio->Refresh();
63}
64
65void RadioButtonTestCase::tearDown()
66{
67 wxDELETE(m_radio);
68}
69
70void RadioButtonTestCase::Click()
71{
72 // GTK does not support selecting a single radio button
73#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__)
744d91d4 74 EventCounter selected(m_radio, wxEVT_COMMAND_RADIOBUTTON_SELECTED);
232fdc63
VZ
75
76 wxUIActionSimulator sim;
77
78 sim.MouseMove(m_radio->GetScreenPosition() + wxPoint(10, 10));
79 sim.MouseClick();
80
81 wxYield();
82
744d91d4 83 CPPUNIT_ASSERT_EQUAL( 1, selected.GetCount() );
232fdc63
VZ
84#endif
85}
86
87void RadioButtonTestCase::Value()
88{
89#ifndef __WXGTK__
744d91d4 90 EventCounter selected(m_radio, wxEVT_COMMAND_RADIOBUTTON_SELECTED);
232fdc63
VZ
91
92 m_radio->SetValue(true);
93
94 CPPUNIT_ASSERT(m_radio->GetValue());
95
96 m_radio->SetValue(false);
97
98 CPPUNIT_ASSERT(!m_radio->GetValue());
99
744d91d4 100 CPPUNIT_ASSERT_EQUAL(0, selected.GetCount());
232fdc63
VZ
101#endif
102}
103
104void RadioButtonTestCase::Group()
105{
106 //Add another button to the first group and create another of two buttons
107 wxRadioButton* g1radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
108 wxID_ANY, "wxRadioButton",
109 wxDefaultPosition,
110 wxDefaultSize, wxRB_GROUP);
111
112 wxRadioButton* g1radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
113 wxID_ANY, "wxRadioButton");
114
115 wxRadioButton* g2radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
116 wxID_ANY, "wxRadioButton",
117 wxDefaultPosition,
118 wxDefaultSize, wxRB_GROUP);
119
120 wxRadioButton* g2radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
121 wxID_ANY, "wxRadioButton");
122
123 g1radio0->SetValue(true);
124 g2radio0->SetValue(true);
125
126 CPPUNIT_ASSERT(g1radio0->GetValue());
127 CPPUNIT_ASSERT(!g1radio1->GetValue());
128 CPPUNIT_ASSERT(g2radio0->GetValue());
129 CPPUNIT_ASSERT(!g2radio1->GetValue());
130
131 g1radio1->SetValue(true);
132 g2radio1->SetValue(true);
133
134 CPPUNIT_ASSERT(!g1radio0->GetValue());
135 CPPUNIT_ASSERT(g1radio1->GetValue());
136 CPPUNIT_ASSERT(!g2radio0->GetValue());
137 CPPUNIT_ASSERT(g2radio1->GetValue());
138
139 g1radio0->SetValue(true);
140 g2radio0->SetValue(true);
141
142 CPPUNIT_ASSERT(g1radio0->GetValue());
143 CPPUNIT_ASSERT(!g1radio1->GetValue());
144 CPPUNIT_ASSERT(g2radio0->GetValue());
145 CPPUNIT_ASSERT(!g2radio1->GetValue());
146
147 wxDELETE(g1radio0);
148 wxDELETE(g1radio1);
149 wxDELETE(g2radio0);
150 wxDELETE(g2radio1);
151}
152
153#endif //wxUSE_RADIOBTN