From 26f037cf7d984624f1fe70a7dd2cd0d84fa9512b Mon Sep 17 00:00:00 2001 From: Mike Iovine <mike.iovine7@gmail.com> Date: Sat, 4 Apr 2020 09:45:09 -0700 Subject: [PATCH] Add more tests --- tests/inflate_test.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/inflate_test.cpp b/tests/inflate_test.cpp index 9b69af0..df3d7ea 100644 --- a/tests/inflate_test.cpp +++ b/tests/inflate_test.cpp @@ -198,12 +198,27 @@ TEST (HuffmanTests, TestReadChunkFixed) { ASSERT_EQ (read_chunk((char *) buf, HUFFMAN_FIXED), i); } + + /* Test reading all possible fixed distances */ - // TODO test fixed distance codes as well? -} + /* + * Mapping of distance literal -> code, again, as laid out in memory. + */ + int codes_dist[30] = {0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, + 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, + 27, 7, 23}; + + for (int i = 0; i < 30; i++) { + reset_pos(); -// TODO -TEST (HuffmanTests, TestReadLens) {} + int code = codes_dist[i]; + unsigned char buf[1]; + + buf[0] = code; + ASSERT_EQ (read_chunk((char *) buf, HUFFMAN_FIXED_DISTS), i); + } + +} int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); -- GitLab