1 | /* $Id: tstRTGetOptArgv.cpp 26484 2010-02-14 02:15:03Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase - RTGetOptArgv*.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <iprt/path.h>
|
---|
35 |
|
---|
36 | #include <iprt/err.h>
|
---|
37 | #include <iprt/param.h>
|
---|
38 | #include <iprt/getopt.h>
|
---|
39 | #include <iprt/string.h>
|
---|
40 | #include <iprt/test.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | static void tst1(void)
|
---|
44 | {
|
---|
45 | RTTestISub("RTGetOptArgvFromString");
|
---|
46 | char **papszArgs = NULL;
|
---|
47 | int cArgs = -1;
|
---|
48 | RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "", NULL), VINF_SUCCESS);
|
---|
49 | RTTESTI_CHECK_RETV(cArgs == 0);
|
---|
50 | RTTESTI_CHECK_RETV(papszArgs);
|
---|
51 | RTTESTI_CHECK_RETV(!papszArgs[0]);
|
---|
52 | RTGetOptArgvFree(papszArgs);
|
---|
53 |
|
---|
54 | RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0 1 \"\"2'' '3' 4 5 '''''6' 7 8 9 10 11", NULL), VINF_SUCCESS);
|
---|
55 | RTTESTI_CHECK_RETV(cArgs == 12);
|
---|
56 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
|
---|
57 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[1], "1"));
|
---|
58 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[2], "2"));
|
---|
59 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[3], "3"));
|
---|
60 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[4], "4"));
|
---|
61 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[5], "5"));
|
---|
62 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[6], "6"));
|
---|
63 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[7], "7"));
|
---|
64 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[8], "8"));
|
---|
65 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[9], "9"));
|
---|
66 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[10], "10"));
|
---|
67 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[11], "11"));
|
---|
68 | RTTESTI_CHECK_RETV(!papszArgs[12]);
|
---|
69 | RTGetOptArgvFree(papszArgs);
|
---|
70 |
|
---|
71 | RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "\t\" asdf \" '\"'xyz \"\t\" '\n' '\"' \"'\"\n\r ", NULL), VINF_SUCCESS);
|
---|
72 | RTTESTI_CHECK_RETV(cArgs == 6);
|
---|
73 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], " asdf "));
|
---|
74 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[1], "\"xyz"));
|
---|
75 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[2], "\t"));
|
---|
76 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[3], "\n"));
|
---|
77 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[4], "\""));
|
---|
78 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[5], "\'"));
|
---|
79 | RTTESTI_CHECK_RETV(!papszArgs[6]);
|
---|
80 | RTGetOptArgvFree(papszArgs);
|
---|
81 |
|
---|
82 | RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, ":0::1::::2:3:4:5:", ":"), VINF_SUCCESS);
|
---|
83 | RTTESTI_CHECK_RETV(cArgs == 6);
|
---|
84 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
|
---|
85 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[1], "1"));
|
---|
86 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[2], "2"));
|
---|
87 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[3], "3"));
|
---|
88 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[4], "4"));
|
---|
89 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[5], "5"));
|
---|
90 | RTTESTI_CHECK_RETV(!papszArgs[6]);
|
---|
91 | RTGetOptArgvFree(papszArgs);
|
---|
92 |
|
---|
93 | RTTESTI_CHECK_RC_RETV(RTGetOptArgvFromString(&papszArgs, &cArgs, "0:1;2:3;4:5", ";;;;;;;;;;;;;;;;;;;;;;:"), VINF_SUCCESS);
|
---|
94 | RTTESTI_CHECK_RETV(cArgs == 6);
|
---|
95 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[0], "0"));
|
---|
96 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[1], "1"));
|
---|
97 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[2], "2"));
|
---|
98 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[3], "3"));
|
---|
99 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[4], "4"));
|
---|
100 | RTTESTI_CHECK_RETV(!strcmp(papszArgs[5], "5"));
|
---|
101 | RTTESTI_CHECK_RETV(!papszArgs[6]);
|
---|
102 | RTGetOptArgvFree(papszArgs);
|
---|
103 | }
|
---|
104 |
|
---|
105 | int main()
|
---|
106 | {
|
---|
107 | char szPath[RTPATH_MAX];
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Init RT+Test.
|
---|
111 | */
|
---|
112 | RTTEST hTest;
|
---|
113 | int rc = RTTestInitAndCreate("tstRTGetOptArgv", &hTest);
|
---|
114 | if (rc)
|
---|
115 | return rc;
|
---|
116 | RTTestBanner(hTest);
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * The test.
|
---|
120 | */
|
---|
121 | tst1();
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Summary.
|
---|
125 | */
|
---|
126 | return RTTestSummaryAndDestroy(hTest);
|
---|
127 | }
|
---|
128 |
|
---|