// Purpose: wxFont unit test
// Author: Francesco Montorsi
// Created: 16.3.09
-// RCS-ID: $Id$
// Copyright: (c) 2009 Francesco Montorsi
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/font.h"
+#include "asserthelper.h"
+
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
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();
// 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)
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,
+ 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;
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()
CPPUNIT_ASSERT( test.IsOk() );
CPPUNIT_ASSERT_EQUAL( true, test.GetUnderlined() );
+ // test Get/SetStrikethrough()
+
+ // Strike through support not implemented in wxOSX currently.
+#ifndef __WXOSX__
+ test.SetStrikethrough(true);
+ CPPUNIT_ASSERT( test.IsOk() );
+ CPPUNIT_ASSERT_EQUAL( true, test.GetStrikethrough() );
+#endif // !__WXOSX__
+
// test Get/SetWeight()
#if !defined(__WXGTK__) && !defined(__WXX11__)
CPPUNIT_ASSERT( !font.SetNativeFontInfo("bloordyblop") );
#endif
+
+ // Pango font description doesn't have 'underlined' and 'strikethrough'
+ // attributes, so wxNativeFontInfo implements these itself. Test if these
+ // are properly preserved by wxNativeFontInfo or its string description.
+ font.SetUnderlined(true);
+ font.SetStrikethrough(true);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ font.SetUnderlined(false);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ font.SetUnderlined(true);
+ font.SetStrikethrough(false);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ // note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
+ // according to docs, so it is not tested.
}
void FontTestCase::NativeFontInfoUserDesc()