#include #include #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); }