]> git.saurik.com Git - wxWidgets.git/blame_incremental - tests/strings/strings.cpp
Rebake after adding libs html and xml to samples using lib adv
[wxWidgets.git] / tests / strings / strings.cpp
... / ...
CommitLineData
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 "testprec.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// ----------------------------------------------------------------------------
27// test class
28// ----------------------------------------------------------------------------
29
30class StringTestCase : public CppUnit::TestCase
31{
32public:
33 StringTestCase();
34
35private:
36 CPPUNIT_TEST_SUITE( StringTestCase );
37 CPPUNIT_TEST( String );
38 CPPUNIT_TEST( PChar );
39 CPPUNIT_TEST( Format );
40 CPPUNIT_TEST( Constructors );
41#if wxUSE_WCHAR_T
42 CPPUNIT_TEST( ConstructorsWithConversion );
43 CPPUNIT_TEST( Conversion );
44 CPPUNIT_TEST( ConversionUTF7 );
45 CPPUNIT_TEST( ConversionUTF8 );
46#endif // wxUSE_WCHAR_T
47 CPPUNIT_TEST( Extraction );
48 CPPUNIT_TEST( Find );
49 CPPUNIT_TEST( Tokenizer );
50 CPPUNIT_TEST( TokenizerGetPosition );
51 CPPUNIT_TEST( Replace );
52 CPPUNIT_TEST( Match );
53 CPPUNIT_TEST( CaseChanges );
54 CPPUNIT_TEST( Compare );
55 CPPUNIT_TEST( CompareNoCase );
56 CPPUNIT_TEST( ToLong );
57 CPPUNIT_TEST( ToULong );
58 CPPUNIT_TEST( ToDouble );
59 CPPUNIT_TEST_SUITE_END();
60
61 void String();
62 void PChar();
63 void Format();
64 void Constructors();
65#if wxUSE_WCHAR_T
66 void ConstructorsWithConversion();
67 void Conversion();
68 void ConversionUTF7();
69 void ConversionUTF8();
70#endif // wxUSE_WCHAR_T
71 void Extraction();
72 void Find();
73 void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode );
74 void Tokenizer();
75 void TokenizerGetPosition();
76 void Replace();
77 void Match();
78 void CaseChanges();
79 void Compare();
80 void CompareNoCase();
81 void ToLong();
82 void ToULong();
83 void ToDouble();
84
85#if wxUSE_WCHAR_T
86 // test if converting s using the given encoding gives ws and vice versa
87 //
88 // if either of the first 2 arguments is NULL, the conversion is supposed
89 // to fail
90 void DoTestConversion(const char *s, const wchar_t *w, wxCSConv& conv);
91#endif // wxUSE_WCHAR_T
92
93 DECLARE_NO_COPY_CLASS(StringTestCase)
94};
95
96// register in the unnamed registry so that these tests are run by default
97CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase );
98
99// also include in it's own registry so that these tests can be run alone
100CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" );
101
102StringTestCase::StringTestCase()
103{
104}
105
106void StringTestCase::String()
107{
108 wxString a, b, c;
109
110 a.reserve (128);
111 b.reserve (128);
112 c.reserve (128);
113
114 for (int i = 0; i < 2; ++i)
115 {
116 a = _T("Hello");
117 b = _T(" world");
118 c = _T("! How'ya doin'?");
119 a += b;
120 a += c;
121 c = _T("Hello world! What's up?");
122 CPPUNIT_ASSERT( c != a );
123 }
124}
125
126void StringTestCase::PChar()
127{
128 wxChar a [128];
129 wxChar b [128];
130 wxChar c [128];
131
132 for (int i = 0; i < 2; ++i)
133 {
134 wxStrcpy (a, _T("Hello"));
135 wxStrcpy (b, _T(" world"));
136 wxStrcpy (c, _T("! How'ya doin'?"));
137 wxStrcat (a, b);
138 wxStrcat (a, c);
139 wxStrcpy (c, _T("Hello world! What's up?"));
140 CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 );
141 }
142}
143
144void StringTestCase::Format()
145{
146 wxString s1,s2;
147 s1.Printf(_T("%03d"), 18);
148 CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) );
149 s2.Printf(_T("Number 18: %s\n"), s1.c_str());
150 CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) );
151}
152
153void StringTestCase::Constructors()
154{
155 #define TEST_CTOR(args, res) \
156 { \
157 wxString s args ; \
158 CPPUNIT_ASSERT( s == res ); \
159 }
160
161 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
162 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
163 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
164
165 static const wxChar *s = _T("?really!");
166 const wxChar *start = wxStrchr(s, _T('r'));
167 const wxChar *end = wxStrchr(s, _T('!'));
168 TEST_CTOR((start, end), _T("really"));
169}
170
171#if wxUSE_WCHAR_T
172void StringTestCase::ConstructorsWithConversion()
173{
174