wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / msvcr90 / tests / msvcr90.c
blob9f6e47b6ec817809f455599586a5f26e1c9c5ef0
1 /*
2 * Copyright 2010 Detlef Riekenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <errno.h>
26 #include "wine/test.h"
28 static _invalid_parameter_handler (__cdecl *p_set_invalid_parameter_handler)(_invalid_parameter_handler);
29 typedef int (__cdecl *_INITTERM_E_FN)(void);
30 static int (__cdecl *p_initterm_e)(_INITTERM_E_FN *table, _INITTERM_E_FN *end);
31 static void* (__cdecl *p_encode_pointer)(void *);
32 static void* (__cdecl *p_decode_pointer)(void *);
33 static void* (__cdecl *p_encoded_null)(void);
34 static int *p_sys_nerr;
35 static int* (__cdecl *p__sys_nerr)(void);
36 static char **p_sys_errlist;
37 static char** (__cdecl *p__sys_errlist)(void);
38 static __int64 (__cdecl *p_strtoi64)(const char *, char **, int);
39 static unsigned __int64 (__cdecl *p_strtoui64)(const char *, char **, int);
41 static void* (WINAPI *pEncodePointer)(void *);
43 int cb_called[4];
45 /* ########## */
47 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
48 const wchar_t *function, const wchar_t *file,
49 unsigned line, uintptr_t arg)
51 ok(expression == NULL, "expression is not NULL\n");
52 ok(function == NULL, "function is not NULL\n");
53 ok(file == NULL, "file is not NULL\n");
54 ok(line == 0, "line = %u\n", line);
55 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
58 static int __cdecl initterm_cb0(void)
60 cb_called[0]++;
61 return 0;
64 static int __cdecl initterm_cb1(void)
66 cb_called[1]++;
67 return 1;
70 static int __cdecl initterm_cb2(void)
72 cb_called[2]++;
73 return 2;
77 static void test__initterm_e(void)
79 _INITTERM_E_FN table[4];
80 int res;
82 if (!p_initterm_e) {
83 skip("_initterm_e not found\n");
84 return;
87 memset(table, 0, sizeof(table));
89 memset(cb_called, 0, sizeof(cb_called));
90 errno = 0xdeadbeef;
91 res = p_initterm_e(table, table);
92 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
93 "got %d with 0x%x {%d, %d, %d}\n",
94 res, errno, cb_called[0], cb_called[1], cb_called[2]);
96 memset(cb_called, 0, sizeof(cb_called));
97 errno = 0xdeadbeef;
98 res = p_initterm_e(table, NULL);
99 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
100 "got %d with 0x%x {%d, %d, %d}\n",
101 res, errno, cb_called[0], cb_called[1], cb_called[2]);
103 if (0) {
104 /* this crash on Windows */
105 errno = 0xdeadbeef;
106 res = p_initterm_e(NULL, table);
107 trace("got %d with 0x%x\n", res, errno);
110 table[0] = initterm_cb0;
111 memset(cb_called, 0, sizeof(cb_called));
112 errno = 0xdeadbeef;
113 res = p_initterm_e(table, &table[1]);
114 ok( !res && (cb_called[0] == 1) && !cb_called[1] && !cb_called[2],
115 "got %d with 0x%x {%d, %d, %d}\n",
116 res, errno, cb_called[0], cb_called[1], cb_called[2]);
119 /* init-function returning failure */
120 table[1] = initterm_cb1;
121 memset(cb_called, 0, sizeof(cb_called));
122 errno = 0xdeadbeef;
123 res = p_initterm_e(table, &table[3]);
124 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
125 "got %d with 0x%x {%d, %d, %d}\n",
126 res, errno, cb_called[0], cb_called[1], cb_called[2]);
128 /* init-function not called, when end < start */
129 memset(cb_called, 0, sizeof(cb_called));
130 errno = 0xdeadbeef;
131 res = p_initterm_e(&table[3], table);
132 ok( !res && !cb_called[0] && !cb_called[1] && !cb_called[2],
133 "got %d with 0x%x {%d, %d, %d}\n",
134 res, errno, cb_called[0], cb_called[1], cb_called[2]);
136 /* initialization stop after first non-zero result */
137 table[2] = initterm_cb0;
138 memset(cb_called, 0, sizeof(cb_called));
139 errno = 0xdeadbeef;
140 res = p_initterm_e(table, &table[3]);
141 ok( (res == 1) && (cb_called[0] == 1) && (cb_called[1] == 1) && !cb_called[2],
142 "got %d with 0x%x {%d, %d, %d}\n",
143 res, errno, cb_called[0], cb_called[1], cb_called[2]);
145 /* NULL pointer in the array are skipped */
146 table[1] = NULL;
147 table[2] = initterm_cb2;
148 memset(cb_called, 0, sizeof(cb_called));
149 errno = 0xdeadbeef;
150 res = p_initterm_e(table, &table[3]);
151 ok( (res == 2) && (cb_called[0] == 1) && !cb_called[1] && (cb_called[2] == 1),
152 "got %d with 0x%x {%d, %d, %d}\n",
153 res, errno, cb_called[0], cb_called[1], cb_called[2]);
157 /* Beware that _encode_pointer is a NOP before XP
158 (the parameter is returned unchanged) */
159 static void test__encode_pointer(void)
161 void *ptr, *res;
163 if(!p_encode_pointer || !p_decode_pointer || !p_encoded_null) {
164 win_skip("_encode_pointer, _decode_pointer or _encoded_null not found\n");
165 return;
168 ptr = (void*)0xdeadbeef;
169 res = p_encode_pointer(ptr);
170 res = p_decode_pointer(res);
171 ok(res == ptr, "Pointers are different after encoding and decoding\n");
173 ok(p_encoded_null() == p_encode_pointer(NULL), "Error encoding null\n");
175 ptr = p_encode_pointer(p_encode_pointer);
176 ok(p_decode_pointer(ptr) == p_encode_pointer, "Error decoding pointer\n");
178 /* Not present before XP */
179 if (!pEncodePointer) {
180 win_skip("EncodePointer not found\n");
181 return;
184 res = pEncodePointer(p_encode_pointer);
185 ok(ptr == res, "_encode_pointer produced different result than EncodePointer\n");
189 static void test_error_messages(void)
191 int *size, size_copy;
193 if(!p_sys_nerr || !p__sys_nerr || !p_sys_errlist || !p__sys_errlist) {
194 win_skip("Skipping test_error_messages tests\n");
195 return;
198 size = p__sys_nerr();
199 size_copy = *size;
200 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
202 *size = 20;
203 ok(*p_sys_nerr == *size, "_sys_nerr = %u, size = %u\n", *p_sys_nerr, *size);
205 *size = size_copy;
207 ok(*p_sys_errlist == *(p__sys_errlist()), "p_sys_errlist != p__sys_errlist()\n");
210 static void test__strtoi64(void)
212 __int64 res;
213 unsigned __int64 ures;
215 if(!p_strtoi64 || !p_strtoui64) {
216 win_skip("_strtoi64 or _strtoui64 not found\n");
217 return;
220 if(!p_set_invalid_parameter_handler) {
221 win_skip("_set_invalid_parameter_handler not found\n");
222 return;
225 errno = 0xdeadbeef;
226 res = p_strtoi64(NULL, NULL, 10);
227 ok(res == 0, "res != 0\n");
228 res = p_strtoi64("123", NULL, 1);
229 ok(res == 0, "res != 0\n");
230 res = p_strtoi64("123", NULL, 37);
231 ok(res == 0, "res != 0\n");
232 ures = p_strtoui64(NULL, NULL, 10);
233 ok(ures == 0, "res = %d\n", (int)ures);
234 ures = p_strtoui64("123", NULL, 1);
235 ok(ures == 0, "res = %d\n", (int)ures);
236 ures = p_strtoui64("123", NULL, 37);
237 ok(ures == 0, "res = %d\n", (int)ures);
238 ok(errno == 0xdeadbeef, "errno = %x\n", errno);
241 /* ########## */
243 START_TEST(msvcr90)
245 HMODULE hcrt;
246 HMODULE hkernel32;
248 SetLastError(0xdeadbeef);
249 hcrt = LoadLibraryA("msvcr90.dll");
250 if (!hcrt) {
251 win_skip("msvcr90.dll not installed (got %d)\n", GetLastError());
252 return;
255 p_set_invalid_parameter_handler = (void *) GetProcAddress(hcrt, "_set_invalid_parameter_handler");
256 if(p_set_invalid_parameter_handler)
257 ok(p_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
258 "Invalid parameter handler was already set\n");
260 p_initterm_e = (void *) GetProcAddress(hcrt, "_initterm_e");
261 p_encode_pointer = (void *) GetProcAddress(hcrt, "_encode_pointer");
262 p_decode_pointer = (void *) GetProcAddress(hcrt, "_decode_pointer");
263 p_encoded_null = (void *) GetProcAddress(hcrt, "_encoded_null");
264 p_sys_nerr = (void *) GetProcAddress(hcrt, "_sys_nerr");
265 p__sys_nerr = (void *) GetProcAddress(hcrt, "__sys_nerr");
266 p_sys_errlist = (void *) GetProcAddress(hcrt, "_sys_errlist");
267 p__sys_errlist = (void *) GetProcAddress(hcrt, "__sys_errlist");
268 p_strtoi64 = (void *) GetProcAddress(hcrt, "_strtoi64");
269 p_strtoui64 = (void *) GetProcAddress(hcrt, "_strtoui64");
271 hkernel32 = GetModuleHandleA("kernel32.dll");
272 pEncodePointer = (void *) GetProcAddress(hkernel32, "EncodePointer");
274 test__initterm_e();
275 test__encode_pointer();
276 test_error_messages();
277 test__strtoi64();