]>
Commit | Line | Data |
---|---|---|
a29cce78 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/mbconv/convauto.cpp | |
3 | // Purpose: wxConvAuto unit test | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2006-04-04 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006 Vadim Zeitlin | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
14 | #include "testprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #if wxUSE_WCHAR_T | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #endif // WX_PRECOMP | |
24 | ||
25 | #include "wx/convauto.h" | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
28 | // test class | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
31 | class ConvAutoTestCase : public CppUnit::TestCase | |
32 | { | |
33 | public: | |
34 | ConvAutoTestCase() { } | |
35 | ||
36 | private: | |
37 | CPPUNIT_TEST_SUITE( ConvAutoTestCase ); | |
38 | CPPUNIT_TEST( Empty ); | |
39 | CPPUNIT_TEST( Short ); | |
40 | CPPUNIT_TEST( None ); | |
41 | CPPUNIT_TEST( UTF32LE ); | |
42 | CPPUNIT_TEST( UTF32BE ); | |
43 | CPPUNIT_TEST( UTF16LE ); | |
44 | CPPUNIT_TEST( UTF16BE ); | |
45 | CPPUNIT_TEST( UTF8 ); | |
46 | CPPUNIT_TEST_SUITE_END(); | |
47 | ||
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); | |
51 | ||
52 | void Empty(); | |
53 | void Short(); | |
54 | void None(); | |
55 | void UTF32LE(); | |
56 | void UTF32BE(); | |
57 | void UTF16LE(); | |
58 | void UTF16BE(); | |
59 | void UTF8(); | |
60 | }; | |
61 | ||
62 | // register in the unnamed registry so that these tests are run by default | |
63 | CPPUNIT_TEST_SUITE_REGISTRATION(ConvAutoTestCase); | |
64 | ||
65 | // also include in it's own registry so that these tests can be run alone | |
81e9dec6 | 66 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConvAutoTestCase, "ConvAutoTestCase"); |
a29cce78 VZ |
67 | |
68 | // ---------------------------------------------------------------------------- | |
69 | // tests | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | void ConvAutoTestCase::TestFirstChar(const char *src, wchar_t wch) | |
73 | { | |
74 | wxWCharBuffer wbuf = wxConvAuto().cMB2WC(src); | |
75 | CPPUNIT_ASSERT( wbuf ); | |
76 | CPPUNIT_ASSERT_EQUAL( wch, *wbuf ); | |
77 | } | |
78 | ||
79 | void ConvAutoTestCase::Empty() | |
80 | { | |
9a83f860 | 81 | TestFirstChar("", wxT('\0')); |
a29cce78 VZ |
82 | } |
83 | ||
84 | void ConvAutoTestCase::Short() | |
85 | { | |
9a83f860 | 86 | TestFirstChar("1", wxT('1')); |
a29cce78 VZ |
87 | } |
88 | ||
89 | void ConvAutoTestCase::None() | |
90 | { | |
9a83f860 | 91 | TestFirstChar("Hello world", wxT('H')); |
a29cce78 VZ |
92 | } |
93 | ||
94 | void ConvAutoTestCase::UTF32LE() | |
95 | { | |
9a83f860 | 96 | TestFirstChar("\xff\xfe\0\0A\0\0\0", wxT('A')); |
a29cce78 VZ |
97 | } |
98 | ||
99 | void ConvAutoTestCase::UTF32BE() | |
100 | { | |
9a83f860 | 101 | TestFirstChar("\0\0\xfe\xff\0\0\0B", wxT('B')); |
a29cce78 VZ |
102 | } |
103 | ||
104 | void ConvAutoTestCase::UTF16LE() | |
105 | { | |
9a83f860 | 106 | TestFirstChar("\xff\xfeZ\0", wxT('Z')); |
a29cce78 VZ |
107 | } |
108 | ||
109 | void ConvAutoTestCase::UTF16BE() | |
110 | { | |
9a83f860 | 111 | TestFirstChar("\xfe\xff\0Y", wxT('Y')); |
a29cce78 VZ |
112 | } |
113 | ||
114 | void ConvAutoTestCase::UTF8() | |
115 | { | |
116 | #ifdef wxHAVE_U_ESCAPE | |
117 | TestFirstChar("\xef\xbb\xbf\xd0\x9f", L'\u041f'); | |
118 | #endif | |
119 | } | |
120 | ||
121 | #endif // wxUSE_WCHAR_T | |
122 |