1 /* Unit test suite for msvcrt C++ objects
3 * Copyright 2003 Jon Griffiths
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * This tests is only valid for ix86 platforms, on others it's a no-op.
21 * Some tests cannot be checked with ok(), for example the dtors. We simply
22 * call them to ensure we don't crash ;-)
24 * If we build this test with VC++ in debug mode, we will fail in _chkstk()
25 * or at program exit malloc() checking if these methods haven't been
26 * implemented correctly (they have).
28 * Tested with a range of native msvcrt's from v4 -> v7.
30 #include "wine/test.h"
35 /* Skip these tests for non x86 platforms */
41 typedef struct __exception
48 typedef struct __type_info
55 /* Function pointers. We need to use these to call these funcs as __thiscall */
56 static HMODULE hMsvcrt
;
58 static void* (*poperator_new
)(unsigned int);
59 static void (*poperator_delete
)(void*);
60 static void* (*pmalloc
)(unsigned int);
61 static void (*pfree
)(void*);
64 static void (WINAPI
*pexception_ctor
)(exception
*,LPCSTR
*);
65 static void (WINAPI
*pexception_copy_ctor
)(exception
*,exception
*);
66 static void (WINAPI
*pexception_default_ctor
)(exception
*);
67 static void (WINAPI
*pexception_dtor
)(exception
*);
68 static exception
* (WINAPI
*pexception_opequals
)(exception
*,exception
*);
69 static char* (WINAPI
*pexception_what
)(exception
*);
70 static void* (WINAPI
*pexception_vtable
)(exception
*);
71 static void (WINAPI
*pexception_vector_dtor
)(exception
*,unsigned int);
72 static void (WINAPI
*pexception_scalar_dtor
)(exception
*,unsigned int);
75 static void (WINAPI
*pbad_typeid_ctor
)(exception
*,LPCSTR
);
76 static void (WINAPI
*pbad_typeid_ctor_closure
)(exception
*);
77 static void (WINAPI
*pbad_typeid_copy_ctor
)(exception
*,exception
*);
78 static void (WINAPI
*pbad_typeid_dtor
)(exception
*);
79 static exception
* (WINAPI
*pbad_typeid_opequals
)(exception
*,exception
*);
80 static char* (WINAPI
*pbad_typeid_what
)(exception
*);
81 static void* (WINAPI
*pbad_typeid_vtable
)(exception
*);
82 static void (WINAPI
*pbad_typeid_vector_dtor
)(exception
*,unsigned int);
83 static void (WINAPI
*pbad_typeid_scalar_dtor
)(exception
*,unsigned int);
86 static void (WINAPI
*pbad_cast_ctor
)(exception
*,LPCSTR
*);
87 static void (WINAPI
*pbad_cast_ctor2
)(exception
*,LPCSTR
);
88 static void (WINAPI
*pbad_cast_ctor_closure
)(exception
*);
89 static void (WINAPI
*pbad_cast_copy_ctor
)(exception
*,exception
*);
90 static void (WINAPI
*pbad_cast_dtor
)(exception
*);
91 static exception
* (WINAPI
*pbad_cast_opequals
)(exception
*,exception
*);
92 static char* (WINAPI
*pbad_cast_what
)(exception
*);
93 static void* (WINAPI
*pbad_cast_vtable
)(exception
*);
94 static void (WINAPI
*pbad_cast_vector_dtor
)(exception
*,unsigned int);
95 static void (WINAPI
*pbad_cast_scalar_dtor
)(exception
*,unsigned int);
97 /* __non_rtti_object */
98 static void (WINAPI
*p__non_rtti_object_ctor
)(exception
*,LPCSTR
);
99 static void (WINAPI
*p__non_rtti_object_copy_ctor
)(exception
*,exception
*);
100 static void (WINAPI
*p__non_rtti_object_dtor
)(exception
*);
101 static exception
* (WINAPI
*p__non_rtti_object_opequals
)(exception
*,exception
*);
102 static char* (WINAPI
*p__non_rtti_object_what
)(exception
*);
103 static void* (WINAPI
*p__non_rtti_object_vtable
)(exception
*);
104 static void (WINAPI
*p__non_rtti_object_vector_dtor
)(exception
*,unsigned int);
105 static void (WINAPI
*p__non_rtti_object_scalar_dtor
)(exception
*,unsigned int);
108 static void (WINAPI
*ptype_info_dtor
)(type_info
*);
109 static char* (WINAPI
*ptype_info_raw_name
)(type_info
*);
110 static char* (WINAPI
*ptype_info_name
)(type_info
*);
111 static int (WINAPI
*ptype_info_before
)(type_info
*,type_info
*);
112 static int (WINAPI
*ptype_info_opequals_equals
)(type_info
*,type_info
*);
113 static int (WINAPI
*ptype_info_opnot_equals
)(type_info
*,type_info
*);
116 static type_info
* (*p__RTtypeid
)(void*);
117 static void* (*p__RTCastToVoid
)(void*);
118 static void* (*p__RTDynamicCast
)(void*,int,void*,void*,int);
121 static char* (*p__unDName
)(char*,const char*,int,void*,void*,unsigned short int);
124 /* _very_ early native versions have serious RTTI bugs, so we check */
125 static void* bAncientVersion
;
127 /* Emulate a __thiscall */
129 inline static void* do_call_func1(void *func
, void *_this
)
131 volatile void* retval
= 0;
140 return (void*)retval
;
143 inline static void* do_call_func2(void *func
, void *_this
, void* arg
)
145 volatile void* retval
= 0;
155 return (void*)retval
;
158 static void* do_call_func1(void *func
, void *_this
)
161 __asm__
__volatile__ ("call *%1"
163 : "g" (func
), "c" (_this
)
167 static void* do_call_func2(void *func
, void *_this
, void* arg
)
170 __asm__
__volatile__ ("pushl %2\n\tcall *%1"
172 : "r" (func
), "g" (arg
), "c" (_this
)
178 #define call_func1(x,y) do_call_func1((void*)x,(void*)y)
179 #define call_func2(x,y,z) do_call_func2((void*)x,(void*)y,(void*)z)
181 /* Some exports are only available in later versions */
182 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
183 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
185 static void InitFunctionPtrs()
187 hMsvcrt
= LoadLibraryA("msvcrt.dll");
188 ok(hMsvcrt
!= 0, "LoadLibraryA failed\n");
191 SETNOFAIL(poperator_new
, "??_U@YAPAXI@Z");
192 SETNOFAIL(poperator_delete
, "??_V@YAXPAX@Z");
193 SET(pmalloc
, "malloc");
197 poperator_new
= pmalloc
;
198 if (!poperator_delete
)
199 poperator_delete
= pfree
;
201 SET(pexception_ctor
, "??0exception@@QAE@ABQBD@Z");
202 SET(pexception_copy_ctor
, "??0exception@@QAE@ABV0@@Z");
203 SET(pexception_default_ctor
, "??0exception@@QAE@XZ");
204 SET(pexception_dtor
, "??1exception@@UAE@XZ");
205 SET(pexception_opequals
, "??4exception@@QAEAAV0@ABV0@@Z");
206 SET(pexception_what
, "?what@exception@@UBEPBDXZ");
207 SET(pexception_vtable
, "??_7exception@@6B@");
208 SET(pexception_vector_dtor
, "??_Eexception@@UAEPAXI@Z");
209 SET(pexception_scalar_dtor
, "??_Gexception@@UAEPAXI@Z");
211 SET(pbad_typeid_ctor
, "??0bad_typeid@@QAE@PBD@Z");
212 SETNOFAIL(pbad_typeid_ctor_closure
, "??_Fbad_typeid@@QAEXXZ");
213 SET(pbad_typeid_copy_ctor
, "??0bad_typeid@@QAE@ABV0@@Z");
214 SET(pbad_typeid_dtor
, "??1bad_typeid@@UAE@XZ");
215 SET(pbad_typeid_opequals
, "??4bad_typeid@@QAEAAV0@ABV0@@Z");
216 SET(pbad_typeid_what
, "?what@exception@@UBEPBDXZ");
217 SET(pbad_typeid_vtable
, "??_7bad_typeid@@6B@");
218 SET(pbad_typeid_vector_dtor
, "??_Ebad_typeid@@UAEPAXI@Z");
219 SET(pbad_typeid_scalar_dtor
, "??_Gbad_typeid@@UAEPAXI@Z");
221 SETNOFAIL(pbad_cast_ctor
, "??0bad_cast@@QAE@ABQBD@Z");
223 SET(pbad_cast_ctor
, "??0bad_cast@@AAE@PBQBD@Z");
224 SETNOFAIL(pbad_cast_ctor2
, "??0bad_cast@@QAE@PBD@Z");
225 SETNOFAIL(pbad_cast_ctor_closure
, "??_Fbad_cast@@QAEXXZ");
226 SET(pbad_cast_copy_ctor
, "??0bad_cast@@QAE@ABV0@@Z");
227 SET(pbad_cast_dtor
, "??1bad_cast@@UAE@XZ");
228 SET(pbad_cast_opequals
, "??4bad_cast@@QAEAAV0@ABV0@@Z");
229 SET(pbad_cast_what
, "?what@exception@@UBEPBDXZ");
230 SET(pbad_cast_vtable
, "??_7bad_cast@@6B@");
231 SET(pbad_cast_vector_dtor
, "??_Ebad_cast@@UAEPAXI@Z");
232 SET(pbad_cast_scalar_dtor
, "??_Gbad_cast@@UAEPAXI@Z");
234 SET(p__non_rtti_object_ctor
, "??0__non_rtti_object@@QAE@PBD@Z");
235 SET(p__non_rtti_object_copy_ctor
, "??0__non_rtti_object@@QAE@ABV0@@Z");
236 SET(p__non_rtti_object_dtor
, "??1__non_rtti_object@@UAE@XZ");
237 SET(p__non_rtti_object_opequals
, "??4__non_rtti_object@@QAEAAV0@ABV0@@Z");
238 SET(p__non_rtti_object_what
, "?what@exception@@UBEPBDXZ");
239 SET(p__non_rtti_object_vtable
, "??_7__non_rtti_object@@6B@");
240 SET(p__non_rtti_object_vector_dtor
, "??_E__non_rtti_object@@UAEPAXI@Z");
241 SET(p__non_rtti_object_scalar_dtor
, "??_G__non_rtti_object@@UAEPAXI@Z");
243 SET(ptype_info_dtor
, "??1type_info@@UAE@XZ");
244 SET(ptype_info_raw_name
, "?raw_name@type_info@@QBEPBDXZ");
245 SET(ptype_info_name
, "?name@type_info@@QBEPBDXZ");
246 SET(ptype_info_before
, "?before@type_info@@QBEHABV1@@Z");
247 SET(ptype_info_opequals_equals
, "??8type_info@@QBEHABV0@@Z");
248 SET(ptype_info_opnot_equals
, "??9type_info@@QBEHABV0@@Z");
250 SET(p__RTtypeid
, "__RTtypeid");
251 SET(p__RTCastToVoid
, "__RTCastToVoid");
252 SET(p__RTDynamicCast
, "__RTDynamicCast");
254 SET(p__unDName
,"__unDName");
256 /* Extremely early versions export logic_error, and crash in RTTI */
257 SETNOFAIL(bAncientVersion
, "??0logic_error@@QAE@ABQBD@Z");
261 static void test_exception(void)
263 static const char* e_name
= "An exception name";
265 exception e
, e2
, e3
, *pe
;
267 if (!poperator_new
|| !poperator_delete
||
268 !pexception_ctor
|| !pexception_copy_ctor
|| !pexception_default_ctor
||
269 !pexception_dtor
|| !pexception_opequals
|| !pexception_what
||
270 !pexception_vtable
|| !pexception_vector_dtor
|| !pexception_scalar_dtor
)
273 /* 'const char*&' ctor */
274 memset(&e
, 0, sizeof(e
));
275 call_func2(pexception_ctor
, &e
, &e_name
);
276 ok(e
.vtable
!= NULL
, "Null exception vtable for e\n");
277 ok(e
.name
&& e
.name
!= e_name
&& !strcmp(e
.name
, "An exception name"), "Bad name '%s' for e\n", e
.name
);
278 ok(e
.do_free
== 1, "do_free set to %d for e\n", e
.do_free
);
281 memset(&e2
, 0, sizeof(e2
));
282 call_func2(pexception_copy_ctor
, &e2
, &e
);
283 ok(e2
.vtable
!= NULL
, "Null exception vtable for e2\n");
284 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "An exception name"), "Bad exception name for e2\n");
285 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
288 memset(&e3
, 1, sizeof(e3
));
289 call_func1(pexception_default_ctor
, &e3
);
290 ok(e3
.vtable
!= NULL
, "Null exception vtable for e3\n");
291 ok(e3
.name
== NULL
, "Bad exception name for e3\n");
292 ok(e3
.do_free
== 0, "do_free set to %d for e3\n", e3
.do_free
);
294 ok(e
.vtable
== e2
.vtable
&& e
.vtable
== e3
.vtable
, "exception vtables differ!\n");
296 /* Test calling the dtors */
297 call_func1(pexception_dtor
, &e2
);
298 call_func1(pexception_dtor
, &e3
);
300 /* Operator equals */
301 memset(&e2
, 0, sizeof(e2
));
302 pe
= call_func2(pexception_opequals
, &e2
, &e
);
303 ok(e2
.vtable
!= NULL
, "Null exception vtable for e2\n");
304 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "An exception name"), "Bad exception name for e2\n");
305 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
306 ok(pe
== &e2
, "opequals didn't return e2\n");
309 name
= call_func1(pexception_what
, &e2
);
310 ok(e2
.name
== name
, "Bad exception name from e2::what()\n");
313 ok(e2
.vtable
== pexception_vtable
, "Bad vtable for e2\n");
314 call_func1(pexception_dtor
, &e2
);
317 pe
= poperator_new(sizeof(exception
));
318 ok(pe
!= NULL
, "new() failed\n");
321 call_func2(pexception_ctor
, pe
, &e_name
);
323 call_func2(pexception_scalar_dtor
, pe
, 0); /* Shouldn't delete pe */
326 call_func2(pexception_scalar_dtor
, pe
, 1); /* Should delete pe */
329 pe
= poperator_new(sizeof(exception
));
330 ok(pe
!= NULL
, "new() failed\n");
333 /* vector dtor, single element */
334 call_func2(pexception_ctor
, pe
, &e_name
);
335 call_func2(pexception_vector_dtor
, pe
, 1); /* Should delete pe as single element*/
338 pe
= poperator_new(sizeof(exception
) * 4 + sizeof(int));
339 ok(pe
!= NULL
, "new() failed\n");
342 /* vector dtor, multiple elements */
343 char name
[] = "a constant";
345 pe
= (exception
*)((int*)pe
+ 1);
346 call_func2(pexception_ctor
, &pe
[0], &e_name
);
347 call_func2(pexception_ctor
, &pe
[1], &e_name
);
348 call_func2(pexception_ctor
, &pe
[2], &e_name
);
350 pe
[3].do_free
= 1; /* Crash if we try to free this */
351 call_func2(pexception_vector_dtor
, pe
, 3); /* Should delete all 3 and then pe block */
354 /* test our exported vtable is kosher */
355 pe
= (void*)pexception_vtable
; /* Use the exception struct to get vtable ptrs */
356 pexception_vector_dtor
= (void*)pe
->vtable
;
357 pexception_what
= (void*)pe
->name
;
359 name
= call_func1(pexception_what
, &e
);
360 ok(e
.name
== name
, "Bad exception name from vtable e::what()\n");
362 if (p__RTtypeid
&& !bAncientVersion
)
365 type_info
*ti
= p__RTtypeid(&e
);
366 ok (ti
&& ti
->mangled
&&
367 !strcmp(ti
->mangled
, ".?AVexception@@"), "bad rtti for e\n");
371 /* Check the returned type_info has rtti too */
372 type_info
*ti2
= p__RTtypeid(ti
);
373 ok (ti2
!= NULL
&& !strcmp(ti2
->mangled
, ".?AVtype_info@@"), "bad rtti for e's type_info\n");
377 call_func2(pexception_vector_dtor
, &e
, 0); /* Should delete e.name, but not e */
380 /* This test is basically a cut 'n' paste of the exception test. but it verifies that
381 * bad_typeid works the exact same way... */
382 static void test_bad_typeid(void)
384 static const char* e_name
= "A bad_typeid name";
386 exception e
, e2
, e3
, *pe
;
388 if (!poperator_new
|| !poperator_delete
||
389 !pbad_typeid_ctor
|| !pbad_typeid_copy_ctor
||
390 !pbad_typeid_dtor
|| !pbad_typeid_opequals
|| !pbad_typeid_what
||
391 !pbad_typeid_vtable
|| !pbad_typeid_vector_dtor
|| !pbad_typeid_scalar_dtor
)
394 /* 'const char*' ctor */
395 memset(&e
, 0, sizeof(e
));
396 call_func2(pbad_typeid_ctor
, &e
, e_name
);
397 ok(e
.vtable
!= NULL
, "Null bad_typeid vtable for e\n");
398 ok(e
.name
&& e
.name
!= e_name
&& !strcmp(e
.name
, "A bad_typeid name"), "Bad name '%s' for e\n", e
.name
);
399 ok(e
.do_free
== 1, "do_free set to %d for e\n", e
.do_free
);
402 memset(&e2
, 0, sizeof(e2
));
403 call_func2(pbad_typeid_copy_ctor
, &e2
, &e
);
404 ok(e2
.vtable
!= NULL
, "Null bad_typeid vtable for e2\n");
405 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A bad_typeid name"), "Bad name '%s' for e2\n", e2
.name
);
406 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
409 if (pbad_typeid_ctor_closure
)
411 memset(&e3
, 1, sizeof(e3
));
412 call_func1(pbad_typeid_ctor_closure
, &e3
);
413 ok(e3
.vtable
!= NULL
, "Null bad_typeid vtable for e3\n");
414 ok(e3
.name
&& !strcmp(e3
.name
, "bad typeid"), "Bad bad_typeid name for e3\n");
415 ok(e3
.do_free
== 1, "do_free set to %d for e3\n", e3
.do_free
);
416 ok(e
.vtable
== e3
.vtable
, "bad_typeid closure vtables differ!\n");
417 call_func1(pbad_typeid_dtor
, &e3
);
419 ok(e
.vtable
== e2
.vtable
, "bad_typeid vtables differ!\n");
421 /* Test calling the dtors */
422 call_func1(pbad_typeid_dtor
, &e2
);
424 /* Operator equals */
425 memset(&e2
, 1, sizeof(e2
));
426 pe
= call_func2(pbad_typeid_opequals
, &e2
, &e
);
427 ok(e2
.vtable
!= NULL
, "Null bad_typeid vtable for e2\n");
428 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A bad_typeid name"), "Bad bad_typeid name for e2\n");
429 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
430 ok(pe
== &e2
, "opequals didn't return e2\n");
433 name
= call_func1(pbad_typeid_what
, &e2
);
434 ok(e2
.name
== name
, "Bad bad_typeid name from e2::what()\n");
437 ok(e2
.vtable
== pexception_vtable
, "Bad vtable for e2\n");
438 call_func1(pbad_typeid_dtor
, &e2
);
441 pe
= poperator_new(sizeof(exception
));
442 ok(pe
!= NULL
, "new() failed\n");
445 call_func2(pbad_typeid_ctor
, pe
, e_name
);
447 call_func2(pbad_typeid_scalar_dtor
, pe
, 0); /* Shouldn't delete pe */
450 call_func2(pbad_typeid_scalar_dtor
, pe
, 1); /* Should delete pe */
453 pe
= poperator_new(sizeof(exception
));
454 ok(pe
!= NULL
, "new() failed\n");
457 /* vector dtor, single element */
458 call_func2(pbad_typeid_ctor
, pe
, e_name
);
459 call_func2(pbad_typeid_vector_dtor
, pe
, 1); /* Should delete pe as single element*/
462 pe
= poperator_new(sizeof(exception
) * 4 + sizeof(int));
463 ok(pe
!= NULL
, "new() failed\n");
466 /* vector dtor, multiple elements */
468 pe
= (exception
*)((int*)pe
+ 1);
469 call_func2(pbad_typeid_ctor
, &pe
[0], e_name
);
470 call_func2(pbad_typeid_ctor
, &pe
[1], e_name
);
471 call_func2(pbad_typeid_ctor
, &pe
[2], e_name
);
473 pe
[3].do_free
= 1; /* Crash if we try to free this element */
474 call_func2(pbad_typeid_vector_dtor
, pe
, 3); /* Should delete all 3 and then pe block */
477 /* test our exported vtable is kosher */
478 pe
= (void*)pbad_typeid_vtable
; /* Use the exception struct to get vtable ptrs */
479 pbad_typeid_vector_dtor
= (void*)pe
->vtable
;
480 pbad_typeid_what
= (void*)pe
->name
;
482 name
= call_func1(pbad_typeid_what
, &e
);
483 ok(e
.name
== name
, "Bad bad_typeid name from vtable e::what()\n");
485 if (p__RTtypeid
&& !bAncientVersion
)
488 type_info
*ti
= p__RTtypeid(&e
);
489 ok (ti
!= NULL
&& !strcmp(ti
->mangled
, ".?AVbad_typeid@@"), "bad rtti for e (%s)\n",
490 !ti
? "null" : ti
->mangled
);
493 call_func2(pbad_typeid_vector_dtor
, &e
, 0); /* Should delete e.name, but not e */
497 /* Ditto for this test... */
498 static void test_bad_cast(void)
500 static const char* e_name
= "A bad_cast name";
502 exception e
, e2
, e3
, *pe
;
504 if (!poperator_new
|| !poperator_delete
||
505 !pbad_cast_ctor
|| !pbad_cast_copy_ctor
||
506 !pbad_cast_dtor
|| !pbad_cast_opequals
|| !pbad_cast_what
||
507 !pbad_cast_vtable
|| !pbad_cast_vector_dtor
|| !pbad_cast_scalar_dtor
)
512 /* 'const char*' ctor */
513 memset(&e
, 0, sizeof(e
));
514 call_func2(pbad_cast_ctor2
, &e
, e_name
);
515 ok(e
.vtable
!= NULL
, "Null bad_cast vtable for e\n");
516 ok(e
.name
&& e
.name
!= e_name
&& !strcmp(e
.name
, "A bad_cast name"), "Bad name '%s' for e\n", e
.name
);
517 ok(e
.do_free
== 1, "do_free set to %d for e\n", e
.do_free
);
518 call_func1(pbad_cast_dtor
, &e
);
521 /* 'const char*&' ctor */
522 memset(&e
, 0, sizeof(e
));
523 call_func2(pbad_cast_ctor
, &e
, &e_name
);
524 ok(e
.vtable
!= NULL
, "Null bad_cast vtable for e\n");
525 ok(e
.name
&& e
.name
!= e_name
&& !strcmp(e
.name
, "A bad_cast name"), "Bad name '%s' for e\n", e
.name
);
526 ok(e
.do_free
== 1, "do_free set to %d for e\n", e
.do_free
);
529 memset(&e2
, 0, sizeof(e2
));
530 call_func2(pbad_cast_copy_ctor
, &e2
, &e
);
531 ok(e2
.vtable
!= NULL
, "Null bad_cast vtable for e2\n");
532 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A bad_cast name"), "Bad name '%s' for e2\n", e2
.name
);
533 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
536 if (pbad_cast_ctor_closure
)
538 memset(&e3
, 1, sizeof(e3
));
539 call_func1(pbad_cast_ctor_closure
, &e3
);
540 ok(e3
.vtable
!= NULL
, "Null bad_cast vtable for e3\n");
541 ok(e3
.name
&& !strcmp(e3
.name
, "bad cast"), "Bad bad_cast name for e3\n");
542 ok(e3
.do_free
== 1, "do_free set to %d for e3\n", e3
.do_free
);
543 ok(e
.vtable
== e3
.vtable
, "bad_cast closure vtables differ!\n");
544 call_func1(pbad_cast_dtor
, &e3
);
546 ok(e
.vtable
== e2
.vtable
, "bad_cast vtables differ!\n");
548 /* Test calling the dtors */
549 call_func1(pbad_cast_dtor
, &e2
);
551 /* Operator equals */
552 memset(&e2
, 1, sizeof(e2
));
553 pe
= call_func2(pbad_cast_opequals
, &e2
, &e
);
554 ok(e2
.vtable
!= NULL
, "Null bad_cast vtable for e2\n");
555 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A bad_cast name"), "Bad bad_cast name for e2\n");
556 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
557 ok(pe
== &e2
, "opequals didn't return e2\n");
560 name
= call_func1(pbad_cast_what
, &e2
);
561 ok(e2
.name
== name
, "Bad bad_cast name from e2::what()\n");
564 ok(e2
.vtable
== pexception_vtable
, "Bad vtable for e2\n");
565 call_func1(pbad_cast_dtor
, &e2
);
568 pe
= poperator_new(sizeof(exception
));
569 ok(pe
!= NULL
, "new() failed\n");
572 call_func2(pbad_cast_ctor
, pe
, &e_name
);
574 call_func2(pbad_cast_scalar_dtor
, pe
, 0); /* Shouldn't delete pe */
577 call_func2(pbad_cast_scalar_dtor
, pe
, 1); /* Should delete pe */
580 pe
= poperator_new(sizeof(exception
));
581 ok(pe
!= NULL
, "new() failed\n");
584 /* vector dtor, single element */
585 call_func2(pbad_cast_ctor
, pe
, &e_name
);
586 call_func2(pbad_cast_vector_dtor
, pe
, 1); /* Should delete pe as single element*/
589 pe
= poperator_new(sizeof(exception
) * 4 + sizeof(int));
590 ok(pe
!= NULL
, "new() failed\n");
593 /* vector dtor, multiple elements */
595 pe
= (exception
*)((int*)pe
+ 1);
596 call_func2(pbad_cast_ctor
, &pe
[0], &e_name
);
597 call_func2(pbad_cast_ctor
, &pe
[1], &e_name
);
598 call_func2(pbad_cast_ctor
, &pe
[2], &e_name
);
600 pe
[3].do_free
= 1; /* Crash if we try to free this element */
601 call_func2(pbad_cast_vector_dtor
, pe
, 3); /* Should delete all 3 and then pe block */
604 /* test our exported vtable is kosher */
605 pe
= (void*)pbad_cast_vtable
; /* Use the exception struct to get vtable ptrs */
606 pbad_cast_vector_dtor
= (void*)pe
->vtable
;
607 pbad_cast_what
= (void*)pe
->name
;
609 name
= call_func1(pbad_cast_what
, &e
);
610 ok(e
.name
== name
, "Bad bad_cast name from vtable e::what()\n");
612 if (p__RTtypeid
&& !bAncientVersion
)
615 type_info
*ti
= p__RTtypeid(&e
);
616 ok (ti
!= NULL
&& !strcmp(ti
->mangled
, ".?AVbad_cast@@"), "bad rtti for e\n");
618 call_func2(pbad_cast_vector_dtor
, &e
, 0); /* Should delete e.name, but not e */
621 /* ... and this one */
622 static void test___non_rtti_object(void)
624 static const char* e_name
= "A __non_rtti_object name";
626 exception e
, e2
, *pe
;
628 if (!poperator_new
|| !poperator_delete
||
629 !p__non_rtti_object_ctor
|| !p__non_rtti_object_copy_ctor
||
630 !p__non_rtti_object_dtor
|| !p__non_rtti_object_opequals
|| !p__non_rtti_object_what
||
631 !p__non_rtti_object_vtable
|| !p__non_rtti_object_vector_dtor
|| !p__non_rtti_object_scalar_dtor
)
634 /* 'const char*' ctor */
635 memset(&e
, 0, sizeof(e
));
636 call_func2(p__non_rtti_object_ctor
, &e
, e_name
);
637 ok(e
.vtable
!= NULL
, "Null __non_rtti_object vtable for e\n");
638 ok(e
.name
&& e
.name
!= e_name
&& !strcmp(e
.name
, "A __non_rtti_object name"), "Bad name '%s' for e\n", e
.name
);
639 ok(e
.do_free
== 1, "do_free set to %d for e\n", e
.do_free
);
642 memset(&e2
, 0, sizeof(e2
));
643 call_func2(p__non_rtti_object_copy_ctor
, &e2
, &e
);
644 ok(e2
.vtable
!= NULL
, "Null __non_rtti_object vtable for e2\n");
645 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A __non_rtti_object name"), "Bad name '%s' for e2\n", e2
.name
);
646 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
647 ok(e
.vtable
== e2
.vtable
, "__non_rtti_object vtables differ!\n");
649 /* Test calling the dtors */
650 call_func1(p__non_rtti_object_dtor
, &e2
);
652 /* Operator equals */
653 memset(&e2
, 1, sizeof(e2
));
654 pe
= call_func2(p__non_rtti_object_opequals
, &e2
, &e
);
655 ok(e2
.vtable
!= NULL
, "Null __non_rtti_object vtable for e2\n");
656 ok(e2
.name
&& e2
.name
!= e
.name
&& !strcmp(e2
.name
, "A __non_rtti_object name"), "Bad __non_rtti_object name for e2\n");
657 ok(e2
.do_free
== 1, "do_free set to %d for e2\n", e2
.do_free
);
658 ok(pe
== &e2
, "opequals didn't return e2\n");
661 name
= call_func1(p__non_rtti_object_what
, &e2
);
662 ok(e2
.name
== name
, "Bad __non_rtti_object name from e2::what()\n");
665 ok(e2
.vtable
== pexception_vtable
, "Bad vtable for e2\n");
666 call_func1(p__non_rtti_object_dtor
, &e2
);
669 pe
= poperator_new(sizeof(exception
));
670 ok(pe
!= NULL
, "new() failed\n");
673 call_func2(p__non_rtti_object_ctor
, pe
, e_name
);
675 call_func2(p__non_rtti_object_scalar_dtor
, pe
, 0); /* Shouldn't delete pe */
678 call_func2(p__non_rtti_object_scalar_dtor
, pe
, 1); /* Should delete pe */
681 pe
= poperator_new(sizeof(exception
));
682 ok(pe
!= NULL
, "new() failed\n");
685 /* vector dtor, single element */
686 call_func2(p__non_rtti_object_ctor
, pe
, e_name
);
687 call_func2(p__non_rtti_object_vector_dtor
, pe
, 1); /* Should delete pe as single element*/
690 pe
= poperator_new(sizeof(exception
) * 4 + sizeof(int));
691 ok(pe
!= NULL
, "new() failed\n");
694 /* vector dtor, multiple elements */
696 pe
= (exception
*)((int*)pe
+ 1);
697 call_func2(p__non_rtti_object_ctor
, &pe
[0], e_name
);
698 call_func2(p__non_rtti_object_ctor
, &pe
[1], e_name
);
699 call_func2(p__non_rtti_object_ctor
, &pe
[2], e_name
);
701 pe
[3].do_free
= 1; /* Crash if we try to free this element */
702 call_func2(p__non_rtti_object_vector_dtor
, pe
, 3); /* Should delete all 3 and then pe block */
705 /* test our exported vtable is kosher */
706 pe
= (void*)p__non_rtti_object_vtable
; /* Use the exception struct to get vtable ptrs */
707 p__non_rtti_object_vector_dtor
= (void*)pe
->vtable
;
708 p__non_rtti_object_what
= (void*)pe
->name
;
710 name
= call_func1(p__non_rtti_object_what
, &e
);
711 ok(e
.name
== name
, "Bad __non_rtti_object name from vtable e::what()\n");
713 if (p__RTtypeid
&& !bAncientVersion
)
716 type_info
*ti
= p__RTtypeid(&e
);
717 ok (ti
!= NULL
&& !strcmp(ti
->mangled
, ".?AV__non_rtti_object@@"), "bad rtti for e\n");
719 call_func2(p__non_rtti_object_vector_dtor
, &e
, 0); /* Should delete e.name, but not e */
723 static void test_type_info(void)
725 static type_info t1
= { NULL
, NULL
,{'.','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
726 static type_info t1_1
= { NULL
, NULL
,{'?','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
727 static type_info t2
= { NULL
, NULL
, {'.','?','A','V','t','e','s','t','2','@','@',0,0,0,0,0 } };
731 if (!pmalloc
|| !pfree
|| !ptype_info_dtor
|| !ptype_info_raw_name
||
732 !ptype_info_name
|| !ptype_info_before
||
733 !ptype_info_opequals_equals
|| !ptype_info_opnot_equals
)
736 /* Test calling the dtors */
737 call_func1(ptype_info_dtor
, &t1
); /* No effect, since name is NULL */
738 t1
.name
= pmalloc(64);
739 strcpy(t1
.name
, "foo");
740 call_func1(ptype_info_dtor
, &t1
); /* Frees t1.name using 'free' */
744 name
= call_func1(ptype_info_raw_name
, &t1
);
746 /* FIXME: This fails on native; it shouldn't though - native bug?
747 * ok(name && !strcmp(name, t1.mangled), "bad raw_name '%s' for t1 (expected '%s')\n", name, t1.mangled);
749 ok(t1
.name
== NULL
, "raw_name() set name for t1\n");
753 name
= call_func1(ptype_info_name
, &t1
);
754 ok(name
&& t1
.name
&& !strcmp(name
, t1
.name
), "bad name '%s' for t1\n", name
);
756 ok(t1
.name
&& !strcmp(t1
.name
, "class test1"), "demangled to '%s' for t1\n", t1
.name
);
757 call_func1(ptype_info_dtor
, &t1
);
761 res
= (int)call_func2(ptype_info_before
, &t1
, &t1
);
762 ok(res
== 0, "expected 0, got %d\n", res
);
763 res
= (int)call_func2(ptype_info_before
, &t2
, &t1
);
764 ok(res
== 0, "expected 0, got %d\n", res
);
765 res
= (int)call_func2(ptype_info_before
, &t1
, &t2
);
766 ok(res
== 1, "expected 1, got %d\n", res
);
767 /* Doesn't check first char */
768 res
= (int)call_func2(ptype_info_before
, &t1
, &t1_1
);
769 ok(res
== 0, "expected 0, got %d\n", res
);
771 /* opequals_equals */
773 res
= (int)call_func2(ptype_info_opequals_equals
, &t1
, &t1
);
774 ok(res
== 1, "expected 1, got %d\n", res
);
775 res
= (int)call_func2(ptype_info_opequals_equals
, &t1
, &t2
);
776 ok(res
== 0, "expected 0, got %d\n", res
);
777 res
= (int)call_func2(ptype_info_opequals_equals
, &t2
, &t1
);
778 ok(res
== 0, "expected 0, got %d\n", res
);
782 res
= (int)call_func2(ptype_info_opnot_equals
, &t1
, &t1
);
783 ok(res
== 0, "expected 0, got %d\n", res
);
784 res
= (int)call_func2(ptype_info_opnot_equals
, &t1
, &t2
);
785 ok(res
== 1, "expected 1, got %d\n", res
);
786 res
= (int)call_func2(ptype_info_opnot_equals
, &t2
, &t1
);
787 ok(res
== 1, "expected 1, got %d\n", res
);
790 /* Test RTTI functions */
791 static void test_rtti(void)
793 static const char* e_name
= "name";
798 if (bAncientVersion
||
799 !p__RTCastToVoid
|| !p__RTtypeid
|| !pexception_ctor
|| !pbad_typeid_ctor
|| !p__RTDynamicCast
)
802 call_func2(pexception_ctor
, &e
, &e_name
);
803 call_func2(pbad_typeid_ctor
, &b
, e_name
);
805 /* dynamic_cast to void* */
806 casted
= p__RTCastToVoid(&e
);
807 ok (casted
== (void*)&e
, "failed cast to void\n");
809 /* dynamic_cast up */
810 ti
= p__RTtypeid(&e
);
811 bti
= p__RTtypeid(&b
);
813 casted
= p__RTDynamicCast(&b
, 0, NULL
, ti
, 0);
814 ok (casted
== (void*)&b
, "failed cast from bad_cast to exception\n");
816 /* dynamic_cast down */
817 casted
= p__RTDynamicCast(&e
, 0, NULL
, bti
, 0);
818 ok (casted
== NULL
, "Cast succeeded\n");
821 static void test_demangle(void)
824 static const char * mangled
= ".ABVVec4@ref2@dice@@";
825 static const char * result
= "class dice::ref2::Vec4 const &";
826 name
= p__unDName(0, mangled
+ 1, 0,pmalloc
,pfree
,0x2800);
827 ok(name
!= NULL
&& !strcmp(name
,result
),"Got name %s \n",name
);
837 test___non_rtti_object();
843 FreeLibrary(hMsvcrt
);
845 #endif /* __i386__ */