X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/23790a2a29ef25f28568b30e78b7f251f1492a12..ef40bc3dae5b9bce810fa6d44b5f43071109a2d9:/tests/font/fonttest.cpp diff --git a/tests/font/fonttest.cpp b/tests/font/fonttest.cpp index 69df21a2f5..e597a5b1b9 100644 --- a/tests/font/fonttest.cpp +++ b/tests/font/fonttest.cpp @@ -37,11 +37,13 @@ public: 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(); @@ -68,7 +70,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( FontTestCase ); -// also include in it's own registry so that these tests can be run alone +// 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) @@ -93,11 +95,31 @@ wxString DumpFont(const wxFont *font) return s; } +void FontTestCase::Construct() +{ + // 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 + // overloaded wxFont ctors. + + CPPUNIT_ASSERT( wxFont(10, wxFONTFAMILY_DEFAULT).IsOk() ); + CPPUNIT_ASSERT( wxFont(10, wxFONTFAMILY_DEFAULT, + wxFONTFLAG_DEFAULT).IsOk() ); + CPPUNIT_ASSERT( wxFont(10, wxFONTFAMILY_DEFAULT, + wxFONTSTYLE_NORMAL, + wxFONTWEIGHT_NORMAL).IsOk() ); + +#if FUTURE_WXWIN_COMPATIBILITY_3_0 + // Tests relying on the soon-to-be-deprecated ctor taking ints and not + // wxFontXXX enum elements. + CPPUNIT_ASSERT( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() ); +#endif // FUTURE_WXWIN_COMPATIBILITY_3_0 +} + void FontTestCase::GetSet() { unsigned numFonts; const wxFont *pf = GetTestFonts(numFonts); - for ( size_t n = 0; n < numFonts; n++ ) + for ( unsigned n = 0; n < numFonts; n++ ) { wxFont test(*pf++); @@ -113,23 +135,17 @@ void FontTestCase::GetSet() // consider adding another branch to this #if #if defined(__WXMSW__) || defined(__WXOSX__) static const char *knownGoodFaceName = "Arial"; -#elif defined(__LINUX__) - static const char *knownGoodFaceName; - wxString distroname = wxGetLinuxDistributionInfo().Id; - - if (distroname.Contains("Ubuntu")) - knownGoodFaceName = "FreeSerif"; - // ttf-freefont and ttf-dejavu packages are installed by default on [X,K]Ubuntu systems - else if (distroname == "Debian") - knownGoodFaceName = "Fixed"; - else - knownGoodFaceName = "DejaVu Sans"; - // this is very popular in many linux distro... #else - static const char *knownGoodFaceName = "Fixed"; + static const char *knownGoodFaceName = "Monospace"; #endif - CPPUNIT_ASSERT( test.SetFaceName(knownGoodFaceName) ); + WX_ASSERT_MESSAGE + ( + ("failed to set face name \"%s\" for test font #%u\n" + "(this failure is harmless if this face name is not " + "available on this system)", knownGoodFaceName, n), + test.SetFaceName(knownGoodFaceName) + ); CPPUNIT_ASSERT( test.IsOk() ); @@ -137,10 +153,13 @@ void FontTestCase::GetSet() test.SetFamily( wxFONTFAMILY_ROMAN ); CPPUNIT_ASSERT( test.IsOk() ); - CPPUNIT_ASSERT( wxFONTFAMILY_ROMAN == test.GetFamily() || - wxFONTFAMILY_UNKNOWN == test.GetFamily() ); - // note that there is always the possibility that GetFamily() returns - // wxFONTFAMILY_UNKNOWN so that we consider it as a valid return value + + // note that there is always the possibility that GetFamily() returns + // wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we + // consider it as a valid return value + const wxFontFamily family = test.GetFamily(); + if ( family != wxFONTFAMILY_DEFAULT ) + CPPUNIT_ASSERT_EQUAL( wxFONTFAMILY_ROMAN, family ); // test Get/SetEncoding()