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