diff options
Diffstat (limited to 'src/util.test.c')
-rw-r--r-- | src/util.test.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/util.test.c b/src/util.test.c new file mode 100644 index 0000000..c2f8462 --- /dev/null +++ b/src/util.test.c @@ -0,0 +1,57 @@ +#include <stdlib.h> + +#include <kalmia.h> +#include "util.h" +#include "test/test.h" + +void next_array_element(); + +void suite_util() +{ + lily_run_test(next_array_element); +} + +void next_array_element() +{ + int *arr = NULL; + size_t count = 0; + size_t max = 0; + + int *next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + lily_assert_not_null(arr); + lily_assert_not_null(next); + + lily_assert_ptr_equal(arr+0, next); + lily_assert_int_equal(count, 1); + lily_assert_int_equal(max, 1); + *next = 2; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+1, next); + lily_assert_int_equal(count, 2); + lily_assert_int_equal(max, 2); + *next = 1; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+2, next); + lily_assert_int_equal(count, 3); + lily_assert_int_equal(max, 4); + *next = 3; + + next = kai_next_array_element((void**) &arr, &count, &max, sizeof(int)); + + lily_assert_not_null(next); + lily_assert_ptr_equal(arr+3, next); + lily_assert_int_equal(count, 4); + lily_assert_int_equal(max, 4); + *next = 4; + + int expected[] = { 2, 1, 3, 4 }; + lily_assert_memory_equal(expected, arr, 4 * sizeof(int)); + + free(arr); +} |