2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/thread.h>
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_1 = "app.exe abc d e";
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
const char* test_args_list_1[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 01:16:49 +04:00
|
|
|
"abc",
|
|
|
|
"d",
|
|
|
|
"e",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_2 = "app.exe abc \t def";
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
const char* test_args_list_2[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 01:16:49 +04:00
|
|
|
"abc",
|
|
|
|
"def",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_3 = "app.exe \"abc\" d e";
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
const char* test_args_list_3[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 01:16:49 +04:00
|
|
|
"abc",
|
|
|
|
"d",
|
|
|
|
"e",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_4 = "app.exe a\\\\b d\"e f\"g h";
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
const char* test_args_list_4[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 01:16:49 +04:00
|
|
|
"a\\\\b",
|
|
|
|
"de fg",
|
|
|
|
"h",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_5 = "app.exe a\\\\\\\"b c d";
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
const char* test_args_list_5[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 01:16:49 +04:00
|
|
|
"a\\\"b",
|
|
|
|
"c",
|
|
|
|
"d",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_6 = "app.exe a\\\\\\\\\"b c\" d e";
|
2013-09-22 03:49:00 +04:00
|
|
|
|
|
|
|
const char* test_args_list_6[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 03:49:00 +04:00
|
|
|
"a\\\\b c",
|
|
|
|
"d",
|
|
|
|
"e",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
const char* test_args_line_7 = "app.exe a\\\\\\\\\"b c\" d e f\\\\\\\\\"g h\" i j";
|
2013-09-22 04:05:14 +04:00
|
|
|
|
|
|
|
const char* test_args_list_7[] =
|
|
|
|
{
|
2013-09-23 01:23:00 +04:00
|
|
|
"app.exe",
|
2013-09-22 04:05:14 +04:00
|
|
|
"a\\\\b c",
|
|
|
|
"d",
|
|
|
|
"e",
|
|
|
|
"f\\\\g h",
|
|
|
|
"i",
|
|
|
|
"j",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-09-22 01:16:49 +04:00
|
|
|
static int test_command_line_parsing_case(const char* line, const char** list)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
LPSTR* pArgs;
|
2013-09-23 01:23:00 +04:00
|
|
|
int numArgs;
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
pArgs = NULL;
|
2013-09-23 01:23:00 +04:00
|
|
|
numArgs = 0;
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
printf("Parsing: %s\n", line);
|
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
pArgs = CommandLineToArgvA(line, &numArgs);
|
2013-09-22 01:16:49 +04:00
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
printf("pNumArgs: %d\n", numArgs);
|
2013-09-22 01:16:49 +04:00
|
|
|
|
2013-09-23 01:23:00 +04:00
|
|
|
for (i = 0; i < numArgs; i++)
|
2013-09-22 01:16:49 +04:00
|
|
|
{
|
|
|
|
printf("argv[%d] = %s\n", i, pArgs[i]);
|
|
|
|
}
|
|
|
|
|
2013-09-22 04:05:14 +04:00
|
|
|
HeapFree(GetProcessHeap(), 0, pArgs);
|
|
|
|
|
2013-09-22 01:16:49 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestThreadCommandLineToArgv(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
test_command_line_parsing_case(test_args_line_1, test_args_list_1);
|
|
|
|
test_command_line_parsing_case(test_args_line_2, test_args_list_2);
|
|
|
|
test_command_line_parsing_case(test_args_line_3, test_args_list_3);
|
|
|
|
test_command_line_parsing_case(test_args_line_4, test_args_list_4);
|
2013-09-22 03:49:00 +04:00
|
|
|
test_command_line_parsing_case(test_args_line_5, test_args_list_5);
|
|
|
|
test_command_line_parsing_case(test_args_line_6, test_args_list_6);
|
2013-09-22 04:05:14 +04:00
|
|
|
test_command_line_parsing_case(test_args_line_7, test_args_list_7);
|
2013-09-22 01:16:49 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|