4#include <winpr/thread.h>
6static const char* test_args_line_1 =
"app.exe abc d e";
8static const char* test_args_list_1[] = {
"app.exe",
"abc",
"d",
"e" };
10static const char* test_args_line_2 =
"app.exe abc \t def";
12static const char* test_args_list_2[] = {
"app.exe",
"abc",
"def" };
14static const char* test_args_line_3 =
"app.exe \"abc\" d e";
16static const char* test_args_list_3[] = {
"app.exe",
"abc",
"d",
"e" };
18static const char* test_args_line_4 =
"app.exe a\\\\b d\"e f\"g h";
20static const char* test_args_list_4[] = {
"app.exe",
"a\\\\b",
"de fg",
"h" };
22static const char* test_args_line_5 =
"app.exe a\\\\\\\"b c d";
24static const char* test_args_list_5[] = {
"app.exe",
"a\\\"b",
"c",
"d" };
26static const char* test_args_line_6 =
"app.exe a\\\\\\\\\"b c\" d e";
28static const char* test_args_list_6[] = {
"app.exe",
"a\\\\b c",
"d",
"e" };
30static const char* test_args_line_7 =
"app.exe a\\\\\\\\\"b c\" d e f\\\\\\\\\"g h\" i j";
32static const char* test_args_list_7[] = {
"app.exe",
"a\\\\b c",
"d",
"e",
"f\\\\g h",
"i",
"j" };
34static const char* test_args_line_8 =
"app.exe arg1 \"arg2\"";
36static const char* test_args_list_8[] = {
"app.exe",
"arg1",
"arg2" };
38static BOOL test_command_line_parsing_case(
const char* line,
const char** list,
size_t expect)
43 printf(
"Parsing: %s\n", line);
45 LPSTR* pArgs = CommandLineToArgvA(line, &numArgs);
48 (void)fprintf(stderr,
"expected %" PRIuz
" arguments, got %d return\n", expect, numArgs);
51 if (numArgs != expect)
53 (void)fprintf(stderr,
"expected %" PRIuz
" arguments, got %d from '%s'\n", expect, numArgs,
58 if ((numArgs > 0) && !pArgs)
60 (void)fprintf(stderr,
"expected %d arguments, got NULL return\n", numArgs);
64 printf(
"pNumArgs: %d\n", numArgs);
66 for (
int i = 0; i < numArgs; i++)
68 printf(
"argv[%d] = %s\n", i, pArgs[i]);
69 if (strcmp(pArgs[i], list[i]) != 0)
71 (void)fprintf(stderr,
"failed at argument %d: got '%s' but expected '%s'\n", i,
84int TestThreadCommandLineToArgv(
int argc,
char* argv[])
90 if (!test_command_line_parsing_case(test_args_line_1, test_args_list_1,
91 ARRAYSIZE(test_args_list_1)))
93 if (!test_command_line_parsing_case(test_args_line_2, test_args_list_2,
94 ARRAYSIZE(test_args_list_2)))
96 if (!test_command_line_parsing_case(test_args_line_3, test_args_list_3,
97 ARRAYSIZE(test_args_list_3)))
99 if (!test_command_line_parsing_case(test_args_line_4, test_args_list_4,
100 ARRAYSIZE(test_args_list_4)))
102 if (!test_command_line_parsing_case(test_args_line_5, test_args_list_5,
103 ARRAYSIZE(test_args_list_5)))
105 if (!test_command_line_parsing_case(test_args_line_6, test_args_list_6,
106 ARRAYSIZE(test_args_list_6)))
108 if (!test_command_line_parsing_case(test_args_line_7, test_args_list_7,
109 ARRAYSIZE(test_args_list_7)))
111 if (!test_command_line_parsing_case(test_args_line_8, test_args_list_8,
112 ARRAYSIZE(test_args_list_8)))