ReactOS 0.4.16-dev-981-g80eb313
data.c
Go to the documentation of this file.
1/*
2 * Tests msvcrt/data.c
3 *
4 * Copyright 2006 Andrew Ziem
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "wine/test.h"
22#include <stdarg.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <fcntl.h>
26#include <sys/stat.h>
27#include <io.h>
28#include <windef.h>
29#include <winbase.h>
30#include <winnls.h>
31#include <process.h>
32#include <errno.h>
33#include <direct.h>
34
35#ifdef __REACTOS__
36_CRTIMP void __cdecl __getmainargs(int *, char ***, char ***, int, int *);
37_CRTIMP void __cdecl __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
38#endif
39
40static int* (__cdecl *p___p___argc)(void);
41static char*** (__cdecl *p___p___argv)(void);
42
44static void (__cdecl *p_initterm)(_INITTERMFUN *start, _INITTERMFUN *end);
45
46static int (__cdecl *p_get_pgmptr)(char **p);
47
48static int callbacked;
49
50static void __cdecl initcallback(void)
51{
52 callbacked++;
53}
54
55#define initterm_test(start, end, expected) \
56 callbacked = 0; \
57 p_initterm(start, end); \
58 ok(expected == callbacked,"_initterm: callbacks count mismatch: got %i, expected %i\n", callbacked, expected);
59
60static void test_initterm(void)
61{
62 int i;
63 static _INITTERMFUN callbacks[4];
64
65 if (!p_initterm)
66 return;
67
68 for (i = 0; i < 4; i++)
69 {
71 }
72
76
77 callbacks[1] = NULL;
79}
80
81static void test_initvar( HMODULE hmsvcrt )
82{
84 int *pp_winver = (int*)GetProcAddress(hmsvcrt, "_winver");
85 int *pp_winmajor = (int*)GetProcAddress(hmsvcrt, "_winmajor");
86 int *pp_winminor = (int*)GetProcAddress(hmsvcrt, "_winminor");
87 int *pp_osver = (int*)GetProcAddress(hmsvcrt, "_osver");
88 int *pp_osplatform = (int*)GetProcAddress(hmsvcrt, "_osplatform");
89 unsigned int winver, winmajor, winminor, osver, osplatform;
90
91 if( !( pp_winmajor && pp_winminor && pp_winver)) {
92 win_skip("_winver variables are not available\n");
93 return;
94 }
95 winver = *pp_winver;
96 winminor = *pp_winminor;
97 winmajor = *pp_winmajor;
99 ok( winminor == osvi.dwMinorVersion, "Wrong value for _winminor %02x expected %02lx\n",
100 winminor, osvi.dwMinorVersion);
101 ok( winmajor == osvi.dwMajorVersion, "Wrong value for _winmajor %02x expected %02lx\n",
102 winmajor, osvi.dwMajorVersion);
103 ok( winver == ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion),
104 "Wrong value for _winver %02x expected %02lx\n",
105 winver, ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion));
106 if( !pp_osver || !pp_osplatform ) {
107 win_skip("_osver variables are not available\n");
108 return;
109 }
110 osver = *pp_osver;
111 osplatform = *pp_osplatform;
112 ok( osver == (osvi.dwBuildNumber & 0xffff) ||
114 ((osvi.dwBuildNumber >> 16) & 0xff) == osvi.dwMinorVersion), /* 95/98/ME */
115 "Wrong value for _osver %04x expected %04lx\n",
116 osver, osvi.dwBuildNumber);
117 ok(osplatform == osvi.dwPlatformId,
118 "Wrong value for _osplatform %x expected %lx\n",
119 osplatform, osvi.dwPlatformId);
120}
121
122static void test_get_pgmptr(void)
123{
124 char *pgm = NULL;
125 int res;
126
127 if (!p_get_pgmptr)
128 return;
129
130 res = p_get_pgmptr(&pgm);
131
132 ok( res == 0, "Wrong _get_pgmptr return value %d expected 0\n", res);
133 ok( pgm != NULL, "_get_pgmptr returned a NULL pointer\n" );
134}
135
136static void test___getmainargs(void)
137{
138 int argc, new_argc, mode;
139 char **argv, **new_argv, **envp;
140 char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
141 FILE *f;
142
143 ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
144
145 mode = 0;
146 __getmainargs(&argc, &argv, &envp, 0, &mode);
147 ok(argc == 4, "argc = %d\n", argc);
148 ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
149 sprintf(filepath, "%s*\\*", tmppath);
150 ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
151 sprintf(filepath, "%swine_test/*", tmppath);
152 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
153 ok(!argv[4], "argv[4] != NULL\n");
154
156 new_argc = *p___p___argc();
157 new_argv = *p___p___argv();
158 ok(new_argc == 4, "*__p___argc() = %d\n", new_argc);
159 ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
160 }
161 else skip("__p___argc or __p___argv is not available\n");
162
163 mode = 0;
164 __getmainargs(&argc, &argv, &envp, 1, &mode);
165 ok(argc == 5, "argc = %d\n", argc);
166 ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
167 sprintf(filepath, "%s*\\*", tmppath);
168 ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
169 sprintf(filepath, "%swine_test/a", tmppath);
170 if(argv[3][strlen(argv[3])-1] == 'a') {
171 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
172 sprintf(filepath, "%swine_test/test", tmppath);
173 ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
174 }else {
175 ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
176 sprintf(filepath, "%swine_test/test", tmppath);
177 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
178 }
179 ok(!argv[5], "argv[5] != NULL\n");
180
182 new_argc = *p___p___argc();
183 new_argv = *p___p___argv();
184 ok(new_argc == argc, "*__p___argc() = %d, expected %d\n", new_argc, argc);
185 ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
186 }
187
188 sprintf(filepath, "%swine_test/b", tmppath);
189 f = fopen(filepath, "w");
190 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
191 fclose(f);
192 mode = 0;
193 __getmainargs(&new_argc, &new_argv, &envp, 1, &mode);
194 ok(new_argc == argc+1, "new_argc = %d, expected %d\n", new_argc, argc+1);
195 _unlink(filepath);
196}
197
199{
200 char cmdline[3*MAX_PATH];
201 char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
204 FILE *f;
205 int ret;
206
207 ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
208 sprintf(cmdline, "%s data %s*\\* %swine_test/*", name, tmppath, tmppath);
209
210 sprintf(filepath, "%swine_test", tmppath);
211 ret = _mkdir(filepath);
212 ok(!ret, "_mkdir failed: %d\n", errno);
213 sprintf(filepath, "%swine_test\\a", tmppath);
214 f = fopen(filepath, "w");
215 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
216 fclose(f);
217 sprintf(filepath, "%swine_test\\test", tmppath);
218 f = fopen(filepath, "w");
219 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
220 fclose(f);
221
222 memset(&startup, 0, sizeof(startup));
223 startup.cb = sizeof(startup);
225 wait_child_process(proc.hProcess);
226
227 _unlink(filepath);
228 sprintf(filepath, "%swine_test\\a", tmppath);
229 _unlink(filepath);
230 sprintf(filepath, "%swine_test", tmppath);
231 _rmdir(filepath);
232}
233
235{
236 HMODULE hmsvcrt;
237 int arg_c;
238 char** arg_v;
239
240 hmsvcrt = GetModuleHandleA("msvcrt.dll");
241 if (!hmsvcrt)
242 hmsvcrt = GetModuleHandleA("msvcrtd.dll");
243 if (hmsvcrt)
244 {
245 p_initterm=(void*)GetProcAddress(hmsvcrt, "_initterm");
246 p_get_pgmptr=(void*)GetProcAddress(hmsvcrt, "_get_pgmptr");
247 p___p___argc=(void*)GetProcAddress(hmsvcrt, "__p___argc");
248 p___p___argv=(void*)GetProcAddress(hmsvcrt, "__p___argv");
249 }
250
251 arg_c = winetest_get_mainargs(&arg_v);
252 if(arg_c >= 3) {
254 return;
255 }
256
258 test_initvar(hmsvcrt);
261}
static int argc
Definition: ServiceArgs.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define __cdecl
Definition: accygwin.h:79
static void startup(void)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
_Check_return_ _CRTIMP int __cdecl _rmdir(_In_z_ const char *_Path)
_Check_return_ _CRTIMP int __cdecl _mkdir(_In_z_ const char *_Path)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
void __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: getargs.c:182
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4747
BOOL WINAPI GetVersionExA(IN LPOSVERSIONINFOA lpVersionInformation)
Definition: version.c:69
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint start
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint res
Definition: glext.h:9613
GLfloat f
Definition: glext.h:7540
GLenum mode
Definition: glext.h:6217
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define f
Definition: ke_i.h:83
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static void test___getmainargs_parent(char *name)
Definition: data.c:198
static int callbacked
Definition: data.c:48
static char ***__cdecl * p___p___argv(void)
static void test_initvar(HMODULE hmsvcrt)
Definition: data.c:81
static void __cdecl initcallback(void)
Definition: data.c:50
static int *__cdecl * p___p___argc(void)
static void test_get_pgmptr(void)
Definition: data.c:122
void(__cdecl * _INITTERMFUN)(void)
Definition: data.c:43
#define initterm_test(start, end, expected)
Definition: data.c:55
static void test_initterm(void)
Definition: data.c:60
static _INITTERMFUN * end
Definition: data.c:44
static void test___getmainargs(void)
Definition: data.c:136
#define argv
Definition: mplay32.c:18
void CDECL __wgetmainargs(int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int *new_mode)
static HANDLE proc()
Definition: pdb.c:34
#define errno
Definition: errno.h:18
_Check_return_ _CRTIMP int __cdecl _unlink(_In_z_ const char *_Filename)
#define win_skip
Definition: test.h:164
int winetest_get_mainargs(char ***pargv)
#define wait_child_process
Definition: test.h:166
#define memset(x, y, z)
Definition: compat.h:39
TCHAR * cmdline
Definition: stretchblt.cpp:32
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwBuildNumber
Definition: rtltypes.h:240
ULONG dwMinorVersion
Definition: rtltypes.h:239
Definition: name.c:39
#define _CRTIMP
Definition: vcruntime.h:54
OSVERSIONINFO osvi
Definition: ver.c:28
int ret
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:184
#define CREATE_DEFAULT_ERROR_MODE
Definition: winbase.h:214
struct _OSVERSIONINFOA OSVERSIONINFOA
static int callbacks
Definition: xmllint.c:838