2010-08-22 18:16:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/radiobuttontest.cpp
|
|
|
|
// Purpose: wxRadioButton unit test
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Created: 2010-07-30
|
|
|
|
// Copyright: (c) 2010 Steven Lamerton
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#if wxUSE_RADIOBTN
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/radiobut.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/uiaction.h"
|
|
|
|
#include "testableframe.h"
|
|
|
|
|
|
|
|
class RadioButtonTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RadioButtonTestCase() { }
|
|
|
|
|
2018-07-29 05:09:17 -04:00
|
|
|
void setUp() wxOVERRIDE;
|
|
|
|
void tearDown() wxOVERRIDE;
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( RadioButtonTestCase );
|
|
|
|
WXUISIM_TEST( Click );
|
|
|
|
CPPUNIT_TEST( Value );
|
|
|
|
CPPUNIT_TEST( Group );
|
2018-12-26 15:12:01 -05:00
|
|
|
CPPUNIT_TEST( Single );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void Click();
|
|
|
|
void Value();
|
|
|
|
void Group();
|
2018-12-26 15:12:01 -05:00
|
|
|
void Single();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxRadioButton* m_radio;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(RadioButtonTestCase);
|
2010-08-22 18:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioButtonTestCase,
|
|
|
|
"RadioButtonTestCase" );
|
|
|
|
|
|
|
|
void RadioButtonTestCase::setUp()
|
|
|
|
{
|
|
|
|
m_radio = new wxRadioButton(wxTheApp->GetTopWindow(), wxID_ANY,
|
|
|
|
"wxRadioButton");
|
|
|
|
m_radio->Update();
|
|
|
|
m_radio->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioButtonTestCase::tearDown()
|
|
|
|
{
|
|
|
|
wxDELETE(m_radio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioButtonTestCase::Click()
|
|
|
|
{
|
2013-06-12 20:08:27 -04:00
|
|
|
// GTK and OS X do not support selecting a single radio button
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__)
|
2013-04-25 06:11:03 -04:00
|
|
|
EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
2014-09-23 13:43:37 -04:00
|
|
|
wxYield();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseMove(m_radio->GetScreenPosition() + wxPoint(10, 10));
|
|
|
|
sim.MouseClick();
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1, selected.GetCount() );
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioButtonTestCase::Value()
|
|
|
|
{
|
|
|
|
#ifndef __WXGTK__
|
2013-04-25 06:11:03 -04:00
|
|
|
EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_radio->SetValue(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_radio->GetValue());
|
|
|
|
|
|
|
|
m_radio->SetValue(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_radio->GetValue());
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, selected.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioButtonTestCase::Group()
|
|
|
|
{
|
|
|
|
//Add another button to the first group and create another of two buttons
|
|
|
|
wxRadioButton* g1radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxRB_GROUP);
|
|
|
|
|
|
|
|
wxRadioButton* g1radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton");
|
|
|
|
|
|
|
|
wxRadioButton* g2radio0 = new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxRB_GROUP);
|
|
|
|
|
|
|
|
wxRadioButton* g2radio1 = new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton");
|
|
|
|
|
|
|
|
g1radio0->SetValue(true);
|
|
|
|
g2radio0->SetValue(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(g1radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(!g1radio1->GetValue());
|
|
|
|
CPPUNIT_ASSERT(g2radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(!g2radio1->GetValue());
|
|
|
|
|
|
|
|
g1radio1->SetValue(true);
|
|
|
|
g2radio1->SetValue(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!g1radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(g1radio1->GetValue());
|
|
|
|
CPPUNIT_ASSERT(!g2radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(g2radio1->GetValue());
|
|
|
|
|
|
|
|
g1radio0->SetValue(true);
|
|
|
|
g2radio0->SetValue(true);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(g1radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(!g1radio1->GetValue());
|
|
|
|
CPPUNIT_ASSERT(g2radio0->GetValue());
|
|
|
|
CPPUNIT_ASSERT(!g2radio1->GetValue());
|
|
|
|
|
|
|
|
wxDELETE(g1radio0);
|
|
|
|
wxDELETE(g1radio1);
|
|
|
|
wxDELETE(g2radio0);
|
|
|
|
wxDELETE(g2radio1);
|
|
|
|
}
|
|
|
|
|
2018-12-26 15:12:01 -05:00
|
|
|
void RadioButtonTestCase::Single()
|
|
|
|
{
|
|
|
|
//Create a group of 2 buttons, having second button selected
|
|
|
|
wxScopedPtr<wxRadioButton> gradio0(new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxRB_GROUP));
|
|
|
|
|
|
|
|
wxScopedPtr<wxRadioButton> gradio1(new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton"));
|
|
|
|
|
|
|
|
gradio1->SetValue(true);
|
|
|
|
|
|
|
|
//Create a "single" button (by default it will not be selected)
|
|
|
|
wxScopedPtr<wxRadioButton> sradio(new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton",
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxRB_SINGLE));
|
|
|
|
|
|
|
|
//Create a non-grouped button and select it
|
|
|
|
wxScopedPtr<wxRadioButton> ngradio(new wxRadioButton(wxTheApp->GetTopWindow(),
|
|
|
|
wxID_ANY, "wxRadioButton"));
|
|
|
|
|
|
|
|
ngradio->SetValue(true);
|
|
|
|
|
|
|
|
//Select the "single" button
|
|
|
|
sradio->SetValue(true);
|
|
|
|
|
|
|
|
CHECK(gradio1->GetValue());
|
|
|
|
CHECK(ngradio->GetValue());
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif //wxUSE_RADIOBTN
|