merge down from merged-API-layer branch: cvs -q up -dP -j API_LAYER_MERGING_BASELINE -j API_LAYER_MERGING_BRANCH

This commit is contained in:
Josh Coalson
2006-09-13 01:42:27 +00:00
parent 461f3eb260
commit 6b21f66784
156 changed files with 8320 additions and 31342 deletions

View File

@@ -25,23 +25,20 @@ noinst_PROGRAMS = test_libFLAC
test_libFLAC_LDADD = \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
$(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \
$(top_builddir)/src/test_libs_common/libtest_libs_common.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
-lm
test_libFLAC_SOURCES = \
bitbuffer.c \
decoders.c \
encoders.c \
file_utils.c \
format.c \
main.c \
metadata.c \
metadata_manip.c \
metadata_object.c \
metadata_utils.c \
bitbuffer.h \
decoders.h \
encoders.h \
file_utils.h \
format.h \
metadata.h \
metadata_utils.h
metadata.h

View File

@@ -27,22 +27,20 @@ PROGRAM_NAME = test_libFLAC
INCLUDES = -I../libFLAC/include -I$(topdir)/include
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libFLAC.a -lm
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libtest_libs_common.a $(libdir)/libFLAC.a -lm
else
LIBS = -lgrabbag -lreplaygain_analysis -lFLAC -lm
LIBS = -lgrabbag -lreplaygain_analysis -ltest_libs_common -lOggFLAC -lFLAC -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_C = \
bitbuffer.c \
decoders.c \
encoders.c \
file_utils.c \
format.c \
main.c \
metadata.c \
metadata_manip.c \
metadata_object.c \
metadata_utils.c
metadata_object.c
include $(topdir)/build/exe.mk

File diff suppressed because it is too large Load Diff

View File

@@ -20,23 +20,42 @@
# include <config.h>
#endif
#include "encoders.h"
#include "file_utils.h"
#include "metadata_utils.h"
#include "FLAC/assert.h"
#include "FLAC/file_encoder.h"
#include "FLAC/seekable_stream_encoder.h"
#include "FLAC/stream_encoder.h"
#include "share/grabbag.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encoders.h"
#include "FLAC/assert.h"
#include "FLAC/stream_encoder.h"
#include "share/grabbag.h"
#include "test_libs_common/file_utils_flac.h"
#include "test_libs_common/metadata_utils.h"
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_encoder_init_file() */
} Layer;
static const char * const LayerString[] = {
"Stream",
"Seekable Stream",
"FILE*",
"Filename"
};
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_ };
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
static const char *flacfilename_ = "metadata.flac";
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
return false;
}
static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
{
FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
@@ -55,54 +74,6 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
return false;
}
static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
{
FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
printf(" stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
}
}
return false;
}
static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
{
FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
printf(" seekable stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
printf(" stream encoder state = %u (%s)\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
}
}
}
return false;
}
static void init_metadata_blocks_()
{
mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
@@ -119,23 +90,42 @@ static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC_
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void)encoder, (void)absolute_byte_offset, (void)client_data;
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
}
static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
(void)encoder, (void)client_data;
*absolute_byte_offset = 0;
return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
}
static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
static FLAC__bool test_stream_encoder()
static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
}
static FLAC__bool test_stream_encoder(Layer layer)
{
FLAC__StreamEncoder *encoder;
FLAC__StreamEncoderState state;
FLAC__StreamDecoderState dstate;
FILE *file = 0;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1];
unsigned i;
samples_array[0] = samples;
printf("\n+++ libFLAC unit test: FLAC__StreamEncoder\n\n");
printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s)\n\n", LayerString[layer]);
printf("testing FLAC__stream_encoder_new()... ");
encoder = FLAC__stream_encoder_new();
@@ -235,24 +225,39 @@ static FLAC__bool test_stream_encoder()
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_write_callback()... ");
if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
return die_s_("returned false", encoder);
printf("OK\n");
switch(layer) {
case LAYER_STREAM:
printf("testing FLAC__stream_encoder_init_stream()... ");
if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_SEEKABLE_STREAM:
printf("testing FLAC__stream_encoder_init_stream()... ");
if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILE:
printf("opening file for FLAC output... ");
file = fopen(flacfilename_, "w+b");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_client_data()... ");
if(!FLAC__stream_encoder_set_client_data(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_init()... ");
if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
return die_s_(0, encoder);
printf("testing FLAC__stream_encoder_init_FILE()... ");
if(FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILENAME:
printf("testing FLAC__stream_encoder_init_file()... ");
if(FLAC__stream_encoder_init_file(encoder, flacfilename_, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
default:
die_("internal error 001");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_state()... ");
@@ -420,653 +425,20 @@ static FLAC__bool test_stream_encoder()
return true;
}
FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void)encoder, (void)absolute_byte_offset, (void)client_data;
return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
}
FLAC__SeekableStreamEncoderTellStatus seekable_stream_encoder_tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
(void)encoder, (void)client_data;
*absolute_byte_offset = 0;
return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
}
FLAC__StreamEncoderWriteStatus seekable_stream_encoder_write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
(void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
static FLAC__bool test_seekable_stream_encoder()
{
FLAC__SeekableStreamEncoder *encoder;
FLAC__SeekableStreamEncoderState state;
FLAC__StreamEncoderState state_;
FLAC__StreamDecoderState dstate;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1];
unsigned i;
samples_array[0] = samples;
printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
printf("testing FLAC__seekable_stream_encoder_new()... ");
encoder = FLAC__seekable_stream_encoder_new();
if(0 == encoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_tell_callback()... ");
if(!FLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_init()... ");
if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
return die_ss_(0, encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_state()... ");
state = FLAC__seekable_stream_encoder_get_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
{
FLAC__uint64 absolute_sample;
unsigned frame_number;
unsigned channel;
unsigned sample;
FLAC__int32 expected;
FLAC__int32 got;
printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
printf("OK\n");
}
printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
(void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
/* we asked the encoder to auto select this so we accept anything */
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
return false;
}
printf("OK\n");
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
printf("testing FLAC__seekable_stream_encoder_process()... ");
if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
return die_ss_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_finish()... ");
FLAC__seekable_stream_encoder_finish(encoder);
printf("OK\n");
printf("testing FLAC__seekable_stream_encoder_delete()... ");
FLAC__seekable_stream_encoder_delete(encoder);
printf("OK\n");
printf("\nPASSED!\n");
return true;
}
static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
}
static FLAC__bool test_file_encoder()
{
FLAC__FileEncoder *encoder;
FLAC__FileEncoderState state;
FLAC__SeekableStreamEncoderState state_;
FLAC__StreamEncoderState state__;
FLAC__StreamDecoderState dstate;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1];
unsigned i;
samples_array[0] = samples;
printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
printf("testing FLAC__file_encoder_new()... ");
encoder = FLAC__file_encoder_new();
if(0 == encoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_set_verify()... ");
if(!FLAC__file_encoder_set_verify(encoder, true))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_streamable_subset()... ");
if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_channels()... ");
if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_sample_rate()... ");
if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_blocksize()... ");
if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_metadata()... ");
if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_filename()... ");
if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_progress_callback()... ");
if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_set_client_data()... ");
if(!FLAC__file_encoder_set_client_data(encoder, 0))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_init()... ");
if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
return die_f_(0, encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_get_state()... ");
state = FLAC__file_encoder_get_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
{
FLAC__uint64 absolute_sample;
unsigned frame_number;
unsigned channel;
unsigned sample;
FLAC__int32 expected;
FLAC__int32 got;
printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
printf("OK\n");
}
printf("testing FLAC__file_encoder_get_verify()... ");
if(FLAC__file_encoder_get_verify(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_streamable_subset()... ");
if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_channels()... ");
if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_sample_rate()... ");
if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_blocksize()... ");
if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
(void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
/* we asked the encoder to auto select this so we accept anything */
printf("OK\n");
printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
return false;
}
printf("OK\n");
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
printf("testing FLAC__file_encoder_process()... ");
if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_process_interleaved()... ");
if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
return die_f_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_finish()... ");
FLAC__file_encoder_finish(encoder);
printf("OK\n");
printf("testing FLAC__file_encoder_delete()... ");
FLAC__file_encoder_delete(encoder);
printf("OK\n");
printf("\nPASSED!\n");
return true;
}
FLAC__bool test_encoders()
{
init_metadata_blocks_();
if(!test_stream_encoder())
if(!test_stream_encoder(LAYER_STREAM))
return false;
if(!test_seekable_stream_encoder())
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_file_encoder())
if(!test_stream_encoder(LAYER_FILE))
return false;
if(!test_stream_encoder(LAYER_FILENAME))
return false;
(void) grabbag__file_remove_file(flacfilename_);

View File

@@ -1,147 +0,0 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "file_utils.h"
#include "FLAC/assert.h"
#include "FLAC/stream_encoder.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h> /* for stat() */
#ifdef min
#undef min
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#ifdef FLAC__VALGRIND_TESTING
static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret = fwrite(ptr, size, nmemb, stream);
if(!ferror(stream))
fflush(stream);
return ret;
}
#else
#define local__fwrite fwrite
#endif
typedef struct {
FILE *file;
} encoder_client_struct;
static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
encoder_client_struct *ecd = (encoder_client_struct*)client_data;
(void)encoder, (void)samples, (void)current_frame;
if(local__fwrite(buffer, 1, bytes, ecd->file) != bytes)
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
else
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
{
FLAC__int32 samples[1024];
FLAC__StreamEncoder *encoder;
encoder_client_struct encoder_client_data;
unsigned i, n;
FLAC__ASSERT(0 != output_filename);
FLAC__ASSERT(0 != streaminfo);
FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO);
FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0));
if(0 == (encoder_client_data.file = fopen(output_filename, "wb")))
return false;
encoder = FLAC__stream_encoder_new();
if(0 == encoder) {
fclose(encoder_client_data.file);
return false;
}
FLAC__stream_encoder_set_verify(encoder, true);
FLAC__stream_encoder_set_streamable_subset(encoder, true);
FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false);
FLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels);
FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample);
FLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate);
FLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize);
FLAC__stream_encoder_set_max_lpc_order(encoder, 0);
FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0);
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false);
FLAC__stream_encoder_set_do_escape_coding(encoder, false);
FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false);
FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0);
FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0);
FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0);
FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
FLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_);
FLAC__stream_encoder_set_metadata_callback(encoder, encoder_metadata_callback_);
FLAC__stream_encoder_set_client_data(encoder, &encoder_client_data);
if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK) {
fclose(encoder_client_data.file);
return false;
}
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
while(length > 0) {
n = min(length, sizeof(samples) / sizeof(FLAC__int32));
if(!FLAC__stream_encoder_process_interleaved(encoder, samples, n)) {
fclose(encoder_client_data.file);
return false;
}
length -= n;
}
FLAC__stream_encoder_finish(encoder);
fclose(encoder_client_data.file);
FLAC__stream_encoder_delete(encoder);
if(0 != output_filesize) {
struct stat filestats;
if(stat(output_filename, &filestats) != 0)
return false;
else
*output_filesize = filestats.st_size;
}
return true;
}

View File

@@ -1,32 +0,0 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef FLAC__TEST_LIBFLAC_FILE_UTILS_H
#define FLAC__TEST_LIBFLAC_FILE_UTILS_H
/* needed because of off_t */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "FLAC/format.h"
#include <sys/types.h> /* for off_t */
FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata);
#endif

View File

@@ -34,12 +34,12 @@
#include <unistd.h> /* for chown(), unlink() */
#endif
#include <sys/stat.h> /* for stat(), maybe chmod() */
#include "file_utils.h"
#include "metadata_utils.h"
#include "FLAC/assert.h"
#include "FLAC/file_decoder.h"
#include "FLAC/stream_decoder.h"
#include "FLAC/metadata.h"
#include "share/grabbag.h"
#include "test_libs_common/file_utils_flac.h"
#include "test_libs_common/metadata_utils.h"
/******************************************************************************
@@ -47,7 +47,7 @@
to create a dummy FLAC file with a known set of initial metadata
blocks, then keep a mirror locally of what we expect the metadata to be
after each operation. Then testing becomes a simple matter of running
a FLAC__FileDecoder over the dummy file after each operation, comparing
a FLAC__StreamDecoder over the dummy file after each operation, comparing
the decoded metadata to what's in our local copy. If there are any
differences in the metadata, or the actual audio data is corrupted, we
will catch it while decoding.
@@ -422,7 +422,7 @@ static FLAC__bool compare_chain_(FLAC__Metadata_Chain *chain, unsigned current_p
/* decoder callbacks for checking the file */
static FLAC__StreamDecoderWriteStatus decoder_write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
static FLAC__StreamDecoderWriteStatus decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
(void)decoder, (void)buffer, (void)client_data;
@@ -438,7 +438,7 @@ static FLAC__StreamDecoderWriteStatus decoder_write_callback_(const FLAC__FileDe
}
/* this version pays no attention to the metadata */
static void decoder_metadata_callback_null_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
static void decoder_metadata_callback_null_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
(void)decoder, (void)metadata, (void)client_data;
@@ -449,7 +449,7 @@ static void decoder_metadata_callback_null_(const FLAC__FileDecoder *decoder, co
}
/* this version is used when we want to compare to our metadata copy */
static void decoder_metadata_callback_compare_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
static void decoder_metadata_callback_compare_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
decoder_client_struct *dcd = (decoder_client_struct*)client_data;
@@ -475,7 +475,7 @@ static void decoder_metadata_callback_compare_(const FLAC__FileDecoder *decoder,
mc_our_block_number_++;
}
static void decoder_error_callback_(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
static void decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
decoder_client_struct *dcd = (decoder_client_struct*)client_data;
(void)decoder;
@@ -559,9 +559,9 @@ static FLAC__bool generate_file_(FLAC__bool include_cuesheet)
return true;
}
static FLAC__bool test_file_(const char *filename, FLAC__FileDecoderMetadataCallback metadata_callback)
static FLAC__bool test_file_(const char *filename, FLAC__StreamDecoderMetadataCallback metadata_callback)
{
FLAC__FileDecoder *decoder;
FLAC__StreamDecoder *decoder;
decoder_client_struct decoder_client_data;
FLAC__ASSERT(0 != filename);
@@ -573,29 +573,24 @@ static FLAC__bool test_file_(const char *filename, FLAC__FileDecoderMetadataCall
printf("\ttesting '%s'... ", filename);
fflush(stdout);
if(0 == (decoder = FLAC__file_decoder_new()))
if(0 == (decoder = FLAC__stream_decoder_new()))
return die_("couldn't allocate decoder instance");
FLAC__file_decoder_set_md5_checking(decoder, true);
FLAC__file_decoder_set_filename(decoder, filename);
FLAC__file_decoder_set_write_callback(decoder, decoder_write_callback_);
FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback);
FLAC__file_decoder_set_error_callback(decoder, decoder_error_callback_);
FLAC__file_decoder_set_client_data(decoder, &decoder_client_data);
FLAC__file_decoder_set_metadata_respond_all(decoder);
if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) {
FLAC__file_decoder_finish(decoder);
FLAC__file_decoder_delete(decoder);
FLAC__stream_decoder_set_md5_checking(decoder, true);
FLAC__stream_decoder_set_metadata_respond_all(decoder);
if(FLAC__stream_decoder_init_file(decoder, filename, decoder_write_callback_, metadata_callback, decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
return die_("initializing decoder\n");
}
if(!FLAC__file_decoder_process_until_end_of_file(decoder)) {
FLAC__file_decoder_finish(decoder);
FLAC__file_decoder_delete(decoder);
if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) {
FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
return die_("decoding file\n");
}
FLAC__file_decoder_finish(decoder);
FLAC__file_decoder_delete(decoder);
FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
if(decoder_client_data.error_occurred)
return false;

View File

@@ -22,7 +22,7 @@
#include "FLAC/assert.h"
#include "FLAC/metadata.h"
#include "metadata_utils.h"
#include "test_libs_common/metadata_utils.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
@@ -467,7 +467,7 @@ static void cs_delete_(FLAC__StreamMetadata *block, unsigned pos)
FLAC__bool test_metadata_object()
{
FLAC__StreamMetadata *block, *blockcopy, *vorbiscomment, *cuesheet;
FLAC__StreamMetadata_SeekPoint seekpoint_array[8];
FLAC__StreamMetadata_SeekPoint seekpoint_array[14];
FLAC__StreamMetadata_VorbisComment_Entry entry;
FLAC__StreamMetadata_CueSheet_Index index;
FLAC__StreamMetadata_CueSheet_Track track;
@@ -879,6 +879,28 @@ FLAC__bool test_metadata_object()
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoint_array[seekpoints++].sample_number = 0;
seekpoint_array[seekpoints++].sample_number = 10;
seekpoint_array[seekpoints++].sample_number = 20;
printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 10, 30)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoint_array[seekpoints++].sample_number = 0;
seekpoint_array[seekpoints++].sample_number = 11;
seekpoint_array[seekpoints++].sample_number = 22;
printf("testing FLAC__metadata_object_seekpoint_template_append_spaced_points_by_samples()... ");
if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(block, 11, 30)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(block);
printf("OK\n");

View File

@@ -1,534 +0,0 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* These are not tests, just utility functions used by the metadata tests
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "metadata_utils.h"
#include "FLAC/metadata.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
FLAC__bool mutils__compare_block_data_streaminfo(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy)
{
if(blockcopy->min_blocksize != block->min_blocksize) {
printf("FAILED, min_blocksize mismatch, expected %u, got %u\n", block->min_blocksize, blockcopy->min_blocksize);
return false;
}
if(blockcopy->max_blocksize != block->max_blocksize) {
printf("FAILED, max_blocksize mismatch, expected %u, got %u\n", block->max_blocksize, blockcopy->max_blocksize);
return false;
}
if(blockcopy->min_framesize != block->min_framesize) {
printf("FAILED, min_framesize mismatch, expected %u, got %u\n", block->min_framesize, blockcopy->min_framesize);
return false;
}
if(blockcopy->max_framesize != block->max_framesize) {
printf("FAILED, max_framesize mismatch, expected %u, got %u\n", block->max_framesize, blockcopy->max_framesize);
return false;
}
if(blockcopy->sample_rate != block->sample_rate) {
printf("FAILED, sample_rate mismatch, expected %u, got %u\n", block->sample_rate, blockcopy->sample_rate);
return false;
}
if(blockcopy->channels != block->channels) {
printf("FAILED, channels mismatch, expected %u, got %u\n", block->channels, blockcopy->channels);
return false;
}
if(blockcopy->bits_per_sample != block->bits_per_sample) {
printf("FAILED, bits_per_sample mismatch, expected %u, got %u\n", block->bits_per_sample, blockcopy->bits_per_sample);
return false;
}
if(blockcopy->total_samples != block->total_samples) {
printf("FAILED, total_samples mismatch, expected %llu, got %llu\n", block->total_samples, blockcopy->total_samples);
return false;
}
if(0 != memcmp(blockcopy->md5sum, block->md5sum, sizeof(block->md5sum))) {
printf("FAILED, md5sum mismatch, expected %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, got %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
(unsigned)block->md5sum[0],
(unsigned)block->md5sum[1],
(unsigned)block->md5sum[2],
(unsigned)block->md5sum[3],
(unsigned)block->md5sum[4],
(unsigned)block->md5sum[5],
(unsigned)block->md5sum[6],
(unsigned)block->md5sum[7],
(unsigned)block->md5sum[8],
(unsigned)block->md5sum[9],
(unsigned)block->md5sum[10],
(unsigned)block->md5sum[11],
(unsigned)block->md5sum[12],
(unsigned)block->md5sum[13],
(unsigned)block->md5sum[14],
(unsigned)block->md5sum[15],
(unsigned)blockcopy->md5sum[0],
(unsigned)blockcopy->md5sum[1],
(unsigned)blockcopy->md5sum[2],
(unsigned)blockcopy->md5sum[3],
(unsigned)blockcopy->md5sum[4],
(unsigned)blockcopy->md5sum[5],
(unsigned)blockcopy->md5sum[6],
(unsigned)blockcopy->md5sum[7],
(unsigned)blockcopy->md5sum[8],
(unsigned)blockcopy->md5sum[9],
(unsigned)blockcopy->md5sum[10],
(unsigned)blockcopy->md5sum[11],
(unsigned)blockcopy->md5sum[12],
(unsigned)blockcopy->md5sum[13],
(unsigned)blockcopy->md5sum[14],
(unsigned)blockcopy->md5sum[15]
);
return false;
}
return true;
}
FLAC__bool mutils__compare_block_data_padding(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, unsigned block_length)
{
/* we don't compare the padding guts */
(void)block, (void)blockcopy, (void)block_length;
return true;
}
FLAC__bool mutils__compare_block_data_application(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, unsigned block_length)
{
if(block_length < sizeof(block->id)) {
printf("FAILED, bad block length = %u\n", block_length);
return false;
}
if(0 != memcmp(blockcopy->id, block->id, sizeof(block->id))) {
printf("FAILED, id mismatch, expected %02X%02X%02X%02X, got %02X%02X%02X%02X\n",
(unsigned)block->id[0],
(unsigned)block->id[1],
(unsigned)block->id[2],
(unsigned)block->id[3],
(unsigned)blockcopy->id[0],
(unsigned)blockcopy->id[1],
(unsigned)blockcopy->id[2],
(unsigned)blockcopy->id[3]
);
return false;
}
if(0 == block->data || 0 == blockcopy->data) {
if(block->data != blockcopy->data) {
printf("FAILED, data mismatch (%s's data pointer is null)\n", 0==block->data?"original":"copy");
return false;
}
else if(block_length - sizeof(block->id) > 0) {
printf("FAILED, data pointer is null but block length is not 0\n");
return false;
}
}
else {
if(block_length - sizeof(block->id) == 0) {
printf("FAILED, data pointer is not null but block length is 0\n");
return false;
}
else if(0 != memcmp(blockcopy->data, block->data, block_length - sizeof(block->id))) {
printf("FAILED, data mismatch\n");
return false;
}
}
return true;
}
FLAC__bool mutils__compare_block_data_seektable(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy)
{
unsigned i;
if(blockcopy->num_points != block->num_points) {
printf("FAILED, num_points mismatch, expected %u, got %u\n", block->num_points, blockcopy->num_points);
return false;
}
for(i = 0; i < block->num_points; i++) {
if(blockcopy->points[i].sample_number != block->points[i].sample_number) {
printf("FAILED, points[%u].sample_number mismatch, expected %llu, got %llu\n", i, block->points[i].sample_number, blockcopy->points[i].sample_number);
return false;
}
if(blockcopy->points[i].stream_offset != block->points[i].stream_offset) {
printf("FAILED, points[%u].stream_offset mismatch, expected %llu, got %llu\n", i, block->points[i].stream_offset, blockcopy->points[i].stream_offset);
return false;
}
if(blockcopy->points[i].frame_samples != block->points[i].frame_samples) {
printf("FAILED, points[%u].frame_samples mismatch, expected %u, got %u\n", i, block->points[i].frame_samples, blockcopy->points[i].frame_samples);
return false;
}
}
return true;
}
FLAC__bool mutils__compare_block_data_vorbiscomment(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy)
{
unsigned i;
if(blockcopy->vendor_string.length != block->vendor_string.length) {
printf("FAILED, vendor_string.length mismatch, expected %u, got %u\n", block->vendor_string.length, blockcopy->vendor_string.length);
return false;
}
if(0 == block->vendor_string.entry || 0 == blockcopy->vendor_string.entry) {
if(block->vendor_string.entry != blockcopy->vendor_string.entry) {
printf("FAILED, vendor_string.entry mismatch\n");
return false;
}
}
else if(0 != memcmp(blockcopy->vendor_string.entry, block->vendor_string.entry, block->vendor_string.length)) {
printf("FAILED, vendor_string.entry mismatch\n");
return false;
}
if(blockcopy->num_comments != block->num_comments) {
printf("FAILED, num_comments mismatch, expected %u, got %u\n", block->num_comments, blockcopy->num_comments);
return false;
}
for(i = 0; i < block->num_comments; i++) {
if(blockcopy->comments[i].length != block->comments[i].length) {
printf("FAILED, comments[%u].length mismatch, expected %u, got %u\n", i, block->comments[i].length, blockcopy->comments[i].length);
return false;
}
if(0 == block->comments[i].entry || 0 == blockcopy->comments[i].entry) {
if(block->comments[i].entry != blockcopy->comments[i].entry) {
printf("FAILED, comments[%u].entry mismatch\n", i);
return false;
}
}
else {
if(0 != memcmp(blockcopy->comments[i].entry, block->comments[i].entry, block->comments[i].length)) {
printf("FAILED, comments[%u].entry mismatch\n", i);
return false;
}
}
}
return true;
}
FLAC__bool mutils__compare_block_data_cuesheet(const FLAC__StreamMetadata_CueSheet *block, const FLAC__StreamMetadata_CueSheet *blockcopy)
{
unsigned i, j;
if(0 != strcmp(blockcopy->media_catalog_number, block->media_catalog_number)) {
printf("FAILED, media_catalog_number mismatch, expected %s, got %s\n", block->media_catalog_number, blockcopy->media_catalog_number);
return false;
}
if(blockcopy->lead_in != block->lead_in) {
printf("FAILED, lead_in mismatch, expected %llu, got %llu\n", block->lead_in, blockcopy->lead_in);
return false;
}
if(blockcopy->is_cd != block->is_cd) {
printf("FAILED, is_cd mismatch, expected %u, got %u\n", (unsigned)block->is_cd, (unsigned)blockcopy->is_cd);
return false;
}
if(blockcopy->num_tracks != block->num_tracks) {
printf("FAILED, num_tracks mismatch, expected %u, got %u\n", block->num_tracks, blockcopy->num_tracks);
return false;
}
for(i = 0; i < block->num_tracks; i++) {
if(blockcopy->tracks[i].offset != block->tracks[i].offset) {
printf("FAILED, tracks[%u].offset mismatch, expected %llu, got %llu\n", i, block->tracks[i].offset, blockcopy->tracks[i].offset);
return false;
}
if(blockcopy->tracks[i].number != block->tracks[i].number) {
printf("FAILED, tracks[%u].number mismatch, expected %u, got %u\n", i, (unsigned)block->tracks[i].number, (unsigned)blockcopy->tracks[i].number);
return false;
}
if(blockcopy->tracks[i].num_indices != block->tracks[i].num_indices) {
printf("FAILED, tracks[%u].num_indices mismatch, expected %u, got %u\n", i, (unsigned)block->tracks[i].num_indices, (unsigned)blockcopy->tracks[i].num_indices);
return false;
}
/* num_indices == 0 means lead-out track so only the track offset and number are valid */
if(block->tracks[i].num_indices > 0) {
if(0 != strcmp(blockcopy->tracks[i].isrc, block->tracks[i].isrc)) {
printf("FAILED, tracks[%u].isrc mismatch, expected %s, got %s\n", i, block->tracks[i].isrc, blockcopy->tracks[i].isrc);
return false;
}
if(blockcopy->tracks[i].type != block->tracks[i].type) {
printf("FAILED, tracks[%u].type mismatch, expected %u, got %u\n", i, (unsigned)block->tracks[i].type, (unsigned)blockcopy->tracks[i].type);
return false;
}
if(blockcopy->tracks[i].pre_emphasis != block->tracks[i].pre_emphasis) {
printf("FAILED, tracks[%u].pre_emphasis mismatch, expected %u, got %u\n", i, (unsigned)block->tracks[i].pre_emphasis, (unsigned)blockcopy->tracks[i].pre_emphasis);
return false;
}
if(0 == block->tracks[i].indices || 0 == blockcopy->tracks[i].indices) {
if(block->tracks[i].indices != blockcopy->tracks[i].indices) {
printf("FAILED, tracks[%u].indices mismatch\n", i);
return false;
}
}
else {
for(j = 0; j < block->tracks[i].num_indices; j++) {
if(blockcopy->tracks[i].indices[j].offset != block->tracks[i].indices[j].offset) {
printf("FAILED, tracks[%u].indices[%u].offset mismatch, expected %llu, got %llu\n", i, j, block->tracks[i].indices[j].offset, blockcopy->tracks[i].indices[j].offset);
return false;
}
if(blockcopy->tracks[i].indices[j].number != block->tracks[i].indices[j].number) {
printf("FAILED, tracks[%u].indices[%u].number mismatch, expected %u, got %u\n", i, j, (unsigned)block->tracks[i].indices[j].number, (unsigned)blockcopy->tracks[i].indices[j].number);
return false;
}
}
}
}
}
return true;
}
FLAC__bool mutils__compare_block_data_unknown(const FLAC__StreamMetadata_Unknown *block, const FLAC__StreamMetadata_Unknown *blockcopy, unsigned block_length)
{
if(0 == block->data || 0 == blockcopy->data) {
if(block->data != blockcopy->data) {
printf("FAILED, data mismatch (%s's data pointer is null)\n", 0==block->data?"original":"copy");
return false;
}
else if(block_length > 0) {
printf("FAILED, data pointer is null but block length is not 0\n");
return false;
}
}
else {
if(block_length == 0) {
printf("FAILED, data pointer is not null but block length is 0\n");
return false;
}
else if(0 != memcmp(blockcopy->data, block->data, block_length)) {
printf("FAILED, data mismatch\n");
return false;
}
}
return true;
}
FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy)
{
if(blockcopy->type != block->type) {
printf("FAILED, type mismatch, expected %s, got %s\n", FLAC__MetadataTypeString[block->type], FLAC__MetadataTypeString[blockcopy->type]);
return false;
}
if(blockcopy->is_last != block->is_last) {
printf("FAILED, is_last mismatch, expected %u, got %u\n", (unsigned)block->is_last, (unsigned)blockcopy->is_last);
return false;
}
if(blockcopy->length != block->length) {
printf("FAILED, length mismatch, expected %u, got %u\n", block->length, blockcopy->length);
return false;
}
switch(block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
return mutils__compare_block_data_streaminfo(&block->data.stream_info, &blockcopy->data.stream_info);
case FLAC__METADATA_TYPE_PADDING:
return mutils__compare_block_data_padding(&block->data.padding, &blockcopy->data.padding, block->length);
case FLAC__METADATA_TYPE_APPLICATION:
return mutils__compare_block_data_application(&block->data.application, &blockcopy->data.application, block->length);
case FLAC__METADATA_TYPE_SEEKTABLE:
return mutils__compare_block_data_seektable(&block->data.seek_table, &blockcopy->data.seek_table);
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
return mutils__compare_block_data_vorbiscomment(&block->data.vorbis_comment, &blockcopy->data.vorbis_comment);
case FLAC__METADATA_TYPE_CUESHEET:
return mutils__compare_block_data_cuesheet(&block->data.cue_sheet, &blockcopy->data.cue_sheet);
default:
return mutils__compare_block_data_unknown(&block->data.unknown, &blockcopy->data.unknown, block->length);
}
}
static void *malloc_or_die_(size_t size)
{
void *x = malloc(size);
if(0 == x) {
fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
exit(1);
}
return x;
}
static void *calloc_or_die_(size_t n, size_t size)
{
void *x = calloc(n, size);
if(0 == x) {
fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)n * (unsigned)size);
exit(1);
}
return x;
}
void mutils__init_metadata_blocks(
FLAC__StreamMetadata *streaminfo,
FLAC__StreamMetadata *padding,
FLAC__StreamMetadata *seektable,
FLAC__StreamMetadata *application1,
FLAC__StreamMetadata *application2,
FLAC__StreamMetadata *vorbiscomment,
FLAC__StreamMetadata *cuesheet,
FLAC__StreamMetadata *unknown
)
{
/*
most of the actual numbers and data in the blocks don't matter,
we just want to make sure the decoder parses them correctly
remember, the metadata interface gets tested after the decoders,
so we do all the metadata manipulation here without it.
*/
/* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
streaminfo->is_last = false;
streaminfo->type = FLAC__METADATA_TYPE_STREAMINFO;
streaminfo->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
streaminfo->data.stream_info.min_blocksize = 576;
streaminfo->data.stream_info.max_blocksize = 576;
streaminfo->data.stream_info.min_framesize = 0;
streaminfo->data.stream_info.max_framesize = 0;
streaminfo->data.stream_info.sample_rate = 44100;
streaminfo->data.stream_info.channels = 1;
streaminfo->data.stream_info.bits_per_sample = 8;
streaminfo->data.stream_info.total_samples = 0;
memset(streaminfo->data.stream_info.md5sum, 0, 16);
padding->is_last = false;
padding->type = FLAC__METADATA_TYPE_PADDING;
padding->length = 1234;
seektable->is_last = false;
seektable->type = FLAC__METADATA_TYPE_SEEKTABLE;
seektable->data.seek_table.num_points = 2;
seektable->length = seektable->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
seektable->data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
seektable->data.seek_table.points[0].sample_number = 0;
seektable->data.seek_table.points[0].stream_offset = 0;
seektable->data.seek_table.points[0].frame_samples = streaminfo->data.stream_info.min_blocksize;
seektable->data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
seektable->data.seek_table.points[1].stream_offset = 1000;
seektable->data.seek_table.points[1].frame_samples = streaminfo->data.stream_info.min_blocksize;
application1->is_last = false;
application1->type = FLAC__METADATA_TYPE_APPLICATION;
application1->length = 8;
memcpy(application1->data.application.id, "\xfe\xdc\xba\x98", 4);
application1->data.application.data = (FLAC__byte*)malloc_or_die_(4);
memcpy(application1->data.application.data, "\xf0\xe1\xd2\xc3", 4);
application2->is_last = false;
application2->type = FLAC__METADATA_TYPE_APPLICATION;
application2->length = 4;
memcpy(application2->data.application.id, "\x76\x54\x32\x10", 4);
application2->data.application.data = 0;
{
const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
vorbiscomment->is_last = false;
vorbiscomment->type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
vorbiscomment->length = (4 + vendor_string_length) + 4 + (4 + 5) + (4 + 0);
vorbiscomment->data.vorbis_comment.vendor_string.length = vendor_string_length;
vorbiscomment->data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(vendor_string_length+1);
memcpy(vorbiscomment->data.vorbis_comment.vendor_string.entry, FLAC__VENDOR_STRING, vendor_string_length+1);
vorbiscomment->data.vorbis_comment.num_comments = 2;
vorbiscomment->data.vorbis_comment.comments = (FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
vorbiscomment->data.vorbis_comment.comments[0].length = 5;
vorbiscomment->data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5+1);
memcpy(vorbiscomment->data.vorbis_comment.comments[0].entry, "ab=cd", 5+1);
vorbiscomment->data.vorbis_comment.comments[1].length = 0;
vorbiscomment->data.vorbis_comment.comments[1].entry = 0;
}
cuesheet->is_last = false;
cuesheet->type = FLAC__METADATA_TYPE_CUESHEET;
cuesheet->length =
/* cuesheet guts */
(
FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
) / 8 +
/* 2 tracks */
3 * (
FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
) / 8 +
/* 3 index points */
3 * (
FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
) / 8
;
memset(cuesheet->data.cue_sheet.media_catalog_number, 0, sizeof(cuesheet->data.cue_sheet.media_catalog_number));
cuesheet->data.cue_sheet.media_catalog_number[0] = 'j';
cuesheet->data.cue_sheet.media_catalog_number[1] = 'C';
cuesheet->data.cue_sheet.lead_in = 2 * 44100;
cuesheet->data.cue_sheet.is_cd = true;
cuesheet->data.cue_sheet.num_tracks = 3;
cuesheet->data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)calloc_or_die_(cuesheet->data.cue_sheet.num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track));
cuesheet->data.cue_sheet.tracks[0].offset = 0;
cuesheet->data.cue_sheet.tracks[0].number = 1;
memcpy(cuesheet->data.cue_sheet.tracks[0].isrc, "ACBDE1234567", sizeof(cuesheet->data.cue_sheet.tracks[0].isrc));
cuesheet->data.cue_sheet.tracks[0].type = 0;
cuesheet->data.cue_sheet.tracks[0].pre_emphasis = 1;
cuesheet->data.cue_sheet.tracks[0].num_indices = 2;
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));
cuesheet->data.cue_sheet.tracks[0].indices[0].offset = 0;
cuesheet->data.cue_sheet.tracks[0].indices[0].number = 0;
cuesheet->data.cue_sheet.tracks[0].indices[1].offset = 123 * 588;
cuesheet->data.cue_sheet.tracks[0].indices[1].number = 1;
cuesheet->data.cue_sheet.tracks[1].offset = 1234 * 588;
cuesheet->data.cue_sheet.tracks[1].number = 2;
memcpy(cuesheet->data.cue_sheet.tracks[1].isrc, "ACBDE7654321", sizeof(cuesheet->data.cue_sheet.tracks[1].isrc));
cuesheet->data.cue_sheet.tracks[1].type = 1;
cuesheet->data.cue_sheet.tracks[1].pre_emphasis = 0;
cuesheet->data.cue_sheet.tracks[1].num_indices = 1;
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));
cuesheet->data.cue_sheet.tracks[1].indices[0].offset = 0;
cuesheet->data.cue_sheet.tracks[1].indices[0].number = 1;
cuesheet->data.cue_sheet.tracks[2].offset = 12345 * 588;
cuesheet->data.cue_sheet.tracks[2].number = 170;
cuesheet->data.cue_sheet.tracks[2].num_indices = 0;
unknown->is_last = true;
unknown->type = 127;
unknown->length = 8;
unknown->data.unknown.data = (FLAC__byte*)malloc_or_die_(unknown->length);
memcpy(unknown->data.unknown.data, "\xfe\xdc\xba\x98\xf0\xe1\xd2\xc3", unknown->length);
}
void mutils__free_metadata_blocks(
FLAC__StreamMetadata *streaminfo,
FLAC__StreamMetadata *padding,
FLAC__StreamMetadata *seektable,
FLAC__StreamMetadata *application1,
FLAC__StreamMetadata *application2,
FLAC__StreamMetadata *vorbiscomment,
FLAC__StreamMetadata *cuesheet,
FLAC__StreamMetadata *unknown
)
{
(void)streaminfo, (void)padding, (void)application2;
free(seektable->data.seek_table.points);
free(application1->data.application.data);
free(vorbiscomment->data.vorbis_comment.vendor_string.entry);
free(vorbiscomment->data.vorbis_comment.comments[0].entry);
free(vorbiscomment->data.vorbis_comment.comments);
free(cuesheet->data.cue_sheet.tracks[0].indices);
free(cuesheet->data.cue_sheet.tracks[1].indices);
free(cuesheet->data.cue_sheet.tracks);
free(unknown->data.unknown.data);
}

View File

@@ -1,69 +0,0 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef FLAC__TEST_LIBFLAC_METADATA_H
#define FLAC__TEST_LIBFLAC_METADATA_H
/*
* These are not tests, just utility functions used by the metadata tests
*/
#include "FLAC/format.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
FLAC__bool mutils__compare_block_data_streaminfo(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy);
FLAC__bool mutils__compare_block_data_padding(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, unsigned block_length);
FLAC__bool mutils__compare_block_data_application(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, unsigned block_length);
FLAC__bool mutils__compare_block_data_seektable(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy);
FLAC__bool mutils__compare_block_data_vorbiscomment(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy);
FLAC__bool mutils__compare_block_data_cuesheet(const FLAC__StreamMetadata_CueSheet *block, const FLAC__StreamMetadata_CueSheet *blockcopy);
FLAC__bool mutils__compare_block_data_unknown(const FLAC__StreamMetadata_Unknown *block, const FLAC__StreamMetadata_Unknown *blockcopy, unsigned block_length);
FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy);
void mutils__init_metadata_blocks(
FLAC__StreamMetadata *streaminfo,
FLAC__StreamMetadata *padding,
FLAC__StreamMetadata *seektable,
FLAC__StreamMetadata *application1,
FLAC__StreamMetadata *application2,
FLAC__StreamMetadata *vorbiscomment,
FLAC__StreamMetadata *cuesheet,
FLAC__StreamMetadata *unknown
);
void mutils__free_metadata_blocks(
FLAC__StreamMetadata *streaminfo,
FLAC__StreamMetadata *padding,
FLAC__StreamMetadata *seektable,
FLAC__StreamMetadata *application1,
FLAC__StreamMetadata *application2,
FLAC__StreamMetadata *vorbiscomment,
FLAC__StreamMetadata *cuesheet,
FLAC__StreamMetadata *unknown
);
#endif

View File

@@ -51,7 +51,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\libFLAC_static.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\test_libs_common_static.lib ..\..\obj\release\lib\libFLAC_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test_libFLAC - Win32 Debug"
@@ -76,7 +76,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\libFLAC_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\test_libs_common_static.lib ..\..\obj\debug\lib\libFLAC_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
@@ -101,10 +101,6 @@ SOURCE=.\encoders.c
# End Source File
# Begin Source File
SOURCE=.\file_utils.c
# End Source File
# Begin Source File
SOURCE=.\format.c
# End Source File
# Begin Source File
@@ -123,10 +119,6 @@ SOURCE=.\metadata_manip.c
SOURCE=.\metadata_object.c
# End Source File
# Begin Source File
SOURCE=.\metadata_utils.c
# End Source File
# End Group
# Begin Group "Header Files"
@@ -145,20 +137,12 @@ SOURCE=.\encoders.h
# End Source File
# Begin Source File
SOURCE=.\file_utils.h
# End Source File
# Begin Source File
SOURCE=.\format.h
# End Source File
# Begin Source File
SOURCE=.\metadata.h
# End Source File
# Begin Source File
SOURCE=.\metadata_utils.h
# End Source File
# End Group
# End Target
# End Project