test/util_allocator.cpp

Mon, 18 Apr 2022 17:26:21 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Apr 2022 17:26:21 +0200
changeset 528
4fbfac557df8
parent 518
74d0372f5c6f
child 571
f83583a0bbac
permissions
-rw-r--r--

#179 improve API for list content destruction

422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "util_allocator.h"
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 void *cx_malloc_testing(void *d, size_t n) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
32 auto data = reinterpret_cast<CxTestingAllocator *>(d);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 void *ptr = malloc(n);
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 data->alloc_total++;
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
35 if (ptr == nullptr) {
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 data->alloc_failed++;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 } else {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
38 data->tracked.insert(ptr);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 return ptr;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 void *cx_realloc_testing(void *d, void *mem, size_t n) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
44 auto data = reinterpret_cast<CxTestingAllocator *>(d);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 void *ptr = realloc(mem, n);
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 if (ptr == mem) {
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 return ptr;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 } else {
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 data->alloc_total++;
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
50 if (ptr == nullptr) {
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 data->alloc_failed++;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 } else {
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 data->free_total++;
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
54 if (data->tracked.erase(mem) == 0) {
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 data->free_failed++;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 }
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
57 data->tracked.insert(ptr);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 return ptr;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 void *cx_calloc_testing(void *d, size_t nelem, size_t n) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
64 auto data = reinterpret_cast<CxTestingAllocator *>(d);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 void *ptr = calloc(nelem, n);
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 data->alloc_total++;
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
67 if (ptr == nullptr) {
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 data->alloc_failed++;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 } else {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
70 data->tracked.insert(ptr);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 return ptr;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 void cx_free_testing(void *d, void *mem) {
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
76 auto data = reinterpret_cast<CxTestingAllocator *>(d);
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 data->free_total++;
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
78 if (data->tracked.erase(mem) == 0) {
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 data->free_failed++;
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 // do not even attempt to free mem, because it is likely to segfault
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 } else {
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 free(mem);
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 cx_allocator_class cx_testing_allocator_class = {
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 cx_malloc_testing,
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 cx_realloc_testing,
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 cx_calloc_testing,
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 cx_free_testing
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 };
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
93 CxTestingAllocator::CxTestingAllocator() : CxAllocator() {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
94 cl = &cx_testing_allocator_class;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
95 data = this;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
96 }
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
97
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
98 bool CxTestingAllocator::verify() const {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
99 return tracked.empty() && alloc_failed == 0 && free_failed == 0 && alloc_total == free_total;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
100 }
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
101
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
102 // SELF-TEST
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
104 #include <gtest/gtest.h>
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
105
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
106 TEST(TestingAllocator, ExpectFree) {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
107 CxTestingAllocator allocator;
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
109 ASSERT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
110 auto ptr = cxMalloc(&allocator, 16);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
111 ASSERT_NE(ptr, nullptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
112 EXPECT_FALSE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
113
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
114 cxFree(&allocator, ptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
115 EXPECT_TRUE(allocator.verify());
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
118 TEST(TestingAllocator, DetectDoubleFree) {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
119 CxTestingAllocator allocator;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
120
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
121 ASSERT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
122 auto ptr = cxMalloc(&allocator, 16);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
123 ASSERT_NE(ptr, nullptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
124
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
125 cxFree(&allocator, ptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
126 EXPECT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
127 ASSERT_NO_FATAL_FAILURE(cxFree(&allocator, ptr));
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
128 EXPECT_FALSE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
129 }
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
130
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
131 TEST(TestingAllocator, FreeUntracked) {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
132 CxTestingAllocator allocator;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
133
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
134 auto ptr = malloc(16);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
135 ASSERT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
136 ASSERT_NO_FATAL_FAILURE(cxFree(&allocator, ptr));
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
137 EXPECT_FALSE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
138 ASSERT_NO_FATAL_FAILURE(free(ptr));
422
afd87df80b13 add utility to verify allocations
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 }
518
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
140
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
141 TEST(TestingAllocator, FullLifecycleWithRealloc) {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
142 CxTestingAllocator allocator;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
143 ASSERT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
144 auto ptr = cxMalloc(&allocator, 16);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
145 ASSERT_NE(ptr, nullptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
146 EXPECT_EQ(allocator.tracked.size(), 1);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
147 ptr = cxRealloc(&allocator, ptr, 256);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
148 ASSERT_NE(ptr, nullptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
149 EXPECT_EQ(allocator.tracked.size(), 1);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
150 cxFree(&allocator, ptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
151 EXPECT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
152 }
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
153
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
154 TEST(TestingAllocator, CallocInitializes) {
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
155 CxTestingAllocator allocator;
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
156 const char* zeros[16] = {0};
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
157 auto ptr = cxCalloc(&allocator, 16, 1);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
158 EXPECT_EQ(memcmp(ptr, zeros, 16), 0);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
159 cxFree(&allocator, ptr);
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
160 EXPECT_TRUE(allocator.verify());
74d0372f5c6f improve testing allocator + add tests for it
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
161 }

mercurial