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.
This commit is contained in:
Janne Grunau 2012-01-31 21:39:48 +01:00
parent c0bc7bd1e7
commit e67e3a3f4a
3 changed files with 45 additions and 18 deletions

View File

@ -19,52 +19,80 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "avcodec.h" #include "libavutil/mem.h"
#include "dsputil.h"
#include "get_bits.h" #include "get_bits.h"
#include "golomb.h" #include "golomb.h"
#include "put_bits.h" #include "put_bits.h"
#undef printf #undef fprintf
#define COUNT 8000 #define COUNT 8191
#define SIZE (COUNT * 40) #define SIZE (COUNT * 4)
int main(void) int main(void)
{ {
int i; int i, ret = 0;
uint8_t temp[SIZE]; uint8_t *temp;
PutBitContext pb; PutBitContext pb;
GetBitContext gb; GetBitContext gb;
temp = av_malloc(SIZE);
if (!temp)
return 2;
init_put_bits(&pb, temp, SIZE); init_put_bits(&pb, temp, SIZE);
printf("testing unsigned exp golomb\n");
for (i = 0; i < COUNT; i++) for (i = 0; i < COUNT; i++)
set_ue_golomb(&pb, i); set_ue_golomb(&pb, i);
flush_put_bits(&pb); flush_put_bits(&pb);
init_get_bits(&gb, temp, 8 * SIZE); init_get_bits(&gb, temp, 8 * SIZE);
for (i = 0; i < COUNT; i++) { 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); j = get_ue_golomb(&gb);
if (j != i) if (j != i) {
printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); 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); init_put_bits(&pb, temp, SIZE);
printf("testing signed exp golomb\n");
for (i = 0; i < COUNT; i++) for (i = 0; i < COUNT; i++)
set_se_golomb(&pb, i - COUNT / 2); set_se_golomb(&pb, i - COUNT / 2);
flush_put_bits(&pb); flush_put_bits(&pb);
init_get_bits(&gb, temp, 8 * SIZE); init_get_bits(&gb, temp, 8 * SIZE);
for (i = 0; i < COUNT; i++) { 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); j = get_se_golomb(&gb);
if (j != i - COUNT / 2) if (j != i - COUNT / 2) {
printf("mismatch at %d (%d should be %d) bits: %6X\n", i, j, i, s); 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;
} }

View File

@ -1,6 +1,7 @@
FATE_TESTS += fate-golomb FATE_TESTS += fate-golomb
fate-golomb: libavcodec/golomb-test$(EXESUF) fate-golomb: libavcodec/golomb-test$(EXESUF)
fate-golomb: CMD = run libavcodec/golomb-test fate-golomb: CMD = run libavcodec/golomb-test
fate-golomb: REF = /dev/null
FATE_TESTS += fate-iirfilter FATE_TESTS += fate-iirfilter
fate-iirfilter: libavcodec/iirfilter-test$(EXESUF) fate-iirfilter: libavcodec/iirfilter-test$(EXESUF)

View File

@ -1,2 +0,0 @@
testing unsigned exp golomb
testing signed exp golomb