Remove CppUnit boilerplate from wxFont unit test

No real changes, just remove the test case class which is not at all
necessary in this unit test.
This commit is contained in:
Vadim Zeitlin
2018-09-05 23:05:10 +02:00
parent 76aad86cfb
commit 7cc016b5fa

View File

@@ -26,51 +26,26 @@
#include "asserthelper.h" #include "asserthelper.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class // local helpers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class FontTestCase : public CppUnit::TestCase // Returns a point to an array of fonts and fills the output parameter with the
// number of elements in this array.
static const wxFont *GetTestFonts(unsigned& numFonts)
{ {
public: static const wxFont testfonts[] =
FontTestCase() { }
private:
CPPUNIT_TEST_SUITE( FontTestCase );
CPPUNIT_TEST( Construct );
CPPUNIT_TEST( GetSet );
CPPUNIT_TEST( NativeFontInfo );
CPPUNIT_TEST( NativeFontInfoUserDesc );
CPPUNIT_TEST_SUITE_END();
void Construct();
void GetSet();
void NativeFontInfo();
void NativeFontInfoUserDesc();
static const wxFont *GetTestFonts(unsigned& numFonts)
{ {
static const wxFont testfonts[] = *wxNORMAL_FONT,
{ *wxSMALL_FONT,
*wxNORMAL_FONT, *wxITALIC_FONT,
*wxSMALL_FONT, *wxSWISS_FONT,
*wxITALIC_FONT, wxFont(5, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)
*wxSWISS_FONT, };
wxFont(5, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)
};
numFonts = WXSIZEOF(testfonts); numFonts = WXSIZEOF(testfonts);
return testfonts; return testfonts;
} }
wxDECLARE_NO_COPY_CLASS(FontTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( FontTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FontTestCase, "FontTestCase" );
wxString DumpFont(const wxFont *font) wxString DumpFont(const wxFont *font)
{ {
@@ -94,15 +69,19 @@ wxString DumpFont(const wxFont *font)
return s; return s;
} }
void FontTestCase::Construct() // ----------------------------------------------------------------------------
// the tests
// ----------------------------------------------------------------------------
TEST_CASE("wxFont::Construct", "[font][ctor]")
{ {
// The main purpose of this test is to verify that the font ctors below // The main purpose of this test is to verify that the font ctors below
// compile because it's easy to introduce ambiguities due to the number of // compile because it's easy to introduce ambiguities due to the number of
// overloaded wxFont ctors. // overloaded wxFont ctors.
CPPUNIT_ASSERT( wxFont(10, wxFONTFAMILY_DEFAULT, CHECK( wxFont(10, wxFONTFAMILY_DEFAULT,
wxFONTSTYLE_NORMAL, wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL).IsOk() ); wxFONTWEIGHT_NORMAL).IsOk() );
#if WXWIN_COMPATIBILITY_3_0 #if WXWIN_COMPATIBILITY_3_0
// Disable the warning about deprecated wxNORMAL as we use it here // Disable the warning about deprecated wxNORMAL as we use it here
@@ -116,7 +95,7 @@ void FontTestCase::Construct()
// Tests relying on the soon-to-be-deprecated ctor taking ints and not // Tests relying on the soon-to-be-deprecated ctor taking ints and not
// wxFontXXX enum elements. // wxFontXXX enum elements.
CPPUNIT_ASSERT( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() ); CHECK( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() );
wxGCC_WARNING_RESTORE(deprecated-declarations) wxGCC_WARNING_RESTORE(deprecated-declarations)
@@ -126,7 +105,7 @@ void FontTestCase::Construct()
#endif // WXWIN_COMPATIBILITY_3_0 #endif // WXWIN_COMPATIBILITY_3_0
} }
void FontTestCase::GetSet() TEST_CASE("wxFont::GetSet", "[font][getters]")
{ {
unsigned numFonts; unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts); const wxFont *pf = GetTestFonts(numFonts);
@@ -135,12 +114,12 @@ void FontTestCase::GetSet()
wxFont test(*pf++); wxFont test(*pf++);
// remember: getters can only be called when wxFont::IsOk() == true // remember: getters can only be called when wxFont::IsOk() == true
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
// test Get/SetFaceName() // test Get/SetFaceName()
CPPUNIT_ASSERT( !test.SetFaceName("a dummy face name") ); CHECK( !test.SetFaceName("a dummy face name") );
CPPUNIT_ASSERT( !test.IsOk() ); CHECK( !test.IsOk() );
// if the call to SetFaceName() below fails on your system/port, // if the call to SetFaceName() below fails on your system/port,
// consider adding another branch to this #if // consider adding another branch to this #if
@@ -157,41 +136,41 @@ void FontTestCase::GetSet()
"available on this system)", knownGoodFaceName, n), "available on this system)", knownGoodFaceName, n),
test.SetFaceName(knownGoodFaceName) test.SetFaceName(knownGoodFaceName)
); );
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
// test Get/SetFamily() // test Get/SetFamily()
test.SetFamily( wxFONTFAMILY_ROMAN ); test.SetFamily( wxFONTFAMILY_ROMAN );
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
// note that there is always the possibility that GetFamily() returns // note that there is always the possibility that GetFamily() returns
// wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we // wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we
// consider it as a valid return value // consider it as a valid return value
const wxFontFamily family = test.GetFamily(); const wxFontFamily family = test.GetFamily();
if ( family != wxFONTFAMILY_DEFAULT ) if ( family != wxFONTFAMILY_DEFAULT )
CPPUNIT_ASSERT_EQUAL( wxFONTFAMILY_ROMAN, family ); CHECK( wxFONTFAMILY_ROMAN == family );
// test Get/SetEncoding() // test Get/SetEncoding()
//test.SetEncoding( wxFONTENCODING_KOI8 ); //test.SetEncoding( wxFONTENCODING_KOI8 );
//CPPUNIT_ASSERT( test.IsOk() ); //CHECK( test.IsOk() );
//CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() ); //CHECK( wxFONTENCODING_KOI8 == test.GetEncoding() );
// test Get/SetPointSize() // test Get/SetPointSize()
test.SetPointSize(30); test.SetPointSize(30);
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( 30, test.GetPointSize() ); CHECK( 30 == test.GetPointSize() );
// test Get/SetPixelSize() // test Get/SetPixelSize()
test.SetPixelSize(wxSize(0,30)); test.SetPixelSize(wxSize(0,30));
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
CPPUNIT_ASSERT( test.GetPixelSize().GetHeight() <= 30 ); CHECK( test.GetPixelSize().GetHeight() <= 30 );
// NOTE: the match found by SetPixelSize() may be not 100% precise; it // NOTE: the match found by SetPixelSize() may be not 100% precise; it
// only grants that a font smaller than the required height will // only grants that a font smaller than the required height will
// be selected // be selected
@@ -200,43 +179,43 @@ void FontTestCase::GetSet()
// test Get/SetStyle() // test Get/SetStyle()
test.SetStyle(wxFONTSTYLE_SLANT); test.SetStyle(wxFONTSTYLE_SLANT);
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
#ifdef __WXMSW__ #ifdef __WXMSW__
// on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC, so accept the latter // on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC, so accept the latter
// as a valid value too. // as a valid value too.
if ( test.GetStyle() != wxFONTSTYLE_ITALIC ) if ( test.GetStyle() != wxFONTSTYLE_ITALIC )
#endif #endif
CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_SLANT, test.GetStyle() ); CHECK( wxFONTSTYLE_SLANT == test.GetStyle() );
// test Get/SetUnderlined() // test Get/SetUnderlined()
test.SetUnderlined(true); test.SetUnderlined(true);
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( true, test.GetUnderlined() ); CHECK( test.GetUnderlined() );
const wxFont fontBase = test.GetBaseFont(); const wxFont fontBase = test.GetBaseFont();
CPPUNIT_ASSERT( fontBase.IsOk() ); CHECK( fontBase.IsOk() );
CPPUNIT_ASSERT( !fontBase.GetUnderlined() ); CHECK( !fontBase.GetUnderlined() );
CPPUNIT_ASSERT( !fontBase.GetStrikethrough() ); CHECK( !fontBase.GetStrikethrough() );
CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_NORMAL, fontBase.GetWeight() ); CHECK( wxFONTWEIGHT_NORMAL == fontBase.GetWeight() );
CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_NORMAL, fontBase.GetStyle() ); CHECK( wxFONTSTYLE_NORMAL == fontBase.GetStyle() );
// test Get/SetStrikethrough() // test Get/SetStrikethrough()
test.SetStrikethrough(true); test.SetStrikethrough(true);
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( true, test.GetStrikethrough() ); CHECK( test.GetStrikethrough() );
// test Get/SetWeight() // test Get/SetWeight()
test.SetWeight(wxFONTWEIGHT_BOLD); test.SetWeight(wxFONTWEIGHT_BOLD);
CPPUNIT_ASSERT( test.IsOk() ); CHECK( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_BOLD, test.GetWeight() ); CHECK( wxFONTWEIGHT_BOLD == test.GetWeight() );
} }
} }
void FontTestCase::NativeFontInfo() TEST_CASE("wxFont::NativeFontInfo", "[font][fontinfo]")
{ {
unsigned numFonts; unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts); const wxFont *pf = GetTestFonts(numFonts);
@@ -245,12 +224,12 @@ void FontTestCase::NativeFontInfo()
wxFont test(*pf++); wxFont test(*pf++);
const wxString& nid = test.GetNativeFontInfoDesc(); const wxString& nid = test.GetNativeFontInfoDesc();
CPPUNIT_ASSERT( !nid.empty() ); CHECK( !nid.empty() );
// documented to be never empty // documented to be never empty
wxFont temp; wxFont temp;
CPPUNIT_ASSERT( temp.SetNativeFontInfo(nid) ); CHECK( temp.SetNativeFontInfo(nid) );
CPPUNIT_ASSERT( temp.IsOk() ); CHECK( temp.IsOk() );
WX_ASSERT_MESSAGE( WX_ASSERT_MESSAGE(
("Test #%u failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \ ("Test #%u failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
n, DumpFont(&test), DumpFont(&temp)), n, DumpFont(&test), DumpFont(&temp)),
@@ -259,14 +238,14 @@ void FontTestCase::NativeFontInfo()
// test that clearly invalid font info strings do not work // test that clearly invalid font info strings do not work
wxFont font; wxFont font;
CPPUNIT_ASSERT( !font.SetNativeFontInfo("") ); CHECK( !font.SetNativeFontInfo("") );
// pango_font_description_from_string() used by wxFont in wxGTK and wxX11 // pango_font_description_from_string() used by wxFont in wxGTK and wxX11
// never returns an error at all so this assertion fails there -- and as it // never returns an error at all so this assertion fails there -- and as it
// doesn't seem to be possible to do anything about it maybe we should // doesn't seem to be possible to do anything about it maybe we should
// change wxMSW and other ports to also accept any strings? // change wxMSW and other ports to also accept any strings?
#if !defined(__WXGTK__) && !defined(__WXX11__) #if !defined(__WXGTK__) && !defined(__WXX11__)
CPPUNIT_ASSERT( !font.SetNativeFontInfo("bloordyblop") ); CHECK( !font.SetNativeFontInfo("bloordyblop") );
#endif #endif
// Pango font description doesn't have 'underlined' and 'strikethrough' // Pango font description doesn't have 'underlined' and 'strikethrough'
@@ -274,23 +253,23 @@ void FontTestCase::NativeFontInfo()
// are properly preserved by wxNativeFontInfo or its string description. // are properly preserved by wxNativeFontInfo or its string description.
font.SetUnderlined(true); font.SetUnderlined(true);
font.SetStrikethrough(true); font.SetStrikethrough(true);
CPPUNIT_ASSERT_EQUAL(font, wxFont(font)); CHECK(font == wxFont(font));
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo())); CHECK(font == wxFont(*font.GetNativeFontInfo()));
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc())); CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
font.SetUnderlined(false); font.SetUnderlined(false);
CPPUNIT_ASSERT_EQUAL(font, wxFont(font)); CHECK(font == wxFont(font));
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo())); CHECK(font == wxFont(*font.GetNativeFontInfo()));
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc())); CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
font.SetUnderlined(true); font.SetUnderlined(true);
font.SetStrikethrough(false); font.SetStrikethrough(false);
CPPUNIT_ASSERT_EQUAL(font, wxFont(font)); CHECK(font == wxFont(font));
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo())); CHECK(font == wxFont(*font.GetNativeFontInfo()));
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc())); CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
// note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes // note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
// according to docs, so it is not tested. // according to docs, so it is not tested.
} }
void FontTestCase::NativeFontInfoUserDesc() TEST_CASE("wxFont::NativeFontInfoUserDesc", "[font][fontinfo]")
{ {
unsigned numFonts; unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts); const wxFont *pf = GetTestFonts(numFonts);
@@ -299,12 +278,12 @@ void FontTestCase::NativeFontInfoUserDesc()
wxFont test(*pf++); wxFont test(*pf++);
const wxString& niud = test.GetNativeFontInfoUserDesc(); const wxString& niud = test.GetNativeFontInfoUserDesc();
CPPUNIT_ASSERT( !niud.empty() ); CHECK( !niud.empty() );
// documented to be never empty // documented to be never empty
wxFont temp2; wxFont temp2;
CPPUNIT_ASSERT( temp2.SetNativeFontInfoUserDesc(niud) ); CHECK( temp2.SetNativeFontInfoUserDesc(niud) );
CPPUNIT_ASSERT( temp2.IsOk() ); CHECK( temp2.IsOk() );
#ifdef __WXGTK__ #ifdef __WXGTK__
// Pango saves/restores all font info in the user-friendly string: // Pango saves/restores all font info in the user-friendly string:
@@ -317,8 +296,8 @@ void FontTestCase::NativeFontInfoUserDesc()
// are not granted to save/restore all font info. // are not granted to save/restore all font info.
// In fact e.g. the font family is not saved at all; test only those // In fact e.g. the font family is not saved at all; test only those
// info which GetNativeFontInfoUserDesc() does indeed save: // info which GetNativeFontInfoUserDesc() does indeed save:
CPPUNIT_ASSERT_EQUAL( test.GetWeight(), temp2.GetWeight() ); CHECK( test.GetWeight() == temp2.GetWeight() );
CPPUNIT_ASSERT_EQUAL( test.GetStyle(), temp2.GetStyle() ); CHECK( test.GetStyle() == temp2.GetStyle() );
// if the original face name was empty, it means that any face name (in // if the original face name was empty, it means that any face name (in
// this family) can be used for the new font so we shouldn't be // this family) can be used for the new font so we shouldn't be
@@ -326,11 +305,11 @@ void FontTestCase::NativeFontInfoUserDesc()
const wxString facename = test.GetFaceName(); const wxString facename = test.GetFaceName();
if ( !facename.empty() ) if ( !facename.empty() )
{ {
CPPUNIT_ASSERT_EQUAL( facename.Upper(), temp2.GetFaceName().Upper() ); CHECK( facename.Upper() == temp2.GetFaceName().Upper() );
} }
CPPUNIT_ASSERT_EQUAL( test.GetPointSize(), temp2.GetPointSize() ); CHECK( test.GetPointSize() == temp2.GetPointSize() );
CPPUNIT_ASSERT_EQUAL( test.GetEncoding(), temp2.GetEncoding() ); CHECK( test.GetEncoding() == temp2.GetEncoding() );
#endif #endif
} }
} }