Changeset 85383 in vbox for trunk/src/VBox/Runtime/testcase/tstRTPath.cpp
- Timestamp:
- Jul 18, 2020 3:26:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.