diff options
| author | jakob <jakob@memeware.net> | 2017-06-06 15:40:40 -0400 |
|---|---|---|
| committer | jakob <jakob@memeware.net> | 2017-06-06 15:40:40 -0400 |
| commit | cfd5fb6e6fb47e084e66e1e4e2d6a99f19be661e (patch) | |
| tree | 5fcfe91127c67f6dbb94a81848e8c1b9e6ddea7d /test/test_compress.c | |
| parent | 17b658ceadd08d693f23448c276958e2eea5970e (diff) | |
Cleaned up
Diffstat (limited to 'test/test_compress.c')
| -rw-r--r-- | test/test_compress.c | 72 |
1 files changed, 72 insertions, 0 deletions
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; +} |