summaryrefslogtreecommitdiff
path: root/tests/set.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/set.c')
-rw-r--r--tests/set.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/set.c b/tests/set.c
index 66d0472..e00a253 100644
--- a/tests/set.c
+++ b/tests/set.c
@@ -3,9 +3,85 @@
#include "../src/testing.h"
+
+static int
+test_set_new(void) {
+ int rc = -1;
+
+ const struct Set *s = NULL;
+
+ test_start("set_new()");
+ {
+ testing("simple allocation");
+
+ const size_t size = sizeof(long long);
+ if (set_new(size, &s)) {
+ logerr("set_new()");
+ goto out;
+ }
+
+ assert(s->value_size == size);
+
+ set_free(&s);
+
+ test_ok();
+ }
+
+ rc = 0;
+out:
+ if (s != NULL) {
+ set_free(&s);
+ }
+ return rc;
+}
+
+static int
+test_set_free(void) {
+ int rc = -1;
+
+ const struct Set *s = NULL;
+
+ test_start("set_free()");
+ {
+ testing("*s becomes NULL again after set_free(&s)");
+
+ assert(s == NULL);
+ if (set_new(1U, &s)) {
+ logerr("set_new()");
+ goto out;
+ }
+
+ assert(s != NULL);
+ set_free(&s);
+ assert(s == NULL);
+
+ test_ok();
+ }
+
+ rc = 0;
+out:
+ if (s != NULL) {
+ set_free(&s);
+ }
+ return rc;
+}
+
+
int
main(void) {
int rc = EXIT_FAILURE;
+
+ if (test_set_new()) {
+ logerr("test_set_new()");
+ goto out;
+ }
+
+ if (test_set_free()) {
+ logerr("test_set_free()");
+ goto out;
+ }
+
rc = EXIT_SUCCESS;
+out:
return rc;
}