Rewrite wxControl label unit test without CppUnit macros
Also remove the macros used in the test to perform the same tests for wxStaticText and wxCheckBox and use a helper function instead, making the code more clear and extensible. No real changes.
This commit is contained in:
@@ -20,83 +20,22 @@
|
|||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/control.h"
|
|
||||||
#include "wx/stattext.h"
|
|
||||||
#include "wx/checkbox.h"
|
#include "wx/checkbox.h"
|
||||||
|
#include "wx/control.h"
|
||||||
|
#include "wx/scopedptr.h"
|
||||||
|
#include "wx/stattext.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
namespace
|
||||||
// test class
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class LabelTestCase : public CppUnit::TestCase
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
LabelTestCase() { }
|
|
||||||
|
|
||||||
virtual void setUp() wxOVERRIDE;
|
const char* const ORIGINAL_LABEL = "origin label";
|
||||||
virtual void tearDown() wxOVERRIDE;
|
|
||||||
|
|
||||||
private:
|
// The actual testing function. It will change the label of the provided
|
||||||
CPPUNIT_TEST_SUITE( LabelTestCase );
|
// control, which is assumed to be ORIGINAL_LABEL initially.
|
||||||
CPPUNIT_TEST( GetLabel );
|
void DoTestLabel(wxControl* c)
|
||||||
CPPUNIT_TEST( GetLabelText );
|
|
||||||
CPPUNIT_TEST( Statics );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void GetLabel();
|
|
||||||
void GetLabelText();
|
|
||||||
void Statics();
|
|
||||||
|
|
||||||
wxStaticText *m_st;
|
|
||||||
|
|
||||||
// we cannot test wxControl directly (it's abstract) so we rather test wxCheckBox
|
|
||||||
wxCheckBox *m_cb;
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(LabelTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( LabelTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LabelTestCase, "LabelTestCase" );
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// test initialization
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#define ORIGINAL_LABEL "original label"
|
|
||||||
|
|
||||||
void LabelTestCase::setUp()
|
|
||||||
{
|
{
|
||||||
m_st = new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);
|
CHECK( c->GetLabel() == ORIGINAL_LABEL );
|
||||||
|
|
||||||
m_cb = new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_st->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( ORIGINAL_LABEL, m_cb->GetLabel() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void LabelTestCase::tearDown()
|
|
||||||
{
|
|
||||||
wxDELETE(m_st);
|
|
||||||
wxDELETE(m_cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// the tests themselves
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#define SET_LABEL(str) \
|
|
||||||
m_st->SetLabel(str); \
|
|
||||||
m_cb->SetLabel(str);
|
|
||||||
|
|
||||||
#define SET_LABEL_TEXT(str) \
|
|
||||||
m_st->SetLabelText(str); \
|
|
||||||
m_cb->SetLabelText(str);
|
|
||||||
|
|
||||||
void LabelTestCase::GetLabel()
|
|
||||||
{
|
|
||||||
const wxString testLabelArray[] = {
|
const wxString testLabelArray[] = {
|
||||||
"label without mnemonics and markup",
|
"label without mnemonics and markup",
|
||||||
"label with &mnemonic",
|
"label with &mnemonic",
|
||||||
@@ -104,92 +43,75 @@ void LabelTestCase::GetLabel()
|
|||||||
"label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",
|
"label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",
|
||||||
};
|
};
|
||||||
|
|
||||||
// test calls to SetLabel() and then to GetLabel()
|
|
||||||
|
|
||||||
for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ )
|
for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ )
|
||||||
{
|
{
|
||||||
SET_LABEL(testLabelArray[s]);
|
const wxString& l = testLabelArray[s];
|
||||||
|
|
||||||
// GetLabel() should always return the string passed to SetLabel()
|
// GetLabel() should always return the string passed to SetLabel()
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabel() );
|
c->SetLabel(l);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabel() );
|
CHECK( c->GetLabel() == l );
|
||||||
|
|
||||||
|
// GetLabelText() should always return the string passed to SetLabelText()
|
||||||
|
c->SetLabelText(l);
|
||||||
|
CHECK( c->GetLabelText() == l );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// test calls to SetLabelText() and then to GetLabel()
|
// test calls to SetLabelText() and then to GetLabel()
|
||||||
|
|
||||||
const wxString& testLabel = "label without mnemonics and markup";
|
wxString testLabel = "label without mnemonics and markup";
|
||||||
SET_LABEL_TEXT(testLabel);
|
c->SetLabelText(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabel() );
|
CHECK( c->GetLabel() == testLabel );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabel() );
|
|
||||||
|
|
||||||
const wxString& testLabel2 = "label with &mnemonic";
|
c->SetLabelText("label with &mnemonic");
|
||||||
const wxString& testLabelText2 = "label with &&mnemonic";
|
CHECK( c->GetLabel() == "label with &&mnemonic" );
|
||||||
SET_LABEL_TEXT(testLabel2);
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabel() );
|
|
||||||
|
|
||||||
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
testLabel = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
||||||
SET_LABEL_TEXT(testLabel3);
|
c->SetLabelText(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabel() );
|
CHECK( c->GetLabel() == testLabel );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabel() );
|
|
||||||
|
|
||||||
const wxString& testLabel4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
|
c->SetLabelText("label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic");
|
||||||
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic";
|
CHECK( c->GetLabel() == "label with <span foreground='blue'>some</span> <b>markup</b> and &&mnemonic" );
|
||||||
SET_LABEL_TEXT(testLabel4);
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabel() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabel() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void LabelTestCase::GetLabelText()
|
|
||||||
{
|
|
||||||
// test calls to SetLabel() and then to GetLabelText()
|
// test calls to SetLabel() and then to GetLabelText()
|
||||||
|
|
||||||
const wxString& testLabel = "label without mnemonics and markup";
|
testLabel = "label without mnemonics and markup";
|
||||||
SET_LABEL(testLabel);
|
c->SetLabel(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_st->GetLabelText() );
|
CHECK( c->GetLabelText() == testLabel );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel, m_cb->GetLabelText() );
|
|
||||||
|
|
||||||
const wxString& testLabel2 = "label with &mnemonic";
|
c->SetLabel("label with &mnemonic");
|
||||||
const wxString& testLabelText2 = "label with mnemonic";
|
CHECK( c->GetLabelText() == "label with mnemonic" );
|
||||||
SET_LABEL(testLabel2);
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_st->GetLabelText() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText2, m_cb->GetLabelText() );
|
|
||||||
|
|
||||||
const wxString& testLabel3 = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
testLabel = "label with <span foreground='blue'>some</span> <b>markup</b>";
|
||||||
SET_LABEL(testLabel3);
|
c->SetLabel(testLabel);
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_st->GetLabelText() );
|
CHECK( c->GetLabelText() == testLabel );
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabel3, m_cb->GetLabelText() );
|
|
||||||
|
|
||||||
const wxString& testLabel4 = "label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic";
|
c->SetLabel("label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic");
|
||||||
const wxString& testLabelText4 = "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic";
|
CHECK( c->GetLabelText() == "label with <span foreground='blue'>some</span> <b>markup</b> and mnemonic");
|
||||||
SET_LABEL(testLabel4);
|
}
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_st->GetLabelText() );
|
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelText4, m_cb->GetLabelText() );
|
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
const wxString testLabelArray[] = {
|
TEST_CASE("wxControl::Label", "[wxControl][label]")
|
||||||
"label without mnemonics and markup",
|
{
|
||||||
"label with &mnemonic",
|
SECTION("wxStaticText")
|
||||||
"label with <span foreground='blue'>some</span> <b>markup</b>",
|
|
||||||
"label with <span foreground='blue'>some</span> <b>markup</b> and &mnemonic",
|
|
||||||
};
|
|
||||||
|
|
||||||
// test calls to SetLabelText() and then to GetLabelText()
|
|
||||||
|
|
||||||
for ( unsigned int s = 0; s < WXSIZEOF(testLabelArray); s++ )
|
|
||||||
{
|
{
|
||||||
SET_LABEL_TEXT(testLabelArray[s]);
|
const wxScopedPtr<wxStaticText>
|
||||||
|
st(new wxStaticText(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL));
|
||||||
|
DoTestLabel(st.get());
|
||||||
|
}
|
||||||
|
|
||||||
// GetLabelText() should always return the string passed to SetLabelText()
|
SECTION("wxCheckBox")
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_st->GetLabelText() );
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL( testLabelArray[s], m_cb->GetLabelText() );
|
const wxScopedPtr<wxCheckBox>
|
||||||
|
cb(new wxCheckBox(wxTheApp->GetTopWindow(), wxID_ANY, ORIGINAL_LABEL));
|
||||||
|
DoTestLabel(cb.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LabelTestCase::Statics()
|
TEST_CASE("wxControl::RemoveMnemonics", "[wxControl][label][mnemonics]")
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL( "mnemonic", wxControl::RemoveMnemonics("&mnemonic") );
|
CHECK( "mnemonic" == wxControl::RemoveMnemonics("&mnemonic") );
|
||||||
CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&mnemonic") );
|
CHECK( "&mnemonic" == wxControl::RemoveMnemonics("&&mnemonic") );
|
||||||
CPPUNIT_ASSERT_EQUAL( "&mnemonic", wxControl::RemoveMnemonics("&&&mnemonic") );
|
CHECK( "&mnemonic" == wxControl::RemoveMnemonics("&&&mnemonic") );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user