update to work with new bitbuffer changes

This commit is contained in:
Josh Coalson 2002-05-04 17:43:48 +00:00
parent 2c9dba8600
commit e6ad5576c4
1 changed files with 119 additions and 93 deletions

View File

@ -16,9 +16,31 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "FLAC/assert.h"
#include "private/bitbuffer.h" /* from the libFLAC private include area */
#include <stdio.h>
#include <string.h> /* for memcmp() */
/*
* WATCHOUT! Since FLAC__BitBuffer is a private structure, we use a copy of
* the definition here to get at the internals. Make sure this is kept up
* to date with what is in ../libFLAC/bitbuffer.c
*/
struct FLAC__BitBuffer {
FLAC__blurb *buffer;
unsigned capacity; /* in blurbs */
unsigned blurbs, bits;
unsigned total_bits; /* must always == FLAC__BITS_PER_BLURB*blurbs+bits */
unsigned consumed_blurbs, consumed_bits;
unsigned total_consumed_bits; /* must always == FLAC__BITS_PER_BLURB*consumed_blurbs+consumed_bits */
FLAC__uint16 read_crc16;
#if FLAC__BITS_PER_BLURB == 32
unsigned crc16_align;
#endif
FLAC__blurb save_head, save_tail;
};
static FLAC__bool dummy_read_callback(FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)buffer, (void)bytes, (void)client_data;
@ -32,6 +54,10 @@ int test_bitbuffer()
unsigned i, j;
static FLAC__byte test_pattern1[19] = { 0xaa, 0xf0, 0xaa, 0xbe, 0xaa, 0xaa, 0xaa, 0xa8, 0x30, 0x0a, 0xaa, 0xaa, 0xaa, 0xad, 0xea, 0xdb, 0xee, 0xfa, 0xce };
FLAC__ASSERT(FLAC__BITS_PER_BLURB == 8);
printf("\n+++ unit test: bitbuffer\n\n");
printf("testing new... OK\n");
bb = FLAC__bitbuffer_new();
bb_zero = FLAC__bitbuffer_new();
@ -57,7 +83,7 @@ int test_bitbuffer()
return 1;
FLAC__bitbuffer_dump(bb_one, stdout);
//@@@printf("capacity = %u\n", bb.capacity);
//@@@printf("capacity = %u\n", bb->capacity);
printf("testing zeroes, raw_uint32*... ");
ok =
@ -79,22 +105,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 0) {
printf("FAILED bit count %u != 0\n", bb.bits);
if(bb->bits != 0) {
printf("FAILED bit count %u != 0\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -109,22 +135,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 6) {
printf("FAILED bit count %u != 6\n", bb.bits);
if(bb->bits != 6) {
printf("FAILED bit count %u != 6\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x3d) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x3d) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -139,22 +165,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 6) {
printf("FAILED bit count %u != 6\n", bb.bits);
if(bb->bits != 6) {
printf("FAILED bit count %u != 6\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x3d) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x3d) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -169,22 +195,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 7) {
printf("FAILED bit count %u != 7\n", bb.bits);
if(bb->bits != 7) {
printf("FAILED bit count %u != 7\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x7b) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x7b) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -201,22 +227,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+1);
if(bb->blurbs != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+1);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 0) {
printf("FAILED bit count %u != 0\n", bb.bits);
if(bb->bits != 0) {
printf("FAILED bit count %u != 0\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes-1] != 0xf7) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-1] != 0xf7) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -233,22 +259,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+1);
if(bb->blurbs != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+1);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 4) {
printf("FAILED bit count %u != 4\n", bb.bits);
if(bb->bits != 4) {
printf("FAILED bit count %u != 4\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x08) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x08) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -265,22 +291,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)+2) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+2);
if(bb->blurbs != sizeof(test_pattern1)+2) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+2);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 4) {
printf("FAILED bit count %u != 4\n", bb.bits);
if(bb->bits != 4) {
printf("FAILED bit count %u != 4\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes-1] != 0x8a || bb.buffer[bb.bytes] != 0x0a) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-1] != 0x8a || bb->buffer[bb->blurbs] != 0x0a) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -296,22 +322,22 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bytes != sizeof(test_pattern1)+4) {
printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+4);
if(bb->blurbs != sizeof(test_pattern1)+4) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+4);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.bits != 5) {
printf("FAILED bit count %u != 5\n", bb.bits);
if(bb->bits != 5) {
printf("FAILED bit count %u != 5\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(bb.total_bits != 8*bb.bytes+bb.bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes-3] != 0x8a || bb.buffer[bb.bytes-2] != 0xaa || bb.buffer[bb.bytes-1] != 0xaa || bb.buffer[bb.bytes] != 0x15) {
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-3] != 0x8a || bb->buffer[bb->blurbs-2] != 0xaa || bb->buffer[bb->blurbs-1] != 0xaa || bb->buffer[bb->blurbs] != 0x15) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return 1;
@ -322,7 +348,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x00000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000000);
ok = bb.total_bits == 8 && bb.buffer[0] == 0;
ok = bb->total_bits == 8 && bb->buffer[0] == 0;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -332,7 +358,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x0000007F)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x0000007F);
ok = bb.total_bits == 8 && bb.buffer[0] == 0x7F;
ok = bb->total_bits == 8 && bb->buffer[0] == 0x7F;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -342,7 +368,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x00000080)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000080);
ok = bb.total_bits == 16 && bb.buffer[0] == 0xC2 && bb.buffer[1] == 0x80;
ok = bb->total_bits == 16 && bb->buffer[0] == 0xC2 && bb->buffer[1] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -352,7 +378,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x000007FF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x000007FF);
ok = bb.total_bits == 16 && bb.buffer[0] == 0xDF && bb.buffer[1] == 0xBF;
ok = bb->total_bits == 16 && bb->buffer[0] == 0xDF && bb->buffer[1] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -362,7 +388,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x00000800)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000800);
ok = bb.total_bits == 24 && bb.buffer[0] == 0xE0 && bb.buffer[1] == 0xA0 && bb.buffer[2] == 0x80;
ok = bb->total_bits == 24 && bb->buffer[0] == 0xE0 && bb->buffer[1] == 0xA0 && bb->buffer[2] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -372,7 +398,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x0000FFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x0000FFFF);
ok = bb.total_bits == 24 && bb.buffer[0] == 0xEF && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF;
ok = bb->total_bits == 24 && bb->buffer[0] == 0xEF && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -382,7 +408,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x00010000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00010000);
ok = bb.total_bits == 32 && bb.buffer[0] == 0xF0 && bb.buffer[1] == 0x90 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80;
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF0 && bb->buffer[1] == 0x90 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -392,7 +418,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x001FFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x001FFFFF);
ok = bb.total_bits == 32 && bb.buffer[0] == 0xF7 && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF;
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF7 && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -402,7 +428,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x00200000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00200000);
ok = bb.total_bits == 40 && bb.buffer[0] == 0xF8 && bb.buffer[1] == 0x88 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80 && bb.buffer[4] == 0x80;
ok = bb->total_bits == 40 && bb->buffer[0] == 0xF8 && bb->buffer[1] == 0x88 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -412,7 +438,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x03FFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x03FFFFFF);
ok = bb.total_bits == 40 && bb.buffer[0] == 0xFB && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF && bb.buffer[4] == 0xBF;
ok = bb->total_bits == 40 && bb->buffer[0] == 0xFB && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -422,7 +448,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x04000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x04000000);
ok = bb.total_bits == 48 && bb.buffer[0] == 0xFC && bb.buffer[1] == 0x84 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80 && bb.buffer[4] == 0x80 && bb.buffer[5] == 0x80;
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFC && bb->buffer[1] == 0x84 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -432,7 +458,7 @@ int test_bitbuffer()
printf("testing utf8_uint32(0x7FFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x7FFFFFFF);
ok = bb.total_bits == 48 && bb.buffer[0] == 0xFD && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF && bb.buffer[4] == 0xBF && bb.buffer[5] == 0xBF;
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFD && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -442,7 +468,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000000000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000000);
ok = bb.total_bits == 8 && bb.buffer[0] == 0;
ok = bb->total_bits == 8 && bb->buffer[0] == 0;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -452,7 +478,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x000000000000007F)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000000000007F);
ok = bb.total_bits == 8 && bb.buffer[0] == 0x7F;
ok = bb->total_bits == 8 && bb->buffer[0] == 0x7F;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -462,7 +488,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000000000080)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000080);
ok = bb.total_bits == 16 && bb.buffer[0] == 0xC2 && bb.buffer[1] == 0x80;
ok = bb->total_bits == 16 && bb->buffer[0] == 0xC2 && bb->buffer[1] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -472,7 +498,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x00000000000007FF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x00000000000007FF);
ok = bb.total_bits == 16 && bb.buffer[0] == 0xDF && bb.buffer[1] == 0xBF;
ok = bb->total_bits == 16 && bb->buffer[0] == 0xDF && bb->buffer[1] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -482,7 +508,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000000000800)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000800);
ok = bb.total_bits == 24 && bb.buffer[0] == 0xE0 && bb.buffer[1] == 0xA0 && bb.buffer[2] == 0x80;
ok = bb->total_bits == 24 && bb->buffer[0] == 0xE0 && bb->buffer[1] == 0xA0 && bb->buffer[2] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -492,7 +518,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x000000000000FFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000000000FFFF);
ok = bb.total_bits == 24 && bb.buffer[0] == 0xEF && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF;
ok = bb->total_bits == 24 && bb->buffer[0] == 0xEF && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -502,7 +528,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000000010000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000010000);
ok = bb.total_bits == 32 && bb.buffer[0] == 0xF0 && bb.buffer[1] == 0x90 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80;
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF0 && bb->buffer[1] == 0x90 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -512,7 +538,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x00000000001FFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x00000000001FFFFF);
ok = bb.total_bits == 32 && bb.buffer[0] == 0xF7 && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF;
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF7 && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -522,7 +548,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000000200000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000200000);
ok = bb.total_bits == 40 && bb.buffer[0] == 0xF8 && bb.buffer[1] == 0x88 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80 && bb.buffer[4] == 0x80;
ok = bb->total_bits == 40 && bb->buffer[0] == 0xF8 && bb->buffer[1] == 0x88 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -532,7 +558,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000003FFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000003FFFFFF);
ok = bb.total_bits == 40 && bb.buffer[0] == 0xFB && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF && bb.buffer[4] == 0xBF;
ok = bb->total_bits == 40 && bb->buffer[0] == 0xFB && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -542,7 +568,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000004000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000004000000);
ok = bb.total_bits == 48 && bb.buffer[0] == 0xFC && bb.buffer[1] == 0x84 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80 && bb.buffer[4] == 0x80 && bb.buffer[5] == 0x80;
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFC && bb->buffer[1] == 0x84 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -552,7 +578,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x000000007FFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000007FFFFFFF);
ok = bb.total_bits == 48 && bb.buffer[0] == 0xFD && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF && bb.buffer[4] == 0xBF && bb.buffer[5] == 0xBF;
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFD && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -562,7 +588,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000080000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000080000000);
ok = bb.total_bits == 56 && bb.buffer[0] == 0xFE && bb.buffer[1] == 0x82 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80 && bb.buffer[4] == 0x80 && bb.buffer[5] == 0x80 && bb.buffer[6] == 0x80;
ok = bb->total_bits == 56 && bb->buffer[0] == 0xFE && bb->buffer[1] == 0x82 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80 && bb->buffer[6] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -572,7 +598,7 @@ int test_bitbuffer()
printf("testing utf8_uint64(0x0000000FFFFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000FFFFFFFFF);
ok = bb.total_bits == 56 && bb.buffer[0] == 0xFE && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF && bb.buffer[4] == 0xBF && bb.buffer[5] == 0xBF && bb.buffer[6] == 0xBF;
ok = bb->total_bits == 56 && bb->buffer[0] == 0xFE && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF && bb->buffer[6] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
@ -582,16 +608,16 @@ int test_bitbuffer()
printf("testing grow... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_raw_uint32(bb, 0xa, 4);
j = bb.capacity;
j = bb->capacity;
for(i = 0; i < j; i++)
FLAC__bitbuffer_write_raw_uint32(bb, 0xaa, 8);
ok = bb.total_bits = i*8+4 && bb.buffer[0] == 0xaa && bb.buffer[i] == 0xa;
ok = bb->total_bits = i*8+4 && bb->buffer[0] == 0xaa && bb->buffer[i] == 0xa;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return 1;
}
printf("capacity = %u\n", bb.capacity);
printf("capacity = %u\n", bb->capacity);
printf("testing clone... ");
ok = FLAC__bitbuffer_clone(bbcopy, bb);
@ -601,25 +627,25 @@ int test_bitbuffer()
FLAC__bitbuffer_dump(bbcopy, stdout);
return 1;
}
if(bb.bytes != bbcopy.bytes) {
printf("FAILED byte count %u != %u\n", bb.bytes, bbcopy.bytes);
if(bb->blurbs != bbcopy->blurbs) {
printf("FAILED byte count %u != %u\n", bb->blurbs, bbcopy->blurbs);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return 1;
}
if(bb.bits != bbcopy.bits) {
printf("FAILED bit count %u != %u\n", bb.bits, bbcopy.bits);
if(bb->bits != bbcopy->bits) {
printf("FAILED bit count %u != %u\n", bb->bits, bbcopy->bits);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return 1;
}
if(bb.total_bits != bbcopy.total_bits) {
printf("FAILED total_bits count %u != %u\n", bb.total_bits, bbcopy.total_bits);
if(bb->total_bits != bbcopy->total_bits) {
printf("FAILED total_bits count %u != %u\n", bb->total_bits, bbcopy->total_bits);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return 1;
}
if(memcmp(bb.buffer, bbcopy.buffer, sizeof(FLAC__byte)*bb.capacity) != 0) {
if(memcmp(bb->buffer, bbcopy->buffer, sizeof(FLAC__byte)*bb->capacity) != 0) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);