Skip to content
Snippets Groups Projects
Commit 5f089d22 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Jean-Marc Valin
Browse files

Add an encoder busting test.

This tests the behavior when merging the last few raw bits into
 the final range coder byte causes a bust.
This is mostly to make Greg Maxwell happy about his code coverage.
In theory the code in question should never be hit (we should only
 bust if the user buffer is too small for SILK, which doesn't use
 raw bits).
parent 16b25e90
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,37 @@ int main(int _argc,char **_argv){
ldexp(nbits2,-3),ldexp(nbits,-3));
ret=-1;
}
/*Testing an encoder bust prefers range coder data over raw bits.
This isn't a general guarantee, will only work for data that is buffered in
the encoder state and not yet stored in the user buffer, and should never
get used in practice.
It's mostly here for code coverage completeness.*/
/*Start with a 16-bit buffer.*/
ec_enc_init(&enc,ptr,2);
/*Write 7 raw bits.*/
ec_enc_bits(&enc,0x55,7);
/*Write 12.3 bits of range coder data.*/
ec_enc_uint(&enc,1,2);
ec_enc_uint(&enc,2,3);
ec_enc_uint(&enc,3,4);
ec_enc_uint(&enc,4,5);
ec_enc_uint(&enc,2,6);
ec_enc_uint(&enc,5,7);
ec_enc_done(&enc);
ec_dec_init(&dec,ptr,2);
if(!enc.error
/*The raw bits should have been overwritten by the range coder data.*/
||ec_dec_bits(&dec,7)!=0x5D
/*And all the range coder data should have been encoded correctly.*/
||ec_dec_uint(&dec,2)!=1
||ec_dec_uint(&dec,3)!=2
||ec_dec_uint(&dec,4)!=3
||ec_dec_uint(&dec,5)!=4
||ec_dec_uint(&dec,6)!=2
||ec_dec_uint(&dec,7)!=5){
fprintf(stderr,"Encoder bust overwrote range coder data with raw bits.\n");
ret=-1;
}
srand(seed);
fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536);
for(i=0;i<409600;i++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment