b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * IPRT Testcase - RTGetOptArgv*.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010 Oracle Corporation
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * available from http://www.virtualbox.org. This file is free software;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * General Public License (GPL) as published by the Free Software
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * The contents of this file may alternatively be used under the terms
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * of the Common Development and Distribution License Version 1.0
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * VirtualBox OSE distribution, in which case the provisions of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * CDDL are applicable instead of those of the GPL.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * You may elect to license modified versions of this file under the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * terms and conditions of either the GPL or the CDDL or both.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync/*******************************************************************************
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync* Header Files *
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync*******************************************************************************/
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync static const struct
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync "abcd \"a \" \" b\" \" c \""
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync "a\\\\\\b \"de fg\" h"
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync "\"a\\\\\\\"b\" c d \"\\\"\""
53f225cb141e4ba722041eb59dea3df589a6cba4vboxsync "\"a\\\\b c\" d e \" \\\\\""
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync for (size_t i = 0; i < RT_ELEMENTS(s_aMscCrtTests); i++)
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync int rc = RTGetOptArgvToString(&pszCmdLine, s_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync if (strcmp(s_aMscCrtTests[i].pszCmdLine, pszCmdLine))
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync " got '%s'\n"
e8d7104a0c14c78c147fedeb2dee7053a17354ebvboxsync " expected '%s'\n",
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync static const struct
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync "abcd 'a ' ' b' ' c '"
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync "'a\n\\b' 'de'\"'\"'fg' h ''\"'\"''"
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++)
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync if (strcmp(s_aBournShTests[i].pszCmdLine, pszCmdLine))
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync " got |%s|\n"
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync " expected |%s|\n",
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync RTTestISub("RTGetOptArgvToString <-> RTGetOptArgvFromString");
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync for (size_t i = 0; i < RT_ELEMENTS(s_aBournShTests); i++)
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync int rc = RTGetOptArgvToString(&pszCmdLine, s_aBournShTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszCmdLine, NULL);
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync while (papszArgs[j] && s_aBournShTests[i].apszArgs[j])
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync if (strcmp(papszArgs[j], s_aBournShTests[i].apszArgs[j]))
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync " FromString: |%s| (got)\n"
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync " ToString: |%s| (expected)\n",
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync i, j, papszArgs[j], s_aBournShTests[i].apszArgs[j]);
ddee36cc1075885bd13dabbd814f18e6090b157fvboxsync RTTESTI_CHECK(s_aBournShTests[i].apszArgs[j] == NULL);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "", NULL), VINF_SUCCESS);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11", NULL), VINF_SUCCESS);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "\t\" asdf \" '\"'xyz \"\t\" '\n' '\"' \"'\"\n\r ", NULL), VINF_SUCCESS);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], " asdf "));
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RETV(!strcmp(papszArgs[1], "\"xyz"));
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, ":0::1::::2:3:4:5:", ":"), VINF_SUCCESS);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0:1;2:3;4:5", ";;;;;;;;;;;;;;;;;;;;;;:"), VINF_SUCCESS);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * Init RT+Test.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync int rc = RTTestInitAndCreate("tstRTGetOptArgv", &hTest);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * The test.