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);
120 /* _very_ early native versions have serious RTTI bugs, so we check */
121 static void* bAncientVersion;
123 /* Emulate a __thiscall */
125 inline static void* do_call_func1(void *func, void *_this)
127 volatile void* retval = 0;
136 return (void*)retval;
139 inline static void* do_call_func2(void *func, void *_this, void* arg)
141 volatile void* retval = 0;
151 return (void*)retval;
154 static void* do_call_func1(void *func, void *_this)
157 __asm__ __volatile__ ("call *%1"
159 : "g" (func), "c" (_this)
163 static void* do_call_func2(void *func, void *_this, void* arg)
166 __asm__ __volatile__ ("pushl %2\n\tcall *%1"
168 : "r" (func), "g" (arg), "c" (_this)
174 #define call_func1(x,y) do_call_func1((void*)x,(void*)y)
175 #define call_func2(x,y,z) do_call_func2((void*)x,(void*)y,(void*)z)
177 /* Some exports are only available in later versions */
178 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y)
179 #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y)
181 static void InitFunctionPtrs()
183 hMsvcrt = LoadLibraryA("msvcrt.dll");
184 ok(hMsvcrt != 0, "LoadLibraryA failed\n");
187 SETNOFAIL(poperator_new, "??_U@YAPAXI@Z");
188 SETNOFAIL(poperator_delete, "??_V@YAXPAX@Z");
189 SET(pmalloc, "malloc");
193 poperator_new = pmalloc;
194 if (!poperator_delete)
195 poperator_delete = pfree;
197 SET(pexception_ctor, "??0exception@@QAE@ABQBD@Z");
198 SET(pexception_copy_ctor, "??0exception@@QAE@ABV0@@Z");
199 SET(pexception_default_ctor, "??0exception@@QAE@XZ");
200 SET(pexception_dtor, "??1exception@@UAE@XZ");
201 SET(pexception_opequals, "??4exception@@QAEAAV0@ABV0@@Z");
202 SET(pexception_what, "?what@exception@@UBEPBDXZ");
203 SET(pexception_vtable, "??_7exception@@6B@");
204 SET(pexception_vector_dtor, "??_Eexception@@UAEPAXI@Z");
205 SET(pexception_scalar_dtor, "??_Gexception@@UAEPAXI@Z");
207 SET(pbad_typeid_ctor, "??0bad_typeid@@QAE@PBD@Z");
208 SETNOFAIL(pbad_typeid_ctor_closure, "??_Fbad_typeid@@QAEXXZ");
209 SET(pbad_typeid_copy_ctor, "??0bad_typeid@@QAE@ABV0@@Z");
210 SET(pbad_typeid_dtor, "??1bad_typeid@@UAE@XZ");
211 SET(pbad_typeid_opequals, "??4bad_typeid@@QAEAAV0@ABV0@@Z");
212 SET(pbad_typeid_what, "?what@exception@@UBEPBDXZ");
213 SET(pbad_typeid_vtable, "??_7bad_typeid@@6B@");
214 SET(pbad_typeid_vector_dtor, "??_Ebad_typeid@@UAEPAXI@Z");
215 SET(pbad_typeid_scalar_dtor, "??_Gbad_typeid@@UAEPAXI@Z");
217 SETNOFAIL(pbad_cast_ctor, "??0bad_cast@@QAE@ABQBD@Z");
219 SET(pbad_cast_ctor, "??0bad_cast@@AAE@PBQBD@Z");
220 SETNOFAIL(pbad_cast_ctor2, "??0bad_cast@@QAE@PBD@Z");
221 SETNOFAIL(pbad_cast_ctor_closure, "??_Fbad_cast@@QAEXXZ");
222 SET(pbad_cast_copy_ctor, "??0bad_cast@@QAE@ABV0@@Z");
223 SET(pbad_cast_dtor, "??1bad_cast@@UAE@XZ");
224 SET(pbad_cast_opequals, "??4bad_cast@@QAEAAV0@ABV0@@Z");
225 SET(pbad_cast_what, "?what@exception@@UBEPBDXZ");
226 SET(pbad_cast_vtable, "??_7bad_cast@@6B@");
227 SET(pbad_cast_vector_dtor, "??_Ebad_cast@@UAEPAXI@Z");
228 SET(pbad_cast_scalar_dtor, "??_Gbad_cast@@UAEPAXI@Z");
230 SET(p__non_rtti_object_ctor, "??0__non_rtti_object@@QAE@PBD@Z");
231 SET(p__non_rtti_object_copy_ctor, "??0__non_rtti_object@@QAE@ABV0@@Z");
232 SET(p__non_rtti_object_dtor, "??1__non_rtti_object@@UAE@XZ");
233 SET(p__non_rtti_object_opequals, "??4__non_rtti_object@@QAEAAV0@ABV0@@Z");
234 SET(p__non_rtti_object_what, "?what@exception@@UBEPBDXZ");
235 SET(p__non_rtti_object_vtable, "??_7__non_rtti_object@@6B@");
236 SET(p__non_rtti_object_vector_dtor, "??_E__non_rtti_object@@UAEPAXI@Z");
237 SET(p__non_rtti_object_scalar_dtor, "??_G__non_rtti_object@@UAEPAXI@Z");
239 SET(ptype_info_dtor, "??1type_info@@UAE@XZ");
240 SET(ptype_info_raw_name, "?raw_name@type_info@@QBEPBDXZ");
241 SET(ptype_info_name, "?name@type_info@@QBEPBDXZ");
242 SET(ptype_info_before, "?before@type_info@@QBEHABV1@@Z");
243 SET(ptype_info_opequals_equals, "??8type_info@@QBEHABV0@@Z");
244 SET(ptype_info_opnot_equals, "??9type_info@@QBEHABV0@@Z");
246 SET(p__RTtypeid, "__RTtypeid");
247 SET(p__RTCastToVoid, "__RTCastToVoid");
248 SET(p__RTDynamicCast, "__RTDynamicCast");
250 /* Extremely early versions export logic_error, and crash in RTTI */
251 SETNOFAIL(bAncientVersion, "??0logic_error@@QAE@ABQBD@Z");
255 static void test_exception(void)
257 static const char* e_name = "An exception name";
259 exception e, e2, e3, *pe;
261 if (!poperator_new || !poperator_delete ||
262 !pexception_ctor || !pexception_copy_ctor || !pexception_default_ctor ||
263 !pexception_dtor || !pexception_opequals || !pexception_what ||
264 !pexception_vtable || !pexception_vector_dtor || !pexception_scalar_dtor)
267 /* 'const char*&' ctor */
268 memset(&e, 0, sizeof(e));
269 call_func2(pexception_ctor, &e, &e_name);
270 ok(e.vtable != NULL, "Null exception vtable for e\n");
271 ok(e.name && e.name != e_name && !strcmp(e.name, "An exception name"), "Bad name '%s' for e\n", e.name);
272 ok(e.do_free == 1, "do_free set to %d for e\n", e.do_free);
275 memset(&e2, 0, sizeof(e2));
276 call_func2(pexception_copy_ctor, &e2, &e);
277 ok(e2.vtable != NULL, "Null exception vtable for e2\n");
278 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "An exception name"), "Bad exception name for e2\n");
279 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
282 memset(&e3, 1, sizeof(e3));
283 call_func1(pexception_default_ctor, &e3);
284 ok(e3.vtable != NULL, "Null exception vtable for e3\n");
285 ok(e3.name == NULL, "Bad exception name for e3\n");
286 ok(e3.do_free == 0, "do_free set to %d for e3\n", e3.do_free);
288 ok(e.vtable == e2.vtable && e.vtable == e3.vtable, "exception vtables differ!\n");
290 /* Test calling the dtors */
291 call_func1(pexception_dtor, &e2);
292 call_func1(pexception_dtor, &e3);
294 /* Operator equals */
295 memset(&e2, 0, sizeof(e2));
296 pe = call_func2(pexception_opequals, &e2, &e);
297 ok(e2.vtable != NULL, "Null exception vtable for e2\n");
298 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "An exception name"), "Bad exception name for e2\n");
299 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
300 ok(pe == &e2, "opequals didn't return e2\n");
303 name = call_func1(pexception_what, &e2);
304 ok(e2.name == name, "Bad exception name from e2::what()\n");
307 ok(e2.vtable == pexception_vtable, "Bad vtable for e2\n");
308 call_func1(pexception_dtor, &e2);
311 pe = poperator_new(sizeof(exception));
312 ok(pe != NULL, "new() failed\n");
315 call_func2(pexception_ctor, pe, &e_name);
317 call_func2(pexception_scalar_dtor, pe, 0); /* Shouldn't delete pe */
320 call_func2(pexception_scalar_dtor, pe, 1); /* Should delete pe */
323 pe = poperator_new(sizeof(exception));
324 ok(pe != NULL, "new() failed\n");
327 /* vector dtor, single element */
328 call_func2(pexception_ctor, pe, &e_name);
329 call_func2(pexception_vector_dtor, pe, 1); /* Should delete pe as single element*/
332 pe = poperator_new(sizeof(exception) * 4 + sizeof(int));
333 ok(pe != NULL, "new() failed\n");
336 /* vector dtor, multiple elements */
337 char name[] = "a constant";
339 pe = (exception*)((int*)pe + 1);
340 call_func2(pexception_ctor, &pe[0], &e_name);
341 call_func2(pexception_ctor, &pe[1], &e_name);
342 call_func2(pexception_ctor, &pe[2], &e_name);
344 pe[3].do_free = 1; /* Crash if we try to free this */
345 call_func2(pexception_vector_dtor, pe, 3); /* Should delete all 3 and then pe block */
348 /* test our exported vtable is kosher */
349 pe = (void*)pexception_vtable; /* Use the exception struct to get vtable ptrs */
350 pexception_vector_dtor = (void*)pe->vtable;
351 pexception_what = (void*)pe->name;
353 name = call_func1(pexception_what, &e);
354 ok(e.name == name, "Bad exception name from vtable e::what()\n");
356 if (p__RTtypeid && !bAncientVersion)
359 type_info *ti = p__RTtypeid(&e);
360 ok (ti && ti->mangled &&
361 !strcmp(ti->mangled, ".?AVexception@@"), "bad rtti for e\n");
365 /* Check the returned type_info has rtti too */
366 type_info *ti2 = p__RTtypeid(ti);
367 ok (ti2 != NULL && !strcmp(ti2->mangled, ".?AVtype_info@@"), "bad rtti for e's type_info\n");
371 call_func2(pexception_vector_dtor, &e, 0); /* Should delete e.name, but not e */
374 /* This test is basically a cut 'n' paste of the exception test. but it verifies that
375 * bad_typeid works the exact same way... */
376 static void test_bad_typeid(void)
378 static const char* e_name = "A bad_typeid name";
380 exception e, e2, e3, *pe;
382 if (!poperator_new || !poperator_delete ||
383 !pbad_typeid_ctor || !pbad_typeid_copy_ctor ||
384 !pbad_typeid_dtor || !pbad_typeid_opequals || !pbad_typeid_what ||
385 !pbad_typeid_vtable || !pbad_typeid_vector_dtor || !pbad_typeid_scalar_dtor)
388 /* 'const char*' ctor */
389 memset(&e, 0, sizeof(e));
390 call_func2(pbad_typeid_ctor, &e, e_name);
391 ok(e.vtable != NULL, "Null bad_typeid vtable for e\n");
392 ok(e.name && e.name != e_name && !strcmp(e.name, "A bad_typeid name"), "Bad name '%s' for e\n", e.name);
393 ok(e.do_free == 1, "do_free set to %d for e\n", e.do_free);
396 memset(&e2, 0, sizeof(e2));
397 call_func2(pbad_typeid_copy_ctor, &e2, &e);
398 ok(e2.vtable != NULL, "Null bad_typeid vtable for e2\n");
399 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A bad_typeid name"), "Bad name '%s' for e2\n", e2.name);
400 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
403 if (pbad_typeid_ctor_closure)
405 memset(&e3, 1, sizeof(e3));
406 call_func1(pbad_typeid_ctor_closure, &e3);
407 ok(e3.vtable != NULL, "Null bad_typeid vtable for e3\n");
408 ok(e3.name && !strcmp(e3.name, "bad typeid"), "Bad bad_typeid name for e3\n");
409 ok(e3.do_free == 1, "do_free set to %d for e3\n", e3.do_free);
410 ok(e.vtable == e3.vtable, "bad_typeid closure vtables differ!\n");
411 call_func1(pbad_typeid_dtor, &e3);
413 ok(e.vtable == e2.vtable, "bad_typeid vtables differ!\n");
415 /* Test calling the dtors */
416 call_func1(pbad_typeid_dtor, &e2);
418 /* Operator equals */
419 memset(&e2, 1, sizeof(e2));
420 pe = call_func2(pbad_typeid_opequals, &e2, &e);
421 ok(e2.vtable != NULL, "Null bad_typeid vtable for e2\n");
422 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A bad_typeid name"), "Bad bad_typeid name for e2\n");
423 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
424 ok(pe == &e2, "opequals didn't return e2\n");
427 name = call_func1(pbad_typeid_what, &e2);
428 ok(e2.name == name, "Bad bad_typeid name from e2::what()\n");
431 ok(e2.vtable == pexception_vtable, "Bad vtable for e2\n");
432 call_func1(pbad_typeid_dtor, &e2);
435 pe = poperator_new(sizeof(exception));
436 ok(pe != NULL, "new() failed\n");
439 call_func2(pbad_typeid_ctor, pe, e_name);
441 call_func2(pbad_typeid_scalar_dtor, pe, 0); /* Shouldn't delete pe */
444 call_func2(pbad_typeid_scalar_dtor, pe, 1); /* Should delete pe */
447 pe = poperator_new(sizeof(exception));
448 ok(pe != NULL, "new() failed\n");
451 /* vector dtor, single element */
452 call_func2(pbad_typeid_ctor, pe, e_name);
453 call_func2(pbad_typeid_vector_dtor, pe, 1); /* Should delete pe as single element*/
456 pe = poperator_new(sizeof(exception) * 4 + sizeof(int));
457 ok(pe != NULL, "new() failed\n");
460 /* vector dtor, multiple elements */
462 pe = (exception*)((int*)pe + 1);
463 call_func2(pbad_typeid_ctor, &pe[0], e_name);
464 call_func2(pbad_typeid_ctor, &pe[1], e_name);
465 call_func2(pbad_typeid_ctor, &pe[2], e_name);
467 pe[3].do_free = 1; /* Crash if we try to free this element */
468 call_func2(pbad_typeid_vector_dtor, pe, 3); /* Should delete all 3 and then pe block */
471 /* test our exported vtable is kosher */
472 pe = (void*)pbad_typeid_vtable; /* Use the exception struct to get vtable ptrs */
473 pbad_typeid_vector_dtor = (void*)pe->vtable;
474 pbad_typeid_what = (void*)pe->name;
476 name = call_func1(pbad_typeid_what, &e);
477 ok(e.name == name, "Bad bad_typeid name from vtable e::what()\n");
479 if (p__RTtypeid && !bAncientVersion)
482 type_info *ti = p__RTtypeid(&e);
483 ok (ti != NULL && !strcmp(ti->mangled, ".?AVbad_typeid@@"), "bad rtti for e (%s)\n",
484 !ti ? "null" : ti->mangled);
487 call_func2(pbad_typeid_vector_dtor, &e, 0); /* Should delete e.name, but not e */
491 /* Ditto for this test... */
492 static void test_bad_cast(void)
494 static const char* e_name = "A bad_cast name";
496 exception e, e2, e3, *pe;
498 if (!poperator_new || !poperator_delete ||
499 !pbad_cast_ctor || !pbad_cast_copy_ctor ||
500 !pbad_cast_dtor || !pbad_cast_opequals || !pbad_cast_what ||
501 !pbad_cast_vtable || !pbad_cast_vector_dtor || !pbad_cast_scalar_dtor)
506 /* 'const char*' ctor */
507 memset(&e, 0, sizeof(e));
508 call_func2(pbad_cast_ctor2, &e, e_name);
509 ok(e.vtable != NULL, "Null bad_cast vtable for e\n");
510 ok(e.name && e.name != e_name && !strcmp(e.name, "A bad_cast name"), "Bad name '%s' for e\n", e.name);
511 ok(e.do_free == 1, "do_free set to %d for e\n", e.do_free);
512 call_func1(pbad_cast_dtor, &e);
515 /* 'const char*&' ctor */
516 memset(&e, 0, sizeof(e));
517 call_func2(pbad_cast_ctor, &e, &e_name);
518 ok(e.vtable != NULL, "Null bad_cast vtable for e\n");
519 ok(e.name && e.name != e_name && !strcmp(e.name, "A bad_cast name"), "Bad name '%s' for e\n", e.name);
520 ok(e.do_free == 1, "do_free set to %d for e\n", e.do_free);
523 memset(&e2, 0, sizeof(e2));
524 call_func2(pbad_cast_copy_ctor, &e2, &e);
525 ok(e2.vtable != NULL, "Null bad_cast vtable for e2\n");
526 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A bad_cast name"), "Bad name '%s' for e2\n", e2.name);
527 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
530 if (pbad_cast_ctor_closure)
532 memset(&e3, 1, sizeof(e3));
533 call_func1(pbad_cast_ctor_closure, &e3);
534 ok(e3.vtable != NULL, "Null bad_cast vtable for e3\n");
535 ok(e3.name && !strcmp(e3.name, "bad cast"), "Bad bad_cast name for e3\n");
536 ok(e3.do_free == 1, "do_free set to %d for e3\n", e3.do_free);
537 ok(e.vtable == e3.vtable, "bad_cast closure vtables differ!\n");
538 call_func1(pbad_cast_dtor, &e3);
540 ok(e.vtable == e2.vtable, "bad_cast vtables differ!\n");
542 /* Test calling the dtors */
543 call_func1(pbad_cast_dtor, &e2);
545 /* Operator equals */
546 memset(&e2, 1, sizeof(e2));
547 pe = call_func2(pbad_cast_opequals, &e2, &e);
548 ok(e2.vtable != NULL, "Null bad_cast vtable for e2\n");
549 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A bad_cast name"), "Bad bad_cast name for e2\n");
550 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
551 ok(pe == &e2, "opequals didn't return e2\n");
554 name = call_func1(pbad_cast_what, &e2);
555 ok(e2.name == name, "Bad bad_cast name from e2::what()\n");
558 ok(e2.vtable == pexception_vtable, "Bad vtable for e2\n");
559 call_func1(pbad_cast_dtor, &e2);
562 pe = poperator_new(sizeof(exception));
563 ok(pe != NULL, "new() failed\n");
566 call_func2(pbad_cast_ctor, pe, &e_name);
568 call_func2(pbad_cast_scalar_dtor, pe, 0); /* Shouldn't delete pe */
571 call_func2(pbad_cast_scalar_dtor, pe, 1); /* Should delete pe */
574 pe = poperator_new(sizeof(exception));
575 ok(pe != NULL, "new() failed\n");
578 /* vector dtor, single element */
579 call_func2(pbad_cast_ctor, pe, &e_name);
580 call_func2(pbad_cast_vector_dtor, pe, 1); /* Should delete pe as single element*/
583 pe = poperator_new(sizeof(exception) * 4 + sizeof(int));
584 ok(pe != NULL, "new() failed\n");
587 /* vector dtor, multiple elements */
589 pe = (exception*)((int*)pe + 1);
590 call_func2(pbad_cast_ctor, &pe[0], &e_name);
591 call_func2(pbad_cast_ctor, &pe[1], &e_name);
592 call_func2(pbad_cast_ctor, &pe[2], &e_name);
594 pe[3].do_free = 1; /* Crash if we try to free this element */
595 call_func2(pbad_cast_vector_dtor, pe, 3); /* Should delete all 3 and then pe block */
598 /* test our exported vtable is kosher */
599 pe = (void*)pbad_cast_vtable; /* Use the exception struct to get vtable ptrs */
600 pbad_cast_vector_dtor = (void*)pe->vtable;
601 pbad_cast_what = (void*)pe->name;
603 name = call_func1(pbad_cast_what, &e);
604 ok(e.name == name, "Bad bad_cast name from vtable e::what()\n");
606 if (p__RTtypeid && !bAncientVersion)
609 type_info *ti = p__RTtypeid(&e);
610 ok (ti != NULL && !strcmp(ti->mangled, ".?AVbad_cast@@"), "bad rtti for e\n");
612 call_func2(pbad_cast_vector_dtor, &e, 0); /* Should delete e.name, but not e */
615 /* ... and this one */
616 static void test___non_rtti_object(void)
618 static const char* e_name = "A __non_rtti_object name";
620 exception e, e2, *pe;
622 if (!poperator_new || !poperator_delete ||
623 !p__non_rtti_object_ctor || !p__non_rtti_object_copy_ctor ||
624 !p__non_rtti_object_dtor || !p__non_rtti_object_opequals || !p__non_rtti_object_what ||
625 !p__non_rtti_object_vtable || !p__non_rtti_object_vector_dtor || !p__non_rtti_object_scalar_dtor)
628 /* 'const char*' ctor */
629 memset(&e, 0, sizeof(e));
630 call_func2(p__non_rtti_object_ctor, &e, e_name);
631 ok(e.vtable != NULL, "Null __non_rtti_object vtable for e\n");
632 ok(e.name && e.name != e_name && !strcmp(e.name, "A __non_rtti_object name"), "Bad name '%s' for e\n", e.name);
633 ok(e.do_free == 1, "do_free set to %d for e\n", e.do_free);
636 memset(&e2, 0, sizeof(e2));
637 call_func2(p__non_rtti_object_copy_ctor, &e2, &e);
638 ok(e2.vtable != NULL, "Null __non_rtti_object vtable for e2\n");
639 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A __non_rtti_object name"), "Bad name '%s' for e2\n", e2.name);
640 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
641 ok(e.vtable == e2.vtable, "__non_rtti_object vtables differ!\n");
643 /* Test calling the dtors */
644 call_func1(p__non_rtti_object_dtor, &e2);
646 /* Operator equals */
647 memset(&e2, 1, sizeof(e2));
648 pe = call_func2(p__non_rtti_object_opequals, &e2, &e);
649 ok(e2.vtable != NULL, "Null __non_rtti_object vtable for e2\n");
650 ok(e2.name && e2.name != e.name && !strcmp(e2.name, "A __non_rtti_object name"), "Bad __non_rtti_object name for e2\n");
651 ok(e2.do_free == 1, "do_free set to %d for e2\n", e2.do_free);
652 ok(pe == &e2, "opequals didn't return e2\n");
655 name = call_func1(p__non_rtti_object_what, &e2);
656 ok(e2.name == name, "Bad __non_rtti_object name from e2::what()\n");
659 ok(e2.vtable == pexception_vtable, "Bad vtable for e2\n");
660 call_func1(p__non_rtti_object_dtor, &e2);
663 pe = poperator_new(sizeof(exception));
664 ok(pe != NULL, "new() failed\n");
667 call_func2(p__non_rtti_object_ctor, pe, e_name);
669 call_func2(p__non_rtti_object_scalar_dtor, pe, 0); /* Shouldn't delete pe */
672 call_func2(p__non_rtti_object_scalar_dtor, pe, 1); /* Should delete pe */
675 pe = poperator_new(sizeof(exception));
676 ok(pe != NULL, "new() failed\n");
679 /* vector dtor, single element */
680 call_func2(p__non_rtti_object_ctor, pe, e_name);
681 call_func2(p__non_rtti_object_vector_dtor, pe, 1); /* Should delete pe as single element*/
684 pe = poperator_new(sizeof(exception) * 4 + sizeof(int));
685 ok(pe != NULL, "new() failed\n");
688 /* vector dtor, multiple elements */
690 pe = (exception*)((int*)pe + 1);
691 call_func2(p__non_rtti_object_ctor, &pe[0], e_name);
692 call_func2(p__non_rtti_object_ctor, &pe[1], e_name);
693 call_func2(p__non_rtti_object_ctor, &pe[2], e_name);
695 pe[3].do_free = 1; /* Crash if we try to free this element */
696 call_func2(p__non_rtti_object_vector_dtor, pe, 3); /* Should delete all 3 and then pe block */
699 /* test our exported vtable is kosher */
700 pe = (void*)p__non_rtti_object_vtable; /* Use the exception struct to get vtable ptrs */
701 p__non_rtti_object_vector_dtor = (void*)pe->vtable;
702 p__non_rtti_object_what = (void*)pe->name;
704 name = call_func1(p__non_rtti_object_what, &e);
705 ok(e.name == name, "Bad __non_rtti_object name from vtable e::what()\n");
707 if (p__RTtypeid && !bAncientVersion)
710 type_info *ti = p__RTtypeid(&e);
711 ok (ti != NULL && !strcmp(ti->mangled, ".?AV__non_rtti_object@@"), "bad rtti for e\n");
713 call_func2(p__non_rtti_object_vector_dtor, &e, 0); /* Should delete e.name, but not e */
717 static void test_type_info(void)
719 static type_info t1 = { NULL, NULL,{'.','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
720 static type_info t1_1 = { NULL, NULL,{'?','?','A','V','t','e','s','t','1','@','@',0,0,0,0,0 } };
721 static type_info t2 = { NULL, NULL, {'.','?','A','V','t','e','s','t','2','@','@',0,0,0,0,0 } };
725 if (!pmalloc || !pfree || !ptype_info_dtor || !ptype_info_raw_name ||
726 !ptype_info_name || !ptype_info_before ||
727 !ptype_info_opequals_equals || !ptype_info_opnot_equals)
730 /* Test calling the dtors */
731 call_func1(ptype_info_dtor, &t1); /* No effect, since name is NULL */
732 t1.name = pmalloc(64);
733 strcpy(t1.name, "foo");
734 call_func1(ptype_info_dtor, &t1); /* Frees t1.name using 'free' */
738 name = call_func1(ptype_info_raw_name, &t1);
740 /* FIXME: This fails on native; it shouldn't though - native bug?
741 * ok(name && !strcmp(name, t1.mangled), "bad raw_name '%s' for t1 (expected '%s')\n", name, t1.mangled);
743 ok(t1.name == NULL, "raw_name() set name for t1\n");
747 name = call_func1(ptype_info_name, &t1);
748 ok(name && t1.name && !strcmp(name, t1.name), "bad name '%s' for t1\n", name);
750 ok(t1.name && !strcmp(t1.name, "class test1"), "demangled to '%s' for t1\n", t1.name);
751 call_func1(ptype_info_dtor, &t1);
755 res = (int)call_func2(ptype_info_before, &t1, &t1);
756 ok(res == 0, "expected 0, got %d\n", res);
757 res = (int)call_func2(ptype_info_before, &t2, &t1);
758 ok(res == 0, "expected 0, got %d\n", res);
759 res = (int)call_func2(ptype_info_before, &t1, &t2);
760 ok(res == 1, "expected 1, got %d\n", res);
761 /* Doesn't check first char */
762 res = (int)call_func2(ptype_info_before, &t1, &t1_1);
763 ok(res == 0, "expected 0, got %d\n", res);
765 /* opequals_equals */
767 res = (int)call_func2(ptype_info_opequals_equals, &t1, &t1);
768 ok(res == 1, "expected 1, got %d\n", res);
769 res = (int)call_func2(ptype_info_opequals_equals, &t1, &t2);
770 ok(res == 0, "expected 0, got %d\n", res);
771 res = (int)call_func2(ptype_info_opequals_equals, &t2, &t1);
772 ok(res == 0, "expected 0, got %d\n", res);
776 res = (int)call_func2(ptype_info_opnot_equals, &t1, &t1);
777 ok(res == 0, "expected 0, got %d\n", res);
778 res = (int)call_func2(ptype_info_opnot_equals, &t1, &t2);
779 ok(res == 1, "expected 1, got %d\n", res);
780 res = (int)call_func2(ptype_info_opnot_equals, &t2, &t1);
781 ok(res == 1, "expected 1, got %d\n", res);
784 /* Test RTTI functions */
785 static void test_rtti(void)
787 static const char* e_name = "name";
792 if (bAncientVersion ||
793 !p__RTCastToVoid || !p__RTtypeid || !pexception_ctor || !pbad_typeid_ctor || !p__RTDynamicCast)
796 call_func2(pexception_ctor, &e, &e_name);
797 call_func2(pbad_typeid_ctor, &b, e_name);
799 /* dynamic_cast to void* */
800 casted = p__RTCastToVoid(&e);
801 ok (casted == (void*)&e, "failed cast to void\n");
803 /* dynamic_cast up */
804 ti = p__RTtypeid(&e);
805 bti = p__RTtypeid(&b);
807 casted = p__RTDynamicCast(&b, 0, NULL, ti, 0);
808 ok (casted == (void*)&b, "failed cast from bad_cast to exception\n");
810 /* dynamic_cast down */
811 casted = p__RTDynamicCast(&e, 0, NULL, bti, 0);
812 ok (casted == NULL, "Cast succeeded\n");
822 test___non_rtti_object();
827 FreeLibrary(hMsvcrt);
829 #endif /* __i386__ */