diff options
author | Janne Grunau <janne-libav@jannau.net> | 2012-02-01 00:39:48 +0400 |
---|---|---|
committer | Janne Grunau <janne-libav@jannau.net> | 2012-02-01 04:18:55 +0400 |
commit | e67e3a3f4a43ad08115b4fcebce39fb487728eb3 (patch) | |
tree | 606e367096b19ed67c18ebd2d417571e5827cd17 /libavcodec | |
parent | c0bc7bd1e785c3cfe1ce988b04108694b95b5c9d (diff) |
fate-golomb: extend golomb-test to get_ue_golomb_long()
get_ue_golomb_long() is only tested for values up to 2^15 - 2 since
we can not write larger values.
Silence the test on success and return a non-zero value on error.
Use an heap scratch buffer instead of large stack buffer.
Remove unneeded includes.
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/golomb-test.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/libavcodec/golomb-test.c b/libavcodec/golomb-test.c index 3dbf9d14cb..bc90f36baf 100644 --- a/libavcodec/golomb-test.c +++ b/libavcodec/golomb-test.c @@ -19,52 +19,80 @@ #include <stdint.h> #include <stdio.h> -#include "avcodec.h" -#include "dsputil.h" +#include "libavutil/mem.h" + #include "get_bits.h" #include "golomb.h" #include "put_bits.h" -#undef printf -#define COUNT 8000 -#define SIZE (COUNT * 40) +#undef fprintf +#define COUNT 8191 +#define SIZE (COUNT * 4) int main(void) { - int i; - uint8_t temp[SIZE]; + int i, ret = 0; + uint8_t *temp; PutBitContext pb; GetBitContext gb; + temp = av_malloc(SIZE); + if (!temp) + return 2; + init_put_bits(&pb, temp, SIZE); - printf("testing unsigned exp golomb\n"); for (i = 0; i < COUNT; i++) set_ue_golomb(&pb, i); flush_put_bits(&pb); init_get_bits(&gb, temp, 8 * SIZE); for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 24); + int j, s = show_bits(&gb, 25); j = get_ue_golomb(&gb); - if (j != i) - printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); + if (j != i) { + fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", + i, j, s); + ret = 1; + } + } + +#define EXTEND(i) (i << 3 | i & 7) + init_put_bits(&pb, temp, SIZE); + for (i = 0; i < COUNT; i++) + set_ue_golomb(&pb, EXTEND(i)); + flush_put_bits(&pb); + + init_get_bits(&gb, temp, 8 * SIZE); + for (i = 0; i < COUNT; i++) { + int j, s = show_bits_long(&gb, 32); + + j = get_ue_golomb_long(&gb); + if (j != EXTEND(i)) { + fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " + "bits: %8x\n", EXTEND(i), j, s); + ret = 1; + } } init_put_bits(&pb, temp, SIZE); - printf("testing signed exp golomb\n"); for (i = 0; i < COUNT; i++) set_se_golomb(&pb, i - COUNT / 2); flush_put_bits(&pb); init_get_bits(&gb, temp, 8 * SIZE); for (i = 0; i < COUNT; i++) { - int j, s = show_bits(&gb, 24); + int j, s = show_bits(&gb, 25); j = get_se_golomb(&gb); - if (j != i - COUNT / 2) - printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); + if (j != i - COUNT / 2) { + fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", + i - COUNT / 2, j, s); + ret = 1; + } } - return 0; + av_free(temp); + + return ret; } |