1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Unit test suite for debug functions.
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2004 Patrik Stridvall
5c2c66affSColin Finck  *
6c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c2c66affSColin Finck  * Lesser General Public License for more details.
15c2c66affSColin Finck  *
16c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck  */
20c2c66affSColin Finck 
21c2c66affSColin Finck #include <stdarg.h>
22c2c66affSColin Finck 
23c2c66affSColin Finck #include "windef.h"
24c2c66affSColin Finck #include "winbase.h"
25c2c66affSColin Finck #include "winnt.h"
26c2c66affSColin Finck 
27c2c66affSColin Finck #include "crtdbg.h"
28c2c66affSColin Finck 
29c2c66affSColin Finck #include "wine/test.h"
30c2c66affSColin Finck 
31c2c66affSColin Finck /**********************************************************************/
32c2c66affSColin Finck 
33c2c66affSColin Finck static void * (__cdecl *pMSVCRTD_operator_new_dbg)(size_t, int, const char *, int) = NULL;
34*3f6b395cSAmine Khaldi static void * (__cdecl *pMSVCRTD_operator_delete)(void *) = NULL;
35c2c66affSColin Finck 
36c2c66affSColin Finck /* Some exports are only available in later versions */
37c2c66affSColin Finck #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hModule,y)
38c2c66affSColin Finck #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
39c2c66affSColin Finck 
init_functions(void)40c2c66affSColin Finck static BOOL init_functions(void)
41c2c66affSColin Finck {
42c2c66affSColin Finck   HMODULE hModule = LoadLibraryA("msvcrtd.dll");
43c2c66affSColin Finck 
44c2c66affSColin Finck   if (!hModule) {
45c2c66affSColin Finck     trace("LoadLibraryA failed to load msvcrtd.dll with GLE=%d\n", GetLastError());
46c2c66affSColin Finck     return FALSE;
47c2c66affSColin Finck   }
48c2c66affSColin Finck 
49c2c66affSColin Finck   if (sizeof(void *) > sizeof(int))  /* 64-bit has a different mangled name */
50*3f6b395cSAmine Khaldi   {
51c2c66affSColin Finck       SET(pMSVCRTD_operator_new_dbg, "??2@YAPEAX_KHPEBDH@Z");
52*3f6b395cSAmine Khaldi       SET(pMSVCRTD_operator_delete, "??3@YAXPEAX@Z");
53*3f6b395cSAmine Khaldi   }
54c2c66affSColin Finck   else
55*3f6b395cSAmine Khaldi   {
56c2c66affSColin Finck       SET(pMSVCRTD_operator_new_dbg, "??2@YAPAXIHPBDH@Z");
57*3f6b395cSAmine Khaldi       SET(pMSVCRTD_operator_delete, "??3@YAXPAX@Z");
58*3f6b395cSAmine Khaldi   }
59c2c66affSColin Finck 
60c2c66affSColin Finck   if (pMSVCRTD_operator_new_dbg == NULL)
61c2c66affSColin Finck     return FALSE;
62c2c66affSColin Finck 
63c2c66affSColin Finck   return TRUE;
64c2c66affSColin Finck }
65c2c66affSColin Finck 
66c2c66affSColin Finck /**********************************************************************/
67c2c66affSColin Finck 
test_new(void)68c2c66affSColin Finck static void test_new(void)
69c2c66affSColin Finck {
70c2c66affSColin Finck   void *mem;
71c2c66affSColin Finck 
72c2c66affSColin Finck   mem = pMSVCRTD_operator_new_dbg(42, _NORMAL_BLOCK, __FILE__, __LINE__);
73c2c66affSColin Finck   ok(mem != NULL, "memory not allocated\n");
74*3f6b395cSAmine Khaldi   pMSVCRTD_operator_delete(mem);
75*3f6b395cSAmine Khaldi 
76*3f6b395cSAmine Khaldi   mem = pMSVCRTD_operator_new_dbg(42, _CRT_BLOCK, __FILE__, __LINE__);
77*3f6b395cSAmine Khaldi   ok(mem != NULL, "memory not allocated\n");
78*3f6b395cSAmine Khaldi   pMSVCRTD_operator_delete(mem);
79c2c66affSColin Finck }
80c2c66affSColin Finck 
81c2c66affSColin Finck /**********************************************************************/
82c2c66affSColin Finck 
START_TEST(debug)83c2c66affSColin Finck START_TEST(debug)
84c2c66affSColin Finck {
85c2c66affSColin Finck   if (!init_functions())
86c2c66affSColin Finck     return;
87c2c66affSColin Finck 
88c2c66affSColin Finck   test_new();
89c2c66affSColin Finck }
90