aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 09:14:29 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 09:14:29 +0100
commitedf331cd2573726d8053ce76e3497203a12d99b9 (patch)
tree73b3b885a7c6e4f35e7cba247cfdce280a4c6e86 /tests
parent615618bb2ad91be24fb74738db0b2f290ccc50a3 (diff)
downloadunja-edf331cd2573726d8053ce76e3497203a12d99b9.tar.gz
unja-edf331cd2573726d8053ce76e3497203a12d99b9.zip
add test for hashmap
Diffstat (limited to 'tests')
-rw-r--r--tests/test.h24
-rw-r--r--tests/test_hashmap.c14
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/test.h b/tests/test.h
new file mode 100644
index 0000000..19868f8
--- /dev/null
+++ b/tests/test.h
@@ -0,0 +1,24 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#define assert(assertion, format, ...) _assert(assertion, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define TESTNAME(v) strcpy(current_test, v);
+
+char current_test[256] = {'\0'};
+
+void _assert(int assertion, const char filename[64], const int line, char *format, ...)
+{
+ if (assertion)
+ {
+ return;
+ }
+
+ va_list args;
+ va_start(args, format);
+ printf("%s:%d:%s failed: ", filename, line, current_test);
+ vprintf(format, args);
+ va_end(args);
+ printf("\n");
+} \ No newline at end of file
diff --git a/tests/test_hashmap.c b/tests/test_hashmap.c
new file mode 100644
index 0000000..cf6f7a2
--- /dev/null
+++ b/tests/test_hashmap.c
@@ -0,0 +1,14 @@
+#include "test.h"
+#include "hashmap.h"
+
+int main() {
+ struct hashmap *hm = hashmap_new();
+ assert(hashmap_get(hm, "foo") == NULL, "expected NULL");
+
+ hashmap_insert(hm, "foo", "bar");
+ char *value = hashmap_get(hm, "foo");
+ assert(value != NULL, "expected value, got NULL");
+ assert(strcmp(value, "bar") == 0, "expected %s, got %s", "bar", value);
+
+ hashmap_free(hm);
+} \ No newline at end of file