diff options
author | Mathis Rosenhauer <rosenhauer@dkrz.de> | 2012-10-23 13:13:03 +0200 |
---|---|---|
committer | Thomas Jahns <jahns@dkrz.de> | 2013-02-19 11:33:00 +0100 |
commit | fca3dc1f18393aabacf34bb1736ae9a05253e5d5 (patch) | |
tree | ea7d40eb725c28642b08d5c37c5d6d5c300b7e20 /tests | |
parent | ec53d5ad5687e4dce2a2013b67cd522f6ec82786 (diff) | |
download | libaec-fca3dc1f18393aabacf34bb1736ae9a05253e5d5.tar.gz libaec-fca3dc1f18393aabacf34bb1736ae9a05253e5d5.tar.bz2 libaec-fca3dc1f18393aabacf34bb1736ae9a05253e5d5.zip |
Decoder: turn FSM switch into functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check_aec.c | 87 | ||||
-rw-r--r-- | tests/check_aec.h | 2 | ||||
-rw-r--r-- | tests/check_code_options.c | 3 |
3 files changed, 91 insertions, 1 deletions
diff --git a/tests/check_aec.c b/tests/check_aec.c index ac1e167..c7ce581 100644 --- a/tests/check_aec.c +++ b/tests/check_aec.c @@ -58,6 +58,93 @@ int update_state(struct test_state *state) return 0; } +int encode_decode_small(struct test_state *state) +{ + int status, i, to, Bps; + struct aec_stream *strm = state->strm; + + strm->avail_out = state->cbuf_len; + strm->next_out = state->cbuf; + + status = aec_encode_init(strm); + if (status != AEC_OK) { + printf("Init failed.\n"); + return 99; + } + + Bps = strm->bit_per_sample / 8; + for (i = 0; i < state->ibuf_len / Bps; i++) { + strm->avail_in = Bps; + strm->next_in = state->ubuf + i * Bps; + status = aec_encode(strm, AEC_NO_FLUSH); + if (status != AEC_OK) { + printf("Encode failed.\n"); + return 99; + } + } + + status = aec_encode(strm, AEC_FLUSH); + if (status != AEC_OK) { + printf("Encode failed.\n"); + return 99; + } + + aec_encode_end(strm); + + strm->avail_out = state->buf_len; + strm->next_out = state->obuf; + to = strm->total_out; + + status = aec_decode_init(strm); + if (status != AEC_OK) { + printf("Init failed.\n"); + return 99; + } + + for (i = 0; i < to; i++) { + strm->avail_in = 1; + strm->next_in = state->cbuf + i; + status = aec_decode(strm, AEC_NO_FLUSH); + if (status != AEC_OK) { + printf("Decode failed.\n"); + return 99; + } + } + + status = aec_decode(strm, AEC_FLUSH); + if (status != AEC_OK) { + printf("Decode failed.\n"); + return 99; + } + + if (memcmp(state->ubuf, state->obuf, state->ibuf_len)) { + printf("FAIL: Uncompressed output differs from input.\n"); + + printf("\nuncompressed buf"); + for (i = 0; i < 80; i++) { + if (i % 8 == 0) + printf("\n"); + printf("%02x ", state->ubuf[i]); + } + printf("\n\ncompressed buf len %i", to); + for (i = 0; i < 80; i++) { + if (i % 8 == 0) + printf("\n"); + printf("%02x ", state->cbuf[i]); + } + printf("\n\ndecompressed buf"); + for (i = 0; i < 80; i++) { + if (i % 8 == 0) + printf("\n"); + printf("%02x ", state->obuf[i]); + } + printf("\n"); + return 99; + } + aec_decode_end(strm); + return 0; +} + int encode_decode(struct test_state *state) { int status, i, to; diff --git a/tests/check_aec.h b/tests/check_aec.h index 884f610..8b9847a 100644 --- a/tests/check_aec.h +++ b/tests/check_aec.h @@ -3,6 +3,7 @@ #include "libaec.h" struct test_state { + int (* codec)(struct test_state *state); int id_len; int byte_per_sample; unsigned char *ubuf; @@ -18,6 +19,7 @@ struct test_state { }; int update_state(struct test_state *state); +int encode_decode_small(struct test_state *state); int encode_decode(struct test_state *state); diff --git a/tests/check_code_options.c b/tests/check_code_options.c index befb72b..de8dce1 100644 --- a/tests/check_code_options.c +++ b/tests/check_code_options.c @@ -20,7 +20,7 @@ int check_block_sizes(struct test_state *state, int id, int id_len) for (rsi = 1; rsi <= max_rsi; rsi++) { state->strm->rsi = rsi; - status = encode_decode(state); + status = state->codec(state); if (status) return status; @@ -212,6 +212,7 @@ int main (void) strm.flags = AEC_DATA_PREPROCESS; state.strm = &strm; + state.codec = encode_decode_small; printf("----------------------------\n"); printf("Checking LSB first, unsigned\n"); |