shithub: opus

Download patch

ref: 5f089d224d599613dd19294e3919f4bb1ba72246
parent: 16b25e908a57ee1ca16db2b6d0b8135312f4b6ad
author: Timothy B. Terriberry <[email protected]>
date: Tue Sep 6 18:28:26 EDT 2011

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).

--- a/libcelt/tests/ectest.c
+++ b/libcelt/tests/ectest.c
@@ -100,6 +100,37 @@
      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++){