fix library list
[platform/upstream/flac.git] / src / test_libFLAC++ / metadata_object.cpp
1 /* test_libFLAC++ - Unit tester for libFLAC++
2  * Copyright (C) 2002  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #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_;
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 bool index_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Index &index, const ::FLAC__StreamMetadata_CueSheet_Index &indexcopy)
44 {
45         if(indexcopy.offset != index.offset)
46                 return false;
47         if(indexcopy.number != index.number)
48                 return false;
49         return true;
50 }
51
52 static bool track_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Track *track, const ::FLAC__StreamMetadata_CueSheet_Track *trackcopy)
53 {
54         unsigned i;
55
56         if(trackcopy->offset != track->offset)
57                 return false;
58         if(trackcopy->number != track->number)
59                 return false;
60         if(0 != strcmp(trackcopy->isrc, track->isrc))
61                 return false;
62         if(trackcopy->type != track->type)
63                 return false;
64         if(trackcopy->pre_emphasis != track->pre_emphasis)
65                 return false;
66         if(trackcopy->num_indices != track->num_indices)
67                 return false;
68         if(0 == track->indices || 0 == trackcopy->indices) {
69                 if(track->indices != trackcopy->indices)
70                         return false;
71         }
72         else {
73                 for(i = 0; i < track->num_indices; i++) {
74                         if(!index_is_equal_(trackcopy->indices[i], track->indices[i]))
75                                 return false;
76                 }
77         }
78         return true;
79 }
80
81 static void init_metadata_blocks_()
82 {
83         streaminfo_.is_last = false;
84         streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
85         streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
86         streaminfo_.data.stream_info.min_blocksize = 576;
87         streaminfo_.data.stream_info.max_blocksize = 576;
88         streaminfo_.data.stream_info.min_framesize = 0;
89         streaminfo_.data.stream_info.max_framesize = 0;
90         streaminfo_.data.stream_info.sample_rate = 44100;
91         streaminfo_.data.stream_info.channels = 1;
92         streaminfo_.data.stream_info.bits_per_sample = 8;
93         streaminfo_.data.stream_info.total_samples = 0;
94         memset(streaminfo_.data.stream_info.md5sum, 0, 16);
95
96         padding_.is_last = false;
97         padding_.type = ::FLAC__METADATA_TYPE_PADDING;
98         padding_.length = 1234;
99
100         seektable_.is_last = false;
101         seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
102         seektable_.data.seek_table.num_points = 2;
103         seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
104         seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
105         seektable_.data.seek_table.points[0].sample_number = 0;
106         seektable_.data.seek_table.points[0].stream_offset = 0;
107         seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
108         seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
109         seektable_.data.seek_table.points[1].stream_offset = 1000;
110         seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
111
112         application_.is_last = false;
113         application_.type = ::FLAC__METADATA_TYPE_APPLICATION;
114         application_.length = 8;
115         memcpy(application_.data.application.id, "\xfe\xdc\xba\x98", 4);
116         application_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
117         memcpy(application_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
118
119         vorbiscomment_.is_last = false;
120         vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
121         vorbiscomment_.length = (4 + 5) + 4 + (4 + 12) + (4 + 12);
122         vorbiscomment_.data.vorbis_comment.vendor_string.length = 5;
123         vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5);
124         memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5);
125         vorbiscomment_.data.vorbis_comment.num_comments = 2;
126         vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
127         vorbiscomment_.data.vorbis_comment.comments[0].length = 12;
128         vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12);
129         memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12);
130         vorbiscomment_.data.vorbis_comment.comments[1].length = 12;
131         vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12);
132         memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12);
133
134         cuesheet_.is_last = true;
135         cuesheet_.type = ::FLAC__METADATA_TYPE_CUESHEET;
136         cuesheet_.length =
137                 /* cuesheet guts */
138                 (
139                         FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
140                         FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
141                         FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
142                         FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
143                 ) / 8 +
144                 /* 2 tracks */
145                 2 * (
146                         FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
147                         FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
148                         FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
149                         FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
150                         FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
151                         FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
152                         FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
153                 ) / 8 +
154                 /* 3 index points */
155                 3 * (
156                         FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
157                         FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
158                         FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
159                 ) / 8
160         ;
161         memset(cuesheet_.data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet_.data.cue_sheet.media_catalog_number));
162         cuesheet_.data.cue_sheet.media_catalog_number[0] = 'j';
163         cuesheet_.data.cue_sheet.media_catalog_number[1] = 'C';
164         cuesheet_.data.cue_sheet.lead_in = 159;
165         cuesheet_.data.cue_sheet.num_tracks = 2;
166         cuesheet_.data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
167         cuesheet_.data.cue_sheet.tracks[0].offset = 1;
168         cuesheet_.data.cue_sheet.tracks[0].number = 1;
169         memcpy(cuesheet_.data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet_.data.cue_sheet.tracks[0].isrc));
170         cuesheet_.data.cue_sheet.tracks[0].type = 0;
171         cuesheet_.data.cue_sheet.tracks[0].pre_emphasis = 1;
172         cuesheet_.data.cue_sheet.tracks[0].num_indices = 2;
173         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));
174         cuesheet_.data.cue_sheet.tracks[0].indices[0].offset = 0;
175         cuesheet_.data.cue_sheet.tracks[0].indices[0].number = 0;
176         cuesheet_.data.cue_sheet.tracks[0].indices[1].offset = 1234567890;
177         cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
178         cuesheet_.data.cue_sheet.tracks[1].offset = 12345678901;
179         cuesheet_.data.cue_sheet.tracks[1].number = 2;
180         memcpy(cuesheet_.data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet_.data.cue_sheet.tracks[1].isrc));
181         cuesheet_.data.cue_sheet.tracks[1].type = 1;
182         cuesheet_.data.cue_sheet.tracks[1].pre_emphasis = 0;
183         cuesheet_.data.cue_sheet.tracks[1].num_indices = 1;
184         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));
185         cuesheet_.data.cue_sheet.tracks[1].indices[0].offset = 0;
186         cuesheet_.data.cue_sheet.tracks[1].indices[0].number = 1;
187 }
188
189 static void free_metadata_blocks_()
190 {
191         free(seektable_.data.seek_table.points);
192         free(application_.data.application.data);
193         free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
194         free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
195         free(vorbiscomment_.data.vorbis_comment.comments);
196         free(cuesheet_.data.cue_sheet.tracks[0].indices);
197         free(cuesheet_.data.cue_sheet.tracks[1].indices);
198         free(cuesheet_.data.cue_sheet.tracks);
199 }
200
201 bool test_metadata_object_streaminfo()
202 {
203         unsigned expected_length;
204
205         printf("testing class FLAC::Metadata::StreamInfo\n");
206
207         printf("testing StreamInfo::StreamInfo()... ");
208         FLAC::Metadata::StreamInfo block;
209         if(!block.is_valid())
210                 return die_("!block.is_valid()");
211         expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
212         if(block.get_length() != expected_length) {
213                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
214                 return false;
215         }
216         printf("OK\n");
217
218         printf("testing StreamInfo::StreamInfo(const StreamInfo &)... +\n");
219         printf("        StreamInfo::operator!=(const StreamInfo &)... ");
220         {
221                 FLAC::Metadata::StreamInfo blockcopy(block);
222                 if(!blockcopy.is_valid())
223                         return die_("!block.is_valid()");
224                 if(blockcopy != block)
225                         return die_("copy is not identical to original");
226                 printf("OK\n");
227
228                 printf("testing StreamInfo::~StreamInfo()... ");
229         }
230         printf("OK\n");
231
232         printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata &)... +\n");
233         printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata &)... ");
234         {
235                 FLAC::Metadata::StreamInfo blockcopy(streaminfo_);
236                 if(!blockcopy.is_valid())
237                         return die_("!block.is_valid()");
238                 if(blockcopy != streaminfo_)
239                         return die_("copy is not identical to original");
240                 printf("OK\n");
241         }
242
243         printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *)... +\n");
244         printf("        StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
245         {
246                 FLAC::Metadata::StreamInfo blockcopy(&streaminfo_);
247                 if(!blockcopy.is_valid())
248                         return die_("!block.is_valid()");
249                 if(blockcopy != streaminfo_)
250                         return die_("copy is not identical to original");
251                 printf("OK\n");
252         }
253
254         printf("testing StreamInfo::operator=(const StreamInfo &)... +\n");
255         printf("        StreamInfo::operator==(const StreamInfo &)... ");
256         {
257                 FLAC::Metadata::StreamInfo blockcopy = block;
258                 if(!blockcopy.is_valid())
259                         return die_("!block.is_valid()");
260                 if(!(blockcopy == block))
261                         return die_("copy is not identical to original");
262                 printf("OK\n");
263         }
264
265         printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata &)... +\n");
266         printf("        StreamInfo::operator==(const ::FLAC__StreamMetadata &)... ");
267         {
268                 FLAC::Metadata::StreamInfo blockcopy = streaminfo_;
269                 if(!blockcopy.is_valid())
270                         return die_("!block.is_valid()");
271                 if(!(blockcopy == streaminfo_))
272                         return die_("copy is not identical to original");
273                 printf("OK\n");
274         }
275
276         printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata *)... +\n");
277         printf("        StreamInfo::operator==(const ::FLAC__StreamMetadata *)... ");
278         {
279                 FLAC::Metadata::StreamInfo blockcopy = &streaminfo_;
280                 if(!blockcopy.is_valid())
281                         return die_("!block.is_valid()");
282                 if(!(blockcopy == streaminfo_))
283                         return die_("copy is not identical to original");
284                 printf("OK\n");
285         }
286
287         printf("testing StreamInfo::set_min_blocksize()... ");
288         block.set_min_blocksize(streaminfo_.data.stream_info.min_blocksize);
289         printf("OK\n");
290
291         printf("testing StreamInfo::set_max_blocksize()... ");
292         block.set_max_blocksize(streaminfo_.data.stream_info.max_blocksize);
293         printf("OK\n");
294
295         printf("testing StreamInfo::set_min_framesize()... ");
296         block.set_min_framesize(streaminfo_.data.stream_info.min_framesize);
297         printf("OK\n");
298
299         printf("testing StreamInfo::set_max_framesize()... ");
300         block.set_max_framesize(streaminfo_.data.stream_info.max_framesize);
301         printf("OK\n");
302
303         printf("testing StreamInfo::set_sample_rate()... ");
304         block.set_sample_rate(streaminfo_.data.stream_info.sample_rate);
305         printf("OK\n");
306
307         printf("testing StreamInfo::set_channels()... ");
308         block.set_channels(streaminfo_.data.stream_info.channels);
309         printf("OK\n");
310
311         printf("testing StreamInfo::set_bits_per_sample()... ");
312         block.set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample);
313         printf("OK\n");
314
315         printf("testing StreamInfo::set_total_samples()... ");
316         block.set_total_samples(streaminfo_.data.stream_info.total_samples);
317         printf("OK\n");
318
319         printf("testing StreamInfo::set_md5sum()... ");
320         block.set_md5sum(streaminfo_.data.stream_info.md5sum);
321         printf("OK\n");
322
323         printf("testing StreamInfo::get_min_blocksize()... ");
324         if(block.get_min_blocksize() != streaminfo_.data.stream_info.min_blocksize)
325                 return die_("value mismatch, doesn't match previously set value");
326         printf("OK\n");
327
328         printf("testing StreamInfo::get_max_blocksize()... ");
329         if(block.get_max_blocksize() != streaminfo_.data.stream_info.max_blocksize)
330                 return die_("value mismatch, doesn't match previously set value");
331         printf("OK\n");
332
333         printf("testing StreamInfo::get_min_framesize()... ");
334         if(block.get_min_framesize() != streaminfo_.data.stream_info.min_framesize)
335                 return die_("value mismatch, doesn't match previously set value");
336         printf("OK\n");
337
338         printf("testing StreamInfo::get_max_framesize()... ");
339         if(block.get_max_framesize() != streaminfo_.data.stream_info.max_framesize)
340                 return die_("value mismatch, doesn't match previously set value");
341         printf("OK\n");
342
343         printf("testing StreamInfo::get_sample_rate()... ");
344         if(block.get_sample_rate() != streaminfo_.data.stream_info.sample_rate)
345                 return die_("value mismatch, doesn't match previously set value");
346         printf("OK\n");
347
348         printf("testing StreamInfo::get_channels()... ");
349         if(block.get_channels() != streaminfo_.data.stream_info.channels)
350                 return die_("value mismatch, doesn't match previously set value");
351         printf("OK\n");
352
353         printf("testing StreamInfo::get_bits_per_sample()... ");
354         if(block.get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample)
355                 return die_("value mismatch, doesn't match previously set value");
356         printf("OK\n");
357
358         printf("testing StreamInfo::get_total_samples()... ");
359         if(block.get_total_samples() != streaminfo_.data.stream_info.total_samples)
360                 return die_("value mismatch, doesn't match previously set value");
361         printf("OK\n");
362
363         printf("testing StreamInfo::get_md5sum()... ");
364         if(0 != memcmp(block.get_md5sum(), streaminfo_.data.stream_info.md5sum, 16))
365                 return die_("value mismatch, doesn't match previously set value");
366         printf("OK\n");
367
368         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
369         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
370         if(0 == clone_)
371                 return die_("returned NULL");
372         if(0 == dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_))
373                 return die_("downcast is NULL");
374         if(*dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_) != block)
375                 return die_("clone is not identical");
376         printf("OK\n");
377
378
379         printf("PASSED\n\n");
380         return true;
381 }
382
383 bool test_metadata_object_padding()
384 {
385         unsigned expected_length;
386
387         printf("testing class FLAC::Metadata::Padding\n");
388
389         printf("testing Padding::Padding()... ");
390         FLAC::Metadata::Padding block;
391         if(!block.is_valid())
392                 return die_("!block.is_valid()");
393         expected_length = 0;
394         if(block.get_length() != expected_length) {
395                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
396                 return false;
397         }
398         printf("OK\n");
399
400         printf("testing Padding::Padding(const Padding &)... +\n");
401         printf("        Padding::operator!=(const Padding &)... ");
402         {
403                 FLAC::Metadata::Padding blockcopy(block);
404                 if(!blockcopy.is_valid())
405                         return die_("!block.is_valid()");
406                 if(blockcopy != block)
407                         return die_("copy is not identical to original");
408                 printf("OK\n");
409
410                 printf("testing Padding::~Padding()... ");
411         }
412         printf("OK\n");
413
414         printf("testing Padding::Padding(const ::FLAC__StreamMetadata &)... +\n");
415         printf("        Padding::operator!=(const ::FLAC__StreamMetadata &)... ");
416         {
417                 FLAC::Metadata::Padding blockcopy(padding_);
418                 if(!blockcopy.is_valid())
419                         return die_("!block.is_valid()");
420                 if(blockcopy != padding_)
421                         return die_("copy is not identical to original");
422                 printf("OK\n");
423         }
424
425         printf("testing Padding::Padding(const ::FLAC__StreamMetadata *)... +\n");
426         printf("        Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
427         {
428                 FLAC::Metadata::Padding blockcopy(&padding_);
429                 if(!blockcopy.is_valid())
430                         return die_("!block.is_valid()");
431                 if(blockcopy != padding_)
432                         return die_("copy is not identical to original");
433                 printf("OK\n");
434         }
435
436         printf("testing Padding::operator=(const Padding &)... +\n");
437         printf("        Padding::operator==(const Padding &)... ");
438         {
439                 FLAC::Metadata::Padding blockcopy = block;
440                 if(!blockcopy.is_valid())
441                         return die_("!block.is_valid()");
442                 if(!(blockcopy == block))
443                         return die_("copy is not identical to original");
444                 printf("OK\n");
445         }
446
447         printf("testing Padding::operator=(const ::FLAC__StreamMetadata &)... +\n");
448         printf("        Padding::operator==(const ::FLAC__StreamMetadata &)... ");
449         {
450                 FLAC::Metadata::Padding blockcopy = padding_;
451                 if(!blockcopy.is_valid())
452                         return die_("!block.is_valid()");
453                 if(!(blockcopy == padding_))
454                         return die_("copy is not identical to original");
455                 printf("OK\n");
456         }
457
458         printf("testing Padding::operator=(const ::FLAC__StreamMetadata *)... +\n");
459         printf("        Padding::operator==(const ::FLAC__StreamMetadata *)... ");
460         {
461                 FLAC::Metadata::Padding blockcopy = &padding_;
462                 if(!blockcopy.is_valid())
463                         return die_("!block.is_valid()");
464                 if(!(blockcopy == padding_))
465                         return die_("copy is not identical to original");
466                 printf("OK\n");
467         }
468
469         printf("testing Padding::set_length()... ");
470         block.set_length(padding_.length);
471         printf("OK\n");
472
473         printf("testing Prototype::get_length()... ");
474         if(block.get_length() != padding_.length)
475                 return die_("value mismatch, doesn't match previously set value");
476         printf("OK\n");
477
478         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
479         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
480         if(0 == clone_)
481                 return die_("returned NULL");
482         if(0 == dynamic_cast<FLAC::Metadata::Padding *>(clone_))
483                 return die_("downcast is NULL");
484         if(*dynamic_cast<FLAC::Metadata::Padding *>(clone_) != block)
485                 return die_("clone is not identical");
486         printf("OK\n");
487
488
489         printf("PASSED\n\n");
490         return true;
491 }
492
493 bool test_metadata_object_application()
494 {
495         unsigned expected_length;
496
497         printf("testing class FLAC::Metadata::Application\n");
498
499         printf("testing Application::Application()... ");
500         FLAC::Metadata::Application block;
501         if(!block.is_valid())
502                 return die_("!block.is_valid()");
503         expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
504         if(block.get_length() != expected_length) {
505                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
506                 return false;
507         }
508         printf("OK\n");
509
510         printf("testing Application::Application(const Application &)... +\n");
511         printf("        Application::operator!=(const Application &)... ");
512         {
513                 FLAC::Metadata::Application blockcopy(block);
514                 if(!blockcopy.is_valid())
515                         return die_("!block.is_valid()");
516                 if(blockcopy != block)
517                         return die_("copy is not identical to original");
518                 printf("OK\n");
519
520                 printf("testing Application::~Application()... ");
521         }
522         printf("OK\n");
523
524         printf("testing Application::Application(const ::FLAC__StreamMetadata &)... +\n");
525         printf("        Application::operator!=(const ::FLAC__StreamMetadata &)... ");
526         {
527                 FLAC::Metadata::Application blockcopy(application_);
528                 if(!blockcopy.is_valid())
529                         return die_("!block.is_valid()");
530                 if(blockcopy != application_)
531                         return die_("copy is not identical to original");
532                 printf("OK\n");
533         }
534
535         printf("testing Application::Application(const ::FLAC__StreamMetadata *)... +\n");
536         printf("        Application::operator!=(const ::FLAC__StreamMetadata *)... ");
537         {
538                 FLAC::Metadata::Application blockcopy(&application_);
539                 if(!blockcopy.is_valid())
540                         return die_("!block.is_valid()");
541                 if(blockcopy != application_)
542                         return die_("copy is not identical to original");
543                 printf("OK\n");
544         }
545
546         printf("testing Application::operator=(const Application &)... +\n");
547         printf("        Application::operator==(const Application &)... ");
548         {
549                 FLAC::Metadata::Application blockcopy = block;
550                 if(!blockcopy.is_valid())
551                         return die_("!block.is_valid()");
552                 if(!(blockcopy == block))
553                         return die_("copy is not identical to original");
554                 printf("OK\n");
555         }
556
557         printf("testing Application::operator=(const ::FLAC__StreamMetadata &)... +\n");
558         printf("        Application::operator==(const ::FLAC__StreamMetadata &)... ");
559         {
560                 FLAC::Metadata::Application blockcopy = application_;
561                 if(!blockcopy.is_valid())
562                         return die_("!block.is_valid()");
563                 if(!(blockcopy == application_))
564                         return die_("copy is not identical to original");
565                 printf("OK\n");
566         }
567
568         printf("testing Application::operator=(const ::FLAC__StreamMetadata *)... +\n");
569         printf("        Application::operator==(const ::FLAC__StreamMetadata *)... ");
570         {
571                 FLAC::Metadata::Application blockcopy = &application_;
572                 if(!blockcopy.is_valid())
573                         return die_("!block.is_valid()");
574                 if(!(blockcopy == application_))
575                         return die_("copy is not identical to original");
576                 printf("OK\n");
577         }
578
579         printf("testing Application::set_id()... ");
580         block.set_id(application_.data.application.id);
581         printf("OK\n");
582
583         printf("testing Application::set_data()... ");
584         block.set_data(application_.data.application.data, application_.length - sizeof(application_.data.application.id), /*copy=*/true);
585         printf("OK\n");
586
587         printf("testing Application::get_id()... ");
588         if(0 != memcmp(block.get_id(), application_.data.application.id, sizeof(application_.data.application.id)))
589                 return die_("value mismatch, doesn't match previously set value");
590         printf("OK\n");
591
592         printf("testing Application::get_data()... ");
593         if(0 != memcmp(block.get_data(), application_.data.application.data, application_.length - sizeof(application_.data.application.id)))
594                 return die_("value mismatch, doesn't match previously set value");
595         printf("OK\n");
596
597         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
598         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
599         if(0 == clone_)
600                 return die_("returned NULL");
601         if(0 == dynamic_cast<FLAC::Metadata::Application *>(clone_))
602                 return die_("downcast is NULL");
603         if(*dynamic_cast<FLAC::Metadata::Application *>(clone_) != block)
604                 return die_("clone is not identical");
605         printf("OK\n");
606
607
608         printf("PASSED\n\n");
609         return true;
610 }
611
612 bool test_metadata_object_seektable()
613 {
614         unsigned expected_length;
615
616         printf("testing class FLAC::Metadata::SeekTable\n");
617
618         printf("testing SeekTable::SeekTable()... ");
619         FLAC::Metadata::SeekTable block;
620         if(!block.is_valid())
621                 return die_("!block.is_valid()");
622         expected_length = 0;
623         if(block.get_length() != expected_length) {
624                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
625                 return false;
626         }
627         printf("OK\n");
628
629         printf("testing SeekTable::SeekTable(const SeekTable &)... +\n");
630         printf("        SeekTable::operator!=(const SeekTable &)... ");
631         {
632                 FLAC::Metadata::SeekTable blockcopy(block);
633                 if(!blockcopy.is_valid())
634                         return die_("!block.is_valid()");
635                 if(blockcopy != block)
636                         return die_("copy is not identical to original");
637                 printf("OK\n");
638
639                 printf("testing SeekTable::~SeekTable()... ");
640         }
641         printf("OK\n");
642
643         printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata &)... +\n");
644         printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
645         {
646                 FLAC::Metadata::SeekTable blockcopy(seektable_);
647                 if(!blockcopy.is_valid())
648                         return die_("!block.is_valid()");
649                 if(blockcopy != seektable_)
650                         return die_("copy is not identical to original");
651                 printf("OK\n");
652         }
653
654         printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *)... +\n");
655         printf("        SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
656         {
657                 FLAC::Metadata::SeekTable blockcopy(&seektable_);
658                 if(!blockcopy.is_valid())
659                         return die_("!block.is_valid()");
660                 if(blockcopy != seektable_)
661                         return die_("copy is not identical to original");
662                 printf("OK\n");
663         }
664
665         printf("testing SeekTable::operator=(const SeekTable &)... +\n");
666         printf("        SeekTable::operator==(const SeekTable &)... ");
667         {
668                 FLAC::Metadata::SeekTable blockcopy = block;
669                 if(!blockcopy.is_valid())
670                         return die_("!block.is_valid()");
671                 if(!(blockcopy == block))
672                         return die_("copy is not identical to original");
673                 printf("OK\n");
674         }
675
676         printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata &)... +\n");
677         printf("        SeekTable::operator==(const ::FLAC__StreamMetadata &)... ");
678         {
679                 FLAC::Metadata::SeekTable blockcopy = seektable_;
680                 if(!blockcopy.is_valid())
681                         return die_("!block.is_valid()");
682                 if(!(blockcopy == seektable_))
683                         return die_("copy is not identical to original");
684                 printf("OK\n");
685         }
686
687         printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata *)... +\n");
688         printf("        SeekTable::operator==(const ::FLAC__StreamMetadata *)... ");
689         {
690                 FLAC::Metadata::SeekTable blockcopy = &seektable_;
691                 if(!blockcopy.is_valid())
692                         return die_("!block.is_valid()");
693                 if(!(blockcopy == seektable_))
694                         return die_("copy is not identical to original");
695                 printf("OK\n");
696         }
697
698         printf("testing SeekTable::insert_point() x 3... ");
699         if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
700                 return die_("returned false");
701         if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
702                 return die_("returned false");
703         if(!block.insert_point(1, seektable_.data.seek_table.points[0]))
704                 return die_("returned false");
705         printf("OK\n");
706
707         printf("testing SeekTable::is_legal()... ");
708         if(block.is_legal())
709                 return die_("returned true");
710         printf("OK\n");
711
712         printf("testing SeekTable::set_point()... ");
713         block.set_point(0, seektable_.data.seek_table.points[0]);
714         printf("OK\n");
715
716         printf("testing SeekTable::delete_point()... ");
717         if(!block.delete_point(0))
718                 return die_("returned false");
719         printf("OK\n");
720
721         printf("testing SeekTable::is_legal()... ");
722         if(!block.is_legal())
723                 return die_("returned false");
724         printf("OK\n");
725
726         printf("testing SeekTable::get_num_points()... ");
727         if(block.get_num_points() != seektable_.data.seek_table.num_points)
728                 return die_("number mismatch");
729         printf("OK\n");
730
731         printf("testing SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
732         if(block != seektable_)
733                 return die_("data mismatch");
734         printf("OK\n");
735
736         printf("testing SeekTable::get_point()... ");
737         if(
738                 block.get_point(1).sample_number != seektable_.data.seek_table.points[1].sample_number ||
739                 block.get_point(1).stream_offset != seektable_.data.seek_table.points[1].stream_offset ||
740                 block.get_point(1).frame_samples != seektable_.data.seek_table.points[1].frame_samples
741         )
742                 return die_("point mismatch");
743         printf("OK\n");
744
745         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
746         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
747         if(0 == clone_)
748                 return die_("returned NULL");
749         if(0 == dynamic_cast<FLAC::Metadata::SeekTable *>(clone_))
750                 return die_("downcast is NULL");
751         if(*dynamic_cast<FLAC::Metadata::SeekTable *>(clone_) != block)
752                 return die_("clone is not identical");
753         printf("OK\n");
754
755
756         printf("PASSED\n\n");
757         return true;
758 }
759
760 bool test_metadata_object_vorbiscomment()
761 {
762         unsigned expected_length;
763
764         printf("testing class FLAC::Metadata::VorbisComment::Entry\n");
765
766         printf("testing Entry::Entry()... ");
767         {
768                 FLAC::Metadata::VorbisComment::Entry entry1;
769                 if(!entry1.is_valid())
770                         return die_("!is_valid()");
771                 printf("OK\n");
772
773                 printf("testing Entry::~Entry()... ");
774         }
775         printf("OK\n");
776
777         printf("testing Entry::Entry(const char *field, unsigned field_length)... ");
778         FLAC::Metadata::VorbisComment::Entry entry2("name2=value2", strlen("name2=value2"));
779         if(!entry2.is_valid())
780                 return die_("!is_valid()");
781         printf("OK\n");
782
783         printf("testing Entry::Entry(const char *field_name, const char *field_value, unsigned field_value_length)... ");
784         FLAC::Metadata::VorbisComment::Entry entry3("name3", "value3", strlen("value3"));
785         if(!entry3.is_valid())
786                 return die_("!is_valid()");
787         printf("OK\n");
788
789         printf("testing Entry::Entry(const Entry &entry)... ");
790         {
791                 FLAC::Metadata::VorbisComment::Entry entry2copy(entry2);
792                 if(!entry2copy.is_valid())
793                         return die_("!is_valid()");
794                 printf("OK\n");
795
796                 printf("testing Entry::~Entry()... ");
797         }
798         printf("OK\n");
799
800         printf("testing Entry::operator=(const Entry &entry)... ");
801         FLAC::Metadata::VorbisComment::Entry entry1 = entry2;
802         if(!entry2.is_valid())
803                 return die_("!is_valid()");
804         printf("OK\n");
805
806         printf("testing Entry::get_field_length()... ");
807         if(entry1.get_field_length() != strlen("name2=value2"))
808                 return die_("value mismatch");
809         printf("OK\n");
810
811         printf("testing Entry::get_field_name_length()... ");
812         if(entry1.get_field_name_length() != strlen("name2"))
813                 return die_("value mismatch");
814         printf("OK\n");
815
816         printf("testing Entry::get_field_value_length()... ");
817         if(entry1.get_field_value_length() != strlen("value2"))
818                 return die_("value mismatch");
819         printf("OK\n");
820
821         printf("testing Entry::get_entry()... ");
822         {
823                 ::FLAC__StreamMetadata_VorbisComment_Entry entry = entry1.get_entry();
824                 if(entry.length != strlen("name2=value2"))
825                         return die_("entry length mismatch");
826                 if(0 != memcmp(entry.entry, "name2=value2", entry.length))
827                         return die_("entry value mismatch");
828         }
829         printf("OK\n");
830
831         printf("testing Entry::get_field()... ");
832         if(0 != memcmp(entry1.get_field(), "name2=value2", strlen("name2=value2")))
833                 return die_("value mismatch");
834         printf("OK\n");
835
836         printf("testing Entry::get_field_name()... ");
837         if(0 != memcmp(entry1.get_field_name(), "name2", strlen("name2")))
838                 return die_("value mismatch");
839         printf("OK\n");
840
841         printf("testing Entry::get_field_value()... ");
842         if(0 != memcmp(entry1.get_field_value(), "value2", strlen("value2")))
843                 return die_("value mismatch");
844         printf("OK\n");
845
846         printf("testing Entry::set_field_name()... ");
847         if(!entry1.set_field_name("name1"))
848                 return die_("returned false");
849         if(0 != memcmp(entry1.get_field_name(), "name1", strlen("name1")))
850                 return die_("value mismatch");
851         if(0 != memcmp(entry1.get_field(), "name1=value2", strlen("name1=value2")))
852                 return die_("entry mismatch");
853         printf("OK\n");
854
855         printf("testing Entry::set_field_value()... ");
856         if(!entry1.set_field_value("value1", strlen("value1")))
857                 return die_("returned false");
858         if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
859                 return die_("value mismatch");
860         if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
861                 return die_("entry mismatch");
862         printf("OK\n");
863
864         printf("testing Entry::set_field()... ");
865         if(!entry1.set_field("name0=value0", strlen("name0=value0")))
866                 return die_("returned false");
867         if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
868                 return die_("value mismatch");
869         if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
870                 return die_("value mismatch");
871         if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
872                 return die_("entry mismatch");
873         printf("OK\n");
874
875         printf("PASSED\n\n");
876
877
878         printf("testing class FLAC::Metadata::VorbisComment\n");
879
880         printf("testing VorbisComment::VorbisComment()... ");
881         FLAC::Metadata::VorbisComment block;
882         if(!block.is_valid())
883                 return die_("!block.is_valid()");
884         expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(::FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
885         if(block.get_length() != expected_length) {
886                 printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
887                 return false;
888         }
889         printf("OK\n");
890
891         printf("testing VorbisComment::VorbisComment(const VorbisComment &)... +\n");
892         printf("        VorbisComment::operator!=(const VorbisComment &)... ");
893         {
894                 FLAC::Metadata::VorbisComment blockcopy(block);
895                 if(!blockcopy.is_valid())
896                         return die_("!block.is_valid()");
897                 if(blockcopy != block)
898                         return die_("copy is not identical to original");
899                 printf("OK\n");
900
901                 printf("testing VorbisComment::~VorbisComment()... ");
902         }
903         printf("OK\n");
904
905         printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata &)... +\n");
906         printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata &)... ");
907         {
908                 FLAC::Metadata::VorbisComment blockcopy(vorbiscomment_);
909                 if(!blockcopy.is_valid())
910                         return die_("!block.is_valid()");
911                 if(blockcopy != vorbiscomment_)
912                         return die_("copy is not identical to original");
913                 printf("OK\n");
914         }
915
916         printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *)... +\n");
917         printf("        VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
918         {
919                 FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_);
920                 if(!blockcopy.is_valid())
921                         return die_("!block.is_valid()");
922                 if(blockcopy != vorbiscomment_)
923                         return die_("copy is not identical to original");
924                 printf("OK\n");
925         }
926
927         printf("testing VorbisComment::operator=(const VorbisComment &)... +\n");
928         printf("        VorbisComment::operator==(const VorbisComment &)... ");
929         {
930                 FLAC::Metadata::VorbisComment blockcopy = block;
931                 if(!blockcopy.is_valid())
932                         return die_("!block.is_valid()");
933                 if(!(blockcopy == block))
934                         return die_("copy is not identical to original");
935                 printf("OK\n");
936         }
937
938         printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata &)... +\n");
939         printf("        VorbisComment::operator==(const ::FLAC__StreamMetadata &)... ");
940         {
941                 FLAC::Metadata::VorbisComment blockcopy = vorbiscomment_;
942                 if(!blockcopy.is_valid())
943                         return die_("!block.is_valid()");
944                 if(!(blockcopy == vorbiscomment_))
945                         return die_("copy is not identical to original");
946                 printf("OK\n");
947         }
948
949         printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata *)... +\n");
950         printf("        VorbisComment::operator==(const ::FLAC__StreamMetadata *)... ");
951         {
952                 FLAC::Metadata::VorbisComment blockcopy = &vorbiscomment_;
953                 if(!blockcopy.is_valid())
954                         return die_("!block.is_valid()");
955                 if(!(blockcopy == vorbiscomment_))
956                         return die_("copy is not identical to original");
957                 printf("OK\n");
958         }
959
960         printf("testing VorbisComment::get_num_comments()... ");
961         if(block.get_num_comments() != 0)
962                 return die_("value mismatch, expected 0");
963         printf("OK\n");
964
965         printf("testing VorbisComment::set_vendor_string()... ");
966         if(!block.set_vendor_string(entry1))
967                 return die_("returned false");
968         printf("OK\n");
969
970         printf("testing VorbisComment::get_vendor_string()... ");
971         if(block.get_vendor_string().get_field_name_length() != vorbiscomment_.data.vorbis_comment.vendor_string.length)
972                 return die_("length mismatch");
973         if(0 != memcmp(block.get_vendor_string().get_field_name(), vorbiscomment_.data.vorbis_comment.vendor_string.entry, vorbiscomment_.data.vorbis_comment.vendor_string.length))
974                 return die_("value mismatch");
975         printf("OK\n");
976
977         printf("testing VorbisComment::insert_comment()... +\n");
978         printf("        VorbisComment::get_comment()... ");
979         if(!block.insert_comment(0, entry3))
980                 return die_("returned false");
981         if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
982                 return die_("length mismatch");
983         if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
984                 return die_("value mismatch");
985         printf("OK\n");
986
987         printf("testing VorbisComment::insert_comment()... +\n");
988         printf("        VorbisComment::get_comment()... ");
989         if(!block.insert_comment(0, entry3))
990                 return die_("returned false");
991         if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
992                 return die_("length mismatch");
993         if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
994                 return die_("value mismatch");
995         printf("OK\n");
996
997         printf("testing VorbisComment::insert_comment()... +\n");
998         printf("        VorbisComment::get_comment()... ");
999         if(!block.insert_comment(1, entry2))
1000                 return die_("returned false");
1001         if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1002                 return die_("length mismatch");
1003         if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1004                 return die_("value mismatch");
1005         printf("OK\n");
1006
1007         printf("testing VorbisComment::set_comment()... +\n");
1008         printf("        VorbisComment::get_comment()... ");
1009         if(!block.set_comment(0, entry2))
1010                 return die_("returned false");
1011         if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1012                 return die_("length mismatch");
1013         if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1014                 return die_("value mismatch");
1015         printf("OK\n");
1016
1017         printf("testing VorbisComment::delete_comment()... +\n");
1018         printf("        VorbisComment::get_comment()... ");
1019         if(!block.delete_comment(0))
1020                 return die_("returned false");
1021         if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
1022                 return die_("length[0] mismatch");
1023         if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
1024                 return die_("value[0] mismatch");
1025         if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
1026                 return die_("length[1] mismatch");
1027         if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
1028                 return die_("value[0] mismatch");
1029         printf("OK\n");
1030
1031         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
1032         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
1033         if(0 == clone_)
1034                 return die_("returned NULL");
1035         if(0 == dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_))
1036                 return die_("downcast is NULL");
1037         if(*dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_) != block)
1038                 return die_("clone is not identical");
1039         printf("OK\n");
1040
1041
1042         printf("PASSED\n\n");
1043         return true;
1044 }
1045
1046 bool test_metadata_object_cuesheet()
1047 {
1048         unsigned expected_length;
1049
1050         printf("testing class FLAC::Metadata::CueSheet::Track\n");
1051
1052         printf("testing Track::Track()... ");
1053         FLAC::Metadata::CueSheet::Track track0;
1054         if(!track0.is_valid())
1055                 return die_("!is_valid()");
1056         printf("OK\n");
1057
1058         {
1059                 printf("testing Track::get_track()... ");
1060                 const ::FLAC__StreamMetadata_CueSheet_Track *trackp = track0.get_track();
1061                 if(0 == trackp)
1062                         return die_("returned pointer is NULL");
1063                 printf("OK\n");
1064
1065                 printf("testing Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track*)... ");
1066                 FLAC::Metadata::CueSheet::Track track2(trackp);
1067                 if(!track2.is_valid())
1068                         return die_("!is_valid()");
1069                 if(!track_is_equal_(track2.get_track(), trackp))
1070                         return die_("copy is not equal");
1071                 printf("OK\n");
1072
1073                 printf("testing Track::~Track()... ");
1074         }
1075         printf("OK\n");
1076
1077         printf("testing Track::Track(const Track &track)... ");
1078         {
1079                 FLAC::Metadata::CueSheet::Track track0copy(track0);
1080                 if(!track0copy.is_valid())
1081                         return die_("!is_valid()");
1082                 if(!track_is_equal_(track0copy.get_track(), track0.get_track()))
1083                         return die_("copy is not equal");
1084                 printf("OK\n");
1085
1086                 printf("testing Track::~Track()... ");
1087         }
1088         printf("OK\n");
1089
1090         printf("testing Track::operator=(const Track &track)... ");
1091         FLAC::Metadata::CueSheet::Track track1 = track0;
1092         if(!track0.is_valid())
1093                 return die_("!is_valid()");
1094         if(!track_is_equal_(track1.get_track(), track0.get_track()))
1095                 return die_("copy is not equal");
1096         printf("OK\n");
1097
1098         printf("testing Track::get_offset()... ");
1099         if(track1.get_offset() != 0)
1100                 return die_("value mismatch");
1101         printf("OK\n");
1102
1103         printf("testing Track::get_number()... ");
1104         if(track1.get_number() != 0)
1105                 return die_("value mismatch");
1106         printf("OK\n");
1107
1108         printf("testing Track::get_isrc()... ");
1109         if(0 != memcmp(track1.get_isrc(), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 13))
1110                 return die_("value mismatch");
1111         printf("OK\n");
1112
1113         printf("testing Track::get_type()... ");
1114         if(track1.get_type() != 0)
1115                 return die_("value mismatch");
1116         printf("OK\n");
1117
1118         printf("testing Track::get_pre_emphasis()... ");
1119         if(track1.get_pre_emphasis() != 0)
1120                 return die_("value mismatch");
1121         printf("OK\n");
1122
1123         printf("testing Track::get_num_indices()... ");
1124         if(track1.get_num_indices() != 0)
1125                 return die_("value mismatch");
1126         printf("OK\n");
1127
1128         printf("testing Track::set_offset()... ");
1129         track1.set_offset(588);
1130         if(track1.get_offset() != 588)
1131                 return die_("value mismatch");
1132         printf("OK\n");
1133
1134         printf("testing Track::set_number()... ");
1135         track1.set_number(1);
1136         if(track1.get_number() != 1)
1137                 return die_("value mismatch");
1138         printf("OK\n");
1139
1140         printf("testing Track::set_isrc()... ");
1141         track1.set_isrc("ABCDE1234567");
1142         if(0 != memcmp(track1.get_isrc(), "ABCDE1234567", 13))
1143                 return die_("value mismatch");
1144         printf("OK\n");
1145
1146         printf("testing Track::set_type()... ");
1147         track1.set_type(1);
1148         if(track1.get_type() != 1)
1149                 return die_("value mismatch");
1150         printf("OK\n");
1151
1152         printf("testing Track::set_pre_emphasis()... ");
1153         track1.set_pre_emphasis(1);
1154         if(track1.get_pre_emphasis() != 1)
1155                 return die_("value mismatch");
1156         printf("OK\n");
1157
1158         printf("PASSED\n\n");
1159
1160         printf("testing class FLAC::Metadata::CueSheet\n");
1161
1162         printf("testing CueSheet::CueSheet()... ");
1163         FLAC::Metadata::CueSheet block;
1164         if(!block.is_valid())
1165                 return die_("!block.is_valid()");
1166         expected_length = (
1167                 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
1168                 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
1169                 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
1170                 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
1171         ) / 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 CueSheet::CueSheet(const CueSheet &)... +\n");
1179         printf("        CueSheet::operator!=(const CueSheet &)... ");
1180         {
1181                 FLAC::Metadata::CueSheet blockcopy(block);
1182                 if(!blockcopy.is_valid())
1183                         return die_("!block.is_valid()");
1184                 if(blockcopy != block)
1185                         return die_("copy is not identical to original");
1186                 printf("OK\n");
1187
1188                 printf("testing CueSheet::~CueSheet()... ");
1189         }
1190         printf("OK\n");
1191
1192         printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata &)... +\n");
1193         printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata &)... ");
1194         {
1195                 FLAC::Metadata::CueSheet blockcopy(cuesheet_);
1196                 if(!blockcopy.is_valid())
1197                         return die_("!block.is_valid()");
1198                 if(blockcopy != cuesheet_)
1199                         return die_("copy is not identical to original");
1200                 printf("OK\n");
1201         }
1202
1203         printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *)... +\n");
1204         printf("        CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
1205         {
1206                 FLAC::Metadata::CueSheet blockcopy(&cuesheet_);
1207                 if(!blockcopy.is_valid())
1208                         return die_("!block.is_valid()");
1209                 if(blockcopy != cuesheet_)
1210                         return die_("copy is not identical to original");
1211                 printf("OK\n");
1212         }
1213
1214         printf("testing CueSheet::operator=(const CueSheet &)... +\n");
1215         printf("        CueSheet::operator==(const CueSheet &)... ");
1216         {
1217                 FLAC::Metadata::CueSheet blockcopy = block;
1218                 if(!blockcopy.is_valid())
1219                         return die_("!block.is_valid()");
1220                 if(!(blockcopy == block))
1221                         return die_("copy is not identical to original");
1222                 printf("OK\n");
1223         }
1224
1225         printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata &)... +\n");
1226         printf("        CueSheet::operator==(const ::FLAC__StreamMetadata &)... ");
1227         {
1228                 FLAC::Metadata::CueSheet blockcopy = cuesheet_;
1229                 if(!blockcopy.is_valid())
1230                         return die_("!block.is_valid()");
1231                 if(!(blockcopy == cuesheet_))
1232                         return die_("copy is not identical to original");
1233                 printf("OK\n");
1234         }
1235
1236         printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata *)... +\n");
1237         printf("        CueSheet::operator==(const ::FLAC__StreamMetadata *)... ");
1238         {
1239                 FLAC::Metadata::CueSheet blockcopy = &cuesheet_;
1240                 if(!blockcopy.is_valid())
1241                         return die_("!block.is_valid()");
1242                 if(!(blockcopy == cuesheet_))
1243                         return die_("copy is not identical to original");
1244                 printf("OK\n");
1245         }
1246
1247         printf("testing CueSheet::get_media_catalog_number()... ");
1248         if(0 != strcmp(block.get_media_catalog_number(), ""))
1249                 return die_("value mismatch");
1250         printf("OK\n");
1251
1252         printf("testing CueSheet::get_lead_in()... ");
1253         if(block.get_lead_in() != 0)
1254                 return die_("value mismatch, expected 0");
1255         printf("OK\n");
1256
1257         printf("testing CueSheet::get_num_tracks()... ");
1258         if(block.get_num_tracks() != 0)
1259                 return die_("value mismatch, expected 0");
1260         printf("OK\n");
1261
1262         printf("testing CueSheet::set_media_catalog_number()... ");
1263         {
1264                 char mcn[129];
1265                 memset(mcn, 0, sizeof(mcn));
1266                 strcpy(mcn, "1234567890123");
1267                 block.set_media_catalog_number(mcn);
1268                 if(0 != memcmp(block.get_media_catalog_number(), mcn, sizeof(mcn)))
1269                         return die_("value mismatch");
1270         }
1271         printf("OK\n");
1272
1273         printf("testing CueSheet::set_lead_in()... ");
1274         block.set_lead_in(588);
1275         if(block.get_lead_in() != 588)
1276                 return die_("value mismatch");
1277         printf("OK\n");
1278
1279         printf("testing CueSheet::insert_track()... +\n");
1280         printf("        CueSheet::get_track()... ");
1281         if(!block.insert_track(0, track0))
1282                 return die_("returned false");
1283         if(!track_is_equal_(block.get_track(0).get_track(), track0.get_track()))
1284                 return die_("value mismatch");
1285         printf("OK\n");
1286
1287         printf("testing CueSheet::insert_track()... +\n");
1288         printf("        CueSheet::get_track()... ");
1289         if(!block.insert_track(1, track1))
1290                 return die_("returned false");
1291         if(!track_is_equal_(block.get_track(1).get_track(), track1.get_track()))
1292                 return die_("value mismatch");
1293         printf("OK\n");
1294
1295         ::FLAC__StreamMetadata_CueSheet_Index index0;
1296         index0.offset = 588*4;
1297         index0.number = 1;
1298
1299         printf("testing CueSheet::insert_index(0)... +\n");
1300         printf("        CueSheet::get_track()... +\n");
1301         printf("        CueSheet::Track::get_index()... ");
1302         if(!block.insert_index(0, 0, index0))
1303                 return die_("returned false");
1304         if(!index_is_equal_(block.get_track(0).get_index(0), index0))
1305                 return die_("value mismatch");
1306         printf("OK\n");
1307
1308         index0.offset = 588*5;
1309         printf("testing CueSheet::Track::set_index()... ");
1310         {
1311                 FLAC::Metadata::CueSheet::Track track_ = block.get_track(0);
1312                 track_.set_index(0, index0);
1313                 if(!index_is_equal_(track_.get_index(0), index0))
1314                         return die_("value mismatch");
1315         }
1316         printf("OK\n");
1317
1318         index0.offset = 588*6;
1319         printf("testing CueSheet::set_index()... ");
1320         block.set_index(0, 0, index0);
1321         if(!index_is_equal_(block.get_track(0).get_index(0), index0))
1322                 return die_("value mismatch");
1323         printf("OK\n");
1324
1325         printf("testing CueSheet::delete_index()... ");
1326         if(!block.delete_index(0, 0))
1327                 return die_("returned false");
1328         if(block.get_track(0).get_num_indices() != 0)
1329                 return die_("num_indices mismatch");
1330         printf("OK\n");
1331
1332
1333         printf("testing CueSheet::set_track()... +\n");
1334         printf("        CueSheet::get_track()... ");
1335         if(!block.set_track(0, track1))
1336                 return die_("returned false");
1337         if(!track_is_equal_(block.get_track(0).get_track(), track1.get_track()))
1338                 return die_("value mismatch");
1339         printf("OK\n");
1340
1341         printf("testing CueSheet::delete_track()... ");
1342         if(!block.delete_track(0))
1343                 return die_("returned false");
1344         if(block.get_num_tracks() != 1)
1345                 return die_("num_tracks mismatch");
1346         printf("OK\n");
1347
1348         printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
1349         FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
1350         if(0 == clone_)
1351                 return die_("returned NULL");
1352         if(0 == dynamic_cast<FLAC::Metadata::CueSheet *>(clone_))
1353                 return die_("downcast is NULL");
1354         if(*dynamic_cast<FLAC::Metadata::CueSheet *>(clone_) != block)
1355                 return die_("clone is not identical");
1356         printf("OK\n");
1357
1358
1359         printf("PASSED\n\n");
1360         return true;
1361 }
1362
1363 bool test_metadata_object()
1364 {
1365         printf("\n+++ libFLAC++ unit test: metadata objects\n\n");
1366
1367         init_metadata_blocks_();
1368
1369         if(!test_metadata_object_streaminfo())
1370                 return false;
1371
1372         if(!test_metadata_object_padding())
1373                 return false;
1374
1375         if(!test_metadata_object_application())
1376                 return false;
1377
1378         if(!test_metadata_object_seektable())
1379                 return false;
1380
1381         if(!test_metadata_object_vorbiscomment())
1382                 return false;
1383
1384         if(!test_metadata_object_cuesheet())
1385                 return false;
1386
1387         free_metadata_blocks_();
1388
1389         return true;
1390 }