1 /* test_unit - Simple FLAC unit tester
2 * Copyright (C) 2000,2001,2002 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "private/bitbuffer.h" /* from the libFLAC private include area */
20 #include <string.h> /* for memcmp() */
22 static FLAC__bool dummy_read_callback(FLAC__byte buffer[], unsigned *bytes, void *client_data)
24 (void)buffer, (void)bytes, (void)client_data;
30 FLAC__BitBuffer bb, bb_zero, bb_one, bbcopy;
33 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 };
35 printf("testing init... OK\n");
36 FLAC__bitbuffer_init(&bb);
37 FLAC__bitbuffer_init(&bb_zero);
38 FLAC__bitbuffer_init(&bb_one);
39 FLAC__bitbuffer_init(&bbcopy);
41 printf("testing clear... ");
42 ok = FLAC__bitbuffer_clear(&bb) && FLAC__bitbuffer_clear(&bb_zero) && FLAC__bitbuffer_clear(&bb_one) && FLAC__bitbuffer_clear(&bbcopy);
43 printf("%s\n", ok?"OK":"FAILED");
47 printf("setting up bb_one... ");
48 ok = FLAC__bitbuffer_write_raw_uint32(&bb_one, 1, 7) && FLAC__bitbuffer_read_raw_uint32(&bb_one, &i, 6, dummy_read_callback, 0);
49 printf("%s\n", ok?"OK":"FAILED");
52 FLAC__bitbuffer_dump(&bb_one, stdout);
54 printf("capacity = %u\n", bb.capacity);
56 printf("testing zeroes, raw_uint32*... ");
58 FLAC__bitbuffer_write_raw_uint32(&bb, 0x1, 1) &&
59 FLAC__bitbuffer_write_raw_uint32(&bb, 0x1, 2) &&
60 FLAC__bitbuffer_write_raw_uint32(&bb, 0xa, 5) &&
61 FLAC__bitbuffer_write_raw_uint32(&bb, 0xf0, 8) &&
62 FLAC__bitbuffer_write_raw_uint32(&bb, 0x2aa, 10) &&
63 FLAC__bitbuffer_write_raw_uint32(&bb, 0xf, 4) &&
64 FLAC__bitbuffer_write_raw_uint32(&bb, 0xaaaaaaaa, 32) &&
65 FLAC__bitbuffer_write_zeroes(&bb, 4) &&
66 FLAC__bitbuffer_write_raw_uint32(&bb, 0x3, 2) &&
67 FLAC__bitbuffer_write_zeroes(&bb, 8) &&
68 FLAC__bitbuffer_write_raw_uint64(&bb, 0xaaaaaaaadeadbeef, 64) &&
69 FLAC__bitbuffer_write_raw_uint32(&bb, 0xace, 12)
73 FLAC__bitbuffer_dump(&bb, stdout);
76 if(bb.bytes != sizeof(test_pattern1)) {
77 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
78 FLAC__bitbuffer_dump(&bb, stdout);
82 printf("FAILED bit count %u != 0\n", bb.bits);
83 FLAC__bitbuffer_dump(&bb, stdout);
86 if(bb.total_bits != 8*bb.bytes+bb.bits) {
87 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
88 FLAC__bitbuffer_dump(&bb, stdout);
91 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0) {
92 printf("FAILED pattern match\n");
93 FLAC__bitbuffer_dump(&bb, stdout);
97 FLAC__bitbuffer_dump(&bb, stdout);
99 printf("testing raw_uint32 some more... ");
100 ok = FLAC__bitbuffer_write_raw_uint32(&bb, 0x3d, 6);
103 FLAC__bitbuffer_dump(&bb, stdout);
106 if(bb.bytes != sizeof(test_pattern1)) {
107 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
108 FLAC__bitbuffer_dump(&bb, stdout);
112 printf("FAILED bit count %u != 6\n", bb.bits);
113 FLAC__bitbuffer_dump(&bb, stdout);
116 if(bb.total_bits != 8*bb.bytes+bb.bits) {
117 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
118 FLAC__bitbuffer_dump(&bb, stdout);
121 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x3d) {
122 printf("FAILED pattern match\n");
123 FLAC__bitbuffer_dump(&bb, stdout);
127 FLAC__bitbuffer_dump(&bb, stdout);
129 printf("testing concatenate_aligned (bb_zero)... ");
130 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_zero);
133 FLAC__bitbuffer_dump(&bb, stdout);
136 if(bb.bytes != sizeof(test_pattern1)) {
137 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
138 FLAC__bitbuffer_dump(&bb, stdout);
142 printf("FAILED bit count %u != 6\n", bb.bits);
143 FLAC__bitbuffer_dump(&bb, stdout);
146 if(bb.total_bits != 8*bb.bytes+bb.bits) {
147 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
148 FLAC__bitbuffer_dump(&bb, stdout);
151 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x3d) {
152 printf("FAILED pattern match\n");
153 FLAC__bitbuffer_dump(&bb, stdout);
157 FLAC__bitbuffer_dump(&bb, stdout);
159 printf("testing concatenate_aligned (bb_one)... ");
160 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_one);
163 FLAC__bitbuffer_dump(&bb, stdout);
166 if(bb.bytes != sizeof(test_pattern1)) {
167 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1));
168 FLAC__bitbuffer_dump(&bb, stdout);
172 printf("FAILED bit count %u != 7\n", bb.bits);
173 FLAC__bitbuffer_dump(&bb, stdout);
176 if(bb.total_bits != 8*bb.bytes+bb.bits) {
177 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
178 FLAC__bitbuffer_dump(&bb, stdout);
181 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x7b) {
182 printf("FAILED pattern match\n");
183 FLAC__bitbuffer_dump(&bb, stdout);
187 FLAC__bitbuffer_dump(&bb, stdout);
189 printf("testing concatenate_aligned (bb_one again)... ");
190 (void)FLAC__bitbuffer_write_raw_uint32(&bb_one, 1, 1);
191 (void)FLAC__bitbuffer_read_raw_uint32(&bb_one, &i, 1, dummy_read_callback, 0);
192 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_one);
195 FLAC__bitbuffer_dump(&bb, stdout);
198 if(bb.bytes != sizeof(test_pattern1)+1) {
199 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+1);
200 FLAC__bitbuffer_dump(&bb, stdout);
204 printf("FAILED bit count %u != 0\n", bb.bits);
205 FLAC__bitbuffer_dump(&bb, stdout);
208 if(bb.total_bits != 8*bb.bytes+bb.bits) {
209 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
210 FLAC__bitbuffer_dump(&bb, stdout);
213 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes-1] != 0xf7) {
214 printf("FAILED pattern match\n");
215 FLAC__bitbuffer_dump(&bb, stdout);
219 FLAC__bitbuffer_dump(&bb, stdout);
221 printf("testing concatenate_aligned (bb_four)... ");
222 (void)FLAC__bitbuffer_clear(&bb_one);
223 (void)FLAC__bitbuffer_write_raw_uint32(&bb_one, 8, 4);
224 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_one);
227 FLAC__bitbuffer_dump(&bb, stdout);
230 if(bb.bytes != sizeof(test_pattern1)+1) {
231 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+1);
232 FLAC__bitbuffer_dump(&bb, stdout);
236 printf("FAILED bit count %u != 4\n", bb.bits);
237 FLAC__bitbuffer_dump(&bb, stdout);
240 if(bb.total_bits != 8*bb.bytes+bb.bits) {
241 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
242 FLAC__bitbuffer_dump(&bb, stdout);
245 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes] != 0x08) {
246 printf("FAILED pattern match\n");
247 FLAC__bitbuffer_dump(&bb, stdout);
251 FLAC__bitbuffer_dump(&bb, stdout);
253 printf("testing concatenate_aligned (bb_eight)... ");
254 (void)FLAC__bitbuffer_read_raw_uint32(&bb_one, &i, 4, dummy_read_callback, 0);
255 (void)FLAC__bitbuffer_write_raw_uint32(&bb_one, 0xaa, 8);
256 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_one);
259 FLAC__bitbuffer_dump(&bb, stdout);
262 if(bb.bytes != sizeof(test_pattern1)+2) {
263 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+2);
264 FLAC__bitbuffer_dump(&bb, stdout);
268 printf("FAILED bit count %u != 4\n", bb.bits);
269 FLAC__bitbuffer_dump(&bb, stdout);
272 if(bb.total_bits != 8*bb.bytes+bb.bits) {
273 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
274 FLAC__bitbuffer_dump(&bb, stdout);
277 if(memcmp(bb.buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb.buffer[bb.bytes-1] != 0x8a || bb.buffer[bb.bytes] != 0x0a) {
278 printf("FAILED pattern match\n");
279 FLAC__bitbuffer_dump(&bb, stdout);
283 FLAC__bitbuffer_dump(&bb, stdout);
285 printf("testing concatenate_aligned (bb_seventeen)... ");
286 (void)FLAC__bitbuffer_write_raw_uint32(&bb_one, 0x155, 9);
287 ok = FLAC__bitbuffer_concatenate_aligned(&bb, &bb_one);
290 FLAC__bitbuffer_dump(&bb, stdout);
293 if(bb.bytes != sizeof(test_pattern1)+4) {
294 printf("FAILED byte count %u != %u\n", bb.bytes, sizeof(test_pattern1)+4);
295 FLAC__bitbuffer_dump(&bb, stdout);
299 printf("FAILED bit count %u != 5\n", bb.bits);
300 FLAC__bitbuffer_dump(&bb, stdout);
303 if(bb.total_bits != 8*bb.bytes+bb.bits) {
304 printf("FAILED total_bits count %u != %u (%u:%u)\n", bb.total_bits, 8*bb.bytes+bb.bits, bb.bytes, bb.bits);
305 FLAC__bitbuffer_dump(&bb, stdout);
308 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) {
309 printf("FAILED pattern match\n");
310 FLAC__bitbuffer_dump(&bb, stdout);
314 FLAC__bitbuffer_dump(&bb, stdout);
316 printf("testing utf8_uint32(0x00000000)... ");
317 FLAC__bitbuffer_clear(&bb);
318 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x00000000);
319 ok = bb.total_bits == 8 && bb.buffer[0] == 0;
320 printf("%s\n", ok?"OK":"FAILED");
322 FLAC__bitbuffer_dump(&bb, stdout);
326 printf("testing utf8_uint32(0x0000007F)... ");
327 FLAC__bitbuffer_clear(&bb);
328 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x0000007F);
329 ok = bb.total_bits == 8 && bb.buffer[0] == 0x7F;
330 printf("%s\n", ok?"OK":"FAILED");
332 FLAC__bitbuffer_dump(&bb, stdout);
336 printf("testing utf8_uint32(0x00000080)... ");
337 FLAC__bitbuffer_clear(&bb);
338 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x00000080);
339 ok = bb.total_bits == 16 && bb.buffer[0] == 0xC2 && bb.buffer[1] == 0x80;
340 printf("%s\n", ok?"OK":"FAILED");
342 FLAC__bitbuffer_dump(&bb, stdout);
346 printf("testing utf8_uint32(0x000007FF)... ");
347 FLAC__bitbuffer_clear(&bb);
348 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x000007FF);
349 ok = bb.total_bits == 16 && bb.buffer[0] == 0xDF && bb.buffer[1] == 0xBF;
350 printf("%s\n", ok?"OK":"FAILED");
352 FLAC__bitbuffer_dump(&bb, stdout);
356 printf("testing utf8_uint32(0x00000800)... ");
357 FLAC__bitbuffer_clear(&bb);
358 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x00000800);
359 ok = bb.total_bits == 24 && bb.buffer[0] == 0xE0 && bb.buffer[1] == 0xA0 && bb.buffer[2] == 0x80;
360 printf("%s\n", ok?"OK":"FAILED");
362 FLAC__bitbuffer_dump(&bb, stdout);
366 printf("testing utf8_uint32(0x0000FFFF)... ");
367 FLAC__bitbuffer_clear(&bb);
368 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x0000FFFF);
369 ok = bb.total_bits == 24 && bb.buffer[0] == 0xEF && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF;
370 printf("%s\n", ok?"OK":"FAILED");
372 FLAC__bitbuffer_dump(&bb, stdout);
376 printf("testing utf8_uint32(0x00010000)... ");
377 FLAC__bitbuffer_clear(&bb);
378 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x00010000);
379 ok = bb.total_bits == 32 && bb.buffer[0] == 0xF0 && bb.buffer[1] == 0x90 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80;
380 printf("%s\n", ok?"OK":"FAILED");
382 FLAC__bitbuffer_dump(&bb, stdout);
386 printf("testing utf8_uint32(0x001FFFFF)... ");
387 FLAC__bitbuffer_clear(&bb);
388 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x001FFFFF);
389 ok = bb.total_bits == 32 && bb.buffer[0] == 0xF7 && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF;
390 printf("%s\n", ok?"OK":"FAILED");
392 FLAC__bitbuffer_dump(&bb, stdout);
396 printf("testing utf8_uint32(0x00200000)... ");
397 FLAC__bitbuffer_clear(&bb);
398 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x00200000);
399 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;
400 printf("%s\n", ok?"OK":"FAILED");
402 FLAC__bitbuffer_dump(&bb, stdout);
406 printf("testing utf8_uint32(0x03FFFFFF)... ");
407 FLAC__bitbuffer_clear(&bb);
408 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x03FFFFFF);
409 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;
410 printf("%s\n", ok?"OK":"FAILED");
412 FLAC__bitbuffer_dump(&bb, stdout);
416 printf("testing utf8_uint32(0x04000000)... ");
417 FLAC__bitbuffer_clear(&bb);
418 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x04000000);
419 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;
420 printf("%s\n", ok?"OK":"FAILED");
422 FLAC__bitbuffer_dump(&bb, stdout);
426 printf("testing utf8_uint32(0x7FFFFFFF)... ");
427 FLAC__bitbuffer_clear(&bb);
428 FLAC__bitbuffer_write_utf8_uint32(&bb, 0x7FFFFFFF);
429 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;
430 printf("%s\n", ok?"OK":"FAILED");
432 FLAC__bitbuffer_dump(&bb, stdout);
436 printf("testing utf8_uint64(0x0000000000000000)... ");
437 FLAC__bitbuffer_clear(&bb);
438 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000000000000);
439 ok = bb.total_bits == 8 && bb.buffer[0] == 0;
440 printf("%s\n", ok?"OK":"FAILED");
442 FLAC__bitbuffer_dump(&bb, stdout);
446 printf("testing utf8_uint64(0x000000000000007F)... ");
447 FLAC__bitbuffer_clear(&bb);
448 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x000000000000007F);
449 ok = bb.total_bits == 8 && bb.buffer[0] == 0x7F;
450 printf("%s\n", ok?"OK":"FAILED");
452 FLAC__bitbuffer_dump(&bb, stdout);
456 printf("testing utf8_uint64(0x0000000000000080)... ");
457 FLAC__bitbuffer_clear(&bb);
458 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000000000080);
459 ok = bb.total_bits == 16 && bb.buffer[0] == 0xC2 && bb.buffer[1] == 0x80;
460 printf("%s\n", ok?"OK":"FAILED");
462 FLAC__bitbuffer_dump(&bb, stdout);
466 printf("testing utf8_uint64(0x00000000000007FF)... ");
467 FLAC__bitbuffer_clear(&bb);
468 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x00000000000007FF);
469 ok = bb.total_bits == 16 && bb.buffer[0] == 0xDF && bb.buffer[1] == 0xBF;
470 printf("%s\n", ok?"OK":"FAILED");
472 FLAC__bitbuffer_dump(&bb, stdout);
476 printf("testing utf8_uint64(0x0000000000000800)... ");
477 FLAC__bitbuffer_clear(&bb);
478 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000000000800);
479 ok = bb.total_bits == 24 && bb.buffer[0] == 0xE0 && bb.buffer[1] == 0xA0 && bb.buffer[2] == 0x80;
480 printf("%s\n", ok?"OK":"FAILED");
482 FLAC__bitbuffer_dump(&bb, stdout);
486 printf("testing utf8_uint64(0x000000000000FFFF)... ");
487 FLAC__bitbuffer_clear(&bb);
488 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x000000000000FFFF);
489 ok = bb.total_bits == 24 && bb.buffer[0] == 0xEF && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF;
490 printf("%s\n", ok?"OK":"FAILED");
492 FLAC__bitbuffer_dump(&bb, stdout);
496 printf("testing utf8_uint64(0x0000000000010000)... ");
497 FLAC__bitbuffer_clear(&bb);
498 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000000010000);
499 ok = bb.total_bits == 32 && bb.buffer[0] == 0xF0 && bb.buffer[1] == 0x90 && bb.buffer[2] == 0x80 && bb.buffer[3] == 0x80;
500 printf("%s\n", ok?"OK":"FAILED");
502 FLAC__bitbuffer_dump(&bb, stdout);
506 printf("testing utf8_uint64(0x00000000001FFFFF)... ");
507 FLAC__bitbuffer_clear(&bb);
508 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x00000000001FFFFF);
509 ok = bb.total_bits == 32 && bb.buffer[0] == 0xF7 && bb.buffer[1] == 0xBF && bb.buffer[2] == 0xBF && bb.buffer[3] == 0xBF;
510 printf("%s\n", ok?"OK":"FAILED");
512 FLAC__bitbuffer_dump(&bb, stdout);
516 printf("testing utf8_uint64(0x0000000000200000)... ");
517 FLAC__bitbuffer_clear(&bb);
518 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000000200000);
519 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;
520 printf("%s\n", ok?"OK":"FAILED");
522 FLAC__bitbuffer_dump(&bb, stdout);
526 printf("testing utf8_uint64(0x0000000003FFFFFF)... ");
527 FLAC__bitbuffer_clear(&bb);
528 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000003FFFFFF);
529 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;
530 printf("%s\n", ok?"OK":"FAILED");
532 FLAC__bitbuffer_dump(&bb, stdout);
536 printf("testing utf8_uint64(0x0000000004000000)... ");
537 FLAC__bitbuffer_clear(&bb);
538 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000004000000);
539 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;
540 printf("%s\n", ok?"OK":"FAILED");
542 FLAC__bitbuffer_dump(&bb, stdout);
546 printf("testing utf8_uint64(0x000000007FFFFFFF)... ");
547 FLAC__bitbuffer_clear(&bb);
548 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x000000007FFFFFFF);
549 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;
550 printf("%s\n", ok?"OK":"FAILED");
552 FLAC__bitbuffer_dump(&bb, stdout);
556 printf("testing utf8_uint64(0x0000000080000000)... ");
557 FLAC__bitbuffer_clear(&bb);
558 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000080000000);
559 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;
560 printf("%s\n", ok?"OK":"FAILED");
562 FLAC__bitbuffer_dump(&bb, stdout);
566 printf("testing utf8_uint64(0x0000000FFFFFFFFF)... ");
567 FLAC__bitbuffer_clear(&bb);
568 FLAC__bitbuffer_write_utf8_uint64(&bb, 0x0000000FFFFFFFFF);
569 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;
570 printf("%s\n", ok?"OK":"FAILED");
572 FLAC__bitbuffer_dump(&bb, stdout);
576 printf("testing grow... ");
577 FLAC__bitbuffer_clear(&bb);
578 FLAC__bitbuffer_write_raw_uint32(&bb, 0xa, 4);
580 for(i = 0; i < j; i++)
581 FLAC__bitbuffer_write_raw_uint32(&bb, 0xaa, 8);
582 ok = bb.total_bits = i*8+4 && bb.buffer[0] == 0xaa && bb.buffer[i] == 0xa;
583 printf("%s\n", ok?"OK":"FAILED");
585 FLAC__bitbuffer_dump(&bb, stdout);
588 printf("capacity = %u\n", bb.capacity);
590 printf("testing clone... ");
591 ok = FLAC__bitbuffer_clone(&bbcopy, &bb);
594 FLAC__bitbuffer_dump(&bb, stdout);
595 FLAC__bitbuffer_dump(&bbcopy, stdout);
598 if(bb.bytes != bbcopy.bytes) {
599 printf("FAILED byte count %u != %u\n", bb.bytes, bbcopy.bytes);
600 FLAC__bitbuffer_dump(&bb, stdout);
601 FLAC__bitbuffer_dump(&bbcopy, stdout);
604 if(bb.bits != bbcopy.bits) {
605 printf("FAILED bit count %u != %u\n", bb.bits, bbcopy.bits);
606 FLAC__bitbuffer_dump(&bb, stdout);
607 FLAC__bitbuffer_dump(&bbcopy, stdout);
610 if(bb.total_bits != bbcopy.total_bits) {
611 printf("FAILED total_bits count %u != %u\n", bb.total_bits, bbcopy.total_bits);
612 FLAC__bitbuffer_dump(&bb, stdout);
613 FLAC__bitbuffer_dump(&bbcopy, stdout);
616 if(memcmp(bb.buffer, bbcopy.buffer, sizeof(FLAC__byte)*bb.capacity) != 0) {
617 printf("FAILED pattern match\n");
618 FLAC__bitbuffer_dump(&bb, stdout);
619 FLAC__bitbuffer_dump(&bbcopy, stdout);
624 printf("testing free... OK\n");
625 FLAC__bitbuffer_free(&bb);
626 FLAC__bitbuffer_free(&bbcopy);
628 printf("\nPASSED!\n");