summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-02-14 18:47:57 -0500
committerjakob <jakob@memeware.net>2017-02-14 18:47:57 -0500
commit1fc6cc323dbaa5387d84630615c0d4cab0c1c5ba (patch)
treec94a738cb6d7f06fde68fc0765ccfd6a6dd19f4b /test
parent01d185f31ff7194773342881fa0e0a550b5d5c5a (diff)
Implemented a basic parser for the XP3 header.
Diffstat (limited to 'test')
-rw-r--r--test/test_header.c38
-rw-r--r--test/test_header.h23
-rw-r--r--test/test_io.c30
-rw-r--r--test/test_io.h23
-rw-r--r--test/test_run.c46
5 files changed, 147 insertions, 13 deletions
diff --git a/test/test_header.c b/test/test_header.c
new file mode 100644
index 0000000..1ae4e19
--- /dev/null
+++ b/test/test_header.c
@@ -0,0 +1,38 @@
+/* test_header.c -- MinUnit test cases for header.c
+
+ 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 <stdlib.h>
+#include <string.h>
+
+#include "minunit.h"
+
+#include "header.h"
+#include "io.h"
+
+extern int tests_run;
+
+
+char *test_header_read(void) {
+ struct stream *s = stream_new(sizeof(struct xp3_header));
+ memset(s->_start, '\x00', sizeof(struct xp3_header));
+ struct xp3_header *h = read_header(s);
+ mu_assert("Header assertions failed", h == NULL);
+ stream_free(s);
+ return NULL;
+}
diff --git a/test/test_header.h b/test/test_header.h
new file mode 100644
index 0000000..83613ce
--- /dev/null
+++ b/test/test_header.h
@@ -0,0 +1,23 @@
+/* test_header.h -- MinUnit test cases for header.c
+
+ 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/>. */
+
+#pragma once
+
+char *test_header_read(void);
+
diff --git a/test/test_io.c b/test/test_io.c
index 8bf7593..fd1e483 100644
--- a/test/test_io.c
+++ b/test/test_io.c
@@ -1,4 +1,4 @@
-/* test_io.c -- MinUnit test cases for I/O related functions.
+/* test_io.c -- MinUnit test cases for io.c
Copyright (C) 2017 Jakob Tsar-Fox, All Rights Reserved.
@@ -17,36 +17,40 @@
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;
+extern int tests_run;
-static char *test_stream_obj(void) {
+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);
+ mu_assert("Incorrect size for `s_1`", s_1->len == 0x10);
+ mu_assert("Incorrect size for `s_2`", s_2->len == 0x20);
+ mu_assert("Incorrect size for `s_3`", s_3->len == 0x40);
stream_free(s_1);
stream_free(s_2);
stream_free(s_3);
+ return NULL;
}
-static char *test_stream_rw(void) {
+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);
+ struct stream *s = stream_new(0x4);
+ stream_write(s, "\x00\x01\x02\x03", 4);
+ mu_assert("Write failure", !memcmp(s->_start, "\x00\x01\x02\x03", 4));
+ mu_assert("Cursor not incremented", s->_cur - s->_start == 4);
+ s->_cur = s->_start;
+
stream_read(dest, s, 4);
mu_assert("Read failure", !memcmp(dest, "\x00\x01\x02\x03", 4));
- stream_free(s_1);
+ mu_assert("Cursor not incremented", s->_cur - s->_start == 4);
+ stream_free(s);
+ return NULL;
}
diff --git a/test/test_io.h b/test/test_io.h
new file mode 100644
index 0000000..c750214
--- /dev/null
+++ b/test/test_io.h
@@ -0,0 +1,23 @@
+/* test_io.h -- MinUnit test cases for io.c
+
+ 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/>. */
+
+#pragma once
+
+char *test_stream_obj(void);
+char *test_stream_rw(void);
diff --git a/test/test_run.c b/test/test_run.c
new file mode 100644
index 0000000..8728b81
--- /dev/null
+++ b/test/test_run.c
@@ -0,0 +1,46 @@
+/* test_io.c -- MinUnit test runner.
+
+ 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 "minunit.h"
+
+#include "test_header.h"
+#include "test_io.h"
+
+int tests_run = 0;
+
+
+static char *run_all_tests(void) {
+ mu_run_test(test_stream_obj);
+ mu_run_test(test_stream_rw);
+ mu_run_test(test_header_read);
+ return NULL;
+}
+
+
+int main(void) {
+ char *ret = run_all_tests();
+ if (ret) {
+ printf("%s\n", ret);
+ return 1;
+ }
+ printf("Successful tests: %d\n", tests_run);
+ return 0;
+}