Changeset 103285 in vbox for trunk/src/VBox/HostServices/SharedFolders/testcase/tstShflCase.cpp
- Timestamp:
- Feb 8, 2024 3:27:12 PM (13 months ago)
- svn:sync-xref-src-repo-rev:
- 161579
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedFolders/testcase/tstShflCase.cpp
r103275 r103285 1 1 /** @file 2 2 * Testcase for shared folder case conversion code. 3 * 4 * @todo r=andy Testcase needs to be rewritten using the test framework. 5 * Otherwise it's almost pointless to run this on the testboxes. 3 6 */ 4 7 … … 42 45 #include <iprt/path.h> 43 46 #include <iprt/string.h> 47 #include <iprt/test.h> 44 48 #include <iprt/uni.h> 45 49 #include <stdio.h> … … 205 209 } 206 210 207 static int vbsfCorrectCasing(char *pszFullPath, char *pszStartComponent )211 static int vbsfCorrectCasing(char *pszFullPath, char *pszStartComponent, size_t cbStartComponent) 208 212 { 209 213 PRTDIRENTRYEX pDirEntry = NULL; … … 230 234 Assert(*(pszStartComponent-1) == RTPATH_DELIMITER); 231 235 *(pszStartComponent-1) = 0; 232 strcpy(pDirEntry->szName, pszFullPath); 236 rc = RTStrCopy(pDirEntry->szName, sizeof(pDirEntry->szName), pszFullPath); 237 if (RT_FAILURE(rc)) 238 goto end; 233 239 szWildCard[0] = RTPATH_DELIMITER; 234 240 szWildCard[1] = '*'; 235 241 szWildCard[2] = 0; 236 strcat(pDirEntry->szName, szWildCard); 237 242 rc = RTStrCat(pDirEntry->szName, sizeof(pDirEntry->szName), szWildCard); 243 if (RT_FAILURE(rc)) 244 goto end; 238 245 rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT, 0 /*fFlags*/); 239 246 *(pszStartComponent-1) = RTPATH_DELIMITER; … … 263 270 { 264 271 Log(("Found original name %s (%s)\n", &pDirEntry->szName[0], pszStartComponent)); 265 strcpy(pszStartComponent, &pDirEntry->szName[0]); 266 rc = VINF_SUCCESS; 272 rc = RTStrCopy(pszStartComponent, cbStartComponent, &pDirEntry->szName[0]); 267 273 break; 268 274 } … … 282 288 283 289 284 static int testCase(char *pszFullPath, bool fWildCard = false)290 static int testCase(char *pszFullPath, size_t cbFullPath, bool fWildCard = false) 285 291 { 286 292 int rc; … … 291 297 { 292 298 /* strip off the last path component, that contains the wildcard(s) */ 293 size_t 294 char *src = pszFullPath +len - 1;295 296 while( src > pszFullPath)297 { 298 if (* src == RTPATH_DELIMITER)299 size_t cchLlen = strlen(pszFullPath); 300 char *pszSrc = pszFullPath + cchLlen - 1; 301 302 while(pszSrc > pszFullPath) 303 { 304 if (*pszSrc == RTPATH_DELIMITER) 299 305 break; 300 src--;301 } 302 if (* src == RTPATH_DELIMITER)306 pszSrc--; 307 } 308 if (*pszSrc == RTPATH_DELIMITER) 303 309 { 304 310 bool fHaveWildcards = false; 305 char *temp = src;311 char *temp = pszSrc; 306 312 307 313 while(*temp) … … 319 325 if (fHaveWildcards) 320 326 { 321 pszWildCardComponent = src;327 pszWildCardComponent = pszSrc; 322 328 *pszWildCardComponent = 0; 323 329 } … … 328 334 if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND) 329 335 { 330 size_t len = strlen(pszFullPath);331 char *src = pszFullPath + len - 1;336 size_t cchLen = strlen(pszFullPath); 337 char *pszSrc = pszFullPath + cchLen - 1; 332 338 333 339 Log(("Handle case insensitive guest fs on top of host case sensitive fs for %s\n", pszFullPath)); 334 340 335 341 /* Find partial path that's valid */ 336 while( src > pszFullPath)337 { 338 if (* src == RTPATH_DELIMITER)342 while(pszSrc > pszFullPath) 343 { 344 if (*pszSrc == RTPATH_DELIMITER) 339 345 { 340 * src = 0;346 *pszSrc = 0; 341 347 rc = RTPathQueryInfo (pszFullPath, &info, RTFSOBJATTRADD_NOTHING); 342 * src = RTPATH_DELIMITER;348 *pszSrc = RTPATH_DELIMITER; 343 349 if (rc == VINF_SUCCESS) 344 350 { 345 351 #ifdef DEBUG 346 * src = 0;352 *pszSrc = 0; 347 353 Log(("Found valid partial path %s\n", pszFullPath)); 348 * src = RTPATH_DELIMITER;354 *pszSrc = RTPATH_DELIMITER; 349 355 #endif 350 356 break; … … 352 358 } 353 359 354 src--;355 } 356 Assert(* src == RTPATH_DELIMITER && RT_SUCCESS(rc));357 if ( * src == RTPATH_DELIMITER360 pszSrc--; 361 } 362 Assert(*pszSrc == RTPATH_DELIMITER && RT_SUCCESS(rc)); 363 if ( *pszSrc == RTPATH_DELIMITER 358 364 && RT_SUCCESS(rc)) 359 365 { 360 src++;366 pszSrc++; 361 367 for(;;) 362 368 { 363 char *end = src;369 char *end = pszSrc; 364 370 bool fEndOfString = true; 365 371 … … 375 381 fEndOfString = false; 376 382 *end = 0; 377 rc = RTPathQueryInfo( src, &info, RTFSOBJATTRADD_NOTHING);383 rc = RTPathQueryInfo(pszSrc, &info, RTFSOBJATTRADD_NOTHING); 378 384 Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND); 379 385 } 380 386 else 381 if (end == src)387 if (end == pszSrc) 382 388 rc = VINF_SUCCESS; /* trailing delimiter */ 383 389 else … … 387 393 { 388 394 /* path component is invalid; try to correct the casing */ 389 rc = vbsfCorrectCasing(pszFullPath, src);395 rc = vbsfCorrectCasing(pszFullPath, pszSrc, cbFullPath - (pszFullPath - pszSrc)); 390 396 if (RT_FAILURE(rc)) 391 397 { … … 400 406 401 407 *end = RTPATH_DELIMITER; 402 src = end + 1;408 pszSrc = end + 1; 403 409 } 404 410 if (RT_FAILURE(rc)) … … 430 436 RTLogFlags(NULL, "unbuffered"); 431 437 432 strcpy(szTest, "c:\\test Dir\\z.bAt");433 testCase(szTest );434 strcpy(szTest, "c:\\test dir\\z.bAt");435 testCase(szTest );436 strcpy(szTest, "c:\\test dir\\SUBDIR\\z.bAt");437 testCase(szTest );438 strcpy(szTest, "c:\\test dir\\SUBDiR\\atestje.bat");439 testCase(szTest );440 strcpy(szTest, "c:\\TEST dir\\subDiR\\aTestje.baT");441 testCase(szTest );442 strcpy(szTest, "c:\\TEST dir\\subDiR\\*");443 testCase(szTest, true);444 strcpy(szTest, "c:\\TEST dir\\subDiR\\");445 testCase(szTest , true);446 strcpy(szTest, "c:\\test dir\\SUBDIR\\");447 testCase(szTest );448 strcpy(szTest, "c:\\test dir\\invalid\\SUBDIR\\test.bat");449 testCase(szTest );438 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test Dir\\z.bAt")); 439 testCase(szTest, sizeof(szTest)); 440 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\z.bAt")); 441 testCase(szTest, sizeof(szTest)); 442 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDIR\\z.bAt")); 443 testCase(szTest, sizeof(szTest)); 444 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDiR\\atestje.bat")); 445 testCase(szTest, sizeof(szTest)); 446 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\aTestje.baT")); 447 testCase(szTest, sizeof(szTest)); 448 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\*")); 449 testCase(szTest, sizeof(szTest), true); 450 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\TEST dir\\subDiR\\")); 451 testCase(szTest ,sizeof(szTest), true); 452 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\SUBDIR\\")); 453 testCase(szTest, sizeof(szTest)); 454 RTTESTI_CHECK_RC_OK(RTStrCopy(szTest, sizeof(szTest), "c:\\test dir\\invalid\\SUBDIR\\test.bat")); 455 testCase(szTest, sizeof(szTest)); 450 456 return 0; 451 457 }
Note:
See TracChangeset
for help on using the changeset viewer.