gdi32: Use NtGdiExcludeClipRect for ExcludeClipRect implementation.
[wine.git] / dlls / msvcrt / tests / data.c
blob52742ba499456feec0a26f48748e7572e9079e68
1 /*
2 * Tests msvcrt/data.c
4 * Copyright 2006 Andrew Ziem
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.
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.
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
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>
35 static int* (__cdecl *p___p___argc)(void);
36 static char*** (__cdecl *p___p___argv)(void);
38 typedef void (__cdecl *_INITTERMFUN)(void);
39 static void (__cdecl *p_initterm)(_INITTERMFUN *start, _INITTERMFUN *end);
41 static int (__cdecl *p_get_pgmptr)(char **p);
43 static int callbacked;
45 static void __cdecl initcallback(void)
47 callbacked++;
50 #define initterm_test(start, end, expected) \
51 callbacked = 0; \
52 p_initterm(start, end); \
53 ok(expected == callbacked,"_initterm: callbacks count mismatch: got %i, expected %i\n", callbacked, expected);
55 static void test_initterm(void)
57 int i;
58 static _INITTERMFUN callbacks[4];
60 if (!p_initterm)
61 return;
63 for (i = 0; i < 4; i++)
65 callbacks[i] = initcallback;
68 initterm_test(&callbacks[0], &callbacks[1], 1);
69 initterm_test(&callbacks[0], &callbacks[2], 2);
70 initterm_test(&callbacks[0], &callbacks[3], 3);
72 callbacks[1] = NULL;
73 initterm_test(&callbacks[0], &callbacks[3], 2);
76 static void test_initvar( HMODULE hmsvcrt )
78 OSVERSIONINFOA osvi = { sizeof(OSVERSIONINFOA) };
79 int *pp_winver = (int*)GetProcAddress(hmsvcrt, "_winver");
80 int *pp_winmajor = (int*)GetProcAddress(hmsvcrt, "_winmajor");
81 int *pp_winminor = (int*)GetProcAddress(hmsvcrt, "_winminor");
82 int *pp_osver = (int*)GetProcAddress(hmsvcrt, "_osver");
83 int *pp_osplatform = (int*)GetProcAddress(hmsvcrt, "_osplatform");
84 unsigned int winver, winmajor, winminor, osver, osplatform;
86 if( !( pp_winmajor && pp_winminor && pp_winver)) {
87 win_skip("_winver variables are not available\n");
88 return;
90 winver = *pp_winver;
91 winminor = *pp_winminor;
92 winmajor = *pp_winmajor;
93 GetVersionExA( &osvi);
94 ok( winminor == osvi.dwMinorVersion, "Wrong value for _winminor %02x expected %02x\n",
95 winminor, osvi.dwMinorVersion);
96 ok( winmajor == osvi.dwMajorVersion, "Wrong value for _winmajor %02x expected %02x\n",
97 winmajor, osvi.dwMajorVersion);
98 ok( winver == ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion),
99 "Wrong value for _winver %02x expected %02x\n",
100 winver, ((osvi.dwMajorVersion << 8) | osvi.dwMinorVersion));
101 if( !pp_osver || !pp_osplatform ) {
102 win_skip("_osver variables are not available\n");
103 return;
105 osver = *pp_osver;
106 osplatform = *pp_osplatform;
107 ok( osver == (osvi.dwBuildNumber & 0xffff) ||
108 ((osvi.dwBuildNumber >> 24) == osvi.dwMajorVersion &&
109 ((osvi.dwBuildNumber >> 16) & 0xff) == osvi.dwMinorVersion), /* 95/98/ME */
110 "Wrong value for _osver %04x expected %04x\n",
111 osver, osvi.dwBuildNumber);
112 ok(osplatform == osvi.dwPlatformId,
113 "Wrong value for _osplatform %x expected %x\n",
114 osplatform, osvi.dwPlatformId);
117 static void test_get_pgmptr(void)
119 char *pgm = NULL;
120 int res;
122 if (!p_get_pgmptr)
123 return;
125 res = p_get_pgmptr(&pgm);
127 ok( res == 0, "Wrong _get_pgmptr return value %d expected 0\n", res);
128 ok( pgm != NULL, "_get_pgmptr returned a NULL pointer\n" );
131 static void test___getmainargs(void)
133 int argc, new_argc, mode;
134 char **argv, **new_argv, **envp;
135 char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
136 FILE *f;
138 ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
140 mode = 0;
141 __getmainargs(&argc, &argv, &envp, 0, &mode);
142 ok(argc == 4, "argc = %d\n", argc);
143 ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
144 sprintf(filepath, "%s*\\*", tmppath);
145 ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
146 sprintf(filepath, "%swine_test/*", tmppath);
147 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
148 ok(!argv[4], "argv[4] != NULL\n");
150 if(p___p___argc && p___p___argv) {
151 new_argc = *p___p___argc();
152 new_argv = *p___p___argv();
153 ok(new_argc == 4, "*__p___argc() = %d\n", new_argc);
154 ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
156 else skip("__p___argc or __p___argv is not available\n");
158 mode = 0;
159 __getmainargs(&argc, &argv, &envp, 1, &mode);
160 ok(argc == 5, "argc = %d\n", argc);
161 ok(!strcmp(argv[1], "data"), "argv[1] = %s\n", argv[1]);
162 sprintf(filepath, "%s*\\*", tmppath);
163 ok(!strcmp(argv[2], filepath), "argv[2] = %s\n", argv[2]);
164 sprintf(filepath, "%swine_test/a", tmppath);
165 if(argv[3][strlen(argv[3])-1] == 'a') {
166 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
167 sprintf(filepath, "%swine_test/test", tmppath);
168 ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
169 }else {
170 ok(!strcmp(argv[4], filepath), "argv[4] = %s\n", argv[4]);
171 sprintf(filepath, "%swine_test/test", tmppath);
172 ok(!strcmp(argv[3], filepath), "argv[3] = %s\n", argv[3]);
174 ok(!argv[5], "argv[5] != NULL\n");
176 if(p___p___argc && p___p___argv) {
177 new_argc = *p___p___argc();
178 new_argv = *p___p___argv();
179 ok(new_argc == argc, "*__p___argc() = %d, expected %d\n", new_argc, argc);
180 ok(new_argv == argv, "*__p___argv() = %p, expected %p\n", new_argv, argv);
183 sprintf(filepath, "%swine_test/b", tmppath);
184 f = fopen(filepath, "w");
185 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
186 fclose(f);
187 mode = 0;
188 __getmainargs(&new_argc, &new_argv, &envp, 1, &mode);
189 ok(new_argc == argc+1, "new_argc = %d, expected %d\n", new_argc, argc+1);
190 _unlink(filepath);
193 static void test___getmainargs_parent(char *name)
195 char cmdline[3*MAX_PATH];
196 char tmppath[MAX_PATH], filepath[MAX_PATH + 14];
197 STARTUPINFOA startup;
198 PROCESS_INFORMATION proc;
199 FILE *f;
200 int ret;
202 ok(GetTempPathA(MAX_PATH, tmppath) != 0, "GetTempPath failed\n");
203 sprintf(cmdline, "%s data %s*\\* %swine_test/*", name, tmppath, tmppath);
205 sprintf(filepath, "%swine_test", tmppath);
206 ret = _mkdir(filepath);
207 ok(!ret, "_mkdir failed: %d\n", errno);
208 sprintf(filepath, "%swine_test\\a", tmppath);
209 f = fopen(filepath, "w");
210 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
211 fclose(f);
212 sprintf(filepath, "%swine_test\\test", tmppath);
213 f = fopen(filepath, "w");
214 ok(f != NULL, "fopen(%s) failed: %d\n", filepath, errno);
215 fclose(f);
217 memset(&startup, 0, sizeof(startup));
218 startup.cb = sizeof(startup);
219 CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &proc);
220 wait_child_process(proc.hProcess);
222 _unlink(filepath);
223 sprintf(filepath, "%swine_test\\a", tmppath);
224 _unlink(filepath);
225 sprintf(filepath, "%swine_test", tmppath);
226 _rmdir(filepath);
229 START_TEST(data)
231 HMODULE hmsvcrt;
232 int arg_c;
233 char** arg_v;
235 hmsvcrt = GetModuleHandleA("msvcrt.dll");
236 if (!hmsvcrt)
237 hmsvcrt = GetModuleHandleA("msvcrtd.dll");
238 if (hmsvcrt)
240 p_initterm=(void*)GetProcAddress(hmsvcrt, "_initterm");
241 p_get_pgmptr=(void*)GetProcAddress(hmsvcrt, "_get_pgmptr");
242 p___p___argc=(void*)GetProcAddress(hmsvcrt, "__p___argc");
243 p___p___argv=(void*)GetProcAddress(hmsvcrt, "__p___argv");
246 arg_c = winetest_get_mainargs(&arg_v);
247 if(arg_c >= 3) {
248 test___getmainargs();
249 return;
252 test_initterm();
253 test_initvar(hmsvcrt);
254 test_get_pgmptr();
255 test___getmainargs_parent(arg_v[0]);