File: settings.cpp

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (170 lines) | stat: -rw-r--r-- 4,245 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/misc/settings.cpp
// Purpose:     test wxSettings
// Author:      Francesco Montorsi
// Created:     2009-03-24
// Copyright:   (c) 2009 Francesco Montorsi
///////////////////////////////////////////////////////////////////////////////

// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

#include "testprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#include "wx/settings.h"
#include "wx/fontenum.h"
#include "wx/brush.h"
#include "wx/pen.h"

// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------

class SettingsTestCase : public CppUnit::TestCase
{
public:
    SettingsTestCase() { }

private:
    CPPUNIT_TEST_SUITE( SettingsTestCase );
        CPPUNIT_TEST( GetColour );
        CPPUNIT_TEST( GetFont );
        CPPUNIT_TEST( GlobalColours );
        CPPUNIT_TEST( GlobalFonts );
        CPPUNIT_TEST( GlobalBrushes );
        CPPUNIT_TEST( GlobalPens );
    CPPUNIT_TEST_SUITE_END();

    void GetColour();
    void GetFont();
    
    // not really wxSystemSettings stuff but still nice to test:
    void GlobalColours();
    void GlobalFonts();
    void GlobalBrushes();
    void GlobalPens();

    DECLARE_NO_COPY_CLASS(SettingsTestCase)
};

// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( SettingsTestCase );

// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SettingsTestCase, "SettingsTestCase" );


void SettingsTestCase::GetColour()
{
    for (unsigned int i=wxSYS_COLOUR_SCROLLBAR; i < wxSYS_COLOUR_MAX; i++)
        CPPUNIT_ASSERT( wxSystemSettings::GetColour((wxSystemColour)i).IsOk() );
}

void SettingsTestCase::GetFont()
{
    const wxSystemFont ids[] = 
    {
        wxSYS_OEM_FIXED_FONT,
        wxSYS_ANSI_FIXED_FONT,
        wxSYS_ANSI_VAR_FONT,
        wxSYS_SYSTEM_FONT,
        wxSYS_DEVICE_DEFAULT_FONT,
        wxSYS_SYSTEM_FIXED_FONT,
        wxSYS_DEFAULT_GUI_FONT
    };

    for (unsigned int i=0; i < WXSIZEOF(ids); i++)
    {
        const wxFont& font = wxSystemSettings::GetFont(ids[i]);
        CPPUNIT_ASSERT( font.IsOk() && 
                        wxFontEnumerator::IsValidFacename(font.GetFaceName()) );
    }
}

void SettingsTestCase::GlobalColours()
{
    wxColour col[] =
    {
        *wxBLACK,
        *wxBLUE,
        *wxCYAN,
        *wxGREEN,
        *wxLIGHT_GREY,
        *wxRED,
        *wxWHITE
    };

    for (unsigned int i=0; i < WXSIZEOF(col); i++)
        CPPUNIT_ASSERT( col[i].IsOk() );
}

void SettingsTestCase::GlobalFonts()
{
    const wxFont font[] =
    {
        *wxNORMAL_FONT,
        *wxSMALL_FONT,
        *wxITALIC_FONT,
        *wxSWISS_FONT
    };

    for (unsigned int i=0; i < WXSIZEOF(font); i++)
    {
        CPPUNIT_ASSERT( font[i].IsOk() );

        const wxString facename = font[i].GetFaceName();
        if ( !facename.empty() )
        {
            WX_ASSERT_MESSAGE(
                ("font #%u: facename \"%s\" is invalid", i, facename),
                wxFontEnumerator::IsValidFacename(facename)
            );
        }
    }
}

void SettingsTestCase::GlobalBrushes()
{
    wxBrush brush[] =
    {
        *wxBLACK_BRUSH,
        *wxBLUE_BRUSH,
        *wxCYAN_BRUSH,
        *wxGREEN_BRUSH,
        *wxGREY_BRUSH,
        *wxLIGHT_GREY_BRUSH,
        *wxMEDIUM_GREY_BRUSH,
        *wxRED_BRUSH,
        *wxTRANSPARENT_BRUSH,
        *wxWHITE_BRUSH
    };

    for (unsigned int i=0; i < WXSIZEOF(brush); i++)
        CPPUNIT_ASSERT( brush[i].IsOk() );
}

void SettingsTestCase::GlobalPens()
{
    wxPen pen[] =
    {
        *wxBLACK_DASHED_PEN,
        *wxBLACK_PEN,
        *wxBLUE_PEN,
        *wxCYAN_PEN,
        *wxGREEN_PEN,
        *wxGREY_PEN,
        *wxLIGHT_GREY_PEN,
        *wxMEDIUM_GREY_PEN,
        *wxRED_PEN,
        *wxTRANSPARENT_PEN,
        *wxWHITE_PEN
    };

    for (unsigned int i=0; i < WXSIZEOF(pen); i++)
        CPPUNIT_ASSERT( pen[i].IsOk() );
}