summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c
blob: 33d0c94f4836fef28666b228362504c04d7995bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/thread.h>

static const char* test_args_line_1 = "app.exe abc d e";

static const char* test_args_list_1[] = { "app.exe", "abc", "d", "e", NULL };

static const char* test_args_line_2 = "app.exe abc  \t   def";

static const char* test_args_list_2[] = { "app.exe", "abc", "def", NULL };

static const char* test_args_line_3 = "app.exe \"abc\" d e";

static const char* test_args_list_3[] = { "app.exe", "abc", "d", "e", NULL };

static const char* test_args_line_4 = "app.exe a\\\\b d\"e f\"g h";

static const char* test_args_list_4[] = { "app.exe", "a\\\\b", "de fg", "h", NULL };

static const char* test_args_line_5 = "app.exe a\\\\\\\"b c d";

static const char* test_args_list_5[] = { "app.exe", "a\\\"b", "c", "d", NULL };

static const char* test_args_line_6 = "app.exe a\\\\\\\\\"b c\" d e";

static const char* test_args_list_6[] = { "app.exe", "a\\\\b c", "d", "e", NULL };

static const char* test_args_line_7 = "app.exe a\\\\\\\\\"b c\" d e f\\\\\\\\\"g h\" i j";

static const char* test_args_list_7[] = { "app.exe",  "a\\\\b c", "d", "e",
	                                      "f\\\\g h", "i",        "j", NULL };

static int test_command_line_parsing_case(const char* line, const char** list)
{
	LPSTR* pArgs = NULL;
	int numArgs = 0;

	pArgs = NULL;
	numArgs = 0;

	printf("Parsing: %s\n", line);

	pArgs = CommandLineToArgvA(line, &numArgs);

	printf("pNumArgs: %d\n", numArgs);

	for (int i = 0; i < numArgs; i++)
	{
		printf("argv[%d] = %s\n", i, pArgs[i]);
	}

	free(pArgs);

	return 0;
}

int TestThreadCommandLineToArgv(int argc, char* argv[])
{

	WINPR_UNUSED(argc);
	WINPR_UNUSED(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);
	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);
	test_command_line_parsing_case(test_args_line_7, test_args_list_7);

	return 0;
}