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