1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
|
#include "../src/engine/directorylistingparser.h"
#include <cppunit/extensions/HelperMacros.h>
#include <list>
/*
* This testsuite asserts the correctness of the CServerPath class.
*/
class CServerPathTest final : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(CServerPathTest);
CPPUNIT_TEST(testGetPath);
CPPUNIT_TEST(testHasParent);
CPPUNIT_TEST(testGetParent);
CPPUNIT_TEST(testFormatSubdir);
CPPUNIT_TEST(testGetCommonParent);
CPPUNIT_TEST(testFormatFilename);
CPPUNIT_TEST(testChangePath);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testGetPath();
void testHasParent();
void testGetParent();
void testFormatSubdir();
void testGetCommonParent();
void testFormatFilename();
void testChangePath();
protected:
};
CPPUNIT_TEST_SUITE_REGISTRATION(CServerPathTest);
void CServerPathTest::testGetPath()
{
const CServerPath unix1(L"/");
CPPUNIT_ASSERT(unix1.GetPath() == L"/");
const CServerPath unix2(L"/foo");
CPPUNIT_ASSERT(unix2.GetPath() == L"/foo");
const CServerPath unix3(L"/foo/bar");
CPPUNIT_ASSERT(unix3.GetPath() == L"/foo/bar");
const CServerPath vms1(L"FOO:[BAR]");
CPPUNIT_ASSERT(vms1.GetPath() == L"FOO:[BAR]");
const CServerPath vms2(L"FOO:[BAR.TEST]");
CPPUNIT_ASSERT(vms2.GetPath() == L"FOO:[BAR.TEST]");
const CServerPath vms3(L"FOO:[BAR^.TEST]");
CPPUNIT_ASSERT(vms3.GetPath() == L"FOO:[BAR^.TEST]");
const CServerPath vms4(L"FOO:[BAR^.TEST.SOMETHING]");
CPPUNIT_ASSERT(vms4.GetPath() == L"FOO:[BAR^.TEST.SOMETHING]");
const CServerPath dos1(L"C:\\");
CPPUNIT_ASSERT(dos1.GetPath() == L"C:\\");
const CServerPath dos2(L"C:\\FOO");
CPPUNIT_ASSERT(dos2.GetPath() == L"C:\\FOO");
const CServerPath dos3(L"md:\\", DOS);
CPPUNIT_ASSERT(dos3.GetPath() == L"md:\\");
const CServerPath dos4(L"C:", DOS);
CPPUNIT_ASSERT(dos4.GetPath() == L"C:\\");
const CServerPath dos5(L"C:\\FOO\\");
CPPUNIT_ASSERT(dos5.GetPath() == L"C:\\FOO");
const CServerPath mvs1(L"'FOO'", MVS);
CPPUNIT_ASSERT(mvs1.GetPath() == L"'FOO'");
const CServerPath mvs2(L"'FOO.'", MVS);
CPPUNIT_ASSERT(mvs2.GetPath() == L"'FOO.'");
const CServerPath mvs3(L"'FOO.BAR'", MVS);
CPPUNIT_ASSERT(mvs3.GetPath() == L"'FOO.BAR'");
const CServerPath mvs4(L"'FOO.BAR.'", MVS);
CPPUNIT_ASSERT(mvs4.GetPath() == L"'FOO.BAR.'");
const CServerPath vxworks1(L":foo:");
CPPUNIT_ASSERT(vxworks1.GetPath() == L":foo:");
const CServerPath vxworks2(L":foo:bar");
CPPUNIT_ASSERT(vxworks2.GetPath() == L":foo:bar");
const CServerPath vxworks3(L":foo:bar/test");
CPPUNIT_ASSERT(vxworks3.GetPath() == L":foo:bar/test");
// ZVM is same as Unix, only makes difference in directory
// listing parser.
const CServerPath zvm1(L"/", ZVM);
CPPUNIT_ASSERT(zvm1.GetPath() == L"/");
const CServerPath zvm2(L"/foo", ZVM);
CPPUNIT_ASSERT(zvm2.GetPath() == L"/foo");
const CServerPath zvm3(L"/foo/bar", ZVM);
CPPUNIT_ASSERT(zvm3.GetPath() == L"/foo/bar");
const CServerPath hpnonstop1(L"\\mysys", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop1.GetPath() == L"\\mysys");
const CServerPath hpnonstop2(L"\\mysys.$myvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop2.GetPath() == L"\\mysys.$myvol");
const CServerPath hpnonstop3(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop3.GetPath() == L"\\mysys.$myvol.mysubvol");
const CServerPath dos_virtual1(L"\\");
CPPUNIT_ASSERT(dos_virtual1.GetPath() == L"\\");
const CServerPath dos_virtual2(L"\\foo");
CPPUNIT_ASSERT(dos_virtual2.GetPath() == L"\\foo");
const CServerPath dos_virtual3(L"\\foo\\bar");
CPPUNIT_ASSERT(dos_virtual3.GetPath() == L"\\foo\\bar");
const CServerPath cygwin1(L"/", CYGWIN);
CPPUNIT_ASSERT(cygwin1.GetPath() == L"/");
const CServerPath cygwin2(L"/foo", CYGWIN);
CPPUNIT_ASSERT(cygwin2.GetPath() == L"/foo");
const CServerPath cygwin3(L"//", CYGWIN);
CPPUNIT_ASSERT(cygwin3.GetPath() == L"//");
const CServerPath cygwin4(L"//foo", CYGWIN);
CPPUNIT_ASSERT(cygwin4.GetPath() == L"//foo");
const CServerPath dos_slashes1(L"C:\\", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes1.GetPath() == L"C:/");
const CServerPath dos_slashes2(L"C:\\FOO", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes2.GetPath() == L"C:/FOO");
const CServerPath dos_slashes3(L"md:\\", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes3.GetPath() == L"md:/");
const CServerPath dos_slashes4(L"C:", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes4.GetPath() == L"C:/");
const CServerPath dos_slashes5(L"C:\\FOO\\", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes5.GetPath() == L"C:/FOO");
}
void CServerPathTest::testHasParent()
{
const CServerPath unix1(L"/");
CPPUNIT_ASSERT(!unix1.HasParent());
const CServerPath unix2(L"/foo");
CPPUNIT_ASSERT(unix2.HasParent());
const CServerPath unix3(L"/foo/bar");
CPPUNIT_ASSERT(unix3.HasParent());
const CServerPath vms1(L"FOO:[BAR]");
CPPUNIT_ASSERT(!vms1.HasParent());
const CServerPath vms2(L"FOO:[BAR.TEST]");
CPPUNIT_ASSERT(vms2.HasParent());
const CServerPath vms3(L"FOO:[BAR^.TEST]");
CPPUNIT_ASSERT(!vms3.HasParent());
const CServerPath vms4(L"FOO:[BAR^.TEST.SOMETHING]");
CPPUNIT_ASSERT(vms4.HasParent());
const CServerPath dos1(L"C:\\");
CPPUNIT_ASSERT(!dos1.HasParent());
const CServerPath dos2(L"C:\\FOO");
CPPUNIT_ASSERT(dos2.HasParent());
const CServerPath mvs1(L"'FOO'", MVS);
CPPUNIT_ASSERT(!mvs1.HasParent());
const CServerPath mvs2(L"'FOO.'", MVS);
CPPUNIT_ASSERT(!mvs2.HasParent());
const CServerPath mvs3(L"'FOO.BAR'", MVS);
CPPUNIT_ASSERT(mvs3.HasParent());
const CServerPath mvs4(L"'FOO.BAR.'", MVS);
CPPUNIT_ASSERT(mvs4.HasParent());
const CServerPath vxworks1(L":foo:");
CPPUNIT_ASSERT(!vxworks1.HasParent());
const CServerPath vxworks2(L":foo:bar");
CPPUNIT_ASSERT(vxworks2.HasParent());
const CServerPath vxworks3(L":foo:bar/test");
CPPUNIT_ASSERT(vxworks3.HasParent());
// ZVM is same as Unix, only makes difference in directory
// listing parser.
const CServerPath zvm1(L"/", ZVM);
CPPUNIT_ASSERT(!zvm1.HasParent());
const CServerPath zvm2(L"/foo", ZVM);
CPPUNIT_ASSERT(zvm2.HasParent());
const CServerPath zvm3(L"/foo/bar", ZVM);
CPPUNIT_ASSERT(zvm3.HasParent());
const CServerPath hpnonstop1(L"\\mysys", HPNONSTOP);
CPPUNIT_ASSERT(!hpnonstop1.HasParent());
const CServerPath hpnonstop2(L"\\mysys.$myvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop2.HasParent());
const CServerPath hpnonstop3(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop3.HasParent());
const CServerPath dos_virtual1(L"\\");
CPPUNIT_ASSERT(!dos_virtual1.HasParent());
const CServerPath dos_virtual2(L"\\foo");
CPPUNIT_ASSERT(dos_virtual2.HasParent());
const CServerPath dos_virtual3(L"\\foo\\bar");
CPPUNIT_ASSERT(dos_virtual3.HasParent());
const CServerPath cygwin1(L"/", CYGWIN);
CPPUNIT_ASSERT(!cygwin1.HasParent());
const CServerPath cygwin2(L"/foo", CYGWIN);
CPPUNIT_ASSERT(cygwin2.HasParent());
const CServerPath cygwin3(L"/foo/bar", CYGWIN);
CPPUNIT_ASSERT(cygwin3.HasParent());
const CServerPath cygwin4(L"//", CYGWIN);
CPPUNIT_ASSERT(!cygwin4.HasParent());
const CServerPath cygwin5(L"//foo", CYGWIN);
CPPUNIT_ASSERT(cygwin5.HasParent());
const CServerPath cygwin6(L"//foo/bar", CYGWIN);
CPPUNIT_ASSERT(cygwin6.HasParent());
const CServerPath dos_slashes1(L"C:\\", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(!dos_slashes1.HasParent());
const CServerPath dos_slashes2(L"C:\\FOO", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes2.HasParent());
}
void CServerPathTest::testGetParent()
{
const CServerPath unix1(L"/");
const CServerPath unix2(L"/foo");
const CServerPath unix3(L"/foo/bar");
CPPUNIT_ASSERT(unix2.GetParent() == unix1);
CPPUNIT_ASSERT(unix3.GetParent() == unix2);
const CServerPath vms1(L"FOO:[BAR]");
const CServerPath vms2(L"FOO:[BAR.TEST]");
const CServerPath vms3(L"FOO:[BAR^.TEST]");
const CServerPath vms4(L"FOO:[BAR^.TEST.SOMETHING]");
CPPUNIT_ASSERT(vms2.GetParent() == vms1);
CPPUNIT_ASSERT(vms4.GetParent() == vms3);
const CServerPath dos1(L"C:\\");
const CServerPath dos2(L"C:\\FOO");
CPPUNIT_ASSERT(dos2.GetParent() == dos1);
const CServerPath mvs1(L"'FOO'", MVS);
const CServerPath mvs2(L"'FOO.'", MVS);
const CServerPath mvs3(L"'FOO.BAR'", MVS);
const CServerPath mvs4(L"'FOO.BAR.'", MVS);
CPPUNIT_ASSERT(mvs3.GetParent() == mvs2);
CPPUNIT_ASSERT(mvs4.GetParent() == mvs2);
const CServerPath vxworks1(L":foo:");
const CServerPath vxworks2(L":foo:bar");
const CServerPath vxworks3(L":foo:bar/test");
CPPUNIT_ASSERT(vxworks2.GetParent() == vxworks1);
CPPUNIT_ASSERT(vxworks3.GetParent() == vxworks2);
// ZVM is same as Unix, only makes difference in directory
// listing parser.
const CServerPath zvm1(L"/", ZVM);
const CServerPath zvm2(L"/foo", ZVM);
const CServerPath zvm3(L"/foo/bar", ZVM);
CPPUNIT_ASSERT(zvm2.GetParent() == zvm1);
CPPUNIT_ASSERT(zvm3.GetParent() == zvm2);
const CServerPath hpnonstop1(L"\\mysys", HPNONSTOP);
const CServerPath hpnonstop2(L"\\mysys.$myvol", HPNONSTOP);
const CServerPath hpnonstop3(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop2.GetParent() == hpnonstop1);
CPPUNIT_ASSERT(hpnonstop3.GetParent() == hpnonstop2);
const CServerPath dos_virtual1(L"\\");
const CServerPath dos_virtual2(L"\\foo");
const CServerPath dos_virtual3(L"\\foo\\bar");
CPPUNIT_ASSERT(dos_virtual2.GetParent() == dos_virtual1);
CPPUNIT_ASSERT(dos_virtual3.GetParent() == dos_virtual2);
const CServerPath cygwin1(L"/", CYGWIN);
const CServerPath cygwin2(L"/foo", CYGWIN);
const CServerPath cygwin3(L"/foo/bar", CYGWIN);
const CServerPath cygwin4(L"//", CYGWIN);
const CServerPath cygwin5(L"//foo", CYGWIN);
const CServerPath cygwin6(L"//foo/bar", CYGWIN);
CPPUNIT_ASSERT(cygwin2.GetParent() == cygwin1);
CPPUNIT_ASSERT(cygwin3.GetParent() == cygwin2);
CPPUNIT_ASSERT(cygwin5.GetParent() == cygwin4);
CPPUNIT_ASSERT(cygwin6.GetParent() == cygwin5);
const CServerPath dos_slashes1(L"C:\\", DOS_FWD_SLASHES);
const CServerPath dos_slashes2(L"C:/FOO", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes2.GetParent() == dos_slashes1);
}
void CServerPathTest::testFormatSubdir()
{
CServerPath path;
path.SetType(VMS);
CPPUNIT_ASSERT(path.FormatSubdir(L"FOO.BAR") == L"FOO^.BAR");
}
void CServerPathTest::testGetCommonParent()
{
const CServerPath unix1(L"/foo");
const CServerPath unix2(L"/foo/baz");
const CServerPath unix3(L"/foo/bar");
CPPUNIT_ASSERT(unix2.GetCommonParent(unix3) == unix1);
CPPUNIT_ASSERT(unix1.GetCommonParent(unix1) == unix1);
CPPUNIT_ASSERT(unix1.GetCommonParent(unix3) == unix1);
const CServerPath vms1(L"FOO:[BAR]");
const CServerPath vms2(L"FOO:[BAR.TEST]");
const CServerPath vms3(L"GOO:[BAR");
const CServerPath vms4(L"GOO:[BAR^.TEST.SOMETHING]");
CPPUNIT_ASSERT(vms2.GetCommonParent(vms1) == vms1);
CPPUNIT_ASSERT(vms3.GetCommonParent(vms1) == CServerPath());
{
const CServerPath dos1(L"C:\\");
const CServerPath dos2(L"C:\\FOO");
const CServerPath dos3(L"D:\\FOO");
CPPUNIT_ASSERT(dos1.GetCommonParent(dos2) == dos1);
CPPUNIT_ASSERT(dos2.GetCommonParent(dos3) == CServerPath());
}
const CServerPath mvs1(L"'FOO'", MVS);
const CServerPath mvs2(L"'FOO.'", MVS);
const CServerPath mvs3(L"'FOO.BAR'", MVS);
const CServerPath mvs4(L"'FOO.BAR.'", MVS);
const CServerPath mvs5(L"'BAR.'", MVS);
const CServerPath mvs6(L"'FOO.BAR.BAZ'", MVS);
CPPUNIT_ASSERT(mvs1.GetCommonParent(mvs2) == CServerPath());
CPPUNIT_ASSERT(mvs3.GetCommonParent(mvs1) == CServerPath());
CPPUNIT_ASSERT(mvs4.GetCommonParent(mvs3) == mvs2);
CPPUNIT_ASSERT(mvs3.GetCommonParent(mvs4) == mvs2);
CPPUNIT_ASSERT(mvs3.GetCommonParent(mvs2) == mvs2);
CPPUNIT_ASSERT(mvs4.GetCommonParent(mvs2) == mvs2);
CPPUNIT_ASSERT(mvs5.GetCommonParent(mvs2) == CServerPath());
CPPUNIT_ASSERT(mvs6.GetCommonParent(mvs4) == mvs4);
CPPUNIT_ASSERT(mvs6.GetCommonParent(mvs3) == mvs2);
const CServerPath vxworks1(L":foo:");
const CServerPath vxworks2(L":foo:bar");
const CServerPath vxworks3(L":foo:baz");
const CServerPath vxworks4(L":baz:bar");
CPPUNIT_ASSERT(vxworks1.GetCommonParent(vxworks2) == vxworks1);
CPPUNIT_ASSERT(vxworks2.GetCommonParent(vxworks3) == vxworks1);
CPPUNIT_ASSERT(vxworks4.GetCommonParent(vxworks2) == CServerPath());
// ZVM is same as Unix, only makes difference in directory
// listing parser.
const CServerPath zvm1(L"/foo", ZVM);
const CServerPath zvm2(L"/foo/baz", ZVM);
const CServerPath zvm3(L"/foo/bar", ZVM);
CPPUNIT_ASSERT(zvm2.GetCommonParent(zvm3) == zvm1);
CPPUNIT_ASSERT(zvm1.GetCommonParent(zvm1) == zvm1);
CServerPath hpnonstop1(L"\\mysys", HPNONSTOP);
CServerPath hpnonstop2(L"\\mysys.$myvol", HPNONSTOP);
CServerPath hpnonstop3(L"\\mysys.$theirvol", HPNONSTOP);
CServerPath hpnonstop4(L"\\theirsys.$myvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop2.GetCommonParent(hpnonstop3) == hpnonstop1);
CPPUNIT_ASSERT(hpnonstop1.GetCommonParent(hpnonstop1) == hpnonstop1);
CPPUNIT_ASSERT(hpnonstop2.GetCommonParent(hpnonstop4) == CServerPath());
const CServerPath dos_virtual1(L"\\foo");
const CServerPath dos_virtual2(L"\\foo\\baz");
const CServerPath dos_virtual3(L"\\foo\\bar");
CPPUNIT_ASSERT(dos_virtual2.GetCommonParent(dos_virtual3) == dos_virtual1);
CPPUNIT_ASSERT(dos_virtual1.GetCommonParent(dos_virtual1) == dos_virtual1);
const CServerPath cygwin1(L"/foo", CYGWIN);
const CServerPath cygwin2(L"/foo/baz", CYGWIN);
const CServerPath cygwin3(L"/foo/bar", CYGWIN);
const CServerPath cygwin4(L"//foo", CYGWIN);
const CServerPath cygwin5(L"//foo/baz", CYGWIN);
const CServerPath cygwin6(L"//foo/bar", CYGWIN);
CPPUNIT_ASSERT(cygwin2.GetCommonParent(cygwin3) == cygwin1);
CPPUNIT_ASSERT(cygwin1.GetCommonParent(cygwin1) == cygwin1);
CPPUNIT_ASSERT(cygwin1.GetCommonParent(cygwin3) == cygwin1);
CPPUNIT_ASSERT(cygwin5.GetCommonParent(cygwin6) == cygwin4);
CPPUNIT_ASSERT(cygwin4.GetCommonParent(cygwin4) == cygwin4);
CPPUNIT_ASSERT(cygwin4.GetCommonParent(cygwin6) == cygwin4);
CPPUNIT_ASSERT(cygwin4.GetCommonParent(cygwin1) == CServerPath());
{
const CServerPath dos_slashes1(L"C:\\", DOS_FWD_SLASHES);
const CServerPath dos_slashes2(L"C:\\FOO", DOS_FWD_SLASHES);
const CServerPath dos_slashes3(L"D:\\FOO", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes1.GetCommonParent(dos_slashes2) == dos_slashes1);
CPPUNIT_ASSERT(dos_slashes2.GetCommonParent(dos_slashes3) == CServerPath());
}
}
void CServerPathTest::testFormatFilename()
{
const CServerPath unix1(L"/");
const CServerPath unix2(L"/foo");
CPPUNIT_ASSERT(unix1.FormatFilename(L"bar", false) == L"/bar");
CPPUNIT_ASSERT(unix2.FormatFilename(L"bar", false) == L"/foo/bar");
const CServerPath vms1(L"FOO:[BAR]");
CPPUNIT_ASSERT(vms1.FormatFilename(L"BAZ", false) == L"FOO:[BAR]BAZ");
{
const CServerPath dos1(L"C:\\");
const CServerPath dos2(L"C:\\foo");
CPPUNIT_ASSERT(dos1.FormatFilename(L"bar", false) == L"C:\\bar");
CPPUNIT_ASSERT(dos2.FormatFilename(L"bar", false) == L"C:\\foo\\bar");
}
const CServerPath mvs1(L"'FOO.BAR'", MVS);
const CServerPath mvs2(L"'FOO.BAR.'", MVS);
CPPUNIT_ASSERT(mvs1.FormatFilename(L"BAZ", false) == L"'FOO.BAR(BAZ)'");
CPPUNIT_ASSERT(mvs2.FormatFilename(L"BAZ", false) == L"'FOO.BAR.BAZ'");
const CServerPath vxworks1(L":foo:");
const CServerPath vxworks2(L":foo:bar");
const CServerPath vxworks3(L":foo:bar/test");
CPPUNIT_ASSERT(vxworks1.FormatFilename(L"baz", false) == L":foo:baz");
CPPUNIT_ASSERT(vxworks2.FormatFilename(L"baz", false) == L":foo:bar/baz");
CPPUNIT_ASSERT(vxworks3.FormatFilename(L"baz", false) == L":foo:bar/test/baz");
// ZVM is same as Unix, only makes difference in directory
// listing parser.
const CServerPath zvm1(L"/", ZVM);
const CServerPath zvm2(L"/foo", ZVM);
CPPUNIT_ASSERT(zvm1.FormatFilename(L"bar", false) == L"/bar");
CPPUNIT_ASSERT(zvm2.FormatFilename(L"bar", false) == L"/foo/bar");
const CServerPath hpnonstop1(L"\\mysys", HPNONSTOP);
const CServerPath hpnonstop2(L"\\mysys.$myvol", HPNONSTOP);
const CServerPath hpnonstop3(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop1.FormatFilename(L"foo", false) == L"\\mysys.foo");
CPPUNIT_ASSERT(hpnonstop2.FormatFilename(L"foo", false) == L"\\mysys.$myvol.foo");
CPPUNIT_ASSERT(hpnonstop3.FormatFilename(L"foo", false) == L"\\mysys.$myvol.mysubvol.foo");
const CServerPath dos_virtual1(L"/");
const CServerPath dos_virtual2(L"/foo");
CPPUNIT_ASSERT(dos_virtual1.FormatFilename(L"bar", false) == L"/bar");
CPPUNIT_ASSERT(dos_virtual2.FormatFilename(L"bar", false) == L"/foo/bar");
const CServerPath cygwin1(L"/", CYGWIN);
const CServerPath cygwin2(L"/foo", CYGWIN);
const CServerPath cygwin3(L"//", CYGWIN);
const CServerPath cygwin4(L"//foo", CYGWIN);
CPPUNIT_ASSERT(cygwin1.FormatFilename(L"bar", false) == L"/bar");
CPPUNIT_ASSERT(cygwin2.FormatFilename(L"bar", false) == L"/foo/bar");
CPPUNIT_ASSERT(cygwin3.FormatFilename(L"bar", false) == L"//bar");
CPPUNIT_ASSERT(cygwin4.FormatFilename(L"bar", false) == L"//foo/bar");
{
const CServerPath dos_slashes1(L"C:\\", DOS_FWD_SLASHES);
const CServerPath dos_slashes2(L"C:\\foo", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes1.FormatFilename(L"bar", false) == L"C:/bar");
CPPUNIT_ASSERT(dos_slashes2.FormatFilename(L"bar", false) == L"C:/foo/bar");
}
}
void CServerPathTest::testChangePath()
{
CServerPath unix1(L"/foo/bar");
CServerPath unix2(L"/foo/bar/baz");
CServerPath unix3(L"/foo/baz");
CServerPath unix4(L"/foo/bar/baz");
CServerPath unix5(L"/foo");
CPPUNIT_ASSERT(unix1.ChangePath(L"baz") && unix1 == unix2);
CPPUNIT_ASSERT(unix2.ChangePath(L"../../baz") && unix2 == unix3);
CPPUNIT_ASSERT(unix3.ChangePath(L"/foo/bar/baz") && unix3 == unix4);
CPPUNIT_ASSERT(unix3.ChangePath(L".") && unix3 == unix4);
std::wstring sub = L"../../bar";
CPPUNIT_ASSERT(unix4.ChangePath(sub, true) && unix4 == unix5 && sub == L"bar");
sub = L"bar/";
CPPUNIT_ASSERT(!unix4.ChangePath(sub, true));
const CServerPath vms1(L"FOO:[BAR]");
CServerPath vms2(L"FOO:[BAR]");
CServerPath vms3(L"FOO:[BAR.BAZ]");
CServerPath vms4(L"FOO:[BAR]");
CServerPath vms5(L"FOO:[BAR.BAZ.BAR]");
CServerPath vms6(L"FOO:[BAR]");
CServerPath vms7(L"FOO:[BAR]");
CServerPath vms8(L"FOO:[BAR]");
CServerPath vms9(L"FOO:[BAZ.BAR]");
CServerPath vms10(L"DOO:[BAZ.BAR]");
CPPUNIT_ASSERT(vms2.ChangePath(L"BAZ") && vms2 == vms3);
CPPUNIT_ASSERT(vms4.ChangePath(L"BAZ.BAR") && vms4 == vms5);
sub = L"BAZ.BAR";
CPPUNIT_ASSERT(vms6.ChangePath(sub, true) && vms6 == vms1 && sub == L"BAZ.BAR");
sub = L"[BAZ.BAR]FOO";
CPPUNIT_ASSERT(!vms7.ChangePath(sub, false));
CPPUNIT_ASSERT(vms8.ChangePath(sub, true) && vms8 == vms9 && sub == L"FOO");
CPPUNIT_ASSERT(vms10.ChangePath(L"FOO:[BAR]") && vms10 == vms1);
{
const CServerPath dos1(L"c:\\bar");
CServerPath dos2(L"c:\\bar");
CServerPath dos3(L"c:\\bar\\baz");
CServerPath dos4(L"c:\\bar");
CServerPath dos5(L"c:\\bar\\baz\\bar");
CServerPath dos6(L"c:\\bar\\baz\\");
CServerPath dos7(L"d:\\bar");
CServerPath dos8(L"c:\\bar\\baz");
CServerPath dos9(L"c:\\bar\\");
CServerPath dos10(L"md:\\bar\\", DOS);
CPPUNIT_ASSERT(dos2.ChangePath(L"baz") && dos2 == dos3);
CPPUNIT_ASSERT(dos4.ChangePath(L"baz\\bar") && dos4 == dos5);
CPPUNIT_ASSERT(dos5.ChangePath(L"\\bar\\") && dos5 == dos1);
CPPUNIT_ASSERT(dos6.ChangePath(L"..\\..\\.\\foo\\..\\bar") && dos6 == dos1);
CPPUNIT_ASSERT(dos7.ChangePath(L"c:\\bar") && dos7 == dos1);
sub = L"\\bar\\foo";
CPPUNIT_ASSERT(dos8.ChangePath(sub, true) && dos8 == dos1 && sub == L"foo");
sub = L"baz\\foo";
CPPUNIT_ASSERT(dos9.ChangePath(sub, true) && dos9 == dos3 && sub == L"foo");
CPPUNIT_ASSERT(dos9.ChangePath(L"md:\\bar\\") && dos9 == dos10);
}
const CServerPath mvs1(L"'BAR.'", MVS);
CServerPath mvs2(L"'BAR.'", MVS);
CServerPath mvs3(L"'BAR.BAZ.'", MVS);
CServerPath mvs4(L"'BAR.'", MVS);
CServerPath mvs5(L"'BAR.BAZ.BAR'", MVS);
CServerPath mvs6(L"'BAR.'", MVS);
CServerPath mvs7(L"'BAR.'", MVS);
CServerPath mvs8(L"'BAR.'", MVS);
CServerPath mvs9(L"'BAR.BAZ'", MVS);
CServerPath mvs10(L"'BAR.BAZ.'", MVS);
CServerPath mvs11(L"'BAR.BAZ'", MVS);
CServerPath mvs12(L"'BAR.BAZ'", MVS);
CPPUNIT_ASSERT(mvs2.ChangePath(L"BAZ.") && mvs2 == mvs3);
CPPUNIT_ASSERT(mvs4.ChangePath(L"BAZ.BAR") && mvs4 == mvs5);
sub = L"BAZ.BAR";
CPPUNIT_ASSERT(mvs6.ChangePath(sub, true) && mvs6 == mvs3 && sub == L"BAR");
sub = L"BAZ.BAR.";
CPPUNIT_ASSERT(!mvs7.ChangePath(sub, true));
sub = L"BAZ(BAR)";
CPPUNIT_ASSERT(mvs8.ChangePath(sub, true) && mvs8 == mvs9 && sub == L"BAR");
CPPUNIT_ASSERT(!mvs5.ChangePath(L"(FOO)"));
CPPUNIT_ASSERT(!mvs9.ChangePath(L"FOO"));
sub = L"(FOO)";
CPPUNIT_ASSERT(!mvs10.ChangePath(sub));
sub = L"(FOO)";
CPPUNIT_ASSERT(mvs11.ChangePath(sub, true) && mvs11 == mvs12 && sub == L"FOO");
const CServerPath vxworks1(L":foo:bar");
CServerPath vxworks2(L":foo:bar");
CServerPath vxworks3(L":foo:bar/baz");
CServerPath vxworks4(L":foo:bar");
CServerPath vxworks5(L":foo:bar/baz/bar");
CServerPath vxworks6(L":foo:bar/baz/");
CServerPath vxworks7(L":bar:bar");
CServerPath vxworks8(L":foo:bar/baz");
CServerPath vxworks9(L":foo:bar/baz/bar");
CPPUNIT_ASSERT(vxworks2.ChangePath(L"baz") && vxworks2 == vxworks3);
CPPUNIT_ASSERT(vxworks4.ChangePath(L"baz/bar") && vxworks4 == vxworks5);
CPPUNIT_ASSERT(vxworks6.ChangePath(L"../.././foo/../bar") && vxworks6 == vxworks1);
CPPUNIT_ASSERT(vxworks7.ChangePath(L":foo:bar") && vxworks7 == vxworks1);
sub = L"bar/foo";
CPPUNIT_ASSERT(vxworks8.ChangePath(sub, true) && vxworks8 == vxworks9 && sub == L"foo");
// ZVM is same as Unix, only makes difference in directory
// listing parser.
CServerPath zvm1(L"/foo/bar", ZVM);
CServerPath zvm2(L"/foo/bar/baz", ZVM);
CServerPath zvm3(L"/foo/baz", ZVM);
CServerPath zvm4(L"/foo/bar/baz", ZVM);
CServerPath zvm5(L"/foo", ZVM);
CPPUNIT_ASSERT(zvm1.ChangePath(L"baz") && zvm1 == zvm2);
CPPUNIT_ASSERT(zvm2.ChangePath(L"../../baz") && zvm2 == zvm3);
CPPUNIT_ASSERT(zvm3.ChangePath(L"/foo/bar/baz") && zvm3 == zvm4);
CPPUNIT_ASSERT(zvm3.ChangePath(L".") && zvm3 == zvm4);
sub = L"../../bar";
CPPUNIT_ASSERT(zvm4.ChangePath(sub, true) && zvm4 == zvm5 && sub == L"bar");
sub = L"bar/";
CPPUNIT_ASSERT(!zvm4.ChangePath(sub, true));
CServerPath hpnonstop1(L"\\mysys.$myvol", HPNONSTOP);
CServerPath hpnonstop2(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CServerPath hpnonstop3(L"\\mysys.$myvol2", HPNONSTOP);
CServerPath hpnonstop4(L"\\mysys.$myvol.mysubvol", HPNONSTOP);
CServerPath hpnonstop5(L"\\mysys", HPNONSTOP);
CPPUNIT_ASSERT(hpnonstop1.ChangePath(L"mysubvol") && hpnonstop1 == hpnonstop2);
CPPUNIT_ASSERT(hpnonstop3.ChangePath(L"\\mysys.$myvol.mysubvol") && hpnonstop3 == hpnonstop4);
sub = L"bar";
CPPUNIT_ASSERT(hpnonstop2.ChangePath(sub, true) && hpnonstop2 == hpnonstop4 && sub == L"bar");
sub = L"$myvol.mysubvol.bar";
CPPUNIT_ASSERT(hpnonstop5.ChangePath(sub, true) && hpnonstop5 == hpnonstop4 && sub == L"bar");
sub = L"bar.";
CPPUNIT_ASSERT(!hpnonstop4.ChangePath(sub, true));
CServerPath dos_virtual1(L"\\foo\\bar");
CServerPath dos_virtual2(L"\\foo\\bar\\baz");
CServerPath dos_virtual3(L"\\foo\\baz");
CServerPath dos_virtual4(L"\\foo\\bar\\baz");
CServerPath dos_virtual5(L"\\foo");
CPPUNIT_ASSERT(dos_virtual1.ChangePath(L"baz") && dos_virtual1 == dos_virtual2);
CPPUNIT_ASSERT(dos_virtual2.ChangePath(L"..\\..\\baz") && dos_virtual2 == dos_virtual3);
CPPUNIT_ASSERT(dos_virtual3.ChangePath(L"\\foo\\bar\\baz") && dos_virtual3 == dos_virtual4);
CPPUNIT_ASSERT(dos_virtual3.ChangePath(L".") && dos_virtual3 == dos_virtual4);
sub = L"..\\..\\bar";
CPPUNIT_ASSERT(dos_virtual4.ChangePath(sub, true) && dos_virtual4 == dos_virtual5 && sub == L"bar");
sub = L"bar\\";
CPPUNIT_ASSERT(!dos_virtual4.ChangePath(sub, true));
CServerPath cygwin1(L"/foo/bar", CYGWIN);
CServerPath cygwin2(L"/foo/bar/baz", CYGWIN);
CServerPath cygwin3(L"/foo/baz", CYGWIN);
CServerPath cygwin4(L"/foo/bar/baz", CYGWIN);
CServerPath cygwin5(L"/foo", CYGWIN);
CServerPath cygwin6(L"//foo", CYGWIN);
CServerPath cygwin7(L"//", CYGWIN);
CPPUNIT_ASSERT(cygwin1.ChangePath(L"baz") && cygwin1 == cygwin2);
CPPUNIT_ASSERT(cygwin2.ChangePath(L"../../baz") && cygwin2 == cygwin3);
CPPUNIT_ASSERT(cygwin3.ChangePath(L"/foo/bar/baz") && cygwin3 == cygwin4);
CPPUNIT_ASSERT(cygwin3.ChangePath(L".") && cygwin3 == cygwin4);
sub = L"../../bar";
CPPUNIT_ASSERT(cygwin4.ChangePath(sub, true) && cygwin4 == cygwin5 && sub == L"bar");
sub = L"bar/";
CPPUNIT_ASSERT(!cygwin4.ChangePath(sub, true));
CPPUNIT_ASSERT(cygwin5.ChangePath(L"//foo") && cygwin5 == cygwin6);
sub = L"//foo";
CPPUNIT_ASSERT(cygwin1.ChangePath(sub, true) && cygwin1 == cygwin7 && sub == L"foo");
{
const CServerPath dos_slashes1(L"c:\\bar", DOS_FWD_SLASHES);
CServerPath dos_slashes2(L"c:\\bar", DOS_FWD_SLASHES);
CServerPath dos_slashes3(L"c:\\bar/baz", DOS_FWD_SLASHES);
CServerPath dos_slashes4(L"c:\\bar", DOS_FWD_SLASHES);
CServerPath dos_slashes5(L"c:\\bar\\baz\\bar", DOS_FWD_SLASHES);
CServerPath dos_slashes6(L"c:\\bar\\baz\\", DOS_FWD_SLASHES);
CServerPath dos_slashes7(L"d:/bar", DOS_FWD_SLASHES);
CServerPath dos_slashes8(L"c:\\bar\\baz", DOS_FWD_SLASHES);
CServerPath dos_slashes9(L"c:\\bar\\", DOS_FWD_SLASHES);
CServerPath dos_slashes10(L"md:\\bar\\", DOS_FWD_SLASHES);
CPPUNIT_ASSERT(dos_slashes2.ChangePath(L"baz") && dos_slashes2 == dos_slashes3);
CPPUNIT_ASSERT(dos_slashes4.ChangePath(L"baz\\bar") && dos_slashes4 == dos_slashes5);
CPPUNIT_ASSERT(dos_slashes5.ChangePath(L"\\bar\\") && dos_slashes5 == dos_slashes1);
CPPUNIT_ASSERT(dos_slashes6.ChangePath(L"..\\..\\.\\foo\\..\\bar") && dos_slashes6 == dos_slashes1);
CPPUNIT_ASSERT(dos_slashes7.ChangePath(L"c:\\bar") && dos_slashes7 == dos_slashes1);
sub = L"\\bar\\foo";
CPPUNIT_ASSERT(dos_slashes8.ChangePath(sub, true) && dos_slashes8 == dos_slashes1 && sub == L"foo");
sub = L"baz\\foo";
CPPUNIT_ASSERT(dos_slashes9.ChangePath(sub, true) && dos_slashes9 == dos_slashes3 && sub == L"foo");
CPPUNIT_ASSERT(dos_slashes9.ChangePath(L"md:\\bar\\") && dos_slashes9 == dos_slashes10);
}
}
|