fontmaptest.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/fontmap/fontmap.cpp
  3. // Purpose: wxFontMapper unit test
  4. // Author: Vadim Zeitlin
  5. // Created: 14.02.04
  6. // Copyright: (c) 2003 TT-Solutions
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // ----------------------------------------------------------------------------
  10. // headers
  11. // ----------------------------------------------------------------------------
  12. #include "testprec.h"
  13. #ifdef __BORLANDC__
  14. #pragma hdrstop
  15. #endif
  16. #ifndef WX_PRECOMP
  17. #include "wx/wx.h"
  18. #endif // WX_PRECOMP
  19. #if wxUSE_FONTMAP
  20. #include "wx/fontmap.h"
  21. // ----------------------------------------------------------------------------
  22. // test class
  23. // ----------------------------------------------------------------------------
  24. class FontMapperTestCase : public CppUnit::TestCase
  25. {
  26. public:
  27. FontMapperTestCase() { }
  28. private:
  29. CPPUNIT_TEST_SUITE( FontMapperTestCase );
  30. CPPUNIT_TEST( NamesAndDesc );
  31. CPPUNIT_TEST_SUITE_END();
  32. void NamesAndDesc();
  33. DECLARE_NO_COPY_CLASS(FontMapperTestCase)
  34. };
  35. // register in the unnamed registry so that these tests are run by default
  36. CPPUNIT_TEST_SUITE_REGISTRATION( FontMapperTestCase );
  37. // also include in its own registry so that these tests can be run alone
  38. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FontMapperTestCase, "FontMapperTestCase" );
  39. void FontMapperTestCase::NamesAndDesc()
  40. {
  41. static const wxChar *charsets[] =
  42. {
  43. // some valid charsets
  44. wxT("us-ascii" ),
  45. wxT("iso8859-1" ),
  46. wxT("iso-8859-12" ),
  47. wxT("koi8-r" ),
  48. wxT("utf-7" ),
  49. wxT("cp1250" ),
  50. wxT("windows-1252"),
  51. // and now some bogus ones
  52. wxT("" ),
  53. wxT("cp1249" ),
  54. wxT("iso--8859-1" ),
  55. wxT("iso-8859-19" ),
  56. };
  57. static const wxChar *names[] =
  58. {
  59. // some valid charsets
  60. wxT("default" ),
  61. wxT("iso-8859-1" ),
  62. wxT("iso-8859-12" ),
  63. wxT("koi8-r" ),
  64. wxT("utf-7" ),
  65. wxT("windows-1250"),
  66. wxT("windows-1252"),
  67. // and now some bogus ones
  68. wxT("default" ),
  69. wxT("unknown--1" ),
  70. wxT("unknown--1" ),
  71. wxT("unknown--1" ),
  72. };
  73. static const wxChar *descriptions[] =
  74. {
  75. // some valid charsets
  76. wxT("Default encoding" ),
  77. wxT("Western European (ISO-8859-1)" ),
  78. wxT("Indian (ISO-8859-12)" ),
  79. wxT("KOI8-R" ),
  80. wxT("Unicode 7 bit (UTF-7)" ),
  81. wxT("Windows Central European (CP 1250)"),
  82. wxT("Windows Western European (CP 1252)"),
  83. // and now some bogus ones
  84. wxT("Default encoding" ),
  85. wxT("Unknown encoding (-1)" ),
  86. wxT("Unknown encoding (-1)" ),
  87. wxT("Unknown encoding (-1)" ),
  88. };
  89. wxFontMapperBase& fmap = *wxFontMapperBase::Get();
  90. for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
  91. {
  92. wxFontEncoding enc = fmap.CharsetToEncoding(charsets[n]);
  93. CPPUNIT_ASSERT_EQUAL( names[n], fmap.GetEncodingName(enc).Lower() );
  94. CPPUNIT_ASSERT_EQUAL( descriptions[n], fmap.GetEncodingDescription(enc) );
  95. }
  96. }
  97. #endif // wxUSE_FONTMAP