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