1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/font/fonttest.cpp
3 // Purpose: wxFont unit test
4 // Author: Francesco Montorsi
7 // Copyright: (c) 2009 Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class FontTestCase
: public CppUnit
::TestCase
39 CPPUNIT_TEST_SUITE( FontTestCase
);
40 CPPUNIT_TEST( GetSet
);
41 CPPUNIT_TEST_SUITE_END();
45 DECLARE_NO_COPY_CLASS(FontTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( FontTestCase
);
51 // also include in it's own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FontTestCase
, "FontTestCase" );
55 void FontTestCase
::GetSet()
57 static const wxFont testfonts
[] =
63 wxFont(5, wxFONTFAMILY_TELETYPE
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
)
66 for ( size_t n
= 0; n
< WXSIZEOF(testfonts
); n
++ )
68 wxFont
test(testfonts
[n
]);
70 // remember: getters can only be called when wxFont::IsOk() == true
71 CPPUNIT_ASSERT( test
.IsOk() );
74 // test Get/SetFaceName()
76 const wxString
& fn
= test
.GetFaceName();
77 CPPUNIT_ASSERT( !fn
.empty() );
79 CPPUNIT_ASSERT( !test
.SetFaceName("a dummy face name") );
80 CPPUNIT_ASSERT( !test
.IsOk() );
82 CPPUNIT_ASSERT( test
.SetFaceName(fn
) );
83 CPPUNIT_ASSERT( test
.IsOk() );
86 // test Get/SetFamily()
88 test
.SetFamily( wxFONTFAMILY_ROMAN
);
89 CPPUNIT_ASSERT( test
.IsOk() );
90 CPPUNIT_ASSERT( wxFONTFAMILY_ROMAN
== test
.GetFamily() ||
91 wxFONTFAMILY_UNKNOWN
== test
.GetFamily() );
92 // note that there is always the possibility that GetFamily() returns
93 // wxFONTFAMILY_UNKNOWN so that we consider it as a valid return value
96 // test Get/SetEncoding()
98 //test.SetEncoding( wxFONTENCODING_KOI8 );
99 //CPPUNIT_ASSERT( test.IsOk() );
100 //CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() );
103 // test Get/SetNativeFontInfo
105 const wxString
& nid
= test
.GetNativeFontInfoDesc();
106 CPPUNIT_ASSERT( !nid
.empty() );
107 // documented to be never empty
110 CPPUNIT_ASSERT( temp
.SetNativeFontInfo(nid
) );
111 CPPUNIT_ASSERT( temp
.IsOk() );
113 ("Test #%lu failed; native info desc was \"%s\" for test and \"%s\" for temp", \
114 n
, nid
, temp
.GetNativeFontInfoDesc()),
118 // test Get/SetNativeFontInfoUserDesc
120 const wxString
& niud
= test
.GetNativeFontInfoUserDesc();
121 CPPUNIT_ASSERT( !niud
.empty() );
122 // documented to be never empty
125 CPPUNIT_ASSERT( temp2
.SetNativeFontInfoUserDesc(niud
) );
126 CPPUNIT_ASSERT( temp2
.IsOk() );
129 // Pango saves/restores all font info in the user-friendly string:
131 ("Test #%lu failed; native info user desc was \"%s\" for test and \"%s\" for temp2", \
132 n
, niud
, temp2
.GetNativeFontInfoUserDesc()),
135 // NOTE: as documented GetNativeFontInfoUserDesc/SetNativeFontInfoUserDesc
136 // are not granted to save/restore all font info.
137 // In fact e.g. the font family is not saved at all; test only those
138 // info which GetNativeFontInfoUserDesc() does indeed save:
139 CPPUNIT_ASSERT_EQUAL( test
.GetWeight(), temp2
.GetWeight() );
140 CPPUNIT_ASSERT_EQUAL( test
.GetStyle(), temp2
.GetStyle() );
141 CPPUNIT_ASSERT( test
.GetFaceName().CmpNoCase(temp2
.GetFaceName()) == 0 );
142 CPPUNIT_ASSERT_EQUAL( test
.GetPointSize(), temp2
.GetPointSize() );
143 CPPUNIT_ASSERT_EQUAL( test
.GetEncoding(), temp2
.GetEncoding() );
147 // test Get/SetPointSize()
149 test
.SetPointSize(30);
150 CPPUNIT_ASSERT( test
.IsOk() );
151 CPPUNIT_ASSERT_EQUAL( 30, test
.GetPointSize() );
154 // test Get/SetPixelSize()
156 test
.SetPixelSize(wxSize(0,30));
157 CPPUNIT_ASSERT( test
.IsOk() );
158 CPPUNIT_ASSERT( test
.GetPixelSize().GetHeight() <= 30 );
159 // NOTE: the match found by SetPixelSize() may be not 100% precise; it
160 // only grants that a font smaller than the required height will
164 // test Get/SetStyle()
166 test
.SetStyle(wxFONTSTYLE_SLANT
);
167 CPPUNIT_ASSERT( test
.IsOk() );
169 // on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC
170 CPPUNIT_ASSERT( wxFONTSTYLE_SLANT
== test
.GetStyle() ||
171 wxFONTSTYLE_ITALIC
== test
.GetStyle() );
173 CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_SLANT
, test
.GetStyle() );
176 // test Get/SetUnderlined()
178 test
.SetUnderlined(true);
179 CPPUNIT_ASSERT( test
.IsOk() );
180 CPPUNIT_ASSERT_EQUAL( true, test
.GetUnderlined() );
183 // test Get/SetWeight()
185 test
.SetWeight(wxFONTWEIGHT_BOLD
);
186 CPPUNIT_ASSERT( test
.IsOk() );
187 CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_BOLD
, test
.GetWeight() );
191 #endif // wxUSE_FONTMAP