From e2287cfe1b7208cdf046abef139c9426351ddbba Mon Sep 17 00:00:00 2001 From: JP Appel Date: Mon, 22 Jul 2024 15:20:23 -0400 Subject: renamed file and log function --- eztester_list.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 eztester_list.c (limited to 'eztester_list.c') diff --git a/eztester_list.c b/eztester_list.c new file mode 100644 index 0000000..bac6fc2 --- /dev/null +++ b/eztester_list.c @@ -0,0 +1,55 @@ +#include "eztester.h" + +#include +#include + +eztester_list *eztester_create_list(const size_t capacity) { + eztester_list *list = malloc(sizeof(eztester_list)); + if (!list) { + return NULL; + } + + list->length = 0; + + if (capacity == 0) { + list->tests = NULL; + list->capacity = 0; + return list; + } + + eztester_test *tests = malloc(capacity * sizeof(eztester_test)); + if (!tests) { + free(list); + return NULL; + } + list->tests = tests; + + list->capacity = capacity; + return list; +} + +void eztester_register(eztester_list *test_list, const eztester_test new_test) { + if (test_list->capacity == 0) { + test_list->tests = realloc(test_list->tests, 2 * sizeof(eztester_test)); + test_list->capacity = 2; + } + if (test_list->capacity <= test_list->length + 1) { + test_list->capacity *= 2; + test_list->tests = + realloc(test_list->tests, test_list->capacity * sizeof(eztester_test)); + assert(test_list->tests); + } + + test_list->tests[test_list->length++] = new_test; +} + +void eztester_clear_list(eztester_list *test_list) { + free(test_list->tests); + test_list->length = 0; + test_list->capacity = 0; +} + +void eztester_destroy_list(eztester_list *test_list) { + eztester_clear_list(test_list); + free(test_list); +} -- cgit v1.2.3