settings.cpp 4.1 KB

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