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
24 #include "wine/test.h"
38 /* basic_string<char, char_traits<char>, allocator<char>> */
39 #define BUF_SIZE_CHAR 16
44 char buf
[BUF_SIZE_CHAR
];
51 static void* (__cdecl
*p_set_invalid_parameter_handler
)(void*);
52 static _locale_t (__cdecl
*p__get_current_locale
)(void);
53 static void (__cdecl
*p_free
)(void*);
55 static void (__cdecl
*p_char_assign
)(void*, const void*);
56 static void (__cdecl
*p_wchar_assign
)(void*, const void*);
57 static void (__cdecl
*p_short_assign
)(void*, const void*);
59 static BYTE (__cdecl
*p_char_eq
)(const void*, const void*);
60 static BYTE (__cdecl
*p_wchar_eq
)(const void*, const void*);
61 static BYTE (__cdecl
*p_short_eq
)(const void*, const void*);
63 static char* (__cdecl
*p_Copy_s
)(char*, size_t, const char*, size_t);
65 static unsigned short (__cdecl
*p_wctype
)(const char*);
66 static MSVCP__Ctypevec
* (__cdecl
*p__Getctype
)(MSVCP__Ctypevec
*);
67 static /*MSVCP__Collvec*/ULONGLONG (__cdecl
*p__Getcoll
)(void);
71 #define __thiscall __stdcall
73 #define __thiscall __cdecl
76 static char* (__thiscall
*p_char_address
)(void*, char*);
77 static void* (__thiscall
*p_char_ctor
)(void*);
78 static void (__thiscall
*p_char_deallocate
)(void*, char*, size_t);
79 static char* (__thiscall
*p_char_allocate
)(void*, size_t);
80 static void (__thiscall
*p_char_construct
)(void*, char*, const char*);
81 static size_t (__thiscall
*p_char_max_size
)(void*);
83 static void* (__thiscall
*p_collate_char_ctor_refs
)(void*, size_t);
84 static int (__thiscall
*p_collate_char_compare
)(const void*, const char*,
85 const char*, const char*, const char*);
86 static void (__thiscall
*p_collate_char_dtor
)(void*);
87 static void* (__thiscall
*p_numpunct_char_ctor
)(void*);
88 static basic_string_char
* (__thiscall
*p_numpunct_char_falsename
)(void*,basic_string_char
*);
89 static void (__thiscall
*p_numpunct_char_dtor
)(void*);
90 static void (__thiscall
*p_basic_string_char_dtor
)(basic_string_char
*);
91 static const char* (__thiscall
*p_basic_string_char_cstr
)(basic_string_char
*);
93 static const int *basic_ostringstream_char_vbtable
;
94 static /*basic_ostringstream_char*/void* (__thiscall
*p_basic_ostringstream_char_ctor_mode
)(
95 /*basic_ostringstream_char*/void*, int, /*MSVCP_bool*/int);
96 static void (__thiscall
*p_basic_ostringstream_char_dtor
)(/*basic_ostringstream_char*/void*);
97 static void (__thiscall
*p_basic_ostringstream_char_vbase_dtor
)(/*basic_ostringstream_char*/void*);
99 static int invalid_parameter
= 0;
100 static void __cdecl
test_invalid_parameter_handler(const wchar_t *expression
,
101 const wchar_t *function
, const wchar_t *file
,
102 unsigned line
, uintptr_t arg
)
104 ok(expression
== NULL
, "expression is not NULL\n");
105 ok(function
== NULL
, "function is not NULL\n");
106 ok(file
== NULL
, "file is not NULL\n");
107 ok(line
== 0, "line = %u\n", line
);
108 ok(arg
== 0, "arg = %lx\n", (UINT_PTR
)arg
);
112 /* Emulate a __thiscall */
115 #include "pshpack1.h"
116 struct thiscall_thunk
118 BYTE pop_eax
; /* popl %eax (ret addr) */
119 BYTE pop_edx
; /* popl %edx (func) */
120 BYTE pop_ecx
; /* popl %ecx (this) */
121 BYTE push_eax
; /* pushl %eax */
122 WORD jmp_edx
; /* jmp *%edx */
126 static void * (WINAPI
*call_thiscall_func1
)( void *func
, void *this );
127 static void * (WINAPI
*call_thiscall_func2
)( void *func
, void *this, const void *a
);
128 static void * (WINAPI
*call_thiscall_func3
)( void *func
, void *this, const void *a
, const void *b
);
129 static void * (WINAPI
*call_thiscall_func5
)( void *func
, void *this, const void *a
, const void *b
,
130 const void *c
, const void *d
);
131 struct thiscall_thunk_retptr
*thunk_retptr
;
133 static void init_thiscall_thunk(void)
135 struct thiscall_thunk
*thunk
= VirtualAlloc( NULL
, sizeof(*thunk
),
136 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
137 thunk
->pop_eax
= 0x58; /* popl %eax */
138 thunk
->pop_edx
= 0x5a; /* popl %edx */
139 thunk
->pop_ecx
= 0x59; /* popl %ecx */
140 thunk
->push_eax
= 0x50; /* pushl %eax */
141 thunk
->jmp_edx
= 0xe2ff; /* jmp *%edx */
142 call_thiscall_func1
= (void *)thunk
;
143 call_thiscall_func2
= (void *)thunk
;
144 call_thiscall_func3
= (void *)thunk
;
145 call_thiscall_func5
= (void *)thunk
;
148 #define call_func1(func,_this) call_thiscall_func1(func,_this)
149 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
150 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
151 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
152 (const void*)(c), (const void *)(d))
156 #define init_thiscall_thunk()
157 #define call_func1(func,_this) func(_this)
158 #define call_func2(func,_this,a) func(_this,a)
159 #define call_func3(func,_this,a,b) func(_this,a,b)
160 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
162 #endif /* __i386__ */
164 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
165 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
166 static BOOL
init(void)
168 HMODULE msvcr
= LoadLibraryA("msvcr90.dll");
169 HMODULE msvcp
= LoadLibraryA("msvcp90.dll");
170 if(!msvcr
|| !msvcp
) {
171 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
175 p_set_invalid_parameter_handler
= (void*)GetProcAddress(msvcr
, "_set_invalid_parameter_handler");
176 p__get_current_locale
= (void*)GetProcAddress(msvcr
, "_get_current_locale");
177 p_free
= (void*)GetProcAddress(msvcr
, "free");
178 if(!p_set_invalid_parameter_handler
|| !p__get_current_locale
|| !p_free
) {
179 win_skip("Error setting tests environment\n");
183 p_set_invalid_parameter_handler(test_invalid_parameter_handler
);
185 SET(p_wctype
, "wctype");
186 SET(p__Getctype
, "_Getctype");
187 SET(p__Getcoll
, "_Getcoll");
188 SET(basic_ostringstream_char_vbtable
, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
189 if(sizeof(void*) == 8) { /* 64-bit initialization */
190 SET(p_char_assign
, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
191 SET(p_wchar_assign
, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
192 SET(p_short_assign
, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");
194 SET(p_char_eq
, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
195 SET(p_wchar_eq
, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
196 SET(p_short_eq
, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");
198 SET(p_Copy_s
, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");
200 SET(p_char_address
, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
201 SET(p_char_ctor
, "??0?$allocator@D@std@@QEAA@XZ");
202 SET(p_char_deallocate
, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
203 SET(p_char_allocate
, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
204 SET(p_char_construct
, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
205 SET(p_char_max_size
, "?max_size@?$allocator@D@std@@QEBA_KXZ");
207 SET(p_collate_char_ctor_refs
, "??0?$collate@D@std@@QEAA@_K@Z");
208 SET(p_collate_char_compare
, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
209 SET(p_collate_char_dtor
, "??1?$collate@D@std@@MEAA@XZ");
210 SET(p_numpunct_char_ctor
, "??_F?$numpunct@D@std@@QEAAXXZ");
211 SET(p_numpunct_char_falsename
, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
212 SET(p_numpunct_char_dtor
, "??1?$numpunct@D@std@@MEAA@XZ");
213 SET(p_basic_string_char_dtor
,
214 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
215 SET(p_basic_string_char_cstr
,
216 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
218 SET(p_basic_ostringstream_char_ctor_mode
,
219 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
220 SET(p_basic_ostringstream_char_dtor
,
221 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
222 SET(p_basic_ostringstream_char_vbase_dtor
,
223 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
225 SET(p_char_assign
, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
226 SET(p_wchar_assign
, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
227 SET(p_short_assign
, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
229 SET(p_char_eq
, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
230 SET(p_wchar_eq
, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
231 SET(p_short_eq
, "?eq@?$char_traits@G@std@@SA_NABG0@Z");
233 SET(p_Copy_s
, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");
235 SET(p_char_address
, "?address@?$allocator@D@std@@QBEPADAAD@Z");
236 SET(p_char_ctor
, "??0?$allocator@D@std@@QAE@XZ");
237 SET(p_char_deallocate
, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
238 SET(p_char_allocate
, "?allocate@?$allocator@D@std@@QAEPADI@Z");
239 SET(p_char_construct
, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
240 SET(p_char_max_size
, "?max_size@?$allocator@D@std@@QBEIXZ");
242 SET(p_collate_char_ctor_refs
, "??0?$collate@D@std@@QAE@I@Z");
243 SET(p_collate_char_compare
, "?compare@?$collate@D@std@@QBEHPBD000@Z");
244 SET(p_collate_char_dtor
, "??1?$collate@D@std@@MAE@XZ");
245 SET(p_numpunct_char_ctor
, "??_F?$numpunct@D@std@@QAEXXZ");
246 SET(p_numpunct_char_falsename
, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
247 SET(p_numpunct_char_dtor
, "??1?$numpunct@D@std@@MAE@XZ");
248 SET(p_basic_string_char_dtor
,
249 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
250 SET(p_basic_string_char_cstr
,
251 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
253 SET(p_basic_ostringstream_char_ctor_mode
,
254 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
255 SET(p_basic_ostringstream_char_dtor
,
256 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
257 SET(p_basic_ostringstream_char_vbase_dtor
,
258 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
261 init_thiscall_thunk();
265 static void test_assign(void)
267 const char in
[] = "abc";
271 p_char_assign(out
, in
);
272 ok(out
[0] == in
[0], "out[0] = %c\n", out
[0]);
273 ok(out
[1] == '#', "out[1] = %c\n", out
[1]);
276 p_wchar_assign(out
, in
);
277 ok(*((char*)out
)==in
[0] && *((char*)out
+1)==in
[1],
278 "out[0] = %d, out[1] = %d\n", (int)out
[0], (int)out
[1]);
279 ok(out
[2] == '#', "out[2] = %c\n", out
[2]);
282 p_short_assign(out
, in
);
283 ok(*((char*)out
)==in
[0] && *((char*)out
+1)==in
[1],
284 "out[0] = %d, out[1] = %d\n", (int)out
[0], (int)out
[1]);
285 ok(out
[2] == '#', "out[2] = %c\n", out
[2]);
288 static void test_equal(void)
290 static const char in1
[] = "abc";
291 static const char in2
[] = "ab";
292 static const char in3
[] = "a";
293 static const char in4
[] = "b";
296 ret
= p_char_eq(in1
, in2
);
297 ok(ret
== TRUE
, "ret = %d\n", (int)ret
);
298 ret
= p_char_eq(in1
, in3
);
299 ok(ret
== TRUE
, "ret = %d\n", (int)ret
);
300 ret
= p_char_eq(in1
, in4
);
301 ok(ret
== FALSE
, "ret = %d\n", (int)ret
);
303 ret
= p_wchar_eq(in1
, in2
);
304 ok(ret
== TRUE
, "ret = %d\n", (int)ret
);
305 ret
= p_wchar_eq(in1
, in3
);
306 ok(ret
== FALSE
, "ret = %d\n", (int)ret
);
307 ret
= p_wchar_eq(in1
, in4
);
308 ok(ret
== FALSE
, "ret = %d\n", (int)ret
);
310 ret
= p_short_eq(in1
, in2
);
311 ok(ret
== TRUE
, "ret = %d\n", (int)ret
);
312 ret
= p_short_eq(in1
, in3
);
313 ok(ret
== FALSE
, "ret = %d\n", (int)ret
);
314 ret
= p_short_eq(in1
, in4
);
315 ok(ret
== FALSE
, "ret = %d\n", (int)ret
);
318 static void test_Copy_s(void)
320 static const char src
[] = "abcd";
325 ret
= p_Copy_s(dest
, 4, src
, 4);
326 ok(ret
== dest
, "ret != dest\n");
327 ok(dest
[4] == '#', "dest[4] != '#'\n");
328 ok(!memcmp(dest
, src
, sizeof(char[4])), "dest = %s\n", dest
);
330 ret
= p_Copy_s(dest
, 32, src
, 4);
331 ok(ret
== dest
, "ret != dest\n");
332 ok(dest
[4] == '#', "dest[4] != '#'\n");
333 ok(!memcmp(dest
, src
, sizeof(char[4])), "dest = %s\n", dest
);
337 ret
= p_Copy_s(dest
, 3, src
, 4);
338 ok(ret
== dest
, "ret != dest\n");
339 ok(dest
[0] == '\0', "dest[0] != 0\n");
340 ok(invalid_parameter
==1, "invalid_parameter = %d\n",
342 invalid_parameter
= 0;
343 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
346 p_Copy_s(NULL
, 32, src
, 4);
347 ok(invalid_parameter
==1, "invalid_parameter = %d\n",
349 invalid_parameter
= 0;
350 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
353 p_Copy_s(dest
, 32, NULL
, 4);
354 ok(invalid_parameter
==1, "invalid_parameter = %d\n",
356 invalid_parameter
= 0;
357 ok(errno
== 0xdeadbeef, "errno = %d\n", errno
);
360 static void test_wctype(void)
362 static const struct {
383 for(i
=0; i
<sizeof(properties
)/sizeof(properties
[0]); i
++) {
384 ret
= p_wctype(properties
[i
].name
);
385 ok(properties
[i
].mask
== ret
, "%d - Expected %x, got %x\n", i
, properties
[i
].mask
, ret
);
389 static void test__Getctype(void)
393 ok(p__Getctype(&ret
) == &ret
, "__Getctype returned incorrect pointer\n");
394 ok(ret
.handle
== 0, "ret.handle = %d\n", ret
.handle
);
395 ok(ret
.page
== 0, "ret.page = %d\n", ret
.page
);
396 ok(ret
.delfl
== 1, "ret.delfl = %d\n", ret
.delfl
);
397 ok(ret
.table
[0] == 32, "ret.table[0] = %d\n", ret
.table
[0]);
400 p__get_current_locale()->locinfo
->lc_handle
[LC_COLLATE
] = 0x1234567;
401 ok(p__Getctype(&ret
) == &ret
, "__Getctype returned incorrect pointer\n");
402 ok(ret
.handle
== 0x1234567, "ret.handle = %d\n", ret
.handle
);
403 ok(ret
.page
== 0, "ret.page = %d\n", ret
.page
);
404 ok(ret
.delfl
== 1, "ret.delfl = %d\n", ret
.delfl
);
405 ok(ret
.table
[0] == 32, "ret.table[0] = %d\n", ret
.table
[0]);
409 static void test__Getcoll(void)
411 ULONGLONG (__cdecl
*p__Getcoll_arg
)(MSVCP__Collvec
*);
414 MSVCP__Collvec collvec
;
418 p__get_current_locale()->locinfo
->lc_handle
[LC_COLLATE
] = 0x7654321;
420 p__Getcoll_arg
= (void*)p__Getcoll
;
421 p__Getcoll_arg(&ret
.collvec
);
422 ok(ret
.collvec
.handle
== 0, "ret.handle = %x\n", ret
.collvec
.handle
);
423 ok(ret
.collvec
.page
== 0, "ret.page = %x\n", ret
.collvec
.page
);
425 ret
.ull
= p__Getcoll();
426 ok(ret
.collvec
.handle
== 0x7654321, "ret.collvec.handle = %x\n", ret
.collvec
.handle
);
427 ok(ret
.collvec
.page
== 0, "ret.page = %x\n", ret
.collvec
.page
);
430 static void test_allocator_char(void)
432 void *allocator
= (void*)0xdeadbeef;
437 allocator
= call_func1(p_char_ctor
, allocator
);
438 ok(allocator
== (void*)0xdeadbeef, "allocator = %p\n", allocator
);
440 ptr
= call_func2(p_char_address
, NULL
, (void*)0xdeadbeef);
441 ok(ptr
== (void*)0xdeadbeef, "incorrect address (%p)\n", ptr
);
444 ptr
= call_func2(p_char_allocate
, allocator
, 10);
445 ok(ptr
!= NULL
, "Memory allocation failed\n");
447 ptr
[0] = ptr
[1] = '#';
449 call_func3(p_char_construct
, allocator
, ptr
, &val
);
451 call_func3(p_char_construct
, allocator
, (ptr
+1), &val
);
452 ok(ptr
[0] == 'a', "ptr[0] = %c\n", ptr
[0]);
453 ok(ptr
[1] == 'b', "ptr[1] = %c\n", ptr
[1]);
455 call_func3(p_char_deallocate
, allocator
, ptr
, -1);
457 size
= (unsigned int)call_func1(p_char_max_size
, allocator
);
458 ok(size
== (unsigned int)0xffffffff, "size = %x\n", size
);
461 static void test_virtual_call(void)
464 basic_string_char bstr
;
466 char str1
[] = "test";
467 char str2
[] = "TEST";
470 p__get_current_locale()->locinfo
->lc_handle
[LC_COLLATE
] = 1;
471 call_func2(p_collate_char_ctor_refs
, this, 0);
472 ret
= (int)call_func5(p_collate_char_compare
, this, str1
, str1
+4, str1
, str1
+4);
473 ok(ret
== 0, "collate<char>::compare returned %d\n", ret
);
474 ret
= (int)call_func5(p_collate_char_compare
, this, str2
, str2
+4, str1
, str1
+4);
475 ok(ret
== 1, "collate<char>::compare returned %d\n", ret
);
476 ret
= (int)call_func5(p_collate_char_compare
, this, str1
, str1
+3, str1
, str1
+4);
477 ok(ret
== -1, "collate<char>::compare returned %d\n", ret
);
478 call_func1(p_collate_char_dtor
, this);
480 call_func1(p_numpunct_char_ctor
, this);
481 call_func2(p_numpunct_char_falsename
, this, &bstr
);
482 p
= call_func1(p_basic_string_char_cstr
, &bstr
);
483 ok(!strcmp(p
, "false"), "numpunct<char>::falsename returned %s\n", p
);
484 call_func1(p_basic_string_char_dtor
, &bstr
);
485 call_func1(p_numpunct_char_dtor
, this);
488 static void test_virtual_base_dtors(void)
492 call_func3(p_basic_ostringstream_char_ctor_mode
, this, 0, 1);
493 call_func1(p_basic_ostringstream_char_vbase_dtor
, this);
495 call_func3(p_basic_ostringstream_char_ctor_mode
, this, 0, 0);
496 call_func1(p_basic_ostringstream_char_dtor
, this+basic_ostringstream_char_vbtable
[1]);
511 test_virtual_base_dtors();
513 test_allocator_char();
515 ok(!invalid_parameter
, "invalid_parameter_handler was invoked too many times\n");