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 );
153 static void init_thiscall_thunk(void)
155 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
156 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
157 thunk->pop_eax = 0x58; /* popl %eax */
158 thunk->pop_edx = 0x5a; /* popl %edx */
159 thunk->pop_ecx = 0x59; /* popl %ecx */
160 thunk->push_eax = 0x50; /* pushl %eax */
161 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
162 call_thiscall_func1 = (void *)thunk;
163 call_thiscall_func2 = (void *)thunk;
164 call_thiscall_func3 = (void *)thunk;
165 call_thiscall_func5 = (void *)thunk;
168 #define call_func1(func,_this) call_thiscall_func1(func,_this)
169 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
170 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
171 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
172 (const void*)(c), (const void *)(d))
176 #define init_thiscall_thunk()
177 #define call_func1(func,_this) func(_this)
178 #define call_func2(func,_this,a) func(_this,a)
179 #define call_func3(func,_this,a,b) func(_this,a,b)
180 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
182 #endif /* __i386__ */
184 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
185 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
186 static BOOL init(void)
188 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
189 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
190 if(!msvcr || !msvcp) {
191 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
195 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
196 p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
197 p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
198 p_free = (void*)GetProcAddress(msvcr, "free");
199 if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free) {
200 win_skip("Error setting tests environment\n");
204 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
206 SET(p_wctype, "wctype");
207 SET(p__Getctype, "_Getctype");
208 SET(p__Getcoll, "_Getcoll");
209 SET(p_wctrans, "wctrans");
210 SET(p_towctrans, "towctrans");
211 SET(basic_ostringstream_char_vbtable, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
212 if(sizeof(void*) == 8) { /* 64-bit initialization */
213 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
214 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
215 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");
217 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
218 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
219 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");
221 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");
223 SET(p_char_address, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
224 SET(p_char_ctor, "??0?$allocator@D@std@@QEAA@XZ");
225 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
226 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
227 SET(p_char_construct, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
228 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QEBA_KXZ");
230 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QEAA@_K@Z");
231 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
232 SET(p_collate_char_dtor, "??1?$collate@D@std@@MEAA@XZ");
233 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QEAAXXZ");
234 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
235 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MEAA@XZ");
236 SET(p_basic_string_char_dtor,
237 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
238 SET(p_basic_string_char_cstr,
239 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
241 SET(p_basic_ostringstream_char_ctor_mode,
242 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
243 SET(p_basic_ostringstream_char_dtor,
244 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
245 SET(p_basic_ostringstream_char_vbase_dtor,
246 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
247 SET(p_basic_ios_char_dtor,
248 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UEAA@XZ");
250 SET(p_complex_float_ctor,
251 "??0?$complex@M@std@@QEAA@AEBM0@Z");
252 SET(p_complex_float_add,
253 "??$?HM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
254 SET(p_complex_float_div,
255 "??$?KM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
256 SET(p_complex_float__Fabs,
257 "??$_Fabs@M@std@@YAMAEBV?$complex@M@0@PEAH@Z");
258 SET(p_complex_float_tan,
259 "??$tan@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
260 SET(p_complex_float_tanh,
261 "??$tanh@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
262 SET(p_complex_float_log10,
263 "??$log10@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
264 SET(p_complex_float_sqrt,
265 "??$sqrt@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
267 SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
268 SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
269 SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
271 SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
272 SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
273 SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");
275 SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");
277 SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
278 SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
279 SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
280 SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
281 SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
282 SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");
284 SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
285 SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
286 SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
287 SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
288 SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
289 SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
290 SET(p_basic_string_char_dtor,
291 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
292 SET(p_basic_string_char_cstr,
293 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
295 SET(p_basic_ostringstream_char_ctor_mode,
296 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
297 SET(p_basic_ostringstream_char_dtor,
298 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
299 SET(p_basic_ostringstream_char_vbase_dtor,
300 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
301 SET(p_basic_ios_char_dtor,
302 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ");
304 SET(p_complex_float_ctor,
305 "??0?$complex@M@std@@QAE@ABM0@Z");
306 SET(p_complex_float_add,
307 "??$?HM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
308 SET(p_complex_float_div,
309 "??$?KM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
310 SET(p_complex_float__Fabs,
311 "??$_Fabs@M@std@@YAMABV?$complex@M@0@PAH@Z");
312 SET(p_complex_float_tan,
313 "??$tan@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
314 SET(p_complex_float_tanh,
315 "??$tanh@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
316 SET(p_complex_float_log10,
317 "??$log10@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
318 SET(p_complex_float_sqrt,
319 "??$sqrt@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
322 init_thiscall_thunk();
326 static void test_assign(void)
328 const char in[] = "abc";
332 p_char_assign(out, in);
333 ok(out[0] == in[0], "out[0] = %c\n", out[0]);
334 ok(out[1] == '#', "out[1] = %c\n", out[1]);
337 p_wchar_assign(out, in);
338 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
339 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
340 ok(out[2] == '#', "out[2] = %c\n", out[2]);
343 p_short_assign(out, in);
344 ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
345 "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
346 ok(out[2] == '#', "out[2] = %c\n", out[2]);
349 static void test_equal(void)
351 static const char in1[] = "abc";
352 static const char in2[] = "ab";
353 static const char in3[] = "a";
354 static const char in4[] = "b";
357 ret = p_char_eq(in1, in2);
358 ok(ret == TRUE, "ret = %d\n", (int)ret);
359 ret = p_char_eq(in1, in3);
360 ok(ret == TRUE, "ret = %d\n", (int)ret);
361 ret = p_char_eq(in1, in4);
362 ok(ret == FALSE, "ret = %d\n", (int)ret);
364 ret = p_wchar_eq(in1, in2);
365 ok(ret == TRUE, "ret = %d\n", (int)ret);
366 ret = p_wchar_eq(in1, in3);
367 ok(ret == FALSE, "ret = %d\n", (int)ret);
368 ret = p_wchar_eq(in1, in4);
369 ok(ret == FALSE, "ret = %d\n", (int)ret);
371 ret = p_short_eq(in1, in2);
372 ok(ret == TRUE, "ret = %d\n", (int)ret);
373 ret = p_short_eq(in1, in3);
374 ok(ret == FALSE, "ret = %d\n", (int)ret);
375 ret = p_short_eq(in1, in4);
376 ok(ret == FALSE, "ret = %d\n", (int)ret);
379 static void test_Copy_s(void)
381 static const char src[] = "abcd";
386 ret = p_Copy_s(dest, 4, src, 4);
387 ok(ret == dest, "ret != dest\n");
388 ok(dest[4] == '#', "dest[4] != '#'\n");
389 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
391 ret = p_Copy_s(dest, 32, src, 4);
392 ok(ret == dest, "ret != dest\n");
393 ok(dest[4] == '#', "dest[4] != '#'\n");
394 ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
398 ret = p_Copy_s(dest, 3, src, 4);
399 ok(ret == dest, "ret != dest\n");
400 ok(dest[0] == '\0', "dest[0] != 0\n");
401 ok(invalid_parameter==1, "invalid_parameter = %d\n",
403 invalid_parameter = 0;
404 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
407 p_Copy_s(NULL, 32, src, 4);
408 ok(invalid_parameter==1, "invalid_parameter = %d\n",
410 invalid_parameter = 0;
411 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
414 p_Copy_s(dest, 32, NULL, 4);
415 ok(invalid_parameter==1, "invalid_parameter = %d\n",
417 invalid_parameter = 0;
418 ok(errno == 0xdeadbeef, "errno = %d\n", errno);
421 static void test_wctype(void)
423 static const struct {
444 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++) {
445 ret = p_wctype(properties[i].name);
446 ok(properties[i].mask == ret, "%d - Expected %x, got %x\n", i, properties[i].mask, ret);
450 static void test__Getctype(void)
455 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
456 ok(ret.handle == 0, "ret.handle = %d\n", ret.handle);
457 ok(ret.page == 0, "ret.page = %d\n", ret.page);
458 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
459 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
462 locale = p__get_current_locale();
463 locale->locinfo->lc_handle[LC_COLLATE] = 0x1234567;
464 p__free_locale(locale);
465 ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
466 ok(ret.handle == 0x1234567, "ret.handle = %d\n", ret.handle);
467 ok(ret.page == 0, "ret.page = %d\n", ret.page);
468 ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
469 ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
473 static void test__Getcoll(void)
475 ULONGLONG (__cdecl *p__Getcoll_arg)(MSVCP__Collvec*);
479 MSVCP__Collvec collvec;
483 locale = p__get_current_locale();
484 locale->locinfo->lc_handle[LC_COLLATE] = 0x7654321;
485 p__free_locale(locale);
487 p__Getcoll_arg = (void*)p__Getcoll;
488 p__Getcoll_arg(&ret.collvec);
489 ok(ret.collvec.handle == 0, "ret.handle = %x\n", ret.collvec.handle);
490 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
492 ret.ull = p__Getcoll();
493 ok(ret.collvec.handle == 0x7654321, "ret.collvec.handle = %x\n", ret.collvec.handle);
494 ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
497 static void test_towctrans(void)
501 ret = p_wctrans("tolower");
502 ok(ret == 2, "wctrans returned %d, expected 2\n", ret);
503 ret = p_wctrans("toupper");
504 ok(ret == 1, "wctrans returned %d, expected 1\n", ret);
505 ret = p_wctrans("toLower");
506 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
508 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
509 if(0) { /* crashes on windows */
510 ret = p_wctrans(NULL);
511 ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
514 ret = p_towctrans('t', 2);
515 ok(ret == 't', "towctrans('t', 2) returned %c, expected t\n", ret);
516 ret = p_towctrans('T', 2);
517 ok(ret == 't', "towctrans('T', 2) returned %c, expected t\n", ret);
518 ret = p_towctrans('T', 0);
519 ok(ret == 't', "towctrans('T', 0) returned %c, expected t\n", ret);
520 ret = p_towctrans('T', 3);
521 ok(ret == 't', "towctrans('T', 3) returned %c, expected t\n", ret);
522 ret = p_towctrans('t', 1);
523 ok(ret == 'T', "towctrans('t', 1) returned %c, expected T\n", ret);
524 ret = p_towctrans('T', 1);
525 ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret);
528 static void test_allocator_char(void)
530 void *allocator = (void*)0xdeadbeef;
535 allocator = call_func1(p_char_ctor, allocator);
536 ok(allocator == (void*)0xdeadbeef, "allocator = %p\n", allocator);
538 ptr = call_func2(p_char_address, NULL, (void*)0xdeadbeef);
539 ok(ptr == (void*)0xdeadbeef, "incorrect address (%p)\n", ptr);
542 ptr = call_func2(p_char_allocate, allocator, 10);
543 ok(ptr != NULL, "Memory allocation failed\n");
545 ptr[0] = ptr[1] = '#';
547 call_func3(p_char_construct, allocator, ptr, &val);
549 call_func3(p_char_construct, allocator, (ptr+1), &val);
550 ok(ptr[0] == 'a', "ptr[0] = %c\n", ptr[0]);
551 ok(ptr[1] == 'b', "ptr[1] = %c\n", ptr[1]);
553 call_func3(p_char_deallocate, allocator, ptr, -1);
555 size = (unsigned int)call_func1(p_char_max_size, allocator);
556 ok(size == (unsigned int)0xffffffff, "size = %x\n", size);
559 static void test_virtual_call(void)
562 basic_string_char bstr;
565 char str1[] = "test";
566 char str2[] = "TEST";
569 locale = p__get_current_locale();
570 locale->locinfo->lc_handle[LC_COLLATE] = 1;
571 p__free_locale(locale);
572 call_func2(p_collate_char_ctor_refs, this, 0);
573 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+4, str1, str1+4);
574 ok(ret == 0, "collate<char>::compare returned %d\n", ret);
575 ret = (int)call_func5(p_collate_char_compare, this, str2, str2+4, str1, str1+4);
576 ok(ret == 1, "collate<char>::compare returned %d\n", ret);
577 ret = (int)call_func5(p_collate_char_compare, this, str1, str1+3, str1, str1+4);
578 ok(ret == -1, "collate<char>::compare returned %d\n", ret);
579 call_func1(p_collate_char_dtor, this);
581 call_func1(p_numpunct_char_ctor, this);
582 call_func2(p_numpunct_char_falsename, this, &bstr);
583 p = call_func1(p_basic_string_char_cstr, &bstr);
584 ok(!strcmp(p, "false"), "numpunct<char>::falsename returned %s\n", p);
585 call_func1(p_basic_string_char_dtor, &bstr);
586 call_func1(p_numpunct_char_dtor, this);
589 static void test_virtual_base_dtors(void)
593 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 1);
594 call_func1(p_basic_ostringstream_char_vbase_dtor, this);
596 /* this test uses vbtable set by earlier test */
597 call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 0);
598 call_func1(p_basic_ostringstream_char_dtor, this+basic_ostringstream_char_vbtable[1]);
599 call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
602 static BOOL almost_eq(float f1, float f2)
610 static void test_complex(void)
612 complex_float c1, c2, c3;
618 call_func3(p_complex_float_ctor, &c1, &f1, &f2);
619 ok(c1.real == 1, "c1.real = %f\n", c1.real);
620 ok(c1.imag == 2, "c1.imag = %f\n", c1.imag);
622 f1 = p_complex_float__Fabs(&c1, &scale);
623 ok(almost_eq(f1, 0.559017), "abs(1+2i) = %f\n", f1);
624 ok(scale == 2, "scale = %d\n", scale);
628 call_func3(p_complex_float_ctor, &c2, &f1, &f2);
629 ok(c2.real == -1, "c2.real = %f\n", c1.real);
630 ok(c2.imag == 1, "c2.imag = %f\n", c1.imag);
632 f1 = p_complex_float__Fabs(&c2, &scale);
633 ok(almost_eq(f1, 0.353553), "abs(1-1i) = %f\n", f1);
634 ok(scale == 2, "scale = %d\n", scale);
636 p_complex_float_add(&c3, &c1, &c2);
637 ok(c3.real == 0, "c3.real = %f\n", c3.real);
638 ok(c3.imag == 3, "c3.imag = %f\n", c3.imag);
640 f1 = p_complex_float__Fabs(&c3, &scale);
641 ok(almost_eq(f1, 0.75), "abs(0+3i) = %f\n", f1);
642 ok(scale == 2, "scale = %d\n", scale);
644 p_complex_float_add(&c2, &c1, &c3);
645 ok(c2.real == 1, "c2.real = %f\n", c1.real);
646 ok(c2.imag == 5, "c2.imag = %f\n", c1.imag);
648 f1 = p_complex_float__Fabs(&c3, &scale);
649 ok(almost_eq(f1, 0.75), "abs(1+5i) = %f\n", f1);
650 ok(scale == 2, "scale = %d\n", scale);
652 /* (1+5i) / (0+3i) */
653 p_complex_float_div(&c1, &c2, &c3);
654 ok(almost_eq(c1.real, 1.666667), "c1.real = %f\n", c1.real);
655 ok(almost_eq(c1.imag, -0.33333), "c1.imag = %f\n", c1.imag);
657 /* (1+5i) / (2+0i) */
660 p_complex_float_div(&c1, &c2, &c3);
661 ok(almost_eq(c1.real, 0.5), "c1.real = %f\n", c1.real);
662 ok(almost_eq(c1.imag, 2.5), "c1.imag = %f\n", c1.imag);
664 f1 = p_complex_float__Fabs(&c1, &scale);
665 ok(almost_eq(f1, 0.637377), "abs(0.5+2.5i) = %f\n", f1);
666 ok(scale == 2, "scale = %d\n", scale);
670 p_complex_float_div(&c1, &c2, &c3);
671 ok(_isnan(c1.real), "c1.real = %f\n", c1.real);
672 ok(_isnan(c1.imag), "c1.imag = %f\n", c1.imag);
674 f1 = p_complex_float__Fabs(&c1, &scale);
675 ok(_isnan(f1), "abs(NaN+NaNi) = %f\n", f1);
676 ok(scale == 0, "scale = %d\n", scale);
678 /* (1+5i) / (NaN-2i) */
680 p_complex_float_div(&c3, &c2, &c1);
681 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
682 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
684 /* (NaN-2i) / (1+0i) */
686 p_complex_float_div(&c3, &c1, &c2);
687 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
688 ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);
690 /* (1+0i) + (NaN-2i) */
691 p_complex_float_add(&c3, &c2, &c1);
692 ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
693 ok(c3.imag == -2, "c3.imag = %f\n", c3.imag);
695 f1 = p_complex_float__Fabs(&c3, &scale);
696 ok(_isnan(f1), "abs(NaN-2i) = %f\n", f1);
697 ok(scale == 0, "scale = %d\n", scale);
700 f1 = p_complex_float__Fabs(&c3, &scale);
701 ok(almost_eq(f1, 250.000504), "abs(1000-2i) = %f\n", f1);
702 ok(scale == 2, "scale = %d\n", scale);
706 f1 = p_complex_float__Fabs(&c3, &scale);
707 ok(almost_eq(f1, 0.565685), "abs(0.1+0.1i) = %f\n", f1);
708 ok(scale == -2, "scale = %d\n", scale);
712 f1 = p_complex_float__Fabs(&c3, &scale);
713 ok(almost_eq(f1, 0.25), "abs(1+0i) = %f\n", f1);
714 ok(scale == 2, "scale = %d\n", scale);
718 f1 = p_complex_float__Fabs(&c3, &scale);
719 ok(almost_eq(f1, 3.96), "abs(0.99+0i) = %f\n", f1);
720 ok(scale == -2, "scale = %d\n", scale);
724 f1 = p_complex_float__Fabs(&c3, &scale);
725 ok(f1 == 0, "abs(0+0i) = %f\n", f1);
726 ok(scale == 0, "scale = %d\n", scale);
730 p_complex_float_tan(&c2, &c1);
731 ok(c2.real == 0, "c2.real = %f\n", c2.real);
732 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
733 p_complex_float_tanh(&c2, &c1);
734 ok(c2.real == 0, "c2.real = %f\n", c2.real);
735 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
736 p_complex_float_log10(&c2, &c1);
737 ok(c2.real < -FLT_MAX /* c2.real == -inf */, "c2.real = %f\n", c2.real);
738 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
739 p_complex_float_sqrt(&c2, &c1);
740 ok(c2.real == 0, "c2.real = %f\n", c2.real);
741 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
745 p_complex_float_tan(&c2, &c1);
746 ok(almost_eq(c2.real, 788906.062500), "c2.real = %f\n", c2.real);
747 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
748 p_complex_float_tanh(&c2, &c1);
749 ok(almost_eq(c2.real, 0.917152), "c2.real = %f\n", c2.real);
750 ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
751 p_complex_float_log10(&c2, &c1);
752 ok(almost_eq(c2.real, 0.196120), "c2.real = %f\n", c2.real);
753 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
754 p_complex_float_sqrt(&c2, &c1);
755 ok(almost_eq(c2.real, 1.253314), "c2.real = %f\n", c2.real);
756 ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
760 p_complex_float_tan(&c2, &c1);
761 ok(almost_eq(c2.real, 1.040818), "c2.real = %f\n", c2.real);
762 ok(almost_eq(c2.imag, 0.362651), "c2.imag = %f\n", c2.imag);
763 p_complex_float_tanh(&c2, &c1);
764 ok(almost_eq(c2.real, 0.999999), "c2.real = %f\n", c2.real);
765 ok(almost_eq(c2.imag, 4.3627e-7), "c2.imag = %g\n", c2.imag);
766 p_complex_float_log10(&c2, &c1);
767 ok(almost_eq(c2.real, 0.852604), "c2.real = %f\n", c2.real);
768 ok(almost_eq(c2.imag, 0.0103674), "c2.imag = %g\n", c2.imag);
769 p_complex_float_sqrt(&c2, &c1);
770 ok(almost_eq(c2.real, 2.668523), "c2.real = %f\n", c2.real);
771 ok(almost_eq(c2.imag, 0.0318528), "c2.imag = %g\n", c2.imag);
775 p_complex_float_tan(&c2, &c1);
776 ok(almost_eq(c2.real, 0.135859), "c2.real = %f\n", c2.real);
777 ok(almost_eq(c2.imag, 0.191341), "c2.imag = %f\n", c2.imag);
778 p_complex_float_tanh(&c2, &c1);
779 ok(almost_eq(c2.real, 0.144134), "c2.real = %f\n", c2.real);
780 ok(almost_eq(c2.imag, 0.188464), "c2.imag = %f\n", c2.imag);
781 p_complex_float_log10(&c2, &c1);
782 ok(almost_eq(c2.real, -0.627072), "c2.real = %f\n", c2.real);
783 ok(almost_eq(c2.imag, 0.4064), "c2.imag = %g\n", c2.imag);
784 p_complex_float_sqrt(&c2, &c1);
785 ok(almost_eq(c2.real, 0.433595), "c2.real = %f\n", c2.real);
786 ok(almost_eq(c2.imag, 0.219099), "c2.imag = %g\n", c2.imag);
802 test_virtual_base_dtors();
803 test_allocator_char();
806 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");