This repository has been archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
150 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Oops, something went wrong.