From ded38a043a5b29379afdcf4076ce0b88b101b8b2 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 10 Feb 2018 15:09:29 +1100 Subject: [PATCH] Add testdata/animated-red-blue.gif --- test/c/std/gif.c | 67 +++++++++++++++++++++++----- test/c/std/zlib.c | 2 +- test/testdata/README.md | 3 ++ test/testdata/animated-red-blue.gif | Bin 0 -> 2913 bytes 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 test/testdata/animated-red-blue.gif diff --git a/test/c/std/gif.c b/test/c/std/gif.c index 4b1df790..8e9094e2 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -54,7 +54,8 @@ void test_basic_bad_receiver() { wuffs_base__reader1 src = {0}; wuffs_gif__status status = wuffs_gif__decoder__decode_config(NULL, &ic, src); if (status != WUFFS_GIF__ERROR_BAD_RECEIVER) { - FAIL("status: got %d, want %d", status, WUFFS_GIF__ERROR_BAD_RECEIVER); + FAIL("decode_config: got %d, want %d", status, + WUFFS_GIF__ERROR_BAD_RECEIVER); } } @@ -65,7 +66,7 @@ void test_basic_initializer_not_called() { wuffs_base__reader1 src = {0}; wuffs_gif__status status = wuffs_gif__decoder__decode_config(&dec, &ic, src); if (status != WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED) { - FAIL("status: got %d, want %d", status, + FAIL("decode_config: got %d, want %d", status, WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED); } } @@ -75,7 +76,7 @@ void test_basic_wuffs_version_bad() { wuffs_gif__decoder dec; wuffs_gif__decoder__initialize(&dec, 0, 0); // 0 is not WUFFS_VERSION. if (dec.private_impl.status != WUFFS_GIF__ERROR_BAD_WUFFS_VERSION) { - FAIL("status: got %d, want %d", dec.private_impl.status, + FAIL("decode_config: got %d, want %d", dec.private_impl.status, WUFFS_GIF__ERROR_BAD_WUFFS_VERSION); return; } @@ -235,7 +236,7 @@ bool do_test_wuffs_lzw_decode(const char* src_filename, } if ((status != WUFFS_GIF__SUSPENSION_SHORT_READ) && (status != WUFFS_GIF__SUSPENSION_SHORT_WRITE)) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32 + FAIL("decode: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32 " (%s)", status, wuffs_gif__status__string(status), WUFFS_GIF__SUSPENSION_SHORT_READ, @@ -398,7 +399,7 @@ bool do_test_wuffs_gif_decode(const char* filename, wuffs_gif__status status = wuffs_gif__decoder__decode_config(&dec, &ic, src_reader); if (status != WUFFS_GIF__STATUS_OK) { - FAIL("status: got %" PRIi32 " (%s)", status, + FAIL("decode_config: got %" PRIi32 " (%s)", status, wuffs_gif__status__string(status)); return false; } @@ -439,8 +440,8 @@ bool do_test_wuffs_gif_decode(const char* filename, } if ((status != WUFFS_GIF__SUSPENSION_SHORT_READ) && (status != WUFFS_GIF__SUSPENSION_SHORT_WRITE)) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32 - " (%s)", + FAIL("decode_frame: got %" PRIi32 " (%s), want %" PRIi32 + " (%s) or %" PRIi32 " (%s)", status, wuffs_gif__status__string(status), WUFFS_GIF__SUSPENSION_SHORT_READ, wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_READ), @@ -496,7 +497,7 @@ bool do_test_wuffs_gif_decode(const char* filename, { if (src.ri == src.wi) { - FAIL("decode_config returned \"ok\" but src was exhausted"); + FAIL("decode_frame returned \"ok\" but src was exhausted"); return false; } wuffs_base__writer1 got_writer = {.buf = &got}; @@ -504,13 +505,13 @@ bool do_test_wuffs_gif_decode(const char* filename, wuffs_gif__status status = wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader); if (status != WUFFS_GIF__SUSPENSION_END_OF_DATA) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, + FAIL("decode_frame: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, wuffs_gif__status__string(status), WUFFS_GIF__SUSPENSION_END_OF_DATA, wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_END_OF_DATA)); return false; } if (src.ri != src.wi) { - FAIL("decode_config returned \"end of data\" but src was not exhausted"); + FAIL("decode_frame returned \"end of data\" but src was not exhausted"); return false; } } @@ -533,10 +534,11 @@ void test_wuffs_gif_call_sequence() { wuffs_base__writer1 got_writer = {.buf = &got}; wuffs_base__reader1 src_reader = {.buf = &src}; + wuffs_gif__status status = wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader); if (status != WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, + FAIL("decode_frame: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, wuffs_gif__status__string(status), WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE, wuffs_gif__status__string(WUFFS_GIF__ERROR_INVALID_CALL_SEQUENCE)); @@ -544,6 +546,46 @@ void test_wuffs_gif_call_sequence() { } } +void test_wuffs_gif_decode_animated() { + CHECK_FOCUS(__func__); + + wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE}; + wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE}; + + if (!read_file(&src, "../../testdata/animated-red-blue.gif")) { + return; + } + + wuffs_gif__decoder dec; + wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0); + + wuffs_base__image_config ic = {{0}}; + wuffs_base__writer1 got_writer = {.buf = &got}; + wuffs_base__reader1 src_reader = {.buf = &src}; + + wuffs_gif__status status = + wuffs_gif__decoder__decode_config(&dec, &ic, src_reader); + if (status != WUFFS_GIF__STATUS_OK) { + FAIL("decode_config: got %" PRIi32 " (%s)", status, + wuffs_gif__status__string(status)); + return; + } + + // TODO: check the loop count. + + // animated-red-blue.gif should have 4 frames. + int i; + for (i = 0; i < 0; i++) { // TODO: increase the 0 in "i < 0" to 4. + got.wi = 0; + status = wuffs_gif__decoder__decode_frame(&dec, got_writer, src_reader); + if (status != WUFFS_GIF__STATUS_OK) { + FAIL("decode_frame #%d: got %" PRIi32 " (%s)", i, status, + wuffs_gif__status__string(status)); + return; + } + } +} + void test_wuffs_gif_decode_input_is_a_gif() { CHECK_FOCUS(__func__); do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif", @@ -593,7 +635,7 @@ void test_wuffs_gif_decode_input_is_a_png() { wuffs_gif__status status = wuffs_gif__decoder__decode_config(&dec, &ic, src_reader); if (status != WUFFS_GIF__ERROR_BAD_GIF_HEADER) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, + FAIL("decode_config: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, wuffs_gif__status__string(status), WUFFS_GIF__ERROR_BAD_GIF_HEADER, wuffs_gif__status__string(WUFFS_GIF__ERROR_BAD_GIF_HEADER)); return; @@ -773,6 +815,7 @@ proc tests[] = { test_wuffs_lzw_decode_pi, // test_wuffs_gif_call_sequence, // + test_wuffs_gif_decode_animated, // test_wuffs_gif_decode_input_is_a_gif, // test_wuffs_gif_decode_input_is_a_gif_many_big_reads, // test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, // diff --git a/test/c/std/zlib.c b/test/c/std/zlib.c index 54c8eca2..2beb9c21 100644 --- a/test/c/std/zlib.c +++ b/test/c/std/zlib.c @@ -204,7 +204,7 @@ void test_wuffs_zlib_checksum_mismatch() { wuffs_zlib__status status = wuffs_zlib__decoder__decode(&dec, got_writer, src_reader); if (status != WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH) { - FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, + FAIL("decode: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status, wuffs_zlib__status__string(status), WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH, wuffs_zlib__status__string(WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH)); diff --git a/test/testdata/README.md b/test/testdata/README.md index 7185f70c..9092bf7c 100644 --- a/test/testdata/README.md +++ b/test/testdata/README.md @@ -22,6 +22,9 @@ world examples of various file formats, or deriviations of them. +animated-red-blue.gif is an original animation by Nigel Tao +. + bricks-\* are various encodings of an original photo by Nigel Tao . diff --git a/test/testdata/animated-red-blue.gif b/test/testdata/animated-red-blue.gif new file mode 100644 index 0000000000000000000000000000000000000000..8f727c0ca754648d598071112dd61b2cd3d7e6f2 GIT binary patch literal 2913 zcmZ?wbhEHbbYL)G_|51cH78d`ltp3~B{I|3F@8Iy?$?3m~%YQew{~jLyy}bVW`26?t`yUYSKPc#bNXY-N zu>TPe|D&S*$He@Pi~FCD@INW(e@e>#w6y;j8UM4g{^#WU&&&H?Q1HK~=zmGc|FW|G z6&3%hs{Ys1{I9F~-`M!Sx%q!<>;Lxl|DB!xySxAQ_Wtkh|37i!|H+g8Po4UI`t<)Z zXa1i(`~Tdz|L4#Dzi{FI#f$$hUHX6d^8YJW{$IWN|Jt?x*RTJ-apV8ZoBwa!`hWZO z|2ud7-@W_)-o5|#@Be@B;Qzyi{~ta2|M>C$Cr|!Aefs~|v;WVZ|9|n~|I3&EU%mSO z`t|=eZ~ni1`~Tg$|L@=b|M21e$B+L%eft0T^Zzej{(t@Y|J%3!-@pI=@#Fu`pZ|aT z`v3d)|382J|NZ;_-@l__KX76HU-3V;pKD04vtxj(k)8oFBNGFI;!hS9E{6XMI-tw} z$|mg$3=B+6Oe`!cY;0^C92{I+Ts%BHe0+QY0s=xpLLwp}Vq#(v5)x8UQZh0!a&mGC z3JOX}N-8QUYHDg48X8(!S~@y9dU|>W1_nk(MkXdEW@cs<78X`kRyH;^c6N3S4h~LE zPA)DkZfQQ86(wadB}82?IOuHe<$&S+i!%nKNhJym<>2ELgN?(UK)gmMvSh zV#SJ8t5&U9vu548bsIKp*tBWWmMvShZQHhE$BtdQcJ0}-XWzbk2M!!Kbm-8LBS(%M zJ9gs4iBqReojG&n+_`fXE?l^D>C%-eSFT;VcH_p4TeoiAxpU{C+suU@@*^XA>VcOO1{`1I-1moHzwef##~$B$pXe*O9L=ik47qs7w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