ReactOS 0.4.15-dev-7842-g558ab78
__getmainargs.c
Go to the documentation of this file.
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
13const char **__p__acmdln(void);
14void __getmainargs(int* argc, char*** argv, char*** env, int expand_wildcards, int* new_mode);
15const wchar_t **__p__wcmdln(void);
16void __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
27void
28ok_argsA_imp(const char* input_args, const char* arg1, const char* arg2, const char* arg3)
29{
30 int argc = 0, mode = 0;
31 int expect_count = arg3 == NULL ? (arg2 == NULL ? 2 : 3) : 4;
32 char** argv, **env;
33
34 /* Remove cached argv, setup our input as program argument. */
35 *__p___argv() = NULL;
36 *__p__acmdln() = input_args;
37
38 /* Process the commandline stored in _acmdln */
39 __getmainargs(&argc, &argv, &env, 0, &mode);
40
41 winetest_ok(argc == expect_count, "Wrong value for argc, expected: %d, got: %d\n", expect_count, argc);
42 if(argc != expect_count)
43 return;
44
45 winetest_ok_str(argv[0], "test.exe");
47 if (expect_count > 2)
48 {
50 if (expect_count > 3)
52 }
53}
54
55void
56ok_argsW_imp(const wchar_t* input_args, const wchar_t* arg1, const wchar_t* arg2, const wchar_t* arg3)
57{
58 int argc = 0, mode = 0;
59 int expect_count = arg3 == NULL ? (arg2 == NULL ? 2 : 3) : 4;
60 wchar_t** argv, **env;
61
62 /* Remove cached wargv, setup our input as program argument. */
63 *__p___wargv() = NULL;
64 *__p__wcmdln() = input_args;
65
66 /* Process the commandline stored in _wcmdln */
67 __wgetmainargs(&argc, &argv, &env, 0, &mode);
68
69 winetest_ok(argc == expect_count, "Wrong value for argc, expected: %d, got: %d\n", expect_count, argc);
70 if(argc != expect_count)
71 return;
72
73 winetest_ok_wstr(argv[0], L"test.exe");
75 if (expect_count > 2)
76 {
78 if (expect_count > 3)
80 }
81}
82
84{
85 ok_argsA("test.exe \"a b c\" d e", "a b c", "d", "e");
86 ok_argsA("test.exe \"ab\\\"c\" \"\\\\\" d", "ab\"c", "\\", "d");
87 ok_argsA("test.exe a\\\\\\b d\"e f\"g h", "a\\\\\\b", "de fg", "h");
88 ok_argsA("test.exe a\\\\\\\"b c d", "a\\\"b", "c", "d");
89 ok_argsA("test.exe a\\\\\\\\\"b c\" d e", "a\\\\b c", "d", "e");
90 ok_argsA("test.exe a b \"\"", "a", "b", "");
91 ok_argsA("test.exe a \"\" b", "a", "", "b");
92 ok_argsA("test.exe a \"b\"\" c", "a", "b\"", "c");
93 ok_argsA("test.exe a \"b\\\"\" c", "a", "b\"", "c");
94 ok_argsA("test.exe a \" b\\ \"\" c", "a", " b\\ \"", "c");
95 ok_argsA("test.exe a \"b\\ \"\"\" c\" d", "a", "b\\ \" c", "d");
96 ok_argsA("test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", "a", "b\\ \" c", "\" d");
97 ok_argsA("test.exe a b c ", "a", "b", "c");
98 ok_argsA("test.exe \"a b c\"", "a b c", NULL, NULL);
99
100 ok_argsW(L"test.exe \"a b c\" d e", L"a b c", L"d", L"e");
101 ok_argsW(L"test.exe \"ab\\\"c\" \"\\\\\" d", L"ab\"c", L"\\", L"d");
102 ok_argsW(L"test.exe a\\\\\\b d\"e f\"g h", L"a\\\\\\b", L"de fg", L"h");
103 ok_argsW(L"test.exe a\\\\\\\"b c d", L"a\\\"b", L"c", L"d");
104 ok_argsW(L"test.exe a\\\\\\\\\"b c\" d e", L"a\\\\b c", L"d", L"e");
105 ok_argsW(L"test.exe a b \"\"", L"a", L"b", L"");
106 ok_argsW(L"test.exe a \"\" b", L"a", L"", L"b");
107 ok_argsW(L"test.exe a \"b\"\" c", L"a", L"b\"", L"c");
108 ok_argsW(L"test.exe a \"b\\\"\" c", L"a", L"b\"", L"c");
109 ok_argsW(L"test.exe a \" b\\ \"\" c", L"a", L" b\\ \"", L"c");
110 ok_argsW(L"test.exe a \"b\\ \"\"\" c\" d", L"a", L"b\\ \" c", L"d");
111 ok_argsW(L"test.exe a \"b\\ \"\"\" \"c \"\"\"\" d", L"a", L"b\\ \" c", L"\" d");
112 ok_argsW(L"test.exe a b c ", L"a", L"b", L"c");
113 ok_argsW(L"test.exe \"a b c\"", L"a b c", NULL, NULL);
114}
static int argc
Definition: ServiceArgs.c:12
#define ok_argsA
Definition: __getmainargs.c:23
#define winetest_ok_wstr(x, y)
Definition: __getmainargs.c:21
void ok_argsW_imp(const wchar_t *input_args, const wchar_t *arg1, const wchar_t *arg2, const wchar_t *arg3)
Definition: __getmainargs.c:56
void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenv, int expand_wildcards, int *new_mode)
Definition: getargs.c:328
const wchar_t ** __p__wcmdln(void)
Definition: environ.c:376
#define winetest_ok_str(x, y)
Definition: __getmainargs.c:19
void __getmainargs(int *argc, char ***argv, char ***env, int expand_wildcards, int *new_mode)
Definition: getargs.c:182
void ok_argsA_imp(const char *input_args, const char *arg1, const char *arg2, const char *arg3)
Definition: __getmainargs.c:28
const char ** __p__acmdln(void)
Definition: environ.c:368
#define ok_argsW
Definition: __getmainargs.c:24
#define START_TEST(x)
Definition: atltest.h:75
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
#define NULL
Definition: types.h:112
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg3
Definition: glext.h:9515
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLenum mode
Definition: glext.h:6217
_CRTIMP char ***__cdecl __p___argv()
Definition: getargs.c:483
_CRTIMP wchar_t ***__cdecl __p___wargv()
Definition: getargs.c:491
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)