1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
///////////////////////////////////////////////////////////////////////////////
// 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() { }
void setUp();
void tearDown();
private:
CPPUNIT_TEST_SUITE( RadioButtonTestCase );
WXUISIM_TEST( Click );
CPPUNIT_TEST( Value );
CPPUNIT_TEST( Group );
CPPUNIT_TEST_SUITE_END();
void Click();
void Value();
void Group();
wxRadioButton* m_radio;
DECLARE_NO_COPY_CLASS(RadioButtonTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( RadioButtonTestCase );
// also include in its own registry so that these tests can be run alone
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()
{
// GTK and OS X do not support selecting a single radio button
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__)
EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
wxUIActionSimulator sim;
sim.MouseMove(m_radio->GetScreenPosition() + wxPoint(10, 10));
sim.MouseClick();
wxYield();
CPPUNIT_ASSERT_EQUAL( 1, selected.GetCount() );
#endif
}
void RadioButtonTestCase::Value()
{
#ifndef __WXGTK__
EventCounter selected(m_radio, wxEVT_RADIOBUTTON);
m_radio->SetValue(true);
CPPUNIT_ASSERT(m_radio->GetValue());
m_radio->SetValue(false);
CPPUNIT_ASSERT(!m_radio->GetValue());
CPPUNIT_ASSERT_EQUAL(0, selected.GetCount());
#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);
}
#endif //wxUSE_RADIOBTN
|