several speed improvements: completely rewritten bitbuffer which uses native machine...
[platform/upstream/flac.git] / src / test_libFLAC / bitwriter.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2000,2001,2002,2003,2004,2005,2006  Josh Coalson
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "FLAC/assert.h"
24 #include "private/bitwriter.h" /* from the libFLAC private include area */
25 #include <stdio.h>
26 #include <string.h> /* for memcmp() */
27
28 /* adjust for compilers that can't understand using LLU suffix for uint64_t literals */
29 #ifdef _MSC_VER
30 #define FLAC__U64L(x) x
31 #else
32 #define FLAC__U64L(x) x##LLU
33 #endif
34
35 /*
36  * WATCHOUT!  Since FLAC__BitWriter is a private structure, we use a copy of
37  * the definition here to get at the internals.  Make sure this is kept up
38  * to date with what is in ../libFLAC/bitwriter.c
39  */
40 typedef FLAC__uint32 bwword;
41
42 struct FLAC__BitWriter {
43         bwword *buffer;
44         bwword accum; /* accumulator; when full, accum is appended to buffer */
45         unsigned capacity; /* of buffer in words */
46         unsigned words; /* # of complete words in buffer */
47         unsigned bits; /* # of used bits in accum */
48 };
49
50 #define TOTAL_BITS(bw) ((bw)->words*sizeof(bwword)*8 + (bw)->bits)
51
52
53 FLAC__bool test_bitwriter()
54 {
55         FLAC__BitWriter *bw;
56         FLAC__bool ok;
57         unsigned i, j;
58 #if WORDS_BIGENDIAN
59         static bwword test_pattern1[5] = { 0xaaf0aabe, 0xaaaaaaa8, 0x300aaaaa, 0xaaadeadb, 0x00eeface };
60 #else
61         static bwword test_pattern1[5] = { 0xbeaaf0aa, 0xa8aaaaaa, 0xaaaa0a30, 0xdbeaadaa, 0x00eeface };
62 #endif
63         unsigned words, bits; /* what we think bw->words and bw->bits should be */
64
65         printf("\n+++ libFLAC unit test: bitwriter\n\n");
66
67         /*
68          * test new -> delete
69          */
70         printf("testing new... ");
71         bw = FLAC__bitwriter_new();
72         if(0 == bw) {
73                 printf("FAILED, returned NULL\n");
74                 return false;
75         }
76         printf("OK\n");
77
78         printf("testing delete... ");
79         FLAC__bitwriter_delete(bw);
80         printf("OK\n");
81
82         /*
83          * test new -> init -> delete
84          */
85         printf("testing new... ");
86         bw = FLAC__bitwriter_new();
87         if(0 == bw) {
88                 printf("FAILED, returned NULL\n");
89                 return false;
90         }
91         printf("OK\n");
92
93         printf("testing init... ");
94         FLAC__bitwriter_init(bw);
95         if(0 == bw) {
96                 printf("FAILED, returned NULL\n");
97                 return false;
98         }
99         printf("OK\n");
100
101         printf("testing delete... ");
102         FLAC__bitwriter_delete(bw);
103         printf("OK\n");
104
105         /*
106          * test new -> init -> clear -> delete
107          */
108         printf("testing new... ");
109         bw = FLAC__bitwriter_new();
110         if(0 == bw) {
111                 printf("FAILED, returned NULL\n");
112                 return false;
113         }
114         printf("OK\n");
115
116         printf("testing init... ");
117         FLAC__bitwriter_init(bw);
118         if(0 == bw) {
119                 printf("FAILED, returned NULL\n");
120                 return false;
121         }
122         printf("OK\n");
123
124         printf("testing clear... ");
125         FLAC__bitwriter_clear(bw);
126         if(0 == bw) {
127                 printf("FAILED, returned NULL\n");
128                 return false;
129         }
130         printf("OK\n");
131
132         printf("testing delete... ");
133         FLAC__bitwriter_delete(bw);
134         printf("OK\n");
135
136         /*
137          * test normal usage
138          */
139         printf("testing new... ");
140         bw = FLAC__bitwriter_new();
141         if(0 == bw) {
142                 printf("FAILED, returned NULL\n");
143                 return false;
144         }
145         printf("OK\n");
146
147         printf("testing init... ");
148         ok = FLAC__bitwriter_init(bw);
149         printf("%s\n", ok?"OK":"FAILED");
150         if(!ok)
151                 return false;
152
153         printf("testing clear... ");
154         FLAC__bitwriter_clear(bw);
155         printf("OK\n");
156
157         words = bits = 0;
158
159         printf("capacity = %u\n", bw->capacity);
160
161         printf("testing zeroes, raw_uint32*... ");
162         ok =
163                 FLAC__bitwriter_write_raw_uint32(bw, 0x1, 1) &&
164                 FLAC__bitwriter_write_raw_uint32(bw, 0x1, 2) &&
165                 FLAC__bitwriter_write_raw_uint32(bw, 0xa, 5) &&
166                 FLAC__bitwriter_write_raw_uint32(bw, 0xf0, 8) &&
167                 FLAC__bitwriter_write_raw_uint32(bw, 0x2aa, 10) &&
168                 FLAC__bitwriter_write_raw_uint32(bw, 0xf, 4) &&
169                 FLAC__bitwriter_write_raw_uint32(bw, 0xaaaaaaaa, 32) &&
170                 FLAC__bitwriter_write_zeroes(bw, 4) &&
171                 FLAC__bitwriter_write_raw_uint32(bw, 0x3, 2) &&
172                 FLAC__bitwriter_write_zeroes(bw, 8) &&
173                 FLAC__bitwriter_write_raw_uint64(bw, FLAC__U64L(0xaaaaaaaadeadbeef), 64) &&
174                 FLAC__bitwriter_write_raw_uint32(bw, 0xace, 12)
175         ;
176         if(!ok) {
177                 printf("FAILED\n");
178                 FLAC__bitwriter_dump(bw, stdout);
179                 return false;
180         }
181         words = 4;
182         bits = 24;
183         if(bw->words != words) {
184                 printf("FAILED byte count %u != %u\n", bw->words, words);
185                 FLAC__bitwriter_dump(bw, stdout);
186                 return false;
187         }
188         if(bw->bits != bits) {
189                 printf("FAILED bit count %u != %u\n", bw->bits, bits);
190                 FLAC__bitwriter_dump(bw, stdout);
191                 return false;
192         }
193         if(memcmp(bw->buffer, test_pattern1, sizeof(bwword)*words) != 0) {
194                 printf("FAILED pattern match (buffer)\n");
195                 FLAC__bitwriter_dump(bw, stdout);
196                 return false;
197         }
198         if((bw->accum & 0x00ffffff) != test_pattern1[words]) {
199                 printf("FAILED pattern match (bw->accum=%08X != %08X)\n", bw->accum&0x00ffffff, test_pattern1[words]);
200                 FLAC__bitwriter_dump(bw, stdout);
201                 return false;
202         }
203         printf("OK\n");
204         FLAC__bitwriter_dump(bw, stdout);
205
206         printf("testing raw_uint32 some more... ");
207         ok = FLAC__bitwriter_write_raw_uint32(bw, 0x3d, 6);
208         if(!ok) {
209                 printf("FAILED\n");
210                 FLAC__bitwriter_dump(bw, stdout);
211                 return false;
212         }
213         bits += 6;
214         test_pattern1[words] <<= 6;
215         test_pattern1[words] |= 0x3d;
216         if(bw->words != words) {
217                 printf("FAILED byte count %u != %u\n", bw->words, words);
218                 FLAC__bitwriter_dump(bw, stdout);
219                 return false;
220         }
221         if(bw->bits != bits) {
222                 printf("FAILED bit count %u != %u\n", bw->bits, bits);
223                 FLAC__bitwriter_dump(bw, stdout);
224                 return false;
225         }
226         if(memcmp(bw->buffer, test_pattern1, sizeof(bwword)*words) != 0) {
227                 printf("FAILED pattern match (buffer)\n");
228                 FLAC__bitwriter_dump(bw, stdout);
229                 return false;
230         }
231         if((bw->accum & 0x3fffffff) != test_pattern1[words]) {
232                 printf("FAILED pattern match (bw->accum=%08X != %08X)\n", bw->accum&0x3fffffff, test_pattern1[words]);
233                 FLAC__bitwriter_dump(bw, stdout);
234                 return false;
235         }
236         printf("OK\n");
237         FLAC__bitwriter_dump(bw, stdout);
238
239         printf("testing utf8_uint32(0x00000000)... ");
240         FLAC__bitwriter_clear(bw);
241         FLAC__bitwriter_write_utf8_uint32(bw, 0x00000000);
242         ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0;
243         printf("%s\n", ok?"OK":"FAILED");
244         if(!ok) {
245                 FLAC__bitwriter_dump(bw, stdout);
246                 return false;
247         }
248
249         printf("testing utf8_uint32(0x0000007F)... ");
250         FLAC__bitwriter_clear(bw);
251         FLAC__bitwriter_write_utf8_uint32(bw, 0x0000007F);
252         ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0x7F;
253         printf("%s\n", ok?"OK":"FAILED");
254         if(!ok) {
255                 FLAC__bitwriter_dump(bw, stdout);
256                 return false;
257         }
258
259         printf("testing utf8_uint32(0x00000080)... ");
260         FLAC__bitwriter_clear(bw);
261         FLAC__bitwriter_write_utf8_uint32(bw, 0x00000080);
262         ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xC280;
263         printf("%s\n", ok?"OK":"FAILED");
264         if(!ok) {
265                 FLAC__bitwriter_dump(bw, stdout);
266                 return false;
267         }
268
269         printf("testing utf8_uint32(0x000007FF)... ");
270         FLAC__bitwriter_clear(bw);
271         FLAC__bitwriter_write_utf8_uint32(bw, 0x000007FF);
272         ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xDFBF;
273         printf("%s\n", ok?"OK":"FAILED");
274         if(!ok) {
275                 FLAC__bitwriter_dump(bw, stdout);
276                 return false;
277         }
278
279         printf("testing utf8_uint32(0x00000800)... ");
280         FLAC__bitwriter_clear(bw);
281         FLAC__bitwriter_write_utf8_uint32(bw, 0x00000800);
282         ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xE0A080;
283         printf("%s\n", ok?"OK":"FAILED");
284         if(!ok) {
285                 FLAC__bitwriter_dump(bw, stdout);
286                 return false;
287         }
288
289         printf("testing utf8_uint32(0x0000FFFF)... ");
290         FLAC__bitwriter_clear(bw);
291         FLAC__bitwriter_write_utf8_uint32(bw, 0x0000FFFF);
292         ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xEFBFBF;
293         printf("%s\n", ok?"OK":"FAILED");
294         if(!ok) {
295                 FLAC__bitwriter_dump(bw, stdout);
296                 return false;
297         }
298
299         printf("testing utf8_uint32(0x00010000)... ");
300         FLAC__bitwriter_clear(bw);
301         FLAC__bitwriter_write_utf8_uint32(bw, 0x00010000);
302 #if WORDS_BIGENDIAN
303         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF0908080;
304 #else
305         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0x808090F0;
306 #endif
307         printf("%s\n", ok?"OK":"FAILED");
308         if(!ok) {
309                 FLAC__bitwriter_dump(bw, stdout);
310                 return false;
311         }
312
313         printf("testing utf8_uint32(0x001FFFFF)... ");
314         FLAC__bitwriter_clear(bw);
315         FLAC__bitwriter_write_utf8_uint32(bw, 0x001FFFFF);
316 #if WORDS_BIGENDIAN
317         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF7BFBFBF;
318 #else
319         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xBFBFBFF7;
320 #endif
321         printf("%s\n", ok?"OK":"FAILED");
322         if(!ok) {
323                 FLAC__bitwriter_dump(bw, stdout);
324                 return false;
325         }
326
327         printf("testing utf8_uint32(0x00200000)... ");
328         FLAC__bitwriter_clear(bw);
329         FLAC__bitwriter_write_utf8_uint32(bw, 0x00200000);
330 #if WORDS_BIGENDIAN
331         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xF8888080 && (bw->accum & 0xff) == 0x80;
332 #else
333         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0x808088F8 && (bw->accum & 0xff) == 0x80;
334 #endif
335         printf("%s\n", ok?"OK":"FAILED");
336         if(!ok) {
337                 FLAC__bitwriter_dump(bw, stdout);
338                 return false;
339         }
340
341         printf("testing utf8_uint32(0x03FFFFFF)... ");
342         FLAC__bitwriter_clear(bw);
343         FLAC__bitwriter_write_utf8_uint32(bw, 0x03FFFFFF);
344 #if WORDS_BIGENDIAN
345         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xFBBFBFBF && (bw->accum & 0xff) == 0xBF;
346 #else
347         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xBFBFBFFB && (bw->accum & 0xff) == 0xBF;
348 #endif
349         printf("%s\n", ok?"OK":"FAILED");
350         if(!ok) {
351                 FLAC__bitwriter_dump(bw, stdout);
352                 return false;
353         }
354
355         printf("testing utf8_uint32(0x04000000)... ");
356         FLAC__bitwriter_clear(bw);
357         FLAC__bitwriter_write_utf8_uint32(bw, 0x04000000);
358 #if WORDS_BIGENDIAN
359         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFC848080 && (bw->accum & 0xffff) == 0x8080;
360 #else
361         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0x808084FC && (bw->accum & 0xffff) == 0x8080;
362 #endif
363         printf("%s\n", ok?"OK":"FAILED");
364         if(!ok) {
365                 FLAC__bitwriter_dump(bw, stdout);
366                 return false;
367         }
368
369         printf("testing utf8_uint32(0x7FFFFFFF)... ");
370         FLAC__bitwriter_clear(bw);
371         FLAC__bitwriter_write_utf8_uint32(bw, 0x7FFFFFFF);
372 #if WORDS_BIGENDIAN
373         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFDBFBFBF && (bw->accum & 0xffff) == 0xBFBF;
374 #else
375         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xBFBFBFFD && (bw->accum & 0xffff) == 0xBFBF;
376 #endif
377         printf("%s\n", ok?"OK":"FAILED");
378         if(!ok) {
379                 FLAC__bitwriter_dump(bw, stdout);
380                 return false;
381         }
382
383         printf("testing utf8_uint64(0x0000000000000000)... ");
384         FLAC__bitwriter_clear(bw);
385         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000000000000);
386         ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0;
387         printf("%s\n", ok?"OK":"FAILED");
388         if(!ok) {
389                 FLAC__bitwriter_dump(bw, stdout);
390                 return false;
391         }
392
393         printf("testing utf8_uint64(0x000000000000007F)... ");
394         FLAC__bitwriter_clear(bw);
395         FLAC__bitwriter_write_utf8_uint64(bw, 0x000000000000007F);
396         ok = TOTAL_BITS(bw) == 8 && (bw->accum & 0xff) == 0x7F;
397         printf("%s\n", ok?"OK":"FAILED");
398         if(!ok) {
399                 FLAC__bitwriter_dump(bw, stdout);
400                 return false;
401         }
402
403         printf("testing utf8_uint64(0x0000000000000080)... ");
404         FLAC__bitwriter_clear(bw);
405         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000000000080);
406         ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xC280;
407         printf("%s\n", ok?"OK":"FAILED");
408         if(!ok) {
409                 FLAC__bitwriter_dump(bw, stdout);
410                 return false;
411         }
412
413         printf("testing utf8_uint64(0x00000000000007FF)... ");
414         FLAC__bitwriter_clear(bw);
415         FLAC__bitwriter_write_utf8_uint64(bw, 0x00000000000007FF);
416         ok = TOTAL_BITS(bw) == 16 && (bw->accum & 0xffff) == 0xDFBF;
417         printf("%s\n", ok?"OK":"FAILED");
418         if(!ok) {
419                 FLAC__bitwriter_dump(bw, stdout);
420                 return false;
421         }
422
423         printf("testing utf8_uint64(0x0000000000000800)... ");
424         FLAC__bitwriter_clear(bw);
425         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000000000800);
426         ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xE0A080;
427         printf("%s\n", ok?"OK":"FAILED");
428         if(!ok) {
429                 FLAC__bitwriter_dump(bw, stdout);
430                 return false;
431         }
432
433         printf("testing utf8_uint64(0x000000000000FFFF)... ");
434         FLAC__bitwriter_clear(bw);
435         FLAC__bitwriter_write_utf8_uint64(bw, 0x000000000000FFFF);
436         ok = TOTAL_BITS(bw) == 24 && (bw->accum & 0xffffff) == 0xEFBFBF;
437         printf("%s\n", ok?"OK":"FAILED");
438         if(!ok) {
439                 FLAC__bitwriter_dump(bw, stdout);
440                 return false;
441         }
442
443         printf("testing utf8_uint64(0x0000000000010000)... ");
444         FLAC__bitwriter_clear(bw);
445         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000000010000);
446 #if WORDS_BIGENDIAN
447         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF0908080;
448 #else
449         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0x808090F0;
450 #endif
451         printf("%s\n", ok?"OK":"FAILED");
452         if(!ok) {
453                 FLAC__bitwriter_dump(bw, stdout);
454                 return false;
455         }
456
457         printf("testing utf8_uint64(0x00000000001FFFFF)... ");
458         FLAC__bitwriter_clear(bw);
459         FLAC__bitwriter_write_utf8_uint64(bw, 0x00000000001FFFFF);
460 #if WORDS_BIGENDIAN
461         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xF7BFBFBF;
462 #else
463         ok = TOTAL_BITS(bw) == 32 && bw->buffer[0] == 0xBFBFBFF7;
464 #endif
465         printf("%s\n", ok?"OK":"FAILED");
466         if(!ok) {
467                 FLAC__bitwriter_dump(bw, stdout);
468                 return false;
469         }
470
471         printf("testing utf8_uint64(0x0000000000200000)... ");
472         FLAC__bitwriter_clear(bw);
473         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000000200000);
474 #if WORDS_BIGENDIAN
475         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xF8888080 && (bw->accum & 0xff) == 0x80;
476 #else
477         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0x808088F8 && (bw->accum & 0xff) == 0x80;
478 #endif
479         printf("%s\n", ok?"OK":"FAILED");
480         if(!ok) {
481                 FLAC__bitwriter_dump(bw, stdout);
482                 return false;
483         }
484
485         printf("testing utf8_uint64(0x0000000003FFFFFF)... ");
486         FLAC__bitwriter_clear(bw);
487         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000003FFFFFF);
488 #if WORDS_BIGENDIAN
489         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xFBBFBFBF && (bw->accum & 0xff) == 0xBF;
490 #else
491         ok = TOTAL_BITS(bw) == 40 && bw->buffer[0] == 0xBFBFBFFB && (bw->accum & 0xff) == 0xBF;
492 #endif
493         printf("%s\n", ok?"OK":"FAILED");
494         if(!ok) {
495                 FLAC__bitwriter_dump(bw, stdout);
496                 return false;
497         }
498
499         printf("testing utf8_uint64(0x0000000004000000)... ");
500         FLAC__bitwriter_clear(bw);
501         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000004000000);
502 #if WORDS_BIGENDIAN
503         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFC848080 && (bw->accum & 0xffff) == 0x8080;
504 #else
505         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0x808084FC && (bw->accum & 0xffff) == 0x8080;
506 #endif
507         printf("%s\n", ok?"OK":"FAILED");
508         if(!ok) {
509                 FLAC__bitwriter_dump(bw, stdout);
510                 return false;
511         }
512
513         printf("testing utf8_uint64(0x000000007FFFFFFF)... ");
514         FLAC__bitwriter_clear(bw);
515         FLAC__bitwriter_write_utf8_uint64(bw, 0x000000007FFFFFFF);
516 #if WORDS_BIGENDIAN
517         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xFDBFBFBF && (bw->accum & 0xffff) == 0xBFBF;
518 #else
519         ok = TOTAL_BITS(bw) == 48 && bw->buffer[0] == 0xBFBFBFFD && (bw->accum & 0xffff) == 0xBFBF;
520 #endif
521         printf("%s\n", ok?"OK":"FAILED");
522         if(!ok) {
523                 FLAC__bitwriter_dump(bw, stdout);
524                 return false;
525         }
526
527         printf("testing utf8_uint64(0x0000000080000000)... ");
528         FLAC__bitwriter_clear(bw);
529         FLAC__bitwriter_write_utf8_uint64(bw, 0x0000000080000000);
530 #if WORDS_BIGENDIAN
531         ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xFE828080 && (bw->accum & 0xffffff) == 0x808080;
532 #else
533         ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0x808082FE && (bw->accum & 0xffffff) == 0x808080;
534 #endif
535         printf("%s\n", ok?"OK":"FAILED");
536         if(!ok) {
537                 FLAC__bitwriter_dump(bw, stdout);
538                 return false;
539         }
540
541         printf("testing utf8_uint64(0x0000000FFFFFFFFF)... ");
542         FLAC__bitwriter_clear(bw);
543         FLAC__bitwriter_write_utf8_uint64(bw, FLAC__U64L(0x0000000FFFFFFFFF));
544 #if WORDS_BIGENDIAN
545         ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xFEBFBFBF && (bw->accum & 0xffffff) == 0xBFBFBF;
546 #else
547         ok = TOTAL_BITS(bw) == 56 && bw->buffer[0] == 0xBFBFBFFE && (bw->accum & 0xffffff) == 0xBFBFBF;
548 #endif
549         printf("%s\n", ok?"OK":"FAILED");
550         if(!ok) {
551                 FLAC__bitwriter_dump(bw, stdout);
552                 return false;
553         }
554
555         printf("testing grow... ");
556         FLAC__bitwriter_clear(bw);
557         FLAC__bitwriter_write_raw_uint32(bw, 0x5, 4);
558         j = bw->capacity;
559         for(i = 0; i < j; i++)
560                 FLAC__bitwriter_write_raw_uint32(bw, 0xaaaaaaaa, 32);
561 #if WORDS_BIGENDIAN
562         ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == 0x5aaaaaaa && (bw->accum & 0xf) == 0xa;
563 #else
564         ok = TOTAL_BITS(bw) == i*32+4 && bw->buffer[0] == 0xaaaaaa5a && (bw->accum & 0xf) == 0xa;
565 #endif
566         printf("%s\n", ok?"OK":"FAILED");
567         if(!ok) {
568                 FLAC__bitwriter_dump(bw, stdout);
569                 return false;
570         }
571         printf("capacity = %u\n", bw->capacity);
572
573         printf("testing free... ");
574         FLAC__bitwriter_free(bw);
575         printf("OK\n");
576
577         printf("testing delete... ");
578         FLAC__bitwriter_delete(bw);
579         printf("OK\n");
580
581         printf("\nPASSED!\n");
582         return true;
583 }