33 |
33 |
34 #ifdef __cplusplus |
34 #ifdef __cplusplus |
35 extern "C" { |
35 extern "C" { |
36 #endif |
36 #endif |
37 |
37 |
|
38 /** |
|
39 * An allocator that verifies allocations / deallocations during testing. |
|
40 * |
|
41 * @par Typical Use |
|
42 * @code |
|
43 * CxTestingAllocator talloc; |
|
44 * cx_testing_allocator_init(&talloc); |
|
45 * CxAllocator *alloc = &talloc.base; |
|
46 * CX_TEST_DO { |
|
47 * // do your tests and use alloc as allocator for all API calls |
|
48 * // ... |
|
49 * // optional: check that the allocator was used |
|
50 * CX_TEST_ASSERT(cx_testing_allocator_used(&talloc)); |
|
51 * // verify |
|
52 * CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
|
53 * } |
|
54 * cx_testing_allocator_destroy(&talloc); |
|
55 * @endcode |
|
56 */ |
38 typedef struct CxTestingAllocator { |
57 typedef struct CxTestingAllocator { |
39 CxAllocator base; |
58 CxAllocator base; |
40 /** |
59 /** |
41 * Total number of all allocations (malloc, calloc, realloc). |
60 * Total number of all allocations (malloc, calloc, realloc). |
42 * A realloc() does only count when the memory has to be moved. |
61 * A realloc() does only count when the memory has to be moved. |
71 } CxTestingAllocator; |
90 } CxTestingAllocator; |
72 |
91 |
73 |
92 |
74 /** |
93 /** |
75 * Initializes a new testing allocator. |
94 * Initializes a new testing allocator. |
|
95 * @see cx_testing_allocator_destroy() |
76 */ |
96 */ |
77 void cx_testing_allocator_init(CxTestingAllocator *alloc); |
97 void cx_testing_allocator_init(CxTestingAllocator *alloc); |
78 |
98 |
79 /** |
99 /** |
80 * Destroys a testing allocator. |
100 * Destroys a testing allocator. |
|
101 * @see cx_testing_allocator_init() |
81 */ |
102 */ |
82 void cx_testing_allocator_destroy(CxTestingAllocator *alloc); |
103 void cx_testing_allocator_destroy(CxTestingAllocator *alloc); |
83 |
104 |
84 /** |
105 /** |
85 * Verifies that this allocator has been used. |
106 * Verifies that this allocator has been used. |
86 * |
107 * |
87 * @return true if any allocation was attempted using this allocator |
108 * @return true iff any allocation was attempted using this allocator |
88 */ |
109 */ |
89 bool cx_testing_allocator_used(const CxTestingAllocator *alloc); |
110 bool cx_testing_allocator_used(const CxTestingAllocator *alloc); |
90 |
111 |
91 /** |
112 /** |
92 * Verifies that all allocated memory blocks are freed and no free occurred twice. |
113 * Verifies that all allocated memory blocks are freed and no free occurred twice. |