1 | // |
2 | // PathTest.cpp |
3 | // |
4 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #include "PathTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/Path.h" |
15 | #include "Poco/Exception.h" |
16 | #include "Poco/Random.h" |
17 | #include "Poco/Environment.h" |
18 | #include <iostream> |
19 | |
20 | #if defined(POCO_OS_FAMILY_WINDOWS) |
21 | #if defined(_WIN32_WCE) |
22 | #include "Poco/Path_WINCE.h" |
23 | #else |
24 | #include "Poco/Path_WIN32.h" |
25 | #endif |
26 | #endif |
27 | |
28 | using Poco::Path; |
29 | using Poco::PathSyntaxException; |
30 | using Poco::Environment; |
31 | using std::clog; |
32 | using std::endl; |
33 | |
34 | PathTest::PathTest(const std::string& rName): CppUnit::TestCase(rName) |
35 | { |
36 | } |
37 | |
38 | |
39 | PathTest::~PathTest() |
40 | { |
41 | } |
42 | |
43 | |
44 | void PathTest::testParseUnix1() |
45 | { |
46 | Path p; |
47 | p.parse("" , Path::PATH_UNIX); |
48 | assertTrue (p.isRelative()); |
49 | assertTrue (!p.isAbsolute()); |
50 | assertTrue (p.depth() == 0); |
51 | assertTrue (p.isDirectory()); |
52 | assertTrue (!p.isFile()); |
53 | assertTrue (p.toString(Path::PATH_UNIX) == "" ); |
54 | |
55 | p.parse("/" , Path::PATH_UNIX); |
56 | assertTrue (!p.isRelative()); |
57 | assertTrue (p.isAbsolute()); |
58 | assertTrue (p.depth() == 0); |
59 | assertTrue (p.isDirectory()); |
60 | assertTrue (!p.isFile()); |
61 | assertTrue (p.toString(Path::PATH_UNIX) == "/" ); |
62 | |
63 | p.parse("/usr" , Path::PATH_UNIX); |
64 | assertTrue (!p.isRelative()); |
65 | assertTrue (p.isAbsolute()); |
66 | assertTrue (p.depth() == 0); |
67 | assertTrue (!p.isDirectory()); |
68 | assertTrue (p.isFile()); |
69 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr" ); |
70 | |
71 | p.parse("/usr/" , Path::PATH_UNIX); |
72 | assertTrue (!p.isRelative()); |
73 | assertTrue (p.isAbsolute()); |
74 | assertTrue (p.depth() == 1); |
75 | assertTrue (p[0] == "usr" ); |
76 | assertTrue (p.isDirectory()); |
77 | assertTrue (!p.isFile()); |
78 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/" ); |
79 | |
80 | p.parse("usr/" , Path::PATH_UNIX); |
81 | assertTrue (p.isRelative()); |
82 | assertTrue (!p.isAbsolute()); |
83 | assertTrue (p.depth() == 1); |
84 | assertTrue (p[0] == "usr" ); |
85 | assertTrue (p.isDirectory()); |
86 | assertTrue (!p.isFile()); |
87 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/" ); |
88 | |
89 | p.parse("usr" , Path::PATH_UNIX); |
90 | assertTrue (p.isRelative()); |
91 | assertTrue (!p.isAbsolute()); |
92 | assertTrue (p.depth() == 0); |
93 | assertTrue (p[0] == "usr" ); |
94 | assertTrue (!p.isDirectory()); |
95 | assertTrue (p.isFile()); |
96 | assertTrue (p.toString(Path::PATH_UNIX) == "usr" ); |
97 | |
98 | p.parse("/usr/local" , Path::PATH_UNIX); |
99 | assertTrue (!p.isRelative()); |
100 | assertTrue (p.isAbsolute()); |
101 | assertTrue (p.depth() == 1); |
102 | assertTrue (p[0] == "usr" ); |
103 | assertTrue (p[1] == "local" ); |
104 | assertTrue (!p.isDirectory()); |
105 | assertTrue (p.isFile()); |
106 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local" ); |
107 | } |
108 | |
109 | |
110 | void PathTest::testParseUnix2() |
111 | { |
112 | Path p; |
113 | p.parse("/usr/local/" , Path::PATH_UNIX); |
114 | assertTrue (!p.isRelative()); |
115 | assertTrue (p.isAbsolute()); |
116 | assertTrue (p.depth() == 2); |
117 | assertTrue (p[0] == "usr" ); |
118 | assertTrue (p[1] == "local" ); |
119 | assertTrue (p.isDirectory()); |
120 | assertTrue (!p.isFile()); |
121 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/" ); |
122 | |
123 | p.parse("usr/local/" , Path::PATH_UNIX); |
124 | assertTrue (p.isRelative()); |
125 | assertTrue (!p.isAbsolute()); |
126 | assertTrue (p.depth() == 2); |
127 | assertTrue (p[0] == "usr" ); |
128 | assertTrue (p[1] == "local" ); |
129 | assertTrue (p.isDirectory()); |
130 | assertTrue (!p.isFile()); |
131 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/local/" ); |
132 | |
133 | p.parse("usr/local" , Path::PATH_UNIX); |
134 | assertTrue (p.isRelative()); |
135 | assertTrue (!p.isAbsolute()); |
136 | assertTrue (p.depth() == 1); |
137 | assertTrue (p[0] == "usr" ); |
138 | assertTrue (p[1] == "local" ); |
139 | assertTrue (!p.isDirectory()); |
140 | assertTrue (p.isFile()); |
141 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/local" ); |
142 | |
143 | p.parse("/usr/local/bin" , Path::PATH_UNIX); |
144 | assertTrue (!p.isRelative()); |
145 | assertTrue (p.isAbsolute()); |
146 | assertTrue (p.depth() == 2); |
147 | assertTrue (p[0] == "usr" ); |
148 | assertTrue (p[1] == "local" ); |
149 | assertTrue (p[2] == "bin" ); |
150 | assertTrue (!p.isDirectory()); |
151 | assertTrue (p.isFile()); |
152 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin" ); |
153 | |
154 | p.parse("/usr/local/bin/" , Path::PATH_UNIX); |
155 | assertTrue (!p.isRelative()); |
156 | assertTrue (p.isAbsolute()); |
157 | assertTrue (p.depth() == 3); |
158 | assertTrue (p[0] == "usr" ); |
159 | assertTrue (p[1] == "local" ); |
160 | assertTrue (p[2] == "bin" ); |
161 | assertTrue (p.isDirectory()); |
162 | assertTrue (!p.isFile()); |
163 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
164 | } |
165 | |
166 | |
167 | void PathTest::testParseUnix3() |
168 | { |
169 | Path p; |
170 | p.parse("//usr/local/bin/" , Path::PATH_UNIX); |
171 | assertTrue (!p.isRelative()); |
172 | assertTrue (p.isAbsolute()); |
173 | assertTrue (p.depth() == 3); |
174 | assertTrue (p[0] == "usr" ); |
175 | assertTrue (p[1] == "local" ); |
176 | assertTrue (p[2] == "bin" ); |
177 | assertTrue (p.isDirectory()); |
178 | assertTrue (!p.isFile()); |
179 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
180 | |
181 | p.parse("/usr//local/bin/" , Path::PATH_UNIX); |
182 | assertTrue (!p.isRelative()); |
183 | assertTrue (p.isAbsolute()); |
184 | assertTrue (p.depth() == 3); |
185 | assertTrue (p[0] == "usr" ); |
186 | assertTrue (p[1] == "local" ); |
187 | assertTrue (p[2] == "bin" ); |
188 | assertTrue (p.isDirectory()); |
189 | assertTrue (!p.isFile()); |
190 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
191 | |
192 | p.parse("/usr/local//bin/" , Path::PATH_UNIX); |
193 | assertTrue (!p.isRelative()); |
194 | assertTrue (p.isAbsolute()); |
195 | assertTrue (p.depth() == 3); |
196 | assertTrue (p[0] == "usr" ); |
197 | assertTrue (p[1] == "local" ); |
198 | assertTrue (p[2] == "bin" ); |
199 | assertTrue (p.isDirectory()); |
200 | assertTrue (!p.isFile()); |
201 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
202 | |
203 | p.parse("/usr/local/bin//" , Path::PATH_UNIX); |
204 | assertTrue (!p.isRelative()); |
205 | assertTrue (p.isAbsolute()); |
206 | assertTrue (p.depth() == 3); |
207 | assertTrue (p[0] == "usr" ); |
208 | assertTrue (p[1] == "local" ); |
209 | assertTrue (p[2] == "bin" ); |
210 | assertTrue (p.isDirectory()); |
211 | assertTrue (!p.isFile()); |
212 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
213 | |
214 | p.parse("/usr/local/./bin/" , Path::PATH_UNIX); |
215 | assertTrue (!p.isRelative()); |
216 | assertTrue (p.isAbsolute()); |
217 | assertTrue (p.depth() == 3); |
218 | assertTrue (p[0] == "usr" ); |
219 | assertTrue (p[1] == "local" ); |
220 | assertTrue (p[2] == "bin" ); |
221 | assertTrue (p.isDirectory()); |
222 | assertTrue (!p.isFile()); |
223 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
224 | |
225 | p.parse("./usr/local/bin/" , Path::PATH_UNIX); |
226 | assertTrue (p.isRelative()); |
227 | assertTrue (!p.isAbsolute()); |
228 | assertTrue (p.depth() == 3); |
229 | assertTrue (p[0] == "usr" ); |
230 | assertTrue (p[1] == "local" ); |
231 | assertTrue (p[2] == "bin" ); |
232 | assertTrue (p.isDirectory()); |
233 | assertTrue (!p.isFile()); |
234 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/local/bin/" ); |
235 | |
236 | p.parse("./usr/local/bin/./" , Path::PATH_UNIX); |
237 | assertTrue (p.isRelative()); |
238 | assertTrue (!p.isAbsolute()); |
239 | assertTrue (p.depth() == 3); |
240 | assertTrue (p[0] == "usr" ); |
241 | assertTrue (p[1] == "local" ); |
242 | assertTrue (p[2] == "bin" ); |
243 | assertTrue (p.isDirectory()); |
244 | assertTrue (!p.isFile()); |
245 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/local/bin/" ); |
246 | |
247 | p.parse("./usr/local/bin/." , Path::PATH_UNIX); |
248 | assertTrue (p.isRelative()); |
249 | assertTrue (!p.isAbsolute()); |
250 | assertTrue (p.depth() == 3); |
251 | assertTrue (p[0] == "usr" ); |
252 | assertTrue (p[1] == "local" ); |
253 | assertTrue (p[2] == "bin" ); |
254 | assertTrue (!p.isDirectory()); |
255 | assertTrue (p.isFile()); |
256 | assertTrue (p.toString(Path::PATH_UNIX) == "usr/local/bin/." ); |
257 | } |
258 | |
259 | |
260 | void PathTest::testParseUnix4() |
261 | { |
262 | Path p; |
263 | p.parse("/usr/local/lib/../bin/" , Path::PATH_UNIX); |
264 | assertTrue (!p.isRelative()); |
265 | assertTrue (p.isAbsolute()); |
266 | assertTrue (p.depth() == 3); |
267 | assertTrue (p[0] == "usr" ); |
268 | assertTrue (p[1] == "local" ); |
269 | assertTrue (p[2] == "bin" ); |
270 | assertTrue (p.isDirectory()); |
271 | assertTrue (!p.isFile()); |
272 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
273 | |
274 | p.parse("/usr/local/lib/../bin/" , Path::PATH_UNIX); |
275 | assertTrue (!p.isRelative()); |
276 | assertTrue (p.isAbsolute()); |
277 | assertTrue (p.depth() == 3); |
278 | assertTrue (p[0] == "usr" ); |
279 | assertTrue (p[1] == "local" ); |
280 | assertTrue (p[2] == "bin" ); |
281 | assertTrue (p.isDirectory()); |
282 | assertTrue (!p.isFile()); |
283 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin/" ); |
284 | |
285 | p.parse("/usr/local/lib/../../" , Path::PATH_UNIX); |
286 | assertTrue (!p.isRelative()); |
287 | assertTrue (p.isAbsolute()); |
288 | assertTrue (p.depth() == 1); |
289 | assertTrue (p[0] == "usr" ); |
290 | assertTrue (p.isDirectory()); |
291 | assertTrue (!p.isFile()); |
292 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/" ); |
293 | |
294 | p.parse("/usr/local/lib/.." , Path::PATH_UNIX); |
295 | assertTrue (!p.isRelative()); |
296 | assertTrue (p.isAbsolute()); |
297 | assertTrue (p.depth() == 3); |
298 | assertTrue (p[0] == "usr" ); |
299 | assertTrue (p[1] == "local" ); |
300 | assertTrue (p[2] == "lib" ); |
301 | assertTrue (!p.isDirectory()); |
302 | assertTrue (p.isFile()); |
303 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/lib/.." ); |
304 | |
305 | p.parse("../usr/local/lib/" , Path::PATH_UNIX); |
306 | assertTrue (p.isRelative()); |
307 | assertTrue (!p.isAbsolute()); |
308 | assertTrue (p.depth() == 4); |
309 | assertTrue (p[0] == ".." ); |
310 | assertTrue (p[1] == "usr" ); |
311 | assertTrue (p[2] == "local" ); |
312 | assertTrue (p[3] == "lib" ); |
313 | assertTrue (p.isDirectory()); |
314 | assertTrue (!p.isFile()); |
315 | assertTrue (p.toString(Path::PATH_UNIX) == "../usr/local/lib/" ); |
316 | |
317 | p.parse("/usr/../lib/" , Path::PATH_UNIX); |
318 | assertTrue (!p.isRelative()); |
319 | assertTrue (p.isAbsolute()); |
320 | assertTrue (p.depth() == 1); |
321 | assertTrue (p[0] == "lib" ); |
322 | assertTrue (p.isDirectory()); |
323 | assertTrue (!p.isFile()); |
324 | assertTrue (p.toString(Path::PATH_UNIX) == "/lib/" ); |
325 | |
326 | p.parse("/usr/../../lib/" , Path::PATH_UNIX); |
327 | assertTrue (!p.isRelative()); |
328 | assertTrue (p.isAbsolute()); |
329 | assertTrue (p.depth() == 1); |
330 | assertTrue (p[0] == "lib" ); |
331 | assertTrue (p.isDirectory()); |
332 | assertTrue (!p.isFile()); |
333 | assertTrue (p.toString(Path::PATH_UNIX) == "/lib/" ); |
334 | |
335 | p.parse("local/../../lib/" , Path::PATH_UNIX); |
336 | assertTrue (p.isRelative()); |
337 | assertTrue (!p.isAbsolute()); |
338 | assertTrue (p.depth() == 2); |
339 | assertTrue (p[0] == ".." ); |
340 | assertTrue (p[1] == "lib" ); |
341 | assertTrue (p.isDirectory()); |
342 | assertTrue (!p.isFile()); |
343 | assertTrue (p.toString(Path::PATH_UNIX) == "../lib/" ); |
344 | |
345 | p.parse("a/b/c/d" , Path::PATH_UNIX); |
346 | assertTrue (p.isRelative()); |
347 | assertTrue (!p.isAbsolute()); |
348 | assertTrue (p.depth() == 3); |
349 | assertTrue (p[0] == "a" ); |
350 | assertTrue (p[1] == "b" ); |
351 | assertTrue (p[2] == "c" ); |
352 | assertTrue (!p.isDirectory()); |
353 | assertTrue (p.isFile()); |
354 | assertTrue (p.toString(Path::PATH_UNIX) == "a/b/c/d" ); |
355 | } |
356 | |
357 | |
358 | void PathTest::testParseUnix5() |
359 | { |
360 | Path p; |
361 | p.parse("/c:/windows/system32/" , Path::PATH_UNIX); |
362 | assertTrue (!p.isRelative()); |
363 | assertTrue (p.isAbsolute()); |
364 | assertTrue (p.getDevice() == "c" ); |
365 | assertTrue (p.depth() == 2); |
366 | assertTrue (p[0] == "windows" ); |
367 | assertTrue (p[1] == "system32" ); |
368 | assertTrue (p.isDirectory()); |
369 | assertTrue (!p.isFile()); |
370 | assertTrue (p.toString(Path::PATH_UNIX) == "/c:/windows/system32/" ); |
371 | } |
372 | |
373 | void PathTest::testExpandVariableFromPath() |
374 | { |
375 | #ifdef POCO_OS_FAMILY_WINDOWS |
376 | std::string pathWithoutVar = "\\usr\\share\\O1%%\\folder" ; |
377 | std::string pathWithVar = "%HOMEDRIVE%%HOMEPATH%\\folder" ; |
378 | std::string correctStringWithoutVar = "\\usr\\share\\O1%%\\folder" ; |
379 | #elif defined(POCO_OS_FAMILY_UNIX) |
380 | std::string pathWithoutVar = "/usr/share/O1\\$\\$/folder" ; |
381 | std::string pathWithVar = "${HOME}/folder" ; |
382 | std::string correctStringWithoutVar = "/usr/share/O1$$/folder" ; |
383 | #else |
384 | return; |
385 | #endif |
386 | |
387 | Poco::Path p; |
388 | std::string s = p.expand(pathWithoutVar); |
389 | assertTrue (s == correctStringWithoutVar); |
390 | s = p.expand(pathWithVar); |
391 | Poco::Path tmpPath = Poco::Path::home(); |
392 | tmpPath.append("folder" ); |
393 | clog << endl << "s =>" << s << '<' << endl; |
394 | clog << endl << "tmpPath.toString()=>" << tmpPath.toString() << '<' << endl; |
395 | assertTrue (s == tmpPath.toString()); |
396 | } |
397 | |
398 | void PathTest::testParseWindows1() |
399 | { |
400 | Path p; |
401 | p.parse("" , Path::PATH_WINDOWS); |
402 | assertTrue (p.isRelative()); |
403 | assertTrue (!p.isAbsolute()); |
404 | assertTrue (p.depth() == 0); |
405 | assertTrue (p.isDirectory()); |
406 | assertTrue (!p.isFile()); |
407 | assertTrue (p.toString(Path::PATH_WINDOWS) == "" ); |
408 | |
409 | p.parse("/" , Path::PATH_WINDOWS); |
410 | assertTrue (!p.isRelative()); |
411 | assertTrue (p.isAbsolute()); |
412 | assertTrue (p.depth() == 0); |
413 | assertTrue (p.isDirectory()); |
414 | assertTrue (!p.isFile()); |
415 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\" ); |
416 | |
417 | p.parse("\\" , Path::PATH_WINDOWS); |
418 | assertTrue (!p.isRelative()); |
419 | assertTrue (p.isAbsolute()); |
420 | assertTrue (p.depth() == 0); |
421 | assertTrue (p.isDirectory()); |
422 | assertTrue (!p.isFile()); |
423 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\" ); |
424 | |
425 | p.parse("/usr" , Path::PATH_WINDOWS); |
426 | assertTrue (!p.isRelative()); |
427 | assertTrue (p.isAbsolute()); |
428 | assertTrue (p.depth() == 0); |
429 | assertTrue (!p.isDirectory()); |
430 | assertTrue (p.isFile()); |
431 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr" ); |
432 | |
433 | p.parse("\\usr" , Path::PATH_WINDOWS); |
434 | assertTrue (!p.isRelative()); |
435 | assertTrue (p.isAbsolute()); |
436 | assertTrue (p.depth() == 0); |
437 | assertTrue (!p.isDirectory()); |
438 | assertTrue (p.isFile()); |
439 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr" ); |
440 | |
441 | p.parse("/usr/" , Path::PATH_WINDOWS); |
442 | assertTrue (!p.isRelative()); |
443 | assertTrue (p.isAbsolute()); |
444 | assertTrue (p.depth() == 1); |
445 | assertTrue (p[0] == "usr" ); |
446 | assertTrue (p.isDirectory()); |
447 | assertTrue (!p.isFile()); |
448 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\" ); |
449 | |
450 | p.parse("\\usr\\" , Path::PATH_WINDOWS); |
451 | assertTrue (!p.isRelative()); |
452 | assertTrue (p.isAbsolute()); |
453 | assertTrue (p.depth() == 1); |
454 | assertTrue (p[0] == "usr" ); |
455 | assertTrue (p.isDirectory()); |
456 | assertTrue (!p.isFile()); |
457 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\" ); |
458 | } |
459 | |
460 | |
461 | void PathTest::testParseWindows2() |
462 | { |
463 | Path p; |
464 | p.parse("usr/" , Path::PATH_WINDOWS); |
465 | assertTrue (p.isRelative()); |
466 | assertTrue (!p.isAbsolute()); |
467 | assertTrue (p.depth() == 1); |
468 | assertTrue (p[0] == "usr" ); |
469 | assertTrue (p.isDirectory()); |
470 | assertTrue (!p.isFile()); |
471 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\" ); |
472 | |
473 | p.parse("usr" , Path::PATH_WINDOWS); |
474 | assertTrue (p.isRelative()); |
475 | assertTrue (!p.isAbsolute()); |
476 | assertTrue (p.depth() == 0); |
477 | assertTrue (p[0] == "usr" ); |
478 | assertTrue (!p.isDirectory()); |
479 | assertTrue (p.isFile()); |
480 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr" ); |
481 | |
482 | p.parse("usr\\" , Path::PATH_WINDOWS); |
483 | assertTrue (p.isRelative()); |
484 | assertTrue (!p.isAbsolute()); |
485 | assertTrue (p.depth() == 1); |
486 | assertTrue (p[0] == "usr" ); |
487 | assertTrue (p.isDirectory()); |
488 | assertTrue (!p.isFile()); |
489 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\" ); |
490 | |
491 | p.parse("/usr/local" , Path::PATH_WINDOWS); |
492 | assertTrue (!p.isRelative()); |
493 | assertTrue (p.isAbsolute()); |
494 | assertTrue (p.depth() == 1); |
495 | assertTrue (p[0] == "usr" ); |
496 | assertTrue (p[1] == "local" ); |
497 | assertTrue (!p.isDirectory()); |
498 | assertTrue (p.isFile()); |
499 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local" ); |
500 | |
501 | p.parse("\\usr\\local" , Path::PATH_WINDOWS); |
502 | assertTrue (!p.isRelative()); |
503 | assertTrue (p.isAbsolute()); |
504 | assertTrue (p.depth() == 1); |
505 | assertTrue (p[0] == "usr" ); |
506 | assertTrue (p[1] == "local" ); |
507 | assertTrue (!p.isDirectory()); |
508 | assertTrue (p.isFile()); |
509 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local" ); |
510 | |
511 | p.parse("/usr/local/" , Path::PATH_WINDOWS); |
512 | assertTrue (!p.isRelative()); |
513 | assertTrue (p.isAbsolute()); |
514 | assertTrue (p.depth() == 2); |
515 | assertTrue (p[0] == "usr" ); |
516 | assertTrue (p[1] == "local" ); |
517 | assertTrue (p.isDirectory()); |
518 | assertTrue (!p.isFile()); |
519 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\" ); |
520 | |
521 | p.parse("usr/local/" , Path::PATH_WINDOWS); |
522 | assertTrue (p.isRelative()); |
523 | assertTrue (!p.isAbsolute()); |
524 | assertTrue (p.depth() == 2); |
525 | assertTrue (p[0] == "usr" ); |
526 | assertTrue (p[1] == "local" ); |
527 | assertTrue (p.isDirectory()); |
528 | assertTrue (!p.isFile()); |
529 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\local\\" ); |
530 | |
531 | p.parse("usr/local" , Path::PATH_WINDOWS); |
532 | assertTrue (p.isRelative()); |
533 | assertTrue (!p.isAbsolute()); |
534 | assertTrue (p.depth() == 1); |
535 | assertTrue (p[0] == "usr" ); |
536 | assertTrue (p[1] == "local" ); |
537 | assertTrue (!p.isDirectory()); |
538 | assertTrue (p.isFile()); |
539 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\local" ); |
540 | |
541 | p.parse("/usr/local/bin" , Path::PATH_WINDOWS); |
542 | assertTrue (!p.isRelative()); |
543 | assertTrue (p.isAbsolute()); |
544 | assertTrue (p.depth() == 2); |
545 | assertTrue (p[0] == "usr" ); |
546 | assertTrue (p[1] == "local" ); |
547 | assertTrue (p[2] == "bin" ); |
548 | assertTrue (!p.isDirectory()); |
549 | assertTrue (p.isFile()); |
550 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin" ); |
551 | |
552 | p.parse("/usr/local/bin/" , Path::PATH_WINDOWS); |
553 | assertTrue (!p.isRelative()); |
554 | assertTrue (p.isAbsolute()); |
555 | assertTrue (p.depth() == 3); |
556 | assertTrue (p[0] == "usr" ); |
557 | assertTrue (p[1] == "local" ); |
558 | assertTrue (p[2] == "bin" ); |
559 | assertTrue (p.isDirectory()); |
560 | assertTrue (!p.isFile()); |
561 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
562 | |
563 | p.parse("/usr//local/bin/" , Path::PATH_WINDOWS); |
564 | assertTrue (!p.isRelative()); |
565 | assertTrue (p.isAbsolute()); |
566 | assertTrue (p.depth() == 3); |
567 | assertTrue (p[0] == "usr" ); |
568 | assertTrue (p[1] == "local" ); |
569 | assertTrue (p[2] == "bin" ); |
570 | assertTrue (p.isDirectory()); |
571 | assertTrue (!p.isFile()); |
572 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
573 | |
574 | p.parse("/usr/local//bin/" , Path::PATH_WINDOWS); |
575 | assertTrue (!p.isRelative()); |
576 | assertTrue (p.isAbsolute()); |
577 | assertTrue (p.depth() == 3); |
578 | assertTrue (p[0] == "usr" ); |
579 | assertTrue (p[1] == "local" ); |
580 | assertTrue (p[2] == "bin" ); |
581 | assertTrue (p.isDirectory()); |
582 | assertTrue (!p.isFile()); |
583 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
584 | |
585 | p.parse("/usr/local/bin//" , Path::PATH_WINDOWS); |
586 | assertTrue (!p.isRelative()); |
587 | assertTrue (p.isAbsolute()); |
588 | assertTrue (p.depth() == 3); |
589 | assertTrue (p[0] == "usr" ); |
590 | assertTrue (p[1] == "local" ); |
591 | assertTrue (p[2] == "bin" ); |
592 | assertTrue (p.isDirectory()); |
593 | assertTrue (!p.isFile()); |
594 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
595 | } |
596 | |
597 | |
598 | void PathTest::testParseWindows3() |
599 | { |
600 | Path p; |
601 | p.parse("/usr/local/./bin/" , Path::PATH_WINDOWS); |
602 | assertTrue (!p.isRelative()); |
603 | assertTrue (p.isAbsolute()); |
604 | assertTrue (p.depth() == 3); |
605 | assertTrue (p[0] == "usr" ); |
606 | assertTrue (p[1] == "local" ); |
607 | assertTrue (p[2] == "bin" ); |
608 | assertTrue (p.isDirectory()); |
609 | assertTrue (!p.isFile()); |
610 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
611 | |
612 | p.parse("./usr/local/bin/" , Path::PATH_WINDOWS); |
613 | assertTrue (p.isRelative()); |
614 | assertTrue (!p.isAbsolute()); |
615 | assertTrue (p.depth() == 3); |
616 | assertTrue (p[0] == "usr" ); |
617 | assertTrue (p[1] == "local" ); |
618 | assertTrue (p[2] == "bin" ); |
619 | assertTrue (p.isDirectory()); |
620 | assertTrue (!p.isFile()); |
621 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\local\\bin\\" ); |
622 | |
623 | p.parse("./usr/local/bin/./" , Path::PATH_WINDOWS); |
624 | assertTrue (p.isRelative()); |
625 | assertTrue (!p.isAbsolute()); |
626 | assertTrue (p.depth() == 3); |
627 | assertTrue (p[0] == "usr" ); |
628 | assertTrue (p[1] == "local" ); |
629 | assertTrue (p[2] == "bin" ); |
630 | assertTrue (p.isDirectory()); |
631 | assertTrue (!p.isFile()); |
632 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\local\\bin\\" ); |
633 | |
634 | p.parse("./usr/local/bin/." , Path::PATH_WINDOWS); |
635 | assertTrue (p.isRelative()); |
636 | assertTrue (!p.isAbsolute()); |
637 | assertTrue (p.depth() == 3); |
638 | assertTrue (p[0] == "usr" ); |
639 | assertTrue (p[1] == "local" ); |
640 | assertTrue (p[2] == "bin" ); |
641 | assertTrue (!p.isDirectory()); |
642 | assertTrue (p.isFile()); |
643 | assertTrue (p.toString(Path::PATH_WINDOWS) == "usr\\local\\bin\\." ); |
644 | |
645 | p.parse("/usr/local/lib/../bin/" , Path::PATH_WINDOWS); |
646 | assertTrue (!p.isRelative()); |
647 | assertTrue (p.isAbsolute()); |
648 | assertTrue (p.depth() == 3); |
649 | assertTrue (p[0] == "usr" ); |
650 | assertTrue (p[1] == "local" ); |
651 | assertTrue (p[2] == "bin" ); |
652 | assertTrue (p.isDirectory()); |
653 | assertTrue (!p.isFile()); |
654 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
655 | |
656 | p.parse("/usr/local/lib/../bin/" , Path::PATH_WINDOWS); |
657 | assertTrue (!p.isRelative()); |
658 | assertTrue (p.isAbsolute()); |
659 | assertTrue (p.depth() == 3); |
660 | assertTrue (p[0] == "usr" ); |
661 | assertTrue (p[1] == "local" ); |
662 | assertTrue (p[2] == "bin" ); |
663 | assertTrue (p.isDirectory()); |
664 | assertTrue (!p.isFile()); |
665 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
666 | |
667 | p.parse("\\usr\\local\\lib\\..\\bin\\" , Path::PATH_WINDOWS); |
668 | assertTrue (!p.isRelative()); |
669 | assertTrue (p.isAbsolute()); |
670 | assertTrue (p.depth() == 3); |
671 | assertTrue (p[0] == "usr" ); |
672 | assertTrue (p[1] == "local" ); |
673 | assertTrue (p[2] == "bin" ); |
674 | assertTrue (p.isDirectory()); |
675 | assertTrue (!p.isFile()); |
676 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\bin\\" ); |
677 | |
678 | p.parse("/usr/local/lib/../../" , Path::PATH_WINDOWS); |
679 | assertTrue (!p.isRelative()); |
680 | assertTrue (p.isAbsolute()); |
681 | assertTrue (p.depth() == 1); |
682 | assertTrue (p[0] == "usr" ); |
683 | assertTrue (p.isDirectory()); |
684 | assertTrue (!p.isFile()); |
685 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\" ); |
686 | |
687 | p.parse("/usr/local/lib/.." , Path::PATH_WINDOWS); |
688 | assertTrue (!p.isRelative()); |
689 | assertTrue (p.isAbsolute()); |
690 | assertTrue (p.depth() == 3); |
691 | assertTrue (p[0] == "usr" ); |
692 | assertTrue (p[1] == "local" ); |
693 | assertTrue (p[2] == "lib" ); |
694 | assertTrue (!p.isDirectory()); |
695 | assertTrue (p.isFile()); |
696 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\usr\\local\\lib\\.." ); |
697 | |
698 | p.parse("../usr/local/lib/" , Path::PATH_WINDOWS); |
699 | assertTrue (p.isRelative()); |
700 | assertTrue (!p.isAbsolute()); |
701 | assertTrue (p.depth() == 4); |
702 | assertTrue (p[0] == ".." ); |
703 | assertTrue (p[1] == "usr" ); |
704 | assertTrue (p[2] == "local" ); |
705 | assertTrue (p[3] == "lib" ); |
706 | assertTrue (p.isDirectory()); |
707 | assertTrue (!p.isFile()); |
708 | assertTrue (p.toString(Path::PATH_WINDOWS) == "..\\usr\\local\\lib\\" ); |
709 | |
710 | p.parse("/usr/../lib/" , Path::PATH_WINDOWS); |
711 | assertTrue (!p.isRelative()); |
712 | assertTrue (p.isAbsolute()); |
713 | assertTrue (p.depth() == 1); |
714 | assertTrue (p[0] == "lib" ); |
715 | assertTrue (p.isDirectory()); |
716 | assertTrue (!p.isFile()); |
717 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\lib\\" ); |
718 | |
719 | p.parse("/usr/../../lib/" , Path::PATH_WINDOWS); |
720 | assertTrue (!p.isRelative()); |
721 | assertTrue (p.isAbsolute()); |
722 | assertTrue (p.depth() == 1); |
723 | assertTrue (p[0] == "lib" ); |
724 | assertTrue (p.isDirectory()); |
725 | assertTrue (!p.isFile()); |
726 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\lib\\" ); |
727 | |
728 | p.parse("local/../../lib/" , Path::PATH_WINDOWS); |
729 | assertTrue (p.isRelative()); |
730 | assertTrue (!p.isAbsolute()); |
731 | assertTrue (p.depth() == 2); |
732 | assertTrue (p[0] == ".." ); |
733 | assertTrue (p[1] == "lib" ); |
734 | assertTrue (p.isDirectory()); |
735 | assertTrue (!p.isFile()); |
736 | assertTrue (p.toString(Path::PATH_WINDOWS) == "..\\lib\\" ); |
737 | } |
738 | |
739 | |
740 | void PathTest::testParseWindows4() |
741 | { |
742 | Path p; |
743 | p.parse("\\\\server\\files" , Path::PATH_WINDOWS); |
744 | assertTrue (!p.isRelative()); |
745 | assertTrue (p.isAbsolute()); |
746 | assertTrue (p.depth() == 1); |
747 | assertTrue (p[0] == "files" ); |
748 | assertTrue (p.getNode() == "server" ); |
749 | assertTrue (p.isDirectory()); |
750 | assertTrue (!p.isFile()); |
751 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\" ); |
752 | |
753 | p.parse("\\\\server\\files\\" , Path::PATH_WINDOWS); |
754 | assertTrue (!p.isRelative()); |
755 | assertTrue (p.isAbsolute()); |
756 | assertTrue (p.depth() == 1); |
757 | assertTrue (p[0] == "files" ); |
758 | assertTrue (p.getNode() == "server" ); |
759 | assertTrue (p.isDirectory()); |
760 | assertTrue (!p.isFile()); |
761 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\" ); |
762 | |
763 | p.parse("\\\\server\\files\\file" , Path::PATH_WINDOWS); |
764 | assertTrue (!p.isRelative()); |
765 | assertTrue (p.isAbsolute()); |
766 | assertTrue (p.depth() == 1); |
767 | assertTrue (p[0] == "files" ); |
768 | assertTrue (p.getNode() == "server" ); |
769 | assertTrue (!p.isDirectory()); |
770 | assertTrue (p.isFile()); |
771 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\file" ); |
772 | |
773 | p.parse("\\\\server\\files\\dir\\file" , Path::PATH_WINDOWS); |
774 | assertTrue (!p.isRelative()); |
775 | assertTrue (p.isAbsolute()); |
776 | assertTrue (p.depth() == 2); |
777 | assertTrue (p[0] == "files" ); |
778 | assertTrue (p[1] == "dir" ); |
779 | assertTrue (p.getNode() == "server" ); |
780 | assertTrue (!p.isDirectory()); |
781 | assertTrue (p.isFile()); |
782 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\dir\\file" ); |
783 | |
784 | p.parse("\\\\server\\files\\dir\\file" , Path::PATH_WINDOWS); |
785 | assertTrue (!p.isRelative()); |
786 | assertTrue (p.isAbsolute()); |
787 | assertTrue (p.depth() == 2); |
788 | assertTrue (p[0] == "files" ); |
789 | assertTrue (p[1] == "dir" ); |
790 | assertTrue (p.getNode() == "server" ); |
791 | assertTrue (!p.isDirectory()); |
792 | assertTrue (p.isFile()); |
793 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\dir\\file" ); |
794 | |
795 | p.parse("\\\\server" , Path::PATH_WINDOWS); |
796 | assertTrue (!p.isRelative()); |
797 | assertTrue (p.isAbsolute()); |
798 | assertTrue (p.depth() == 0); |
799 | assertTrue (p.getNode() == "server" ); |
800 | assertTrue (p.isDirectory()); |
801 | assertTrue (!p.isFile()); |
802 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\" ); |
803 | |
804 | p.parse("c:\\" , Path::PATH_WINDOWS); |
805 | assertTrue (!p.isRelative()); |
806 | assertTrue (p.isAbsolute()); |
807 | assertTrue (p.depth() == 0); |
808 | assertTrue (p.getDevice() == "c" ); |
809 | assertTrue (p.isDirectory()); |
810 | assertTrue (!p.isFile()); |
811 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\" ); |
812 | |
813 | p.parse("c:\\WinNT" , Path::PATH_WINDOWS); |
814 | assertTrue (!p.isRelative()); |
815 | assertTrue (p.isAbsolute()); |
816 | assertTrue (p.depth() == 0); |
817 | assertTrue (p.getDevice() == "c" ); |
818 | assertTrue (!p.isDirectory()); |
819 | assertTrue (p.isFile()); |
820 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT" ); |
821 | |
822 | p.parse("c:\\WinNT\\" , Path::PATH_WINDOWS); |
823 | assertTrue (!p.isRelative()); |
824 | assertTrue (p.isAbsolute()); |
825 | assertTrue (p.depth() == 1); |
826 | assertTrue (p[0] == "WinNT" ); |
827 | assertTrue (p.getDevice() == "c" ); |
828 | assertTrue (p.isDirectory()); |
829 | assertTrue (!p.isFile()); |
830 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT\\" ); |
831 | |
832 | try |
833 | { |
834 | p.parse("~:\\" , Path::PATH_WINDOWS); |
835 | fail("bad path - must throw exception" ); |
836 | } |
837 | catch (PathSyntaxException&) |
838 | { |
839 | } |
840 | |
841 | try |
842 | { |
843 | p.parse("c:file.txt" , Path::PATH_WINDOWS); |
844 | fail("bad path - must throw exception" ); |
845 | } |
846 | catch (PathSyntaxException&) |
847 | { |
848 | } |
849 | |
850 | p.parse("a\\b\\c\\d" , Path::PATH_WINDOWS); |
851 | assertTrue (p.isRelative()); |
852 | assertTrue (!p.isAbsolute()); |
853 | assertTrue (p.depth() == 3); |
854 | assertTrue (p[0] == "a" ); |
855 | assertTrue (p[1] == "b" ); |
856 | assertTrue (p[2] == "c" ); |
857 | assertTrue (!p.isDirectory()); |
858 | assertTrue (p.isFile()); |
859 | assertTrue (p.toString(Path::PATH_WINDOWS) == "a\\b\\c\\d" ); |
860 | } |
861 | |
862 | void PathTest::testParseWindows5() |
863 | { |
864 | Path p; |
865 | p.parse("/c:/windows/system32/" , Path::PATH_WINDOWS); |
866 | assertTrue (!p.isRelative()); |
867 | assertTrue (p.isAbsolute()); |
868 | assertTrue (p.getDevice() == "c" ); |
869 | assertTrue (p.depth() == 2); |
870 | assertTrue (p[0] == "windows" ); |
871 | assertTrue (p[1] == "system32" ); |
872 | assertTrue (p.isDirectory()); |
873 | assertTrue (!p.isFile()); |
874 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\windows\\system32\\" ); |
875 | } |
876 | |
877 | void PathTest::testParseVMS1() |
878 | { |
879 | Path p; |
880 | p.parse("" , Path::PATH_VMS); |
881 | assertTrue (p.isRelative()); |
882 | assertTrue (!p.isAbsolute()); |
883 | assertTrue (p.depth() == 0); |
884 | assertTrue (p.isDirectory()); |
885 | assertTrue (!p.isFile()); |
886 | assertTrue (p.toString(Path::PATH_VMS) == "" ); |
887 | |
888 | p.parse("[]" , Path::PATH_VMS); |
889 | assertTrue (p.isRelative()); |
890 | assertTrue (!p.isAbsolute()); |
891 | assertTrue (p.depth() == 0); |
892 | assertTrue (p.isDirectory()); |
893 | assertTrue (!p.isFile()); |
894 | assertTrue (p.toString(Path::PATH_VMS) == "" ); |
895 | |
896 | p.parse("[foo]" , Path::PATH_VMS); |
897 | assertTrue (!p.isRelative()); |
898 | assertTrue (p.isAbsolute()); |
899 | assertTrue (p.depth() == 1); |
900 | assertTrue (p[0] == "foo" ); |
901 | assertTrue (p.isDirectory()); |
902 | assertTrue (!p.isFile()); |
903 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
904 | |
905 | p.parse("[.foo]" , Path::PATH_VMS); |
906 | assertTrue (p.isRelative()); |
907 | assertTrue (!p.isAbsolute()); |
908 | assertTrue (p.depth() == 1); |
909 | assertTrue (p[0] == "foo" ); |
910 | assertTrue (p.isDirectory()); |
911 | assertTrue (!p.isFile()); |
912 | assertTrue (p.toString(Path::PATH_VMS) == "[.foo]" ); |
913 | |
914 | p.parse("[foo.bar]" , Path::PATH_VMS); |
915 | assertTrue (!p.isRelative()); |
916 | assertTrue (p.isAbsolute()); |
917 | assertTrue (p.depth() == 2); |
918 | assertTrue (p[0] == "foo" ); |
919 | assertTrue (p[1] == "bar" ); |
920 | assertTrue (p.isDirectory()); |
921 | assertTrue (!p.isFile()); |
922 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]" ); |
923 | |
924 | p.parse("[.foo.bar]" , Path::PATH_VMS); |
925 | assertTrue (p.isRelative()); |
926 | assertTrue (!p.isAbsolute()); |
927 | assertTrue (p.depth() == 2); |
928 | assertTrue (p[0] == "foo" ); |
929 | assertTrue (p[1] == "bar" ); |
930 | assertTrue (p.isDirectory()); |
931 | assertTrue (!p.isFile()); |
932 | assertTrue (p.toString(Path::PATH_VMS) == "[.foo.bar]" ); |
933 | |
934 | p.parse("[foo.bar.foobar]" , Path::PATH_VMS); |
935 | assertTrue (!p.isRelative()); |
936 | assertTrue (p.isAbsolute()); |
937 | assertTrue (p.depth() == 3); |
938 | assertTrue (p[0] == "foo" ); |
939 | assertTrue (p[1] == "bar" ); |
940 | assertTrue (p[2] == "foobar" ); |
941 | assertTrue (p.isDirectory()); |
942 | assertTrue (!p.isFile()); |
943 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar.foobar]" ); |
944 | |
945 | p.parse("[.foo.bar.foobar]" , Path::PATH_VMS); |
946 | assertTrue (p.isRelative()); |
947 | assertTrue (!p.isAbsolute()); |
948 | assertTrue (p.depth() == 3); |
949 | assertTrue (p[0] == "foo" ); |
950 | assertTrue (p[1] == "bar" ); |
951 | assertTrue (p[2] == "foobar" ); |
952 | assertTrue (p.isDirectory()); |
953 | assertTrue (!p.isFile()); |
954 | assertTrue (p.toString(Path::PATH_VMS) == "[.foo.bar.foobar]" ); |
955 | } |
956 | |
957 | |
958 | void PathTest::testParseVMS2() |
959 | { |
960 | Path p; |
961 | p.parse("[foo][bar]" , Path::PATH_VMS); |
962 | assertTrue (!p.isRelative()); |
963 | assertTrue (p.isAbsolute()); |
964 | assertTrue (p.depth() == 2); |
965 | assertTrue (p[0] == "foo" ); |
966 | assertTrue (p[1] == "bar" ); |
967 | assertTrue (p.isDirectory()); |
968 | assertTrue (!p.isFile()); |
969 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]" ); |
970 | |
971 | p.parse("[foo.][bar]" , Path::PATH_VMS); |
972 | assertTrue (!p.isRelative()); |
973 | assertTrue (p.isAbsolute()); |
974 | assertTrue (p.depth() == 2); |
975 | assertTrue (p[0] == "foo" ); |
976 | assertTrue (p[1] == "bar" ); |
977 | assertTrue (p.isDirectory()); |
978 | assertTrue (!p.isFile()); |
979 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]" ); |
980 | |
981 | p.parse("[foo.bar][foo]" , Path::PATH_VMS); |
982 | assertTrue (!p.isRelative()); |
983 | assertTrue (p.isAbsolute()); |
984 | assertTrue (p.depth() == 3); |
985 | assertTrue (p[0] == "foo" ); |
986 | assertTrue (p[1] == "bar" ); |
987 | assertTrue (p[2] == "foo" ); |
988 | assertTrue (p.isDirectory()); |
989 | assertTrue (!p.isFile()); |
990 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar.foo]" ); |
991 | |
992 | try |
993 | { |
994 | p.parse("[foo.bar][.foo]" , Path::PATH_VMS); |
995 | failmsg("bad path - must throw exception" ); |
996 | } |
997 | catch (PathSyntaxException&) |
998 | { |
999 | } |
1000 | |
1001 | try |
1002 | { |
1003 | p.parse("[.foo.bar][foo]" , Path::PATH_VMS); |
1004 | failmsg("bad path - must throw exception" ); |
1005 | } |
1006 | catch (PathSyntaxException&) |
1007 | { |
1008 | } |
1009 | |
1010 | p.parse("[-]" , Path::PATH_VMS); |
1011 | assertTrue (p.isRelative()); |
1012 | assertTrue (!p.isAbsolute()); |
1013 | assertTrue (p.depth() == 1); |
1014 | assertTrue (p[0] == ".." ); |
1015 | assertTrue (p.isDirectory()); |
1016 | assertTrue (!p.isFile()); |
1017 | assertTrue (p.toString(Path::PATH_VMS) == "[-]" ); |
1018 | |
1019 | p.parse("[--]" , Path::PATH_VMS); |
1020 | assertTrue (p.isRelative()); |
1021 | assertTrue (!p.isAbsolute()); |
1022 | assertTrue (p.depth() == 2); |
1023 | assertTrue (p[0] == ".." ); |
1024 | assertTrue (p[1] == ".." ); |
1025 | assertTrue (p.isDirectory()); |
1026 | assertTrue (!p.isFile()); |
1027 | assertTrue (p.toString(Path::PATH_VMS) == "[--]" ); |
1028 | |
1029 | p.parse("[---]" , Path::PATH_VMS); |
1030 | assertTrue (p.isRelative()); |
1031 | assertTrue (!p.isAbsolute()); |
1032 | assertTrue (p.depth() == 3); |
1033 | assertTrue (p[0] == ".." ); |
1034 | assertTrue (p[1] == ".." ); |
1035 | assertTrue (p[2] == ".." ); |
1036 | assertTrue (p.isDirectory()); |
1037 | assertTrue (!p.isFile()); |
1038 | assertTrue (p.toString(Path::PATH_VMS) == "[---]" ); |
1039 | |
1040 | p.parse("[-.-]" , Path::PATH_VMS); |
1041 | assertTrue (p.isRelative()); |
1042 | assertTrue (!p.isAbsolute()); |
1043 | assertTrue (p.depth() == 2); |
1044 | assertTrue (p[0] == ".." ); |
1045 | assertTrue (p[1] == ".." ); |
1046 | assertTrue (p.isDirectory()); |
1047 | assertTrue (!p.isFile()); |
1048 | assertTrue (p.toString(Path::PATH_VMS) == "[--]" ); |
1049 | |
1050 | p.parse("[.-.-]" , Path::PATH_VMS); |
1051 | assertTrue (p.isRelative()); |
1052 | assertTrue (!p.isAbsolute()); |
1053 | assertTrue (p.depth() == 2); |
1054 | assertTrue (p[0] == ".." ); |
1055 | assertTrue (p[1] == ".." ); |
1056 | assertTrue (p.isDirectory()); |
1057 | assertTrue (!p.isFile()); |
1058 | assertTrue (p.toString(Path::PATH_VMS) == "[--]" ); |
1059 | |
1060 | p.parse("[-.-.-]" , Path::PATH_VMS); |
1061 | assertTrue (p.isRelative()); |
1062 | assertTrue (!p.isAbsolute()); |
1063 | assertTrue (p.depth() == 3); |
1064 | assertTrue (p[0] == ".." ); |
1065 | assertTrue (p[1] == ".." ); |
1066 | assertTrue (p[2] == ".." ); |
1067 | assertTrue (p.isDirectory()); |
1068 | assertTrue (!p.isFile()); |
1069 | assertTrue (p.toString(Path::PATH_VMS) == "[---]" ); |
1070 | |
1071 | p.parse("[.-.-.-]" , Path::PATH_VMS); |
1072 | assertTrue (p.isRelative()); |
1073 | assertTrue (!p.isAbsolute()); |
1074 | assertTrue (p.depth() == 3); |
1075 | assertTrue (p[0] == ".." ); |
1076 | assertTrue (p[1] == ".." ); |
1077 | assertTrue (p[2] == ".." ); |
1078 | assertTrue (p.isDirectory()); |
1079 | assertTrue (!p.isFile()); |
1080 | assertTrue (p.toString(Path::PATH_VMS) == "[---]" ); |
1081 | |
1082 | p.parse("[.--.-]" , Path::PATH_VMS); |
1083 | assertTrue (p.isRelative()); |
1084 | assertTrue (!p.isAbsolute()); |
1085 | assertTrue (p.depth() == 3); |
1086 | assertTrue (p[0] == ".." ); |
1087 | assertTrue (p[1] == ".." ); |
1088 | assertTrue (p[2] == ".." ); |
1089 | assertTrue (p.isDirectory()); |
1090 | assertTrue (!p.isFile()); |
1091 | assertTrue (p.toString(Path::PATH_VMS) == "[---]" ); |
1092 | |
1093 | p.parse("[--.-]" , Path::PATH_VMS); |
1094 | assertTrue (p.isRelative()); |
1095 | assertTrue (!p.isAbsolute()); |
1096 | assertTrue (p.depth() == 3); |
1097 | assertTrue (p[0] == ".." ); |
1098 | assertTrue (p[1] == ".." ); |
1099 | assertTrue (p[2] == ".." ); |
1100 | assertTrue (p.isDirectory()); |
1101 | assertTrue (!p.isFile()); |
1102 | assertTrue (p.toString(Path::PATH_VMS) == "[---]" ); |
1103 | } |
1104 | |
1105 | |
1106 | void PathTest::testParseVMS3() |
1107 | { |
1108 | Path p; |
1109 | p.parse("[foo][-]" , Path::PATH_VMS); |
1110 | assertTrue (!p.isRelative()); |
1111 | assertTrue (p.isAbsolute()); |
1112 | assertTrue (p.depth() == 1); |
1113 | assertTrue (p[0] == "foo" ); |
1114 | assertTrue (p.isDirectory()); |
1115 | assertTrue (!p.isFile()); |
1116 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1117 | |
1118 | p.parse("[foo][--]" , Path::PATH_VMS); |
1119 | assertTrue (!p.isRelative()); |
1120 | assertTrue (p.isAbsolute()); |
1121 | assertTrue (p.depth() == 1); |
1122 | assertTrue (p[0] == "foo" ); |
1123 | assertTrue (p.isDirectory()); |
1124 | assertTrue (!p.isFile()); |
1125 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1126 | |
1127 | p.parse("[foo][-.-]" , Path::PATH_VMS); |
1128 | assertTrue (!p.isRelative()); |
1129 | assertTrue (p.isAbsolute()); |
1130 | assertTrue (p.depth() == 1); |
1131 | assertTrue (p[0] == "foo" ); |
1132 | assertTrue (p.isDirectory()); |
1133 | assertTrue (!p.isFile()); |
1134 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1135 | |
1136 | p.parse("[foo][bar.-]" , Path::PATH_VMS); |
1137 | assertTrue (!p.isRelative()); |
1138 | assertTrue (p.isAbsolute()); |
1139 | assertTrue (p.depth() == 1); |
1140 | assertTrue (p[0] == "foo" ); |
1141 | assertTrue (p.isDirectory()); |
1142 | assertTrue (!p.isFile()); |
1143 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1144 | |
1145 | p.parse("[foo][bar.foo.-]" , Path::PATH_VMS); |
1146 | assertTrue (!p.isRelative()); |
1147 | assertTrue (p.isAbsolute()); |
1148 | assertTrue (p.depth() == 2); |
1149 | assertTrue (p[0] == "foo" ); |
1150 | assertTrue (p[1] == "bar" ); |
1151 | assertTrue (p.isDirectory()); |
1152 | assertTrue (!p.isFile()); |
1153 | assertTrue (p.toString(Path::PATH_VMS) == "[foo.bar]" ); |
1154 | |
1155 | p.parse("[foo][bar.foo.--]" , Path::PATH_VMS); |
1156 | assertTrue (!p.isRelative()); |
1157 | assertTrue (p.isAbsolute()); |
1158 | assertTrue (p.depth() == 1); |
1159 | assertTrue (p[0] == "foo" ); |
1160 | assertTrue (p.isDirectory()); |
1161 | assertTrue (!p.isFile()); |
1162 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1163 | |
1164 | p.parse("[foo][bar.foo.---]" , Path::PATH_VMS); |
1165 | assertTrue (!p.isRelative()); |
1166 | assertTrue (p.isAbsolute()); |
1167 | assertTrue (p.depth() == 1); |
1168 | assertTrue (p[0] == "foo" ); |
1169 | assertTrue (p.isDirectory()); |
1170 | assertTrue (!p.isFile()); |
1171 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1172 | |
1173 | p.parse("[foo][bar.foo.-.-.-]" , Path::PATH_VMS); |
1174 | assertTrue (!p.isRelative()); |
1175 | assertTrue (p.isAbsolute()); |
1176 | assertTrue (p.depth() == 1); |
1177 | assertTrue (p[0] == "foo" ); |
1178 | assertTrue (p.isDirectory()); |
1179 | assertTrue (!p.isFile()); |
1180 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]" ); |
1181 | } |
1182 | |
1183 | |
1184 | void PathTest::testParseVMS4() |
1185 | { |
1186 | Path p; |
1187 | p.parse("device:[foo]" , Path::PATH_VMS); |
1188 | assertTrue (!p.isRelative()); |
1189 | assertTrue (p.isAbsolute()); |
1190 | assertTrue (p.depth() == 1); |
1191 | assertTrue (p[0] == "foo" ); |
1192 | assertTrue (p.getDevice() == "device" ); |
1193 | assertTrue (p.isDirectory()); |
1194 | assertTrue (!p.isFile()); |
1195 | assertTrue (p.toString(Path::PATH_VMS) == "device:[foo]" ); |
1196 | |
1197 | p.parse("device:[.foo]" , Path::PATH_VMS); |
1198 | assertTrue (p.isRelative()); |
1199 | assertTrue (!p.isAbsolute()); |
1200 | assertTrue (p.depth() == 1); |
1201 | assertTrue (p[0] == "foo" ); |
1202 | assertTrue (p.getDevice() == "device" ); |
1203 | assertTrue (p.isDirectory()); |
1204 | assertTrue (!p.isFile()); |
1205 | assertTrue (p.toString(Path::PATH_VMS) == "device:[.foo]" ); |
1206 | |
1207 | p.parse("node::device:[foo]" , Path::PATH_VMS); |
1208 | assertTrue (!p.isRelative()); |
1209 | assertTrue (p.isAbsolute()); |
1210 | assertTrue (p.depth() == 1); |
1211 | assertTrue (p[0] == "foo" ); |
1212 | assertTrue (p.getNode() == "node" ); |
1213 | assertTrue (p.getDevice() == "device" ); |
1214 | assertTrue (p.isDirectory()); |
1215 | assertTrue (!p.isFile()); |
1216 | assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo]" ); |
1217 | |
1218 | p.parse("node::device:[foo.bar]" , Path::PATH_VMS); |
1219 | assertTrue (!p.isRelative()); |
1220 | assertTrue (p.isAbsolute()); |
1221 | assertTrue (p.depth() == 2); |
1222 | assertTrue (p[0] == "foo" ); |
1223 | assertTrue (p[1] == "bar" ); |
1224 | assertTrue (p.getNode() == "node" ); |
1225 | assertTrue (p.getDevice() == "device" ); |
1226 | assertTrue (p.isDirectory()); |
1227 | assertTrue (!p.isFile()); |
1228 | assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar]" ); |
1229 | |
1230 | p.parse("node::device:[foo.bar.][goo]" , Path::PATH_VMS); |
1231 | assertTrue (!p.isRelative()); |
1232 | assertTrue (p.isAbsolute()); |
1233 | assertTrue (p.depth() == 3); |
1234 | assertTrue (p[0] == "foo" ); |
1235 | assertTrue (p[1] == "bar" ); |
1236 | assertTrue (p[2] == "goo" ); |
1237 | assertTrue (p.getNode() == "node" ); |
1238 | assertTrue (p.getDevice() == "device" ); |
1239 | assertTrue (p.isDirectory()); |
1240 | assertTrue (!p.isFile()); |
1241 | assertTrue (p.toString(Path::PATH_VMS) == "node::device:[foo.bar.goo]" ); |
1242 | |
1243 | p.parse("[]foo.txt" , Path::PATH_VMS); |
1244 | assertTrue (p.isRelative()); |
1245 | assertTrue (!p.isAbsolute()); |
1246 | assertTrue (p.depth() == 0); |
1247 | assertTrue (!p.isDirectory()); |
1248 | assertTrue (p.isFile()); |
1249 | assertTrue (p.toString(Path::PATH_VMS) == "foo.txt" ); |
1250 | |
1251 | p.parse("[foo]bar.txt" , Path::PATH_VMS); |
1252 | assertTrue (!p.isRelative()); |
1253 | assertTrue (p.isAbsolute()); |
1254 | assertTrue (p.depth() == 1); |
1255 | assertTrue (p[0] == "foo" ); |
1256 | assertTrue (!p.isDirectory()); |
1257 | assertTrue (p.isFile()); |
1258 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]bar.txt" ); |
1259 | |
1260 | p.parse("[foo]bar.txt;" , Path::PATH_VMS); |
1261 | assertTrue (!p.isRelative()); |
1262 | assertTrue (p.isAbsolute()); |
1263 | assertTrue (p.depth() == 1); |
1264 | assertTrue (p[0] == "foo" ); |
1265 | assertTrue (!p.isDirectory()); |
1266 | assertTrue (p.isFile()); |
1267 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]bar.txt" ); |
1268 | |
1269 | p.parse("[foo]bar.txt;5" , Path::PATH_VMS); |
1270 | assertTrue (!p.isRelative()); |
1271 | assertTrue (p.isAbsolute()); |
1272 | assertTrue (p.depth() == 1); |
1273 | assertTrue (p[0] == "foo" ); |
1274 | assertTrue (!p.isDirectory()); |
1275 | assertTrue (p.isFile()); |
1276 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]bar.txt;5" ); |
1277 | assertTrue (p.version() == "5" ); |
1278 | |
1279 | p.parse("foo:bar.txt" , Path::PATH_VMS); |
1280 | assertTrue (!p.isRelative()); |
1281 | assertTrue (p.isAbsolute()); |
1282 | assertTrue (p.depth() == 0); |
1283 | assertTrue (p.getDevice() == "foo" ); |
1284 | assertTrue (!p.isDirectory()); |
1285 | assertTrue (p.isFile()); |
1286 | assertTrue (p.toString(Path::PATH_VMS) == "foo:bar.txt" ); |
1287 | |
1288 | p.parse("foo:bar.txt;5" , Path::PATH_VMS); |
1289 | assertTrue (!p.isRelative()); |
1290 | assertTrue (p.isAbsolute()); |
1291 | assertTrue (p.depth() == 0); |
1292 | assertTrue (p.getDevice() == "foo" ); |
1293 | assertTrue (!p.isDirectory()); |
1294 | assertTrue (p.isFile()); |
1295 | assertTrue (p.toString(Path::PATH_VMS) == "foo:bar.txt;5" ); |
1296 | assertTrue (p.version() == "5" ); |
1297 | |
1298 | p.parse("foo:" , Path::PATH_VMS); |
1299 | assertTrue (!p.isRelative()); |
1300 | assertTrue (p.isAbsolute()); |
1301 | assertTrue (p.depth() == 0); |
1302 | assertTrue (p.getDevice() == "foo" ); |
1303 | assertTrue (p.isDirectory()); |
1304 | assertTrue (!p.isFile()); |
1305 | assertTrue (p.toString(Path::PATH_VMS) == "foo:" ); |
1306 | |
1307 | p.parse("bar.txt" , Path::PATH_VMS); |
1308 | assertTrue (p.isRelative()); |
1309 | assertTrue (!p.isAbsolute()); |
1310 | assertTrue (p.depth() == 0); |
1311 | assertTrue (!p.isDirectory()); |
1312 | assertTrue (p.isFile()); |
1313 | assertTrue (p.toString(Path::PATH_VMS) == "bar.txt" ); |
1314 | |
1315 | p.parse("bar.txt;5" , Path::PATH_VMS); |
1316 | assertTrue (p.isRelative()); |
1317 | assertTrue (!p.isAbsolute()); |
1318 | assertTrue (p.depth() == 0); |
1319 | assertTrue (!p.isDirectory()); |
1320 | assertTrue (p.isFile()); |
1321 | assertTrue (p.toString(Path::PATH_VMS) == "bar.txt;5" ); |
1322 | assertTrue (p.version() == "5" ); |
1323 | } |
1324 | |
1325 | |
1326 | void PathTest::testParseGuess() |
1327 | { |
1328 | Path p; |
1329 | |
1330 | p.parse("foo:bar.txt;5" , Path::PATH_GUESS); |
1331 | assertTrue (!p.isRelative()); |
1332 | assertTrue (p.isAbsolute()); |
1333 | assertTrue (p.depth() == 0); |
1334 | assertTrue (p.getDevice() == "foo" ); |
1335 | assertTrue (!p.isDirectory()); |
1336 | assertTrue (p.isFile()); |
1337 | assertTrue (p.toString(Path::PATH_VMS) == "foo:bar.txt;5" ); |
1338 | assertTrue (p.version() == "5" ); |
1339 | |
1340 | p.parse("/usr/local/bin" , Path::PATH_GUESS); |
1341 | assertTrue (!p.isRelative()); |
1342 | assertTrue (p.isAbsolute()); |
1343 | assertTrue (p.depth() == 2); |
1344 | assertTrue (p[0] == "usr" ); |
1345 | assertTrue (p[1] == "local" ); |
1346 | assertTrue (p[2] == "bin" ); |
1347 | assertTrue (!p.isDirectory()); |
1348 | assertTrue (p.isFile()); |
1349 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/bin" ); |
1350 | |
1351 | p.parse("\\\\server\\files" , Path::PATH_GUESS); |
1352 | assertTrue (!p.isRelative()); |
1353 | assertTrue (p.isAbsolute()); |
1354 | assertTrue (p.depth() == 1); |
1355 | assertTrue (p[0] == "files" ); |
1356 | assertTrue (p.getNode() == "server" ); |
1357 | assertTrue (p.isDirectory()); |
1358 | assertTrue (!p.isFile()); |
1359 | assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\server\\files\\" ); |
1360 | |
1361 | p.parse("c:\\WinNT" , Path::PATH_GUESS); |
1362 | assertTrue (!p.isRelative()); |
1363 | assertTrue (p.isAbsolute()); |
1364 | assertTrue (p.depth() == 0); |
1365 | assertTrue (p.getDevice() == "c" ); |
1366 | assertTrue (!p.isDirectory()); |
1367 | assertTrue (p.isFile()); |
1368 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\WinNT" ); |
1369 | |
1370 | p.parse("foo:bar.txt;5" , Path::PATH_GUESS); |
1371 | assertTrue (!p.isRelative()); |
1372 | assertTrue (p.isAbsolute()); |
1373 | assertTrue (p.depth() == 0); |
1374 | assertTrue (p.getDevice() == "foo" ); |
1375 | assertTrue (!p.isDirectory()); |
1376 | assertTrue (p.isFile()); |
1377 | assertTrue (p.toString(Path::PATH_VMS) == "foo:bar.txt;5" ); |
1378 | assertTrue (p.version() == "5" ); |
1379 | |
1380 | p.parse("[foo]bar.txt" , Path::PATH_GUESS); |
1381 | assertTrue (!p.isRelative()); |
1382 | assertTrue (p.isAbsolute()); |
1383 | assertTrue (p.depth() == 1); |
1384 | assertTrue (p[0] == "foo" ); |
1385 | assertTrue (!p.isDirectory()); |
1386 | assertTrue (p.isFile()); |
1387 | assertTrue (p.toString(Path::PATH_VMS) == "[foo]bar.txt" ); |
1388 | } |
1389 | |
1390 | |
1391 | void PathTest::testTryParse() |
1392 | { |
1393 | Path p; |
1394 | #if defined(POCO_OS_FAMILY_UNIX) |
1395 | assertTrue (p.tryParse("/etc/passwd" )); |
1396 | assertTrue (p.toString() == "/etc/passwd" ); |
1397 | #elif defined(POCO_OS_FAMILY_WINDOWS) |
1398 | assertTrue (p.tryParse("c:\\windows\\system32" )); |
1399 | assertTrue (p.toString() == "c:\\windows\\system32" ); |
1400 | assertTrue (!p.tryParse("c:foo.bar" )); |
1401 | assertTrue (p.toString() == "c:\\windows\\system32" ); |
1402 | #endif |
1403 | |
1404 | assertTrue (p.tryParse("c:\\windows\\system" , Path::PATH_WINDOWS)); |
1405 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\windows\\system" ); |
1406 | assertTrue (!p.tryParse("c:foo.bar" , Path::PATH_WINDOWS)); |
1407 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\windows\\system" ); |
1408 | } |
1409 | |
1410 | |
1411 | void PathTest::testStatics() |
1412 | { |
1413 | std::string s = Path::current(); |
1414 | assertTrue (!s.empty()); |
1415 | Path p(s); |
1416 | assertTrue (p.isDirectory() && p.isAbsolute()); |
1417 | |
1418 | s = Path::home(); |
1419 | assertTrue (!s.empty()); |
1420 | p = s; |
1421 | assertTrue (p.isDirectory() && p.isAbsolute()); |
1422 | |
1423 | s = Path::temp(); |
1424 | assertTrue (!s.empty()); |
1425 | p = s; |
1426 | assertTrue (p.isDirectory() && p.isAbsolute()); |
1427 | |
1428 | s = Path::null(); |
1429 | assertTrue (!s.empty()); |
1430 | p = s; |
1431 | } |
1432 | |
1433 | |
1434 | void PathTest::testBaseNameExt() |
1435 | { |
1436 | Path p("foo.bar" ); |
1437 | assertTrue (p.getFileName() == "foo.bar" ); |
1438 | assertTrue (p.getBaseName() == "foo" ); |
1439 | assertTrue (p.getExtension() == "bar" ); |
1440 | |
1441 | p.setBaseName("readme" ); |
1442 | assertTrue (p.getFileName() == "readme.bar" ); |
1443 | assertTrue (p.getBaseName() == "readme" ); |
1444 | assertTrue (p.getExtension() == "bar" ); |
1445 | |
1446 | p.setExtension("txt" ); |
1447 | assertTrue (p.getFileName() == "readme.txt" ); |
1448 | assertTrue (p.getBaseName() == "readme" ); |
1449 | assertTrue (p.getExtension() == "txt" ); |
1450 | |
1451 | p.setExtension("html" ); |
1452 | assertTrue (p.getFileName() == "readme.html" ); |
1453 | assertTrue (p.getBaseName() == "readme" ); |
1454 | assertTrue (p.getExtension() == "html" ); |
1455 | |
1456 | p.setBaseName("index" ); |
1457 | assertTrue (p.getFileName() == "index.html" ); |
1458 | assertTrue (p.getBaseName() == "index" ); |
1459 | assertTrue (p.getExtension() == "html" ); |
1460 | } |
1461 | |
1462 | |
1463 | void PathTest::testAbsolute() |
1464 | { |
1465 | Path base("C:\\Program Files\\" , Path::PATH_WINDOWS); |
1466 | Path rel("Poco" ); |
1467 | Path abs = rel.absolute(base); |
1468 | assertTrue (abs.toString(Path::PATH_WINDOWS) == "C:\\Program Files\\Poco" ); |
1469 | |
1470 | base.parse("/usr/local" , Path::PATH_UNIX); |
1471 | rel.parse("Poco/include" , Path::PATH_UNIX); |
1472 | abs = rel.absolute(base); |
1473 | assertTrue (abs.toString(Path::PATH_UNIX) == "/usr/local/Poco/include" ); |
1474 | |
1475 | base.parse("/usr/local/bin" , Path::PATH_UNIX); |
1476 | rel.parse("../Poco/include" , Path::PATH_UNIX); |
1477 | abs = rel.absolute(base); |
1478 | assertTrue (abs.toString(Path::PATH_UNIX) == "/usr/local/Poco/include" ); |
1479 | } |
1480 | |
1481 | |
1482 | void PathTest::testRobustness() |
1483 | { |
1484 | Poco::Random r; |
1485 | for (int i = 0; i < 256; ++i) |
1486 | { |
1487 | int len = r.next(1024); |
1488 | std::string s; |
1489 | while (s.size() < len) |
1490 | { |
1491 | char c = r.nextChar(); |
1492 | if (c != 0) s += c; |
1493 | } |
1494 | try |
1495 | { |
1496 | Path p(s, Path::PATH_WINDOWS); |
1497 | } |
1498 | catch (PathSyntaxException&) |
1499 | { |
1500 | } |
1501 | try |
1502 | { |
1503 | Path p(s, Path::PATH_UNIX); |
1504 | } |
1505 | catch (PathSyntaxException&) |
1506 | { |
1507 | } |
1508 | try |
1509 | { |
1510 | Path p(s, Path::PATH_VMS); |
1511 | } |
1512 | catch (PathSyntaxException&) |
1513 | { |
1514 | } |
1515 | try |
1516 | { |
1517 | Path p(s, Path::PATH_GUESS); |
1518 | } |
1519 | catch (PathSyntaxException&) |
1520 | { |
1521 | } |
1522 | } |
1523 | } |
1524 | |
1525 | |
1526 | void PathTest::testParent() |
1527 | { |
1528 | Path p("/usr/local/include" , Path::PATH_UNIX); |
1529 | p.makeParent(); |
1530 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/" ); |
1531 | p.makeParent(); |
1532 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/" ); |
1533 | p.makeParent(); |
1534 | assertTrue (p.toString(Path::PATH_UNIX) == "/" ); |
1535 | p.makeParent(); |
1536 | assertTrue (p.toString(Path::PATH_UNIX) == "/" ); |
1537 | } |
1538 | |
1539 | |
1540 | void PathTest::testForDirectory() |
1541 | { |
1542 | Path p = Path::forDirectory("/usr/local/include" , Path::PATH_UNIX); |
1543 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/include/" ); |
1544 | |
1545 | p = Path::forDirectory("/usr/local/include/" , Path::PATH_UNIX); |
1546 | assertTrue (p.toString(Path::PATH_UNIX) == "/usr/local/include/" ); |
1547 | } |
1548 | |
1549 | |
1550 | void PathTest::testExpand() |
1551 | { |
1552 | #if defined(POCO_OS_FAMILY_UNIX) |
1553 | std::string s = Path::expand("~/.profile" ); |
1554 | assertTrue (s == Path::expand("$HOME/.profile" )); |
1555 | assertTrue (s == Environment::get("HOME" ) + ".profile" || s == Environment::get("HOME" ) + "/.profile" ); |
1556 | Path p(s); |
1557 | s = Path::expand("$HOME/.profile" ); |
1558 | assertTrue (s == Path::expand("~/.profile" )); |
1559 | s = Path::expand("${HOME}/.profile" ); |
1560 | assertTrue (s == Path::expand("~/.profile" )); |
1561 | #elif defined(POCO_OS_FAMILY_WINDOWS) |
1562 | std::string s = Path::expand("%TMP%\\foo" ); |
1563 | assertTrue (s == Environment::get("TMP" ) + "\\foo" ); |
1564 | Path p(s); |
1565 | #else |
1566 | std::string s = Path::expand("SYS$LOGIN:[projects]" ); |
1567 | assertTrue (s.find(":[projects]" ) != std::string::npos); |
1568 | Path p(s); |
1569 | #endif |
1570 | } |
1571 | |
1572 | |
1573 | void PathTest::testListRoots() |
1574 | { |
1575 | std::vector<std::string> devs; |
1576 | Path::listRoots(devs); |
1577 | assertTrue (devs.size() > 0); |
1578 | for (std::vector<std::string>::iterator it = devs.begin(); it != devs.end(); ++it) |
1579 | { |
1580 | std::cout << *it << std::endl; |
1581 | } |
1582 | } |
1583 | |
1584 | |
1585 | void PathTest::testFind() |
1586 | { |
1587 | Path p; |
1588 | #if defined(POCO_OS_FAMILY_UNIX) |
1589 | bool found = Path::find(Environment::get("PATH" ), "ls" , p); |
1590 | bool notfound = Path::find(Environment::get("PATH" ), "xxxyyy123" , p); |
1591 | #elif defined(POCO_OS_FAMILY_WINDOWS) |
1592 | #if defined(_WIN32_WCE) |
1593 | return; |
1594 | #endif |
1595 | bool found = Path::find(Environment::get("Path" ), "cmd.exe" , p); |
1596 | bool notfound = Path::find(Environment::get("Path" ), "xxxyyy123.zzz" , p); |
1597 | #else |
1598 | bool found = true; |
1599 | bool notfound = false; |
1600 | #endif |
1601 | assertTrue (found); |
1602 | assertTrue (!notfound); |
1603 | |
1604 | std::string fn = p.toString(); |
1605 | assertTrue (fn.size() > 0); |
1606 | } |
1607 | |
1608 | |
1609 | void PathTest::testSwap() |
1610 | { |
1611 | Path p1("c:\\temp\\foo.bar" ); |
1612 | Path p2("\\\\server\\files\\foo.bar" ); |
1613 | p1.swap(p2); |
1614 | assertTrue (p1.toString() == "\\\\server\\files\\foo.bar" ); |
1615 | assertTrue (p2.toString() == "c:\\temp\\foo.bar" ); |
1616 | } |
1617 | |
1618 | |
1619 | void PathTest::testResolve() |
1620 | { |
1621 | Path p("c:\\foo\\" , Path::PATH_WINDOWS); |
1622 | p.resolve("test.dat" ); |
1623 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\test.dat" ); |
1624 | |
1625 | p.assign("c:\\foo\\" , Path::PATH_WINDOWS); |
1626 | p.resolve(Path("d:\\bar.txt" , Path::PATH_WINDOWS)); |
1627 | assertTrue (p.toString(Path::PATH_WINDOWS) == "d:\\bar.txt" ); |
1628 | |
1629 | p.assign("c:\\foo\\bar.txt" , Path::PATH_WINDOWS); |
1630 | p.resolve("foo.txt" ); |
1631 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\foo.txt" ); |
1632 | |
1633 | p.assign("c:\\foo\\bar\\" , Path::PATH_WINDOWS); |
1634 | p.resolve(Path("..\\baz\\test.dat" , Path::PATH_WINDOWS)); |
1635 | assertTrue (p.toString(Path::PATH_WINDOWS) == "c:\\foo\\baz\\test.dat" ); |
1636 | } |
1637 | |
1638 | |
1639 | void PathTest::testPushPop() |
1640 | { |
1641 | Path p; |
1642 | p.pushDirectory("a" ); |
1643 | p.pushDirectory("b" ); |
1644 | p.pushDirectory("c" ); |
1645 | assertTrue (p.toString(Path::PATH_UNIX) == "a/b/c/" ); |
1646 | |
1647 | p.popDirectory(); |
1648 | assertTrue (p.toString(Path::PATH_UNIX) == "a/b/" ); |
1649 | |
1650 | p.popFrontDirectory(); |
1651 | assertTrue (p.toString(Path::PATH_UNIX) == "b/" ); |
1652 | } |
1653 | |
1654 | |
1655 | void PathTest::testWindowsSystem() |
1656 | { |
1657 | #if defined(POCO_OS_FAMILY_WINDOWS) |
1658 | std::cout << Poco::PathImpl::systemImpl() << std::endl; |
1659 | #endif |
1660 | } |
1661 | |
1662 | |
1663 | void PathTest::setUp() |
1664 | { |
1665 | } |
1666 | |
1667 | |
1668 | void PathTest::tearDown() |
1669 | { |
1670 | } |
1671 | |
1672 | |
1673 | CppUnit::Test* PathTest::suite() |
1674 | { |
1675 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("PathTest" ); |
1676 | |
1677 | CppUnit_addTest(pSuite, PathTest, testParseUnix1); |
1678 | CppUnit_addTest(pSuite, PathTest, testParseUnix2); |
1679 | CppUnit_addTest(pSuite, PathTest, testParseUnix3); |
1680 | CppUnit_addTest(pSuite, PathTest, testParseUnix4); |
1681 | CppUnit_addTest(pSuite, PathTest, testParseUnix5); |
1682 | CppUnit_addTest(pSuite, PathTest, testExpandVariableFromPath); |
1683 | CppUnit_addTest(pSuite, PathTest, testParseWindows1); |
1684 | CppUnit_addTest(pSuite, PathTest, testParseWindows2); |
1685 | CppUnit_addTest(pSuite, PathTest, testParseWindows3); |
1686 | CppUnit_addTest(pSuite, PathTest, testParseWindows4); |
1687 | CppUnit_addTest(pSuite, PathTest, testParseWindows5); |
1688 | CppUnit_addTest(pSuite, PathTest, testParseVMS1); |
1689 | CppUnit_addTest(pSuite, PathTest, testParseVMS2); |
1690 | CppUnit_addTest(pSuite, PathTest, testParseVMS3); |
1691 | CppUnit_addTest(pSuite, PathTest, testParseVMS4); |
1692 | CppUnit_addTest(pSuite, PathTest, testParseGuess); |
1693 | CppUnit_addTest(pSuite, PathTest, testTryParse); |
1694 | CppUnit_addTest(pSuite, PathTest, testStatics); |
1695 | CppUnit_addTest(pSuite, PathTest, testBaseNameExt); |
1696 | CppUnit_addTest(pSuite, PathTest, testAbsolute); |
1697 | CppUnit_addTest(pSuite, PathTest, testRobustness); |
1698 | CppUnit_addTest(pSuite, PathTest, testParent); |
1699 | CppUnit_addTest(pSuite, PathTest, testForDirectory); |
1700 | CppUnit_addTest(pSuite, PathTest, testExpand); |
1701 | CppUnit_addTest(pSuite, PathTest, testListRoots); |
1702 | CppUnit_addTest(pSuite, PathTest, testFind); |
1703 | CppUnit_addTest(pSuite, PathTest, testSwap); |
1704 | CppUnit_addTest(pSuite, PathTest, testResolve); |
1705 | CppUnit_addTest(pSuite, PathTest, testPushPop); |
1706 | CppUnit_addTest(pSuite, PathTest, testWindowsSystem); |
1707 | |
1708 | return pSuite; |
1709 | } |
1710 | |