quartz: Remove unused variables.
[wine] / dlls / msvcp90 / tests / misc.c
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdio.h>
20 #include <locale.h>
21 #include <wctype.h>
22
23 #include <windef.h>
24 #include <winbase.h>
25 #include "wine/test.h"
26
27 typedef struct {
28     LCID handle;
29     unsigned page;
30     short *table;
31     int delfl;
32 } MSVCP__Ctypevec;
33
34 typedef struct {
35     LCID handle;
36     unsigned page;
37 } MSVCP__Collvec;
38
39 /* basic_string<char, char_traits<char>, allocator<char>> */
40 #define BUF_SIZE_CHAR 16
41 typedef struct
42 {
43     void *allocator;
44     union {
45         char buf[BUF_SIZE_CHAR];
46         char *ptr;
47     } data;
48     size_t size;
49     size_t res;
50 } basic_string_char;
51
52 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
53 static _locale_t (__cdecl *p__get_current_locale)(void);
54 static void (__cdecl *p__free_locale)(_locale_t);
55 static void  (__cdecl *p_free)(void*);
56
57 static void (__cdecl *p_char_assign)(void*, const void*);
58 static void (__cdecl *p_wchar_assign)(void*, const void*);
59 static void (__cdecl *p_short_assign)(void*, const void*);
60
61 static BYTE (__cdecl *p_char_eq)(const void*, const void*);
62 static BYTE (__cdecl *p_wchar_eq)(const void*, const void*);
63 static BYTE (__cdecl *p_short_eq)(const void*, const void*);
64
65 static char* (__cdecl *p_Copy_s)(char*, size_t, const char*, size_t);
66
67 static unsigned short (__cdecl *p_wctype)(const char*);
68 static MSVCP__Ctypevec* (__cdecl *p__Getctype)(MSVCP__Ctypevec*);
69 static /*MSVCP__Collvec*/ULONGLONG (__cdecl *p__Getcoll)(void);
70 static wctrans_t (__cdecl *p_wctrans)(const char*);
71 static wint_t (__cdecl *p_towctrans)(wint_t, wctrans_t);
72
73 #undef __thiscall
74 #ifdef __i386__
75 #define __thiscall __stdcall
76 #else
77 #define __thiscall __cdecl
78 #endif
79
80 static char* (__thiscall *p_char_address)(void*, char*);
81 static void* (__thiscall *p_char_ctor)(void*);
82 static void (__thiscall *p_char_deallocate)(void*, char*, size_t);
83 static char* (__thiscall *p_char_allocate)(void*, size_t);
84 static void (__thiscall *p_char_construct)(void*, char*, const char*);
85 static size_t (__thiscall *p_char_max_size)(void*);
86
87 static void* (__thiscall *p_collate_char_ctor_refs)(void*, size_t);
88 static int (__thiscall *p_collate_char_compare)(const void*, const char*,
89         const char*, const char*, const char*);
90 static void (__thiscall *p_collate_char_dtor)(void*);
91 static void* (__thiscall *p_numpunct_char_ctor)(void*);
92 static basic_string_char* (__thiscall *p_numpunct_char_falsename)(void*,basic_string_char*);
93 static void (__thiscall *p_numpunct_char_dtor)(void*);
94 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
95 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
96
97 static const int *basic_ostringstream_char_vbtable;
98 static /*basic_ostringstream_char*/void* (__thiscall *p_basic_ostringstream_char_ctor_mode)(
99         /*basic_ostringstream_char*/void*, int, /*MSVCP_bool*/int);
100 static void (__thiscall *p_basic_ostringstream_char_dtor)(/*basic_ostringstream_char*/void*);
101 static void (__thiscall *p_basic_ostringstream_char_vbase_dtor)(/*basic_ostringstream_char*/void*);
102 static void (__thiscall *p_basic_ios_char_dtor)(/*basic_ios_char*/void*);
103
104 static int invalid_parameter = 0;
105 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
106         const wchar_t *function, const wchar_t *file,
107         unsigned line, uintptr_t arg)
108 {
109     ok(expression == NULL, "expression is not NULL\n");
110     ok(function == NULL, "function is not NULL\n");
111     ok(file == NULL, "file is not NULL\n");
112     ok(line == 0, "line = %u\n", line);
113     ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
114     invalid_parameter++;
115 }
116
117 /* Emulate a __thiscall */
118 #ifdef __i386__
119
120 #include "pshpack1.h"
121 struct thiscall_thunk
122 {
123     BYTE pop_eax;    /* popl  %eax (ret addr) */
124     BYTE pop_edx;    /* popl  %edx (func) */
125     BYTE pop_ecx;    /* popl  %ecx (this) */
126     BYTE push_eax;   /* pushl %eax */
127     WORD jmp_edx;    /* jmp  *%edx */
128 };
129 #include "poppack.h"
130
131 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
132 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
133 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
134 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
135         const void *c, const void *d );
136 struct thiscall_thunk_retptr *thunk_retptr;
137
138 static void init_thiscall_thunk(void)
139 {
140     struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
141                                                  MEM_COMMIT, PAGE_EXECUTE_READWRITE );
142     thunk->pop_eax  = 0x58;   /* popl  %eax */
143     thunk->pop_edx  = 0x5a;   /* popl  %edx */
144     thunk->pop_ecx  = 0x59;   /* popl  %ecx */
145     thunk->push_eax = 0x50;   /* pushl %eax */
146     thunk->jmp_edx  = 0xe2ff; /* jmp  *%edx */
147     call_thiscall_func1 = (void *)thunk;
148     call_thiscall_func2 = (void *)thunk;
149     call_thiscall_func3 = (void *)thunk;
150     call_thiscall_func5 = (void *)thunk;
151 }
152
153 #define call_func1(func,_this) call_thiscall_func1(func,_this)
154 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
155 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
156 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
157         (const void*)(c), (const void *)(d))
158
159 #else
160
161 #define init_thiscall_thunk()
162 #define call_func1(func,_this) func(_this)
163 #define call_func2(func,_this,a) func(_this,a)
164 #define call_func3(func,_this,a,b) func(_this,a,b)
165 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
166
167 #endif /* __i386__ */
168
169 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
170 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
171 static BOOL init(void)
172 {
173     HMODULE msvcr = LoadLibraryA("msvcr90.dll");
174     HMODULE msvcp = LoadLibraryA("msvcp90.dll");
175     if(!msvcr || !msvcp) {
176         win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
177         return FALSE;
178     }
179
180     p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
181     p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
182     p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
183     p_free = (void*)GetProcAddress(msvcr, "free");
184     if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free) {
185         win_skip("Error setting tests environment\n");
186         return FALSE;
187     }
188
189     p_set_invalid_parameter_handler(test_invalid_parameter_handler);
190
191     SET(p_wctype, "wctype");
192     SET(p__Getctype, "_Getctype");
193     SET(p__Getcoll, "_Getcoll");
194     SET(p_wctrans, "wctrans");
195     SET(p_towctrans, "towctrans");
196     SET(basic_ostringstream_char_vbtable, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
197     if(sizeof(void*) == 8) { /* 64-bit initialization */
198         SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
199         SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
200         SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");
201
202         SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
203         SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
204         SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");
205
206         SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");
207
208         SET(p_char_address, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
209         SET(p_char_ctor, "??0?$allocator@D@std@@QEAA@XZ");
210         SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
211         SET(p_char_allocate, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
212         SET(p_char_construct, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
213         SET(p_char_max_size, "?max_size@?$allocator@D@std@@QEBA_KXZ");
214
215         SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QEAA@_K@Z");
216         SET(p_collate_char_compare, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
217         SET(p_collate_char_dtor, "??1?$collate@D@std@@MEAA@XZ");
218         SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QEAAXXZ");
219         SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
220         SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MEAA@XZ");
221         SET(p_basic_string_char_dtor,
222                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
223         SET(p_basic_string_char_cstr,
224                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
225
226         SET(p_basic_ostringstream_char_ctor_mode,
227                 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
228         SET(p_basic_ostringstream_char_dtor,
229                 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
230         SET(p_basic_ostringstream_char_vbase_dtor,
231                 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
232         SET(p_basic_ios_char_dtor,
233                 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UEAA@XZ");
234     } else {
235         SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
236         SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
237         SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
238
239         SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
240         SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
241         SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");
242
243         SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");
244
245         SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
246         SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
247         SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
248         SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
249         SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
250         SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");
251
252         SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
253         SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
254         SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
255         SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
256         SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
257         SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
258         SET(p_basic_string_char_dtor,
259                 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
260         SET(p_basic_string_char_cstr,
261                 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
262
263         SET(p_basic_ostringstream_char_ctor_mode,
264                 "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
265         SET(p_basic_ostringstream_char_dtor,
266                 "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
267         SET(p_basic_ostringstream_char_vbase_dtor,
268                 "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
269         SET(p_basic_ios_char_dtor,
270                 "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ");
271     }
272
273     init_thiscall_thunk();
274     return TRUE;
275 }
276
277 static void test_assign(void)
278 {
279     const char in[] = "abc";
280     char out[4];
281
282     out[1] = '#';
283     p_char_assign(out, in);
284     ok(out[0] == in[0], "out[0] = %c\n", out[0]);
285     ok(out[1] == '#', "out[1] = %c\n", out[1]);
286
287     out[2] = '#';
288     p_wchar_assign(out, in);
289     ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
290             "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
291     ok(out[2] == '#', "out[2] = %c\n", out[2]);
292
293     out[2] = '#';
294     p_short_assign(out, in);
295     ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
296             "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
297     ok(out[2] == '#', "out[2] = %c\n", out[2]);
298 }
299
300 static void test_equal(void)
301 {
302     static const char in1[] = "abc";
303     static const char in2[] = "ab";
304     static const char in3[] = "a";
305     static const char in4[] = "b";
306     BYTE ret;
307
308     ret = p_char_eq(in1, in2);
309     ok(ret == TRUE, "ret = %d\n", (int)ret);
310     ret = p_char_eq(in1, in3);
311     ok(ret == TRUE, "ret = %d\n", (int)ret);
312     ret = p_char_eq(in1, in4);
313     ok(ret == FALSE, "ret = %d\n", (int)ret);
314
315     ret = p_wchar_eq(in1, in2);
316     ok(ret == TRUE, "ret = %d\n", (int)ret);
317     ret = p_wchar_eq(in1, in3);
318     ok(ret == FALSE, "ret = %d\n", (int)ret);
319     ret = p_wchar_eq(in1, in4);
320     ok(ret == FALSE, "ret = %d\n", (int)ret);
321
322     ret = p_short_eq(in1, in2);
323     ok(ret == TRUE, "ret = %d\n", (int)ret);
324     ret = p_short_eq(in1, in3);
325     ok(ret == FALSE, "ret = %d\n", (int)ret);
326     ret = p_short_eq(in1, in4);
327     ok(ret == FALSE, "ret = %d\n", (int)ret);
328 }
329
330 static void test_Copy_s(void)
331 {
332     static const char src[] = "abcd";
333     char dest[32], *ret;
334
335     dest[4] = '#';
336     dest[5] = '\0';
337     ret = p_Copy_s(dest, 4, src, 4);
338     ok(ret == dest, "ret != dest\n");
339     ok(dest[4] == '#', "dest[4] != '#'\n");
340     ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
341
342     ret = p_Copy_s(dest, 32, src, 4);
343     ok(ret == dest, "ret != dest\n");
344     ok(dest[4] == '#', "dest[4] != '#'\n");
345     ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);
346
347     errno = 0xdeadbeef;
348     dest[0] = '#';
349     ret = p_Copy_s(dest, 3, src, 4);
350     ok(ret == dest, "ret != dest\n");
351     ok(dest[0] == '\0', "dest[0] != 0\n");
352     ok(invalid_parameter==1, "invalid_parameter = %d\n",
353             invalid_parameter);
354     invalid_parameter = 0;
355     ok(errno == 0xdeadbeef, "errno = %d\n", errno);
356
357     errno = 0xdeadbeef;
358     p_Copy_s(NULL, 32, src, 4);
359     ok(invalid_parameter==1, "invalid_parameter = %d\n",
360             invalid_parameter);
361     invalid_parameter = 0;
362     ok(errno == 0xdeadbeef, "errno = %d\n", errno);
363
364     errno = 0xdeadbeef;
365     p_Copy_s(dest, 32, NULL, 4);
366     ok(invalid_parameter==1, "invalid_parameter = %d\n",
367             invalid_parameter);
368     invalid_parameter = 0;
369     ok(errno == 0xdeadbeef, "errno = %d\n", errno);
370 }
371
372 static void test_wctype(void)
373 {
374     static const struct {
375         const char *name;
376         unsigned short mask;
377     } properties[] = {
378         { "alnum",  0x107 },
379         { "alpha",  0x103 },
380         { "cntrl",  0x020 },
381         { "digit",  0x004 },
382         { "graph",  0x117 },
383         { "lower",  0x002 },
384         { "print",  0x157 },
385         { "punct",  0x010 },
386         { "space",  0x008 },
387         { "upper",  0x001 },
388         { "xdigit", 0x080 },
389         { "ALNUM",  0x000 },
390         { "Alnum",  0x000 },
391         { "",  0x000 }
392     };
393     int i, ret;
394
395     for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++) {
396         ret = p_wctype(properties[i].name);
397         ok(properties[i].mask == ret, "%d - Expected %x, got %x\n", i, properties[i].mask, ret);
398     }
399 }
400
401 static void test__Getctype(void)
402 {
403     MSVCP__Ctypevec ret;
404     _locale_t locale;
405
406     ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
407     ok(ret.handle == 0, "ret.handle = %d\n", ret.handle);
408     ok(ret.page == 0, "ret.page = %d\n", ret.page);
409     ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
410     ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
411     p_free(ret.table);
412
413     locale = p__get_current_locale();
414     locale->locinfo->lc_handle[LC_COLLATE] = 0x1234567;
415     p__free_locale(locale);
416     ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
417     ok(ret.handle == 0x1234567, "ret.handle = %d\n", ret.handle);
418     ok(ret.page == 0, "ret.page = %d\n", ret.page);
419     ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
420     ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
421     p_free(ret.table);
422 }
423
424 static void test__Getcoll(void)
425 {
426     ULONGLONG (__cdecl *p__Getcoll_arg)(MSVCP__Collvec*);
427     _locale_t locale;
428
429     union {
430         MSVCP__Collvec collvec;
431         ULONGLONG ull;
432     }ret;
433
434     locale = p__get_current_locale();
435     locale->locinfo->lc_handle[LC_COLLATE] = 0x7654321;
436     p__free_locale(locale);
437     ret.ull = 0;
438     p__Getcoll_arg = (void*)p__Getcoll;
439     p__Getcoll_arg(&ret.collvec);
440     ok(ret.collvec.handle == 0, "ret.handle = %x\n", ret.collvec.handle);
441     ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
442
443     ret.ull = p__Getcoll();
444     ok(ret.collvec.handle == 0x7654321, "ret.collvec.handle = %x\n", ret.collvec.handle);
445     ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
446 }
447
448 static void test_towctrans(void)
449 {
450     wchar_t ret;
451
452     ret = p_wctrans("tolower");
453     ok(ret == 2, "wctrans returned %d, expected 2\n", ret);
454     ret = p_wctrans("toupper");
455     ok(ret == 1, "wctrans returned %d, expected 1\n", ret);
456     ret = p_wctrans("toLower");
457     ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
458     ret = p_wctrans("");
459     ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
460     if(0) { /* crashes on windows */
461         ret = p_wctrans(NULL);
462         ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
463     }
464
465     ret = p_towctrans('t', 2);
466     ok(ret == 't', "towctrans('t', 2) returned %c, expected t\n", ret);
467     ret = p_towctrans('T', 2);
468     ok(ret == 't', "towctrans('T', 2) returned %c, expected t\n", ret);
469     ret = p_towctrans('T', 0);
470     ok(ret == 't', "towctrans('T', 0) returned %c, expected t\n", ret);
471     ret = p_towctrans('T', 3);
472     ok(ret == 't', "towctrans('T', 3) returned %c, expected t\n", ret);
473     ret = p_towctrans('t', 1);
474     ok(ret == 'T', "towctrans('t', 1) returned %c, expected T\n", ret);
475     ret = p_towctrans('T', 1);
476     ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret);
477 }
478
479 static void test_allocator_char(void)
480 {
481     void *allocator = (void*)0xdeadbeef;
482     char *ptr;
483     char val;
484     unsigned int size;
485
486     allocator = call_func1(p_char_ctor, allocator);
487     ok(allocator == (void*)0xdeadbeef, "allocator = %p\n", allocator);
488
489     ptr = call_func2(p_char_address, NULL, (void*)0xdeadbeef);
490     ok(ptr == (void*)0xdeadbeef, "incorrect address (%p)\n", ptr);
491
492     ptr = NULL;
493     ptr = call_func2(p_char_allocate, allocator, 10);
494     ok(ptr != NULL, "Memory allocation failed\n");
495
496     ptr[0] = ptr[1] = '#';
497     val = 'a';
498     call_func3(p_char_construct, allocator, ptr, &val);
499     val = 'b';
500     call_func3(p_char_construct, allocator, (ptr+1), &val);
501     ok(ptr[0] == 'a', "ptr[0] = %c\n", ptr[0]);
502     ok(ptr[1] == 'b', "ptr[1] = %c\n", ptr[1]);
503
504     call_func3(p_char_deallocate, allocator, ptr, -1);
505
506     size = (unsigned int)call_func1(p_char_max_size, allocator);
507     ok(size == (unsigned int)0xffffffff, "size = %x\n", size);
508 }
509
510 static void test_virtual_call(void)
511 {
512     BYTE this[256];
513     basic_string_char bstr;
514     _locale_t locale;
515     const char *p;
516     char str1[] = "test";
517     char str2[] = "TEST";
518     int ret;
519
520     locale = p__get_current_locale();
521     locale->locinfo->lc_handle[LC_COLLATE] = 1;
522     p__free_locale(locale);
523     call_func2(p_collate_char_ctor_refs, this, 0);
524     ret = (int)call_func5(p_collate_char_compare, this, str1, str1+4, str1, str1+4);
525     ok(ret == 0, "collate<char>::compare returned %d\n", ret);
526     ret = (int)call_func5(p_collate_char_compare, this, str2, str2+4, str1, str1+4);
527     ok(ret == 1, "collate<char>::compare returned %d\n", ret);
528     ret = (int)call_func5(p_collate_char_compare, this, str1, str1+3, str1, str1+4);
529     ok(ret == -1, "collate<char>::compare returned %d\n", ret);
530     call_func1(p_collate_char_dtor, this);
531
532     call_func1(p_numpunct_char_ctor, this);
533     call_func2(p_numpunct_char_falsename, this, &bstr);
534     p = call_func1(p_basic_string_char_cstr, &bstr);
535     ok(!strcmp(p, "false"), "numpunct<char>::falsename returned %s\n", p);
536     call_func1(p_basic_string_char_dtor, &bstr);
537     call_func1(p_numpunct_char_dtor, this);
538 }
539
540 static void test_virtual_base_dtors(void)
541 {
542     char this[512];
543
544     call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 1);
545     call_func1(p_basic_ostringstream_char_vbase_dtor, this);
546
547     /* this test uses vbtable set by earlier test */
548     call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 0);
549     call_func1(p_basic_ostringstream_char_dtor, this+basic_ostringstream_char_vbtable[1]);
550     call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
551 }
552
553 START_TEST(misc)
554 {
555     if(!init())
556         return;
557
558     test_assign();
559     test_equal();
560     test_Copy_s();
561     test_wctype();
562     test__Getctype();
563     test__Getcoll();
564     test_towctrans();
565     test_virtual_call();
566     test_virtual_base_dtors();
567
568     test_allocator_char();
569
570     ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
571 }