Changeset 85383 in vbox
- Timestamp:
- Jul 18, 2020 3:26:42 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139397
- Location:
- trunk
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/path.h
r85382 r85383 525 525 * The paths are not made absolute or real, they are taken as given. 526 526 * 527 * @returns Length (in characters) of the common path, 0 if not found. 527 * @returns The common path length as represented by \a papszPaths[0], 0 if not 528 * found or invalid input. 528 529 * @param cPaths Number of paths in \a papszPaths. 529 * @param papszPaths Array of paths to find common path for. 530 * @param papszPaths Array of paths to find common path for. The paths must 531 * not contains ".." sequences, as that's too complicated 532 * to handle. 530 533 */ 531 534 RTDECL(size_t) RTPathFindCommon(size_t cPaths, const char * const *papszPaths); … … 536 539 * The paths are not made absolute or real, they are taken as given. 537 540 * 538 * @returns Length (in characters) of the common path, 0 if not found. 541 * @returns The common path length as represented by \a papszPaths[0], 0 if not 542 * found or invalid input. 539 543 * @param cPaths Number of paths in \a papszPaths. 540 * @param papszPaths Array of paths to find common path for. 541 * @param fFlags RTPATH_STR_F_STYLE_XXX. Other RTPATH_STR_F_XXX flags 542 * will be ignored. 544 * @param papszPaths Array of paths to find common path for. The paths must 545 * not contains ".." sequences, as that's too complicated 546 * to handle. 547 * @param fFlags RTPATH_STR_F_STYLE_XXX and RTPATH_STR_F_NO_START if 548 * wanted. Other RTPATH_STR_F_XXX flags will be ignored. 543 549 */ 544 550 RTDECL(size_t) RTPathFindCommonEx(size_t cPaths, const char * const *papszPaths, uint32_t fFlags); -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r85311 r85383 101 101 tstOnce \ 102 102 tstRTPath \ 103 tstRTPathFindCommon \104 103 tstRTPathGlob \ 105 104 tstRTPathQueryInfo \ -
trunk/src/VBox/Runtime/testcase/tstRTPath.cpp
r82968 r85383 353 353 RTTestFailed(hTest, "sub-test #%u: got '%s', expected '%s' (style %#x)", 354 354 i, szPath, s_aTests[i].pszOut, s_aTests[i].fFlags); 355 } 356 } 357 358 359 static void testFindCommon(RTTEST hTest) 360 { 361 RTTestSub(hTest, "RTPathFindCommon"); 362 363 static struct 364 { 365 char const *apszPaths[4]; 366 uint32_t fFlags; 367 char const *pszCommon; 368 } const aTests[] = 369 { 370 /* Simple stuff first. */ 371 { { "", "", "", NULL, }, RTPATH_STR_F_STYLE_UNIX, 372 "" }, 373 { { "none", "none", "", NULL, }, RTPATH_STR_F_STYLE_UNIX, 374 "" }, 375 /* Missing start slash. */ 376 { { "/path/to/stuff1", "path/to/stuff2", NULL, NULL, }, RTPATH_STR_F_STYLE_UNIX, 377 "" }, 378 /* Working stuff. */ 379 { { "/path/to/stuff1", "/path/to/stuff2", "/path/to/stuff3", NULL, }, RTPATH_STR_F_STYLE_UNIX, 380 "/path/to/" }, 381 { { "/path/to/stuff1", "/path/to/", "/path/", NULL, }, RTPATH_STR_F_STYLE_UNIX, 382 "/path/" }, 383 { { "/path/to/stuff1", "/", "/path/", NULL, }, RTPATH_STR_F_STYLE_UNIX, 384 "" }, 385 { { "/path/to/../stuff1", "./../", "/path/to/stuff2/..", NULL, }, RTPATH_STR_F_STYLE_UNIX, 386 "" }, 387 388 #if 0 /** @todo */ 389 /* Things that should be working that aren't: */ 390 { { "a/single/path", NULL, NULL, NULL, }, RTPATH_STR_F_STYLE_UNIX, 391 "a/single/path" }, 392 { { "a/single\\path", NULL, NULL, NULL, }, RTPATH_STR_F_STYLE_DOS, 393 "a/single\\path" }, 394 { { "C:\\Windows", NULL, NULL, NULL, }, RTPATH_STR_F_STYLE_DOS, 395 "C:\\Windows" }, 396 { { "c:/windows", "c:\\program files", "C:\\AppData", NULL, }, RTPATH_STR_F_STYLE_DOS, 397 "c:/" }, 398 { { "//usr/bin/env", "/usr//bin/env", "/usr/bin///env", "/usr/bin/env", }, RTPATH_STR_F_STYLE_UNIX, 399 "//usr/bin/env" }, 400 { { "//usr/bin/env", "/usr//./././bin/env", "/usr/bin///env", "/usr/bin/env", }, RTPATH_STR_F_STYLE_UNIX, 401 "//usr/bin/env" }, 402 { { "//./what/ever", "\\\\.\\what\\is\\up", "\\\\.\\\\what\\is\\up", NULL, }, RTPATH_STR_F_STYLE_DOS, 403 "//./what/" }, 404 { { "//./unc/is/weird", "///./unc/is/weird", NULL, NULL, }, RTPATH_STR_F_STYLE_DOS, 405 "" }, 406 { { "/path/to/stuff1", "path/to/stuff2", NULL, NULL, }, RTPATH_STR_F_STYLE_UNIX | RTPATH_STR_F_NO_START, 407 "/path/to/" }, 408 { { "path/to/stuff1", "//path\\/to\\stuff2", NULL, NULL, }, RTPATH_STR_F_STYLE_DOS | RTPATH_STR_F_NO_START, 409 "path/to/" }, 410 411 /* '..' elements are not supported for now and leads to zero return. */ 412 { { "/usr/bin/env", "/usr/../usr/bin/env", "/usr/bin/../bin/env", NULL, }, RTPATH_STR_F_STYLE_UNIX, 413 "" }, 414 { { "/lib/", "/lib/amd64/../lib.so", "/lib/i386/../libdl.so", NULL, }, RTPATH_STR_F_STYLE_UNIX, 415 "" }, 416 #endif 417 }; 418 419 for (size_t i = 0; i < RT_ELEMENTS(aTests); i++) 420 { 421 size_t cPaths = RT_ELEMENTS(aTests[i].apszPaths); 422 while (cPaths > 0 && aTests[i].apszPaths[cPaths - 1] == NULL) 423 cPaths--; 424 425 size_t const cchCommon = RTPathFindCommonEx(cPaths, aTests[i].apszPaths, aTests[i].fFlags); 426 size_t const cchExpect = strlen(aTests[i].pszCommon); 427 if (cchCommon != cchExpect) 428 RTTestFailed(hTest, 429 "Test %zu failed: got %zu, expected %zu (cPaths=%zu: '%s' '%s' '%s' '%s', fFlags=%#x)", i, cchCommon, 430 cchExpect, cPaths, aTests[i].apszPaths[0], aTests[i].apszPaths[1], aTests[i].apszPaths[2], 431 aTests[i].apszPaths[3], aTests[i].fFlags); 355 432 } 356 433 } … … 1087 1164 testPurgeFilename(hTest); 1088 1165 testEnsureTrailingSeparator(hTest); 1166 testFindCommon(hTest); 1089 1167 1090 1168 /*
Note:
See TracChangeset
for help on using the changeset viewer.