Remove CppUnit boilerplate and macros from ellipsization tests

This commit is contained in:
Maarten Bent
2019-08-14 20:53:02 +02:00
parent b245e4a571
commit 533d82655f

View File

@@ -23,34 +23,14 @@
// test class // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class EllipsizationTestCase : public CppUnit::TestCase class EllipsizationTestCase
{ {
public: public:
EllipsizationTestCase() { } EllipsizationTestCase() { }
private:
CPPUNIT_TEST_SUITE( EllipsizationTestCase );
CPPUNIT_TEST( NormalCase );
CPPUNIT_TEST( EnoughSpace );
CPPUNIT_TEST( VeryLittleSpace );
CPPUNIT_TEST( HasThreeDots );
CPPUNIT_TEST_SUITE_END();
void NormalCase();
void EnoughSpace();
void VeryLittleSpace();
void HasThreeDots();
wxDECLARE_NO_COPY_CLASS(EllipsizationTestCase);
}; };
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( EllipsizationTestCase );
// also include in its own registry so that these tests can be run alone TEST_CASE_METHOD(EllipsizationTestCase, "Ellipsization::NormalCase", "[ellipsization]")
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EllipsizationTestCase, "EllipsizationTestCase" );
void EllipsizationTestCase::NormalCase()
{ {
wxMemoryDC dc; wxMemoryDC dc;
@@ -137,7 +117,7 @@ void EllipsizationTestCase::NormalCase()
} }
void EllipsizationTestCase::EnoughSpace() TEST_CASE_METHOD(EllipsizationTestCase, "Ellipsization::EnoughSpace", "[ellipsization]")
{ {
// No ellipsization should occur if there's plenty of space. // No ellipsization should occur if there's plenty of space.
@@ -146,16 +126,13 @@ void EllipsizationTestCase::EnoughSpace()
wxString testString("some label"); wxString testString("some label");
const int width = dc.GetTextExtent(testString).GetWidth() + 50; const int width = dc.GetTextExtent(testString).GetWidth() + 50;
CPPUNIT_ASSERT_EQUAL(testString, CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width) == testString );
wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width)); CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width) == testString );
CPPUNIT_ASSERT_EQUAL(testString, CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width) == testString );
wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width));
CPPUNIT_ASSERT_EQUAL(testString,
wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width));
} }
void EllipsizationTestCase::VeryLittleSpace() TEST_CASE_METHOD(EllipsizationTestCase, "Ellipsization::VeryLittleSpace", "[ellipsization]")
{ {
// If there's not enough space, the shortened label should still contain "..." and one character // If there's not enough space, the shortened label should still contain "..." and one character
@@ -163,30 +140,26 @@ void EllipsizationTestCase::VeryLittleSpace()
const int width = dc.GetTextExtent("s...").GetWidth(); const int width = dc.GetTextExtent("s...").GetWidth();
CPPUNIT_ASSERT_EQUAL("...l", CHECK( wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, width) == "...l" );
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_START, width)); CHECK( wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, width) == "s..." );
CPPUNIT_ASSERT_EQUAL("s...", CHECK( wxControl::Ellipsize("some label1", dc, wxELLIPSIZE_MIDDLE, width) == "s..." );
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_MIDDLE, width)); CHECK( wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, width) == "s..." );
CPPUNIT_ASSERT_EQUAL("s...",
wxControl::Ellipsize("some label1", dc, wxELLIPSIZE_MIDDLE, width));
CPPUNIT_ASSERT_EQUAL("s...",
wxControl::Ellipsize("some label", dc, wxELLIPSIZE_END, width));
} }
void EllipsizationTestCase::HasThreeDots() TEST_CASE_METHOD(EllipsizationTestCase, "Ellipsization::HasThreeDots", "[ellipsization]")
{ {
wxMemoryDC dc; wxMemoryDC dc;
wxString testString("some longer text"); wxString testString("some longer text");
const int width = dc.GetTextExtent(testString).GetWidth() - 5; const int width = dc.GetTextExtent(testString).GetWidth() - 5;
CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).StartsWith("...") ); CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).StartsWith("...") );
CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).EndsWith("...") ); CHECK( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_START, width).EndsWith("...") );
CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width).EndsWith("...") ); CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_END, width).EndsWith("...") );
CPPUNIT_ASSERT( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).Contains("...") ); CHECK( wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).Contains("...") );
CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).StartsWith("...") ); CHECK( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).StartsWith("...") );
CPPUNIT_ASSERT( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).EndsWith("...") ); CHECK( !wxControl::Ellipsize(testString, dc, wxELLIPSIZE_MIDDLE, width).EndsWith("...") );
} }