Get rid of CppUnit boilerplate in wxNumberFormatter unit tests

No real changes, just drop CppUnit::TestCase inheritance and the legacy
macros and use TEST_CASE_METHOD() instead.
This commit is contained in:
Vadim Zeitlin
2021-02-21 16:52:06 +01:00
parent d3f051e328
commit 5ebce65494

View File

@@ -20,72 +20,32 @@
// test class // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class NumFormatterTestCase : public CppUnit::TestCase class NumFormatterTestCase
{ {
public: public:
NumFormatterTestCase() { m_locale = NULL; } NumFormatterTestCase() :
virtual void setUp() wxOVERRIDE
{
// We need to use a locale with known decimal point and which uses the // We need to use a locale with known decimal point and which uses the
// thousands separator for the tests to make sense. // thousands separator for the tests to make sense.
m_locale = new wxLocale(wxLANGUAGE_ENGLISH_UK, m_locale(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT)
wxLOCALE_DONT_LOAD_DEFAULT); {
if ( !m_locale->IsOk() )
tearDown();
} }
virtual void tearDown() wxOVERRIDE protected:
{ bool CanRunTest() const { return m_locale.IsOk(); }
delete m_locale;
m_locale = NULL;
}
private: private:
CPPUNIT_TEST_SUITE( NumFormatterTestCase ); wxLocale m_locale;
CPPUNIT_TEST( LongToString );
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
CPPUNIT_TEST( LongLongToString );
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
CPPUNIT_TEST( DoubleToString );
CPPUNIT_TEST( NoTrailingZeroes );
CPPUNIT_TEST( LongFromString );
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
CPPUNIT_TEST( LongLongFromString );
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
CPPUNIT_TEST( DoubleFromString );
CPPUNIT_TEST_SUITE_END();
void LongToString();
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void LongLongToString();
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void DoubleToString();
void NoTrailingZeroes();
void LongFromString();
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void LongLongFromString();
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void DoubleFromString();
wxLocale *m_locale;
wxDECLARE_NO_COPY_CLASS(NumFormatterTestCase); wxDECLARE_NO_COPY_CLASS(NumFormatterTestCase);
}; };
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( NumFormatterTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( NumFormatterTestCase, "NumFormatterTestCase" );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// tests themselves // tests themselves
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void NumFormatterTestCase::LongToString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::LongToString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString( 1L)); CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString( 1L));
@@ -109,9 +69,9 @@ void NumFormatterTestCase::LongToString()
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void NumFormatterTestCase::LongLongToString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::LongLongToString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString(wxLL( 1))); CPPUNIT_ASSERT_EQUAL( "1", wxNumberFormatter::ToString(wxLL( 1)));
@@ -127,9 +87,9 @@ void NumFormatterTestCase::LongLongToString()
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void NumFormatterTestCase::DoubleToString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::DoubleToString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
CPPUNIT_ASSERT_EQUAL("1.0", wxNumberFormatter::ToString(1., 1)); CPPUNIT_ASSERT_EQUAL("1.0", wxNumberFormatter::ToString(1., 1));
@@ -154,14 +114,14 @@ void NumFormatterTestCase::DoubleToString()
wxNumberFormatter::ToString(-0.02, 1, wxNumberFormatter::Style_None)); wxNumberFormatter::ToString(-0.02, 1, wxNumberFormatter::Style_None));
} }
void NumFormatterTestCase::NoTrailingZeroes() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::NoTrailingZeroes", "[numformatter]")
{ {
WX_ASSERT_FAILS_WITH_ASSERT WX_ASSERT_FAILS_WITH_ASSERT
( (
wxNumberFormatter::ToString(123L, wxNumberFormatter::Style_NoTrailingZeroes) wxNumberFormatter::ToString(123L, wxNumberFormatter::Style_NoTrailingZeroes)
); );
if ( !m_locale ) if ( !CanRunTest() )
return; return;
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
@@ -231,9 +191,9 @@ void NumFormatterTestCase::NoTrailingZeroes()
); );
} }
void NumFormatterTestCase::LongFromString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::LongFromString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
WX_ASSERT_FAILS_WITH_ASSERT WX_ASSERT_FAILS_WITH_ASSERT
@@ -267,9 +227,9 @@ void NumFormatterTestCase::LongFromString()
#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void NumFormatterTestCase::LongLongFromString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::LongLongFromString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
WX_ASSERT_FAILS_WITH_ASSERT WX_ASSERT_FAILS_WITH_ASSERT
@@ -303,9 +263,9 @@ void NumFormatterTestCase::LongLongFromString()
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
void NumFormatterTestCase::DoubleFromString() TEST_CASE_METHOD(NumFormatterTestCase, "NumFormatter::DoubleFromString", "[numformatter]")
{ {
if ( !m_locale ) if ( !CanRunTest() )
return; return;
WX_ASSERT_FAILS_WITH_ASSERT WX_ASSERT_FAILS_WITH_ASSERT