]>
git.saurik.com Git - wxWidgets.git/blob - tests/mbconv/convautotest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/mbconv/convauto.cpp
3 // Purpose: wxConvAuto unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2006 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
25 #include "wx/convauto.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class ConvAutoTestCase
: public CppUnit::TestCase
34 ConvAutoTestCase() { }
37 CPPUNIT_TEST_SUITE( ConvAutoTestCase
);
38 CPPUNIT_TEST( Empty
);
39 CPPUNIT_TEST( Short
);
41 CPPUNIT_TEST( UTF32LE
);
42 CPPUNIT_TEST( UTF32BE
);
43 CPPUNIT_TEST( UTF16LE
);
44 CPPUNIT_TEST( UTF16BE
);
46 CPPUNIT_TEST_SUITE_END();
48 // real test function: check that converting the src multibyte string to
49 // wide char using wxConvAuto yields wch as the first result
50 void TestFirstChar(const char *src
, wchar_t wch
);
62 // register in the unnamed registry so that these tests are run by default
63 CPPUNIT_TEST_SUITE_REGISTRATION(ConvAutoTestCase
);
65 // also include in it's own registry so that these tests can be run alone
66 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConvAutoTestCase
, "ConvAutoTestCase");
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 void ConvAutoTestCase::TestFirstChar(const char *src
, wchar_t wch
)
74 wxWCharBuffer wbuf
= wxConvAuto().cMB2WC(src
);
75 CPPUNIT_ASSERT( wbuf
);
76 CPPUNIT_ASSERT_EQUAL( wch
, *wbuf
);
79 void ConvAutoTestCase::Empty()
81 TestFirstChar("", wxT('\0'));
84 void ConvAutoTestCase::Short()
86 TestFirstChar("1", wxT('1'));
89 void ConvAutoTestCase::None()
91 TestFirstChar("Hello world", wxT('H'));
94 void ConvAutoTestCase::UTF32LE()
96 TestFirstChar("\xff\xfe\0\0A\0\0\0", wxT('A'));
99 void ConvAutoTestCase::UTF32BE()
101 TestFirstChar("\0\0\xfe\xff\0\0\0B", wxT('B'));
104 void ConvAutoTestCase::UTF16LE()
106 TestFirstChar("\xff\xfeZ\0", wxT('Z'));
109 void ConvAutoTestCase::UTF16BE()
111 TestFirstChar("\xfe\xff\0Y", wxT('Y'));
114 void ConvAutoTestCase::UTF8()
116 #ifdef wxHAVE_U_ESCAPE
117 TestFirstChar("\xef\xbb\xbf\xd0\x9f", L
'\u041f');
121 #endif // wxUSE_WCHAR_T