b6a23adecc7f7f593a065efb2bd5507d32bf042c
[reactos.git] / rostests / apitests / crt / __getmainargs.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for __getmainargs and __wgetmainargs
5 * PROGRAMMER: Yaroslav Veremenko <yaroslav@veremenko.info>
6 */
7
8 #include <apitest.h>
9 #include <stdio.h>
10 #include <string.h>
11
12
13 const char **__p__acmdln(void);
14 void __getmainargs(int* argc, char*** argv, char*** env, int expand_wildcards, int* new_mode);
15 const wchar_t **__p__wcmdln(void);
16 void __wgetmainargs(int* argc, wchar_t*** wargv, wchar_t*** wenv, int expand_wildcards, int* new_mode);
17
18
19 #define winetest_ok_str(x, y) \
20 winetest_ok(strcmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", y, x)
21 #define winetest_ok_wstr(x, y) \
22 winetest_ok(wcscmp(x, y) == 0, "Wrong string. Expected '%s', got '%s'\n", wine_dbgstr_w(y), wine_dbgstr_w(x))
23 #define ok_argsA (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_argsA_imp
24 #define ok_argsW (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : ok_argsW_imp
25
26
27 void
28 ok_argsA_imp(const char* input_args, const char* arg1, const char* arg2, const char* arg3)
29 {
30 int argc = 0, mode = 0;
31 char** argv, **env;
32
33 /* Remove cached argv, setup our input as program argument. */
34 *__p___argv() = NULL;
35 *__p__acmdln() = input_args;
36
37 /* Process the commandline stored in _acmdln */
38 __getmainargs(&argc, &argv, &env, 0, &mode);
39
40 winetest_ok(argc == 4, "Wrong value for argc, expected: 4, got: %d\n", argc);
41 if(argc != 4)
42 return;
43
44 winetest_ok_str(argv[0], "test.exe");
45 winetest_ok_str(argv[1], arg1);
46 winetest_ok_str(argv[2], arg2);
47 winetest_ok_str(argv[3], arg3);
48 }
49
50 void
51 ok_argsW_imp(const wchar_t* input_args, const wchar_t* arg1, const wchar_t* arg2, const wchar_t* arg3)
52 {
53 int argc = 0, mode = 0;
54 wchar_t** argv, **env;
55
56 /* Remove cached wargv, setup our input as program argument. */
57 *__p___wargv() = NULL;
58 *__p__wcmdln() = input_args;
59
60 /* Process the commandline stored in _wcmdln */
61 __wgetmainargs(&argc, &argv, &env, 0, &mode);
62
63 winetest_ok(argc == 4, "Wrong value for argc, expected: 4, got: %d\n", argc);
64 if(argc != 4)
65 return;
66
67 winetest_ok_wstr(argv[0], L"test.exe");
68 winetest_ok_wstr(argv[1], arg1);
69 winetest_ok_wstr(argv[2], arg2);
70 winetest_ok_wstr(argv[3], arg3);
71 }
72
73 START_TEST(__getmainargs)
74 {
75 ok_argsA("test.exe \"a b c\" d e", "a b c", "d", "e");
76 ok_argsA("test.exe \"ab\\\"c\" \"\\\\\" d", "ab\"c", "\\", "d");
77 ok_argsA("test.exe a\\\\\\b d\"e f\"g h", "a\\\\\\b", "de fg", "h");
78 ok_argsA("test.exe a\\\\\\\"b c d", "a\\\"b", "c", "d");
79 ok_argsA("test.exe a\\\\\\\\\"b c\" d e", "a\\\\b c", "d", "e");
80 ok_argsA("test.exe a b \"\"", "a", "b", "");
81 ok_argsA("test.exe a \"\" b", "a", "", "b");
82 ok_argsA("test.exe a \"b\"\" c", "a", "b\"", "c");
83 ok_argsA("test.exe a \"b\\\"\" c", "a", "b\"", "c");
84 ok_argsA("test.exe a \" b\\ \"\" c", "a", " b\\ \"", "c");
85 ok_argsA("test.exe a \"b\\ \"\"\" c\" d", "a", "b\\ \" c", "d");
86 ok_argsA("test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", "a", "b\\ \" c", "\" d");
87 ok_argsA("test.exe a b c ", "a", "b", "c");
88
89 ok_argsW(L"test.exe \"a b c\" d e", L"a b c", L"d", L"e");
90 ok_argsW(L"test.exe \"ab\\\"c\" \"\\\\\" d", L"ab\"c", L"\\", L"d");
91 ok_argsW(L"test.exe a\\\\\\b d\"e f\"g h", L"a\\\\\\b", L"de fg", L"h");
92 ok_argsW(L"test.exe a\\\\\\\"b c d", L"a\\\"b", L"c", L"d");
93 ok_argsW(L"test.exe a\\\\\\\\\"b c\" d e", L"a\\\\b c", L"d", L"e");
94 ok_argsW(L"test.exe a b \"\"", L"a", L"b", L"");
95 ok_argsW(L"test.exe a \"\" b", L"a", L"", L"b");
96 ok_argsW(L"test.exe a \"b\"\" c", L"a", L"b\"", L"c");
97 ok_argsW(L"test.exe a \"b\\\"\" c", L"a", L"b\"", L"c");
98 ok_argsW(L"test.exe a \" b\\ \"\" c", L"a", L" b\\ \"", L"c");
99 ok_argsW(L"test.exe a \"b\\ \"\"\" c\" d", L"a", L"b\\ \" c", L"d");
100 ok_argsW(L"test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", L"a", L"b\\ \" c", L"\" d");
101 ok_argsW(L"test.exe a b c ", L"a", L"b", L"c");
102 }