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