~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Foundation/testsuite/src/StringTokenizerTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// StringTokenizerTest.cpp
 
3
//
 
4
// $Id: //poco/1.2/Foundation/testsuite/src/StringTokenizerTest.cpp#1 $
 
5
//
 
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
7
// and Contributors.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person or organization
 
10
// obtaining a copy of the software and accompanying documentation covered by
 
11
// this license (the "Software") to use, reproduce, display, distribute,
 
12
// execute, and transmit the Software, and to prepare derivative works of the
 
13
// Software, and to permit third-parties to whom the Software is furnished to
 
14
// do so, all subject to the following:
 
15
// 
 
16
// The copyright notices in the Software and this entire statement, including
 
17
// the above license grant, this restriction and the following disclaimer,
 
18
// must be included in all copies of the Software, in whole or in part, and
 
19
// all derivative works of the Software, unless such copies or derivative
 
20
// works are solely in the form of machine-executable object code generated by
 
21
// a source language processor.
 
22
// 
 
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
29
// DEALINGS IN THE SOFTWARE.
 
30
//
 
31
 
 
32
 
 
33
#include "StringTokenizerTest.h"
 
34
#include "CppUnit/TestCaller.h"
 
35
#include "CppUnit/TestSuite.h"
 
36
#include "Poco/StringTokenizer.h"
 
37
 
 
38
 
 
39
using Poco::StringTokenizer;
 
40
 
 
41
 
 
42
StringTokenizerTest::StringTokenizerTest(const std::string& name): CppUnit::TestCase(name)
 
43
{
 
44
}
 
45
 
 
46
 
 
47
StringTokenizerTest::~StringTokenizerTest()
 
48
{
 
49
}
 
50
 
 
51
 
 
52
void StringTokenizerTest::testStringTokenizer()
 
53
{
 
54
        {
 
55
                StringTokenizer st("", "");
 
56
                assert (st.begin() == st.end());
 
57
        }
 
58
        {
 
59
                StringTokenizer st("", "", StringTokenizer::TOK_IGNORE_EMPTY);
 
60
                assert (st.begin() == st.end());
 
61
        }
 
62
        {
 
63
                StringTokenizer st("", "", StringTokenizer::TOK_TRIM);
 
64
                assert (st.begin() == st.end());
 
65
        }
 
66
        {
 
67
                StringTokenizer st("", "", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
68
                assert (st.begin() == st.end());
 
69
        }
 
70
        {
 
71
                StringTokenizer st("abc", "");
 
72
                StringTokenizer::Iterator it = st.begin();
 
73
                assert (it != st.end());
 
74
                assert (*it++ == "abc");
 
75
                assert (it == st.end());
 
76
        }       
 
77
        {
 
78
                StringTokenizer st("abc ", "", StringTokenizer::TOK_TRIM);
 
79
                StringTokenizer::Iterator it = st.begin();
 
80
                assert (it != st.end());
 
81
                assert (*it++ == "abc");
 
82
                assert (it == st.end());
 
83
        }       
 
84
        {
 
85
                StringTokenizer st("  abc  ", "", StringTokenizer::TOK_TRIM);
 
86
                StringTokenizer::Iterator it = st.begin();
 
87
                assert (it != st.end());
 
88
                assert (*it++ == "abc");
 
89
                assert (it == st.end());
 
90
        }       
 
91
        {
 
92
                StringTokenizer st("  abc", "", StringTokenizer::TOK_TRIM);
 
93
                StringTokenizer::Iterator it = st.begin();
 
94
                assert (it != st.end());
 
95
                assert (*it++ == "abc");
 
96
                assert (it == st.end());
 
97
        }       
 
98
        {
 
99
                StringTokenizer st("abc", "b");
 
100
                StringTokenizer::Iterator it = st.begin();
 
101
                assert (it != st.end());
 
102
                assert (*it++ == "a");
 
103
                assert (it != st.end());
 
104
                assert (*it++ == "c");
 
105
                assert (it == st.end());
 
106
        }       
 
107
        {
 
108
                StringTokenizer st("abc", "b", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
109
                StringTokenizer::Iterator it = st.begin();
 
110
                assert (it != st.end());
 
111
                assert (*it++ == "a");
 
112
                assert (it != st.end());
 
113
                assert (*it++ == "c");
 
114
                assert (it == st.end());
 
115
        }       
 
116
        {
 
117
                StringTokenizer st("abc", "bc");
 
118
                StringTokenizer::Iterator it = st.begin();
 
119
                assert (it != st.end());
 
120
                assert (*it++ == "a");
 
121
                assert (it != st.end());
 
122
                assert (*it++ == "");
 
123
                assert (it == st.end());
 
124
        }       
 
125
        {
 
126
                StringTokenizer st("abc", "bc", StringTokenizer::TOK_TRIM);
 
127
                StringTokenizer::Iterator it = st.begin();
 
128
                assert (it != st.end());
 
129
                assert (*it++ == "a");
 
130
                assert (it != st.end());
 
131
                assert (*it++ == "");
 
132
                assert (it == st.end());
 
133
        }       
 
134
        {
 
135
                StringTokenizer st("abc", "bc", StringTokenizer::TOK_IGNORE_EMPTY);
 
136
                StringTokenizer::Iterator it = st.begin();
 
137
                assert (it != st.end());
 
138
                assert (*it++ == "a");
 
139
                assert (it == st.end());
 
140
        }       
 
141
        {
 
142
                StringTokenizer st("abc", "bc", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
143
                StringTokenizer::Iterator it = st.begin();
 
144
                assert (it != st.end());
 
145
                assert (*it++ == "a");
 
146
                assert (it == st.end());
 
147
        }       
 
148
        {
 
149
                StringTokenizer st("abc", "bc", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
150
                StringTokenizer::Iterator it = st.begin();
 
151
                assert (it != st.end());
 
152
                assert (*it++ == "a");
 
153
                assert (it == st.end());
 
154
        }       
 
155
        {
 
156
                StringTokenizer st("a a,c c", ",");
 
157
                StringTokenizer::Iterator it = st.begin();
 
158
                assert (it != st.end());
 
159
                assert (*it++ == "a a");
 
160
                assert (it != st.end());
 
161
                assert (*it++ == "c c");
 
162
                assert (it == st.end());
 
163
        }       
 
164
        {
 
165
                StringTokenizer st("a a,c c", ",", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
166
                StringTokenizer::Iterator it = st.begin();
 
167
                assert (it != st.end());
 
168
                assert (*it++ == "a a");
 
169
                assert (it != st.end());
 
170
                assert (*it++ == "c c");
 
171
                assert (it == st.end());
 
172
        }       
 
173
        {
 
174
                StringTokenizer st(" a a , , c c ", ",");
 
175
                StringTokenizer::Iterator it = st.begin();
 
176
                assert (it != st.end());
 
177
                assert (*it++ == " a a ");
 
178
                assert (it != st.end());
 
179
                assert (*it++ == " ");
 
180
                assert (it != st.end());
 
181
                assert (*it++ == " c c ");
 
182
                assert (it == st.end());
 
183
        }       
 
184
        {
 
185
                StringTokenizer st(" a a , , c c ", ",", StringTokenizer::TOK_TRIM);
 
186
                StringTokenizer::Iterator it = st.begin();
 
187
                assert (it != st.end());
 
188
                assert (*it++ == "a a");
 
189
                assert (it != st.end());
 
190
                assert (*it++ == "");
 
191
                assert (it != st.end());
 
192
                assert (*it++ == "c c");
 
193
                assert (it == st.end());
 
194
        }       
 
195
        {
 
196
                StringTokenizer st(" a a , , c c ", ",", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
197
                StringTokenizer::Iterator it = st.begin();
 
198
                assert (it != st.end());
 
199
                assert (*it++ == "a a");
 
200
                assert (it != st.end());
 
201
                assert (*it++ == "c c");
 
202
                assert (it == st.end());
 
203
        }       
 
204
        {
 
205
                StringTokenizer st("abc,def,,ghi , jk,  l ", ",", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
206
                StringTokenizer::Iterator it = st.begin();
 
207
                assert (it != st.end());
 
208
                assert (*it++ == "abc");
 
209
                assert (it != st.end());
 
210
                assert (*it++ == "def");
 
211
                assert (it != st.end());
 
212
                assert (*it++ == "ghi");
 
213
                assert (it != st.end());
 
214
                assert (*it++ == "jk");
 
215
                assert (it != st.end());
 
216
                assert (*it++ == "l");
 
217
                assert (it == st.end());
 
218
        }       
 
219
        {
 
220
                StringTokenizer st("abc,def,,ghi // jk,  l ", ",/", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
221
                StringTokenizer::Iterator it = st.begin();
 
222
                assert (it != st.end());
 
223
                assert (*it++ == "abc");
 
224
                assert (it != st.end());
 
225
                assert (*it++ == "def");
 
226
                assert (it != st.end());
 
227
                assert (*it++ == "ghi");
 
228
                assert (it != st.end());
 
229
                assert (*it++ == "jk");
 
230
                assert (it != st.end());
 
231
                assert (*it++ == "l");
 
232
                assert (it == st.end());
 
233
        }       
 
234
        {
 
235
                StringTokenizer st("a/bc,def,,ghi // jk,  l ", ",/", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
236
                StringTokenizer::Iterator it = st.begin();
 
237
                assert (it != st.end());
 
238
                assert (*it++ == "a");
 
239
                assert (it != st.end());
 
240
                assert (*it++ == "bc");
 
241
                assert (it != st.end());
 
242
                assert (*it++ == "def");
 
243
                assert (it != st.end());
 
244
                assert (*it++ == "ghi");
 
245
                assert (it != st.end());
 
246
                assert (*it++ == "jk");
 
247
                assert (it != st.end());
 
248
                assert (*it++ == "l");
 
249
                assert (it == st.end());
 
250
        }
 
251
        {
 
252
                StringTokenizer st(",ab,cd,", ",");
 
253
                StringTokenizer::Iterator it = st.begin();
 
254
                assert (it != st.end());
 
255
                assert (*it++ == "");
 
256
                assert (it != st.end());
 
257
                assert (*it++ == "ab");
 
258
                assert (it != st.end());
 
259
                assert (*it++ == "cd");
 
260
                assert (it == st.end());
 
261
        }
 
262
        {
 
263
                StringTokenizer st(",ab,cd,", ",", StringTokenizer::TOK_IGNORE_EMPTY);
 
264
                StringTokenizer::Iterator it = st.begin();
 
265
                assert (it != st.end());
 
266
                assert (*it++ == "ab");
 
267
                assert (it != st.end());
 
268
                assert (*it++ == "cd");
 
269
                assert (it == st.end());
 
270
        }
 
271
        {
 
272
                StringTokenizer st(" , ab , cd , ", ",", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
273
                StringTokenizer::Iterator it = st.begin();
 
274
                assert (it != st.end());
 
275
                assert (*it++ == "ab");
 
276
                assert (it != st.end());
 
277
                assert (*it++ == "cd");
 
278
                assert (it == st.end());
 
279
        }
 
280
        {
 
281
                StringTokenizer st("1 : 2 , : 3 ", ":,", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
 
282
                assert (st.count() == 3);
 
283
                assert (st[0] == "1");
 
284
                assert (st[1] == "2");
 
285
                assert (st[2] == "3");
 
286
        }
 
287
}
 
288
 
 
289
 
 
290
void StringTokenizerTest::setUp()
 
291
{
 
292
}
 
293
 
 
294
 
 
295
void StringTokenizerTest::tearDown()
 
296
{
 
297
}
 
298
 
 
299
 
 
300
CppUnit::Test* StringTokenizerTest::suite()
 
301
{
 
302
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("StringTokenizerTest");
 
303
 
 
304
        CppUnit_addTest(pSuite, StringTokenizerTest, testStringTokenizer);
 
305
 
 
306
        return pSuite;
 
307
}