Add lzw_decoder.set_literal_width.

This commit is contained in:
Nigel Tao committed 2017-06-11 14:02:05 +10:00
1 parent c27bec10d3
commit 019e83f190
8 files changed
+170 -31

No files matched your search

+37 -9
View File
@@ -30,7 +30,7 @@ void test_constructor_not_called() {
}
}
void test_bad_argument() {
void test_bad_argument_null() {
test_funcname = __func__;
puffs_gif_lzw_decoder dec;
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
@@ -41,6 +41,33 @@ void test_bad_argument() {
}
}
void test_bad_argument_out_of_range() {
test_funcname = __func__;
puffs_gif_lzw_decoder dec;
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
// Setting to 8 is in the [2..8] range.
puffs_gif_lzw_decoder_set_literal_width(&dec, 8);
if (dec.private_impl.status != puffs_gif_status_ok) {
FAIL("status: got %d, want %d", dec.private_impl.status,
puffs_gif_status_ok);
}
// Setting to 999 is out of range.
puffs_gif_lzw_decoder_set_literal_width(&dec, 999);
if (dec.private_impl.status != puffs_gif_error_bad_argument) {
FAIL("status: got %d, want %d", dec.private_impl.status,
puffs_gif_error_bad_argument);
}
// That error status code should be sticky.
puffs_gif_lzw_decoder_set_literal_width(&dec, 8);
if (dec.private_impl.status != puffs_gif_error_bad_argument) {
FAIL("status: got %d, want %d", dec.private_impl.status,
puffs_gif_error_bad_argument);
}
}
void test_bad_receiver() {
test_funcname = __func__;
puffs_base_buf1 dst = {0};
@@ -139,12 +166,13 @@ void test_status_strings() {
// The empty comments forces clang-format to place one element per line.
test tests[] = {
test_constructor_not_called, //
test_bad_argument, //
test_bad_receiver, //
test_puffs_version_bad, //
test_puffs_version_good, //
test_status_is_error, //
test_status_strings, //
NULL, //
test_constructor_not_called, //
test_bad_argument_null, //
test_bad_argument_out_of_range, //
test_bad_receiver, //
test_puffs_version_bad, //
test_puffs_version_good, //
test_status_is_error, //
test_status_strings, //
NULL, //
};
+3 -2
View File
@@ -48,7 +48,8 @@ void test_lzw_decode() {
goto cleanup0;
}
// The first byte in that file, the LZW literal width, should be 0x08.
if (src.ptr[0] != 0x08) {
uint8_t literal_width = src.ptr[0];
if (literal_width != 0x08) {
FAIL("LZW literal width: got %d, want %d", (int)(src.ptr[0]), 0x08);
goto cleanup0;
}
@@ -56,7 +57,7 @@ void test_lzw_decode() {
puffs_gif_lzw_decoder dec;
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
// TODO: call puffs_gif_lzw_decoder_set_literal_width.
puffs_gif_lzw_decoder_set_literal_width(&dec, literal_width);
puffs_gif_status status =
puffs_gif_lzw_decoder_decode(&dec, &got, &src, false);
if (status != puffs_gif_status_ok) {