]>
Commit | Line | Data |
---|---|---|
1cd53e88 VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/strings/strings.cpp | |
3 | // Purpose: wxString unit test | |
4 | // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba | |
5 | // Created: 2004-04-19 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/wx.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | #include "wx/tokenzr.h" | |
25 | ||
26 | #include "wx/cppunit.h" | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // test class | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | class StringTestCase : public CppUnit::TestCase | |
33 | { | |
34 | public: | |
35 | StringTestCase(); | |
36 | ||
37 | private: | |
38 | CPPUNIT_TEST_SUITE( StringTestCase ); | |
39 | CPPUNIT_TEST( String ); | |
40 | CPPUNIT_TEST( PChar ); | |
41 | CPPUNIT_TEST( Format ); | |
42 | CPPUNIT_TEST( Constructors ); | |
ad3fca67 VS |
43 | #if wxUSE_WCHAR_T |
44 | CPPUNIT_TEST( ConstructorsWithConversion ); | |
45 | #endif | |
265d5cce | 46 | CPPUNIT_TEST( Conversion ); |
1cd53e88 VS |
47 | CPPUNIT_TEST( Extraction ); |
48 | CPPUNIT_TEST( Find ); | |
49 | CPPUNIT_TEST( Tokenizer ); | |
76c6fcbc | 50 | CPPUNIT_TEST( TokenizerGetPosition ); |
1cd53e88 VS |
51 | CPPUNIT_TEST( Replace ); |
52 | CPPUNIT_TEST( Match ); | |
bd7f096d | 53 | CPPUNIT_TEST( CaseChanges ); |
dcb68102 RN |
54 | CPPUNIT_TEST( Compare ); |
55 | CPPUNIT_TEST( CompareNoCase ); | |
1cd53e88 VS |
56 | CPPUNIT_TEST_SUITE_END(); |
57 | ||
58 | void String(); | |
59 | void PChar(); | |
60 | void Format(); | |
61 | void Constructors(); | |
ad3fca67 VS |
62 | #if wxUSE_WCHAR_T |
63 | void ConstructorsWithConversion(); | |
64 | #endif | |
265d5cce | 65 | void Conversion(); |
1cd53e88 VS |
66 | void Extraction(); |
67 | void Find(); | |
0a199299 | 68 | void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode ); |
1cd53e88 | 69 | void Tokenizer(); |
76c6fcbc | 70 | void TokenizerGetPosition(); |
1cd53e88 VS |
71 | void Replace(); |
72 | void Match(); | |
bd7f096d | 73 | void CaseChanges(); |
dcb68102 RN |
74 | void Compare(); |
75 | void CompareNoCase(); | |
1cd53e88 VS |
76 | |
77 | DECLARE_NO_COPY_CLASS(StringTestCase) | |
78 | }; | |
79 | ||
80 | // register in the unnamed registry so that these tests are run by default | |
81 | CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase ); | |
82 | ||
83 | // also include in it's own registry so that these tests can be run alone | |
84 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" ); | |
85 | ||
86 | StringTestCase::StringTestCase() | |
87 | { | |
88 | } | |
89 | ||
90 | void StringTestCase::String() | |
91 | { | |
92 | wxString a, b, c; | |
93 | ||
94 | a.reserve (128); | |
95 | b.reserve (128); | |
96 | c.reserve (128); | |
97 | ||
98 | for (int i = 0; i < 2; ++i) | |
99 | { | |
100 | a = _T("Hello"); | |
101 | b = _T(" world"); | |
102 | c = _T("! How'ya doin'?"); | |
103 | a += b; | |
104 | a += c; | |
105 | c = _T("Hello world! What's up?"); | |
106 | CPPUNIT_ASSERT( c != a ); | |
107 | } | |
108 | } | |
109 | ||
110 | void StringTestCase::PChar() | |
111 | { | |
112 | wxChar a [128]; | |
113 | wxChar b [128]; | |
114 | wxChar c [128]; | |
115 | ||
116 | for (int i = 0; i < 2; ++i) | |
117 | { | |
118 | wxStrcpy (a, _T("Hello")); | |
119 | wxStrcpy (b, _T(" world")); | |
120 | wxStrcpy (c, _T("! How'ya doin'?")); | |
121 | wxStrcat (a, b); | |
122 | wxStrcat (a, c); | |
123 | wxStrcpy (c, _T("Hello world! What's up?")); | |
124 | CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 ); | |
125 | } | |
126 | } | |
127 | ||
128 | void StringTestCase::Format() | |
129 | { | |
130 | wxString s1,s2; | |
131 | s1.Printf(_T("%03d"), 18); | |
132 | CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) ); | |
133 | s2.Printf(_T("Number 18: %s\n"), s1.c_str()); | |
134 | CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) ); | |
135 | } | |
136 | ||
137 | void StringTestCase::Constructors() | |
138 | { | |
139 | #define TEST_CTOR(args, res) \ | |
140 | { \ | |
141 | wxString s args ; \ | |
142 | CPPUNIT_ASSERT( s == res ); \ | |
143 | } | |
144 | ||
145 | TEST_CTOR((_T('Z'), 4), _T("ZZZZ")); | |
146 | TEST_CTOR((_T("Hello"), 4), _T("Hell")); | |
147 | TEST_CTOR((_T("Hello"), 5), _T("Hello")); | |
148 | ||
149 | static const wxChar *s = _T("?really!"); | |
150 | const wxChar *start = wxStrchr(s, _T('r')); | |
151 | const wxChar *end = wxStrchr(s, _T('!')); | |
152 | TEST_CTOR((start, end), _T("really")); | |
153 | } | |
154 | ||
ad3fca67 VS |
155 | #if wxUSE_WCHAR_T |
156 | void StringTestCase::ConstructorsWithConversion() | |
157 | { | |
15e2adbd VZ |
158 |