summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/map.c20
-rw-r--r--tests/sptree.c20
-rw-r--r--tests/test.h12
-rw-r--r--tests/vec.c34
4 files changed, 83 insertions, 3 deletions
diff --git a/tests/map.c b/tests/map.c
index 6c42787..a370413 100644
--- a/tests/map.c
+++ b/tests/map.c
@@ -1,20 +1,38 @@
#include <assert.h>
#include <stdio.h>
+#include "test.h"
+/* required defs */
#define MAP_KEY int
#define MAP_TYPE int
#define MAP_HASH(a) CONTS_MAP_NO_HASH(a)
#define MAP_CMP(a, b) ((a) - (b))
#define MAP_NAME ints
+
+/* optional defs */
+#define MAP_MALLOC mallocc
+#define MAP_CALLOC callocc
+#define MAP_REALLOC reallocc
+#define MAP_FREE free
+
#include <conts/map.h>
int main()
{
+#if defined(COVERAGE)
+ assert(!covsrv_init());
+ atexit(covsrv_destroy);
+#endif
+
/* heuristic, but if we know how many elements we'll need, we should
* give it to the create function. */
struct ints ints = ints_create(0);
for (int i = 0; i < 1000000; ++i) {
- ints_insert(&ints, i, i);
+ if (!ints_insert(&ints, i, i)) {
+ fprintf(stderr, "failed inserting %d\n", i);
+ ints_destroy(&ints);
+ return -1;
+ }
}
assert(ints_len(&ints) == 1000000);
diff --git a/tests/sptree.c b/tests/sptree.c
index b8d1e5a..6ab3d6a 100644
--- a/tests/sptree.c
+++ b/tests/sptree.c
@@ -1,16 +1,34 @@
#include <assert.h>
#include <stdio.h>
+#include "test.h"
+/* required defs */
#define SPTREE_TYPE int
#define SPTREE_CMP(a, b) ((b) - (a))
#define SPTREE_NAME ints
+
+/* optional defs */
+#define SPTREE_MALLOC mallocc
+#define SPTREE_CALLOC callocc
+#define SPTREE_REALLOC reallocc
+#define SPTREE_FREE free
+
#include <conts/sptree.h>
int main()
{
+#if defined(COVERAGE)
+ assert(!covsrv_init());
+ atexit(covsrv_destroy);
+#endif
+
struct ints ints = ints_create();
for (int i = 0; i < 1000000; ++i) {
- ints_insert(&ints, i);
+ if (!ints_insert(&ints, i)) {
+ fprintf(stderr, "failed inserting %d\n", i);
+ ints_destroy(&ints);
+ return -1;
+ }
}
assert(ints_len(&ints) == 1000000);
diff --git a/tests/test.h b/tests/test.h
new file mode 100644
index 0000000..2fa0879
--- /dev/null
+++ b/tests/test.h
@@ -0,0 +1,12 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <covsrv/covsrv.h>
+
+#define cover_ptr(name, ...) ({covsrv_die() ? NULL : name (__VA_ARGS__);})
+
+#define mallocc(...) cover_ptr(malloc, __VA_ARGS__)
+#define callocc(...) cover_ptr(calloc, __VA_ARGS__)
+#define reallocc(...) cover_ptr(realloc, __VA_ARGS__)
+
+#endif /* TEST_H */
diff --git a/tests/vec.c b/tests/vec.c
index a84096c..8531b14 100644
--- a/tests/vec.c
+++ b/tests/vec.c
@@ -1,14 +1,33 @@
+#include <stdio.h>
#include <assert.h>
+#include "test.h"
+/* required defs */
#define VEC_TYPE int
#define VEC_NAME ints
+
+/* optional defs */
+#define VEC_MALLOC mallocc
+#define VEC_CALLOC callocc
+#define VEC_REALLOC reallocc
+#define VEC_FREE free
+
#include <conts/vec.h>
int main()
{
+#if defined(COVERAGE)
+ assert(!covsrv_init());
+ atexit(covsrv_destroy);
+#endif
+
struct ints ints = ints_create(0);
for (int i = 0; i < 1000000; ++i) {
- ints_append(&ints, i);
+ if (!ints_append(&ints, i)) {
+ fprintf(stderr, "failed appending %d to vec\n", i);
+ ints_destroy(&ints);
+ return -1;
+ }
}
assert(ints_len(&ints) == 1000000);
@@ -23,6 +42,19 @@ int main()
i++;
}
+ /* TEN million !!1! */
+ if (!ints_reserve(&ints, 10000000)) {
+ fprintf(stderr, "failed reserving vec\n");
+ ints_destroy(&ints);
+ return -1;
+ }
+
+ /* set size back to keep test runtime reasonable
+ * (is shrink necessary when we already have reserve? I
+ * guess it shows intention a bit better and just asserts instead of
+ * maybe fails?) */
+ ints_shrink(&ints, 1000000);
+
for (int i = 1000000 - 1; i >= 0; --i) {
ints_remove(&ints, i);
}