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