correct test failures under MSW, it shouldn't assume that all predefined fonts have non-empty facenames; also simplified it by separating different tests in different functions

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-05-17 11:51:09 +00:00
parent d508a9d979
commit c56fc0dc30

View File

@@ -38,9 +38,29 @@ public:
private: private:
CPPUNIT_TEST_SUITE( FontTestCase ); CPPUNIT_TEST_SUITE( FontTestCase );
CPPUNIT_TEST( GetSet ); CPPUNIT_TEST( GetSet );
CPPUNIT_TEST( NativeFontInfo );
CPPUNIT_TEST( NativeFontInfoUserDesc );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
void GetSet(); void GetSet();
void NativeFontInfo();
void NativeFontInfoUserDesc();
static const wxFont *GetTestFonts(unsigned& numFonts)
{
static const wxFont testfonts[] =
{
*wxNORMAL_FONT,
*wxSMALL_FONT,
*wxITALIC_FONT,
*wxSWISS_FONT,
wxFont(5, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)
};
numFonts = WXSIZEOF(testfonts);
return testfonts;
}
DECLARE_NO_COPY_CLASS(FontTestCase) DECLARE_NO_COPY_CLASS(FontTestCase)
}; };
@@ -75,32 +95,21 @@ wxString DumpFont(const wxFont *font)
void FontTestCase::GetSet() void FontTestCase::GetSet()
{ {
static const wxFont testfonts[] = unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts);
for ( size_t n = 0; n < numFonts; n++ )
{ {
*wxNORMAL_FONT, wxFont test(*pf++);
*wxSMALL_FONT,
*wxITALIC_FONT,
*wxSWISS_FONT,
wxFont(5, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)
};
for ( size_t n = 0; n < WXSIZEOF(testfonts); n++ )
{
wxFont test(testfonts[n]);
// remember: getters can only be called when wxFont::IsOk() == true // remember: getters can only be called when wxFont::IsOk() == true
CPPUNIT_ASSERT( test.IsOk() ); CPPUNIT_ASSERT( test.IsOk() );
// test Get/SetFaceName() // test Get/SetFaceName()
const wxString& fn = test.GetFaceName();
CPPUNIT_ASSERT( !fn.empty() );
CPPUNIT_ASSERT( !test.SetFaceName("a dummy face name") ); CPPUNIT_ASSERT( !test.SetFaceName("a dummy face name") );
CPPUNIT_ASSERT( !test.IsOk() ); CPPUNIT_ASSERT( !test.IsOk() );
CPPUNIT_ASSERT( test.SetFaceName(fn) ); CPPUNIT_ASSERT( test.SetFaceName("Arial") );
CPPUNIT_ASSERT( test.IsOk() ); CPPUNIT_ASSERT( test.IsOk() );
@@ -121,50 +130,6 @@ void FontTestCase::GetSet()
//CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() ); //CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() );
// test Get/SetNativeFontInfo
const wxString& nid = test.GetNativeFontInfoDesc();
CPPUNIT_ASSERT( !nid.empty() );
// documented to be never empty
wxFont temp;
CPPUNIT_ASSERT( temp.SetNativeFontInfo(nid) );
CPPUNIT_ASSERT( temp.IsOk() );
WX_ASSERT_MESSAGE(
("Test #%lu failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
n, DumpFont(&test), DumpFont(&temp)),
temp == test );
// test Get/SetNativeFontInfoUserDesc
const wxString& niud = test.GetNativeFontInfoUserDesc();
CPPUNIT_ASSERT( !niud.empty() );
// documented to be never empty
wxFont temp2;
CPPUNIT_ASSERT( temp2.SetNativeFontInfoUserDesc(niud) );
CPPUNIT_ASSERT( temp2.IsOk() );
#ifdef __WXGTK__
// Pango saves/restores all font info in the user-friendly string:
WX_ASSERT_MESSAGE(
("Test #%lu failed; native info user desc was \"%s\" for test and \"%s\" for temp2", \
n, niud, temp2.GetNativeFontInfoUserDesc()),
temp2 == test );
#else
// NOTE: as documented GetNativeFontInfoUserDesc/SetNativeFontInfoUserDesc
// are not granted to save/restore all font info.
// In fact e.g. the font family is not saved at all; test only those
// info which GetNativeFontInfoUserDesc() does indeed save:
CPPUNIT_ASSERT_EQUAL( test.GetWeight(), temp2.GetWeight() );
CPPUNIT_ASSERT_EQUAL( test.GetStyle(), temp2.GetStyle() );
CPPUNIT_ASSERT( test.GetFaceName().CmpNoCase(temp2.GetFaceName()) == 0 );
CPPUNIT_ASSERT_EQUAL( test.GetPointSize(), temp2.GetPointSize() );
CPPUNIT_ASSERT_EQUAL( test.GetEncoding(), temp2.GetEncoding() );
#endif
// test Get/SetPointSize() // test Get/SetPointSize()
test.SetPointSize(30); test.SetPointSize(30);
@@ -209,4 +174,76 @@ void FontTestCase::GetSet()
} }
} }
void FontTestCase::NativeFontInfo()
{
unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts);
for ( size_t n = 0; n < numFonts; n++ )
{
wxFont test(*pf++);
const wxString& nid = test.GetNativeFontInfoDesc();
CPPUNIT_ASSERT( !nid.empty() );
// documented to be never empty
wxFont temp;
CPPUNIT_ASSERT( temp.SetNativeFontInfo(nid) );
CPPUNIT_ASSERT( temp.IsOk() );
WX_ASSERT_MESSAGE(
("Test #%lu failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
n, DumpFont(&test), DumpFont(&temp)),
temp == test );
}
// test that clearly invalid font info strings do not work
wxFont font;
CPPUNIT_ASSERT( !font.SetNativeFontInfo("") );
CPPUNIT_ASSERT( !font.SetNativeFontInfo("bloordyblop") );
}
void FontTestCase::NativeFontInfoUserDesc()
{
unsigned numFonts;
const wxFont *pf = GetTestFonts(numFonts);
for ( size_t n = 0; n < numFonts; n++ )
{
wxFont test(*pf++);
const wxString& niud = test.GetNativeFontInfoUserDesc();
CPPUNIT_ASSERT( !niud.empty() );
// documented to be never empty
wxFont temp2;
CPPUNIT_ASSERT( temp2.SetNativeFontInfoUserDesc(niud) );
CPPUNIT_ASSERT( temp2.IsOk() );
#ifdef __WXGTK__
// Pango saves/restores all font info in the user-friendly string:
WX_ASSERT_MESSAGE(
("Test #%lu failed; native info user desc was \"%s\" for test and \"%s\" for temp2", \
n, niud, temp2.GetNativeFontInfoUserDesc()),
temp2 == test );
#else
// NOTE: as documented GetNativeFontInfoUserDesc/SetNativeFontInfoUserDesc
// are not granted to save/restore all font info.
// In fact e.g. the font family is not saved at all; test only those
// info which GetNativeFontInfoUserDesc() does indeed save:
CPPUNIT_ASSERT_EQUAL( test.GetWeight(), temp2.GetWeight() );
CPPUNIT_ASSERT_EQUAL( test.GetStyle(), temp2.GetStyle() );
// 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
// surprised to find that they differ in this case
const wxString facename = test.GetFaceName();
if ( !facename.empty() )
{
CPPUNIT_ASSERT_EQUAL( facename.Upper(), temp2.GetFaceName().Upper() );
}
CPPUNIT_ASSERT_EQUAL( test.GetPointSize(), temp2.GetPointSize() );
CPPUNIT_ASSERT_EQUAL( test.GetEncoding(), temp2.GetEncoding() );
#endif
}
}
#endif // wxUSE_FONTMAP #endif // wxUSE_FONTMAP