aboutsummaryrefslogtreecommitdiff
path: root/core/array.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-02-17 11:59:11 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-02-17 11:59:11 +0100
commit1c4b748a508552358d5654412389636029257c29 (patch)
tree082fb1961ecc117d8a030dd753fa37624c036bae /core/array.c
parentbdd09982d10b119fa220e6b03893afcfe9bd8e15 (diff)
downloadvis-1c4b748a508552358d5654412389636029257c29.tar.gz
vis-1c4b748a508552358d5654412389636029257c29.tar.xz
test/core: add some more array related tests
Diffstat (limited to 'core/array.c')
-rw-r--r--core/array.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/array.c b/core/array.c
index 64f6b81..5cf19a6 100644
--- a/core/array.c
+++ b/core/array.c
@@ -54,6 +54,15 @@ static void test_small_objects(void) {
"Re-add integer: %zu = %d", i, values[i]);
}
+ int old, *tmp;
+ ok((tmp = array_get(&arr, 0)) && (old = *tmp) && array_set(&arr, 0, NULL) &&
+ array_get(&arr, 0) == tmp && *tmp == 0 && array_set(&arr, 0, &old) &&
+ array_get(&arr, 0) == tmp && *tmp == old, "Set array element NULL");
+ ok(!array_set(&arr, array_length(&arr), &values[0]) && errno == EINVAL, "Get past end of array");
+ ok(!array_get(&arr, array_length(&arr)) && errno == EINVAL, "Get past end of array");
+
+ ok(!array_remove(&arr, array_length(&arr)) && errno == EINVAL, "Remove past end of array");
+
int *v;
size_t len_before = array_length(&arr);
@@ -124,6 +133,20 @@ static void test_large_objects(void) {
static void test_pointers(void) {
Array arr;
+
+ array_init_sized(&arr, 1);
+ ok(array_length(&arr) == 0 && array_get_ptr(&arr, 0) == NULL && errno == ENOTSUP,
+ "Initialization with size 1");
+
+ ok(!array_add_ptr(&arr, &arr) && errno == ENOTSUP && array_get_ptr(&arr, 0) == NULL,
+ "Add pointer to non-pointer array");
+
+ errno = 0;
+ char byte = '_', *ptr;
+ ok(array_add(&arr, &byte) && (ptr = array_get(&arr, 0)) && *ptr == byte,
+ "Add byte element");
+ ok(!array_get_ptr(&arr, 0) && errno == ENOTSUP, "Get pointer from non-pointer array");
+
array_init(&arr);
ok(array_length(&arr) == 0 && array_get_ptr(&arr, 0) == NULL && errno == EINVAL,
"Initialization");
@@ -156,6 +179,13 @@ static void test_pointers(void) {
"Get item: %zu = %p", i, (void*)item);
}
+ Item *tmp;
+ ok((tmp = array_get_ptr(&arr, 0)) && array_set_ptr(&arr, 0, NULL) &&
+ array_get_ptr(&arr, 0) == NULL && array_set_ptr(&arr, 0, tmp) &&
+ array_get_ptr(&arr, 0) == tmp, "Set pointer NULL");
+ ok(!array_set_ptr(&arr, array_length(&arr), items[0]) && errno == EINVAL, "Set pointer past end of array");
+ ok(!array_get_ptr(&arr, array_length(&arr)) && errno == EINVAL, "Get pointer past end of array");
+
array_clear(&arr);
ok(array_length(&arr) == 0 && array_get_ptr(&arr, 0) == NULL && errno == EINVAL, "Clear");