summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-02-19 10:57:47 -0500
committerjakob <jakob@memeware.net>2017-02-19 10:57:47 -0500
commit32fb7b11d83138cc288d62c1f1674d95cc94e8de (patch)
tree290c5a27b58e24bb82bd46decba0aa5e1282e003 /test
parent1fc6cc323dbaa5387d84630615c0d4cab0c1c5ba (diff)
Implemented table linked list, decompression and encryption. Tests have been improved.
Diffstat (limited to 'test')
-rw-r--r--test/minunit.h1
-rw-r--r--test/test_header.c9
-rw-r--r--test/test_header.h1
-rw-r--r--test/test_io.c33
-rw-r--r--test/test_io.h3
-rw-r--r--test/test_run.c5
-rw-r--r--test/test_table.c36
-rw-r--r--test/test_table.h22
8 files changed, 109 insertions, 1 deletions
diff --git a/test/minunit.h b/test/minunit.h
index 7422998..80ef040 100644
--- a/test/minunit.h
+++ b/test/minunit.h
@@ -1,3 +1,4 @@
+#pragma once
#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_header.c b/test/test_header.c
index 1ae4e19..15aa18c 100644
--- a/test/test_header.c
+++ b/test/test_header.c
@@ -30,9 +30,18 @@ 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_rewind(s);
+ memcpy(s->_start, "\x58\x50\x33\x0d\x0a\x20\x0a\x1a\x8b\x67\x01\x17\x00"
+ "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x80\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\xd1\xfe\x56\x0b\x00\x00\x00\x00", 42);
+ h = read_header(s);
+ mu_assert("Header read as invalid", h != NULL);
+
stream_free(s);
return NULL;
}
diff --git a/test/test_header.h b/test/test_header.h
index 83613ce..5a23235 100644
--- a/test/test_header.h
+++ b/test/test_header.h
@@ -20,4 +20,3 @@
#pragma once
char *test_header_read(void);
-
diff --git a/test/test_io.c b/test/test_io.c
index fd1e483..86dde8e 100644
--- a/test/test_io.c
+++ b/test/test_io.c
@@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with Nekopack. If not, see <http://www.gnu.org/licenses/>. */
+#include <stdint.h>
#include <string.h>
#include "minunit.h"
@@ -54,3 +55,35 @@ char *test_stream_rw(void) {
stream_free(s);
return NULL;
}
+
+
+char *test_stream_realloc(void) {
+ struct stream *s = stream_new(0x2);
+ stream_write(s, "\x00\x01\x02\x03", 4);
+ mu_assert("`len` not modified", s->len > 0x2);
+ return NULL;
+}
+
+
+char *test_stream_xor(void) {
+ struct stream *s = stream_new(2);
+ stream_write(s, "\x01\x01", 2);
+ stream_xor(s, 1, 0);
+ mu_assert("Initial key failure", !memcmp(s->_start, "\x00\x01", 2));
+ stream_xor(s, 0, 1);
+ mu_assert("Primary key failure", !memcmp(s->_start, "\x01\x00", 2));
+ stream_free(s);
+ return NULL;
+}
+
+
+char *test_stream_nav(void) {
+ struct stream *s = stream_new(2);
+ mu_assert("Cursor not at beginning", stream_tell(s) == 0);
+ stream_seek(s, 2);
+ mu_assert("Cursor not advanced", stream_tell(s) == 2);
+ stream_rewind(s);
+ mu_assert("Cursor not rewinded", stream_tell(s) == 0);
+ stream_free(s);
+ return NULL;
+}
diff --git a/test/test_io.h b/test/test_io.h
index c750214..ab3547f 100644
--- a/test/test_io.h
+++ b/test/test_io.h
@@ -21,3 +21,6 @@
char *test_stream_obj(void);
char *test_stream_rw(void);
+char *test_stream_realloc(void);
+char *test_stream_xor(void);
+char *test_stream_nav(void);
diff --git a/test/test_run.c b/test/test_run.c
index 8728b81..7ec1403 100644
--- a/test/test_run.c
+++ b/test/test_run.c
@@ -23,6 +23,7 @@
#include "test_header.h"
#include "test_io.h"
+#include "test_table.h"
int tests_run = 0;
@@ -30,7 +31,11 @@ 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_stream_realloc);
+ mu_run_test(test_stream_xor);
+ mu_run_test(test_stream_nav);
mu_run_test(test_header_read);
+ mu_run_test(test_table_list);
return NULL;
}
diff --git a/test/test_table.c b/test/test_table.c
new file mode 100644
index 0000000..efdac3d
--- /dev/null
+++ b/test/test_table.c
@@ -0,0 +1,36 @@
+/* test_table.c -- MinUnit test cases for table.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 "minunit.h"
+
+#include "table.h"
+
+
+char *test_table_list(void) {
+ struct table_entry *root = calloc(sizeof(struct table_entry), 1);
+ mu_assert("Structure not zeroed", root->next == NULL);
+ struct table_entry *next = calloc(sizeof(struct table_entry), 1);
+ next->key = 0xffffffff;
+ entry_append(root, next);
+ mu_assert("Entry not inserted", root->next->key == 0xffffffff);
+ entry_free(root);
+ return NULL;
+}
diff --git a/test/test_table.h b/test/test_table.h
new file mode 100644
index 0000000..1c6fe03
--- /dev/null
+++ b/test/test_table.h
@@ -0,0 +1,22 @@
+/* test_table.h -- MinUnit test cases for table.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_table_list(void);