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
26 #include "wine/test.h"
40 /* basic_string<char, char_traits<char>, allocator<char>> */
41 #define BUF_SIZE_CHAR 16
46 char buf[BUF_SIZE_CHAR];
53 /* class 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);
82 #define __thiscall __stdcall
84 #define __thiscall __cdecl
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*);
116 static complex_float* (__cdecl *p_complex_float_tanh)(complex_float*, const complex_float*);
117 static complex_float* (__cdecl *p_complex_float_log10)(complex_float*, const complex_float*);
118 static complex_float* (__cdecl *p_complex_float_sqrt)(complex_float*, const complex_float*);
120 static int invalid_parameter = 0;
121 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
122 const wchar_t *function, const wchar_t *file,
123 unsigned line, uintptr_t arg)
125 ok(expression == NULL, "expression is not NULL\n");
126 ok(function == NULL, "function is not NULL\n");
127 ok(file == NULL, "file is not NULL\n");
128 ok(line == 0, "line = %u\n", line);
129 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
133 /* Emulate a __thiscall */
136 #include "pshpack1.h"
137 struct thiscall_thunk
139 BYTE pop_eax; /* popl %eax (ret addr) */
140 BYTE pop_edx; /* popl %edx (func) */
141 BYTE pop_ecx; /* popl %ecx (this) */
142 BYTE push_eax; /* pushl %eax */
143 WORD jmp_edx; /* jmp *%edx */
147 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
148 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
149 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
150 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
151 const void *c, const void *d );
152 struct thiscall_thunk_retptr *thunk_retptr;
154 static void init_thiscall_thunk(void)
156 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
157 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
158 thunk->pop_eax = 0x58; /* popl %eax */
159 thunk->pop_edx = 0x5a; /* popl %edx */
160 thunk->pop_ecx = 0x59; /* popl %ecx */
161 thunk->push_eax = 0x50; /* pushl %eax */
162 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
163 call_thiscall_func1 = (void *)thunk;
164 call_thiscall_func2 = (void *)thunk;
165 call_thiscall_func3 = (void *)thunk;
166 call_thiscall_func5 = (void *)thunk;
169 #define call_func1(func,_this) call_thiscall_func1(func,_this)
170 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
171 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
172 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
173 (const void*)(c), (const void *)(d))
177 #define init_thiscall_thunk()
178 #define call_func1(func,_this) func(_this)
179 #define call_func2(func,_this,a) func(_this,a)
180 #define call_func3(func,_this,a,b) func(_this,a,b)
181 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
183 #endif /* __i386__ */
185 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
186 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
187 static BOOL init(void)
189 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
190 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
191 if(!msvcr || !msvcp) {
192 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
196 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
197 p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
198 p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
199 p_free = (void*)GetProcAddress(msvcr, "free");
200 if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free) {
201 win_skip("Error setting tests environment\n");
205 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
207 SET(p_wctype, "wctype");
208 SET(p__Getctype, "_Getctype");
209 SET(p__Getcoll, "_Getcoll");
210 SET(p_wctrans, "wctrans");
211 SET(p_towctrans, "towctrans");
212 SET(basic_ostringstream_char_vbtable, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
213 if(sizeof(void*) == 8) { /* 64-bit initialization */
214 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
215 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
216 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");
218 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
219 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
220 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");
222 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");
224 SET(p_char_address, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
225 SET(p_char_ctor, "??0?$allocator@D@std@@QEAA@XZ");
226 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
227 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
228 SET(p_char_construct, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
229 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QEBA_KXZ");
231 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QEAA@_K@Z");
232 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
233 SET(p_collate_char_dtor, "??1?$collate@D@std@@MEAA@XZ");
234 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QEAAXXZ");
235 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
236 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MEAA@XZ");
237 SET(p_basic_string_char_dtor,
238 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
239 SET(p_basic_string_char_cstr,
240 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
242 SET(p_basic_ostringstream_char_ctor_mode,
243 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
244 SET(p_basic_ostringstream_char_dtor,
245 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
246 SET(p_basic_ostringstream_char_vbase_dtor,
247 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
248 SET(p_basic_ios_char_dtor,
249 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UEAA@XZ");
251 SET(p_complex_float_ctor,
252 "??0?$complex@M@std@@QEAA@AEBM0@Z");
253 SET(p_complex_float_add,
254 "??$?HM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
255 SET(p_complex_float_div,
256 "??$?KM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
257 SET(p_complex_float__Fabs,
258 "??$_Fabs@M@std@@YAMAEBV?$complex@M@0@PEAH@Z");
259 SET(p_complex_float_tan,
260 "??$tan@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
261 SET(p_complex_float_tanh,
262 "??$tanh@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
263 SET(p_complex_float_log10,
264 "??$log10@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
265 SET(p_complex_float_sqrt,
266 "??$sqrt@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
268 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
269 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
270 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
272 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
273 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
274 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");
276 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");
278 SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
279 SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
280 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
281 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
282 SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
283 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");
285 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
286 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
287 SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
288 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
289 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
290 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
291 SET(p_basic_string_char_dtor,
292 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
293 SET(p_basic_string_char_cstr,
294 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
296 SET(p_basic_ostringstream_char_ctor_mode,
297 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
298 SET(p_basic_ostringstream_char_dtor,
299 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
300 SET(p_basic_ostringstream_char_vbase_dtor,
301 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
302 SET(p_basic_ios_char_dtor,
303 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ");
305 SET(p_complex_float_ctor,
306 "??0?$complex@M@std@@QAE@ABM0@Z");
307 SET(p_complex_float_add,
308 "??$?HM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
309 SET(p_complex_float_div,
310 "??$?KM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
311 SET(p_complex_float__Fabs,
312 "??$_Fabs@M@std@@YAMABV?$complex@M@0@PAH@Z");
313 SET(p_complex_float_tan,
314 "??$tan@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
315 SET(p_complex_float_tanh,
316 "??$tanh@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
317 SET(p_complex_float_log10,
318 "??$log10@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
319 SET(p_complex_float_sqrt,
320 "??$sqrt@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
323 init_thiscall_thunk();
327 static void test_assign(void)
329 const char in[] = "abc";
333 p_char_assign(out, in);
334 ok(out[0] == in[0], "out[0] = %c\n", out[0]);
335 ok(out[1] == '#', "out[1] = %c\n", out[1]);
338 p_wchar_assign(out, in);
339 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
340 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
341 ok(out[2] == '#', "out[2] = %c\n", out[2]);
344 p_short_assign(out, in);
345 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
346 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
347 ok(out[2] == '#', "out[2] = %c\n", out[2]);
350 static void test_equal(void)
352 static const char in1[] = "abc";
353 static const char in2[] = "ab";
354 static const char in3[] = "a";
355 static const char in4[] = "b";
358 ret = p_char_eq(in1, in2);
359 ok(ret == TRUE, "ret = %d\n", (int)ret);
360 ret = p_char_eq(in1, in3);
361 ok(ret == TRUE, "ret = %d\n", (int)ret);
362 ret = p_char_eq(in1, in4);
363 ok(ret == FALSE, "ret = %d\n", (int)ret);
365 ret = p_wchar_eq(in1, in2);
366 ok(ret == TRUE, "ret = %d\n", (int)ret);
367 ret = p_wchar_eq(in1, in3);
368 ok(ret == FALSE, "ret = %d\n", (int)ret);
369 ret = p_wchar_eq(in1, in4);
370 ok(ret == FALSE, "ret = %d\n", (int)ret);
372 ret = p_short_eq(in1, in2);
373 ok(ret == TRUE, "ret = %d\n", (int)ret);
374 ret = p_short_eq(in1, in3);
375 ok(ret == FALSE, "ret = %d\n", (int)ret);
376 ret = p_short_eq(in1, in4);
377 ok(ret == FALSE, "ret = %d\n", (int)ret);
380 static void test_Copy_s(void)
382 static const char src[] = "abcd";
387 ret = p_Copy_s(dest, 4, src, 4);
388 ok(ret == dest, "ret != dest\n");
389 ok(dest[4] == '#', "dest[4] != '#'\n");
390 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
392 ret = p_Copy_s(dest, 32, src, 4);
393 ok(ret == dest, "ret != dest\n");
394 ok(dest[4] == '#', "dest[4] != '#'\n");
395 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
399 ret = p_Copy_s(dest, 3, src, 4);
400 ok(ret == dest, "ret != dest\n");
401 ok(dest[0] == '\0', "dest[0] != 0\n");
402 ok(invalid_parameter==1, "invalid_parameter = %d\n",
404 invalid_parameter = 0;
405 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
408 p_Copy_s(NULL, 32, src, 4);
409 ok(invalid_parameter==1, "invalid_parameter = %d\n",
411 invalid_parameter = 0;
412 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
415 p_Copy_s(dest, 32, NULL, 4);
416 ok(invalid_parameter==1, "invalid_parameter = %d\n",
418 invalid_parameter = 0;
419 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
422 static void test_wctype(void)
424 static const struct {
445 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++) {
446 ret = p_wctype(properties[i].name);
447 ok(properties[i].mask == ret, "%d - Expected %x, got %x\n", i, properties[i].mask, ret);
451 static void test__Getctype(void)
456 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
457 ok(ret.handle == 0, "ret.handle = %d\n", ret.handle);
458 ok(ret.page == 0, "ret.page = %d\n", ret.page);
459 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
460 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
463 locale = p__get_current_locale();
464 locale->locinfo->lc_handle[LC_COLLATE] = 0x1234567;
465 p__free_locale(locale);
466 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
467 ok(ret.handle == 0x1234567, "ret.handle = %d\n", ret.handle);
468 ok(ret.page == 0, "ret.page = %d\n", ret.page);
469 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
470 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
474 static void test__Getcoll(void)
476 ULONGLONG (__cdecl *p__Getcoll_arg)(MSVCP__Collvec*);
480 MSVCP__Collvec collvec;
484 locale = p__get_current_locale();
485 locale->locinfo->lc_handle[LC_COLLATE] = 0x7654321;
486 p__free_locale(locale);
488 p__Getcoll_arg = (void*)p__Getcoll;
489 p__Getcoll_arg(&ret.collvec);
490 ok(ret.collvec.handle == 0, "ret.handle = %x\n", ret.collvec.handle);
491 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
493 ret.ull = p__Getcoll();
494 ok(ret.collvec.handle == 0x7654321, "ret.collvec.handle = %x\n", ret.collvec.handle);
495 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
498 static void test_towctrans(void)
502 ret = p_wctrans("tolower");
503 ok(ret == 2, "wctrans returned %d, expected 2\n", ret);
504 ret = p_wctrans("toupper");
505 ok(ret == 1, "wctrans returned %d, expected 1\n", ret);
506 ret = p_wctrans("toLower");
507 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
509 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
510 if(0) { /* crashes on windows */
511 ret = p_wctrans(NULL);
512 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
515 ret = p_towctrans('t', 2);
516 ok(ret == 't', "towctrans('t', 2) returned %c, expected t\n", ret);
517 ret = p_towctrans('T', 2);
518 ok(ret == 't', "towctrans('T', 2) returned %c, expected t\n", ret);
519 ret = p_towctrans('T', 0);
520 ok(ret == 't', "towctrans('T', 0) returned %c, expected t\n", ret);
521 ret = p_towctrans('T', 3);
522 ok(ret == 't', "towctrans('T', 3) returned %c, expected t\n", ret);
523 ret = p_towctrans('t', 1);
524 ok(ret == 'T', "towctrans('t', 1) returned %c, expected T\n", ret);
525 ret = p_towctrans('T', 1);
526 ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret);
529 static void test_allocator_char(void)
531 void *allocator = (void*)0xdeadbeef;
536 allocator = call_func1(p_char_ctor, allocator);
537 ok(allocator == (void*)0xdeadbeef, "allocator = %p\n", allocator);
539 ptr = call_func2(p_char_address, NULL, (void*)0xdeadbeef);
540 ok(ptr == (void*)0xdeadbeef, "incorrect address (%p)\n", ptr);
543 ptr = call_func2(p_char_allocate, allocator, 10);
544 ok(ptr != NULL, "Memory allocation failed\n");
546 ptr[0] = ptr[1] = '#';
548 call_func3(p_char_construct, allocator, ptr, &val);
550 call_func3(p_char_construct, allocator, (ptr+1), &val);
551 ok(ptr[0] == 'a', "ptr[0] = %c\n", ptr[0]);
552 ok(ptr[1] == 'b', "ptr[1] = %c\n", ptr[1]);
554 call_func3(p_char_deallocate, allocator, ptr, -1);
556 size = (unsigned int)call_func1(p_char_max_size, allocator);
557 ok(size == (unsigned int)0xffffffff, "size = %x\n", size);
560 static void test_virtual_call(void)
563 basic_string_char bstr;
566 char str1[] = "test";
567 char str2[] = "TEST";
570 locale = p__get_current_locale();
571 locale->locinfo->lc_handle[LC_COLLATE] = 1;
572 p__free_locale(locale);
573 call_func2(p_collate_char_ctor_refs, this, 0);
574 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+4, str1, str1+4);
575 ok(ret == 0, "collate<char>::compare returned %d\n", ret);
576 ret = (int)call_func5(p_collate_char_compare, this, str2, str2+4, str1, str1+4);
577 ok(ret == 1, "collate<char>::compare returned %d\n", ret);
578 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+3, str1, str1+4);
579 ok(ret == -1, "collate<char>::compare returned %d\n", ret);
580 call_func1(p_collate_char_dtor, this);
582 call_func1(p_numpunct_char_ctor, this);
583 call_func2(p_numpunct_char_falsename, this, &bstr);
584 p = call_func1(p_basic_string_char_cstr, &bstr);
585 ok(!strcmp(p, "false"), "numpunct<char>::falsename returned %s\n", p);
586 call_func1(p_basic_string_char_dtor, &bstr);
587 call_func1(p_numpunct_char_dtor, this);
590 static void test_virtual_base_dtors(void)
594 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 1);
595 call_func1(p_basic_ostringstream_char_vbase_dtor, this);
597 /* this test uses vbtable set by earlier test */
598 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 0);
599 call_func1(p_basic_ostringstream_char_dtor, this+basic_ostringstream_char_vbtable[1]);
600 call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
603 static BOOL almost_eq(float f1, float f2)
611 static void test_complex(void)
613 complex_float c1, c2, c3;
619 call_func3(p_complex_float_ctor, &c1, &f1, &f2);
620 ok(c1.real == 1, "c1.real = %f\n", c1.real);
621 ok(c1.imag == 2, "c1.imag = %f\n", c1.imag);
623 f1 = p_complex_float__Fabs(&c1, &scale);
624 ok(almost_eq(f1, 0.559017), "abs(1+2i) = %f\n", f1);
625 ok(scale == 2, "scale = %d\n", scale);
629 call_func3(p_complex_float_ctor, &c2, &f1, &f2);
630 ok(c2.real == -1, "c2.real = %f\n", c1.real);
631 ok(c2.imag == 1, "c2.imag = %f\n", c1.imag);
633 f1 = p_complex_float__Fabs(&c2, &scale);
634 ok(almost_eq(f1, 0.353553), "abs(1-1i) = %f\n", f1);
635 ok(scale == 2, "scale = %d\n", scale);
637 p_complex_float_add(&c3, &c1, &c2);
638 ok(c3.real == 0, "c3.real = %f\n", c3.real);
639 ok(c3.imag == 3, "c3.imag = %f\n", c3.imag);
641 f1 = p_complex_float__Fabs(&c3, &scale);
642 ok(almost_eq(f1, 0.75), "abs(0+3i) = %f\n", f1);
643 ok(scale == 2, "scale = %d\n", scale);
645 p_complex_float_add(&c2, &c1, &c3);
646 ok(c2.real == 1, "c2.real = %f\n", c1.real);
647 ok(c2.imag == 5, "c2.imag = %f\n", c1.imag);
649 f1 = p_complex_float__Fabs(&c3, &scale);
650 ok(almost_eq(f1, 0.75), "abs(1+5i) = %f\n", f1);
651 ok(scale == 2, "scale = %d\n", scale);
653 /* (1+5i) / (0+3i) */
654 p_complex_float_div(&c1, &c2, &c3);
655 ok(almost_eq(c1.real, 1.666667), "c1.real = %f\n", c1.real);
656 ok(almost_eq(c1.imag, -0.33333), "c1.imag = %f\n", c1.imag);
658 /* (1+5i) / (2+0i) */
661 p_complex_float_div(&c1, &c2, &c3);
662 ok(almost_eq(c1.real, 0.5), "c1.real = %f\n", c1.real);
663 ok(almost_eq(c1.imag, 2.5), "c1.imag = %f\n", c1.imag);
665 f1 = p_complex_float__Fabs(&c1, &scale);
666 ok(almost_eq(f1, 0.637377), "abs(0.5+2.5i) = %f\n", f1);
667 ok(scale == 2, "scale = %d\n", scale);
671 p_complex_float_div(&c1, &c2, &c3);
672 ok(_isnan(c1.real), "c1.real = %f\n", c1.real);
673 ok(_isnan(c1.imag), "c1.imag = %f\n", c1.imag);
675 f1 = p_complex_float__Fabs(&c1, &scale);
676 ok(_isnan(f1), "abs(NaN+NaNi) = %f\n", f1);
677 ok(scale == 0, "scale = %d\n", scale);
679 /* (1+5i) / (NaN-2i) */
681 p_complex_float_div(&c3, &c2, &c1);
682 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
683 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
685 /* (NaN-2i) / (1+0i) */
687 p_complex_float_div(&c3, &c1, &c2);
688 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
689 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
691 /* (1+0i) + (NaN-2i) */
692 p_complex_float_add(&c3, &c2, &c1);
693 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
694 ok(c3.imag == -2, "c3.imag = %f\n", c3.imag);
696 f1 = p_complex_float__Fabs(&c3, &scale);
697 ok(_isnan(f1), "abs(NaN-2i) = %f\n", f1);
698 ok(scale == 0, "scale = %d\n", scale);
701 f1 = p_complex_float__Fabs(&c3, &scale);
702 ok(almost_eq(f1, 250.000504), "abs(1000-2i) = %f\n", f1);
703 ok(scale == 2, "scale = %d\n", scale);
707 f1 = p_complex_float__Fabs(&c3, &scale);
708 ok(almost_eq(f1, 0.565685), "abs(0.1+0.1i) = %f\n", f1);
709 ok(scale == -2, "scale = %d\n", scale);
713 f1 = p_complex_float__Fabs(&c3, &scale);
714 ok(almost_eq(f1, 0.25), "abs(1+0i) = %f\n", f1);
715 ok(scale == 2, "scale = %d\n", scale);
719 f1 = p_complex_float__Fabs(&c3, &scale);
720 ok(almost_eq(f1, 3.96), "abs(0.99+0i) = %f\n", f1);
721 ok(scale == -2, "scale = %d\n", scale);
725 f1 = p_complex_float__Fabs(&c3, &scale);
726 ok(f1 == 0, "abs(0+0i) = %f\n", f1);
727 ok(scale == 0, "scale = %d\n", scale);
731 p_complex_float_tan(&c2, &c1);
732 ok(c2.real == 0, "c2.real = %f\n", c2.real);
733 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
734 p_complex_float_tanh(&c2, &c1);
735 ok(c2.real == 0, "c2.real = %f\n", c2.real);
736 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
737 p_complex_float_log10(&c2, &c1);
738 ok(c2.real < -FLT_MAX /* c2.real == -inf */, "c2.real = %f\n", c2.real);
739 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
740 p_complex_float_sqrt(&c2, &c1);
741 ok(c2.real == 0, "c2.real = %f\n", c2.real);
742 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
746 p_complex_float_tan(&c2, &c1);
747 ok(almost_eq(c2.real, 788906.062500), "c2.real = %f\n", c2.real);
748 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
749 p_complex_float_tanh(&c2, &c1);
750 ok(almost_eq(c2.real, 0.917152), "c2.real = %f\n", c2.real);
751 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
752 p_complex_float_log10(&c2, &c1);
753 ok(almost_eq(c2.real, 0.196120), "c2.real = %f\n", c2.real);
754 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
755 p_complex_float_sqrt(&c2, &c1);
756 ok(almost_eq(c2.real, 1.253314), "c2.real = %f\n", c2.real);
757 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
761 p_complex_float_tan(&c2, &c1);
762 ok(almost_eq(c2.real, 1.040818), "c2.real = %f\n", c2.real);
763 ok(almost_eq(c2.imag, 0.362651), "c2.imag = %f\n", c2.imag);
764 p_complex_float_tanh(&c2, &c1);
765 ok(almost_eq(c2.real, 0.999999), "c2.real = %f\n", c2.real);
766 ok(almost_eq(c2.imag, 4.3627e-7), "c2.imag = %g\n", c2.imag);
767 p_complex_float_log10(&c2, &c1);
768 ok(almost_eq(c2.real, 0.852604), "c2.real = %f\n", c2.real);
769 ok(almost_eq(c2.imag, 0.0103674), "c2.imag = %g\n", c2.imag);
770 p_complex_float_sqrt(&c2, &c1);
771 ok(almost_eq(c2.real, 2.668523), "c2.real = %f\n", c2.real);
772 ok(almost_eq(c2.imag, 0.0318528), "c2.imag = %g\n", c2.imag);
776 p_complex_float_tan(&c2, &c1);
777 ok(almost_eq(c2.real, 0.135859), "c2.real = %f\n", c2.real);
778 ok(almost_eq(c2.imag, 0.191341), "c2.imag = %f\n", c2.imag);
779 p_complex_float_tanh(&c2, &c1);
780 ok(almost_eq(c2.real, 0.144134), "c2.real = %f\n", c2.real);
781 ok(almost_eq(c2.imag, 0.188464), "c2.imag = %f\n", c2.imag);
782 p_complex_float_log10(&c2, &c1);
783 ok(almost_eq(c2.real, -0.627072), "c2.real = %f\n", c2.real);
784 ok(almost_eq(c2.imag, 0.4064), "c2.imag = %g\n", c2.imag);
785 p_complex_float_sqrt(&c2, &c1);
786 ok(almost_eq(c2.real, 0.433595), "c2.real = %f\n", c2.real);
787 ok(almost_eq(c2.imag, 0.219099), "c2.imag = %g\n", c2.imag);
803 test_virtual_base_dtors();
804 test_allocator_char();
807 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");