Files
wxWidgets/tests/controls/radioboxtest.cpp
T
Vadim Zeitlin 7c2031620d Remove CppUnit boilerplate from wxRadioBox unit test
Define a simple fixture instead of inheriting from CppUnit::TestCase.

No real changes, just make the code shorter, less redundant and make it
simpler to run individual tests.
2022-08-29 18:32:52 +02:00

196 lines
5.5 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Name: tests/controls/radioboxtest.cpp
// Purpose: wxRadioBox unit test
// Author: Steven Lamerton
// Created: 2010-07-14
// Copyright: (c) 2010 Steven Lamerton
///////////////////////////////////////////////////////////////////////////////
#include "testprec.h"
#if wxUSE_RADIOBOX
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/radiobox.h"
#endif // WX_PRECOMP
#include "wx/tooltip.h"
class RadioBoxTestCase
{
protected:
RadioBoxTestCase();
~RadioBoxTestCase();
wxRadioBox* m_radio;
wxDECLARE_NO_COPY_CLASS(RadioBoxTestCase);
};
RadioBoxTestCase::RadioBoxTestCase()
{
wxArrayString choices;
choices.push_back("item 0");
choices.push_back("item 1");
choices.push_back("item 2");
m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
wxDefaultPosition, wxDefaultSize, choices);
}
RadioBoxTestCase::~RadioBoxTestCase()
{
wxTheApp->GetTopWindow()->DestroyChildren();
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::FindString", "[radiobox][find]")
{
CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("not here"));
CPPUNIT_ASSERT_EQUAL(1, m_radio->FindString("item 1"));
CPPUNIT_ASSERT_EQUAL(2, m_radio->FindString("ITEM 2"));
CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("ITEM 2", true));
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::RowColCount", "[radiobox]")
{
#ifndef __WXGTK__
wxArrayString choices;
choices.push_back("item 0");
choices.push_back("item 1");
choices.push_back("item 2");
m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
wxDefaultPosition, wxDefaultSize, choices, 2);
CPPUNIT_ASSERT_EQUAL(2, m_radio->GetColumnCount());
CPPUNIT_ASSERT_EQUAL(2, m_radio->GetRowCount());
m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
wxDefaultPosition, wxDefaultSize, choices, 1,
wxRA_SPECIFY_ROWS);
CPPUNIT_ASSERT_EQUAL(3, m_radio->GetColumnCount());
CPPUNIT_ASSERT_EQUAL(1, m_radio->GetRowCount());
#endif
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::Enable", "[radiobox][enable]")
{
#ifndef __WXOSX__
m_radio->Enable(false);
CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
m_radio->Enable(1, true);
CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
CPPUNIT_ASSERT(!m_radio->IsItemEnabled(2));
m_radio->Enable(true);
CPPUNIT_ASSERT(m_radio->IsItemEnabled(0));
CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
m_radio->Enable(0, false);
CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
#endif
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::Show", "[radiobox][show]")
{
m_radio->Show(false);
CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
m_radio->Show(1, true);
CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
CPPUNIT_ASSERT(m_radio->IsItemShown(1));
CPPUNIT_ASSERT(!m_radio->IsItemShown(2));
m_radio->Show(true);
CPPUNIT_ASSERT(m_radio->IsItemShown(0));
CPPUNIT_ASSERT(m_radio->IsItemShown(1));
CPPUNIT_ASSERT(m_radio->IsItemShown(2));
m_radio->Show(0, false);
CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
CPPUNIT_ASSERT(m_radio->IsItemShown(1));
CPPUNIT_ASSERT(m_radio->IsItemShown(2));
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::HelpText", "[radiobox][help]")
{
CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(0));
m_radio->SetItemHelpText(1, "Item 1 help");
CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemHelpText(1));
m_radio->SetItemHelpText(1, "");
CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(1));
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::ToolTip", "[radiobox][tooltip]")
{
#if defined (__WXMSW__) || defined(__WXGTK__)
//GetItemToolTip returns null if there is no tooltip set
CPPUNIT_ASSERT(!m_radio->GetItemToolTip(0));
m_radio->SetItemToolTip(1, "Item 1 help");
CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemToolTip(1)->GetTip());
m_radio->SetItemToolTip(1, "");
//However if we set a blank tip this does count as a tooltip
CPPUNIT_ASSERT(!m_radio->GetItemToolTip(1));
#endif
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::Selection", "[radiobox][selection]")
{
//Until other item containers the first item is selected by default
CPPUNIT_ASSERT_EQUAL(0, m_radio->GetSelection());
CPPUNIT_ASSERT_EQUAL("item 0", m_radio->GetStringSelection());
m_radio->SetSelection(1);
CPPUNIT_ASSERT_EQUAL(1, m_radio->GetSelection());
CPPUNIT_ASSERT_EQUAL("item 1", m_radio->GetStringSelection());
m_radio->SetStringSelection("item 2");
CPPUNIT_ASSERT_EQUAL(2, m_radio->GetSelection());
CPPUNIT_ASSERT_EQUAL("item 2", m_radio->GetStringSelection());
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::Count", "[radiobox]")
{
//A trivial test for the item count as items can neither
//be added or removed
CPPUNIT_ASSERT_EQUAL(3, m_radio->GetCount());
CPPUNIT_ASSERT(!m_radio->IsEmpty());
}
TEST_CASE_METHOD(RadioBoxTestCase, "RadioBox::SetString", "[radiobox]")
{
m_radio->SetString(0, "new item 0");
m_radio->SetString(2, "");
CPPUNIT_ASSERT_EQUAL("new item 0", m_radio->GetString(0));
CPPUNIT_ASSERT_EQUAL("", m_radio->GetString(2));
}
#endif // wxUSE_RADIOBOX