Changeset 55499 in vbox for trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp
- Timestamp:
- Apr 28, 2015 11:54:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTGetOptArgv.cpp
r55494 r55499 33 33 #include <iprt/param.h> 34 34 #include <iprt/getopt.h> 35 #include <iprt/ldr.h> 35 36 #include <iprt/string.h> 36 37 #include <iprt/test.h> … … 173 174 "arg1 \"arg2=\\\"zyx\\\"\" arg3=\\\\\\" 174 175 }, 176 { 177 " a\\\\\\\\b d\"e f\"g h ij\t", 178 NULL, 179 4, 180 { 181 "a\\\\b", 182 "de fg", 183 "h", 184 "ij", 185 NULL, NULL, NULL, NULL, 186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 187 }, 188 "'a\\\\b' 'de fg' h ij", 189 "a\\\\b \"de fg\" h ij", 190 } 175 191 }; 192 193 194 195 static void tstCheckNativeMsCrtToArgv(const char *pszCmdLine, int cExpectedArgs, const char * const *papszExpectedArgs) 196 { 197 #ifdef RT_OS_WINDOWS 198 /* 199 * Resolve APIs. 200 */ 201 static void *(__stdcall * s_pfnLocalFree)(void *pvFree); 202 static PRTUTF16 *(__stdcall * s_pfnCommandLineToArgvW)(PCRTUTF16 pwszCmdLine, int *pcArgs); 203 if (!s_pfnCommandLineToArgvW) 204 { 205 *(void **)&s_pfnLocalFree = RTLdrGetSystemSymbol("kernel32.dll", "LocalFree"); 206 RTTESTI_CHECK_RETV(s_pfnLocalFree != NULL); 207 *(void **)&s_pfnCommandLineToArgvW = RTLdrGetSystemSymbol("shell32.dll", "CommandLineToArgvW"); 208 RTTESTI_CHECK_RETV(s_pfnCommandLineToArgvW != NULL); 209 } 210 211 /* 212 * Calc expected arguments if needed. 213 */ 214 if (cExpectedArgs == -1) 215 for (cExpectedArgs = 0; papszExpectedArgs[cExpectedArgs]; cExpectedArgs++) 216 { /* nothing */ } 217 218 /* 219 * Convert input command line to UTF-16 and call native API. 220 */ 221 RTUTF16 wszCmdLine[1024]; 222 PRTUTF16 pwszCmdLine = &wszCmdLine[1]; 223 RTTESTI_CHECK_RC_RETV(RTStrToUtf16Ex(pszCmdLine, RTSTR_MAX, &pwszCmdLine, 1023, NULL), VINF_SUCCESS); 224 wszCmdLine[0] = ' '; 225 226 int cArgs = -2; 227 PRTUTF16 *papwszArgs = s_pfnCommandLineToArgvW(wszCmdLine, &cArgs); 228 229 /* 230 * Check the result. 231 */ 232 if (cArgs - 1 != cExpectedArgs) 233 RTTestIFailed("Native returns cArgs=%d, expected %d (cmdline=|%s|)", cArgs - 1, cExpectedArgs, pszCmdLine); 234 int cArgsCheck = RT_MIN(cArgs - 1, cExpectedArgs); 235 for (int i = 0; i < cArgsCheck; i++) 236 { 237 char *pszArg = NULL; 238 RTTESTI_CHECK_RC_RETV(RTUtf16ToUtf8(papwszArgs[i + 1], &pszArg), VINF_SUCCESS); 239 if (strcmp(pszArg, papszExpectedArgs[i])) 240 RTTestIFailed("Native returns argv[%i]='%s', expected '%s' (cmdline=|%s|)", 241 i, pszArg, papszExpectedArgs[i], pszCmdLine); 242 RTStrFree(pszArg); 243 } 244 245 if (papwszArgs) 246 s_pfnLocalFree(papwszArgs); 247 #else 248 NOREF(pszCmdLine); 249 NOREF(cExpectedArgs); 250 NOREF(papszExpectedArgs); 251 #endif 252 } 253 176 254 177 255 … … 194 272 for (int iArg = 0; iArg < cArgs1; iArg++) 195 273 if (strcmp(papszArgs1[iArg], g_aBourneTests[i].apszArgs[iArg]) != 0) 196 RTTestIFailed("g_aBourneTests[%i]/ #1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))",274 RTTestIFailed("g_aBourneTests[%i]/1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", 197 275 i, iArg, papszArgs1[iArg], g_aBourneTests[i].apszArgs[iArg], 198 276 g_aBourneTests[i].pszInput, g_aBourneTests[i].pszSeparators); … … 287 365 int rc = RTGetOptArgvToString(&pszCmdLine, s_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 288 366 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 289 if (strcmp(s_aMscCrtTests[i].pszCmdLine, pszCmdLine)) 367 if (!strcmp(s_aMscCrtTests[i].pszCmdLine, pszCmdLine)) 368 tstCheckNativeMsCrtToArgv(pszCmdLine, -1, s_aMscCrtTests[i].apszArgs); 369 else 290 370 RTTestIFailed("g_aTest[%i] failed:\n" 291 371 " got '%s'\n" … … 300 380 int rc = RTGetOptArgvToString(&pszCmdLine, g_aBourneTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); 301 381 RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); 302 if (strcmp(g_aBourneTests[i].pszOutMsCrt, pszCmdLine)) 382 if (!strcmp(g_aBourneTests[i].pszOutMsCrt, pszCmdLine)) 383 tstCheckNativeMsCrtToArgv(pszCmdLine, g_aBourneTests[i].cArgs, g_aBourneTests[i].apszArgs); 384 else 303 385 RTTestIFailed("g_aBourneTests[%i] failed:\n" 304 386 " got |%s|\n"
Note:
See TracChangeset
for help on using the changeset viewer.