1 /* test_libFLAC++ - Unit tester for libFLAC++
2  * Copyright (C) 2002-2009  Josh Coalson
3  * Copyright (C) 2011-2016  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 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <stdio.h>
25 #include <stdlib.h> /* for malloc() */
26 #include <string.h> /* for memcmp() */
27 #include "FLAC/assert.h"
28 #include "FLAC++/metadata.h"
29 #include "share/safe_str.h"
30 
31 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application_, vorbiscomment_, cuesheet_, picture_;
32 
die_(const char * msg)33 static bool die_(const char *msg)
34 {
35 	printf("FAILED, %s\n", msg);
36 	return false;
37 }
38 
malloc_or_die_(size_t size)39 static void *malloc_or_die_(size_t size)
40 {
41 	void *x = malloc(size);
42 	if(0 == x) {
43 		fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (uint32_t)size);
44 		exit(1);
45 	}
46 	return x;
47 }
48 
strdup_or_die_(const char * s)49 static char *strdup_or_die_(const char *s)
50 {
51 	char *x = strdup(s);
52 	if(0 == x) {
53 		fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s);
54 		exit(1);
55 	}
56 	return x;
57 }
58 
index_is_equal_(const::FLAC__StreamMetadata_CueSheet_Index & indx,const::FLAC__StreamMetadata_CueSheet_Index & indxcopy)59 static bool index_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Index &indx, const ::FLAC__StreamMetadata_CueSheet_Index &indxcopy)
60 {
61 	if(indxcopy.offset != indx.offset)
62 		return false;
63 	if(indxcopy.number != indx.number)
64 		return false;
65 	return true;
66 }
67 
track_is_equal_(const::FLAC__StreamMetadata_CueSheet_Track * track,const::FLAC__StreamMetadata_CueSheet_Track * trackcopy)68 static bool track_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Track *track, const ::FLAC__StreamMetadata_CueSheet_Track *trackcopy)
69 {
70 	uint32_t i;
71 
72 	if(trackcopy->offset != track->offset)
73 		return false;
74 	if(trackcopy->number != track->number)
75 		return false;
76 	if(0 != strcmp(trackcopy->isrc, track->isrc))
77 		return false;
78 	if(trackcopy->type != track->type)
79 		return false;
80 	if(trackcopy->pre_emphasis != track->pre_emphasis)
81 		return false;
82 	if(trackcopy->num_indices != track->num_indices)
83 		return false;
84 	if(0 == track->indices || 0 == trackcopy->indices) {
85 		if(track->indices != trackcopy->indices)
86 			return false;
87 	}
88 	else {
89 		for(i = 0; i < track->num_indices; i++) {
90 			if(!index_is_equal_(trackcopy->indices[i], track->indices[i]))
91 				return false;
92 		}
93 	}
94 	return true;
95 }
96 
init_metadata_blocks_()97 static void init_metadata_blocks_()
98 {
99 	streaminfo_.is_last = false;
100 	streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
101 	streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
102 	streaminfo_.data.stream_info.min_blocksize = 576;
103 	streaminfo_.data.stream_info.max_blocksize = 576;
104 	streaminfo_.data.stream_info.min_framesize = 0;
105 	streaminfo_.data.stream_info.max_framesize = 0;
106 	streaminfo_.data.stream_info.sample_rate = 44100;
107 	streaminfo_.data.stream_info.channels = 1;
108 	streaminfo_.data.stream_info.bits_per_sample = 8;
109 	streaminfo_.data.stream_info.total_samples = 0;
110 	memset(streaminfo_.data.stream_info.md5sum, 0, 16);
111 
112 	padding_.is_last = false;
113 	padding_.type = ::FLAC__METADATA_TYPE_PADDING;
114 	padding_.length = 1234;
115 
116 	seektable_.is_last = false;
117 	seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
118 	seektable_.data.seek_table.num_points = 2;
119 	seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
120 	seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
121 	seektable_.data.seek_table.points[0].sample_number = 0;
122 	seektable_.data.seek_table.points[0].stream_offset = 0;
123 	seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
124 	seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
125 	seektable_.data.seek_table.points[1].stream_offset = 1000;
126 	seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
127 
128 	application_.is_last = false;
129 	application_.type = ::FLAC__METADATA_TYPE_APPLICATION;
130 	application_.length = 8;
131 	memcpy(application_.data.application.id, "\xfe\xdc\xba\x98", 4);
132 	application_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
133 	memcpy(application_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
134 
135 	vorbiscomment_.is_last = false;
136 	vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
137 	vorbiscomment_.length = (4 + 5) + 4 + (4 + 12) + (4 + 12);
138 	vorbiscomment_.data.vorbis_comment.vendor_string.length = 5;
139 	vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5+1);
140 	memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5+1);
141 	vorbiscomment_.data.vorbis_comment.num_comments = 2;
142 	vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
143 	vorbiscomment_.data.vorbis_comment.comments[0].length = 12;
144 	vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12+1);
145 	memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12+1);
146 	vorbiscomment_.data.vorbis_comment.comments[1].length = 12;
147 	vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12+1);
148 	memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12+1);
149 
150 	cuesheet_.is_last = false;
151 	cuesheet_.type = ::FLAC__METADATA_TYPE_CUESHEET;
152 	cuesheet_.length =
153 		/* cuesheet guts */
154 		(
155 			FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
156 			FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
157 			FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
158 			FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
159 			FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
160 		) / 8 +
161 		/* 2 tracks */
162 		2 * (
163 			FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
164 			FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
165 			FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
166 			FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
167 			FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
168 			FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
169 			FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
170 		) / 8 +
171 		/* 3 index points */
172 		3 * (
173 			FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
174 			FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
175 			FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
176 		) / 8
177 	;
178 	memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number));
179 	cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j';
180 	cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C';
181 	cuesheet_.data.cue_sheet.lead_in = 159;
182 	cuesheet_.data.cue_sheet.is_cd = true;
183 	cuesheet_.data.cue_sheet.num_tracks = 2;
184 	cuesheet_.data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
185 	cuesheet_.data.cue_sheet.tracks[0].offset = 1;
186 	cuesheet_.data.cue_sheet.tracks[0].number = 1;
187 	memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc));
188 	cuesheet_.data.cue_sheet.tracks[0].type = 0;
189 	cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1;
190 	cuesheet_.data.cue_sheet.tracks[0].num_indices = 2;
191 	cuesheet_.data.cue_sheet.tracks[0].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet_.data.cue_sheet.tracks[0].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
192 	cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0;
193 	cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0;
194 	cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 1234567890;
195 	cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
196 	cuesheet_.data.cue_sheet.tracks[1].offset = 2345678901u;
197 	cuesheet_.data.cue_sheet.tracks[1].number = 2;
198 	memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc));
199 	cuesheet_.data.cue_sheet.tracks[1].type = 1;
200 	cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0;
201 	cuesheet_.data.cue_sheet.tracks[1].num_indices = 1;
202 	cuesheet_.data.cue_sheet.tracks[1].indices = (FLAC__StreamMetadata_CueSheet_Index*)malloc_or_die_(cuesheet_.data.cue_sheet.tracks[1].num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
203 	cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0;
204 	cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1;
205 
206 	picture_.is_last = true;
207 	picture_.type = FLAC__METADATA_TYPE_PICTURE;
208 	picture_.length =
209 		(
210 			FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
211 			FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */
212 			FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */
213 			FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
214 			FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
215 			FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
216 			FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
217 			FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
218 		) / 8
219 	;
220 	picture_.data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
221 	picture_.data.picture.mime_type = strdup_or_die_("image/jpeg");
222 	picture_.length += strlen(picture_.data.picture.mime_type);
223 	picture_.data.picture.description = (FLAC__byte*)strdup_or_die_("desc");
224 	picture_.length += strlen((const char *)picture_.data.picture.description);
225 	picture_.data.picture.width = 300;
226 	picture_.data.picture.height = 300;
227 	picture_.data.picture.depth = 24;
228 	picture_.data.picture.colors = 0;
229 	picture_.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
230 	picture_.data.picture.data_length = strlen((const char *)picture_.data.picture.data);
231 	picture_.length += picture_.data.picture.data_length;
232 }
233 
free_metadata_blocks_()234 static void free_metadata_blocks_()
235 {
236 	free(seektable_.data.seek_table.points);
237 	free(application_.data.application.data);
238 	free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
239 	free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
240 	free(vorbiscomment_.data.vorbis_comment.comments[1].entry);
241 	free(vorbiscomment_.data.vorbis_comment.comments);
242 	free(cuesheet_.data.cue_sheet.tracks[0].indices);
243 	free(cuesheet_.data.cue_sheet.tracks[1].indices);
244 	free(cuesheet_.data.cue_sheet.tracks);
245 	free(picture_.data.picture.mime_type);
246 	free(picture_.data.picture.description);
247 	free(picture_.data.picture.data);
248 }
249 
test_metadata_object_streaminfo()250 bool test_metadata_object_streaminfo()
251 {
252 	uint32_t expected_length;
253 
254 	printf("testing class FLAC::Metadata::StreamInfo\n");
255 
256 	printf("testing StreamInfo::StreamInfo()... ");
257 	FLAC::Metadata::StreamInfo block;
258 	if(!block.is_valid())
259 		return die_("!block.is_valid()");
260 	expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
261 	if(block.get_length() != expected_length) {
262 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
263 		return false;
264 	}
265 	printf("OK\n");
266 
267 	printf("testing StreamInfo::StreamInfo(const StreamInfo &)... +\n");
268 	printf("        StreamInfo::operator!=(const StreamInfo &)... ");
269 	{
270 		FLAC::Metadata::StreamInfo blockcopy(block);
271 		if(!blockcopy.is_valid())
272 			return die_("!blockcopy.is_valid()");
273 		if(blockcopy != block)
274 			return die_("copy is not identical to original");
275 		printf("OK\n");
276 
277 		printf("testing StreamInfo::~StreamInfo()... ");
278 	}
279 	printf("OK\n");
280 
281 	printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata &)... +\n");
282 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata &)... ");
283 	{
284 		FLAC::Metadata::StreamInfo blockcopy(streaminfo_);
285 		if(!blockcopy.is_valid())
286 			return die_("!blockcopy.is_valid()");
287 		if(blockcopy != streaminfo_)
288 			return die_("copy is not identical to original");
289 		printf("OK\n");
290 	}
291 
292 	printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *)... +\n");
293 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
294 	{
295 		FLAC::Metadata::StreamInfo blockcopy(&streaminfo_);
296 		if(!blockcopy.is_valid())
297 			return die_("!blockcopy.is_valid()");
298 		if(blockcopy != streaminfo_)
299 			return die_("copy is not identical to original");
300 		printf("OK\n");
301 	}
302 
303 	printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=true)... +\n");
304 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
305 	{
306 		FLAC::Metadata::StreamInfo blockcopy(&streaminfo_, /*copy=*/true);
307 		if(!blockcopy.is_valid())
308 			return die_("!blockcopy.is_valid()");
309 		if(blockcopy != streaminfo_)
310 			return die_("copy is not identical to original");
311 		printf("OK\n");
312 	}
313 
314 	printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=false)... +\n");
315 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
316 	{
317 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_);
318 		FLAC::Metadata::StreamInfo blockcopy(copy, /*copy=*/false);
319 		if(!blockcopy.is_valid())
320 			return die_("!blockcopy.is_valid()");
321 		if(blockcopy != streaminfo_)
322 			return die_("copy is not identical to original");
323 		printf("OK\n");
324 	}
325 
326 	printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
327 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
328 	{
329 		FLAC::Metadata::StreamInfo blockcopy;
330 		blockcopy.assign(&streaminfo_, /*copy=*/true);
331 		if(!blockcopy.is_valid())
332 			return die_("!blockcopy.is_valid()");
333 		if(blockcopy != streaminfo_)
334 			return die_("copy is not identical to original");
335 		printf("OK\n");
336 	}
337 
338 	printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
339 	printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
340 	{
341 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_);
342 		FLAC::Metadata::StreamInfo blockcopy;
343 		blockcopy.assign(copy, /*copy=*/false);
344 		if(!blockcopy.is_valid())
345 			return die_("!blockcopy.is_valid()");
346 		if(blockcopy != streaminfo_)
347 			return die_("copy is not identical to original");
348 		printf("OK\n");
349 	}
350 
351 	printf("testing StreamInfo::operator=(const StreamInfo &)... +\n");
352 	printf("        StreamInfo::operator==(const StreamInfo &)... ");
353 	{
354 		FLAC::Metadata::StreamInfo blockcopy = block;
355 		if(!blockcopy.is_valid())
356 			return die_("!blockcopy.is_valid()");
357 		if(!(blockcopy == block))
358 			return die_("copy is not identical to original");
359 		printf("OK\n");
360 	}
361 
362 	printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata &)... +\n");
363 	printf("        StreamInfo::operator==(const ::FLAC__StreamMetadata &)... ");
364 	{
365 		FLAC::Metadata::StreamInfo blockcopy = streaminfo_;
366 		if(!blockcopy.is_valid())
367 			return die_("!blockcopy.is_valid()");
368 		if(!(blockcopy == streaminfo_))
369 			return die_("copy is not identical to original");
370 		printf("OK\n");
371 	}
372 
373 	printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata *)... +\n");
374 	printf("        StreamInfo::operator==(const ::FLAC__StreamMetadata *)... ");
375 	{
376 		FLAC::Metadata::StreamInfo blockcopy = &streaminfo_;
377 		if(!blockcopy.is_valid())
378 			return die_("!blockcopy.is_valid()");
379 		if(!(blockcopy == streaminfo_))
380 			return die_("copy is not identical to original");
381 		printf("OK\n");
382 	}
383 
384 	printf("testing StreamInfo::set_min_blocksize()... ");
385 	block.set_min_blocksize(streaminfo_.data.stream_info.min_blocksize);
386 	printf("OK\n");
387 
388 	printf("testing StreamInfo::set_max_blocksize()... ");
389 	block.set_max_blocksize(streaminfo_.data.stream_info.max_blocksize);
390 	printf("OK\n");
391 
392 	printf("testing StreamInfo::set_min_framesize()... ");
393 	block.set_min_framesize(streaminfo_.data.stream_info.min_framesize);
394 	printf("OK\n");
395 
396 	printf("testing StreamInfo::set_max_framesize()... ");
397 	block.set_max_framesize(streaminfo_.data.stream_info.max_framesize);
398 	printf("OK\n");
399 
400 	printf("testing StreamInfo::set_sample_rate()... ");
401 	block.set_sample_rate(streaminfo_.data.stream_info.sample_rate);
402 	printf("OK\n");
403 
404 	printf("testing StreamInfo::set_channels()... ");
405 	block.set_channels(streaminfo_.data.stream_info.channels);
406 	printf("OK\n");
407 
408 	printf("testing StreamInfo::set_bits_per_sample()... ");
409 	block.set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample);
410 	printf("OK\n");
411 
412 	printf("testing StreamInfo::set_total_samples()... ");
413 	block.set_total_samples(streaminfo_.data.stream_info.total_samples);
414 	printf("OK\n");
415 
416 	printf("testing StreamInfo::set_md5sum()... ");
417 	block.set_md5sum(streaminfo_.data.stream_info.md5sum);
418 	printf("OK\n");
419 
420 	printf("testing StreamInfo::get_min_blocksize()... ");
421 	if(block.get_min_blocksize() != streaminfo_.data.stream_info.min_blocksize)
422 		return die_("value mismatch, doesn't match previously set value");
423 	printf("OK\n");
424 
425 	printf("testing StreamInfo::get_max_blocksize()... ");
426 	if(block.get_max_blocksize() != streaminfo_.data.stream_info.max_blocksize)
427 		return die_("value mismatch, doesn't match previously set value");
428 	printf("OK\n");
429 
430 	printf("testing StreamInfo::get_min_framesize()... ");
431 	if(block.get_min_framesize() != streaminfo_.data.stream_info.min_framesize)
432 		return die_("value mismatch, doesn't match previously set value");
433 	printf("OK\n");
434 
435 	printf("testing StreamInfo::get_max_framesize()... ");
436 	if(block.get_max_framesize() != streaminfo_.data.stream_info.max_framesize)
437 		return die_("value mismatch, doesn't match previously set value");
438 	printf("OK\n");
439 
440 	printf("testing StreamInfo::get_sample_rate()... ");
441 	if(block.get_sample_rate() != streaminfo_.data.stream_info.sample_rate)
442 		return die_("value mismatch, doesn't match previously set value");
443 	printf("OK\n");
444 
445 	printf("testing StreamInfo::get_channels()... ");
446 	if(block.get_channels() != streaminfo_.data.stream_info.channels)
447 		return die_("value mismatch, doesn't match previously set value");
448 	printf("OK\n");
449 
450 	printf("testing StreamInfo::get_bits_per_sample()... ");
451 	if(block.get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample)
452 		return die_("value mismatch, doesn't match previously set value");
453 	printf("OK\n");
454 
455 	printf("testing StreamInfo::get_total_samples()... ");
456 	if(block.get_total_samples() != streaminfo_.data.stream_info.total_samples)
457 		return die_("value mismatch, doesn't match previously set value");
458 	printf("OK\n");
459 
460 	printf("testing StreamInfo::get_md5sum()... ");
461 	if(0 != memcmp(block.get_md5sum(), streaminfo_.data.stream_info.md5sum, 16))
462 		return die_("value mismatch, doesn't match previously set value");
463 	printf("OK\n");
464 
465 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
466 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
467 	if(0 == clone_)
468 		return die_("returned NULL");
469 	if(0 == dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_))
470 		return die_("downcast is NULL");
471 	if(*dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_) != block)
472 		return die_("clone is not identical");
473 	printf("OK\n");
474 	printf("testing StreamInfo::~StreamInfo()... ");
475 	delete clone_;
476 	printf("OK\n");
477 
478 
479 	printf("PASSED\n\n");
480 	return true;
481 }
482 
test_metadata_object_padding()483 bool test_metadata_object_padding()
484 {
485 	uint32_t expected_length;
486 
487 	printf("testing class FLAC::Metadata::Padding\n");
488 
489 	printf("testing Padding::Padding()... ");
490 	FLAC::Metadata::Padding block;
491 	if(!block.is_valid())
492 		return die_("!block.is_valid()");
493 	expected_length = 0;
494 	if(block.get_length() != expected_length) {
495 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
496 		return false;
497 	}
498 	printf("OK\n");
499 
500 	printf("testing Padding::Padding(const Padding &)... +\n");
501 	printf("        Padding::operator!=(const Padding &)... ");
502 	{
503 		FLAC::Metadata::Padding blockcopy(block);
504 		if(!blockcopy.is_valid())
505 			return die_("!blockcopy.is_valid()");
506 		if(blockcopy != block)
507 			return die_("copy is not identical to original");
508 		printf("OK\n");
509 
510 		printf("testing Padding::~Padding()... ");
511 	}
512 	printf("OK\n");
513 
514 	printf("testing Padding::Padding(const ::FLAC__StreamMetadata &)... +\n");
515 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata &)... ");
516 	{
517 		FLAC::Metadata::Padding blockcopy(padding_);
518 		if(!blockcopy.is_valid())
519 			return die_("!blockcopy.is_valid()");
520 		if(blockcopy != padding_)
521 			return die_("copy is not identical to original");
522 		printf("OK\n");
523 	}
524 
525 	printf("testing Padding::Padding(const ::FLAC__StreamMetadata *)... +\n");
526 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
527 	{
528 		FLAC::Metadata::Padding blockcopy(&padding_);
529 		if(!blockcopy.is_valid())
530 			return die_("!blockcopy.is_valid()");
531 		if(blockcopy != padding_)
532 			return die_("copy is not identical to original");
533 		printf("OK\n");
534 	}
535 
536 	printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=true)... +\n");
537 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
538 	{
539 		FLAC::Metadata::Padding blockcopy(&padding_, /*copy=*/true);
540 		if(!blockcopy.is_valid())
541 			return die_("!blockcopy.is_valid()");
542 		if(blockcopy != padding_)
543 			return die_("copy is not identical to original");
544 		printf("OK\n");
545 	}
546 
547 	printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=false)... +\n");
548 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
549 	{
550 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_);
551 		FLAC::Metadata::Padding blockcopy(copy, /*copy=*/false);
552 		if(!blockcopy.is_valid())
553 			return die_("!blockcopy.is_valid()");
554 		if(blockcopy != padding_)
555 			return die_("copy is not identical to original");
556 		printf("OK\n");
557 	}
558 
559 	printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
560 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
561 	{
562 		FLAC::Metadata::Padding blockcopy;
563 		blockcopy.assign(&padding_, /*copy=*/true);
564 		if(!blockcopy.is_valid())
565 			return die_("!blockcopy.is_valid()");
566 		if(blockcopy != padding_)
567 			return die_("copy is not identical to original");
568 		printf("OK\n");
569 	}
570 
571 	printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
572 	printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
573 	{
574 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_);
575 		FLAC::Metadata::Padding blockcopy;
576 		blockcopy.assign(copy, /*copy=*/false);
577 		if(!blockcopy.is_valid())
578 			return die_("!blockcopy.is_valid()");
579 		if(blockcopy != padding_)
580 			return die_("copy is not identical to original");
581 		printf("OK\n");
582 	}
583 
584 	printf("testing Padding::operator=(const Padding &)... +\n");
585 	printf("        Padding::operator==(const Padding &)... ");
586 	{
587 		FLAC::Metadata::Padding blockcopy = block;
588 		if(!blockcopy.is_valid())
589 			return die_("!blockcopy.is_valid()");
590 		if(!(blockcopy == block))
591 			return die_("copy is not identical to original");
592 		printf("OK\n");
593 	}
594 
595 	printf("testing Padding::operator=(const ::FLAC__StreamMetadata &)... +\n");
596 	printf("        Padding::operator==(const ::FLAC__StreamMetadata &)... ");
597 	{
598 		FLAC::Metadata::Padding blockcopy = padding_;
599 		if(!blockcopy.is_valid())
600 			return die_("!blockcopy.is_valid()");
601 		if(!(blockcopy == padding_))
602 			return die_("copy is not identical to original");
603 		printf("OK\n");
604 	}
605 
606 	printf("testing Padding::operator=(const ::FLAC__StreamMetadata *)... +\n");
607 	printf("        Padding::operator==(const ::FLAC__StreamMetadata *)... ");
608 	{
609 		FLAC::Metadata::Padding blockcopy = &padding_;
610 		if(!blockcopy.is_valid())
611 			return die_("!blockcopy.is_valid()");
612 		if(!(blockcopy == padding_))
613 			return die_("copy is not identical to original");
614 		printf("OK\n");
615 	}
616 
617 	printf("testing Padding::set_length()... ");
618 	block.set_length(padding_.length);
619 	printf("OK\n");
620 
621 	printf("testing Prototype::get_length()... ");
622 	if(block.get_length() != padding_.length)
623 		return die_("value mismatch, doesn't match previously set value");
624 	printf("OK\n");
625 
626 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
627 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
628 	if(0 == clone_)
629 		return die_("returned NULL");
630 	if(0 == dynamic_cast<FLAC::Metadata::Padding *>(clone_))
631 		return die_("downcast is NULL");
632 	if(*dynamic_cast<FLAC::Metadata::Padding *>(clone_) != block)
633 		return die_("clone is not identical");
634 	printf("OK\n");
635 	printf("testing Padding::~Padding()... ");
636 	delete clone_;
637 	printf("OK\n");
638 
639 
640 	printf("PASSED\n\n");
641 	return true;
642 }
643 
test_metadata_object_application()644 bool test_metadata_object_application()
645 {
646 	uint32_t expected_length;
647 
648 	printf("testing class FLAC::Metadata::Application\n");
649 
650 	printf("testing Application::Application()... ");
651 	FLAC::Metadata::Application block;
652 	if(!block.is_valid())
653 		return die_("!block.is_valid()");
654 	expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
655 	if(block.get_length() != expected_length) {
656 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
657 		return false;
658 	}
659 	printf("OK\n");
660 
661 	printf("testing Application::Application(const Application &)... +\n");
662 	printf("        Application::operator!=(const Application &)... ");
663 	{
664 		FLAC::Metadata::Application blockcopy(block);
665 		if(!blockcopy.is_valid())
666 			return die_("!blockcopy.is_valid()");
667 		if(blockcopy != block)
668 			return die_("copy is not identical to original");
669 		printf("OK\n");
670 
671 		printf("testing Application::~Application()... ");
672 	}
673 	printf("OK\n");
674 
675 	printf("testing Application::Application(const ::FLAC__StreamMetadata &)... +\n");
676 	printf("        Application::operator!=(const ::FLAC__StreamMetadata &)... ");
677 	{
678 		FLAC::Metadata::Application blockcopy(application_);
679 		if(!blockcopy.is_valid())
680 			return die_("!blockcopy.is_valid()");
681 		if(blockcopy != application_)
682 			return die_("copy is not identical to original");
683 		printf("OK\n");
684 	}
685 
686 	printf("testing Application::Application(const ::FLAC__StreamMetadata *)... +\n");
687 	printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
688 	{
689 		FLAC::Metadata::Application blockcopy(&application_);
690 		if(!blockcopy.is_valid())
691 			return die_("!blockcopy.is_valid()");
692 		if(blockcopy != application_)
693 			return die_("copy is not identical to original");
694 		printf("OK\n");
695 	}
696 
697 	printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=true)... +\n");
698 	printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
699 	{
700 		FLAC::Metadata::Application blockcopy(&application_, /*copy=*/true);
701 		if(!blockcopy.is_valid())
702 			return die_("!blockcopy.is_valid()");
703 		if(blockcopy != application_)
704 			return die_("copy is not identical to original");
705 		printf("OK\n");
706 	}
707 
708 	printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=false)... +\n");
709 	printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
710 	{
711 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_);
712 		FLAC::Metadata::Application blockcopy(copy, /*copy=*/false);
713 		if(!blockcopy.is_valid())
714 			return die_("!blockcopy.is_valid()");
715 		if(blockcopy != application_)
716 			return die_("copy is not identical to original");
717 		printf("OK\n");
718 	}
719 
720 	printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
721 	printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
722 	{
723 		FLAC::Metadata::Application blockcopy;
724 		blockcopy.assign(&application_, /*copy=*/true);
725 		if(!blockcopy.is_valid())
726 			return die_("!blockcopy.is_valid()");
727 		if(blockcopy != application_)
728 			return die_("copy is not identical to original");
729 		printf("OK\n");
730 	}
731 
732 	printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
733 	printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
734 	{
735 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_);
736 		FLAC::Metadata::Application blockcopy;
737 		blockcopy.assign(copy, /*copy=*/false);
738 		if(!blockcopy.is_valid())
739 			return die_("!blockcopy.is_valid()");
740 		if(blockcopy != application_)
741 			return die_("copy is not identical to original");
742 		printf("OK\n");
743 	}
744 
745 	printf("testing Application::operator=(const Application &)... +\n");
746 	printf("        Application::operator==(const Application &)... ");
747 	{
748 		FLAC::Metadata::Application blockcopy = block;
749 		if(!blockcopy.is_valid())
750 			return die_("!blockcopy.is_valid()");
751 		if(!(blockcopy == block))
752 			return die_("copy is not identical to original");
753 		printf("OK\n");
754 	}
755 
756 	printf("testing Application::operator=(const ::FLAC__StreamMetadata &)... +\n");
757 	printf("        Application::operator==(const ::FLAC__StreamMetadata &)... ");
758 	{
759 		FLAC::Metadata::Application blockcopy = application_;
760 		if(!blockcopy.is_valid())
761 			return die_("!blockcopy.is_valid()");
762 		if(!(blockcopy == application_))
763 			return die_("copy is not identical to original");
764 		printf("OK\n");
765 	}
766 
767 	printf("testing Application::operator=(const ::FLAC__StreamMetadata *)... +\n");
768 	printf("        Application::operator==(const ::FLAC__StreamMetadata *)... ");
769 	{
770 		FLAC::Metadata::Application blockcopy = &application_;
771 		if(!blockcopy.is_valid())
772 			return die_("!blockcopy.is_valid()");
773 		if(!(blockcopy == application_))
774 			return die_("copy is not identical to original");
775 		printf("OK\n");
776 	}
777 
778 	printf("testing Application::set_id()... ");
779 	block.set_id(application_.data.application.id);
780 	printf("OK\n");
781 
782 	printf("testing Application::set_data()... ");
783 	block.set_data(application_.data.application.data, application_.length - sizeof(application_.data.application.id), /*copy=*/true);
784 	printf("OK\n");
785 
786 	printf("testing Application::get_id()... ");
787 	if(0 != memcmp(block.get_id(), application_.data.application.id, sizeof(application_.data.application.id)))
788 		return die_("value mismatch, doesn't match previously set value");
789 	printf("OK\n");
790 
791 	printf("testing Application::get_data()... ");
792 	if(0 != memcmp(block.get_data(), application_.data.application.data, application_.length - sizeof(application_.data.application.id)))
793 		return die_("value mismatch, doesn't match previously set value");
794 	printf("OK\n");
795 
796 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
797 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
798 	if(0 == clone_)
799 		return die_("returned NULL");
800 	if(0 == dynamic_cast<FLAC::Metadata::Application *>(clone_))
801 		return die_("downcast is NULL");
802 	if(*dynamic_cast<FLAC::Metadata::Application *>(clone_) != block)
803 		return die_("clone is not identical");
804 	printf("OK\n");
805 	printf("testing Application::~Application()... ");
806 	delete clone_;
807 	printf("OK\n");
808 
809 
810 	printf("PASSED\n\n");
811 	return true;
812 }
813 
test_metadata_object_seektable()814 bool test_metadata_object_seektable()
815 {
816 	uint32_t expected_length;
817 
818 	printf("testing class FLAC::Metadata::SeekTable\n");
819 
820 	printf("testing SeekTable::SeekTable()... ");
821 	FLAC::Metadata::SeekTable block;
822 	if(!block.is_valid())
823 		return die_("!block.is_valid()");
824 	expected_length = 0;
825 	if(block.get_length() != expected_length) {
826 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
827 		return false;
828 	}
829 	printf("OK\n");
830 
831 	printf("testing SeekTable::SeekTable(const SeekTable &)... +\n");
832 	printf("        SeekTable::operator!=(const SeekTable &)... ");
833 	{
834 		FLAC::Metadata::SeekTable blockcopy(block);
835 		if(!blockcopy.is_valid())
836 			return die_("!blockcopy.is_valid()");
837 		if(blockcopy != block)
838 			return die_("copy is not identical to original");
839 		printf("OK\n");
840 
841 		printf("testing SeekTable::~SeekTable()... ");
842 	}
843 	printf("OK\n");
844 
845 	printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata &)... +\n");
846 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
847 	{
848 		FLAC::Metadata::SeekTable blockcopy(seektable_);
849 		if(!blockcopy.is_valid())
850 			return die_("!blockcopy.is_valid()");
851 		if(blockcopy != seektable_)
852 			return die_("copy is not identical to original");
853 		printf("OK\n");
854 	}
855 
856 	printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *)... +\n");
857 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
858 	{
859 		FLAC::Metadata::SeekTable blockcopy(&seektable_);
860 		if(!blockcopy.is_valid())
861 			return die_("!blockcopy.is_valid()");
862 		if(blockcopy != seektable_)
863 			return die_("copy is not identical to original");
864 		printf("OK\n");
865 	}
866 
867 	printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=true)... +\n");
868 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
869 	{
870 		FLAC::Metadata::SeekTable blockcopy(&seektable_, /*copy=*/true);
871 		if(!blockcopy.is_valid())
872 			return die_("!blockcopy.is_valid()");
873 		if(blockcopy != seektable_)
874 			return die_("copy is not identical to original");
875 		printf("OK\n");
876 	}
877 
878 	printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=false)... +\n");
879 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
880 	{
881 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_);
882 		FLAC::Metadata::SeekTable blockcopy(copy, /*copy=*/false);
883 		if(!blockcopy.is_valid())
884 			return die_("!blockcopy.is_valid()");
885 		if(blockcopy != seektable_)
886 			return die_("copy is not identical to original");
887 		printf("OK\n");
888 	}
889 
890 	printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
891 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
892 	{
893 		FLAC::Metadata::SeekTable blockcopy;
894 		blockcopy.assign(&seektable_, /*copy=*/true);
895 		if(!blockcopy.is_valid())
896 			return die_("!blockcopy.is_valid()");
897 		if(blockcopy != seektable_)
898 			return die_("copy is not identical to original");
899 		printf("OK\n");
900 	}
901 
902 	printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
903 	printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
904 	{
905 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_);
906 		FLAC::Metadata::SeekTable blockcopy;
907 		blockcopy.assign(copy, /*copy=*/false);
908 		if(!blockcopy.is_valid())
909 			return die_("!blockcopy.is_valid()");
910 		if(blockcopy != seektable_)
911 			return die_("copy is not identical to original");
912 		printf("OK\n");
913 	}
914 
915 	printf("testing SeekTable::operator=(const SeekTable &)... +\n");
916 	printf("        SeekTable::operator==(const SeekTable &)... ");
917 	{
918 		FLAC::Metadata::SeekTable blockcopy = block;
919 		if(!blockcopy.is_valid())
920 			return die_("!blockcopy.is_valid()");
921 		if(!(blockcopy == block))
922 			return die_("copy is not identical to original");
923 		printf("OK\n");
924 	}
925 
926 	printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata &)... +\n");
927 	printf("        SeekTable::operator==(const ::FLAC__StreamMetadata &)... ");
928 	{
929 		FLAC::Metadata::SeekTable blockcopy = seektable_;
930 		if(!blockcopy.is_valid())
931 			return die_("!blockcopy.is_valid()");
932 		if(!(blockcopy == seektable_))
933 			return die_("copy is not identical to original");
934 		printf("OK\n");
935 	}
936 
937 	printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata *)... +\n");
938 	printf("        SeekTable::operator==(const ::FLAC__StreamMetadata *)... ");
939 	{
940 		FLAC::Metadata::SeekTable blockcopy = &seektable_;
941 		if(!blockcopy.is_valid())
942 			return die_("!blockcopy.is_valid()");
943 		if(!(blockcopy == seektable_))
944 			return die_("copy is not identical to original");
945 		printf("OK\n");
946 	}
947 
948 	printf("testing SeekTable::insert_point() x 3... ");
949 	if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
950 		return die_("returned false");
951 	if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
952 		return die_("returned false");
953 	if(!block.insert_point(1, seektable_.data.seek_table.points[0]))
954 		return die_("returned false");
955 	printf("OK\n");
956 
957 	printf("testing SeekTable::is_legal()... ");
958 	if(block.is_legal())
959 		return die_("returned true");
960 	printf("OK\n");
961 
962 	printf("testing SeekTable::set_point()... ");
963 	block.set_point(0, seektable_.data.seek_table.points[0]);
964 	printf("OK\n");
965 
966 	printf("testing SeekTable::delete_point()... ");
967 	if(!block.delete_point(0))
968 		return die_("returned false");
969 	printf("OK\n");
970 
971 	printf("testing SeekTable::is_legal()... ");
972 	if(!block.is_legal())
973 		return die_("returned false");
974 	printf("OK\n");
975 
976 	printf("testing SeekTable::get_num_points()... ");
977 	if(block.get_num_points() != seektable_.data.seek_table.num_points)
978 		return die_("number mismatch");
979 	printf("OK\n");
980 
981 	printf("testing SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
982 	if(block != seektable_)
983 		return die_("data mismatch");
984 	printf("OK\n");
985 
986 	printf("testing SeekTable::get_point()... ");
987 	if(
988 		block.get_point(1).sample_number != seektable_.data.seek_table.points[1].sample_number ||
989 		block.get_point(1).stream_offset != seektable_.data.seek_table.points[1].stream_offset ||
990 		block.get_point(1).frame_samples != seektable_.data.seek_table.points[1].frame_samples
991 	)
992 		return die_("point mismatch");
993 	printf("OK\n");
994 
995 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
996 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
997 	if(0 == clone_)
998 		return die_("returned NULL");
999 	if(0 == dynamic_cast<FLAC::Metadata::SeekTable *>(clone_))
1000 		return die_("downcast is NULL");
1001 	if(*dynamic_cast<FLAC::Metadata::SeekTable *>(clone_) != block)
1002 		return die_("clone is not identical");
1003 	printf("OK\n");
1004 	printf("testing SeekTable::~SeekTable()... ");
1005 	delete clone_;
1006 	printf("OK\n");
1007 
1008 
1009 	printf("PASSED\n\n");
1010 	return true;
1011 }
1012 
test_metadata_object_vorbiscomment()1013 bool test_metadata_object_vorbiscomment()
1014 {
1015 	uint32_t expected_length;
1016 
1017 	printf("testing class FLAC::Metadata::VorbisComment::Entry\n");
1018 
1019 	printf("testing Entry::Entry()... ");
1020 	{
1021 		FLAC::Metadata::VorbisComment::Entry entry1;
1022 		if(!entry1.is_valid())
1023 			return die_("!is_valid()");
1024 		printf("OK\n");
1025 
1026 		printf("testing Entry::~Entry()... ");
1027 	}
1028 	printf("OK\n");
1029 
1030 	printf("testing Entry::Entry(const char *field, uint32_t field_length)... ");
1031 	FLAC::Metadata::VorbisComment::Entry entry2("name2=value2", strlen("name2=value2"));
1032 	if(!entry2.is_valid())
1033 		return die_("!is_valid()");
1034 	printf("OK\n");
1035 
1036 	{
1037 		printf("testing Entry::Entry(const char *field)... ");
1038 		FLAC::Metadata::VorbisComment::Entry entry2z("name2=value2");
1039 		if(!entry2z.is_valid())
1040 			return die_("!is_valid()");
1041 		if(strcmp(entry2.get_field(), entry2z.get_field()))
1042 			return die_("bad value");
1043 		printf("OK\n");
1044 	}
1045 
1046 	printf("testing Entry::Entry(const char *field_name, const char *field_value, uint32_t field_value_length)... ");
1047 	FLAC::Metadata::VorbisComment::Entry entry3("name3", "value3", strlen("value3"));
1048 	if(!entry3.is_valid())
1049 		return die_("!is_valid()");
1050 	printf("OK\n");
1051 
1052 	{
1053 		printf("testing Entry::Entry(const char *field_name, const char *field_value)... ");
1054 		FLAC::Metadata::VorbisComment::Entry entry3z("name3", "value3");
1055 		if(!entry3z.is_valid())
1056 			return die_("!is_valid()");
1057 		if(strcmp(entry3.get_field(), entry3z.get_field()))
1058 			return die_("bad value");
1059 		printf("OK\n");
1060 	}
1061 
1062 	printf("testing Entry::Entry(const Entry &entry)... ");
1063 	{
1064 		FLAC::Metadata::VorbisComment::Entry entry2copy(entry2);
1065 		if(!entry2copy.is_valid())
1066 			return die_("!is_valid()");
1067 		printf("OK\n");
1068 
1069 		printf("testing Entry::~Entry()... ");
1070 	}
1071 	printf("OK\n");
1072 
1073 	printf("testing Entry::operator=(const Entry &entry)... ");
1074 	FLAC::Metadata::VorbisComment::Entry entry1 = entry2;
1075 	if(!entry2.is_valid())
1076 		return die_("!is_valid()");
1077 	printf("OK\n");
1078 
1079 	printf("testing Entry::get_field_length()... ");
1080 	if(entry1.get_field_length() != strlen("name2=value2"))
1081 		return die_("value mismatch");
1082 	printf("OK\n");
1083 
1084 	printf("testing Entry::get_field_name_length()... ");
1085 	if(entry1.get_field_name_length() != strlen("name2"))
1086 		return die_("value mismatch");
1087 	printf("OK\n");
1088 
1089 	printf("testing Entry::get_field_value_length()... ");
1090 	if(entry1.get_field_value_length() != strlen("value2"))
1091 		return die_("value mismatch");
1092 	printf("OK\n");
1093 
1094 	printf("testing Entry::get_entry()... ");
1095 	{
1096 		::FLAC__StreamMetadata_VorbisComment_Entry entry = entry1.get_entry();
1097 		if(entry.length != strlen("name2=value2"))
1098 			return die_("entry length mismatch");
1099 		if(0 != memcmp(entry.entry, "name2=value2", entry.length))
1100 			return die_("entry value mismatch");
1101 	}
1102 	printf("OK\n");
1103 
1104 	printf("testing Entry::get_field()... ");
1105 	if(0 != memcmp(entry1.get_field(), "name2=value2", strlen("name2=value2")))
1106 		return die_("value mismatch");
1107 	printf("OK\n");
1108 
1109 	printf("testing Entry::get_field_name()... ");
1110 	if(0 != memcmp(entry1.get_field_name(), "name2", strlen("name2")))
1111 		return die_("value mismatch");
1112 	printf("OK\n");
1113 
1114 	printf("testing Entry::get_field_value()... ");
1115 	if(0 != memcmp(entry1.get_field_value(), "value2", strlen("value2")))
1116 		return die_("value mismatch");
1117 	printf("OK\n");
1118 
1119 	printf("testing Entry::set_field_name()... ");
1120 	if(!entry1.set_field_name("name1"))
1121 		return die_("returned false");
1122 	if(0 != memcmp(entry1.get_field_name(), "name1", strlen("name1")))
1123 		return die_("value mismatch");
1124 	if(0 != memcmp(entry1.get_field(), "name1=value2", strlen("name1=value2")))
1125 		return die_("entry mismatch");
1126 	printf("OK\n");
1127 
1128 	printf("testing Entry::set_field_value(const char *field_value, uint32_t field_value_length)... ");
1129 	if(!entry1.set_field_value("value1", strlen("value1")))
1130 		return die_("returned false");
1131 	if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
1132 		return die_("value mismatch");
1133 	if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
1134 		return die_("entry mismatch");
1135 	printf("OK\n");
1136 
1137 	printf("testing Entry::set_field_value(const char *field_value)... ");
1138 	if(!entry1.set_field_value("value1"))
1139 		return die_("returned false");
1140 	if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
1141 		return die_("value mismatch");
1142 	if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
1143 		return die_("entry mismatch");
1144 	printf("OK\n");
1145 
1146 	printf("testing Entry::set_field(const char *field, uint32_t field_length)... ");
1147 	if(!entry1.set_field("name0=value0", strlen("name0=value0")))
1148 		return die_("returned false");
1149 	if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
1150 		return die_("value mismatch");
1151 	if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
1152 		return die_("value mismatch");
1153 	if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
1154 		return die_("entry mismatch");
1155 	printf("OK\n");
1156 
1157 	printf("testing Entry::set_field(const char *field)... ");
1158 	if(!entry1.set_field("name0=value0"))
1159 		return die_("returned false");
1160 	if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
1161 		return die_("value mismatch");
1162 	if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
1163 		return die_("value mismatch");
1164 	if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
1165 		return die_("entry mismatch");
1166 	printf("OK\n");
1167 
1168 	printf("PASSED\n\n");
1169 
1170 
1171 	printf("testing class FLAC::Metadata::VorbisComment\n");
1172 
1173 	printf("testing VorbisComment::VorbisComment()... ");
1174 	FLAC::Metadata::VorbisComment block;
1175 	if(!block.is_valid())
1176 		return die_("!block.is_valid()");
1177 	expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(::FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
1178 	if(block.get_length() != expected_length) {
1179 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
1180 		return false;
1181 	}
1182 	printf("OK\n");
1183 
1184 	printf("testing VorbisComment::VorbisComment(const VorbisComment &)... +\n");
1185 	printf("        VorbisComment::operator!=(const VorbisComment &)... ");
1186 	{
1187 		FLAC::Metadata::VorbisComment blockcopy(block);
1188 		if(!blockcopy.is_valid())
1189 			return die_("!blockcopy.is_valid()");
1190 		if(blockcopy != block)
1191 			return die_("copy is not identical to original");
1192 		printf("OK\n");
1193 
1194 		printf("testing VorbisComment::~VorbisComment()... ");
1195 	}
1196 	printf("OK\n");
1197 
1198 	printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata &)... +\n");
1199 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata &)... ");
1200 	{
1201 		FLAC::Metadata::VorbisComment blockcopy(vorbiscomment_);
1202 		if(!blockcopy.is_valid())
1203 			return die_("!blockcopy.is_valid()");
1204 		if(blockcopy != vorbiscomment_)
1205 			return die_("copy is not identical to original");
1206 		printf("OK\n");
1207 	}
1208 
1209 	printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *)... +\n");
1210 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
1211 	{
1212 		FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_);
1213 		if(!blockcopy.is_valid())
1214 			return die_("!blockcopy.is_valid()");
1215 		if(blockcopy != vorbiscomment_)
1216 			return die_("copy is not identical to original");
1217 		printf("OK\n");
1218 	}
1219 
1220 	printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1221 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
1222 	{
1223 		FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_, /*copy=*/true);
1224 		if(!blockcopy.is_valid())
1225 			return die_("!blockcopy.is_valid()");
1226 		if(blockcopy != vorbiscomment_)
1227 			return die_("copy is not identical to original");
1228 		printf("OK\n");
1229 	}
1230 
1231 	printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1232 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
1233 	{
1234 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_);
1235 		FLAC::Metadata::VorbisComment blockcopy(copy, /*copy=*/false);
1236 		if(!blockcopy.is_valid())
1237 			return die_("!blockcopy.is_valid()");
1238 		if(blockcopy != vorbiscomment_)
1239 			return die_("copy is not identical to original");
1240 		printf("OK\n");
1241 	}
1242 
1243 	printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1244 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
1245 	{
1246 		FLAC::Metadata::VorbisComment blockcopy;
1247 		blockcopy.assign(&vorbiscomment_, /*copy=*/true);
1248 		if(!blockcopy.is_valid())
1249 			return die_("!blockcopy.is_valid()");
1250 		if(blockcopy != vorbiscomment_)
1251 			return die_("copy is not identical to original");
1252 		printf("OK\n");
1253 	}
1254 
1255 	printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1256 	printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
1257 	{
1258 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_);
1259 		FLAC::Metadata::VorbisComment blockcopy;
1260 		blockcopy.assign(copy, /*copy=*/false);
1261 		if(!blockcopy.is_valid())
1262 			return die_("!blockcopy.is_valid()");
1263 		if(blockcopy != vorbiscomment_)
1264 			return die_("copy is not identical to original");
1265 		printf("OK\n");
1266 	}
1267 
1268 	printf("testing VorbisComment::operator=(const VorbisComment &)... +\n");
1269 	printf("        VorbisComment::operator==(const VorbisComment &)... ");
1270 	{
1271 		FLAC::Metadata::VorbisComment blockcopy = block;
1272 		if(!blockcopy.is_valid())
1273 			return die_("!blockcopy.is_valid()");
1274 		if(!(blockcopy == block))
1275 			return die_("copy is not identical to original");
1276 		printf("OK\n");
1277 	}
1278 
1279 	printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata &)... +\n");
1280 	printf("        VorbisComment::operator==(const ::FLAC__StreamMetadata &)... ");
1281 	{
1282 		FLAC::Metadata::VorbisComment blockcopy = vorbiscomment_;
1283 		if(!blockcopy.is_valid())
1284 			return die_("!blockcopy.is_valid()");
1285 		if(!(blockcopy == vorbiscomment_))
1286 			return die_("copy is not identical to original");
1287 		printf("OK\n");
1288 	}
1289 
1290 	printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata *)... +\n");
1291 	printf("        VorbisComment::operator==(const ::FLAC__StreamMetadata *)... ");
1292 	{
1293 		FLAC::Metadata::VorbisComment blockcopy = &vorbiscomment_;
1294 		if(!blockcopy.is_valid())
1295 			return die_("!blockcopy.is_valid()");
1296 		if(!(blockcopy == vorbiscomment_))
1297 			return die_("copy is not identical to original");
1298 		printf("OK\n");
1299 	}
1300 
1301 	printf("testing VorbisComment::get_num_comments()... ");
1302 	if(block.get_num_comments() != 0)
1303 		return die_("value mismatch, expected 0");
1304 	printf("OK\n");
1305 
1306 	printf("testing VorbisComment::set_vendor_string()... ");
1307 	if(!block.set_vendor_string((const FLAC__byte *)"mame0"))
1308 		return die_("returned false");
1309 	printf("OK\n");
1310 	vorbiscomment_.data.vorbis_comment.vendor_string.entry[0] = 'm';
1311 
1312 	printf("testing VorbisComment::get_vendor_string()... ");
1313 	if(strlen((const char *)block.get_vendor_string()) != vorbiscomment_.data.vorbis_comment.vendor_string.length)
1314 		return die_("length mismatch");
1315 	if(0 != memcmp(block.get_vendor_string(), vorbiscomment_.data.vorbis_comment.vendor_string.entry, vorbiscomment_.data.vorbis_comment.vendor_string.length))
1316 		return die_("value mismatch");
1317 	printf("OK\n");
1318 
1319 	printf("testing VorbisComment::append_comment()... +\n");
1320 	printf("        VorbisComment::get_comment()... ");
1321 	if(!block.append_comment(entry3))
1322 		return die_("returned false");
1323 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
1324 		return die_("length mismatch");
1325 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
1326 		return die_("value mismatch");
1327 	printf("OK\n");
1328 
1329 	printf("testing VorbisComment::append_comment()... +\n");
1330 	printf("        VorbisComment::get_comment()... ");
1331 	if(!block.append_comment(entry2))
1332 		return die_("returned false");
1333 	if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1334 		return die_("length mismatch");
1335 	if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1336 		return die_("value mismatch");
1337 	printf("OK\n");
1338 
1339 	printf("testing VorbisComment::delete_comment()... +\n");
1340 	printf("        VorbisComment::get_comment()... ");
1341 	if(!block.delete_comment(0))
1342 		return die_("returned false");
1343 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1344 		return die_("length[0] mismatch");
1345 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1346 		return die_("value[0] mismatch");
1347 	printf("OK\n");
1348 
1349 	printf("testing VorbisComment::delete_comment()... +\n");
1350 	printf("        VorbisComment::get_comment()... ");
1351 	if(!block.delete_comment(0))
1352 		return die_("returned false");
1353 	if(block.get_num_comments() != 0)
1354 		return die_("block mismatch, expected num_comments = 0");
1355 	printf("OK\n");
1356 
1357 	printf("testing VorbisComment::insert_comment()... +\n");
1358 	printf("        VorbisComment::get_comment()... ");
1359 	if(!block.insert_comment(0, entry3))
1360 		return die_("returned false");
1361 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
1362 		return die_("length mismatch");
1363 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
1364 		return die_("value mismatch");
1365 	printf("OK\n");
1366 
1367 	printf("testing VorbisComment::insert_comment()... +\n");
1368 	printf("        VorbisComment::get_comment()... ");
1369 	if(!block.insert_comment(0, entry3))
1370 		return die_("returned false");
1371 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
1372 		return die_("length mismatch");
1373 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
1374 		return die_("value mismatch");
1375 	printf("OK\n");
1376 
1377 	printf("testing VorbisComment::insert_comment()... +\n");
1378 	printf("        VorbisComment::get_comment()... ");
1379 	if(!block.insert_comment(1, entry2))
1380 		return die_("returned false");
1381 	if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1382 		return die_("length mismatch");
1383 	if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1384 		return die_("value mismatch");
1385 	printf("OK\n");
1386 
1387 	printf("testing VorbisComment::set_comment()... +\n");
1388 	printf("        VorbisComment::get_comment()... ");
1389 	if(!block.set_comment(0, entry2))
1390 		return die_("returned false");
1391 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1392 		return die_("length mismatch");
1393 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1394 		return die_("value mismatch");
1395 	printf("OK\n");
1396 
1397 	printf("testing VorbisComment::delete_comment()... +\n");
1398 	printf("        VorbisComment::get_comment()... ");
1399 	if(!block.delete_comment(0))
1400 		return die_("returned false");
1401 	if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1402 		return die_("length[0] mismatch");
1403 	if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1404 		return die_("value[0] mismatch");
1405 	if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
1406 		return die_("length[1] mismatch");
1407 	if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
1408 		return die_("value[0] mismatch");
1409 	printf("OK\n");
1410 
1411 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
1412 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
1413 	if(0 == clone_)
1414 		return die_("returned NULL");
1415 	if(0 == dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_))
1416 		return die_("downcast is NULL");
1417 	if(*dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_) != block)
1418 		return die_("clone is not identical");
1419 	printf("OK\n");
1420 	printf("testing VorbisComment::~VorbisComment()... ");
1421 	delete clone_;
1422 	printf("OK\n");
1423 
1424 
1425 	printf("PASSED\n\n");
1426 	return true;
1427 }
1428 
test_metadata_object_cuesheet()1429 bool test_metadata_object_cuesheet()
1430 {
1431 	uint32_t expected_length;
1432 
1433 	printf("testing class FLAC::Metadata::CueSheet::Track\n");
1434 
1435 	printf("testing Track::Track()... ");
1436 	FLAC::Metadata::CueSheet::Track track0;
1437 	if(!track0.is_valid())
1438 		return die_("!is_valid()");
1439 	printf("OK\n");
1440 
1441 	{
1442 		printf("testing Track::get_track()... ");
1443 		const ::FLAC__StreamMetadata_CueSheet_Track *trackp = track0.get_track();
1444 		if(0 == trackp)
1445 			return die_("returned pointer is NULL");
1446 		printf("OK\n");
1447 
1448 		printf("testing Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track*)... ");
1449 		FLAC::Metadata::CueSheet::Track track2(trackp);
1450 		if(!track2.is_valid())
1451 			return die_("!is_valid()");
1452 		if(!track_is_equal_(track2.get_track(), trackp))
1453 			return die_("copy is not equal");
1454 		printf("OK\n");
1455 
1456 		printf("testing Track::~Track()... ");
1457 	}
1458 	printf("OK\n");
1459 
1460 	printf("testing Track::Track(const Track &track)... ");
1461 	{
1462 		FLAC::Metadata::CueSheet::Track track0copy(track0);
1463 		if(!track0copy.is_valid())
1464 			return die_("!is_valid()");
1465 		if(!track_is_equal_(track0copy.get_track(), track0.get_track()))
1466 			return die_("copy is not equal");
1467 		printf("OK\n");
1468 
1469 		printf("testing Track::~Track()... ");
1470 	}
1471 	printf("OK\n");
1472 
1473 	printf("testing Track::operator=(const Track &track)... ");
1474 	FLAC::Metadata::CueSheet::Track track1 = track0;
1475 	if(!track0.is_valid())
1476 		return die_("!is_valid()");
1477 	if(!track_is_equal_(track1.get_track(), track0.get_track()))
1478 		return die_("copy is not equal");
1479 	printf("OK\n");
1480 
1481 	printf("testing Track::get_offset()... ");
1482 	if(track1.get_offset() != 0)
1483 		return die_("value mismatch");
1484 	printf("OK\n");
1485 
1486 	printf("testing Track::get_number()... ");
1487 	if(track1.get_number() != 0)
1488 		return die_("value mismatch");
1489 	printf("OK\n");
1490 
1491 	printf("testing Track::get_isrc()... ");
1492 	if(0 != memcmp(track1.get_isrc(), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 13))
1493 		return die_("value mismatch");
1494 	printf("OK\n");
1495 
1496 	printf("testing Track::get_type()... ");
1497 	if(track1.get_type() != 0)
1498 		return die_("value mismatch");
1499 	printf("OK\n");
1500 
1501 	printf("testing Track::get_pre_emphasis()... ");
1502 	if(track1.get_pre_emphasis() != 0)
1503 		return die_("value mismatch");
1504 	printf("OK\n");
1505 
1506 	printf("testing Track::get_num_indices()... ");
1507 	if(track1.get_num_indices() != 0)
1508 		return die_("value mismatch");
1509 	printf("OK\n");
1510 
1511 	printf("testing Track::set_offset()... ");
1512 	track1.set_offset(588);
1513 	if(track1.get_offset() != 588)
1514 		return die_("value mismatch");
1515 	printf("OK\n");
1516 
1517 	printf("testing Track::set_number()... ");
1518 	track1.set_number(1);
1519 	if(track1.get_number() != 1)
1520 		return die_("value mismatch");
1521 	printf("OK\n");
1522 
1523 	printf("testing Track::set_isrc()... ");
1524 	track1.set_isrc("ABCDE1234567");
1525 	if(0 != memcmp(track1.get_isrc(), "ABCDE1234567", 13))
1526 		return die_("value mismatch");
1527 	printf("OK\n");
1528 
1529 	printf("testing Track::set_type()... ");
1530 	track1.set_type(1);
1531 	if(track1.get_type() != 1)
1532 		return die_("value mismatch");
1533 	printf("OK\n");
1534 
1535 	printf("testing Track::set_pre_emphasis()... ");
1536 	track1.set_pre_emphasis(1);
1537 	if(track1.get_pre_emphasis() != 1)
1538 		return die_("value mismatch");
1539 	printf("OK\n");
1540 
1541 	printf("PASSED\n\n");
1542 
1543 	printf("testing class FLAC::Metadata::CueSheet\n");
1544 
1545 	printf("testing CueSheet::CueSheet()... ");
1546 	FLAC::Metadata::CueSheet block;
1547 	if(!block.is_valid())
1548 		return die_("!block.is_valid()");
1549 	expected_length = (
1550 		FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1551 		FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1552 		FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
1553 		FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1554 		FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1555 	) / 8;
1556 	if(block.get_length() != expected_length) {
1557 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
1558 		return false;
1559 	}
1560 	printf("OK\n");
1561 
1562 	printf("testing CueSheet::CueSheet(const CueSheet &)... +\n");
1563 	printf("        CueSheet::operator!=(const CueSheet &)... ");
1564 	{
1565 		FLAC::Metadata::CueSheet blockcopy(block);
1566 		if(!blockcopy.is_valid())
1567 			return die_("!blockcopy.is_valid()");
1568 		if(blockcopy != block)
1569 			return die_("copy is not identical to original");
1570 		printf("OK\n");
1571 
1572 		printf("testing CueSheet::~CueSheet()... ");
1573 	}
1574 	printf("OK\n");
1575 
1576 	printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata &)... +\n");
1577 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata &)... ");
1578 	{
1579 		FLAC::Metadata::CueSheet blockcopy(cuesheet_);
1580 		if(!blockcopy.is_valid())
1581 			return die_("!blockcopy.is_valid()");
1582 		if(blockcopy != cuesheet_)
1583 			return die_("copy is not identical to original");
1584 		printf("OK\n");
1585 	}
1586 
1587 	printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *)... +\n");
1588 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1589 	{
1590 		FLAC::Metadata::CueSheet blockcopy(&cuesheet_);
1591 		if(!blockcopy.is_valid())
1592 			return die_("!blockcopy.is_valid()");
1593 		if(blockcopy != cuesheet_)
1594 			return die_("copy is not identical to original");
1595 		printf("OK\n");
1596 	}
1597 
1598 	printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1599 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1600 	{
1601 		FLAC::Metadata::CueSheet blockcopy(&cuesheet_, /*copy=*/true);
1602 		if(!blockcopy.is_valid())
1603 			return die_("!blockcopy.is_valid()");
1604 		if(blockcopy != cuesheet_)
1605 			return die_("copy is not identical to original");
1606 		printf("OK\n");
1607 	}
1608 
1609 	printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1610 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1611 	{
1612 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_);
1613 		FLAC::Metadata::CueSheet blockcopy(copy, /*copy=*/false);
1614 		if(!blockcopy.is_valid())
1615 			return die_("!blockcopy.is_valid()");
1616 		if(blockcopy != cuesheet_)
1617 			return die_("copy is not identical to original");
1618 		printf("OK\n");
1619 	}
1620 
1621 	printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1622 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1623 	{
1624 		FLAC::Metadata::CueSheet blockcopy;
1625 		blockcopy.assign(&cuesheet_, /*copy=*/true);
1626 		if(!blockcopy.is_valid())
1627 			return die_("!blockcopy.is_valid()");
1628 		if(blockcopy != cuesheet_)
1629 			return die_("copy is not identical to original");
1630 		printf("OK\n");
1631 	}
1632 
1633 	printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1634 	printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1635 	{
1636 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_);
1637 		FLAC::Metadata::CueSheet blockcopy;
1638 		blockcopy.assign(copy, /*copy=*/false);
1639 		if(!blockcopy.is_valid())
1640 			return die_("!blockcopy.is_valid()");
1641 		if(blockcopy != cuesheet_)
1642 			return die_("copy is not identical to original");
1643 		printf("OK\n");
1644 	}
1645 
1646 	printf("testing CueSheet::operator=(const CueSheet &)... +\n");
1647 	printf("        CueSheet::operator==(const CueSheet &)... ");
1648 	{
1649 		FLAC::Metadata::CueSheet blockcopy = block;
1650 		if(!blockcopy.is_valid())
1651 			return die_("!blockcopy.is_valid()");
1652 		if(!(blockcopy == block))
1653 			return die_("copy is not identical to original");
1654 		printf("OK\n");
1655 	}
1656 
1657 	printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata &)... +\n");
1658 	printf("        CueSheet::operator==(const ::FLAC__StreamMetadata &)... ");
1659 	{
1660 		FLAC::Metadata::CueSheet blockcopy = cuesheet_;
1661 		if(!blockcopy.is_valid())
1662 			return die_("!blockcopy.is_valid()");
1663 		if(!(blockcopy == cuesheet_))
1664 			return die_("copy is not identical to original");
1665 		printf("OK\n");
1666 	}
1667 
1668 	printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata *)... +\n");
1669 	printf("        CueSheet::operator==(const ::FLAC__StreamMetadata *)... ");
1670 	{
1671 		FLAC::Metadata::CueSheet blockcopy = &cuesheet_;
1672 		if(!blockcopy.is_valid())
1673 			return die_("!blockcopy.is_valid()");
1674 		if(!(blockcopy == cuesheet_))
1675 			return die_("copy is not identical to original");
1676 		printf("OK\n");
1677 	}
1678 
1679 	printf("testing CueSheet::get_media_catalog_number()... ");
1680 	if(0 != strcmp(block.get_media_catalog_number(), ""))
1681 		return die_("value mismatch");
1682 	printf("OK\n");
1683 
1684 	printf("testing CueSheet::get_lead_in()... ");
1685 	if(block.get_lead_in() != 0)
1686 		return die_("value mismatch, expected 0");
1687 	printf("OK\n");
1688 
1689 	printf("testing CueSheet::get_is_cd()... ");
1690 	if(block.get_is_cd())
1691 		return die_("value mismatch, expected false");
1692 	printf("OK\n");
1693 
1694 	printf("testing CueSheet::get_num_tracks()... ");
1695 	if(block.get_num_tracks() != 0)
1696 		return die_("value mismatch, expected 0");
1697 	printf("OK\n");
1698 
1699 	printf("testing CueSheet::set_media_catalog_number()... ");
1700 	{
1701 		char mcn[129];
1702 		memset(mcn, 0, sizeof(mcn));
1703 		safe_strncpy(mcn, "1234567890123", sizeof(mcn));
1704 		block.set_media_catalog_number(mcn);
1705 		if(0 != memcmp(block.get_media_catalog_number(), mcn, sizeof(mcn)))
1706 			return die_("value mismatch");
1707 	}
1708 	printf("OK\n");
1709 
1710 	printf("testing CueSheet::set_lead_in()... ");
1711 	block.set_lead_in(588);
1712 	if(block.get_lead_in() != 588)
1713 		return die_("value mismatch");
1714 	printf("OK\n");
1715 
1716 	printf("testing CueSheet::set_is_cd()... ");
1717 	block.set_is_cd(true);
1718 	if(!block.get_is_cd())
1719 		return die_("value mismatch");
1720 	printf("OK\n");
1721 
1722 	printf("testing CueSheet::insert_track()... +\n");
1723 	printf("        CueSheet::get_track()... ");
1724 	if(!block.insert_track(0, track0))
1725 		return die_("returned false");
1726 	if(!track_is_equal_(block.get_track(0).get_track(), track0.get_track()))
1727 		return die_("value mismatch");
1728 	printf("OK\n");
1729 
1730 	printf("testing CueSheet::insert_track()... +\n");
1731 	printf("        CueSheet::get_track()... ");
1732 	if(!block.insert_track(1, track1))
1733 		return die_("returned false");
1734 	if(!track_is_equal_(block.get_track(1).get_track(), track1.get_track()))
1735 		return die_("value mismatch");
1736 	printf("OK\n");
1737 
1738 	::FLAC__StreamMetadata_CueSheet_Index index0;
1739 	index0.offset = 588*4;
1740 	index0.number = 1;
1741 
1742 	printf("testing CueSheet::insert_index(0)... +\n");
1743 	printf("        CueSheet::get_track()... +\n");
1744 	printf("        CueSheet::Track::get_index()... ");
1745 	if(!block.insert_index(0, 0, index0))
1746 		return die_("returned false");
1747 	if(!index_is_equal_(block.get_track(0).get_index(0), index0))
1748 		return die_("value mismatch");
1749 	printf("OK\n");
1750 
1751 	index0.offset = 588*5;
1752 	printf("testing CueSheet::Track::set_index()... ");
1753 	{
1754 		FLAC::Metadata::CueSheet::Track track_ = block.get_track(0);
1755 		track_.set_index(0, index0);
1756 		if(!index_is_equal_(track_.get_index(0), index0))
1757 			return die_("value mismatch");
1758 	}
1759 	printf("OK\n");
1760 
1761 	index0.offset = 588*6;
1762 	printf("testing CueSheet::set_index()... ");
1763 	block.set_index(0, 0, index0);
1764 	if(!index_is_equal_(block.get_track(0).get_index(0), index0))
1765 		return die_("value mismatch");
1766 	printf("OK\n");
1767 
1768 	printf("testing CueSheet::delete_index()... ");
1769 	if(!block.delete_index(0, 0))
1770 		return die_("returned false");
1771 	if(block.get_track(0).get_num_indices() != 0)
1772 		return die_("num_indices mismatch");
1773 	printf("OK\n");
1774 
1775 
1776 	printf("testing CueSheet::set_track()... +\n");
1777 	printf("        CueSheet::get_track()... ");
1778 	if(!block.set_track(0, track1))
1779 		return die_("returned false");
1780 	if(!track_is_equal_(block.get_track(0).get_track(), track1.get_track()))
1781 		return die_("value mismatch");
1782 	printf("OK\n");
1783 
1784 	printf("testing CueSheet::delete_track()... ");
1785 	if(!block.delete_track(0))
1786 		return die_("returned false");
1787 	if(block.get_num_tracks() != 1)
1788 		return die_("num_tracks mismatch");
1789 	printf("OK\n");
1790 
1791 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
1792 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
1793 	if(0 == clone_)
1794 		return die_("returned NULL");
1795 	if(0 == dynamic_cast<FLAC::Metadata::CueSheet *>(clone_))
1796 		return die_("downcast is NULL");
1797 	if(*dynamic_cast<FLAC::Metadata::CueSheet *>(clone_) != block)
1798 		return die_("clone is not identical");
1799 	printf("OK\n");
1800 	printf("testing CueSheet::~CueSheet()... ");
1801 	delete clone_;
1802 	printf("OK\n");
1803 
1804 	printf("PASSED\n\n");
1805 	return true;
1806 }
1807 
test_metadata_object_picture()1808 bool test_metadata_object_picture()
1809 {
1810 	uint32_t expected_length;
1811 
1812 	printf("testing class FLAC::Metadata::Picture\n");
1813 
1814 	printf("testing Picture::Picture()... ");
1815 	FLAC::Metadata::Picture block;
1816 	if(!block.is_valid())
1817 		return die_("!block.is_valid()");
1818 	expected_length = (
1819 		FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
1820 		FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
1821 		FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
1822 		FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
1823 		FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
1824 		FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
1825 		FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
1826 		FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
1827 	) / 8;
1828 	if(block.get_length() != expected_length) {
1829 		printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
1830 		return false;
1831 	}
1832 	printf("OK\n");
1833 
1834 	printf("testing Picture::Picture(const Picture &)... +\n");
1835 	printf("        Picture::operator!=(const Picture &)... ");
1836 	{
1837 		FLAC::Metadata::Picture blockcopy(block);
1838 		if(!blockcopy.is_valid())
1839 			return die_("!blockcopy.is_valid()");
1840 		if(blockcopy != block)
1841 			return die_("copy is not identical to original");
1842 		printf("OK\n");
1843 
1844 		printf("testing Picture::~Picture()... ");
1845 	}
1846 	printf("OK\n");
1847 
1848 	printf("testing Picture::Picture(const ::FLAC__StreamMetadata &)... +\n");
1849 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata &)... ");
1850 	{
1851 		FLAC::Metadata::Picture blockcopy(picture_);
1852 		if(!blockcopy.is_valid())
1853 			return die_("!blockcopy.is_valid()");
1854 		if(blockcopy != picture_)
1855 			return die_("copy is not identical to original");
1856 		printf("OK\n");
1857 	}
1858 
1859 	printf("testing Picture::Picture(const ::FLAC__StreamMetadata *)... +\n");
1860 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
1861 	{
1862 		FLAC::Metadata::Picture blockcopy(&picture_);
1863 		if(!blockcopy.is_valid())
1864 			return die_("!blockcopy.is_valid()");
1865 		if(blockcopy != picture_)
1866 			return die_("copy is not identical to original");
1867 		printf("OK\n");
1868 	}
1869 
1870 	printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1871 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
1872 	{
1873 		FLAC::Metadata::Picture blockcopy(&picture_, /*copy=*/true);
1874 		if(!blockcopy.is_valid())
1875 			return die_("!blockcopy.is_valid()");
1876 		if(blockcopy != picture_)
1877 			return die_("copy is not identical to original");
1878 		printf("OK\n");
1879 	}
1880 
1881 	printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1882 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
1883 	{
1884 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_);
1885 		FLAC::Metadata::Picture blockcopy(copy, /*copy=*/false);
1886 		if(!blockcopy.is_valid())
1887 			return die_("!blockcopy.is_valid()");
1888 		if(blockcopy != picture_)
1889 			return die_("copy is not identical to original");
1890 		printf("OK\n");
1891 	}
1892 
1893 	printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
1894 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
1895 	{
1896 		FLAC::Metadata::Picture blockcopy;
1897 		blockcopy.assign(&picture_, /*copy=*/true);
1898 		if(!blockcopy.is_valid())
1899 			return die_("!blockcopy.is_valid()");
1900 		if(blockcopy != picture_)
1901 			return die_("copy is not identical to original");
1902 		printf("OK\n");
1903 	}
1904 
1905 	printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
1906 	printf("        Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
1907 	{
1908 		::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_);
1909 		FLAC::Metadata::Picture blockcopy;
1910 		blockcopy.assign(copy, /*copy=*/false);
1911 		if(!blockcopy.is_valid())
1912 			return die_("!blockcopy.is_valid()");
1913 		if(blockcopy != picture_)
1914 			return die_("copy is not identical to original");
1915 		printf("OK\n");
1916 	}
1917 
1918 	printf("testing Picture::operator=(const Picture &)... +\n");
1919 	printf("        Picture::operator==(const Picture &)... ");
1920 	{
1921 		FLAC::Metadata::Picture blockcopy = block;
1922 		if(!blockcopy.is_valid())
1923 			return die_("!blockcopy.is_valid()");
1924 		if(!(blockcopy == block))
1925 			return die_("copy is not identical to original");
1926 		printf("OK\n");
1927 	}
1928 
1929 	printf("testing Picture::operator=(const ::FLAC__StreamMetadata &)... +\n");
1930 	printf("        Picture::operator==(const ::FLAC__StreamMetadata &)... ");
1931 	{
1932 		FLAC::Metadata::Picture blockcopy = picture_;
1933 		if(!blockcopy.is_valid())
1934 			return die_("!blockcopy.is_valid()");
1935 		if(!(blockcopy == picture_))
1936 			return die_("copy is not identical to original");
1937 		printf("OK\n");
1938 	}
1939 
1940 	printf("testing Picture::operator=(const ::FLAC__StreamMetadata *)... +\n");
1941 	printf("        Picture::operator==(const ::FLAC__StreamMetadata *)... ");
1942 	{
1943 		FLAC::Metadata::Picture blockcopy = &picture_;
1944 		if(!blockcopy.is_valid())
1945 			return die_("!blockcopy.is_valid()");
1946 		if(!(blockcopy == picture_))
1947 			return die_("copy is not identical to original");
1948 		printf("OK\n");
1949 	}
1950 
1951 	printf("testing Picture::get_type()... ");
1952 	if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER)
1953 		return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER");
1954 	printf("OK\n");
1955 
1956 	printf("testing Picture::set_type()... +\n");
1957 	printf("        Picture::get_type()... ");
1958 	block.set_type(::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA);
1959 	if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA)
1960 		return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA");
1961 	printf("OK\n");
1962 
1963 	printf("testing Picture::set_mime_type()... ");
1964 	if(!block.set_mime_type("qmage/jpeg"))
1965 		return die_("returned false");
1966 	printf("OK\n");
1967 	picture_.data.picture.mime_type[0] = 'q';
1968 
1969 	printf("testing Picture::get_mime_type()... ");
1970 	if(0 != strcmp(block.get_mime_type(), picture_.data.picture.mime_type))
1971 		return die_("value mismatch");
1972 	printf("OK\n");
1973 
1974 	printf("testing Picture::set_description()... ");
1975 	if(!block.set_description((const FLAC__byte*)"qesc"))
1976 		return die_("returned false");
1977 	printf("OK\n");
1978 	picture_.data.picture.description[0] = 'q';
1979 
1980 	printf("testing Picture::get_description()... ");
1981 	if(0 != strcmp((const char *)block.get_description(), (const char *)picture_.data.picture.description))
1982 		return die_("value mismatch");
1983 	printf("OK\n");
1984 
1985 	printf("testing Picture::get_width()... ");
1986 	if(block.get_width() != 0)
1987 		return die_("value mismatch, expected 0");
1988 	printf("OK\n");
1989 
1990 	printf("testing Picture::set_width()... +\n");
1991 	printf("        Picture::get_width()... ");
1992 	block.set_width(400);
1993 	if(block.get_width() != 400)
1994 		return die_("value mismatch, expected 400");
1995 	printf("OK\n");
1996 
1997 	printf("testing Picture::get_height()... ");
1998 	if(block.get_height() != 0)
1999 		return die_("value mismatch, expected 0");
2000 	printf("OK\n");
2001 
2002 	printf("testing Picture::set_height()... +\n");
2003 	printf("        Picture::get_height()... ");
2004 	block.set_height(200);
2005 	if(block.get_height() != 200)
2006 		return die_("value mismatch, expected 200");
2007 	printf("OK\n");
2008 
2009 	printf("testing Picture::get_depth()... ");
2010 	if(block.get_depth() != 0)
2011 		return die_("value mismatch, expected 0");
2012 	printf("OK\n");
2013 
2014 	printf("testing Picture::set_depth()... +\n");
2015 	printf("        Picture::get_depth()... ");
2016 	block.set_depth(16);
2017 	if(block.get_depth() != 16)
2018 		return die_("value mismatch, expected 16");
2019 	printf("OK\n");
2020 
2021 	printf("testing Picture::get_colors()... ");
2022 	if(block.get_colors() != 0)
2023 		return die_("value mismatch, expected 0");
2024 	printf("OK\n");
2025 
2026 	printf("testing Picture::set_colors()... +\n");
2027 	printf("        Picture::get_colors()... ");
2028 	block.set_colors(1u>16);
2029 	if(block.get_colors() != (1u>16))
2030 		return die_("value mismatch, expected 2^16");
2031 	printf("OK\n");
2032 
2033 	printf("testing Picture::get_data_length()... ");
2034 	if(block.get_data_length() != 0)
2035 		return die_("value mismatch, expected 0");
2036 	printf("OK\n");
2037 
2038 	printf("testing Picture::set_data()... ");
2039 	if(!block.set_data((const FLAC__byte*)"qOMEJPEGDATA", strlen("qOMEJPEGDATA")))
2040 		return die_("returned false");
2041 	printf("OK\n");
2042 	picture_.data.picture.data[0] = 'q';
2043 
2044 	printf("testing Picture::get_data()... ");
2045 	if(block.get_data_length() != picture_.data.picture.data_length)
2046 		return die_("length mismatch");
2047 	if(0 != memcmp(block.get_data(), picture_.data.picture.data, picture_.data.picture.data_length))
2048 		return die_("value mismatch");
2049 	printf("OK\n");
2050 
2051 	printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
2052 	FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
2053 	if(0 == clone_)
2054 		return die_("returned NULL");
2055 	if(0 == dynamic_cast<FLAC::Metadata::Picture *>(clone_))
2056 		return die_("downcast is NULL");
2057 	if(*dynamic_cast<FLAC::Metadata::Picture *>(clone_) != block)
2058 		return die_("clone is not identical");
2059 	printf("OK\n");
2060 	printf("testing Picture::~Picture()... ");
2061 	delete clone_;
2062 	printf("OK\n");
2063 
2064 
2065 	printf("PASSED\n\n");
2066 	return true;
2067 }
2068 
test_metadata_object()2069 bool test_metadata_object()
2070 {
2071 	printf("\n+++ libFLAC++ unit test: metadata objects\n\n");
2072 
2073 	init_metadata_blocks_();
2074 
2075 	if(!test_metadata_object_streaminfo())
2076 		return false;
2077 
2078 	if(!test_metadata_object_padding())
2079 		return false;
2080 
2081 	if(!test_metadata_object_application())
2082 		return false;
2083 
2084 	if(!test_metadata_object_seektable())
2085 		return false;
2086 
2087 	if(!test_metadata_object_vorbiscomment())
2088 		return false;
2089 
2090 	if(!test_metadata_object_cuesheet())
2091 		return false;
2092 
2093 	if(!test_metadata_object_picture())
2094 		return false;
2095 
2096 	free_metadata_blocks_();
2097 
2098 	return true;
2099 }
2100