2
// StringTokenizerTest.cpp
4
// $Id: //poco/1.2/Foundation/testsuite/src/StringTokenizerTest.cpp#1 $
6
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
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:
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.
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.
33
#include "StringTokenizerTest.h"
34
#include "CppUnit/TestCaller.h"
35
#include "CppUnit/TestSuite.h"
36
#include "Poco/StringTokenizer.h"
39
using Poco::StringTokenizer;
42
StringTokenizerTest::StringTokenizerTest(const std::string& name): CppUnit::TestCase(name)
47
StringTokenizerTest::~StringTokenizerTest()
52
void StringTokenizerTest::testStringTokenizer()
55
StringTokenizer st("", "");
56
assert (st.begin() == st.end());
59
StringTokenizer st("", "", StringTokenizer::TOK_IGNORE_EMPTY);
60
assert (st.begin() == st.end());
63
StringTokenizer st("", "", StringTokenizer::TOK_TRIM);
64
assert (st.begin() == st.end());
67
StringTokenizer st("", "", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
68
assert (st.begin() == st.end());
71
StringTokenizer st("abc", "");
72
StringTokenizer::Iterator it = st.begin();
73
assert (it != st.end());
74
assert (*it++ == "abc");
75
assert (it == st.end());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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");
290
void StringTokenizerTest::setUp()
295
void StringTokenizerTest::tearDown()
300
CppUnit::Test* StringTokenizerTest::suite()
302
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("StringTokenizerTest");
304
CppUnit_addTest(pSuite, StringTokenizerTest, testStringTokenizer);