summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-02-13 16:53:11 -0500
committerjakob <jakob@memeware.net>2017-02-13 16:53:11 -0500
commit01d185f31ff7194773342881fa0e0a550b5d5c5a (patch)
treee708be1001500e0932f77f82483e6c90a3e4e24d /test
parent3b9772a65146afb36e29b5bce082ce5aa1483c22 (diff)
Began inevetable rewrite.
Diffstat (limited to 'test')
-rw-r--r--test/minunit.h3
-rw-r--r--test/test_io.c52
2 files changed, 55 insertions, 0 deletions
diff --git a/test/minunit.h b/test/minunit.h
new file mode 100644
index 0000000..7422998
--- /dev/null
+++ b/test/minunit.h
@@ -0,0 +1,3 @@
+#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
+#define mu_run_test(test) do { char *message = test(); tests_run++; if (message) return message; } while (0)
+extern int tests_run;
diff --git a/test/test_io.c b/test/test_io.c
new file mode 100644
index 0000000..8bf7593
--- /dev/null
+++ b/test/test_io.c
@@ -0,0 +1,52 @@
+/* test_io.c -- MinUnit test cases for I/O related functions.
+
+ Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
+
+ This file is part of Nekopack.
+
+ Nekopack is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ Nekopack is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "minunit.h"
+
+#include "io.h"
+
+int tests_run = 0;
+
+
+static char *test_stream_obj(void) {
+ struct stream *s_1 = stream_new(0x10);
+ struct stream *s_2 = stream_new(0x20);
+ struct stream *s_3 = stream_new(0x40);
+ mu_assert("Incorrect size for `s_1`", s_1.len == 0x10);
+ mu_assert("Incorrect size for `s_2`", s_1.len == 0x20);
+ mu_assert("Incorrect size for `s_3`", s_1.len == 0x40);
+ stream_free(s_1);
+ stream_free(s_2);
+ stream_free(s_3);
+}
+
+
+static char *test_stream_rw(void) {
+ char dest[4];
+ struct stream *s_1 = stream_new(0x4);
+ stream_write(s_1, "\x00\x01\x02\x03", 4);
+ mu_assert("Write failure", !memcmp(s_1->_start, "\x00\x01\x02\x03", 4));
+ mu_assert("Cursor not incremented", s_1->cur - s_1->start == 4);
+ stream_read(dest, s, 4);
+ mu_assert("Read failure", !memcmp(dest, "\x00\x01\x02\x03", 4));
+ stream_free(s_1);
+}