]> git.saurik.com Git - wxWidgets.git/commitdiff
make sure that wxSystemSettings::GetFont/GetColour return values are always valid
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Tue, 24 Mar 2009 23:13:02 +0000 (23:13 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Tue, 24 Mar 2009 23:13:02 +0000 (23:13 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59820 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

15 files changed:
interface/wx/settings.h
src/gtk/settings.cpp
src/msw/settings.cpp
src/osx/carbon/settings.cpp
tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/misc/settings.cpp [new file with mode: 0644]
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj
tests/test_vc9_test_gui.vcproj

index 7b2ebc087a80947098f6a062c1b334f8724b5063..cec68d3332e8b8671179eeecbd9bbec427c850bb 100644 (file)
@@ -217,8 +217,9 @@ enum wxSystemScreenType
     @class wxSystemSettings
 
     wxSystemSettings allows the application to ask for details about the system.
-    This can include settings such as standard colours, fonts,
-    and user interface element sizes.
+
+    This can include settings such as standard colours, fonts, and user interface 
+    element sizes.
 
     @library{wxcore}
     @category{cfg}
@@ -238,13 +239,23 @@ public:
 
     /**
         Returns a system colour.
-        @a index can be one of the ::wxSystemColour enum values.
+
+        @param index 
+            Can be one of the ::wxSystemColour enum values.
+            
+        @return
+            The returned colour is always valid.
     */
     static wxColour GetColour(wxSystemColour index);
 
     /**
         Returns a system font.
-        @a index can be one of the ::wxSystemFont enum values.
+
+        @param index 
+            Can be one of the ::wxSystemFont enum values.
+            
+        @return
+            The returned font is always valid.
     */
     static wxFont GetFont(wxSystemFont index);
 
index 6e5e0f363f21e95c4cd16766f1cbd5515296222a..89cb46dbad63ba80defa43360f6887f8cac14898 100644 (file)
@@ -19,6 +19,7 @@
 #endif
 
 #include "wx/fontutil.h"
+#include "wx/fontenum.h"
 
 #include <gtk/gtk.h>
 #include "wx/gtk/private/win_gtk.h"
@@ -232,6 +233,7 @@ wxColour wxSystemSettingsNative::GetColour( wxSystemColour index )
             break;
     }
 
+    wxASSERT(color.IsOk());
     return color;
 }
 
@@ -255,6 +257,13 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
                 wxNativeFontInfo info;
                 info.description = ButtonStyle()->font_desc;
                 gs_fontSystem = wxFont(info);
+                
+                // (try to) heal the default font (on some common systems e.g. Ubuntu
+                // it's "Sans Serif" but the real font is called "Sans"):
+                if (!wxFontEnumerator::IsValidFacename(gs_fontSystem.GetFaceName()) &&
+                    gs_fontSystem.GetFaceName() == "Sans Serif")
+                    gs_fontSystem.SetFaceName("Sans");
+                
                 info.description = NULL;
             }
             font = gs_fontSystem;
@@ -263,6 +272,9 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
         default:
             break;
     }
+
+    wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName()));
+
     return font;
 }
 
index 591b4f7c634c21bd3666eb78c9126886f97ebdfd..e627033416467762824e0e5bda30b5fb6c7b29a3 100644 (file)
@@ -40,6 +40,7 @@
 #endif
 
 #include "wx/fontutil.h"
+#include "wx/fontenum.h"
 
 // ----------------------------------------------------------------------------
 // private classes
@@ -207,8 +208,10 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
         colSys = ::GetSysColor(index);
 #endif
     }
-
-    return wxRGBToColour(colSys);
+    
+    wxColour ret = wxRGBToColour(colSys);
+    wxASSERT(ret.IsOk());
+    return ret;
 }
 
 // ----------------------------------------------------------------------------
@@ -267,6 +270,8 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
         gs_fontDefault = new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT));
     }
 
+    wxASSERT(gs_fontDefault->IsOk() && 
+             wxFontEnumerator::IsValidFacename(gs_fontDefault->GetFaceName()));
     return *gs_fontDefault;
 #else // !__WXWINCE__
     // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
@@ -286,6 +291,7 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
         gs_fontDefault = new wxFont(font);
     }
 
+    wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName()));
     return font;
 #endif // __WXWINCE__/!__WXWINCE__
 }
index ad5c4f79873536a64a66a4955691a49b4afdd9d1..b7608a7e25375f4edddd2a7171d510a7a6c2be2b 100644 (file)
@@ -19,6 +19,7 @@
 #endif
 
 #include "wx/osx/private.h"
+#include "wx/fontenum.h"
 
 // ----------------------------------------------------------------------------
 // wxSystemSettingsNative
@@ -146,6 +147,8 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
             break ;
     }
 
+    //wxASSERT(resultColor.IsOk());
+
     return resultColor;
 }
 
@@ -155,20 +158,25 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
 
 wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
 {
+    wxFont font;
+    
     switch (index)
     {
         case wxSYS_ANSI_VAR_FONT :
         case wxSYS_SYSTEM_FONT :
         case wxSYS_DEVICE_DEFAULT_FONT :
         case wxSYS_DEFAULT_GUI_FONT :
-            return *wxSMALL_FONT ;
+            font = *wxSMALL_FONT ;
             break ;
 
         default :
+            font = *wxNORMAL_FONT ;
             break ;
     }
 
-    return *wxNORMAL_FONT;
+    //wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName()));
+
+    return font;
 }
 
 // ----------------------------------------------------------------------------
index 829f622e99b658b4a674c20a93cd178908a294aa..3ac2885e143b1dfd83ef0269c1411b40538db326 100644 (file)
@@ -141,6 +141,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_guifuncs.o \
        test_gui_selstoretest.o \
        test_gui_garbage.o \
+       test_gui_settings.o \
        test_gui_socket.o \
        test_gui_clientsize.o \
        test_gui_setsize.o
@@ -602,6 +603,9 @@ test_gui_selstoretest.o: $(srcdir)/misc/selstoretest.cpp $(TEST_GUI_ODEP)
 test_gui_garbage.o: $(srcdir)/misc/garbage.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/garbage.cpp
 
+test_gui_settings.o: $(srcdir)/misc/settings.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/settings.cpp
+
 test_gui_socket.o: $(srcdir)/net/socket.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/net/socket.cpp
 
index 0680d67ac98e6330fa6c44ac3025baa2eded89be..1abc6619b7d5b8d5235075abeea5148eeced4f32 100644 (file)
@@ -126,6 +126,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_guifuncs.obj \
        $(OBJS)\test_gui_selstoretest.obj \
        $(OBJS)\test_gui_garbage.obj \
+       $(OBJS)\test_gui_settings.obj \
        $(OBJS)\test_gui_socket.obj \
        $(OBJS)\test_gui_clientsize.obj \
        $(OBJS)\test_gui_setsize.obj
@@ -644,6 +645,9 @@ $(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
 $(OBJS)\test_gui_garbage.obj: .\misc\garbage.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\garbage.cpp
 
+$(OBJS)\test_gui_settings.obj: .\misc\settings.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\settings.cpp
+
 $(OBJS)\test_gui_socket.obj: .\net\socket.cpp
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp
 
index 5b72865aa95ac6cc635461438c3824b3042b1651..c96c6b7dd91214f3aead6ae85f9ab3c3810cff9c 100644 (file)
@@ -119,6 +119,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_guifuncs.o \
        $(OBJS)\test_gui_selstoretest.o \
        $(OBJS)\test_gui_garbage.o \
+       $(OBJS)\test_gui_settings.o \
        $(OBJS)\test_gui_socket.o \
        $(OBJS)\test_gui_clientsize.o \
        $(OBJS)\test_gui_setsize.o
@@ -624,6 +625,9 @@ $(OBJS)\test_gui_selstoretest.o: ./misc/selstoretest.cpp
 $(OBJS)\test_gui_garbage.o: ./misc/garbage.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_gui_settings.o: ./misc/settings.cpp
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_gui_socket.o: ./net/socket.cpp
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
 
index 108eb438530f8d710195ea32c0fd4884db96c34c..3437a89141ec3bb8f1a6b194a6b9659174e747cb 100644 (file)
@@ -122,6 +122,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_guifuncs.obj \
        $(OBJS)\test_gui_selstoretest.obj \
        $(OBJS)\test_gui_garbage.obj \
+       $(OBJS)\test_gui_settings.obj \
        $(OBJS)\test_gui_socket.obj \
        $(OBJS)\test_gui_clientsize.obj \
        $(OBJS)\test_gui_setsize.obj
@@ -729,6 +730,9 @@ $(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp
 $(OBJS)\test_gui_garbage.obj: .\misc\garbage.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\garbage.cpp
 
+$(OBJS)\test_gui_settings.obj: .\misc\settings.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\settings.cpp
+
 $(OBJS)\test_gui_socket.obj: .\net\socket.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp
 
index be9cb430d516ec99ea373e67deb670eb9fd6b62a..e68b7d9166fb207201775cbe0874ef1e2479a70b 100644 (file)
@@ -357,6 +357,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_guifuncs.obj &
        $(OBJS)\test_gui_selstoretest.obj &
        $(OBJS)\test_gui_garbage.obj &
+       $(OBJS)\test_gui_settings.obj &
        $(OBJS)\test_gui_socket.obj &
        $(OBJS)\test_gui_clientsize.obj &
        $(OBJS)\test_gui_setsize.obj
@@ -685,6 +686,9 @@ $(OBJS)\test_gui_selstoretest.obj :  .AUTODEPEND .\misc\selstoretest.cpp
 $(OBJS)\test_gui_garbage.obj :  .AUTODEPEND .\misc\garbage.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
+$(OBJS)\test_gui_settings.obj :  .AUTODEPEND .\misc\settings.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
 $(OBJS)\test_gui_socket.obj :  .AUTODEPEND .\net\socket.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
 
diff --git a/tests/misc/settings.cpp b/tests/misc/settings.cpp
new file mode 100644 (file)
index 0000000..c87e831
--- /dev/null
@@ -0,0 +1,159 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/misc/settings.cpp
+// Purpose:     test wxSettings
+// Author:      Francesco Montorsi
+// Created:     2009-03-24
+// RCS-ID:      $Id$
+// Copyright:   (c) 2009 Francesco Montorsi
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include "wx/settings.h"
+#include "wx/fontenum.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 it's 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()
+{
+    wxFont font[] =
+    {
+        *wxNORMAL_FONT,
+        *wxSMALL_FONT,
+        *wxITALIC_FONT,
+        *wxSWISS_FONT
+    };
+
+    for (unsigned int i=0; i < WXSIZEOF(font); i++)
+        CPPUNIT_ASSERT( font[i].IsOk() && 
+                        wxFontEnumerator::IsValidFacename(font[i].GetFaceName()) );
+}
+
+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() );
+}
index 8aa99d7080d5644df51034a6bf6c3f51222d928c..868899f3a2b276a99ac3ca8c97239a054341764c 100644 (file)
             misc/guifuncs.cpp
             misc/selstoretest.cpp
             misc/garbage.cpp
+            misc/settings.cpp
             <!--
                 This one is intentionally duplicated here (it is also part of
                 non-GUI test) as sockets behave differently in console and GUI
index f6ff7d1a2a0a3b03987267497572c14236180150..468e84bddbf7a4bcea1ccf1b414565b9b8dbfa6e 100644 (file)
@@ -309,6 +309,10 @@ SOURCE=.\window\setsize.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\misc\settings.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\geometry\size.cpp\r
 # End Source File\r
 # Begin Source File\r
index b3703f41ebd82f0218f1ac6456470bcfbba9db84..d83a3e762144407de4ff8d1b2dfb16fc1b3c87d8 100644 (file)
                        <File\r
                                RelativePath=".\window\setsize.cpp">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\settings.cpp">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\geometry\size.cpp">\r
                        </File>\r
index 300bceedccb2d6adbcfd75c4ce6bcfc106b20058..20a1ec570868aa23e7615af8bb6a1c56a26d5259 100644 (file)
                                RelativePath=".\window\setsize.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\settings.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\geometry\size.cpp"\r
                                >\r
index 06a4880e8b1f51aaed6c5d5b111fa69a2e80667e..014291758f36fb61e17862f058e6f8a5b5f33262 100644 (file)
                                RelativePath=".\window\setsize.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\misc\settings.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath=".\geometry\size.cpp"\r
                                >\r