summaryrefslogtreecommitdiffstats
path: root/test/failing_allocator.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-09-28 11:14:08 -0400
committerDavid Robillard <d@drobilla.net>2024-09-28 11:15:15 -0400
commit50c73ad346fb63eb6d057dcc7d1351c95e12e83d (patch)
tree17e1be3b38642022e582dfde58ccced85c4ca15e /test/failing_allocator.h
parent19bd977e943bf37c2c24ee0116486fa9b7611f70 (diff)
downloadzix-50c73ad346fb63eb6d057dcc7d1351c95e12e83d.tar.gz
zix-50c73ad346fb63eb6d057dcc7d1351c95e12e83d.tar.bz2
zix-50c73ad346fb63eb6d057dcc7d1351c95e12e83d.zip
Improve test allocator API
Add a simple API for setting up the failing allocator to avoid manually tinkering with its members. Conveniently, this also avoids confusing cppcheck.
Diffstat (limited to 'test/failing_allocator.h')
-rw-r--r--test/failing_allocator.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/test/failing_allocator.h b/test/failing_allocator.h
index 982874d..5f6d220 100644
--- a/test/failing_allocator.h
+++ b/test/failing_allocator.h
@@ -1,8 +1,8 @@
-// Copyright 2021 David Robillard <d@drobilla.net>
+// Copyright 2021-2024 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#ifndef ZIX_FAILING_ALLOCATOR_H
-#define ZIX_FAILING_ALLOCATOR_H
+#ifndef ZIX_TEST_FAILING_ALLOCATOR_H
+#define ZIX_TEST_FAILING_ALLOCATOR_H
#include "zix/allocator.h"
@@ -15,7 +15,12 @@ typedef struct {
size_t n_remaining; ///< Number of remaining successful allocations
} ZixFailingAllocator;
+/// Return an allocator configured by default to succeed
ZixFailingAllocator
zix_failing_allocator(void);
-#endif // ZIX_FAILING_ALLOCATOR_H
+/// Reset an allocator to fail after some number of "allowed" allocations
+size_t
+zix_failing_allocator_reset(ZixFailingAllocator* allocator, size_t n_allowed);
+
+#endif // ZIX_TEST_FAILING_ALLOCATOR_H