From 50c73ad346fb63eb6d057dcc7d1351c95e12e83d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 28 Sep 2024 11:14:08 -0400 Subject: 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. --- test/failing_allocator.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'test/failing_allocator.h') 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 +// Copyright 2021-2024 David Robillard // 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 -- cgit v1.2.1