Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / tests / misc / settings.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/misc/settings.cpp
3 // Purpose: test wxSettings
4 // Author: Francesco Montorsi
5 // Created: 2009-03-24
6 // Copyright: (c) 2009 Francesco Montorsi
7 ///////////////////////////////////////////////////////////////////////////////
8
9 // ----------------------------------------------------------------------------
10 // headers
11 // ----------------------------------------------------------------------------
12
13 #include "testprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/settings.h"
20 #include "wx/fontenum.h"
21 #include "wx/brush.h"
22 #include "wx/pen.h"
23
24 // ----------------------------------------------------------------------------
25 // test class
26 // ----------------------------------------------------------------------------
27
28 class SettingsTestCase : public CppUnit::TestCase
29 {
30 public:
31 SettingsTestCase() { }
32
33 private:
34 CPPUNIT_TEST_SUITE( SettingsTestCase );
35 CPPUNIT_TEST( GetColour );
36 CPPUNIT_TEST( GetFont );
37 CPPUNIT_TEST( GlobalColours );
38 CPPUNIT_TEST( GlobalFonts );
39 CPPUNIT_TEST( GlobalBrushes );
40 CPPUNIT_TEST( GlobalPens );
41 CPPUNIT_TEST_SUITE_END();
42
43 void GetColour();
44 void GetFont();
45
46 // not really wxSystemSettings stuff but still nice to test:
47 void GlobalColours();
48 void GlobalFonts();
49 void GlobalBrushes();
50 void GlobalPens();
51
52 DECLARE_NO_COPY_CLASS(SettingsTestCase)
53 };
54
55 // register in the unnamed registry so that these tests are run by default
56 CPPUNIT_TEST_SUITE_REGISTRATION( SettingsTestCase );
57
58 // also include in its own registry so that these tests can be run alone
59 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SettingsTestCase, "SettingsTestCase" );
60
61
62 void SettingsTestCase::GetColour()
63 {
64 for (unsigned int i=wxSYS_COLOUR_SCROLLBAR; i < wxSYS_COLOUR_MAX; i++)
65 CPPUNIT_ASSERT( wxSystemSettings::GetColour((wxSystemColour)i).IsOk() );
66 }
67
68 void SettingsTestCase::GetFont()
69 {
70 const wxSystemFont ids[] =
71 {
72 wxSYS_OEM_FIXED_FONT,
73 wxSYS_ANSI_FIXED_FONT,
74 wxSYS_ANSI_VAR_FONT,
75 wxSYS_SYSTEM_FONT,
76 wxSYS_DEVICE_DEFAULT_FONT,
77 wxSYS_SYSTEM_FIXED_FONT,
78 wxSYS_DEFAULT_GUI_FONT
79 };
80
81 for (unsigned int i=0; i < WXSIZEOF(ids); i++)
82 {
83 const wxFont& font = wxSystemSettings::GetFont(ids[i]);
84 CPPUNIT_ASSERT( font.IsOk() &&
85 wxFontEnumerator::IsValidFacename(font.GetFaceName()) );
86 }
87 }
88
89 void SettingsTestCase::GlobalColours()
90 {
91 wxColour col[] =
92 {
93 *wxBLACK,
94 *wxBLUE,
95 *wxCYAN,
96 *wxGREEN,
97 *wxLIGHT_GREY,
98 *wxRED,
99 *wxWHITE
100 };
101
102 for (unsigned int i=0; i < WXSIZEOF(col); i++)
103 CPPUNIT_ASSERT( col[i].IsOk() );
104 }
105
106 void SettingsTestCase::GlobalFonts()
107 {
108 const wxFont font[] =
109 {
110 *wxNORMAL_FONT,
111 *wxSMALL_FONT,
112 *wxITALIC_FONT,
113 *wxSWISS_FONT
114 };
115
116 for (unsigned int i=0; i < WXSIZEOF(font); i++)
117 {
118 CPPUNIT_ASSERT( font[i].IsOk() );
119
120 const wxString facename = font[i].GetFaceName();
121 if ( !facename.empty() )
122 {
123 WX_ASSERT_MESSAGE(
124 ("font #%u: facename \"%s\" is invalid", i, facename),
125 wxFontEnumerator::IsValidFacename(facename)
126 );
127 }
128 }
129 }
130
131 void SettingsTestCase::GlobalBrushes()
132 {
133 wxBrush brush[] =
134 {
135 *wxBLACK_BRUSH,
136 *wxBLUE_BRUSH,
137 *wxCYAN_BRUSH,
138 *wxGREEN_BRUSH,
139 *wxGREY_BRUSH,
140 *wxLIGHT_GREY_BRUSH,
141 *wxMEDIUM_GREY_BRUSH,
142 *wxRED_BRUSH,
143 *wxTRANSPARENT_BRUSH,
144 *wxWHITE_BRUSH
145 };
146
147 for (unsigned int i=0; i < WXSIZEOF(brush); i++)
148 CPPUNIT_ASSERT( brush[i].IsOk() );
149 }
150
151 void SettingsTestCase::GlobalPens()
152 {
153 wxPen pen[] =
154 {
155 *wxBLACK_DASHED_PEN,
156 *wxBLACK_PEN,
157 *wxBLUE_PEN,
158 *wxCYAN_PEN,
159 *wxGREEN_PEN,
160 *wxGREY_PEN,
161 *wxLIGHT_GREY_PEN,
162 *wxMEDIUM_GREY_PEN,
163 *wxRED_PEN,
164 *wxTRANSPARENT_PEN,
165 *wxWHITE_PEN
166 };
167
168 for (unsigned int i=0; i < WXSIZEOF(pen); i++)
169 CPPUNIT_ASSERT( pen[i].IsOk() );
170 }