Changeset 27968 in vbox
- Timestamp:
- Apr 2, 2010 8:36:35 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
-
common/misc/getoptargv.cpp (modified) (2 diffs)
-
testcase/tstRTGetOptArgv.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/getoptargv.cpp
r27386 r27968 390 390 { 391 391 AssertReturn(!(fFlags & ~RTGETOPTARGV_CNV_QUOTE_MASK), VERR_INVALID_PARAMETER); 392 AssertReturn((fFlags & RTGETOPTARGV_CNV_QUOTE_MASK) == RTGETOPTARGV_CNV_QUOTE_MS_CRT, VERR_NOT_IMPLEMENTED);393 392 394 393 #define PUT_CH(ch) \ … … 462 461 PUT_CH('"'); 463 462 } 464 else /* bourne shell */ 465 { 466 AssertFailed(/*later*/); 463 else 464 { 465 /* 466 * Bourne Shell quoting. Quote the whole thing in single quotes 467 * and use double quotes for any single quote chars. 468 */ 469 PUT_CH('\''); 470 char ch; 471 while ((ch = *pszArg++)) 472 { 473 if (ch == '\'') 474 { 475 PUT_SZ("'\"'\"'"); 476 } 477 else 478 { 479 PUT_CH(ch); 480 } 481 } 482 PUT_CH('\''); 467 483 } 468 484 } -
trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp
r27797 r27968 49 49 const char * const apszArgs[5]; 50 50 const char *pszCmdLine; 51 } s_a Tests[] =51 } s_aMscCrtTests[] = 52 52 { 53 53 { … … 69 69 }; 70 70 71 for (size_t i = 0; i < RT_ELEMENTS(s_a Tests); i++)71 for (size_t i = 0; i < RT_ELEMENTS(s_aMscCrtTests); i++) 72 72 { 73 73 char *pszCmdLine = NULL; 74 int rc = RTGetOptArgvToString(&pszCmdLine, s_a Tests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);75 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 76 if (strcmp(s_a Tests[i].pszCmdLine, pszCmdLine))74 int rc = RTGetOptArgvToString(&pszCmdLine, s_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 75 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 76 if (strcmp(s_aMscCrtTests[i].pszCmdLine, pszCmdLine)) 77 77 RTTestIFailed("g_aTest[%i] failed:\n" 78 78 " got '%s'\n" 79 79 " expected '%s'\n", 80 i, pszCmdLine, s_aTests[i].pszCmdLine); 80 i, pszCmdLine, s_aMscCrtTests[i].pszCmdLine); 81 RTStrFree(pszCmdLine); 82 } 83 84 85 RTTestISub("RTGetOptArgvToString / BOURNE_SH"); 86 87 static const struct 88 { 89 const char * const apszArgs[5]; 90 const char *pszCmdLine; 91 } s_aBournShTests[] = 92 { 93 { 94 { "abcd", "a ", " b", " c ", NULL }, 95 "abcd 'a ' ' b' ' c '" 96 }, 97 { 98 { "a\n\\b", "de'fg", "h", "'", NULL }, 99 "'a\n\\b' 'de'\"'\"'fg' h ''\"'\"''" 100 } 101 }; 102 103 for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++) 104 { 105 char *pszCmdLine = NULL; 106 int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); 107 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 108 if (strcmp(s_aBournShTests[i].pszCmdLine, pszCmdLine)) 109 RTTestIFailed("g_aTest[%i] failed:\n" 110 " got |%s|\n" 111 " expected |%s|\n", 112 i, pszCmdLine, s_aBournShTests[i].pszCmdLine); 113 RTStrFree(pszCmdLine); 114 } 115 116 117 RTTestISub("RTGetOptArgvToString <-> RTGetOptArgvFromString"); 118 119 for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++) 120 { 121 char *pszCmdLine = NULL; 122 int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); 123 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 124 125 char **papszArgs; 126 int cArgs; 127 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, NULL); 128 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 129 130 size_t j = 0; 131 while (papszArgs[j] && s_aBournShTests[i].apszArgs[j]) 132 { 133 if (strcmp(papszArgs[j], s_aBournShTests[i].apszArgs[j])) 134 RTTestIFailed("Test #%u, argument #%u mismatch:\n" 135 " FromString: |%s| (got)\n" 136 " ToString: |%s| (expected)\n", 137 i, j, papszArgs[j], s_aBournShTests[i].apszArgs[j]); 138 139 /* next */ 140 j++; 141 } 142 RTTESTI_CHECK(papszArgs[j] == NULL); 143 RTTESTI_CHECK(s_aBournShTests[i].apszArgs[j] == NULL); 144 145 RTGetOptArgvFree(papszArgs); 81 146 RTStrFree(pszCmdLine); 82 147 }
Note:
See TracChangeset
for help on using the changeset viewer.

