1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <schroedinger/schro.h>
int fail;
void
dump_bits (SchroBits *bits, int n)
{
int i;
for(i=0;i<n*8;i++){
printf(" %d", (bits->buffer->data[(i>>3)] >> (7 - (i&7))) & 1);
}
printf("\n");
}
int test (void)
{
SchroBuffer *buffer = schro_buffer_new_and_alloc (300);
SchroBits *bits;
SchroBits bits2;
int i;
int chunk1;
int chunk2;
int ref[10];
int x;
chunk1 = rand()&0x1f;
bits = schro_bits_new ();
schro_bits_encode_init (bits, buffer);
for(i=0;i<chunk1;i++){
schro_bits_encode_bit (bits, rand()&1);
}
chunk2 = 0;
for(i=0;i<10;i++){
ref[i] = rand() & 0xf;
schro_bits_encode_sint (bits, ref[i]);
chunk2 += schro_bits_estimate_sint (ref[i]);
}
for(i=0;i<100;i++){
schro_bits_encode_bit (bits, rand()&1);
}
schro_bits_flush (bits);
schro_bits_free (bits);
bits = schro_bits_new ();
schro_bits_decode_init (bits, buffer);
schro_bits_copy (&bits2, bits);
schro_bits_skip_bits (&bits2, chunk1);
schro_bits_set_length (&bits2, chunk2);
printf("chunk1 %d\n", chunk1);
for(i=0;i<10;i++){
x = schro_bits_decode_sint (&bits2);
printf("%d %d\n", ref[i], x);
if (x != ref[i]) fail = TRUE;
}
schro_bits_free (bits);
return 0;
}
int
main (int argc, char *argv[])
{
schro_init();
srand(time(NULL));
test();
return fail;
}
|