msvcp90: Added std::tan(complex) tests.
[wine/wine-gecko.git] / dlls / msvcp90 / tests / misc.c
blob0f1b27e3e85258c6f66751cd490fc3e4fa034fdb
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
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 <stdio.h>
20 #include <locale.h>
21 #include <wctype.h>
22 #include <float.h>
24 #include <windef.h>
25 #include <winbase.h>
26 #include "wine/test.h"
28 typedef struct {
29 LCID handle;
30 unsigned page;
31 short *table;
32 int delfl;
33 } MSVCP__Ctypevec;
35 typedef struct {
36 LCID handle;
37 unsigned page;
38 } MSVCP__Collvec;
40 /* basic_string<char, char_traits<char>, allocator<char>> */
41 #define BUF_SIZE_CHAR 16
42 typedef struct
44 void *allocator;
45 union {
46 char buf[BUF_SIZE_CHAR];
47 char *ptr;
48 } data;
49 size_t size;
50 size_t res;
51 } basic_string_char;
53 /* class complex<float> */
54 typedef struct {
55 float real;
56 float imag;
57 } complex_float;
59 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
60 static _locale_t (__cdecl *p__get_current_locale)(void);
61 static void (__cdecl *p__free_locale)(_locale_t);
62 static void (__cdecl *p_free)(void*);
64 static void (__cdecl *p_char_assign)(void*, const void*);
65 static void (__cdecl *p_wchar_assign)(void*, const void*);
66 static void (__cdecl *p_short_assign)(void*, const void*);
68 static BYTE (__cdecl *p_char_eq)(const void*, const void*);
69 static BYTE (__cdecl *p_wchar_eq)(const void*, const void*);
70 static BYTE (__cdecl *p_short_eq)(const void*, const void*);
72 static char* (__cdecl *p_Copy_s)(char*, size_t, const char*, size_t);
74 static unsigned short (__cdecl *p_wctype)(const char*);
75 static MSVCP__Ctypevec* (__cdecl *p__Getctype)(MSVCP__Ctypevec*);
76 static /*MSVCP__Collvec*/ULONGLONG (__cdecl *p__Getcoll)(void);
77 static wctrans_t (__cdecl *p_wctrans)(const char*);
78 static wint_t (__cdecl *p_towctrans)(wint_t, wctrans_t);
80 #undef __thiscall
81 #ifdef __i386__
82 #define __thiscall __stdcall
83 #else
84 #define __thiscall __cdecl
85 #endif
87 static char* (__thiscall *p_char_address)(void*, char*);
88 static void* (__thiscall *p_char_ctor)(void*);
89 static void (__thiscall *p_char_deallocate)(void*, char*, size_t);
90 static char* (__thiscall *p_char_allocate)(void*, size_t);
91 static void (__thiscall *p_char_construct)(void*, char*, const char*);
92 static size_t (__thiscall *p_char_max_size)(void*);
94 static void* (__thiscall *p_collate_char_ctor_refs)(void*, size_t);
95 static int (__thiscall *p_collate_char_compare)(const void*, const char*,
96 const char*, const char*, const char*);
97 static void (__thiscall *p_collate_char_dtor)(void*);
98 static void* (__thiscall *p_numpunct_char_ctor)(void*);
99 static basic_string_char* (__thiscall *p_numpunct_char_falsename)(void*,basic_string_char*);
100 static void (__thiscall *p_numpunct_char_dtor)(void*);
101 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
102 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
104 static const int *basic_ostringstream_char_vbtable;
105 static /*basic_ostringstream_char*/void* (__thiscall *p_basic_ostringstream_char_ctor_mode)(
106 /*basic_ostringstream_char*/void*, int, /*MSVCP_bool*/int);
107 static void (__thiscall *p_basic_ostringstream_char_dtor)(/*basic_ostringstream_char*/void*);
108 static void (__thiscall *p_basic_ostringstream_char_vbase_dtor)(/*basic_ostringstream_char*/void*);
109 static void (__thiscall *p_basic_ios_char_dtor)(/*basic_ios_char*/void*);
111 static complex_float* (__thiscall *p_complex_float_ctor)(complex_float*, const float*, const float*);
112 static complex_float* (__cdecl *p_complex_float_add)(complex_float*, const complex_float*, const complex_float*);
113 static complex_float* (__cdecl *p_complex_float_div)(complex_float*, const complex_float*, const complex_float*);
114 static float (__cdecl *p_complex_float__Fabs)(const complex_float*, int*);
115 static complex_float* (__cdecl *p_complex_float_tan)(complex_float*, const complex_float*);
117 static int invalid_parameter = 0;
118 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
119 const wchar_t *function, const wchar_t *file,
120 unsigned line, uintptr_t arg)
122 ok(expression == NULL, "expression is not NULL\n");
123 ok(function == NULL, "function is not NULL\n");
124 ok(file == NULL, "file is not NULL\n");
125 ok(line == 0, "line = %u\n", line);
126 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
127 invalid_parameter++;
130 /* Emulate a __thiscall */
131 #ifdef __i386__
133 #include "pshpack1.h"
134 struct thiscall_thunk
136 BYTE pop_eax; /* popl %eax (ret addr) */
137 BYTE pop_edx; /* popl %edx (func) */
138 BYTE pop_ecx; /* popl %ecx (this) */
139 BYTE push_eax; /* pushl %eax */
140 WORD jmp_edx; /* jmp *%edx */
142 #include "poppack.h"
144 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
145 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
146 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
147 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
148 const void *c, const void *d );
149 struct thiscall_thunk_retptr *thunk_retptr;
151 static void init_thiscall_thunk(void)
153 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
154 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
155 thunk->pop_eax = 0x58; /* popl %eax */
156 thunk->pop_edx = 0x5a; /* popl %edx */
157 thunk->pop_ecx = 0x59; /* popl %ecx */
158 thunk->push_eax = 0x50; /* pushl %eax */
159 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
160 call_thiscall_func1 = (void *)thunk;
161 call_thiscall_func2 = (void *)thunk;
162 call_thiscall_func3 = (void *)thunk;
163 call_thiscall_func5 = (void *)thunk;
166 #define call_func1(func,_this) call_thiscall_func1(func,_this)
167 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
168 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
169 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
170 (const void*)(c), (const void *)(d))
172 #else
174 #define init_thiscall_thunk()
175 #define call_func1(func,_this) func(_this)
176 #define call_func2(func,_this,a) func(_this,a)
177 #define call_func3(func,_this,a,b) func(_this,a,b)
178 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
180 #endif /* __i386__ */
182 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
183 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
184 static BOOL init(void)
186 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
187 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
188 if(!msvcr || !msvcp) {
189 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
190 return FALSE;
193 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
194 p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
195 p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
196 p_free = (void*)GetProcAddress(msvcr, "free");
197 if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free) {
198 win_skip("Error setting tests environment\n");
199 return FALSE;
202 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
204 SET(p_wctype, "wctype");
205 SET(p__Getctype, "_Getctype");
206 SET(p__Getcoll, "_Getcoll");
207 SET(p_wctrans, "wctrans");
208 SET(p_towctrans, "towctrans");
209 SET(basic_ostringstream_char_vbtable, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
210 if(sizeof(void*) == 8) { /* 64-bit initialization */
211 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
212 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
213 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");
215 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
216 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
217 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");
219 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");
221 SET(p_char_address, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
222 SET(p_char_ctor, "??0?$allocator@D@std@@QEAA@XZ");
223 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
224 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
225 SET(p_char_construct, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
226 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QEBA_KXZ");
228 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QEAA@_K@Z");
229 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
230 SET(p_collate_char_dtor, "??1?$collate@D@std@@MEAA@XZ");
231 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QEAAXXZ");
232 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
233 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MEAA@XZ");
234 SET(p_basic_string_char_dtor,
235 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
236 SET(p_basic_string_char_cstr,
237 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
239 SET(p_basic_ostringstream_char_ctor_mode,
240 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
241 SET(p_basic_ostringstream_char_dtor,
242 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
243 SET(p_basic_ostringstream_char_vbase_dtor,
244 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
245 SET(p_basic_ios_char_dtor,
246 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UEAA@XZ");
248 SET(p_complex_float_ctor,
249 "??0?$complex@M@std@@QEAA@AEBM0@Z");
250 SET(p_complex_float_add,
251 "??$?HM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
252 SET(p_complex_float_div,
253 "??$?KM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
254 SET(p_complex_float__Fabs,
255 "??$_Fabs@M@std@@YAMAEBV?$complex@M@0@PEAH@Z");
256 SET(p_complex_float_tan,
257 "??$tan@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
258 } else {
259 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
260 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
261 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
263 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
264 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
265 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");
267 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");
269 SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
270 SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
271 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
272 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
273 SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
274 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");
276 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
277 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
278 SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
279 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
280 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
281 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
282 SET(p_basic_string_char_dtor,
283 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
284 SET(p_basic_string_char_cstr,
285 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
287 SET(p_basic_ostringstream_char_ctor_mode,
288 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
289 SET(p_basic_ostringstream_char_dtor,
290 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
291 SET(p_basic_ostringstream_char_vbase_dtor,
292 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
293 SET(p_basic_ios_char_dtor,
294 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ");
296 SET(p_complex_float_ctor,
297 "??0?$complex@M@std@@QAE@ABM0@Z");
298 SET(p_complex_float_add,
299 "??$?HM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
300 SET(p_complex_float_div,
301 "??$?KM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
302 SET(p_complex_float__Fabs,
303 "??$_Fabs@M@std@@YAMABV?$complex@M@0@PAH@Z");
304 SET(p_complex_float_tan,
305 "??$tan@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
308 init_thiscall_thunk();
309 return TRUE;
312 static void test_assign(void)
314 const char in[] = "abc";
315 char out[4];
317 out[1] = '#';
318 p_char_assign(out, in);
319 ok(out[0] == in[0], "out[0] = %c\n", out[0]);
320 ok(out[1] == '#', "out[1] = %c\n", out[1]);
322 out[2] = '#';
323 p_wchar_assign(out, in);
324 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
325 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
326 ok(out[2] == '#', "out[2] = %c\n", out[2]);
328 out[2] = '#';
329 p_short_assign(out, in);
330 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
331 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
332 ok(out[2] == '#', "out[2] = %c\n", out[2]);
335 static void test_equal(void)
337 static const char in1[] = "abc";
338 static const char in2[] = "ab";
339 static const char in3[] = "a";
340 static const char in4[] = "b";
341 BYTE ret;
343 ret = p_char_eq(in1, in2);
344 ok(ret == TRUE, "ret = %d\n", (int)ret);
345 ret = p_char_eq(in1, in3);
346 ok(ret == TRUE, "ret = %d\n", (int)ret);
347 ret = p_char_eq(in1, in4);
348 ok(ret == FALSE, "ret = %d\n", (int)ret);
350 ret = p_wchar_eq(in1, in2);
351 ok(ret == TRUE, "ret = %d\n", (int)ret);
352 ret = p_wchar_eq(in1, in3);
353 ok(ret == FALSE, "ret = %d\n", (int)ret);
354 ret = p_wchar_eq(in1, in4);
355 ok(ret == FALSE, "ret = %d\n", (int)ret);
357 ret = p_short_eq(in1, in2);
358 ok(ret == TRUE, "ret = %d\n", (int)ret);
359 ret = p_short_eq(in1, in3);
360 ok(ret == FALSE, "ret = %d\n", (int)ret);
361 ret = p_short_eq(in1, in4);
362 ok(ret == FALSE, "ret = %d\n", (int)ret);
365 static void test_Copy_s(void)
367 static const char src[] = "abcd";
368 char dest[32], *ret;
370 dest[4] = '#';
371 dest[5] = '\0';
372 ret = p_Copy_s(dest, 4, src, 4);
373 ok(ret == dest, "ret != dest\n");
374 ok(dest[4] == '#', "dest[4] != '#'\n");
375 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
377 ret = p_Copy_s(dest, 32, src, 4);
378 ok(ret == dest, "ret != dest\n");
379 ok(dest[4] == '#', "dest[4] != '#'\n");
380 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
382 errno = 0xdeadbeef;
383 dest[0] = '#';
384 ret = p_Copy_s(dest, 3, src, 4);
385 ok(ret == dest, "ret != dest\n");
386 ok(dest[0] == '\0', "dest[0] != 0\n");
387 ok(invalid_parameter==1, "invalid_parameter = %d\n",
388 invalid_parameter);
389 invalid_parameter = 0;
390 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
392 errno = 0xdeadbeef;
393 p_Copy_s(NULL, 32, src, 4);
394 ok(invalid_parameter==1, "invalid_parameter = %d\n",
395 invalid_parameter);
396 invalid_parameter = 0;
397 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
399 errno = 0xdeadbeef;
400 p_Copy_s(dest, 32, NULL, 4);
401 ok(invalid_parameter==1, "invalid_parameter = %d\n",
402 invalid_parameter);
403 invalid_parameter = 0;
404 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
407 static void test_wctype(void)
409 static const struct {
410 const char *name;
411 unsigned short mask;
412 } properties[] = {
413 { "alnum", 0x107 },
414 { "alpha", 0x103 },
415 { "cntrl", 0x020 },
416 { "digit", 0x004 },
417 { "graph", 0x117 },
418 { "lower", 0x002 },
419 { "print", 0x157 },
420 { "punct", 0x010 },
421 { "space", 0x008 },
422 { "upper", 0x001 },
423 { "xdigit", 0x080 },
424 { "ALNUM", 0x000 },
425 { "Alnum", 0x000 },
426 { "", 0x000 }
428 int i, ret;
430 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++) {
431 ret = p_wctype(properties[i].name);
432 ok(properties[i].mask == ret, "%d - Expected %x, got %x\n", i, properties[i].mask, ret);
436 static void test__Getctype(void)
438 MSVCP__Ctypevec ret;
439 _locale_t locale;
441 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
442 ok(ret.handle == 0, "ret.handle = %d\n", ret.handle);
443 ok(ret.page == 0, "ret.page = %d\n", ret.page);
444 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
445 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
446 p_free(ret.table);
448 locale = p__get_current_locale();
449 locale->locinfo->lc_handle[LC_COLLATE] = 0x1234567;
450 p__free_locale(locale);
451 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
452 ok(ret.handle == 0x1234567, "ret.handle = %d\n", ret.handle);
453 ok(ret.page == 0, "ret.page = %d\n", ret.page);
454 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
455 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
456 p_free(ret.table);
459 static void test__Getcoll(void)
461 ULONGLONG (__cdecl *p__Getcoll_arg)(MSVCP__Collvec*);
462 _locale_t locale;
464 union {
465 MSVCP__Collvec collvec;
466 ULONGLONG ull;
467 }ret;
469 locale = p__get_current_locale();
470 locale->locinfo->lc_handle[LC_COLLATE] = 0x7654321;
471 p__free_locale(locale);
472 ret.ull = 0;
473 p__Getcoll_arg = (void*)p__Getcoll;
474 p__Getcoll_arg(&ret.collvec);
475 ok(ret.collvec.handle == 0, "ret.handle = %x\n", ret.collvec.handle);
476 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
478 ret.ull = p__Getcoll();
479 ok(ret.collvec.handle == 0x7654321, "ret.collvec.handle = %x\n", ret.collvec.handle);
480 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
483 static void test_towctrans(void)
485 wchar_t ret;
487 ret = p_wctrans("tolower");
488 ok(ret == 2, "wctrans returned %d, expected 2\n", ret);
489 ret = p_wctrans("toupper");
490 ok(ret == 1, "wctrans returned %d, expected 1\n", ret);
491 ret = p_wctrans("toLower");
492 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
493 ret = p_wctrans("");
494 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
495 if(0) { /* crashes on windows */
496 ret = p_wctrans(NULL);
497 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
500 ret = p_towctrans('t', 2);
501 ok(ret == 't', "towctrans('t', 2) returned %c, expected t\n", ret);
502 ret = p_towctrans('T', 2);
503 ok(ret == 't', "towctrans('T', 2) returned %c, expected t\n", ret);
504 ret = p_towctrans('T', 0);
505 ok(ret == 't', "towctrans('T', 0) returned %c, expected t\n", ret);
506 ret = p_towctrans('T', 3);
507 ok(ret == 't', "towctrans('T', 3) returned %c, expected t\n", ret);
508 ret = p_towctrans('t', 1);
509 ok(ret == 'T', "towctrans('t', 1) returned %c, expected T\n", ret);
510 ret = p_towctrans('T', 1);
511 ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret);
514 static void test_allocator_char(void)
516 void *allocator = (void*)0xdeadbeef;
517 char *ptr;
518 char val;
519 unsigned int size;
521 allocator = call_func1(p_char_ctor, allocator);
522 ok(allocator == (void*)0xdeadbeef, "allocator = %p\n", allocator);
524 ptr = call_func2(p_char_address, NULL, (void*)0xdeadbeef);
525 ok(ptr == (void*)0xdeadbeef, "incorrect address (%p)\n", ptr);
527 ptr = NULL;
528 ptr = call_func2(p_char_allocate, allocator, 10);
529 ok(ptr != NULL, "Memory allocation failed\n");
531 ptr[0] = ptr[1] = '#';
532 val = 'a';
533 call_func3(p_char_construct, allocator, ptr, &val);
534 val = 'b';
535 call_func3(p_char_construct, allocator, (ptr+1), &val);
536 ok(ptr[0] == 'a', "ptr[0] = %c\n", ptr[0]);
537 ok(ptr[1] == 'b', "ptr[1] = %c\n", ptr[1]);
539 call_func3(p_char_deallocate, allocator, ptr, -1);
541 size = (unsigned int)call_func1(p_char_max_size, allocator);
542 ok(size == (unsigned int)0xffffffff, "size = %x\n", size);
545 static void test_virtual_call(void)
547 BYTE this[256];
548 basic_string_char bstr;
549 _locale_t locale;
550 const char *p;
551 char str1[] = "test";
552 char str2[] = "TEST";
553 int ret;
555 locale = p__get_current_locale();
556 locale->locinfo->lc_handle[LC_COLLATE] = 1;
557 p__free_locale(locale);
558 call_func2(p_collate_char_ctor_refs, this, 0);
559 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+4, str1, str1+4);
560 ok(ret == 0, "collate<char>::compare returned %d\n", ret);
561 ret = (int)call_func5(p_collate_char_compare, this, str2, str2+4, str1, str1+4);
562 ok(ret == 1, "collate<char>::compare returned %d\n", ret);
563 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+3, str1, str1+4);
564 ok(ret == -1, "collate<char>::compare returned %d\n", ret);
565 call_func1(p_collate_char_dtor, this);
567 call_func1(p_numpunct_char_ctor, this);
568 call_func2(p_numpunct_char_falsename, this, &bstr);
569 p = call_func1(p_basic_string_char_cstr, &bstr);
570 ok(!strcmp(p, "false"), "numpunct<char>::falsename returned %s\n", p);
571 call_func1(p_basic_string_char_dtor, &bstr);
572 call_func1(p_numpunct_char_dtor, this);
575 static void test_virtual_base_dtors(void)
577 char this[512];
579 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 1);
580 call_func1(p_basic_ostringstream_char_vbase_dtor, this);
582 /* this test uses vbtable set by earlier test */
583 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 0);
584 call_func1(p_basic_ostringstream_char_dtor, this+basic_ostringstream_char_vbtable[1]);
585 call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
588 static BOOL almost_eq(float f1, float f2)
590 f1 = (f1-f2)/f1;
591 if(f1 < 0)
592 f1 = -f1;
593 return f1 < 0.0001;
596 static void test_complex(void)
598 complex_float c1, c2, c3;
599 float f1, f2;
600 int scale;
602 f1 = 1;
603 f2 = 2;
604 call_func3(p_complex_float_ctor, &c1, &f1, &f2);
605 ok(c1.real == 1, "c1.real = %f\n", c1.real);
606 ok(c1.imag == 2, "c1.imag = %f\n", c1.imag);
608 f1 = p_complex_float__Fabs(&c1, &scale);
609 ok(almost_eq(f1, 0.559017), "abs(1+2i) = %f\n", f1);
610 ok(scale == 2, "scale = %d\n", scale);
612 f1 = -1;
613 f2 = 1;
614 call_func3(p_complex_float_ctor, &c2, &f1, &f2);
615 ok(c2.real == -1, "c2.real = %f\n", c1.real);
616 ok(c2.imag == 1, "c2.imag = %f\n", c1.imag);
618 f1 = p_complex_float__Fabs(&c2, &scale);
619 ok(almost_eq(f1, 0.353553), "abs(1-1i) = %f\n", f1);
620 ok(scale == 2, "scale = %d\n", scale);
622 p_complex_float_add(&c3, &c1, &c2);
623 ok(c3.real == 0, "c3.real = %f\n", c3.real);
624 ok(c3.imag == 3, "c3.imag = %f\n", c3.imag);
626 f1 = p_complex_float__Fabs(&c3, &scale);
627 ok(almost_eq(f1, 0.75), "abs(0+3i) = %f\n", f1);
628 ok(scale == 2, "scale = %d\n", scale);
630 p_complex_float_add(&c2, &c1, &c3);
631 ok(c2.real == 1, "c2.real = %f\n", c1.real);
632 ok(c2.imag == 5, "c2.imag = %f\n", c1.imag);
634 f1 = p_complex_float__Fabs(&c3, &scale);
635 ok(almost_eq(f1, 0.75), "abs(1+5i) = %f\n", f1);
636 ok(scale == 2, "scale = %d\n", scale);
638 /* (1+5i) / (0+3i) */
639 p_complex_float_div(&c1, &c2, &c3);
640 ok(almost_eq(c1.real, 1.666667), "c1.real = %f\n", c1.real);
641 ok(almost_eq(c1.imag, -0.33333), "c1.imag = %f\n", c1.imag);
643 /* (1+5i) / (2+0i) */
644 c3.real = 2;
645 c3.imag = 0;
646 p_complex_float_div(&c1, &c2, &c3);
647 ok(almost_eq(c1.real, 0.5), "c1.real = %f\n", c1.real);
648 ok(almost_eq(c1.imag, 2.5), "c1.imag = %f\n", c1.imag);
650 f1 = p_complex_float__Fabs(&c1, &scale);
651 ok(almost_eq(f1, 0.637377), "abs(0.5+2.5i) = %f\n", f1);
652 ok(scale == 2, "scale = %d\n", scale);
654 /* (1+5i) / 0 */
655 c3.real = 0;
656 p_complex_float_div(&c1, &c2, &c3);
657 ok(_isnan(c1.real), "c1.real = %f\n", c1.real);
658 ok(_isnan(c1.imag), "c1.imag = %f\n", c1.imag);
660 f1 = p_complex_float__Fabs(&c1, &scale);
661 ok(_isnan(f1), "abs(NaN+NaNi) = %f\n", f1);
662 ok(scale == 0, "scale = %d\n", scale);
664 /* (1+5i) / (NaN-2i) */
665 c1.imag = -2;
666 p_complex_float_div(&c3, &c2, &c1);
667 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
668 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
670 /* (NaN-2i) / (1+0i) */
671 c2.imag = 0;
672 p_complex_float_div(&c3, &c1, &c2);
673 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
674 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
676 /* (1+0i) + (NaN-2i) */
677 p_complex_float_add(&c3, &c2, &c1);
678 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
679 ok(c3.imag == -2, "c3.imag = %f\n", c3.imag);
681 f1 = p_complex_float__Fabs(&c3, &scale);
682 ok(_isnan(f1), "abs(NaN-2i) = %f\n", f1);
683 ok(scale == 0, "scale = %d\n", scale);
685 c3.real = 1000;
686 f1 = p_complex_float__Fabs(&c3, &scale);
687 ok(almost_eq(f1, 250.000504), "abs(1000-2i) = %f\n", f1);
688 ok(scale == 2, "scale = %d\n", scale);
690 c3.real = 0.1;
691 c3.imag = 0.1;
692 f1 = p_complex_float__Fabs(&c3, &scale);
693 ok(almost_eq(f1, 0.565685), "abs(0.1+0.1i) = %f\n", f1);
694 ok(scale == -2, "scale = %d\n", scale);
696 c3.real = 1;
697 c3.imag = 0;
698 f1 = p_complex_float__Fabs(&c3, &scale);
699 ok(almost_eq(f1, 0.25), "abs(1+0i) = %f\n", f1);
700 ok(scale == 2, "scale = %d\n", scale);
702 c3.real = 0.99;
703 c3.imag = 0;
704 f1 = p_complex_float__Fabs(&c3, &scale);
705 ok(almost_eq(f1, 3.96), "abs(0.99+0i) = %f\n", f1);
706 ok(scale == -2, "scale = %d\n", scale);
708 c3.real = 0;
709 c3.imag = 0;
710 f1 = p_complex_float__Fabs(&c3, &scale);
711 ok(f1 == 0, "abs(0+0i) = %f\n", f1);
712 ok(scale == 0, "scale = %d\n", scale);
714 c1.real = 0;
715 c1.imag = 0;
716 p_complex_float_tan(&c2, &c1);
717 ok(c2.real == 0, "c2.real = %f\n", c2.real);
718 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
720 c1.real = 3.14159/2;
721 c1.imag = 0;
722 p_complex_float_tan(&c2, &c1);
723 ok(almost_eq(c2.real, 788906.062500), "c2.real = %f\n", c2.real);
724 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
726 c1.real = 7.12;
727 c1.imag = 0.17;
728 p_complex_float_tan(&c2, &c1);
729 ok(almost_eq(c2.real, 1.040818), "c2.real = %f\n", c2.real);
730 ok(almost_eq(c2.imag, 0.362651), "c2.imag = %f\n", c2.imag);
733 START_TEST(misc)
735 if(!init())
736 return;
738 test_assign();
739 test_equal();
740 test_Copy_s();
741 test_wctype();
742 test__Getctype();
743 test__Getcoll();
744 test_towctrans();
745 test_virtual_call();
746 test_virtual_base_dtors();
747 test_allocator_char();
748 test_complex();
750 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");