1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/* 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 "compress.h"
#include "io.h"
#include "minunit.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;
}
const 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("[compress] test_compress: Could not open test vectors",
s != NULL && expected != NULL);
struct stream *res = stream_deflate(s, s->len);
mu_assert("[compress] test_compress: Expected compression not met",
streams_eq(res, expected));
stream_free(s);
stream_free(expected);
stream_free(res);
return NULL;
}
const 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("[compress] test_decompress: Could not open test vectors",
s != NULL && expected != NULL);
struct stream *res = stream_inflate(s, s->len, 176608);
mu_assert("[compress] test_decompress: Expected compression not met",
streams_eq(res, expected));
stream_free(s);
stream_free(expected);
stream_free(res);
return NULL;
}
|