]>
git.saurik.com Git - wxWidgets.git/blob - tests/font/fonttest.cpp
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_MODERN
);
89 //CPPUNIT_ASSERT_EQUAL( wxFONTFAMILY_MODERN, test.GetFamily() );
92 // test Get/SetEncoding()
94 //test.SetEncoding( wxFONTENCODING_KOI8 );
95 //CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() );
98 // test Get/SetNativeFontInfo
100 const wxString
& nid
= test
.GetNativeFontInfoDesc();
101 CPPUNIT_ASSERT( !nid
.empty() );
104 temp
.SetNativeFontInfo(nid
);
105 CPPUNIT_ASSERT( temp
== test
);
108 // test Get/SetNativeFontInfoUserDesc
110 const wxString
& niud
= test
.GetNativeFontInfoUserDesc();
111 CPPUNIT_ASSERT( !niud
.empty() );
114 temp2
.SetNativeFontInfoUserDesc(niud
);
115 CPPUNIT_ASSERT( temp2
== test
);
118 // test Get/SetPointSize()
120 test
.SetPointSize(30);
121 CPPUNIT_ASSERT_EQUAL( 30, test
.GetPointSize() );
124 // test Get/SetPixelSize()
126 test
.SetPixelSize(wxSize(0,30));
127 CPPUNIT_ASSERT( test
.GetPixelSize().GetHeight() <= 30 );
128 // NOTE: the match found by SetPixelSize() may be not 100% precise; it
129 // only grants that a font smaller than the required height will
133 // test Get/SetStyle()
135 test
.SetStyle(wxFONTSTYLE_SLANT
);
136 CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_SLANT
, test
.GetStyle() );
139 // test Get/SetUnderlined()
141 test
.SetUnderlined(true);
142 CPPUNIT_ASSERT_EQUAL( true, test
.GetUnderlined() );
145 // test Get/SetWeight()
147 test
.SetWeight(wxFONTWEIGHT_BOLD
);
148 CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_BOLD
, test
.GetWeight() );
152 #endif // wxUSE_FONTMAP