]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/strings.cpp
file dialog with wxMULTIPLE style still doesn't allow to select multiple files but...
[wxWidgets.git] / tests / strings / strings.cpp
CommitLineData
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
8899b155 14#include "testprec.h"
1cd53e88
VS
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
1cd53e88
VS
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 );
ad3fca67
VS
41#if wxUSE_WCHAR_T
42 CPPUNIT_TEST( ConstructorsWithConversion );
265d5cce 43 CPPUNIT_TEST( Conversion );
c20d8682 44 CPPUNIT_TEST( ConversionUTF7 );
ec54fe9e
VZ
45 CPPUNIT_TEST( ConversionUTF8 );
46#endif // wxUSE_WCHAR_T
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();
265d5cce 64 void Conversion();
c20d8682 65 void ConversionUTF7();
ec54fe9e
VZ
66 void ConversionUTF8();
67#endif // wxUSE_WCHAR_T
1cd53e88
VS
68 void Extraction();
69 void Find();
0a199299 70 void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode );
1cd53e88 71 void Tokenizer();
76c6fcbc 72 void TokenizerGetPosition();
1cd53e88
VS
73 void Replace();
74 void Match();
bd7f096d 75 void CaseChanges();
dcb68102
RN
76 void Compare();
77 void CompareNoCase();
1cd53e88 78
00b34ed7
VZ
79#if wxUSE_WCHAR_T
80 // test if converting s using the given encoding gives ws and vice versa
81 //
82 // if either of the first 2 arguments is NULL, the conversion is supposed
83 // to fail
84 void DoTestConversion(const char *s, const wchar_t *w, wxCSConv& conv);
85#endif // wxUSE_WCHAR_T
86
1cd53e88
VS
87 DECLARE_NO_COPY_CLASS(StringTestCase)
88};
89
90// register in the unnamed registry so that these tests are run by default
91CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase );
92
93// also include in it's own registry so that these tests can be run alone
94CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" );
95
96StringTestCase::StringTestCase()
97{
98}
99
100void StringTestCase::String()
101{
102 wxString a, b, c;
103
104 a.reserve (128);
105 b.reserve (128);
106 c.reserve (128);
107
108 for (int i = 0; i < 2; ++i)
109 {
110 a = _T("Hello");
111 b = _T(" world");
112 c = _T("! How'ya doin'?");
113 a += b;
114 a += c;
115 c = _T("Hello world! What's up?");
116 CPPUNIT_ASSERT( c != a );
117 }
118}
119
120void StringTestCase::PChar()
121{
122 wxChar a [128];
123 wxChar b [128];
124 wxChar c [128];
125
126 for (int i = 0; i < 2; ++i)
127 {
128 wxStrcpy (a, _T("Hello"));
129 wxStrcpy (b, _T(" world"));
130 wxStrcpy (c, _T("! How'ya doin'?"));
131 wxStrcat (a, b);
132 wxStrcat (a, c);
133 wxStrcpy (c, _T("Hello world! What's up?"));
134 CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 );
135 }
136}
137
138void StringTestCase::Format()
139{
140 wxString s1,s2;
141 s1.Printf(_T("%03d"), 18);
142 CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) );
143 s2.Printf(_T("Number 18: %s\n"), s1.c_str());
144 CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) );
145}
146
147void StringTestCase::Constructors()
148{
149 #define TEST_CTOR(args, res) \
150 { \
151 wxString s args ; \
152 CPPUNIT_ASSERT( s == res ); \
153 }
154
155 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
156 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
157 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
158
159 static const wxChar *s = _T("?really!");
160 const wxChar *start = wxStrchr(s, _T('r'));
161 const wxChar *end = wxStrchr(s, _T('!'));
162 TEST_CTOR((start, end), _T("really"));
163}
164
ad3fca67
VS
165#if wxUSE_WCHAR_T
166void StringTestCase::ConstructorsWithConversion()
167{
15e2adbd
VZ
168