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