4 #include <winpr/thread.h>
6 static const char* test_args_line_1 =
"app.exe abc d e";
8 static const char* test_args_list_1[] = {
"app.exe",
"abc",
"d",
"e" };
10 static const char* test_args_line_2 =
"app.exe abc \t def";
12 static const char* test_args_list_2[] = {
"app.exe",
"abc",
"def" };
14 static const char* test_args_line_3 =
"app.exe \"abc\" d e";
16 static const char* test_args_list_3[] = {
"app.exe",
"abc",
"d",
"e" };
18 static const char* test_args_line_4 =
"app.exe a\\\\b d\"e f\"g h";
20 static const char* test_args_list_4[] = {
"app.exe",
"a\\\\b",
"de fg",
"h" };
22 static const char* test_args_line_5 =
"app.exe a\\\\\\\"b c d";
24 static const char* test_args_list_5[] = {
"app.exe",
"a\\\"b",
"c",
"d" };
26 static const char* test_args_line_6 =
"app.exe a\\\\\\\\\"b c\" d e";
28 static const char* test_args_list_6[] = {
"app.exe",
"a\\\\b c",
"d",
"e" };
30 static const char* test_args_line_7 =
"app.exe a\\\\\\\\\"b c\" d e f\\\\\\\\\"g h\" i j";
32 static const char* test_args_list_7[] = {
"app.exe",
"a\\\\b c",
"d",
"e",
"f\\\\g h",
"i",
"j" };
34 static BOOL test_command_line_parsing_case(
const char* line,
const char** list,
size_t expect)
39 printf(
"Parsing: %s\n", line);
41 LPSTR* pArgs = CommandLineToArgvA(line, &numArgs);
44 (void)fprintf(stderr,
"expected %" PRIuz
" arguments, got %d return\n", expect, numArgs);
47 if (numArgs != expect)
49 (void)fprintf(stderr,
"expected %" PRIuz
" arguments, got %d from '%s'\n", expect, numArgs,
54 if ((numArgs > 0) && !pArgs)
56 (void)fprintf(stderr,
"expected %d arguments, got NULL return\n", numArgs);
60 printf(
"pNumArgs: %d\n", numArgs);
62 for (
int i = 0; i < numArgs; i++)
64 printf(
"argv[%d] = %s\n", i, pArgs[i]);
65 if (strcmp(pArgs[i], list[i]) != 0)
67 (void)fprintf(stderr,
"failed at argument %d: got '%s' but expected '%s'\n", i,
80 int TestThreadCommandLineToArgv(
int argc,
char* argv[])
86 if (!test_command_line_parsing_case(test_args_line_1, test_args_list_1,
87 ARRAYSIZE(test_args_list_1)))
89 if (!test_command_line_parsing_case(test_args_line_2, test_args_list_2,
90 ARRAYSIZE(test_args_list_2)))
92 if (!test_command_line_parsing_case(test_args_line_3, test_args_list_3,
93 ARRAYSIZE(test_args_list_3)))
95 if (!test_command_line_parsing_case(test_args_line_4, test_args_list_4,
96 ARRAYSIZE(test_args_list_4)))
98 if (!test_command_line_parsing_case(test_args_line_5, test_args_list_5,
99 ARRAYSIZE(test_args_list_5)))
101 if (!test_command_line_parsing_case(test_args_line_6, test_args_list_6,
102 ARRAYSIZE(test_args_list_6)))
104 if (!test_command_line_parsing_case(test_args_line_7, test_args_list_7,
105 ARRAYSIZE(test_args_list_7)))