/[ascend]/trunk/test/CUnit/MyMem.h
ViewVC logotype

Contents of /trunk/test/CUnit/MyMem.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download) (as text)
Sun Oct 30 01:38:20 2005 UTC (18 years, 1 month ago) by jds
File MIME type: text/x-chdr
File size: 4512 byte(s)
- prototype unit test suite based on CUnit added.
- unit tests for base/generic/general and base/generic/utilites added.
- 2nd manual rework of doxygen documentation in general and utilities.
- bug fixes (mostly general & utilities) found during test development.
- added asc_assert prototype to redirect failures to Asc_Panic() and enable decoupling assertions from NDEBUG.
- some modifications of interface & implementation to facilitate testing.
- utilities/ascPrint & utilities/ascMalloc functions now always included in base libs to minimize recompilation when an interface chooses different options.
1 /*
2 * CUnit - A Unit testing framework library for C.
3 * Copyright (C) 2001 Anil Kumar
4 * Copyright (C) 2004, 2005 Anil Kumar, Jerry St.Clair
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 * Contains Memory Related Defines to use internal routines to detect Memory Leak
23 * in Debug Versions
24 *
25 * Created By : Anil Kumar on ...(18 June 2002)
26 * Last Modified : 18/Jun/2002
27 * Comment : Memory Debug Functions
28 * EMail : aksaharan@yahoo.com
29 *
30 * Modified : 17-Jul-2004 (JDS)
31 * Comment : New interface for global function names.
32 * EMail : jds2@users.sourceforge.net
33 *
34 * Modified : 5-Sep-2004 (JDS)
35 * Comment : Added internal test interface.
36 * EMail : jds2@users.sourceforge.net
37 */
38
39 /** @file
40 * Memory management functions (user interface).
41 * Two versions of memory allocation/deallocation are available.
42 * If compiled with MEMTRACE defined, CUnit keeps track of all
43 * system allocations & deallocations. The memory record can
44 * then be reported using CU_CREATE_MEMORY_REPORT. Otherwise,
45 * standard system memory allocation is used without tracing.
46 */
47 /** @addtogroup Framework
48 * @{
49 */
50
51 #ifndef CUNIT_MYMEM_H_SEEN
52 #define CUNIT_MYMEM_H_SEEN
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 #ifdef MEMTRACE
59 /*@null@*/ void* CU_calloc(size_t nmemb, size_t size, unsigned int uiLine, const char* szFileName);
60 /*@null@*/ void* CU_malloc(size_t size, unsigned int uiLine, const char* szFileName);
61 /*@null@*/ void CU_free(void *ptr, unsigned int uiLine, const char* szFileName);
62 /*@null@*/ void* CU_realloc(void *ptr, size_t size, unsigned int uiLine, const char* szFileName);
63 CU_EXPORT void CU_dump_memory_usage(const char*);
64
65 /** c-allocate with memory tracking. */
66 #define CU_CALLOC(x, y) CU_calloc((x), (y), __LINE__, __FILE__)
67 /** m-allocate with memory tracking. */
68 #define CU_MALLOC(x) CU_malloc((x), __LINE__, __FILE__)
69 /** Free with memory tracking. */
70 #define CU_FREE(x) CU_free((x), __LINE__, __FILE__)
71 /** Reallocate with memory tracking. */
72 #define CU_REALLOC(x, y) CU_realloc((x), (y), __LINE__, __FILE__)
73 /** Generate report on tracked memory. */
74 #define CU_CREATE_MEMORY_REPORT(x) CU_dump_memory_usage((x))
75 /** Generate report on tracked memory (old macro). */
76 #define CU_DUMP_MEMORY_USAGE(x) CU_dump_memory_usage((x))
77 #else
78 /** Standard calloc() if MEMTRACE not defined. */
79 #define CU_CALLOC(x, y) calloc((x), (y))
80 /** Standard malloc() if MEMTRACE not defined. */
81 #define CU_MALLOC(x) malloc((x))
82 /** Standard free() if MEMTRACE not defined. */
83 #define CU_FREE(x) free((x))
84 /** Standard realloc() if MEMTRACE not defined. */
85 #define CU_REALLOC(x, y) realloc((x), (y))
86 /** No-op if MEMTRACE not defined. */
87 #define CU_CREATE_MEMORY_REPORT(x)
88 /** No-op if MEMTRACE not defined. */
89 #define CU_DUMP_MEMORY_USAGE(x)
90 #endif
91
92 #ifdef CUNIT_BUILD_TESTS
93 /** Disable memory allocation for testing purposes. */
94 void test_cunit_deactivate_malloc(void);
95 /** Enable memory allocation for testing purposes. */
96 void test_cunit_activate_malloc(void);
97 /** Retrieve number of memory events for a given pointer */
98 unsigned int test_cunit_get_n_memevents(void* pLocation);
99 /** Retrieve number of allocations for a given pointer */
100 unsigned int test_cunit_get_n_allocations(void* pLocation);
101 /** Retrieve number of deallocations for a given pointer */
102 unsigned int test_cunit_get_n_deallocations(void* pLocation);
103
104 void test_cunit_MyMem(void);
105 #endif
106
107
108 #ifdef __cplusplus
109 }
110 #endif
111 #endif /* CUNIT_MYMEM_H_SEEN */
112 /** @} */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22