summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_cli.c16
-rw-r--r--test/test_compress.c72
-rw-r--r--test/test_compress.h23
-rw-r--r--test/test_run.c3
-rw-r--r--test/vectors/test.binbin0 -> 176569 bytes
-rwxr-xr-xtest/vectors/test.pngbin0 -> 176608 bytes
6 files changed, 106 insertions, 8 deletions
diff --git a/test/test_cli.c b/test/test_cli.c
index eed7e30..86d6a2e 100644
--- a/test/test_cli.c
+++ b/test/test_cli.c
@@ -37,19 +37,19 @@ char *test_out_path(void) {
}
-char *test_vararg_index(void) {
- char *argv[] = {"nekopack", "-l", "a.xp3"};
- struct params p = parse_args(3, argv);
- mu_assert("Invalid vararg index", !strcmp("a.xp3", argv[p.vararg_index]));
+char *test_game_id(void) {
+ char *argv[] = {"nekopack", "-g", "nekopara_volume_1", "a.xp3"};
+ struct params p = parse_args(4, argv);
+ mu_assert("Incorrect game ID", p.game == NEKOPARA_VOLUME_1);
free(p.out);
return NULL;
}
-char *test_game_id(void) {
- char *argv[] = {"nekopack", "-g", "nekopara_volume_1", "a.xp3"};
- struct params p = parse_args(4, argv);
- mu_assert("Incorrect game ID", p.game == NEKOPARA_VOLUME_1);
+char *test_vararg_index(void) {
+ char *argv[] = {"nekopack", "-l", "a.xp3"};
+ struct params p = parse_args(3, argv);
+ mu_assert("Invalid vararg index", !strcmp("a.xp3", argv[p.vararg_index]));
free(p.out);
return NULL;
}
diff --git a/test/test_compress.c b/test/test_compress.c
new file mode 100644
index 0000000..583dd8b
--- /dev/null
+++ b/test/test_compress.c
@@ -0,0 +1,72 @@
+/* test_compress.c -- MinUnit test cases for compress.c
+
+ Copyright (C) 2017 Jakob Kreuze, 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 <stdbool.h>
+
+#include "minunit.h"
+
+#include "compress.h"
+#include "io.h"
+
+extern int tests_run;
+
+/* FIXME: This won't hold up for the future. Even if it works across
+ different versions of zlib, if the compression rate is ever changed
+ this test will fail. */
+
+/* TODO: Replace with a proper stream comparison and put it in io.c? */
+static bool streams_eq(struct stream *a, struct stream *b) {
+ if (a->len != b->len)
+ return false;
+ for (unsigned long i = 0; i < a->len; i++) {
+ if (a->_start[i] != b->_start[i])
+ return false;
+ }
+ return true;
+}
+
+
+char *test_compress(void) {
+ struct stream *s = stream_from_file("test/vectors/test.png");
+ struct stream *expected = stream_from_file("test/vectors/test.bin");
+ mu_assert("Could not open test vectors", s != NULL && expected != NULL);
+
+ struct stream *res = stream_deflate(s, s->len);
+ mu_assert("Expected compression not met", streams_eq(res, expected));
+
+ stream_free(s);
+ stream_free(expected);
+ stream_free(res);
+ return NULL;
+}
+
+
+char *test_decompress(void) {
+ struct stream *s = stream_from_file("test/vectors/test.bin");
+ struct stream *expected = stream_from_file("test/vectors/test.png");
+ mu_assert("Could not open test vectors", s != NULL && expected != NULL);
+
+ struct stream *res = stream_inflate(s, s->len, 176608);
+ mu_assert("Expected compression not met", streams_eq(res, expected));
+
+ stream_free(s);
+ stream_free(expected);
+ stream_free(res);
+ return NULL;
+}
diff --git a/test/test_compress.h b/test/test_compress.h
new file mode 100644
index 0000000..0a1f3ea
--- /dev/null
+++ b/test/test_compress.h
@@ -0,0 +1,23 @@
+/* test_compress.h -- MinUnit test cases for compress.c
+
+ Copyright (C) 2017 Jakob Kreuze, 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_compress(void);
+char *test_decompress(void);
diff --git a/test/test_run.c b/test/test_run.c
index f1dc80e..4263c7f 100644
--- a/test/test_run.c
+++ b/test/test_run.c
@@ -22,6 +22,7 @@
#include "minunit.h"
#include "test_cli.h"
+#include "test_compress.h"
#include "test_crypto.h"
#include "test_encoding.h"
#include "test_header.h"
@@ -35,6 +36,8 @@ static char *run_all_tests(void) {
mu_run_test(test_out_path);
mu_run_test(test_vararg_index);
mu_run_test(test_game_id);
+ mu_run_test(test_compress);
+ mu_run_test(test_decompress);
mu_run_test(test_derive_initial);
mu_run_test(test_derive_primary);
mu_run_test(test_stream_obj);
diff --git a/test/vectors/test.bin b/test/vectors/test.bin
new file mode 100644
index 0000000..19fd87b
--- /dev/null
+++ b/test/vectors/test.bin
Binary files differ
diff --git a/test/vectors/test.png b/test/vectors/test.png
new file mode 100755
index 0000000..8fee322
--- /dev/null
+++ b/test/vectors/test.png
Binary files differ