diff options
author | sanine <sanine.not@pm.me> | 2023-01-03 23:31:48 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-03 23:31:48 -0600 |
commit | 13a7c902c051fa8da1e476687c17bb5431d258e1 (patch) | |
tree | ec75993aba0b8264f0dffd03eee2191020b206be /src/util/util.test.c | |
parent | e68e6d4e433fe42a0c6df18b2f2d7990b91b7cd6 (diff) |
add kai_expand_array
Diffstat (limited to 'src/util/util.test.c')
-rw-r--r-- | src/util/util.test.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/util/util.test.c b/src/util/util.test.c new file mode 100644 index 0000000..9f64085 --- /dev/null +++ b/src/util/util.test.c @@ -0,0 +1,61 @@ +#include <test/test.h> +#include "util.h" + +LILY_FILE_BEGIN(util_suite) + + +LILY_TEST("expand NULL array") +{ + size_t count = 0; + int *array = NULL; + + int *first = kai_expand_array((void**) &array, &count, sizeof(int)); + + CHECK_NEQ(first, NULL, "%p"); + CHECK_NEQ(array, NULL, "%p"); + CHECK_EQ(first, array, "%p"); + CHECK_EQ(count, 1, "%d"); + + int *second = kai_expand_array((void**) &array, &count, sizeof(int)); + + CHECK_NEQ(second, NULL, "%p"); + CHECK_EQ(second, array+1, "%p"); + CHECK_EQ(count, 2, "%d"); + + free(array); +} +#include LILY_PUSH_TEST() + + +struct test100 { + int value; + const char *str; +}; + +LILY_TEST("expand array 100 times") +{ + size_t count = 0; + struct test100 *array = NULL; + + const char *str = "hello, world!"; + + for (int i=0; i<100; i++) { + struct test100 *element = kai_expand_array((void**) &array, &count, sizeof(struct test100)); + element->value = i; + element->str = str; + } + + CHECK_EQ(count, 100, "%ul"); + + for (int i=0; i<100; i++) { + CHECK_EQ(array[i].value, i, "%d"); + CHECK_EQ(array[i].str, str, "%p"); + } + + free(array); +} +#include LILY_PUSH_TEST() + + +#define LILY_FILE_END +#include LILY_REGISTER_TESTS() |