]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/strings.cpp
don't duplicate code checking for X for X11 and Motif ports; filter out -RNONE from...
[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
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
32class StringTestCase : public CppUnit::TestCase
33{
34public:
35 StringTestCase();
36
37private:
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
1cd53e88
VS
46 CPPUNIT_TEST( Extraction );
47 CPPUNIT_TEST( Find );
48 CPPUNIT_TEST( Tokenizer );
49 CPPUNIT_TEST( Replace );
50 CPPUNIT_TEST( Match );
bd7f096d 51 CPPUNIT_TEST( CaseChanges );
1cd53e88
VS
52 CPPUNIT_TEST_SUITE_END();
53
54 void String();
55 void PChar();
56 void Format();
57 void Constructors();
ad3fca67
VS
58#if wxUSE_WCHAR_T
59 void ConstructorsWithConversion();
60#endif
1cd53e88
VS
61 void Extraction();
62 void Find();
0a199299 63 void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode );
1cd53e88
VS
64 void Tokenizer();
65 void Replace();
66 void Match();
bd7f096d 67 void CaseChanges();
1cd53e88
VS
68
69 DECLARE_NO_COPY_CLASS(StringTestCase)
70};
71
72// register in the unnamed registry so that these tests are run by default
73CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase );
74
75// also include in it's own registry so that these tests can be run alone
76CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" );
77
78StringTestCase::StringTestCase()
79{
80}
81
82void StringTestCase::String()
83{
84 wxString a, b, c;
85
86 a.reserve (128);
87 b.reserve (128);
88 c.reserve (128);
89
90 for (int i = 0; i < 2; ++i)
91 {
92 a = _T("Hello");
93 b = _T(" world");
94 c = _T("! How'ya doin'?");
95 a += b;
96 a += c;
97 c = _T("Hello world! What's up?");
98 CPPUNIT_ASSERT( c != a );
99 }
100}
101
102void StringTestCase::PChar()
103{
104 wxChar a [128];
105 wxChar b [128];
106 wxChar c [128];
107
108 for (int i = 0; i < 2; ++i)
109 {
110 wxStrcpy (a, _T("Hello"));
111 wxStrcpy (b, _T(" world"));
112 wxStrcpy (c, _T("! How'ya doin'?"));
113 wxStrcat (a, b);
114 wxStrcat (a, c);
115 wxStrcpy (c, _T("Hello world! What's up?"));
116 CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 );
117 }
118}
119
120void StringTestCase::Format()
121{
122 wxString s1,s2;
123 s1.Printf(_T("%03d"), 18);
124 CPPUNIT_ASSERT( s1 == wxString::Format(_T("%03d"), 18) );
125 s2.Printf(_T("Number 18: %s\n"), s1.c_str());
126 CPPUNIT_ASSERT( s2 == wxString::Format(_T("Number 18: %s\n"), s1.c_str()) );
127}
128
129void StringTestCase::Constructors()
130{
131 #define TEST_CTOR(args, res) \
132 { \
133 wxString s args ; \
134 CPPUNIT_ASSERT( s == res ); \
135 }
136
137 TEST_CTOR((_T('Z'), 4), _T("ZZZZ"));
138 TEST_CTOR((_T("Hello"), 4), _T("Hell"));
139 TEST_CTOR((_T("Hello"), 5), _T("Hello"));
140
141 static const wxChar *s = _T("?really!");
142 const wxChar *start = wxStrchr(s, _T('r'));
143 const wxChar *end = wxStrchr(s, _T('!'));
144 TEST_CTOR((start, end), _T("really"));
145}
146
ad3fca67
VS
147#if wxUSE_WCHAR_T
148void StringTestCase::ConstructorsWithConversion()
149{
150