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