static void tst2(void) { RTTestISub("RTGetOptArgvToString / MS_CRT"); for (size_t i = 0; i < RT_ELEMENTS(g_aMscCrtTests); i++) { char *pszCmdLine = NULL; int rc = RTGetOptArgvToString(&pszCmdLine, g_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); if (!strcmp(g_aMscCrtTests[i].pszCmdLine, pszCmdLine)) tstCheckNativeMsCrtToArgv(pszCmdLine, -1, g_aMscCrtTests[i].apszArgs); else RTTestIFailed("g_aTest[%i] failed:\n" " got '%s'\n" " expected '%s'\n", i, pszCmdLine, g_aMscCrtTests[i].pszCmdLine); RTStrFree(pszCmdLine); } for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++) { char *pszCmdLine = NULL; int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT); RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); if (!strcmp(g_aTests[i].pszOutMsCrt, pszCmdLine)) tstCheckNativeMsCrtToArgv(pszCmdLine, g_aTests[i].cArgs, g_aTests[i].apszArgs); else RTTestIFailed("g_aTests[%i] failed:\n" " got |%s|\n" " expected |%s|\n", i, pszCmdLine, g_aTests[i].pszOutMsCrt); RTStrFree(pszCmdLine); } RTTestISub("RTGetOptArgvToString / BOURNE_SH"); for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++) { char *pszCmdLine = NULL; int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS); if (strcmp(g_aTests[i].pszOutBourneSh, pszCmdLine)) RTTestIFailed("g_aTests[%i] failed:\n" " got |%s|\n" " expected |%s|\n", i, pszCmdLine, g_aTests[i].pszOutBourneSh); RTStrFree(pszCmdLine); } }
/** * Executes SVN. * * Standard error and standard output is suppressed. * * @returns VINF_SUCCESS if the command executed successfully. * @param pState The rewrite state to work on. * @param papszArgs The SVN argument. * @param fNormalFailureOk Whether normal failure is ok. */ static int scmSvnRun(PSCMRWSTATE pState, const char **papszArgs, bool fNormalFailureOk) { char *pszCmdLine = NULL; int rc = RTGetOptArgvToString(&pszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); if (RT_FAILURE(rc)) return rc; ScmVerbose(pState, 2, "executing: %s\n", pszCmdLine); /* Lazy bird uses RTProcExecToString. */ RTPROCSTATUS Status; rc = RTProcExec(g_szSvnPath, papszArgs, RTENV_DEFAULT, RTPROCEXEC_FLAGS_STD_NULL, &Status); if ( RT_SUCCESS(rc) && ( Status.enmReason != RTPROCEXITREASON_NORMAL || Status.iStatus != 0) ) { if (fNormalFailureOk || Status.enmReason != RTPROCEXITREASON_NORMAL) RTMsgError("%s: %s -> %s %u\n", pState->pszFilename, pszCmdLine, Status.enmReason == RTPROCEXITREASON_NORMAL ? "exit code" : Status.enmReason == RTPROCEXITREASON_SIGNAL ? "signal" : Status.enmReason == RTPROCEXITREASON_ABEND ? "abnormal end" : "abducted by alien", Status.iStatus); rc = VERR_GENERAL_FAILURE; } else if (RT_FAILURE(rc)) RTMsgError("%s: %s -> %Rrc\n", pState->pszFilename, pszCmdLine, rc); RTStrFree(pszCmdLine); return rc; }
RTDECL(int) RTGetOptArgvToUtf16String(PRTUTF16 *ppwszCmdLine, const char * const *papszArgv, uint32_t fFlags) { char *pszCmdLine; int rc = RTGetOptArgvToString(&pszCmdLine, papszArgv, fFlags); if (RT_SUCCESS(rc)) { rc = RTStrToUtf16(pszCmdLine, ppwszCmdLine); RTStrFree(pszCmdLine); } return rc; }
static void tst3(void) { /* * Bourne shell round-tripping. */ RTTestISub("Round-trips / BOURNE_SH"); for (unsigned i = 0; i < RT_ELEMENTS(g_aTests); i++) { /* First */ char **papszArgs1 = NULL; int cArgs1 = -1; int rc = RTGetOptArgvFromString(&papszArgs1, &cArgs1, g_aTests[i].pszInBourne, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, g_aTests[i].pszSeparators); if (rc == VINF_SUCCESS) { if (cArgs1 != g_aTests[i].cArgs) RTTestIFailed("g_aTests[%i]: #1=%d, expected %d", i, cArgs1, g_aTests[i].cArgs); for (int iArg = 0; iArg < cArgs1; iArg++) if (strcmp(papszArgs1[iArg], g_aTests[i].apszArgs[iArg]) != 0) RTTestIFailed("g_aTests[%i]/1: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s', '%s'))", i, iArg, papszArgs1[iArg], g_aTests[i].apszArgs[iArg], g_aTests[i].pszInBourne, g_aTests[i].pszSeparators); RTTESTI_CHECK_RETV(papszArgs1[cArgs1] == NULL); /* Second */ char *pszArgs2 = NULL; rc = RTGetOptArgvToString(&pszArgs2, papszArgs1, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); if (rc == VINF_SUCCESS) { if (strcmp(pszArgs2, g_aTests[i].pszOutBourneSh)) RTTestIFailed("g_aTests[%i]/2: '%s', expected '%s'", i, pszArgs2, g_aTests[i].pszOutBourneSh); /* * Third */ char **papszArgs3 = NULL; int cArgs3 = -1; rc = RTGetOptArgvFromString(&papszArgs3, &cArgs3, pszArgs2, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL); if (rc == VINF_SUCCESS) { if (cArgs3 != g_aTests[i].cArgs) RTTestIFailed("g_aTests[%i]/3: %d, expected %d", i, cArgs3, g_aTests[i].cArgs); for (int iArg = 0; iArg < cArgs3; iArg++) if (strcmp(papszArgs3[iArg], g_aTests[i].apszArgs[iArg]) != 0) RTTestIFailed("g_aTests[%i]/3: argv[%i] differs: got '%s', expected '%s' (RTGetOptArgvFromString(,,'%s',))", i, iArg, papszArgs3[iArg], g_aTests[i].apszArgs[iArg], pszArgs2); RTTESTI_CHECK_RETV(papszArgs3[cArgs3] == NULL); /* * Fourth */ char *pszArgs4 = NULL; rc = RTGetOptArgvToString(&pszArgs4, papszArgs3, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); if (rc == VINF_SUCCESS) { if (strcmp(pszArgs4, pszArgs2)) RTTestIFailed("g_aTests[%i]/4: '%s' does not match #4='%s'", i, pszArgs2, pszArgs4); RTStrFree(pszArgs4); } else RTTestIFailed("g_aTests[%i]/4: RTGetOptArgvToString() -> %Rrc", i, rc); RTGetOptArgvFree(papszArgs3); } else RTTestIFailed("g_aTests[%i]/3: RTGetOptArgvFromString() -> %Rrc", i, rc); RTStrFree(pszArgs2); } else RTTestIFailed("g_aTests[%i]/2: RTGetOptArgvToString() -> %Rrc", i, rc); RTGetOptArgvFree(papszArgs1); } else RTTestIFailed("g_aTests[%i]/1: RTGetOptArgvFromString(,,'%s', '%s') -> %Rrc", i, g_aTests[i].pszInBourne, g_aTests[i].pszSeparators, rc); } }