Commit 88adfd06 authored by Chris Müller's avatar Chris Müller

test: add operation tests for arrays (currently failing).

parent cfb94241
#include "unittest.h"
#include "structures/array.h"
#include <assert.h>
#include <stdio.h>
static void
test_array_allocation(const_pointer data)
......@@ -26,8 +27,42 @@ test_array_allocation(const_pointer data)
static void
test_array_operations(const_pointer data)
{
char text[] = { 'A', 'B', 'C', 'D', 'E' };
struct CryArray* array = cry_array_new(2, 4);
assert(cry_array_size(array) == 0);
assert(cry_array_alloc(array) == 4);
cry_array_append(array, text, 5);
cry_array_append(array, "\0", 1);
assert(cry_array_size(array) == 6);
assert(cry_array_alloc(array) == 8);
assert(strcmp(cry_array_get(array, 0), "ABCDE") == 0);
assert(cry_array_remove(array, 0, 2) == CRY_OKAY);
assert(cry_array_size(array) == 4);
assert(cry_array_alloc(array) == 8);
assert(cry_array_get(array, 0) != 0);
printf("%s", cry_array_get(array, 0));
assert(strcmp(cry_array_get(array, 0), "CDE") == 0);
cry_array_free(array);
}
void
cry_test_arrays(void)
{
cry_unittest_run("structures.array.allocation", test_array_allocation, 0, 10);
cry_unittest_run("structures.array.operations", test_array_operations, 0, 10);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment