3 #include <winpr/assert.h>
4 #include <winpr/tchar.h>
5 #include <winpr/cmdline.h>
6 #include <winpr/strlst.h>
8 static const char* testArgv[] = {
"mstsc.exe",
18 "/valuelist:value1,value2",
22 static const char testListAppName[] =
"test app name";
23 static const char* testListArgs[] = {
24 "a,b,c,d",
"a:,\"b:xxx, yyy\",c",
"a:,,,b",
"a:,\",b",
"\"a,b,c,d d d,fff\"",
"",
25 NULL,
"'a,b,\",c'",
"\"a,b,',c\"",
"', a, ', b,c'",
"\"a,b,\",c\""
28 static const char* testListArgs1[] = { testListAppName,
"a",
"b",
"c",
"d" };
29 static const char* testListArgs2[] = { testListAppName,
"a:",
"b:xxx, yyy",
"c" };
32 static const char* testListArgs5[] = { testListAppName,
"a",
"b",
"c",
"d d d",
"fff" };
33 static const char* testListArgs6[] = { testListAppName };
34 static const char* testListArgs7[] = { testListAppName };
35 static const char* testListArgs8[] = { testListAppName,
"a",
"b",
"\"",
"c" };
36 static const char* testListArgs9[] = { testListAppName,
"a",
"b",
"'",
"c" };
40 static const char** testListArgsResult[] = { testListArgs1,
51 static const size_t testListArgsCount[] = {
52 ARRAYSIZE(testListArgs1),
53 ARRAYSIZE(testListArgs2),
56 ARRAYSIZE(testListArgs5),
57 ARRAYSIZE(testListArgs6),
58 ARRAYSIZE(testListArgs7),
59 ARRAYSIZE(testListArgs8),
60 ARRAYSIZE(testListArgs9),
65 static BOOL checkResult(
size_t index,
char** actual,
size_t actualCount)
67 const char** result = testListArgsResult[index];
68 const size_t resultCount = testListArgsCount[index];
70 if (resultCount != actualCount)
75 return (actual == NULL);
82 for (
size_t x = 0; x < actualCount; x++)
84 const char* a = result[x];
85 const char* b = actual[x];
87 if (strcmp(a, b) != 0)
95 static BOOL TestCommandLineParseCommaSeparatedValuesEx(
void)
97 WINPR_ASSERT(ARRAYSIZE(testListArgs) == ARRAYSIZE(testListArgsResult));
98 WINPR_ASSERT(ARRAYSIZE(testListArgs) == ARRAYSIZE(testListArgsCount));
100 for (
size_t x = 0; x < ARRAYSIZE(testListArgs); x++)
108 const char* list = testListArgs[x];
110 ptr.pp = CommandLineParseCommaSeparatedValuesEx(testListAppName, list, &count);
111 BOOL valid = checkResult(x, ptr.pp, count);
120 int TestCmdLine(
int argc,
char* argv[])
129 char** command_line = NULL;
131 {
"v", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"destination server" },
132 {
"port", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"server port" },
133 {
"w", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"width" },
134 {
"h", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"height" },
135 {
"f", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"fullscreen" },
136 {
"bpp", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
137 "session bpp (color depth)" },
138 {
"admin", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1,
"console",
139 "admin (or console) session" },
140 {
"multimon", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"multi-monitor" },
141 {
"a", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1,
"addin",
"addin" },
142 {
"u", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"username" },
143 {
"p", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"password" },
144 {
"d", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"domain" },
145 {
"z", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
"compression" },
146 {
"audio", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"audio output mode" },
147 {
"mic", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"audio input (microphone)" },
148 {
"fonts", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
149 "smooth fonts (cleartype)" },
150 {
"aero", COMMAND_LINE_VALUE_BOOL, NULL, NULL, BoolValueFalse, -1, NULL,
151 "desktop composition" },
152 {
"window-drag", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
153 "full window drag" },
154 {
"menu-anims", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
156 {
"themes", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
"themes" },
157 {
"wallpaper", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
"wallpaper" },
158 {
"codec", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
"codec" },
159 {
"nego", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
160 "protocol security negotiation" },
161 {
"sec", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
162 "force specific protocol security" },
163 #if defined(WITH_FREERDP_DEPRECATED)
164 {
"sec-rdp", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
165 "rdp protocol security" },
166 {
"sec-tls", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
167 "tls protocol security" },
168 {
"sec-nla", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL,
169 "nla protocol security" },
170 {
"sec-ext", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL,
171 "nla extended protocol security" },
172 {
"cert-name", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL,
173 "certificate name" },
174 {
"cert-ignore", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
175 "ignore certificate" },
177 {
"valuelist", COMMAND_LINE_VALUE_REQUIRED,
"<val1>,<val2>", NULL, NULL, -1, NULL,
178 "List of comma separated values." },
179 {
"valuelist-empty", COMMAND_LINE_VALUE_REQUIRED,
"<val1>,<val2>", NULL, NULL, -1, NULL,
180 "List of comma separated values. Used to test correct behavior if an empty list was "
182 {
"version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1,
183 NULL,
"print version" },
184 {
"help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1,
"?",
186 { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
192 flags = COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_SIGIL_PLUS_MINUS;
193 testArgc = string_list_length(testArgv);
194 command_line = string_list_copy(testArgv);
198 printf(
"Argument duplication failed (not enough memory?)\n");
202 status = CommandLineParseArgumentsA(testArgc, command_line, args, flags, NULL, NULL, NULL);
206 printf(
"CommandLineParseArgumentsA failure: %d\n", status);
210 arg = CommandLineFindArgumentA(args,
"w");
212 if (strcmp(
"1024", arg->Value) != 0)
214 printf(
"CommandLineFindArgumentA: unexpected %s value %s\n", arg->Name, arg->Value);
218 arg = CommandLineFindArgumentA(args,
"h");
220 if (strcmp(
"768", arg->Value) != 0)
222 printf(
"CommandLineFindArgumentA: unexpected %s value %s\n", arg->Name, arg->Value);
226 arg = CommandLineFindArgumentA(args,
"f");
230 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
234 arg = CommandLineFindArgumentA(args,
"admin");
238 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
242 arg = CommandLineFindArgumentA(args,
"multimon");
246 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
250 arg = CommandLineFindArgumentA(args,
"v");
252 if (strcmp(
"localhost:3389", arg->Value) != 0)
254 printf(
"CommandLineFindArgumentA: unexpected %s value %s\n", arg->Name, arg->Value);
258 arg = CommandLineFindArgumentA(args,
"fonts");
262 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
266 arg = CommandLineFindArgumentA(args,
"wallpaper");
270 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
274 arg = CommandLineFindArgumentA(args,
"help");
278 printf(
"CommandLineFindArgumentA: unexpected %s value\n", arg->Name);
287 if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
290 printf(
"Argument: %s\n", arg->Name);
291 CommandLineSwitchStart(arg) CommandLineSwitchCase(arg,
"v")
294 CommandLineSwitchCase(arg,
"w")
296 width = strtol(arg->Value, NULL, 0);
301 CommandLineSwitchCase(arg,
"h")
303 height = strtol(arg->Value, NULL, 0);
308 CommandLineSwitchCase(arg,
"valuelist")
312 p = CommandLineParseCommaSeparatedValuesEx(arg->Name, arg->Value, &count);
315 if (!p || count != 3)
317 printf(
"CommandLineParseCommaSeparatedValuesEx: invalid p or count (%" PRIuz
323 CommandLineSwitchCase(arg,
"valuelist-empty")
327 p = CommandLineParseCommaSeparatedValuesEx(arg->Name, arg->Value, &count);
330 if (!p || count != 1)
332 printf(
"CommandLineParseCommaSeparatedValuesEx: invalid p or count (%" PRIuz
338 CommandLineSwitchDefault(arg)
341 CommandLineSwitchEnd(arg)
342 }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
344 if ((width != 1024) || (height != 768))
346 printf(
"Unexpected width and height: Actual: (%ldx%ld), Expected: (1024x768)\n", width,
353 string_list_free(command_line);
355 if (!TestCommandLineParseCommaSeparatedValuesEx())