summaryrefslogtreecommitdiffstats
path: root/test/failing_allocator.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-10 20:54:08 -0400
committerDavid Robillard <d@drobilla.net>2021-09-10 21:41:29 -0400
commitcf3b3048da0f80d3643ba0a9bc61a29ca5c5cf8b (patch)
treeb24292319826dd451b2b4a2228c63c246dd1d549 /test/failing_allocator.h
parent592961cc6b6c92ba6af2c30d01aa4f2a00955b68 (diff)
downloadzix-cf3b3048da0f80d3643ba0a9bc61a29ca5c5cf8b.tar.gz
zix-cf3b3048da0f80d3643ba0a9bc61a29ca5c5cf8b.tar.bz2
zix-cf3b3048da0f80d3643ba0a9bc61a29ca5c5cf8b.zip
Test failed Ring allocation
Diffstat (limited to 'test/failing_allocator.h')
-rw-r--r--test/failing_allocator.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/failing_allocator.h b/test/failing_allocator.h
new file mode 100644
index 0000000..b9daf75
--- /dev/null
+++ b/test/failing_allocator.h
@@ -0,0 +1,33 @@
+/*
+ Copyright 2021 David Robillard <d@drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#ifndef ZIX_FAILING_ALLOCATOR_H
+#define ZIX_FAILING_ALLOCATOR_H
+
+#include "zix/allocator.h"
+
+#include <stddef.h>
+
+/// An allocator that fails after some number of successes for testing
+typedef struct {
+ size_t n_allocations; ///< The number of allocations that have been attempted
+ size_t n_remaining; ///< The number of remaining successful allocations
+} ZixFailingAllocatorState;
+
+ZixAllocator
+zix_failing_allocator(ZixFailingAllocatorState* state);
+
+#endif // ZIX_FAILING_ALLOCATOR_H