summaryrefslogtreecommitdiffstats
path: root/src/test_libFLAC++
diff options
context:
space:
mode:
Diffstat (limited to 'src/test_libFLAC++')
-rw-r--r--src/test_libFLAC++/CMakeLists.txt10
-rw-r--r--src/test_libFLAC++/Makefile.am50
-rw-r--r--src/test_libFLAC++/Makefile.in720
-rw-r--r--src/test_libFLAC++/decoders.cpp1179
-rw-r--r--src/test_libFLAC++/decoders.h25
-rw-r--r--src/test_libFLAC++/encoders.cpp576
-rw-r--r--src/test_libFLAC++/encoders.h25
-rw-r--r--src/test_libFLAC++/main.cpp42
-rw-r--r--src/test_libFLAC++/metadata.cpp41
-rw-r--r--src/test_libFLAC++/metadata.h25
-rw-r--r--src/test_libFLAC++/metadata_manip.cpp2241
-rw-r--r--src/test_libFLAC++/metadata_object.cpp2099
12 files changed, 7033 insertions, 0 deletions
diff --git a/src/test_libFLAC++/CMakeLists.txt b/src/test_libFLAC++/CMakeLists.txt
new file mode 100644
index 0000000..2fa7b1e
--- /dev/null
+++ b/src/test_libFLAC++/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_executable(test_libFLAC++
+ decoders.cpp
+ encoders.cpp
+ main.cpp
+ metadata.cpp
+ metadata_manip.cpp
+ metadata_object.cpp
+ $<$<BOOL:${WIN32}>:../../include/share/win_utf8_io.h>
+ $<$<BOOL:${WIN32}>:../share/win_utf8_io/win_utf8_io.c>)
+target_link_libraries(test_libFLAC++ FLAC++ test_libs_common grabbag)
diff --git a/src/test_libFLAC++/Makefile.am b/src/test_libFLAC++/Makefile.am
new file mode 100644
index 0000000..8bf746f
--- /dev/null
+++ b/src/test_libFLAC++/Makefile.am
@@ -0,0 +1,50 @@
+# test_libFLAC++ - Unit tester for libFLAC++
+# Copyright (C) 2002-2009 Josh Coalson
+# Copyright (C) 2011-2023 Xiph.Org Foundation
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+EXTRA_DIST = \
+ CMakeLists.txt
+
+AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
+check_PROGRAMS = test_libFLAC++
+
+if OS_IS_WINDOWS
+win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
+endif
+
+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 \
+ $(top_builddir)/src/libFLAC/libFLAC.la \
+ $(win_utf8_lib) \
+ @OGG_LIBS@ \
+ -lm
+
+test_libFLAC___SOURCES = \
+ decoders.cpp \
+ encoders.cpp \
+ main.cpp \
+ metadata.cpp \
+ metadata_manip.cpp \
+ metadata_object.cpp \
+ decoders.h \
+ encoders.h \
+ metadata.h
+
+CLEANFILES = test_libFLAC++.exe
diff --git a/src/test_libFLAC++/Makefile.in b/src/test_libFLAC++/Makefile.in
new file mode 100644
index 0000000..825dad6
--- /dev/null
+++ b/src/test_libFLAC++/Makefile.in
@@ -0,0 +1,720 @@
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# test_libFLAC++ - Unit tester for libFLAC++
+# Copyright (C) 2002-2009 Josh Coalson
+# Copyright (C) 2011-2023 Xiph.Org Foundation
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+check_PROGRAMS = test_libFLAC++$(EXEEXT)
+subdir = src/test_libFLAC++
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/add_cflags.m4 \
+ $(top_srcdir)/m4/add_cxxflags.m4 \
+ $(top_srcdir)/m4/ax_add_fortify_source.m4 \
+ $(top_srcdir)/m4/ax_check_compile_flag.m4 \
+ $(top_srcdir)/m4/ax_check_enable_debug.m4 \
+ $(top_srcdir)/m4/bswap.m4 $(top_srcdir)/m4/clang.m4 \
+ $(top_srcdir)/m4/codeset.m4 $(top_srcdir)/m4/gcc_version.m4 \
+ $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
+ $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/ogg.m4 \
+ $(top_srcdir)/m4/really_gcc.m4 \
+ $(top_srcdir)/m4/stack_protect.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am_test_libFLAC___OBJECTS = decoders.$(OBJEXT) encoders.$(OBJEXT) \
+ main.$(OBJEXT) metadata.$(OBJEXT) metadata_manip.$(OBJEXT) \
+ metadata_object.$(OBJEXT)
+test_libFLAC___OBJECTS = $(am_test_libFLAC___OBJECTS)
+test_libFLAC___DEPENDENCIES = \
+ $(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 \
+ $(top_builddir)/src/libFLAC/libFLAC.la $(win_utf8_lib)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/decoders.Po ./$(DEPDIR)/encoders.Po \
+ ./$(DEPDIR)/main.Po ./$(DEPDIR)/metadata.Po \
+ ./$(DEPDIR)/metadata_manip.Po ./$(DEPDIR)/metadata_object.Po
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo " CXX " $@;
+am__v_CXX_1 =
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo " CXXLD " $@;
+am__v_CXXLD_1 =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(test_libFLAC___SOURCES)
+DIST_SOURCES = $(test_libFLAC___SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCAS = @CCAS@
+CCASDEPMODE = @CCASDEPMODE@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DOXYGEN = @DOXYGEN@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ENABLE_64_BIT_WORDS = @ENABLE_64_BIT_WORDS@
+ETAGS = @ETAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FLAC__HAS_OGG = @FLAC__HAS_OGG@
+FLAC__TEST_LEVEL = @FLAC__TEST_LEVEL@
+FLAC__TEST_WITH_VALGRIND = @FLAC__TEST_WITH_VALGRIND@
+GCC_MAJOR_VERSION = @GCC_MAJOR_VERSION@
+GCC_MINOR_VERSION = @GCC_MINOR_VERSION@
+GCC_VERSION = @GCC_VERSION@
+GIT_COMMIT_VERSION_HASH = @GIT_COMMIT_VERSION_HASH@
+GIT_FOUND = @GIT_FOUND@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
+LIB_FUZZING_ENGINE = @LIB_FUZZING_ENGINE@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OBJ_FORMAT = @OBJ_FORMAT@
+OGG_CFLAGS = @OGG_CFLAGS@
+OGG_LIBS = @OGG_LIBS@
+OGG_PACKAGE = @OGG_PACKAGE@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PANDOC = @PANDOC@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+RC = @RC@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+EXTRA_DIST = \
+ CMakeLists.txt
+
+AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
+@OS_IS_WINDOWS_TRUE@win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
+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 \
+ $(top_builddir)/src/libFLAC/libFLAC.la \
+ $(win_utf8_lib) \
+ @OGG_LIBS@ \
+ -lm
+
+test_libFLAC___SOURCES = \
+ decoders.cpp \
+ encoders.cpp \
+ main.cpp \
+ metadata.cpp \
+ metadata_manip.cpp \
+ metadata_object.cpp \
+ decoders.h \
+ encoders.h \
+ metadata.h
+
+CLEANFILES = test_libFLAC++.exe
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cpp .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/test_libFLAC++/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/test_libFLAC++/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-checkPROGRAMS:
+ @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+test_libFLAC++$(EXEEXT): $(test_libFLAC___OBJECTS) $(test_libFLAC___DEPENDENCIES) $(EXTRA_test_libFLAC___DEPENDENCIES)
+ @rm -f test_libFLAC++$(EXEEXT)
+ $(AM_V_CXXLD)$(CXXLINK) $(test_libFLAC___OBJECTS) $(test_libFLAC___LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/decoders.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/encoders.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/metadata.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/metadata_manip.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/metadata_object.Po@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.cpp.o:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cpp.obj:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cpp.lo:
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f ./$(DEPDIR)/decoders.Po
+ -rm -f ./$(DEPDIR)/encoders.Po
+ -rm -f ./$(DEPDIR)/main.Po
+ -rm -f ./$(DEPDIR)/metadata.Po
+ -rm -f ./$(DEPDIR)/metadata_manip.Po
+ -rm -f ./$(DEPDIR)/metadata_object.Po
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f ./$(DEPDIR)/decoders.Po
+ -rm -f ./$(DEPDIR)/encoders.Po
+ -rm -f ./$(DEPDIR)/main.Po
+ -rm -f ./$(DEPDIR)/metadata.Po
+ -rm -f ./$(DEPDIR)/metadata_manip.Po
+ -rm -f ./$(DEPDIR)/metadata_object.Po
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+ clean-checkPROGRAMS clean-generic clean-libtool cscopelist-am \
+ ctags ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am
+
+.PRECIOUS: Makefile
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/test_libFLAC++/decoders.cpp b/src/test_libFLAC++/decoders.cpp
new file mode 100644
index 0000000..9f375f3
--- /dev/null
+++ b/src/test_libFLAC++/decoders.cpp
@@ -0,0 +1,1179 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "decoders.h"
+#include "FLAC/assert.h"
+#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
+#include "FLAC++/decoder.h"
+#include "share/grabbag.h"
+#include "share/compat.h"
+extern "C" {
+#include "test_libs_common/file_utils_flac.h"
+#include "test_libs_common/metadata_utils.h"
+}
+
+#ifdef _MSC_VER
+// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
+#pragma warning ( disable : 4800 )
+#endif
+
+typedef enum {
+ LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */
+ LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */
+ LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */
+ LAYER_FILENAME /* FLAC__stream_decoder_init_file() */
+} Layer;
+
+static const char * const LayerString[] = {
+ "Stream",
+ "Seekable Stream",
+ "FILE*",
+ "Filename"
+};
+
+static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
+static ::FLAC__StreamMetadata *expected_metadata_sequence_[9];
+static uint32_t num_expected_;
+static FLAC__off_t flacfilesize_;
+
+static const char *flacfilename(bool is_ogg)
+{
+ return is_ogg? "metadata.oga" : "metadata.flac";
+}
+
+static bool die_(const char *msg)
+{
+ printf("ERROR: %s\n", msg);
+ return false;
+}
+
+static FLAC__bool die_s_(const char *msg, const FLAC::Decoder::Stream *decoder)
+{
+ FLAC::Decoder::Stream::State state = decoder->get_state();
+
+ if(msg)
+ printf("FAILED, %s", msg);
+ else
+ printf("FAILED");
+
+ printf(", state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+
+ return false;
+}
+
+static void init_metadata_blocks_()
+{
+ mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
+}
+
+static void free_metadata_blocks_()
+{
+ mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
+}
+
+static bool generate_file_(FLAC__bool is_ogg)
+{
+ printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
+
+ if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
+ return die_("creating the encoded file");
+
+ return true;
+}
+
+
+class DecoderCommon {
+public:
+ Layer layer_;
+ uint32_t current_metadata_number_;
+ bool ignore_errors_;
+ bool error_occurred_;
+
+ DecoderCommon(Layer layer): layer_(layer), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
+ virtual ~DecoderCommon(void) { }
+ ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame);
+ void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata);
+ void common_error_callback_(::FLAC__StreamDecoderErrorStatus status);
+};
+
+::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame)
+{
+ if(error_occurred_)
+ return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+
+ if(
+ (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
+ (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
+ ) {
+ printf("content... ");
+ fflush(stdout);
+ }
+
+ return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
+void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata)
+{
+ if(error_occurred_)
+ return;
+
+ printf("%u... ", current_metadata_number_);
+ fflush(stdout);
+
+ if(current_metadata_number_ >= num_expected_) {
+ (void)die_("got more metadata blocks than expected");
+ error_occurred_ = true;
+ }
+ else {
+ if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) {
+ (void)die_("metadata block mismatch");
+ error_occurred_ = true;
+ }
+ }
+ current_metadata_number_++;
+}
+
+void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status)
+{
+ if(!ignore_errors_) {
+ printf("ERROR: got error callback: err = %u (%s)\n", (uint32_t)status, ::FLAC__StreamDecoderErrorStatusString[status]);
+ error_occurred_ = true;
+ }
+}
+
+class StreamDecoder : public FLAC::Decoder::Stream, public DecoderCommon {
+public:
+ FILE *file_;
+
+ StreamDecoder(Layer layer): FLAC::Decoder::Stream(), DecoderCommon(layer), file_(0) { }
+ ~StreamDecoder() { }
+
+ // from FLAC::Decoder::Stream
+ ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
+ ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
+ ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
+ ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
+ bool eof_callback();
+ ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
+ void metadata_callback(const ::FLAC__StreamMetadata *metadata);
+ void error_callback(::FLAC__StreamDecoderErrorStatus status);
+
+ bool test_respond(bool is_ogg);
+private:
+ StreamDecoder(const StreamDecoder&);
+ StreamDecoder&operator=(const StreamDecoder&);
+};
+
+::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], size_t *bytes)
+{
+ const size_t requested_bytes = *bytes;
+
+ if(error_occurred_)
+ return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+
+ if(feof(file_)) {
+ *bytes = 0;
+ return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ }
+ else if(requested_bytes > 0) {
+ *bytes = ::fread(buffer, 1, requested_bytes, file_);
+ if(*bytes == 0) {
+ if(feof(file_))
+ return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ else
+ return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ }
+ else {
+ return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ }
+ }
+ else
+ return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
+}
+
+::FLAC__StreamDecoderSeekStatus StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset)
+{
+ if(layer_ == LAYER_STREAM)
+ return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
+
+ if(error_occurred_)
+ return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
+
+ if(fseeko(file_, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0) {
+ error_occurred_ = true;
+ return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
+ }
+
+ return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK;
+}
+
+::FLAC__StreamDecoderTellStatus StreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
+{
+ if(layer_ == LAYER_STREAM)
+ return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
+
+ if(error_occurred_)
+ return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
+
+ FLAC__off_t offset = ftello(file_);
+ *absolute_byte_offset = (FLAC__uint64)offset;
+
+ if(offset < 0) {
+ error_occurred_ = true;
+ return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
+ }
+
+ return ::FLAC__STREAM_DECODER_TELL_STATUS_OK;
+}
+
+::FLAC__StreamDecoderLengthStatus StreamDecoder::length_callback(FLAC__uint64 *stream_length)
+{
+ if(layer_ == LAYER_STREAM)
+ return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
+
+ if(error_occurred_)
+ return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
+
+ *stream_length = (FLAC__uint64)flacfilesize_;
+ return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
+}
+
+bool StreamDecoder::eof_callback()
+{
+ if(layer_ == LAYER_STREAM)
+ return false;
+
+ if(error_occurred_)
+ return true;
+
+ return (bool)feof(file_);
+}
+
+::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
+{
+ (void)buffer;
+
+ return common_write_callback_(frame);
+}
+
+void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
+{
+ common_metadata_callback_(metadata);
+}
+
+void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
+{
+ common_error_callback_(status);
+}
+
+bool StreamDecoder::test_respond(bool is_ogg)
+{
+ ::FLAC__StreamDecoderInitStatus init_status;
+
+ if(!set_md5_checking(true)) {
+ printf("FAILED at set_md5_checking(), returned false\n");
+ return false;
+ }
+
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg? init_ogg() : init();
+ if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
+ return die_s_(0, this);
+ printf("OK\n");
+
+ current_metadata_number_ = 0;
+
+ if(fseeko(file_, 0, SEEK_SET) < 0) {
+ printf("FAILED rewinding input, errno = %d\n", errno);
+ return false;
+ }
+
+ printf("testing process_until_end_of_stream()... ");
+ if(!process_until_end_of_stream()) {
+ State state = get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing finish()... ");
+ if(!finish()) {
+ State state = get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ return true;
+}
+
+class FileDecoder : public FLAC::Decoder::File, public DecoderCommon {
+public:
+ FileDecoder(Layer layer): FLAC::Decoder::File(), DecoderCommon(layer) { }
+ ~FileDecoder() { }
+
+ // from FLAC::Decoder::Stream
+ ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
+ void metadata_callback(const ::FLAC__StreamMetadata *metadata);
+ void error_callback(::FLAC__StreamDecoderErrorStatus status);
+
+ bool test_respond(bool is_ogg);
+};
+
+::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
+{
+ (void)buffer;
+ return common_write_callback_(frame);
+}
+
+void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
+{
+ common_metadata_callback_(metadata);
+}
+
+void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
+{
+ common_error_callback_(status);
+}
+
+bool FileDecoder::test_respond(bool is_ogg)
+{
+ ::FLAC__StreamDecoderInitStatus init_status;
+
+ if(!set_md5_checking(true)) {
+ printf("FAILED at set_md5_checking(), returned false\n");
+ return false;
+ }
+
+ switch(layer_) {
+ case LAYER_FILE:
+ {
+ printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
+ FILE *file = ::flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == file) {
+ printf("ERROR (%s)\n", strerror(errno));
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg? init_ogg(file) : init(file);
+ }
+ break;
+ case LAYER_FILENAME:
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg? init_ogg(flacfilename(is_ogg)) : init(flacfilename(is_ogg));
+ break;
+ default:
+ die_("internal error 001");
+ return false;
+ }
+ if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
+ return die_s_(0, this);
+ printf("OK\n");
+
+ current_metadata_number_ = 0;
+
+ printf("testing process_until_end_of_stream()... ");
+ if(!process_until_end_of_stream()) {
+ State state = get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing finish()... ");
+ if(!finish()) {
+ State state = get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ return true;
+}
+
+
+static FLAC::Decoder::Stream *new_by_layer(Layer layer)
+{
+ if(layer < LAYER_FILE)
+ return new StreamDecoder(layer);
+ else
+ return new FileDecoder(layer);
+}
+
+static bool test_stream_decoder(Layer layer, bool is_ogg)
+{
+ FLAC::Decoder::Stream *decoder;
+ ::FLAC__StreamDecoderInitStatus init_status;
+ bool expect;
+
+ printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
+
+ //
+ // test new -> delete
+ //
+ printf("allocating decoder instance... ");
+ decoder = new_by_layer(layer);
+ if(0 == decoder) {
+ printf("FAILED, new returned NULL\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing is_valid()... ");
+ if(!decoder->is_valid()) {
+ printf("FAILED, returned false\n");
+ delete decoder;
+ return false;
+ }
+ printf("OK\n");
+
+ printf("freeing decoder instance... ");
+ delete decoder;
+ printf("OK\n");
+
+ //
+ // test new -> init -> delete
+ //
+ printf("allocating decoder instance... ");
+ decoder = new_by_layer(layer);
+ if(0 == decoder) {
+ printf("FAILED, new returned NULL\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing is_valid()... ");
+ if(!decoder->is_valid()) {
+ printf("FAILED, returned false\n");
+ delete decoder;
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ switch(layer) {
+ case LAYER_STREAM:
+ case LAYER_SEEKABLE_STREAM:
+ dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin;
+ init_status = is_ogg? decoder->init_ogg() : decoder->init();
+ break;
+ case LAYER_FILE:
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(stdin) :
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin);
+ break;
+ case LAYER_FILENAME:
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
+ break;
+ default:
+ die_("internal error 006");
+ delete decoder;
+ return false;
+ }
+ if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
+ return die_s_(0, decoder);
+ printf("OK\n");
+
+ printf("freeing decoder instance... ");
+ delete decoder;
+ printf("OK\n");
+
+ //
+ // test normal usage
+ //
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+
+ printf("allocating decoder instance... ");
+ decoder = new_by_layer(layer);
+ if(0 == decoder) {
+ printf("FAILED, new returned NULL\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing is_valid()... ");
+ if(!decoder->is_valid()) {
+ printf("FAILED, returned false\n");
+ delete decoder;
+ return false;
+ }
+ printf("OK\n");
+
+ if(is_ogg) {
+ printf("testing set_ogg_serial_number()... ");
+ if(!decoder->set_ogg_serial_number(file_utils__ogg_serial_number))
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+ }
+
+ if(!decoder->set_md5_checking(true)) {
+ printf("FAILED at set_md5_checking(), returned false\n");
+ return false;
+ }
+
+ switch(layer) {
+ case LAYER_STREAM:
+ case LAYER_SEEKABLE_STREAM:
+ printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
+ dynamic_cast<StreamDecoder*>(decoder)->file_ = ::flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) {
+ printf("ERROR (%s)\n", strerror(errno));
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg? decoder->init_ogg() : decoder->init();
+ break;
+ case LAYER_FILE:
+ {
+ printf("opening FLAC file... ");
+ FILE *file = ::flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == file) {
+ printf("ERROR (%s)\n", strerror(errno));
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(file) :
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file);
+ }
+ break;
+ case LAYER_FILENAME:
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
+ dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
+ break;
+ default:
+ die_("internal error 009");
+ return false;
+ }
+ if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
+ return die_s_(0, decoder);
+ printf("OK\n");
+
+ printf("testing get_state()... ");
+ FLAC::Decoder::Stream::State state = decoder->get_state();
+ printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+
+ dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
+ dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
+ dynamic_cast<DecoderCommon*>(decoder)->error_occurred_ = false;
+
+ printf("testing get_md5_checking()... ");
+ if(!decoder->get_md5_checking()) {
+ printf("FAILED, returned false, expected true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing process_until_end_of_metadata()... ");
+ if(!decoder->process_until_end_of_metadata())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ printf("testing process_single()... ");
+ if(!decoder->process_single())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ printf("testing skip_single_frame()... ");
+ if(!decoder->skip_single_frame())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ if(layer < LAYER_FILE) {
+ printf("testing flush()... ");
+ if(!decoder->flush())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = true;
+ printf("testing process_single()... ");
+ if(!decoder->process_single())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+ dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false;
+ }
+
+ expect = (layer != LAYER_STREAM);
+ printf("testing seek_absolute()... ");
+ if(decoder->seek_absolute(0) != expect)
+ return die_s_(expect? "returned false" : "returned true", decoder);
+ printf("OK\n");
+
+ printf("testing process_until_end_of_stream()... ");
+ if(!decoder->process_until_end_of_stream())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ expect = (layer != LAYER_STREAM);
+ printf("testing seek_absolute()... ");
+ if(decoder->seek_absolute(0) != expect)
+ return die_s_(expect? "returned false" : "returned true", decoder);
+ printf("OK\n");
+
+ printf("testing get_channels()... ");
+ {
+ uint32_t channels = decoder->get_channels();
+ if(channels != streaminfo_.data.stream_info.channels) {
+ printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
+ return false;
+ }
+ }
+ printf("OK\n");
+
+ printf("testing get_bits_per_sample()... ");
+ {
+ uint32_t bits_per_sample = decoder->get_bits_per_sample();
+ if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
+ printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
+ return false;
+ }
+ }
+ printf("OK\n");
+
+ printf("testing get_sample_rate()... ");
+ {
+ uint32_t sample_rate = decoder->get_sample_rate();
+ if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
+ printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
+ return false;
+ }
+ }
+ printf("OK\n");
+
+ printf("testing get_blocksize()... ");
+ {
+ uint32_t blocksize = decoder->get_blocksize();
+ /* value could be anything since we're at the last block, so accept any reasonable answer */
+ printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
+ if(blocksize == 0)
+ return false;
+ }
+
+ printf("testing get_channel_assignment()... ");
+ {
+ ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
+ printf("returned %u (%s)... OK\n", (uint32_t)ca, ::FLAC__ChannelAssignmentString[ca]);
+ }
+
+ if(layer < LAYER_FILE) {
+ printf("testing reset()... ");
+ if(!decoder->reset())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+
+ if(layer == LAYER_STREAM) {
+ /* after a reset() we have to rewind the input ourselves */
+ printf("rewinding input... ");
+ if(fseeko(dynamic_cast<StreamDecoder*>(decoder)->file_, 0, SEEK_SET) < 0) {
+ printf("FAILED, errno = %d\n", errno);
+ return false;
+ }
+ printf("OK\n");
+ }
+
+ dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0;
+
+ printf("testing process_until_end_of_stream()... ");
+ if(!decoder->process_until_end_of_stream())
+ return die_s_("returned false", decoder);
+ printf("OK\n");
+ }
+
+ printf("testing finish()... ");
+ if(!decoder->finish()) {
+ state = decoder->get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ /*
+ * respond all
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+ else {
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * respond all, ignore VORBIS_COMMENT
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore(VORBIS_COMMENT)... ");
+ if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ if(!is_ogg) /* encoder removes seektable for ogg */
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * respond all, ignore APPLICATION
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore(APPLICATION)... ");
+ if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+ else {
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * respond all, ignore APPLICATION id of app#1
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore_application(of app block #1)... ");
+ if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+ else {
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * respond all, ignore APPLICATION id of app#1 & app#2
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore_application(of app block #1)... ");
+ if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore_application(of app block #2)... ");
+ if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes seektable */
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+ else {
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all, respond VORBIS_COMMENT
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond(VORBIS_COMMENT)... ");
+ if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all, respond APPLICATION
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond(APPLICATION)... ");
+ if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all, respond APPLICATION id of app#1
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond_application(of app block #1)... ");
+ if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all, respond APPLICATION id of app#1 & app#2
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond_application(of app block #1)... ");
+ if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond_application(of app block #2)... ");
+ if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * respond all, ignore APPLICATION, respond APPLICATION id of app#1
+ */
+
+ printf("testing set_metadata_respond_all()... ");
+ if(!decoder->set_metadata_respond_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore(APPLICATION)... ");
+ if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond_application(of app block #1)... ");
+ if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping. Also removes the seektable */
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+ else {
+ expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+ expected_metadata_sequence_[num_expected_++] = &padding_;
+ expected_metadata_sequence_[num_expected_++] = &seektable_;
+ expected_metadata_sequence_[num_expected_++] = &application1_;
+ expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+ expected_metadata_sequence_[num_expected_++] = &cuesheet_;
+ expected_metadata_sequence_[num_expected_++] = &picture_;
+ expected_metadata_sequence_[num_expected_++] = &unknown_;
+ }
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ /*
+ * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
+ */
+
+ printf("testing set_metadata_ignore_all()... ");
+ if(!decoder->set_metadata_ignore_all()) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_respond(APPLICATION)... ");
+ if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing set_metadata_ignore_application(of app block #1)... ");
+ if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {
+ printf("FAILED, returned false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ num_expected_ = 0;
+ expected_metadata_sequence_[num_expected_++] = &application2_;
+
+ if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
+ return false;
+
+ if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
+ ::fclose(dynamic_cast<StreamDecoder*>(decoder)->file_);
+
+ printf("freeing decoder instance... ");
+ delete decoder;
+ printf("OK\n");
+
+ printf("\nPASSED!\n");
+
+ return true;
+}
+
+bool test_decoders()
+{
+ FLAC__bool is_ogg = false;
+
+ while(1) {
+ init_metadata_blocks_();
+
+ if(!generate_file_(is_ogg))
+ return false;
+
+ if(!test_stream_decoder(LAYER_STREAM, is_ogg))
+ return false;
+
+ if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
+ return false;
+
+ if(!test_stream_decoder(LAYER_FILE, is_ogg))
+ return false;
+
+ if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
+ return false;
+
+ (void) grabbag__file_remove_file(flacfilename(is_ogg));
+
+ free_metadata_blocks_();
+
+ if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
+ break;
+ is_ogg = true;
+ }
+
+ return true;
+}
diff --git a/src/test_libFLAC++/decoders.h b/src/test_libFLAC++/decoders.h
new file mode 100644
index 0000000..4bbce13
--- /dev/null
+++ b/src/test_libFLAC++/decoders.h
@@ -0,0 +1,25 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef FLAC__TEST_LIBFLACPP_DECODERS_H
+#define FLAC__TEST_LIBFLACPP_DECODERS_H
+
+bool test_decoders();
+
+#endif
diff --git a/src/test_libFLAC++/encoders.cpp b/src/test_libFLAC++/encoders.cpp
new file mode 100644
index 0000000..0e356af
--- /dev/null
+++ b/src/test_libFLAC++/encoders.cpp
@@ -0,0 +1,576 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "encoders.h"
+#include "FLAC/assert.h"
+#include "FLAC++/encoder.h"
+#include "share/grabbag.h"
+extern "C" {
+#include "test_libs_common/file_utils_flac.h"
+#include "test_libs_common/metadata_utils.h"
+}
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "share/compat.h"
+
+#ifdef _MSC_VER
+// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
+#pragma warning ( disable : 4800 )
+#endif
+
+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_, picture_, unknown_;
+static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
+static const uint32_t num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
+
+static const char *flacfilename(bool is_ogg)
+{
+ return is_ogg? "metadata.oga" : "metadata.flac";
+}
+
+static bool die_(const char *msg)
+{
+ printf("ERROR: %s\n", msg);
+ return false;
+}
+
+static bool die_s_(const char *msg, const FLAC::Encoder::Stream *encoder)
+{
+ FLAC::Encoder::Stream::State state = encoder->get_state();
+
+ if(msg)
+ printf("FAILED, %s", msg);
+ else
+ printf("FAILED");
+
+ printf(", state = %u (%s)\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring());
+ if(state == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
+ FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
+ printf(" verify decoder state = %u (%s)\n", (uint32_t)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
+ }
+
+ return false;
+}
+
+static void init_metadata_blocks_()
+{
+ mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
+}
+
+static void free_metadata_blocks_()
+{
+ mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
+}
+
+class StreamEncoder : public FLAC::Encoder::Stream {
+public:
+ Layer layer_;
+ FILE *file_;
+
+ StreamEncoder(Layer layer): FLAC::Encoder::Stream(), layer_(layer), file_(0) { }
+ ~StreamEncoder() { }
+
+ // from FLAC::Encoder::Stream
+ ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
+ ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame);
+ ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
+ ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
+ void metadata_callback(const ::FLAC__StreamMetadata *metadata);
+private:
+ StreamEncoder(const StreamEncoder&);
+ StreamEncoder&operator=(const StreamEncoder&);
+};
+
+::FLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], size_t *bytes)
+{
+ if(*bytes > 0) {
+ *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file_);
+ if(ferror(file_))
+ return ::FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
+ else if(*bytes == 0)
+ return ::FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
+ else
+ return ::FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
+ }
+ else
+ return ::FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
+}
+
+::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame)
+{
+ (void)samples, (void)current_frame;
+
+ if(fwrite(buffer, 1, bytes, file_) != bytes)
+ return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
+ else
+ return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+::FLAC__StreamEncoderSeekStatus StreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset)
+{
+ if(layer_==LAYER_STREAM)
+ return ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
+ else if(fseeko(file_, (FLAC__off_t)absolute_byte_offset, SEEK_SET) < 0)
+ return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
+ else
+ return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
+}
+
+::FLAC__StreamEncoderTellStatus StreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
+{
+ FLAC__off_t pos;
+ if(layer_==LAYER_STREAM)
+ return ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
+ else if((pos = ftello(file_)) < 0)
+ return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
+ else {
+ *absolute_byte_offset = (FLAC__uint64)pos;
+ return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
+ }
+}
+
+void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
+{
+ (void)metadata;
+}
+
+class FileEncoder : public FLAC::Encoder::File {
+public:
+ Layer layer_;
+
+ FileEncoder(Layer layer): FLAC::Encoder::File(), layer_(layer) { }
+ ~FileEncoder() { }
+
+ // from FLAC::Encoder::File
+ void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate);
+};
+
+void FileEncoder::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate)
+{
+ (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
+}
+
+static FLAC::Encoder::Stream *new_by_layer(Layer layer)
+{
+ if(layer < LAYER_FILE)
+ return new StreamEncoder(layer);
+ else
+ return new FileEncoder(layer);
+}
+
+static bool test_stream_encoder(Layer layer, bool is_ogg)
+{
+ FLAC::Encoder::Stream *encoder;
+ ::FLAC__StreamEncoderInitStatus init_status;
+ FILE *file = 0;
+ FLAC__int32 samples[1024];
+ FLAC__int32 *samples_array[1] = { samples };
+ uint32_t i;
+
+ printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC");
+
+ printf("allocating encoder instance... ");
+ encoder = new_by_layer(layer);
+ if(0 == encoder) {
+ printf("FAILED, new returned NULL\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing is_valid()... ");
+ if(!encoder->is_valid()) {
+ printf("FAILED, returned false\n");
+ delete encoder;
+ return false;
+ }
+ printf("OK\n");
+
+ if(is_ogg) {
+ printf("testing set_ogg_serial_number()... ");
+ if(!encoder->set_ogg_serial_number(file_utils__ogg_serial_number))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+ }
+
+ printf("testing set_verify()... ");
+ if(!encoder->set_verify(true))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_streamable_subset()... ");
+ if(!encoder->set_streamable_subset(true))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_channels()... ");
+ if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_bits_per_sample()... ");
+ if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_sample_rate()... ");
+ if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_compression_level()... ");
+ if(!encoder->set_compression_level((uint32_t)(-1)))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_blocksize()... ");
+ if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_do_mid_side_stereo()... ");
+ if(!encoder->set_do_mid_side_stereo(false))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_loose_mid_side_stereo()... ");
+ if(!encoder->set_loose_mid_side_stereo(false))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_max_lpc_order()... ");
+ if(!encoder->set_max_lpc_order(0))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_qlp_coeff_precision()... ");
+ if(!encoder->set_qlp_coeff_precision(0))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_do_qlp_coeff_prec_search()... ");
+ if(!encoder->set_do_qlp_coeff_prec_search(false))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_do_escape_coding()... ");
+ if(!encoder->set_do_escape_coding(false))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_do_exhaustive_model_search()... ");
+ if(!encoder->set_do_exhaustive_model_search(false))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_min_residual_partition_order()... ");
+ if(!encoder->set_min_residual_partition_order(0))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_max_residual_partition_order()... ");
+ if(!encoder->set_max_residual_partition_order(0))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_rice_parameter_search_dist()... ");
+ if(!encoder->set_rice_parameter_search_dist(0))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_total_samples_estimate()... ");
+ if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_metadata()... ");
+ if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing set_limit_min_bitrate()... ");
+ if(!encoder->set_limit_min_bitrate(true))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ if(layer < LAYER_FILENAME) {
+ printf("opening file for FLAC output... ");
+ file = ::flac_fopen(flacfilename(is_ogg), "w+b");
+ if(0 == file) {
+ printf("ERROR (%s)\n", strerror(errno));
+ return false;
+ }
+ printf("OK\n");
+ if(layer < LAYER_FILE)
+ dynamic_cast<StreamEncoder*>(encoder)->file_ = file;
+ }
+
+ switch(layer) {
+ case LAYER_STREAM:
+ case LAYER_SEEKABLE_STREAM:
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg? encoder->init_ogg() : encoder->init();
+ break;
+ case LAYER_FILE:
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(file) :
+ dynamic_cast<FLAC::Encoder::File*>(encoder)->init(file);
+ break;
+ case LAYER_FILENAME:
+ printf("testing init%s()... ", is_ogg? "_ogg":"");
+ init_status = is_ogg?
+ dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(flacfilename(is_ogg)) :
+ dynamic_cast<FLAC::Encoder::File*>(encoder)->init(flacfilename(is_ogg));
+ break;
+ default:
+ die_("internal error 001");
+ return false;
+ }
+ if(init_status != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
+ return die_s_(0, encoder);
+ printf("OK\n");
+
+ printf("testing get_state()... ");
+ FLAC::Encoder::Stream::State state = encoder->get_state();
+ printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring());
+
+ printf("testing get_verify_decoder_state()... ");
+ FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
+ printf("returned state = %u (%s)... OK\n", (uint32_t)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
+
+ {
+ FLAC__uint64 absolute_sample;
+ uint32_t frame_number;
+ uint32_t channel;
+ uint32_t sample;
+ FLAC__int32 expected;
+ FLAC__int32 got;
+
+ printf("testing get_verify_decoder_error_stats()... ");
+ encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
+ printf("OK\n");
+ }
+
+ printf("testing get_verify()... ");
+ if(encoder->get_verify() != true) {
+ printf("FAILED, expected true, got false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_streamable_subset()... ");
+ if(encoder->get_streamable_subset() != true) {
+ printf("FAILED, expected true, got false\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_do_mid_side_stereo()... ");
+ if(encoder->get_do_mid_side_stereo() != false) {
+ printf("FAILED, expected false, got true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_loose_mid_side_stereo()... ");
+ if(encoder->get_loose_mid_side_stereo() != false) {
+ printf("FAILED, expected false, got true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_channels()... ");
+ if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
+ printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_bits_per_sample()... ");
+ if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
+ printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_sample_rate()... ");
+ if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
+ printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_blocksize()... ");
+ if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
+ printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_max_lpc_order()... ");
+ if(encoder->get_max_lpc_order() != 0) {
+ printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_lpc_order());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_qlp_coeff_precision()... ");
+ (void)encoder->get_qlp_coeff_precision();
+ /* we asked the encoder to auto select this so we accept anything */
+ printf("OK\n");
+
+ printf("testing get_do_qlp_coeff_prec_search()... ");
+ if(encoder->get_do_qlp_coeff_prec_search() != false) {
+ printf("FAILED, expected false, got true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_do_escape_coding()... ");
+ if(encoder->get_do_escape_coding() != false) {
+ printf("FAILED, expected false, got true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_do_exhaustive_model_search()... ");
+ if(encoder->get_do_exhaustive_model_search() != false) {
+ printf("FAILED, expected false, got true\n");
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_min_residual_partition_order()... ");
+ if(encoder->get_min_residual_partition_order() != 0) {
+ printf("FAILED, expected %d, got %u\n", 0, encoder->get_min_residual_partition_order());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_max_residual_partition_order()... ");
+ if(encoder->get_max_residual_partition_order() != 0) {
+ printf("FAILED, expected %d, got %u\n", 0, encoder->get_max_residual_partition_order());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_rice_parameter_search_dist()... ");
+ if(encoder->get_rice_parameter_search_dist() != 0) {
+ printf("FAILED, expected %d, got %u\n", 0, encoder->get_rice_parameter_search_dist());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_total_samples_estimate()... ");
+ if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
+ printf("FAILED, expected %" PRIu64 ", got %" PRIu64 "\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing get_limit_min_bitrate()... ");
+ if(encoder->get_limit_min_bitrate() != true) {
+ printf("FAILED, expected true, got false\n");
+ 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 process()... ");
+ if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing process_interleaved()... ");
+ if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
+ return die_s_("returned false", encoder);
+ printf("OK\n");
+
+ printf("testing finish()... ");
+ if(!encoder->finish()) {
+ state = encoder->get_state();
+ printf("FAILED, returned false, state = %u (%s)\n", (uint32_t)((::FLAC__StreamEncoderState)state), state.as_cstring());
+ return false;
+ }
+ printf("OK\n");
+
+ if(layer < LAYER_FILE)
+ ::fclose(dynamic_cast<StreamEncoder*>(encoder)->file_);
+
+ printf("freeing encoder instance... ");
+ delete encoder;
+ printf("OK\n");
+
+ printf("\nPASSED!\n");
+
+ return true;
+}
+
+bool test_encoders()
+{
+ FLAC__bool is_ogg = false;
+
+ while(1) {
+ init_metadata_blocks_();
+
+ if(!test_stream_encoder(LAYER_STREAM, is_ogg))
+ return false;
+
+ if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg))
+ return false;
+
+ if(!test_stream_encoder(LAYER_FILE, is_ogg))
+ return false;
+
+ if(!test_stream_encoder(LAYER_FILENAME, is_ogg))
+ return false;
+
+ (void) grabbag__file_remove_file(flacfilename(is_ogg));
+
+ free_metadata_blocks_();
+
+ if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
+ break;
+ is_ogg = true;
+ }
+
+ return true;
+}
diff --git a/src/test_libFLAC++/encoders.h b/src/test_libFLAC++/encoders.h
new file mode 100644
index 0000000..9da415c
--- /dev/null
+++ b/src/test_libFLAC++/encoders.h
@@ -0,0 +1,25 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef FLAC__TEST_LIBFLACPP_ENCODERS_H
+#define FLAC__TEST_LIBFLACPP_ENCODERS_H
+
+bool test_encoders();
+
+#endif
diff --git a/src/test_libFLAC++/main.cpp b/src/test_libFLAC++/main.cpp
new file mode 100644
index 0000000..7183def
--- /dev/null
+++ b/src/test_libFLAC++/main.cpp
@@ -0,0 +1,42 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "decoders.h"
+#include "encoders.h"
+#include "metadata.h"
+
+int main(int argc, char *argv[])
+{
+ (void)argc, (void)argv;
+
+ if(!test_encoders())
+ return 1;
+
+ if(!test_decoders())
+ return 1;
+
+ if(!test_metadata())
+ return 1;
+
+ return 0;
+}
diff --git a/src/test_libFLAC++/metadata.cpp b/src/test_libFLAC++/metadata.cpp
new file mode 100644
index 0000000..a31031b
--- /dev/null
+++ b/src/test_libFLAC++/metadata.cpp
@@ -0,0 +1,41 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "metadata.h"
+#include <stdio.h>
+
+extern bool test_metadata_object();
+extern bool test_metadata_file_manipulation();
+
+bool test_metadata()
+{
+ if(!test_metadata_object())
+ return false;
+
+ if(!test_metadata_file_manipulation())
+ return false;
+
+ printf("\nPASSED!\n");
+
+ return true;
+}
diff --git a/src/test_libFLAC++/metadata.h b/src/test_libFLAC++/metadata.h
new file mode 100644
index 0000000..8c45bc0
--- /dev/null
+++ b/src/test_libFLAC++/metadata.h
@@ -0,0 +1,25 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef FLAC__TEST_LIBFLACPP_METADATA_H
+#define FLAC__TEST_LIBFLACPP_METADATA_H
+
+bool test_metadata();
+
+#endif
diff --git a/src/test_libFLAC++/metadata_manip.cpp b/src/test_libFLAC++/metadata_manip.cpp
new file mode 100644
index 0000000..5d395db
--- /dev/null
+++ b/src/test_libFLAC++/metadata_manip.cpp
@@ -0,0 +1,2241 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h> /* for malloc() */
+#include <string.h> /* for memcpy()/memset() */
+#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
+#ifdef _MSC_VER
+#include <sys/utime.h>
+#endif
+#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
+#include <unistd.h> /* for chown(), unlink() */
+#endif
+#include <sys/stat.h> /* for stat(), maybe chmod() */
+#include "FLAC/assert.h"
+#include "FLAC++/decoder.h"
+#include "FLAC++/metadata.h"
+#include "share/grabbag.h"
+#include "share/compat.h"
+#include "share/macros.h"
+#include "share/safe_str.h"
+extern "C" {
+#include "test_libs_common/file_utils_flac.h"
+}
+
+/******************************************************************************
+ The general strategy of these tests (for interface levels 1 and 2) is
+ 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::Decoder::File 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.
+******************************************************************************/
+
+class OurFileDecoder: public FLAC::Decoder::File {
+public:
+ inline OurFileDecoder(bool ignore_metadata): ignore_metadata_(ignore_metadata), error_occurred_(false) { }
+
+ bool ignore_metadata_;
+ bool error_occurred_;
+protected:
+ ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
+ void metadata_callback(const ::FLAC__StreamMetadata *metadata);
+ void error_callback(::FLAC__StreamDecoderErrorStatus status);
+};
+
+struct OurMetadata {
+ FLAC::Metadata::Prototype *blocks[64];
+ uint32_t num_blocks;
+};
+
+/* our copy of the metadata in flacfilename() */
+static OurMetadata our_metadata_;
+
+/* the current block number that corresponds to the position of the iterator we are testing */
+static uint32_t mc_our_block_number_ = 0;
+
+static const char *flacfilename(bool is_ogg)
+{
+ return is_ogg? "metadata.oga" : "metadata.flac";
+}
+
+static bool die_(const char *msg)
+{
+ printf("ERROR: %s\n", msg);
+ return false;
+}
+
+static bool die_c_(const char *msg, FLAC::Metadata::Chain::Status status)
+{
+ printf("ERROR: %s\n", msg);
+ printf(" status=%u (%s)\n", (uint32_t)((::FLAC__Metadata_ChainStatus)status), status.as_cstring());
+ return false;
+}
+
+static bool die_ss_(const char *msg, FLAC::Metadata::SimpleIterator &iterator)
+{
+ const FLAC::Metadata::SimpleIterator::Status status = iterator.status();
+ printf("ERROR: %s\n", msg);
+ printf(" status=%u (%s)\n", (uint32_t)((::FLAC__Metadata_SimpleIteratorStatus)status), status.as_cstring());
+ return false;
+}
+
+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", (uint32_t)size);
+ exit(1);
+ }
+ return x;
+}
+
+static char *strdup_or_die_(const char *s)
+{
+ char *x = strdup(s);
+ if(0 == x) {
+ fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s);
+ exit(1);
+ }
+ return x;
+}
+
+/* functions for working with our metadata copy */
+
+static bool replace_in_our_metadata_(FLAC::Metadata::Prototype *block, uint32_t position, bool copy)
+{
+ uint32_t i;
+ FLAC::Metadata::Prototype *obj = block;
+ FLAC__ASSERT(position < our_metadata_.num_blocks);
+ if(copy) {
+ if(0 == (obj = FLAC::Metadata::clone(block)))
+ return die_("during FLAC::Metadata::clone()");
+ }
+ delete our_metadata_.blocks[position];
+ our_metadata_.blocks[position] = obj;
+
+ /* set the is_last flags */
+ for(i = 0; i < our_metadata_.num_blocks - 1; i++)
+ our_metadata_.blocks[i]->set_is_last(false);
+ our_metadata_.blocks[i]->set_is_last(true);
+
+ return true;
+}
+
+static bool insert_to_our_metadata_(FLAC::Metadata::Prototype *block, uint32_t position, bool copy)
+{
+ uint32_t i;
+ FLAC::Metadata::Prototype *obj = block;
+ if(copy) {
+ if(0 == (obj = FLAC::Metadata::clone(block)))
+ return die_("during FLAC::Metadata::clone()");
+ }
+ if(position > our_metadata_.num_blocks) {
+ position = our_metadata_.num_blocks;
+ }
+ else {
+ for(i = our_metadata_.num_blocks; i > position; i--)
+ our_metadata_.blocks[i] = our_metadata_.blocks[i-1];
+ }
+ our_metadata_.blocks[position] = obj;
+ our_metadata_.num_blocks++;
+
+ /* set the is_last flags */
+ for(i = 0; i < our_metadata_.num_blocks - 1; i++)
+ our_metadata_.blocks[i]->set_is_last(false);
+ our_metadata_.blocks[i]->set_is_last(true);
+
+ return true;
+}
+
+static void delete_from_our_metadata_(uint32_t position)
+{
+ uint32_t i;
+ FLAC__ASSERT(position < our_metadata_.num_blocks);
+ delete our_metadata_.blocks[position];
+ for(i = position; i < our_metadata_.num_blocks - 1; i++)
+ our_metadata_.blocks[i] = our_metadata_.blocks[i+1];
+ our_metadata_.num_blocks--;
+
+ /* set the is_last flags */
+ if(our_metadata_.num_blocks > 0) {
+ for(i = 0; i < our_metadata_.num_blocks - 1; i++)
+ our_metadata_.blocks[i]->set_is_last(false);
+ our_metadata_.blocks[i]->set_is_last(true);
+ }
+}
+
+void add_to_padding_length_(uint32_t indx, int delta)
+{
+ FLAC::Metadata::Padding *padding = dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[indx]);
+ FLAC__ASSERT(0 != padding);
+ padding->set_length((uint32_t)((int)padding->get_length() + delta));
+}
+
+/*
+ * This wad of functions supports filename- and callback-based chain reading/writing.
+ * Everything up to set_file_stats_() is copied from libFLAC/metadata_iterators.c
+ */
+bool open_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+{
+ static const char *tempfile_suffix = ".metadata_edit";
+ size_t destlen = strlen(filename) + strlen(tempfile_suffix) + 1;
+
+ *tempfilename = (char*)malloc(destlen);
+ if (*tempfilename == 0)
+ return false;
+ flac_snprintf(*tempfilename, destlen, "%s%s", filename, tempfile_suffix);
+
+ *tempfile = flac_fopen(*tempfilename, "wb");
+ if (*tempfile == 0)
+ return false;
+
+ return true;
+}
+
+void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
+{
+ if (*tempfile != 0) {
+ (void)fclose(*tempfile);
+ *tempfile = 0;
+ }
+
+ if (*tempfilename != 0) {
+ (void)flac_unlink(*tempfilename);
+ free(*tempfilename);
+ *tempfilename = 0;
+ }
+}
+
+bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename)
+{
+ FLAC__ASSERT(0 != filename);
+ FLAC__ASSERT(0 != tempfile);
+ FLAC__ASSERT(0 != tempfilename);
+ FLAC__ASSERT(0 != *tempfilename);
+
+ if(0 != *tempfile) {
+ (void)fclose(*tempfile);
+ *tempfile = 0;
+ }
+
+#if defined _MSC_VER || defined __MINGW32__ || defined __EMX__
+ /* on some flavors of windows, flac_rename() will fail if the destination already exists */
+ if(flac_unlink(filename) < 0) {
+ cleanup_tempfile_(tempfile, tempfilename);
+ return false;
+ }
+#endif
+
+ if(0 != flac_rename(*tempfilename, filename)) {
+ cleanup_tempfile_(tempfile, tempfilename);
+ return false;
+ }
+
+ cleanup_tempfile_(tempfile, tempfilename);
+
+ return true;
+}
+
+bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
+{
+ FLAC__ASSERT(0 != filename);
+ FLAC__ASSERT(0 != stats);
+ return (0 == flac_stat(filename, stats));
+}
+
+void set_file_stats_(const char *filename, struct flac_stat_s *stats)
+{
+ FLAC__ASSERT(0 != filename);
+ FLAC__ASSERT(0 != stats);
+
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) && !defined(_WIN32)
+ struct timespec srctime[2] = {};
+ srctime[0].tv_sec = stats->st_atime;
+ srctime[1].tv_sec = stats->st_mtime;
+#else
+ struct utimbuf srctime;
+ srctime.actime = stats->st_atime;
+ srctime.modtime = stats->st_mtime;
+#endif
+ (void)flac_chmod(filename, stats->st_mode);
+ (void)flac_utime(filename, &srctime);
+#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
+ FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1)));
+ FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid));
+#endif
+}
+
+#ifdef FLAC__VALGRIND_TESTING
+static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, ::FLAC__IOHandle handle)
+{
+ FILE *stream = (FILE*)handle;
+ size_t ret = fwrite(ptr, size, nmemb, stream);
+ if(!ferror(stream))
+ fflush(stream);
+ return ret;
+}
+#endif
+
+static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
+{
+ FLAC__off_t o = (FLAC__off_t)offset;
+ FLAC__ASSERT(offset == o);
+ return fseeko((FILE*)handle, o, whence);
+}
+
+static FLAC__int64 chain_tell_cb_(::FLAC__IOHandle handle)
+{
+ return ftello((FILE*)handle);
+}
+
+static int chain_eof_cb_(::FLAC__IOHandle handle)
+{
+ return feof((FILE*)handle);
+}
+
+static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool preserve_file_stats, bool filename_based, const char *filename)
+{
+ if(filename_based)
+ return chain.write(use_padding, preserve_file_stats);
+ else {
+ ::FLAC__IOCallbacks callbacks;
+
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.read = (::FLAC__IOCallback_Read)fread;
+#ifdef FLAC__VALGRIND_TESTING
+ callbacks.write = chain_write_cb_;
+#else
+ callbacks.write = (::FLAC__IOCallback_Write)fwrite;
+#endif
+ callbacks.seek = chain_seek_cb_;
+ callbacks.eof = chain_eof_cb_;
+
+ if(chain.check_if_tempfile_needed(use_padding)) {
+ struct flac_stat_s stats;
+ FILE *file, *tempfile;
+ char *tempfilename;
+ if(preserve_file_stats) {
+ if(!get_file_stats_(filename, &stats))
+ return false;
+ }
+ if(0 == (file = flac_fopen(filename, "rb")))
+ return false; /*@@@@ chain status still says OK though */
+ if(!open_tempfile_(filename, &tempfile, &tempfilename)) {
+ fclose(file);
+ cleanup_tempfile_(&tempfile, &tempfilename);
+ return false; /*@@@@ chain status still says OK though */
+ }
+ if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks, (::FLAC__IOHandle)tempfile, callbacks)) {
+ fclose(file);
+ fclose(tempfile);
+ return false;
+ }
+ fclose(file);
+ fclose(tempfile);
+ file = tempfile = 0;
+ if(!transport_tempfile_(filename, &tempfile, &tempfilename))
+ return false;
+ if(preserve_file_stats)
+ set_file_stats_(filename, &stats);
+ }
+ else {
+ FILE *file = flac_fopen(filename, "r+b");
+ if(0 == file)
+ return false; /*@@@@ chain status still says OK though */
+ if(!chain.write(use_padding, (::FLAC__IOHandle)file, callbacks)) {
+ fclose(file);
+ return false;
+ }
+ fclose(file);
+ }
+ }
+
+ return true;
+}
+
+static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg)
+{
+ if(filename_based)
+ return chain.read(filename, is_ogg);
+ else {
+ ::FLAC__IOCallbacks callbacks;
+
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.read = (::FLAC__IOCallback_Read)fread;
+ callbacks.seek = chain_seek_cb_;
+ callbacks.tell = chain_tell_cb_;
+
+ {
+ bool ret;
+ FILE *file = flac_fopen(filename, "rb");
+ if(0 == file)
+ return false; /*@@@@ chain status still says OK though */
+ ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
+ fclose(file);
+ return ret;
+ }
+ }
+}
+
+/* function for comparing our metadata to a FLAC::Metadata::Chain */
+
+static bool compare_chain_(FLAC::Metadata::Chain &chain, uint32_t current_position, FLAC::Metadata::Prototype *current_block)
+{
+ uint32_t i;
+ FLAC::Metadata::Iterator iterator;
+ bool next_ok = true;
+
+ printf("\tcomparing chain... ");
+ fflush(stdout);
+
+ if(!iterator.is_valid())
+ return die_("allocating memory for iterator");
+
+ iterator.init(chain);
+
+ i = 0;
+ do {
+ FLAC::Metadata::Prototype *block;
+
+ printf("%u... ", i);
+ fflush(stdout);
+
+ if(0 == (block = iterator.get_block()))
+ return die_("getting block from iterator");
+
+ if(*block != *our_metadata_.blocks[i])
+ return die_("metadata block mismatch");
+
+ delete block;
+ i++;
+ next_ok = iterator.next();
+ } while(i < our_metadata_.num_blocks && next_ok);
+
+ if(next_ok)
+ return die_("chain has more blocks than expected");
+
+ if(i < our_metadata_.num_blocks)
+ return die_("short block count in chain");
+
+ if(0 != current_block) {
+ printf("CURRENT_POSITION... ");
+ fflush(stdout);
+
+ if(*current_block != *our_metadata_.blocks[current_position])
+ return die_("metadata block mismatch");
+ }
+
+ printf("PASSED\n");
+
+ return true;
+}
+
+::FLAC__StreamDecoderWriteStatus OurFileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
+{
+ (void)buffer;
+
+ if(
+ (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
+ (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
+ ) {
+ printf("content... ");
+ fflush(stdout);
+ }
+
+ return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
+void OurFileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
+{
+ /* don't bother checking if we've already hit an error */
+ if(error_occurred_)
+ return;
+
+ printf("%u... ", mc_our_block_number_);
+ fflush(stdout);
+
+ if(!ignore_metadata_) {
+ if(mc_our_block_number_ >= our_metadata_.num_blocks) {
+ (void)die_("got more metadata blocks than expected");
+ error_occurred_ = true;
+ }
+ else {
+ if(*our_metadata_.blocks[mc_our_block_number_] != metadata) {
+ (void)die_("metadata block mismatch");
+ error_occurred_ = true;
+ }
+ }
+ }
+
+ mc_our_block_number_++;
+}
+
+void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
+{
+ error_occurred_ = true;
+ printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (uint32_t)status);
+}
+
+static bool generate_file_(bool include_extras, bool is_ogg)
+{
+ ::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding;
+ ::FLAC__StreamMetadata *metadata[4];
+ uint32_t i = 0, n = 0;
+
+ printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : "");
+
+ while(our_metadata_.num_blocks > 0)
+ delete_from_our_metadata_(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);
+
+ {
+ const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING);
+ vorbiscomment.is_last = false;
+ vorbiscomment.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
+ vorbiscomment.length = (4 + vendor_string_length) + 4;
+ 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 = 0;
+ vorbiscomment.data.vorbis_comment.comments = 0;
+ }
+
+ {
+ if (0 == (cuesheet = ::FLAC__metadata_object_new(::FLAC__METADATA_TYPE_CUESHEET)))
+ return die_("priming our metadata");
+ cuesheet->is_last = false;
+ safe_strncpy(cuesheet->data.cue_sheet.media_catalog_number, "bogo-MCN", sizeof(cuesheet->data.cue_sheet.media_catalog_number));
+ cuesheet->data.cue_sheet.lead_in = 123;
+ cuesheet->data.cue_sheet.is_cd = false;
+ if (!FLAC__metadata_object_cuesheet_insert_blank_track(cuesheet, 0))
+ return die_("priming our metadata");
+ cuesheet->data.cue_sheet.tracks[0].number = 1;
+ if (!FLAC__metadata_object_cuesheet_track_insert_blank_index(cuesheet, 0, 0))
+ return die_("priming our metadata");
+ }
+
+ {
+ picture.is_last = false;
+ picture.type = ::FLAC__METADATA_TYPE_PICTURE;
+ picture.length =
+ (
+ FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
+ FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */
+ FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */
+ FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
+ ) / 8
+ ;
+ picture.data.picture.type = ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
+ picture.data.picture.mime_type = strdup_or_die_("image/jpeg");
+ picture.length += strlen(picture.data.picture.mime_type);
+ picture.data.picture.description = (FLAC__byte*)strdup_or_die_("desc");
+ picture.length += strlen((const char *)picture.data.picture.description);
+ picture.data.picture.width = 300;
+ picture.data.picture.height = 300;
+ picture.data.picture.depth = 24;
+ picture.data.picture.colors = 0;
+ picture.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
+ picture.data.picture.data_length = strlen((const char *)picture.data.picture.data);
+ picture.length += picture.data.picture.data_length;
+ }
+
+ padding.is_last = true;
+ padding.type = ::FLAC__METADATA_TYPE_PADDING;
+ padding.length = 1234;
+
+ metadata[n++] = &vorbiscomment;
+ if(include_extras) {
+ metadata[n++] = cuesheet;
+ metadata[n++] = &picture;
+ }
+ metadata[n++] = &padding;
+
+ FLAC::Metadata::StreamInfo s(&streaminfo);
+ FLAC::Metadata::VorbisComment v(&vorbiscomment);
+ FLAC::Metadata::CueSheet c(cuesheet, /*copy=*/false);
+ FLAC::Metadata::Picture pi(&picture);
+ FLAC::Metadata::Padding p(&padding);
+ if(
+ !insert_to_our_metadata_(&s, i++, /*copy=*/true) ||
+ !insert_to_our_metadata_(&v, i++, /*copy=*/true) ||
+ (include_extras && !insert_to_our_metadata_(&c, i++, /*copy=*/true)) ||
+ (include_extras && !insert_to_our_metadata_(&pi, i++, /*copy=*/true)) ||
+ !insert_to_our_metadata_(&p, i++, /*copy=*/true)
+ )
+ return die_("priming our metadata");
+
+ if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n))
+ return die_("creating the encoded file");
+
+ free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
+ free(picture.data.picture.mime_type);
+ free(picture.data.picture.description);
+ free(picture.data.picture.data);
+
+ return true;
+}
+
+static bool test_file_(bool is_ogg, bool ignore_metadata)
+{
+ const char *filename = flacfilename(is_ogg);
+ OurFileDecoder decoder(ignore_metadata);
+
+ mc_our_block_number_ = 0;
+ decoder.error_occurred_ = false;
+
+ printf("\ttesting '%s'... ", filename);
+ fflush(stdout);
+
+ if(!decoder.is_valid())
+ return die_("couldn't allocate decoder instance");
+
+ decoder.set_md5_checking(true);
+ decoder.set_metadata_respond_all();
+ if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
+ (void)decoder.finish();
+ return die_("initializing decoder\n");
+ }
+ if(!decoder.process_until_end_of_stream()) {
+ (void)decoder.finish();
+ return die_("decoding file\n");
+ }
+
+ (void)decoder.finish();
+
+ if(decoder.error_occurred_)
+ return false;
+
+ if(mc_our_block_number_ != our_metadata_.num_blocks)
+ return die_("short metadata block count");
+
+ printf("PASSED\n");
+ return true;
+}
+
+static bool change_stats_(const char *filename, bool read_only)
+{
+ if(!grabbag__file_change_stats(filename, read_only))
+ return die_("during grabbag__file_change_stats()");
+
+ return true;
+}
+
+static bool remove_file_(const char *filename)
+{
+ while(our_metadata_.num_blocks > 0)
+ delete_from_our_metadata_(0);
+
+ if(!grabbag__file_remove_file(filename))
+ return die_("removing file");
+
+ return true;
+}
+
+static bool test_level_0_()
+{
+ FLAC::Metadata::StreamInfo streaminfo;
+
+ printf("\n\n++++++ testing level 0 interface\n");
+
+ if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
+ return false;
+
+ printf("testing FLAC::Metadata::get_streaminfo()... ");
+
+ if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo))
+ return die_("during FLAC::Metadata::get_streaminfo()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(streaminfo.get_channels() != 1)
+ return die_("mismatch in streaminfo.get_channels()");
+ if(streaminfo.get_bits_per_sample() != 8)
+ return die_("mismatch in streaminfo.get_bits_per_sample()");
+ if(streaminfo.get_sample_rate() != 44100)
+ return die_("mismatch in streaminfo.get_sample_rate()");
+ if(streaminfo.get_min_blocksize() != 576)
+ return die_("mismatch in streaminfo.get_min_blocksize()");
+ if(streaminfo.get_max_blocksize() != 576)
+ return die_("mismatch in streaminfo.get_max_blocksize()");
+
+ printf("OK\n");
+
+ {
+ printf("testing FLAC::Metadata::get_tags(VorbisComment *&)... ");
+
+ FLAC::Metadata::VorbisComment *tags = 0;
+
+ if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
+ return die_("during FLAC::Metadata::get_tags()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(tags->get_num_comments() != 0)
+ return die_("mismatch in tags->get_num_comments()");
+
+ printf("OK\n");
+
+ delete tags;
+ }
+
+ {
+ printf("testing FLAC::Metadata::get_tags(VorbisComment &)... ");
+
+ FLAC::Metadata::VorbisComment tags;
+
+ if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
+ return die_("during FLAC::Metadata::get_tags()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(tags.get_num_comments() != 0)
+ return die_("mismatch in tags.get_num_comments()");
+
+ printf("OK\n");
+ }
+
+ {
+ printf("testing FLAC::Metadata::get_cuesheet(CueSheet *&)... ");
+
+ FLAC::Metadata::CueSheet *cuesheet = 0;
+
+ if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
+ return die_("during FLAC::Metadata::get_cuesheet()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(cuesheet->get_lead_in() != 123)
+ return die_("mismatch in cuesheet->get_lead_in()");
+
+ printf("OK\n");
+
+ delete cuesheet;
+ }
+
+ {
+ printf("testing FLAC::Metadata::get_cuesheet(CueSheet &)... ");
+
+ FLAC::Metadata::CueSheet cuesheet;
+
+ if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
+ return die_("during FLAC::Metadata::get_cuesheet()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(cuesheet.get_lead_in() != 123)
+ return die_("mismatch in cuesheet.get_lead_in()");
+
+ printf("OK\n");
+ }
+
+ {
+ printf("testing FLAC::Metadata::get_picture(Picture *&)... ");
+
+ FLAC::Metadata::Picture *picture = 0;
+
+ if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1)))
+ return die_("during FLAC::Metadata::get_picture()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(picture->get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
+ return die_("mismatch in picture->get_type ()");
+
+ printf("OK\n");
+
+ delete picture;
+ }
+
+ {
+ printf("testing FLAC::Metadata::get_picture(Picture &)... ");
+
+ FLAC::Metadata::Picture picture;
+
+ if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(uint32_t)(-1), /*max_height=*/(uint32_t)(-1), /*max_depth=*/(uint32_t)(-1), /*max_colors=*/(uint32_t)(-1)))
+ return die_("during FLAC::Metadata::get_picture()");
+
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(picture.get_type () != ::FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
+ return die_("mismatch in picture->get_type ()");
+
+ printf("OK\n");
+ }
+
+ if(!remove_file_(flacfilename(/*is_ogg=*/false)))
+ return false;
+
+ return true;
+}
+
+static bool test_level_1_()
+{
+ FLAC::Metadata::Prototype *block;
+ FLAC::Metadata::StreamInfo *streaminfo;
+ FLAC::Metadata::Padding *padding;
+ FLAC::Metadata::Application *app;
+ FLAC__byte data[1000];
+ uint32_t our_current_position = 0;
+
+ // initialize 'data' to avoid Valgrind errors
+ memset(data, 0, sizeof(data));
+
+ printf("\n\n++++++ testing level 1 interface\n");
+
+ /************************************************************/
+ {
+ printf("simple iterator on read-only file\n");
+
+ if(!generate_file_(/*include_extras=*/false, /*is_ogg=*/false))
+ return false;
+
+ if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read_only=*/true))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
+ return false;
+
+ FLAC::Metadata::SimpleIterator iterator;
+
+ if(!iterator.is_valid())
+ return die_("iterator.is_valid() returned false");
+
+ if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false))
+ return die_("iterator.init() returned false");
+
+ printf("is writable = %u\n", (uint32_t)iterator.is_writable());
+ if(iterator.is_writable())
+ return die_("iterator claims file is writable when tester thinks it should not be; are you running as root?\n");
+
+ printf("iterate forwards\n");
+
+ if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_STREAMINFO)
+ return die_("expected STREAMINFO type from iterator.get_block_type()");
+ if(0 == (block = iterator.get_block()))
+ return die_("getting block 0");
+ if(block->get_type() != ::FLAC__METADATA_TYPE_STREAMINFO)
+ return die_("expected STREAMINFO type");
+ if(block->get_is_last())
+ return die_("expected is_last to be false");
+ if(block->get_length() != FLAC__STREAM_METADATA_STREAMINFO_LENGTH)
+ return die_("bad STREAMINFO length");
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
+ FLAC__ASSERT(0 != streaminfo);
+ if(streaminfo->get_channels() != 1)
+ return die_("mismatch in channels");
+ if(streaminfo->get_bits_per_sample() != 8)
+ return die_("mismatch in bits_per_sample");
+ if(streaminfo->get_sample_rate() != 44100)
+ return die_("mismatch in sample_rate");
+ if(streaminfo->get_min_blocksize() != 576)
+ return die_("mismatch in min_blocksize");
+ if(streaminfo->get_max_blocksize() != 576)
+ return die_("mismatch in max_blocksize");
+ // we will delete streaminfo a little later when we're really done with it...
+
+ if(!iterator.next())
+ return die_("forward iterator ended early");
+ our_current_position++;
+
+ if(!iterator.next())
+ return die_("forward iterator ended early");
+ our_current_position++;
+
+ if(iterator.get_block_type() != ::FLAC__METADATA_TYPE_PADDING)
+ return die_("expected PADDING type from iterator.get_block_type()");
+ if(0 == (block = iterator.get_block()))
+ return die_("getting block 1");
+ if(block->get_type() != ::FLAC__METADATA_TYPE_PADDING)
+ return die_("expected PADDING type");
+ if(!block->get_is_last())
+ return die_("expected is_last to be true");
+ /* check to see if some basic data matches (c.f. generate_file_()) */
+ if(block->get_length() != 1234)
+ return die_("bad PADDING length");
+ delete block;
+
+ if(iterator.next())
+ return die_("forward iterator returned true but should have returned false");
+
+ printf("iterate backwards\n");
+ if(!iterator.prev())
+ return die_("reverse iterator ended early");
+ if(!iterator.prev())
+ return die_("reverse iterator ended early");
+ if(iterator.prev())
+ return die_("reverse iterator returned true but should have returned false");
+
+ printf("testing iterator.set_block() on read-only file...\n");
+
+ if(!iterator.set_block(streaminfo, false))
+ printf("PASSED. iterator.set_block() returned false like it should\n");
+ else
+ return die_("iterator.set_block() returned true but shouldn't have");
+ delete streaminfo;
+ }
+
+ /************************************************************/
+ {
+ printf("simple iterator on writable file\n");
+
+ if(!change_stats_(flacfilename(/*is_ogg=*/false), /*read-only=*/false))
+ return false;
+
+ printf("creating APPLICATION block\n");
+
+ if(0 == (app = new FLAC::Metadata::Application()))
+ return die_("new FLAC::Metadata::Application()");
+ app->set_id((const uint8_t *)"duh");
+
+ printf("creating PADDING block\n");
+
+ if(0 == (padding = new FLAC::Metadata::Padding())) {
+ delete app;
+ return die_("new FLAC::Metadata::Padding()");
+ }
+ padding->set_length(20);
+
+ FLAC::Metadata::SimpleIterator iterator;
+
+ if(!iterator.is_valid()) {
+ delete app;
+ delete padding;
+ return die_("iterator.is_valid() returned false");
+ }
+
+ if(!iterator.init(flacfilename(/*is_ogg=*/false), /*read_only=*/false, /*preserve_file_stats=*/false)) {
+ delete app;
+ delete padding;
+ return die_("iterator.init() returned false");
+ }
+ our_current_position = 0;
+
+ printf("is writable = %u\n", (uint32_t)iterator.is_writable());
+
+ printf("[S]VP\ttry to write over STREAMINFO block...\n");
+ if(!iterator.set_block(app, false))
+ printf("\titerator.set_block() returned false like it should\n");
+ else {
+ delete app;
+ delete padding;
+ return die_("iterator.set_block() returned true but shouldn't have");
+ }
+
+ if(iterator.status() != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT)
+ return die_("iterator.status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT");
+
+ printf("[S]VP\tnext\n");
+ if(!iterator.next()) {
+ delete app;
+ delete padding;
+ return die_("iterator ended early\n");
+ }
+ our_current_position++;
+
+ printf("S[V]P\tnext\n");
+ if(!iterator.next()) {
+ delete app;
+ delete padding;
+ return die_("iterator ended early\n");
+ }
+ our_current_position++;
+
+ printf("SV[P]\tinsert PADDING after, don't expand into padding\n");
+ padding->set_length(25);
+ if(!iterator.insert_block_after(padding, false))
+ return die_ss_("iterator.insert_block_after(padding, false)", iterator);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return false;
+
+ printf("SVP[P]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SV[P]P\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("S[V]PP\tinsert PADDING after, don't expand into padding\n");
+ padding->set_length(30);
+ if(!iterator.insert_block_after(padding, false))
+ return die_ss_("iterator.insert_block_after(padding, false)", iterator);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[P]PP\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("S[V]PPP\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("[S]VPPP\tdelete (STREAMINFO block), must fail\n");
+ if(iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false) should have returned false", iterator);
+
+ if(iterator.status() != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT)
+ return die_("iterator.status() should have been FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT");
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("[S]VPPP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("S[V]PPP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]PP\tdelete (middle block), replace with padding\n");
+ if(!iterator.delete_block(true))
+ return die_ss_("iterator.delete_block(true)", iterator);
+ our_current_position--;
+
+ printf("S[V]PPP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]PP\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]PP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVP[P]\tdelete (last block), replace with padding\n");
+ if(!iterator.delete_block(true))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ our_current_position--;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[P]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVP[P]\tdelete (last block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[P]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("S[V]P\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("[S]VP\tset STREAMINFO (change sample rate)\n");
+ FLAC__ASSERT(our_current_position == 0);
+ block = iterator.get_block();
+ streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
+ FLAC__ASSERT(0 != streaminfo);
+ streaminfo->set_sample_rate(32000);
+ if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(block, false))
+ return die_ss_("iterator.set_block(block, false)", iterator);
+ delete block;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("[S]VP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("S[V]P\tinsert APPLICATION after, expand into padding of exceeding size\n");
+ app->set_id((const uint8_t *)"euh"); /* twiddle the id so that our comparison doesn't miss transposition */
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return false;
+ add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVA[P]\tset APPLICATION, expand into padding of exceeding size\n");
+ app->set_id((const uint8_t *)"fuh"); /* twiddle the id */
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+ if(!insert_to_our_metadata_(app, our_current_position, /*copy=*/true))
+ return false;
+ add_to_padding_length_(our_current_position+1, -((int)(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) + (int)app->get_length()));
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]P\tset APPLICATION (grow), don't expand into padding\n");
+ app->set_id((const uint8_t *)"guh"); /* twiddle the id */
+ if(!app->set_data(data, sizeof(data), true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app, false))
+ return die_ss_("iterator.set_block(app, false)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]P\tset APPLICATION (shrink), don't fill in with padding\n");
+ app->set_id((const uint8_t *)"huh"); /* twiddle the id */
+ if(!app->set_data(data, 12, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app, false))
+ return die_ss_("iterator.set_block(app, false)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]P\tset APPLICATION (grow), expand into padding of exceeding size\n");
+ app->set_id((const uint8_t *)"iuh"); /* twiddle the id */
+ if(!app->set_data(data, sizeof(data), true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ add_to_padding_length_(our_current_position+1, -((int)sizeof(data) - 12));
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]P\tset APPLICATION (shrink), fill in with padding\n");
+ app->set_id((const uint8_t *)"juh"); /* twiddle the id */
+ if(!app->set_data(data, 23, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/true))
+ return die_("copying object");
+ dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(sizeof(data) - 23 - FLAC__STREAM_METADATA_HEADER_LENGTH);
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]PP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVAA[P]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVAAP[P]\tset PADDING (shrink), don't fill in with padding\n");
+ padding->set_length(5);
+ if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(padding, false))
+ return die_ss_("iterator.set_block(padding, false)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVAAP[P]\tset APPLICATION (grow)\n");
+ app->set_id((const uint8_t *)"kuh"); /* twiddle the id */
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app, false))
+ return die_ss_("iterator.set_block(app, false)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVAAP[A]\tset PADDING (equal)\n");
+ padding->set_length(27);
+ if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(padding, false))
+ return die_ss_("iterator.set_block(padding, false)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVAAP[P]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SVAA[P]P\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVA[A]P\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVA[P]\tinsert PADDING after\n");
+ padding->set_length(5);
+ if(!iterator.insert_block_after(padding, false))
+ return die_ss_("iterator.insert_block_after(padding, false)", iterator);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVAP[P]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SVA[P]P\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is too small\n");
+ if(!app->set_data(data, 32, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PP\tset APPLICATION (grow), try to expand into padding which is 'close' but still too small\n");
+ if(!app->set_data(data, 60, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PP\tset APPLICATION (grow), expand into padding which will leave 0-length pad\n");
+ if(!app->set_data(data, 87, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(0);
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PP\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
+ if(!app->set_data(data, 91, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete_from_our_metadata_(our_current_position+1);
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tset APPLICATION (grow), expand into padding which is exactly consumed\n");
+ if(!app->set_data(data, 100, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete_from_our_metadata_(our_current_position+1);
+ our_metadata_.blocks[our_current_position]->set_is_last(true);
+ if(!iterator.set_block(app, true))
+ return die_ss_("iterator.set_block(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tset PADDING (equal size)\n");
+ padding->set_length(app->get_length());
+ if(!replace_in_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(padding, true))
+ return die_ss_("iterator.set_block(padding, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[P]\tinsert PADDING after\n");
+ if(!iterator.insert_block_after(padding, false))
+ return die_ss_("iterator.insert_block_after(padding, false)", iterator);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVP[P]\tinsert PADDING after\n");
+ padding->set_length(5);
+ if(!iterator.insert_block_after(padding, false))
+ return die_ss_("iterator.insert_block_after(padding, false)", iterator);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return false;
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVPP[P]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SVP[P]P\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("SV[P]PP\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is too small\n");
+ if(!app->set_data(data, 101, true))
+ return die_("setting APPLICATION data");
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]PPP\tinsert APPLICATION after, try to expand into padding which is 'close' but still too small\n");
+ if(!app->set_data(data, 97, true))
+ return die_("setting APPLICATION data");
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PPP\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]PPP\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
+ if(!app->set_data(data, 100, true))
+ return die_("setting APPLICATION data");
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete_from_our_metadata_(our_current_position+1);
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]PP\tinsert APPLICATION after, expand into padding which will leave 0-length pad\n");
+ if(!app->set_data(data, 96, true))
+ return die_("setting APPLICATION data");
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return die_("copying object");
+ dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(0);
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]PP\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]PP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]P\tdelete (middle block), don't replace with padding\n");
+ if(!iterator.delete_block(false))
+ return die_ss_("iterator.delete_block(false)", iterator);
+ delete_from_our_metadata_(our_current_position--);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+
+ printf("S[V]P\tinsert APPLICATION after, expand into padding which is exactly consumed\n");
+ if(!app->set_data(data, 1, true))
+ return die_("setting APPLICATION data");
+ if(!insert_to_our_metadata_(app, ++our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete_from_our_metadata_(our_current_position+1);
+ if(!iterator.insert_block_after(app, true))
+ return die_ss_("iterator.insert_block_after(app, true)", iterator);
+
+ if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/false))
+ return false;
+ }
+
+ delete app;
+ delete padding;
+
+ if(!remove_file_(flacfilename(/*is_ogg=*/false)))
+ return false;
+
+ return true;
+}
+
+static bool test_level_2_(bool filename_based, bool is_ogg)
+{
+ FLAC::Metadata::Prototype *block;
+ FLAC::Metadata::StreamInfo *streaminfo;
+ FLAC::Metadata::Application *app;
+ FLAC::Metadata::Padding *padding;
+ FLAC__byte data[2000];
+ uint32_t our_current_position;
+
+ // initialize 'data' to avoid Valgrind errors
+ memset(data, 0, sizeof(data));
+
+ printf("\n\n++++++ testing level 2 interface (%s-based, %s FLAC)\n", filename_based? "filename":"callback", is_ogg? "Ogg":"native");
+
+ printf("generate read-only file\n");
+
+ if(!generate_file_(/*include_extras=*/false, is_ogg))
+ return false;
+
+ if(!change_stats_(flacfilename(is_ogg), /*read_only=*/true))
+ return false;
+
+ printf("create chain\n");
+ FLAC::Metadata::Chain chain;
+ if(!chain.is_valid())
+ return die_("allocating memory for chain");
+
+ printf("read chain\n");
+
+ if(!read_chain_(chain, flacfilename(is_ogg), filename_based, is_ogg))
+ return die_c_("reading chain", chain.status());
+
+ printf("[S]VP\ttest initial metadata\n");
+
+ if(!compare_chain_(chain, 0, 0))
+ return false;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ if(is_ogg)
+ goto end;
+
+ printf("switch file to read-write\n");
+
+ if(!change_stats_(flacfilename(is_ogg), /*read-only=*/false))
+ return false;
+
+ printf("create iterator\n");
+ {
+ FLAC::Metadata::Iterator iterator;
+ if(!iterator.is_valid())
+ return die_("allocating memory for iterator");
+
+ our_current_position = 0;
+
+ iterator.init(chain);
+
+ if(0 == (block = iterator.get_block()))
+ return die_("getting block from iterator");
+
+ FLAC__ASSERT(block->get_type() == FLAC__METADATA_TYPE_STREAMINFO);
+
+ printf("[S]VP\tmodify STREAMINFO, write\n");
+
+ streaminfo = dynamic_cast<FLAC::Metadata::StreamInfo *>(block);
+ FLAC__ASSERT(0 != streaminfo);
+ streaminfo->set_sample_rate(32000);
+ if(!replace_in_our_metadata_(block, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete block;
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/true, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, true)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("[S]VP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("S[V]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]\treplace PADDING with identical-size APPLICATION\n");
+ if(0 == (block = iterator.get_block()))
+ return die_("getting block from iterator");
+ if(0 == (app = new FLAC::Metadata::Application()))
+ return die_("new FLAC::Metadata::Application()");
+ app->set_id((const uint8_t *)"duh");
+ if(!app->set_data(data, block->get_length()-(FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), true))
+ return die_("setting APPLICATION data");
+ delete block;
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tshrink APPLICATION, don't use padding\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 26, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tgrow APPLICATION, don't use padding\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 28, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tgrow APPLICATION, use padding, but last block is not padding\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 36, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, but delta is too small for new PADDING block\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 33, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tshrink APPLICATION, use padding, last block is not padding, delta is enough for new PADDING block\n");
+ if(0 == (padding = new FLAC::Metadata::Padding()))
+ return die_("creating PADDING block");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 29, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ padding->set_length(0);
+ if(!insert_to_our_metadata_(padding, our_current_position+1, /*copy=*/false))
+ return die_("internal error");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tshrink APPLICATION, use padding, last block is padding\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 16, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ dynamic_cast<FLAC::Metadata::Padding *>(our_metadata_.blocks[our_current_position+1])->set_length(13);
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding, but delta is too small\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 50, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exceeding size\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 56, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ add_to_padding_length_(our_current_position+1, -(56 - 50));
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]P\tgrow APPLICATION, use padding, last block is padding of exact size\n");
+ if(0 == (app = dynamic_cast<FLAC::Metadata::Application *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("copying object");
+ if(!app->set_data(data, 67, true))
+ return die_("setting APPLICATION data");
+ if(!replace_in_our_metadata_(app, our_current_position, /*copy=*/true))
+ return die_("copying object");
+ delete_from_our_metadata_(our_current_position+1);
+ if(!iterator.set_block(app))
+ return die_c_("iterator.set_block(app)", chain.status());
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV[A]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("S[V]A\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("[S]VA\tinsert PADDING before STREAMINFO (should fail)\n");
+ if(0 == (padding = new FLAC::Metadata::Padding()))
+ return die_("creating PADDING block");
+ padding->set_length(30);
+ if(!iterator.insert_block_before(padding))
+ printf("\titerator.insert_block_before() returned false like it should\n");
+ else
+ return die_("iterator.insert_block_before() should have returned false");
+
+ printf("[S]VA\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("S[V]A\tinsert PADDING after\n");
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return die_("copying metadata");
+ if(!iterator.insert_block_after(padding))
+ return die_("iterator.insert_block_after(padding)");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("SV[P]A\tinsert PADDING before\n");
+ if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("creating PADDING block");
+ padding->set_length(17);
+ if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying metadata");
+ if(!iterator.insert_block_before(padding))
+ return die_("iterator.insert_block_before(padding)");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("SV[P]PA\tinsert PADDING before\n");
+ if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[our_current_position]))))
+ return die_("creating PADDING block");
+ padding->set_length(0);
+ if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying metadata");
+ if(!iterator.insert_block_before(padding))
+ return die_("iterator.insert_block_before(padding)");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("SV[P]PPA\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVP[P]PA\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVPP[P]A\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SVPPP[A]\tinsert PADDING after\n");
+ if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[2]))))
+ return die_("creating PADDING block");
+ padding->set_length(57);
+ if(!insert_to_our_metadata_(padding, ++our_current_position, /*copy=*/true))
+ return die_("copying metadata");
+ if(!iterator.insert_block_after(padding))
+ return die_("iterator.insert_block_after(padding)");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("SVPPPA[P]\tinsert PADDING before\n");
+ if(0 == (padding = dynamic_cast<FLAC::Metadata::Padding *>(FLAC::Metadata::clone(our_metadata_.blocks[2]))))
+ return die_("creating PADDING block");
+ padding->set_length(99);
+ if(!insert_to_our_metadata_(padding, our_current_position, /*copy=*/true))
+ return die_("copying metadata");
+ if(!iterator.insert_block_before(padding))
+ return die_("iterator.insert_block_before(padding)");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ }
+ our_current_position = 0;
+
+ printf("SVPPPAPP\tmerge padding\n");
+ chain.merge_padding();
+ add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[3]->get_length());
+ add_to_padding_length_(2, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[4]->get_length());
+ add_to_padding_length_(6, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[7]->get_length());
+ delete_from_our_metadata_(7);
+ delete_from_our_metadata_(4);
+ delete_from_our_metadata_(3);
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ if(!compare_chain_(chain, 0, 0))
+ return false;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SVPAP\tsort padding\n");
+ chain.sort_padding();
+ add_to_padding_length_(4, FLAC__STREAM_METADATA_HEADER_LENGTH + our_metadata_.blocks[2]->get_length());
+ delete_from_our_metadata_(2);
+
+ if(!write_chain_(chain, /*use_padding=*/true, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(true, false)", chain.status());
+ if(!compare_chain_(chain, 0, 0))
+ return false;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("create iterator\n");
+ {
+ FLAC::Metadata::Iterator iterator;
+ if(!iterator.is_valid())
+ return die_("allocating memory for iterator");
+
+ our_current_position = 0;
+
+ iterator.init(chain);
+
+ printf("[S]VAP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("S[V]AP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[A]P\tdelete middle block, replace with padding\n");
+ if(0 == (padding = new FLAC::Metadata::Padding()))
+ return die_("creating PADDING block");
+ padding->set_length(71);
+ if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false))
+ return die_("copying object");
+ if(!iterator.delete_block(/*replace_with_padding=*/true))
+ return die_c_("iterator.delete_block(true)", chain.status());
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("S[V]PP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]P\tdelete middle block, don't replace with padding\n");
+ delete_from_our_metadata_(our_current_position--);
+ if(!iterator.delete_block(/*replace_with_padding=*/false))
+ return die_c_("iterator.delete_block(false)", chain.status());
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("S[V]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]\tdelete last block, replace with padding\n");
+ if(0 == (padding = new FLAC::Metadata::Padding()))
+ return die_("creating PADDING block");
+ padding->set_length(219);
+ if(!replace_in_our_metadata_(padding, our_current_position--, /*copy=*/false))
+ return die_("copying object");
+ if(!iterator.delete_block(/*replace_with_padding=*/true))
+ return die_c_("iterator.delete_block(true)", chain.status());
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("S[V]P\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+ our_current_position++;
+
+ printf("SV[P]\tdelete last block, don't replace with padding\n");
+ delete_from_our_metadata_(our_current_position--);
+ if(!iterator.delete_block(/*replace_with_padding=*/false))
+ return die_c_("iterator.delete_block(false)", chain.status());
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ printf("S[V]\tprev\n");
+ if(!iterator.prev())
+ return die_("iterator ended early\n");
+ our_current_position--;
+
+ printf("[S]V\tdelete STREAMINFO block, should fail\n");
+ if(iterator.delete_block(/*replace_with_padding=*/false))
+ return die_("iterator.delete_block() on STREAMINFO should have failed but didn't");
+
+ block = iterator.get_block();
+ if(!compare_chain_(chain, our_current_position, block))
+ return false;
+ delete block;
+
+ } // delete iterator
+ our_current_position = 0;
+
+ printf("SV\tmerge padding\n");
+ chain.merge_padding();
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ if(!compare_chain_(chain, 0, 0))
+ return false;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+ printf("SV\tsort padding\n");
+ chain.sort_padding();
+
+ if(!write_chain_(chain, /*use_padding=*/false, /*preserve_file_stats=*/false, filename_based, flacfilename(is_ogg)))
+ return die_c_("during chain.write(false, false)", chain.status());
+ if(!compare_chain_(chain, 0, 0))
+ return false;
+ if(!test_file_(is_ogg, /*ignore_metadata=*/false))
+ return false;
+
+end:
+ if(!remove_file_(flacfilename(is_ogg)))
+ return false;
+
+ return true;
+}
+
+static bool test_level_2_misc_(bool is_ogg)
+{
+ ::FLAC__IOCallbacks callbacks;
+
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.read = (::FLAC__IOCallback_Read)fread;
+#ifdef FLAC__VALGRIND_TESTING
+ callbacks.write = chain_write_cb_;
+#else
+ callbacks.write = (::FLAC__IOCallback_Write)fwrite;
+#endif
+ callbacks.seek = chain_seek_cb_;
+ callbacks.tell = chain_tell_cb_;
+ callbacks.eof = chain_eof_cb_;
+
+ printf("\n\n++++++ testing level 2 interface (mismatched read/write protections)\n");
+
+ printf("generate file\n");
+
+ if(!generate_file_(/*include_extras=*/false, is_ogg))
+ return false;
+
+ printf("create chain\n");
+ FLAC::Metadata::Chain chain;
+ if(!chain.is_valid())
+ return die_("allocating chain");
+
+ printf("read chain (filename-based)\n");
+
+ if(!chain.read(flacfilename(is_ogg)))
+ return die_c_("reading chain", chain.status());
+
+ printf("write chain with wrong method Chain::write(with callbacks)\n");
+ {
+ if(chain.write(/*use_padding=*/false, 0, callbacks))
+ return die_c_("mismatched write should have failed", chain.status());
+ if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH)
+ return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status());
+ printf(" OK: Chain::write(with callbacks) returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n");
+ }
+
+ printf("read chain (filename-based)\n");
+
+ if(!chain.read(flacfilename(is_ogg)))
+ return die_c_("reading chain", chain.status());
+
+ printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n");
+ {
+ if(chain.write(/*use_padding=*/false, 0, callbacks, 0, callbacks))
+ return die_c_("mismatched write should have failed", chain.status());
+ if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH)
+ return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status());
+ printf(" OK: Chain::write(with callbacks and tempfile) returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n");
+ }
+
+ printf("read chain (callback-based)\n");
+ {
+ FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == file)
+ return die_("opening file");
+ if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
+ fclose(file);
+ return die_c_("reading chain", chain.status());
+ }
+ fclose(file);
+ }
+
+ printf("write chain with wrong method write()\n");
+ {
+ if(chain.write(/*use_padding=*/false, /*preserve_file_stats=*/false))
+ return die_c_("mismatched write should have failed", chain.status());
+ if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH)
+ return die_c_("expected FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH", chain.status());
+ printf(" OK: write() returned false,FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH like it should\n");
+ }
+
+ printf("read chain (callback-based)\n");
+ {
+ FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == file)
+ return die_("opening file");
+ if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
+ fclose(file);
+ return die_c_("reading chain", chain.status());
+ }
+ fclose(file);
+ }
+
+ printf("testing Chain::check_if_tempfile_needed()... ");
+
+ if(!chain.check_if_tempfile_needed(/*use_padding=*/false))
+ printf("OK: Chain::check_if_tempfile_needed() returned false like it should\n");
+ else
+ return die_("Chain::check_if_tempfile_needed() returned true but shouldn't have");
+
+ printf("write chain with wrong method Chain::write(with callbacks and tempfile)\n");
+ {
+ if(chain.write(/*use_padding=*/false, 0, callbacks, 0, callbacks))
+ return die_c_("mismatched write should have failed", chain.status());
+ if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL)
+ return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", chain.status());
+ printf(" OK: Chain::write(with callbacks and tempfile) returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n");
+ }
+
+ printf("read chain (callback-based)\n");
+ {
+ FILE *file = flac_fopen(flacfilename(is_ogg), "rb");
+ if(0 == file)
+ return die_("opening file");
+ if(!chain.read((::FLAC__IOHandle)file, callbacks)) {
+ fclose(file);
+ return die_c_("reading chain", chain.status());
+ }
+ fclose(file);
+ }
+
+ printf("create iterator\n");
+ {
+ FLAC::Metadata::Iterator iterator;
+ if(!iterator.is_valid())
+ return die_("allocating memory for iterator");
+
+ iterator.init(chain);
+
+ printf("[S]VP\tnext\n");
+ if(!iterator.next())
+ return die_("iterator ended early\n");
+
+ printf("S[V]P\tdelete VORBIS_COMMENT, write\n");
+ if(!iterator.delete_block(/*replace_with_padding=*/false))
+ return die_c_("block delete failed\n", chain.status());
+
+ printf("testing Chain::check_if_tempfile_needed()... ");
+
+ if(chain.check_if_tempfile_needed(/*use_padding=*/false))
+ printf("OK: Chain::check_if_tempfile_needed() returned true like it should\n");
+ else
+ return die_("Chain::check_if_tempfile_needed() returned false but shouldn't have");
+
+ printf("write chain with wrong method Chain::write(with callbacks)\n");
+ {
+ if(chain.write(/*use_padding=*/false, 0, callbacks))
+ return die_c_("mismatched write should have failed", chain.status());
+ if(chain.status() != ::FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL)
+ return die_c_("expected FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL", chain.status());
+ printf(" OK: Chain::write(with callbacks) returned false,FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL like it should\n");
+ }
+
+ } // delete iterator
+
+ if(!remove_file_(flacfilename(is_ogg)))
+ return false;
+
+ return true;
+}
+
+bool test_metadata_file_manipulation()
+{
+ printf("\n+++ libFLAC++ unit test: metadata manipulation\n\n");
+
+ our_metadata_.num_blocks = 0;
+
+ if(!test_level_0_())
+ return false;
+
+ if(!test_level_1_())
+ return false;
+
+ if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/false)) /* filename-based */
+ return false;
+ if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/false)) /* callback-based */
+ return false;
+ if(!test_level_2_misc_(/*is_ogg=*/false))
+ return false;
+
+ if(FLAC_API_SUPPORTS_OGG_FLAC) {
+ if(!test_level_2_(/*filename_based=*/true, /*is_ogg=*/true)) /* filename-based */
+ return false;
+ if(!test_level_2_(/*filename_based=*/false, /*is_ogg=*/true)) /* callback-based */
+ return false;
+#if 0
+ /* when ogg flac write is supported, will have to add this: */
+ if(!test_level_2_misc_(/*is_ogg=*/true))
+ return false;
+#endif
+ }
+
+ return true;
+}
diff --git a/src/test_libFLAC++/metadata_object.cpp b/src/test_libFLAC++/metadata_object.cpp
new file mode 100644
index 0000000..ab4cfbf
--- /dev/null
+++ b/src/test_libFLAC++/metadata_object.cpp
@@ -0,0 +1,2099 @@
+/* test_libFLAC++ - Unit tester for libFLAC++
+ * Copyright (C) 2002-2009 Josh Coalson
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h> /* for malloc() */
+#include <string.h> /* for memcmp() */
+#include "FLAC/assert.h"
+#include "FLAC++/metadata.h"
+#include "share/safe_str.h"
+
+static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application_, vorbiscomment_, cuesheet_, picture_;
+
+static bool die_(const char *msg)
+{
+ printf("FAILED, %s\n", msg);
+ return false;
+}
+
+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", (uint32_t)size);
+ exit(1);
+ }
+ return x;
+}
+
+static char *strdup_or_die_(const char *s)
+{
+ char *x = strdup(s);
+ if(0 == x) {
+ fprintf(stderr, "ERROR: out of memory copying string \"%s\"\n", s);
+ exit(1);
+ }
+ return x;
+}
+
+static bool index_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Index &indx, const ::FLAC__StreamMetadata_CueSheet_Index &indxcopy)
+{
+ if(indxcopy.offset != indx.offset)
+ return false;
+ if(indxcopy.number != indx.number)
+ return false;
+ return true;
+}
+
+static bool track_is_equal_(const ::FLAC__StreamMetadata_CueSheet_Track *track, const ::FLAC__StreamMetadata_CueSheet_Track *trackcopy)
+{
+ uint32_t i;
+
+ if(trackcopy->offset != track->offset)
+ return false;
+ if(trackcopy->number != track->number)
+ return false;
+ if(0 != strcmp(trackcopy->isrc, track->isrc))
+ return false;
+ if(trackcopy->type != track->type)
+ return false;
+ if(trackcopy->pre_emphasis != track->pre_emphasis)
+ return false;
+ if(trackcopy->num_indices != track->num_indices)
+ return false;
+ if(0 == track->indices || 0 == trackcopy->indices) {
+ if(track->indices != trackcopy->indices)
+ return false;
+ }
+ else {
+ for(i = 0; i < track->num_indices; i++) {
+ if(!index_is_equal_(trackcopy->indices[i], track->indices[i]))
+ return false;
+ }
+ }
+ return true;
+}
+
+static void init_metadata_blocks_()
+{
+ 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;
+
+ application_.is_last = false;
+ application_.type = ::FLAC__METADATA_TYPE_APPLICATION;
+ application_.length = 8;
+ memcpy(application_.data.application.id, "\xfe\xdc\xba\x98", 4);
+ application_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
+ memcpy(application_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
+
+ vorbiscomment_.is_last = false;
+ vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
+ vorbiscomment_.length = (4 + 5) + 4 + (4 + 12) + (4 + 12);
+ vorbiscomment_.data.vorbis_comment.vendor_string.length = 5;
+ vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(5+1);
+ memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "name0", 5+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 = 12;
+ vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(12+1);
+ memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "name2=value2", 12+1);
+ vorbiscomment_.data.vorbis_comment.comments[1].length = 12;
+ vorbiscomment_.data.vorbis_comment.comments[1].entry = (FLAC__byte*)malloc_or_die_(12+1);
+ memcpy(vorbiscomment_.data.vorbis_comment.comments[1].entry, "name3=value3", 12+1);
+
+ 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 */
+ 2 * (
+ 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 = 159;
+ cuesheet_.data.cue_sheet.is_cd = true;
+ cuesheet_.data.cue_sheet.num_tracks = 2;
+ cuesheet_.data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)malloc_or_die_(cuesheet_.data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track));
+ cuesheet_.data.cue_sheet.tracks[0].offset = 1;
+ 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 = 1234567890;
+ cuesheet_.data.cue_sheet.tracks[0].indices[1].number = 1;
+ cuesheet_.data.cue_sheet.tracks[1].offset = 2345678901u;
+ 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;
+
+ picture_.is_last = true;
+ picture_.type = FLAC__METADATA_TYPE_PICTURE;
+ picture_.length =
+ (
+ FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
+ FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* will add the length for the string later */
+ FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* will add the length for the string later */
+ FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN /* will add the length for the data later */
+ ) / 8
+ ;
+ picture_.data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
+ picture_.data.picture.mime_type = strdup_or_die_("image/jpeg");
+ picture_.length += strlen(picture_.data.picture.mime_type);
+ picture_.data.picture.description = (FLAC__byte*)strdup_or_die_("desc");
+ picture_.length += strlen((const char *)picture_.data.picture.description);
+ picture_.data.picture.width = 300;
+ picture_.data.picture.height = 300;
+ picture_.data.picture.depth = 24;
+ picture_.data.picture.colors = 0;
+ picture_.data.picture.data = (FLAC__byte*)strdup_or_die_("SOMEJPEGDATA");
+ picture_.data.picture.data_length = strlen((const char *)picture_.data.picture.data);
+ picture_.length += picture_.data.picture.data_length;
+}
+
+static void free_metadata_blocks_()
+{
+ free(seektable_.data.seek_table.points);
+ free(application_.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[1].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(picture_.data.picture.mime_type);
+ free(picture_.data.picture.description);
+ free(picture_.data.picture.data);
+}
+
+bool test_metadata_object_streaminfo()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::StreamInfo\n");
+
+ printf("testing StreamInfo::StreamInfo()... ");
+ FLAC::Metadata::StreamInfo block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing StreamInfo::StreamInfo(const StreamInfo &)... +\n");
+ printf(" StreamInfo::operator!=(const StreamInfo &)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing StreamInfo::~StreamInfo()... ");
+ }
+ printf("OK\n");
+
+ printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy(streaminfo_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy(&streaminfo_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy(&streaminfo_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::StreamInfo(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_);
+ FLAC::Metadata::StreamInfo blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy;
+ blockcopy.assign(&streaminfo_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" StreamInfo::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&streaminfo_);
+ FLAC::Metadata::StreamInfo blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != streaminfo_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::operator=(const StreamInfo &)... +\n");
+ printf(" StreamInfo::operator==(const StreamInfo &)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" StreamInfo::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy = streaminfo_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == streaminfo_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" StreamInfo::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::StreamInfo blockcopy = &streaminfo_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == streaminfo_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing StreamInfo::set_min_blocksize()... ");
+ block.set_min_blocksize(streaminfo_.data.stream_info.min_blocksize);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_max_blocksize()... ");
+ block.set_max_blocksize(streaminfo_.data.stream_info.max_blocksize);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_min_framesize()... ");
+ block.set_min_framesize(streaminfo_.data.stream_info.min_framesize);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_max_framesize()... ");
+ block.set_max_framesize(streaminfo_.data.stream_info.max_framesize);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_sample_rate()... ");
+ block.set_sample_rate(streaminfo_.data.stream_info.sample_rate);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_channels()... ");
+ block.set_channels(streaminfo_.data.stream_info.channels);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_bits_per_sample()... ");
+ block.set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_total_samples()... ");
+ block.set_total_samples(streaminfo_.data.stream_info.total_samples);
+ printf("OK\n");
+
+ printf("testing StreamInfo::set_md5sum()... ");
+ block.set_md5sum(streaminfo_.data.stream_info.md5sum);
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_min_blocksize()... ");
+ if(block.get_min_blocksize() != streaminfo_.data.stream_info.min_blocksize)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_max_blocksize()... ");
+ if(block.get_max_blocksize() != streaminfo_.data.stream_info.max_blocksize)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_min_framesize()... ");
+ if(block.get_min_framesize() != streaminfo_.data.stream_info.min_framesize)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_max_framesize()... ");
+ if(block.get_max_framesize() != streaminfo_.data.stream_info.max_framesize)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_sample_rate()... ");
+ if(block.get_sample_rate() != streaminfo_.data.stream_info.sample_rate)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_channels()... ");
+ if(block.get_channels() != streaminfo_.data.stream_info.channels)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_bits_per_sample()... ");
+ if(block.get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_total_samples()... ");
+ if(block.get_total_samples() != streaminfo_.data.stream_info.total_samples)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing StreamInfo::get_md5sum()... ");
+ if(0 != memcmp(block.get_md5sum(), streaminfo_.data.stream_info.md5sum, 16))
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::StreamInfo *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing StreamInfo::~StreamInfo()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_padding()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::Padding\n");
+
+ printf("testing Padding::Padding()... ");
+ FLAC::Metadata::Padding block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = 0;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing Padding::Padding(const Padding &)... +\n");
+ printf(" Padding::operator!=(const Padding &)... ");
+ {
+ FLAC::Metadata::Padding blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing Padding::~Padding()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Padding::Padding(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Padding blockcopy(padding_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::Padding(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Padding blockcopy(&padding_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Padding blockcopy(&padding_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::Padding(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_);
+ FLAC::Metadata::Padding blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Padding blockcopy;
+ blockcopy.assign(&padding_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Padding::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&padding_);
+ FLAC::Metadata::Padding blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != padding_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::operator=(const Padding &)... +\n");
+ printf(" Padding::operator==(const Padding &)... ");
+ {
+ FLAC::Metadata::Padding blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Padding::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Padding blockcopy = padding_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == padding_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Padding::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Padding blockcopy = &padding_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == padding_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Padding::set_length()... ");
+ block.set_length(padding_.length);
+ printf("OK\n");
+
+ printf("testing Prototype::get_length()... ");
+ if(block.get_length() != padding_.length)
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::Padding *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::Padding *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing Padding::~Padding()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_application()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::Application\n");
+
+ printf("testing Application::Application()... ");
+ FLAC::Metadata::Application block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing Application::Application(const Application &)... +\n");
+ printf(" Application::operator!=(const Application &)... ");
+ {
+ FLAC::Metadata::Application blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing Application::~Application()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Application::Application(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Application blockcopy(application_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::Application(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Application blockcopy(&application_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Application blockcopy(&application_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::Application(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_);
+ FLAC::Metadata::Application blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Application blockcopy;
+ blockcopy.assign(&application_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Application::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&application_);
+ FLAC::Metadata::Application blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != application_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::operator=(const Application &)... +\n");
+ printf(" Application::operator==(const Application &)... ");
+ {
+ FLAC::Metadata::Application blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Application::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Application blockcopy = application_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == application_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Application::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Application blockcopy = &application_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == application_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Application::set_id()... ");
+ block.set_id(application_.data.application.id);
+ printf("OK\n");
+
+ printf("testing Application::set_data()... ");
+ block.set_data(application_.data.application.data, application_.length - sizeof(application_.data.application.id), /*copy=*/true);
+ printf("OK\n");
+
+ printf("testing Application::get_id()... ");
+ if(0 != memcmp(block.get_id(), application_.data.application.id, sizeof(application_.data.application.id)))
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing Application::get_data()... ");
+ if(0 != memcmp(block.get_data(), application_.data.application.data, application_.length - sizeof(application_.data.application.id)))
+ return die_("value mismatch, doesn't match previously set value");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::Application *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::Application *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing Application::~Application()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_seektable()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::SeekTable\n");
+
+ printf("testing SeekTable::SeekTable()... ");
+ FLAC::Metadata::SeekTable block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = 0;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing SeekTable::SeekTable(const SeekTable &)... +\n");
+ printf(" SeekTable::operator!=(const SeekTable &)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing SeekTable::~SeekTable()... ");
+ }
+ printf("OK\n");
+
+ printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy(seektable_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy(&seektable_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy(&seektable_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::SeekTable(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_);
+ FLAC::Metadata::SeekTable blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy;
+ blockcopy.assign(&seektable_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" SeekTable::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&seektable_);
+ FLAC::Metadata::SeekTable blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != seektable_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::operator=(const SeekTable &)... +\n");
+ printf(" SeekTable::operator==(const SeekTable &)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" SeekTable::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy = seektable_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == seektable_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" SeekTable::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::SeekTable blockcopy = &seektable_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == seektable_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing SeekTable::insert_point() x 3... ");
+ if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
+ return die_("returned false");
+ if(!block.insert_point(0, seektable_.data.seek_table.points[1]))
+ return die_("returned false");
+ if(!block.insert_point(1, seektable_.data.seek_table.points[0]))
+ return die_("returned false");
+ printf("OK\n");
+
+ printf("testing SeekTable::is_legal()... ");
+ if(block.is_legal())
+ return die_("returned true");
+ printf("OK\n");
+
+ printf("testing SeekTable::set_point()... ");
+ block.set_point(0, seektable_.data.seek_table.points[0]);
+ printf("OK\n");
+
+ printf("testing SeekTable::delete_point()... ");
+ if(!block.delete_point(0))
+ return die_("returned false");
+ printf("OK\n");
+
+ printf("testing SeekTable::is_legal()... ");
+ if(!block.is_legal())
+ return die_("returned false");
+ printf("OK\n");
+
+ printf("testing SeekTable::get_num_points()... ");
+ if(block.get_num_points() != seektable_.data.seek_table.num_points)
+ return die_("number mismatch");
+ printf("OK\n");
+
+ printf("testing SeekTable::operator!=(const ::FLAC__StreamMetadata &)... ");
+ if(block != seektable_)
+ return die_("data mismatch");
+ printf("OK\n");
+
+ printf("testing SeekTable::get_point()... ");
+ if(
+ block.get_point(1).sample_number != seektable_.data.seek_table.points[1].sample_number ||
+ block.get_point(1).stream_offset != seektable_.data.seek_table.points[1].stream_offset ||
+ block.get_point(1).frame_samples != seektable_.data.seek_table.points[1].frame_samples
+ )
+ return die_("point mismatch");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::SeekTable *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::SeekTable *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing SeekTable::~SeekTable()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_vorbiscomment()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::VorbisComment::Entry\n");
+
+ printf("testing Entry::Entry()... ");
+ {
+ FLAC::Metadata::VorbisComment::Entry entry1;
+ if(!entry1.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ printf("testing Entry::~Entry()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Entry::Entry(const char *field, uint32_t field_length)... ");
+ FLAC::Metadata::VorbisComment::Entry entry2("name2=value2", strlen("name2=value2"));
+ if(!entry2.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ {
+ printf("testing Entry::Entry(const char *field)... ");
+ FLAC::Metadata::VorbisComment::Entry entry2z("name2=value2");
+ if(!entry2z.is_valid())
+ return die_("!is_valid()");
+ if(strcmp(entry2.get_field(), entry2z.get_field()))
+ return die_("bad value");
+ printf("OK\n");
+ }
+
+ printf("testing Entry::Entry(const char *field_name, const char *field_value, uint32_t field_value_length)... ");
+ FLAC::Metadata::VorbisComment::Entry entry3("name3", "value3", strlen("value3"));
+ if(!entry3.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ {
+ printf("testing Entry::Entry(const char *field_name, const char *field_value)... ");
+ FLAC::Metadata::VorbisComment::Entry entry3z("name3", "value3");
+ if(!entry3z.is_valid())
+ return die_("!is_valid()");
+ if(strcmp(entry3.get_field(), entry3z.get_field()))
+ return die_("bad value");
+ printf("OK\n");
+ }
+
+ printf("testing Entry::Entry(const Entry &entry)... ");
+ {
+ FLAC::Metadata::VorbisComment::Entry entry2copy(entry2);
+ if(!entry2copy.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ printf("testing Entry::~Entry()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Entry::operator=(const Entry &entry)... ");
+ FLAC::Metadata::VorbisComment::Entry entry1 = entry2;
+ if(!entry2.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ printf("testing Entry::get_field_length()... ");
+ if(entry1.get_field_length() != strlen("name2=value2"))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::get_field_name_length()... ");
+ if(entry1.get_field_name_length() != strlen("name2"))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::get_field_value_length()... ");
+ if(entry1.get_field_value_length() != strlen("value2"))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::get_entry()... ");
+ {
+ ::FLAC__StreamMetadata_VorbisComment_Entry entry = entry1.get_entry();
+ if(entry.length != strlen("name2=value2"))
+ return die_("entry length mismatch");
+ if(0 != memcmp(entry.entry, "name2=value2", entry.length))
+ return die_("entry value mismatch");
+ }
+ printf("OK\n");
+
+ printf("testing Entry::get_field()... ");
+ if(0 != memcmp(entry1.get_field(), "name2=value2", strlen("name2=value2")))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::get_field_name()... ");
+ if(0 != memcmp(entry1.get_field_name(), "name2", strlen("name2")))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::get_field_value()... ");
+ if(0 != memcmp(entry1.get_field_value(), "value2", strlen("value2")))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::set_field_name()... ");
+ if(!entry1.set_field_name("name1"))
+ return die_("returned false");
+ if(0 != memcmp(entry1.get_field_name(), "name1", strlen("name1")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field(), "name1=value2", strlen("name1=value2")))
+ return die_("entry mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::set_field_value(const char *field_value, uint32_t field_value_length)... ");
+ if(!entry1.set_field_value("value1", strlen("value1")))
+ return die_("returned false");
+ if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
+ return die_("entry mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::set_field_value(const char *field_value)... ");
+ if(!entry1.set_field_value("value1"))
+ return die_("returned false");
+ if(0 != memcmp(entry1.get_field_value(), "value1", strlen("value1")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field(), "name1=value1", strlen("name1=value1")))
+ return die_("entry mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::set_field(const char *field, uint32_t field_length)... ");
+ if(!entry1.set_field("name0=value0", strlen("name0=value0")))
+ return die_("returned false");
+ if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
+ return die_("entry mismatch");
+ printf("OK\n");
+
+ printf("testing Entry::set_field(const char *field)... ");
+ if(!entry1.set_field("name0=value0"))
+ return die_("returned false");
+ if(0 != memcmp(entry1.get_field_name(), "name0", strlen("name0")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field_value(), "value0", strlen("value0")))
+ return die_("value mismatch");
+ if(0 != memcmp(entry1.get_field(), "name0=value0", strlen("name0=value0")))
+ return die_("entry mismatch");
+ printf("OK\n");
+
+ printf("PASSED\n\n");
+
+
+ printf("testing class FLAC::Metadata::VorbisComment\n");
+
+ printf("testing VorbisComment::VorbisComment()... ");
+ FLAC::Metadata::VorbisComment block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + strlen(::FLAC__VENDOR_STRING) + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN/8);
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing VorbisComment::VorbisComment(const VorbisComment &)... +\n");
+ printf(" VorbisComment::operator!=(const VorbisComment &)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing VorbisComment::~VorbisComment()... ");
+ }
+ printf("OK\n");
+
+ printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy(vorbiscomment_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy(&vorbiscomment_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::VorbisComment(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_);
+ FLAC::Metadata::VorbisComment blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy;
+ blockcopy.assign(&vorbiscomment_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" VorbisComment::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&vorbiscomment_);
+ FLAC::Metadata::VorbisComment blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != vorbiscomment_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::operator=(const VorbisComment &)... +\n");
+ printf(" VorbisComment::operator==(const VorbisComment &)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" VorbisComment::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy = vorbiscomment_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == vorbiscomment_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" VorbisComment::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::VorbisComment blockcopy = &vorbiscomment_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == vorbiscomment_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing VorbisComment::get_num_comments()... ");
+ if(block.get_num_comments() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing VorbisComment::set_vendor_string()... ");
+ if(!block.set_vendor_string((const FLAC__byte *)"mame0"))
+ return die_("returned false");
+ printf("OK\n");
+ vorbiscomment_.data.vorbis_comment.vendor_string.entry[0] = 'm';
+
+ printf("testing VorbisComment::get_vendor_string()... ");
+ if(strlen((const char *)block.get_vendor_string()) != vorbiscomment_.data.vorbis_comment.vendor_string.length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_vendor_string(), vorbiscomment_.data.vorbis_comment.vendor_string.entry, vorbiscomment_.data.vorbis_comment.vendor_string.length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::append_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.append_comment(entry3))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::append_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.append_comment(entry2))
+ return die_("returned false");
+ if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::delete_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.delete_comment(0))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
+ return die_("length[0] mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
+ return die_("value[0] mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::delete_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.delete_comment(0))
+ return die_("returned false");
+ if(block.get_num_comments() != 0)
+ return die_("block mismatch, expected num_comments = 0");
+ printf("OK\n");
+
+ printf("testing VorbisComment::insert_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.insert_comment(0, entry3))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::insert_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.insert_comment(0, entry3))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::insert_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.insert_comment(1, entry2))
+ return die_("returned false");
+ if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::set_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.set_comment(0, entry2))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing VorbisComment::delete_comment()... +\n");
+ printf(" VorbisComment::get_comment()... ");
+ if(!block.delete_comment(0))
+ return die_("returned false");
+ if(block.get_comment(0).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[0].length)
+ return die_("length[0] mismatch");
+ if(0 != memcmp(block.get_comment(0).get_field(), vorbiscomment_.data.vorbis_comment.comments[0].entry, vorbiscomment_.data.vorbis_comment.comments[0].length))
+ return die_("value[0] mismatch");
+ if(block.get_comment(1).get_field_length() != vorbiscomment_.data.vorbis_comment.comments[1].length)
+ return die_("length[1] mismatch");
+ if(0 != memcmp(block.get_comment(1).get_field(), vorbiscomment_.data.vorbis_comment.comments[1].entry, vorbiscomment_.data.vorbis_comment.comments[1].length))
+ return die_("value[0] mismatch");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::VorbisComment *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing VorbisComment::~VorbisComment()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_cuesheet()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::CueSheet::Track\n");
+
+ printf("testing Track::Track()... ");
+ FLAC::Metadata::CueSheet::Track track0;
+ if(!track0.is_valid())
+ return die_("!is_valid()");
+ printf("OK\n");
+
+ {
+ printf("testing Track::get_track()... ");
+ const ::FLAC__StreamMetadata_CueSheet_Track *trackp = track0.get_track();
+ if(0 == trackp)
+ return die_("returned pointer is NULL");
+ printf("OK\n");
+
+ printf("testing Track::Track(const ::FLAC__StreamMetadata_CueSheet_Track*)... ");
+ FLAC::Metadata::CueSheet::Track track2(trackp);
+ if(!track2.is_valid())
+ return die_("!is_valid()");
+ if(!track_is_equal_(track2.get_track(), trackp))
+ return die_("copy is not equal");
+ printf("OK\n");
+
+ printf("testing Track::~Track()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Track::Track(const Track &track)... ");
+ {
+ FLAC::Metadata::CueSheet::Track track0copy(track0);
+ if(!track0copy.is_valid())
+ return die_("!is_valid()");
+ if(!track_is_equal_(track0copy.get_track(), track0.get_track()))
+ return die_("copy is not equal");
+ printf("OK\n");
+
+ printf("testing Track::~Track()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Track::operator=(const Track &track)... ");
+ FLAC::Metadata::CueSheet::Track track1 = track0;
+ if(!track0.is_valid())
+ return die_("!is_valid()");
+ if(!track_is_equal_(track1.get_track(), track0.get_track()))
+ return die_("copy is not equal");
+ printf("OK\n");
+
+ printf("testing Track::get_offset()... ");
+ if(track1.get_offset() != 0)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::get_number()... ");
+ if(track1.get_number() != 0)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::get_isrc()... ");
+ if(0 != memcmp(track1.get_isrc(), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 13))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::get_type()... ");
+ if(track1.get_type() != 0)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::get_pre_emphasis()... ");
+ if(track1.get_pre_emphasis() != 0)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::get_num_indices()... ");
+ if(track1.get_num_indices() != 0)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::set_offset()... ");
+ track1.set_offset(588);
+ if(track1.get_offset() != 588)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::set_number()... ");
+ track1.set_number(1);
+ if(track1.get_number() != 1)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::set_isrc()... ");
+ track1.set_isrc("ABCDE1234567");
+ if(0 != memcmp(track1.get_isrc(), "ABCDE1234567", 13))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::set_type()... ");
+ track1.set_type(1);
+ if(track1.get_type() != 1)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Track::set_pre_emphasis()... ");
+ track1.set_pre_emphasis(1);
+ if(track1.get_pre_emphasis() != 1)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("PASSED\n\n");
+
+ printf("testing class FLAC::Metadata::CueSheet\n");
+
+ printf("testing CueSheet::CueSheet()... ");
+ FLAC::Metadata::CueSheet block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = (
+ 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;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing CueSheet::CueSheet(const CueSheet &)... +\n");
+ printf(" CueSheet::operator!=(const CueSheet &)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing CueSheet::~CueSheet()... ");
+ }
+ printf("OK\n");
+
+ printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy(cuesheet_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy(&cuesheet_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy(&cuesheet_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::CueSheet(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_);
+ FLAC::Metadata::CueSheet blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy;
+ blockcopy.assign(&cuesheet_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" CueSheet::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&cuesheet_);
+ FLAC::Metadata::CueSheet blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != cuesheet_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::operator=(const CueSheet &)... +\n");
+ printf(" CueSheet::operator==(const CueSheet &)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" CueSheet::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy = cuesheet_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == cuesheet_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" CueSheet::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::CueSheet blockcopy = &cuesheet_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == cuesheet_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing CueSheet::get_media_catalog_number()... ");
+ if(0 != strcmp(block.get_media_catalog_number(), ""))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::get_lead_in()... ");
+ if(block.get_lead_in() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing CueSheet::get_is_cd()... ");
+ if(block.get_is_cd())
+ return die_("value mismatch, expected false");
+ printf("OK\n");
+
+ printf("testing CueSheet::get_num_tracks()... ");
+ if(block.get_num_tracks() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing CueSheet::set_media_catalog_number()... ");
+ {
+ char mcn[129];
+ memset(mcn, 0, sizeof(mcn));
+ safe_strncpy(mcn, "1234567890123", sizeof(mcn));
+ block.set_media_catalog_number(mcn);
+ if(0 != memcmp(block.get_media_catalog_number(), mcn, sizeof(mcn)))
+ return die_("value mismatch");
+ }
+ printf("OK\n");
+
+ printf("testing CueSheet::set_lead_in()... ");
+ block.set_lead_in(588);
+ if(block.get_lead_in() != 588)
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::set_is_cd()... ");
+ block.set_is_cd(true);
+ if(!block.get_is_cd())
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::insert_track()... +\n");
+ printf(" CueSheet::get_track()... ");
+ if(!block.insert_track(0, track0))
+ return die_("returned false");
+ if(!track_is_equal_(block.get_track(0).get_track(), track0.get_track()))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::insert_track()... +\n");
+ printf(" CueSheet::get_track()... ");
+ if(!block.insert_track(1, track1))
+ return die_("returned false");
+ if(!track_is_equal_(block.get_track(1).get_track(), track1.get_track()))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ ::FLAC__StreamMetadata_CueSheet_Index index0;
+ index0.offset = 588*4;
+ index0.number = 1;
+
+ printf("testing CueSheet::insert_index(0)... +\n");
+ printf(" CueSheet::get_track()... +\n");
+ printf(" CueSheet::Track::get_index()... ");
+ if(!block.insert_index(0, 0, index0))
+ return die_("returned false");
+ if(!index_is_equal_(block.get_track(0).get_index(0), index0))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ index0.offset = 588*5;
+ printf("testing CueSheet::Track::set_index()... ");
+ {
+ FLAC::Metadata::CueSheet::Track track_ = block.get_track(0);
+ track_.set_index(0, index0);
+ if(!index_is_equal_(track_.get_index(0), index0))
+ return die_("value mismatch");
+ }
+ printf("OK\n");
+
+ index0.offset = 588*6;
+ printf("testing CueSheet::set_index()... ");
+ block.set_index(0, 0, index0);
+ if(!index_is_equal_(block.get_track(0).get_index(0), index0))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::delete_index()... ");
+ if(!block.delete_index(0, 0))
+ return die_("returned false");
+ if(block.get_track(0).get_num_indices() != 0)
+ return die_("num_indices mismatch");
+ printf("OK\n");
+
+
+ printf("testing CueSheet::set_track()... +\n");
+ printf(" CueSheet::get_track()... ");
+ if(!block.set_track(0, track1))
+ return die_("returned false");
+ if(!track_is_equal_(block.get_track(0).get_track(), track1.get_track()))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing CueSheet::delete_track()... ");
+ if(!block.delete_track(0))
+ return die_("returned false");
+ if(block.get_num_tracks() != 1)
+ return die_("num_tracks mismatch");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::CueSheet *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::CueSheet *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing CueSheet::~CueSheet()... ");
+ delete clone_;
+ printf("OK\n");
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object_picture()
+{
+ uint32_t expected_length;
+
+ printf("testing class FLAC::Metadata::Picture\n");
+
+ printf("testing Picture::Picture()... ");
+ FLAC::Metadata::Picture block;
+ if(!block.is_valid())
+ return die_("!block.is_valid()");
+ expected_length = (
+ FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
+ FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
+ FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
+ FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN
+ ) / 8;
+ if(block.get_length() != expected_length) {
+ printf("FAILED, bad length, expected %u, got %u\n", expected_length, block.get_length());
+ return false;
+ }
+ printf("OK\n");
+
+ printf("testing Picture::Picture(const Picture &)... +\n");
+ printf(" Picture::operator!=(const Picture &)... ");
+ {
+ FLAC::Metadata::Picture blockcopy(block);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != block)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+
+ printf("testing Picture::~Picture()... ");
+ }
+ printf("OK\n");
+
+ printf("testing Picture::Picture(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Picture blockcopy(picture_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::Picture(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Picture blockcopy(&picture_);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Picture blockcopy(&picture_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::Picture(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_);
+ FLAC::Metadata::Picture blockcopy(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=true)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Picture blockcopy;
+ blockcopy.assign(&picture_, /*copy=*/true);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::assign(const ::FLAC__StreamMetadata *, copy=false)... +\n");
+ printf(" Picture::operator!=(const ::FLAC__StreamMetadata *)... ");
+ {
+ ::FLAC__StreamMetadata *copy = ::FLAC__metadata_object_clone(&picture_);
+ FLAC::Metadata::Picture blockcopy;
+ blockcopy.assign(copy, /*copy=*/false);
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(blockcopy != picture_)
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::operator=(const Picture &)... +\n");
+ printf(" Picture::operator==(const Picture &)... ");
+ {
+ FLAC::Metadata::Picture blockcopy = block;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == block))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::operator=(const ::FLAC__StreamMetadata &)... +\n");
+ printf(" Picture::operator==(const ::FLAC__StreamMetadata &)... ");
+ {
+ FLAC::Metadata::Picture blockcopy = picture_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == picture_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::operator=(const ::FLAC__StreamMetadata *)... +\n");
+ printf(" Picture::operator==(const ::FLAC__StreamMetadata *)... ");
+ {
+ FLAC::Metadata::Picture blockcopy = &picture_;
+ if(!blockcopy.is_valid())
+ return die_("!blockcopy.is_valid()");
+ if(!(blockcopy == picture_))
+ return die_("copy is not identical to original");
+ printf("OK\n");
+ }
+
+ printf("testing Picture::get_type()... ");
+ if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER)
+ return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER");
+ printf("OK\n");
+
+ printf("testing Picture::set_type()... +\n");
+ printf(" Picture::get_type()... ");
+ block.set_type(::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA);
+ if(block.get_type() != ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA)
+ return die_("value mismatch, expected ::FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA");
+ printf("OK\n");
+
+ printf("testing Picture::set_mime_type()... ");
+ if(!block.set_mime_type("qmage/jpeg"))
+ return die_("returned false");
+ printf("OK\n");
+ picture_.data.picture.mime_type[0] = 'q';
+
+ printf("testing Picture::get_mime_type()... ");
+ if(0 != strcmp(block.get_mime_type(), picture_.data.picture.mime_type))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Picture::set_description()... ");
+ if(!block.set_description((const FLAC__byte*)"qesc"))
+ return die_("returned false");
+ printf("OK\n");
+ picture_.data.picture.description[0] = 'q';
+
+ printf("testing Picture::get_description()... ");
+ if(0 != strcmp((const char *)block.get_description(), (const char *)picture_.data.picture.description))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing Picture::get_width()... ");
+ if(block.get_width() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing Picture::set_width()... +\n");
+ printf(" Picture::get_width()... ");
+ block.set_width(400);
+ if(block.get_width() != 400)
+ return die_("value mismatch, expected 400");
+ printf("OK\n");
+
+ printf("testing Picture::get_height()... ");
+ if(block.get_height() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing Picture::set_height()... +\n");
+ printf(" Picture::get_height()... ");
+ block.set_height(200);
+ if(block.get_height() != 200)
+ return die_("value mismatch, expected 200");
+ printf("OK\n");
+
+ printf("testing Picture::get_depth()... ");
+ if(block.get_depth() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing Picture::set_depth()... +\n");
+ printf(" Picture::get_depth()... ");
+ block.set_depth(16);
+ if(block.get_depth() != 16)
+ return die_("value mismatch, expected 16");
+ printf("OK\n");
+
+ printf("testing Picture::get_colors()... ");
+ if(block.get_colors() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing Picture::set_colors()... +\n");
+ printf(" Picture::get_colors()... ");
+ block.set_colors(1u>16);
+ if(block.get_colors() != (1u>16))
+ return die_("value mismatch, expected 2^16");
+ printf("OK\n");
+
+ printf("testing Picture::get_data_length()... ");
+ if(block.get_data_length() != 0)
+ return die_("value mismatch, expected 0");
+ printf("OK\n");
+
+ printf("testing Picture::set_data()... ");
+ if(!block.set_data((const FLAC__byte*)"qOMEJPEGDATA", strlen("qOMEJPEGDATA")))
+ return die_("returned false");
+ printf("OK\n");
+ picture_.data.picture.data[0] = 'q';
+
+ printf("testing Picture::get_data()... ");
+ if(block.get_data_length() != picture_.data.picture.data_length)
+ return die_("length mismatch");
+ if(0 != memcmp(block.get_data(), picture_.data.picture.data, picture_.data.picture.data_length))
+ return die_("value mismatch");
+ printf("OK\n");
+
+ printf("testing FLAC::Metadata::clone(const FLAC::Metadata::Prototype *)... ");
+ FLAC::Metadata::Prototype *clone_ = FLAC::Metadata::clone(&block);
+ if(0 == clone_)
+ return die_("returned NULL");
+ if(0 == dynamic_cast<FLAC::Metadata::Picture *>(clone_))
+ return die_("downcast is NULL");
+ if(*dynamic_cast<FLAC::Metadata::Picture *>(clone_) != block)
+ return die_("clone is not identical");
+ printf("OK\n");
+ printf("testing Picture::~Picture()... ");
+ delete clone_;
+ printf("OK\n");
+
+
+ printf("PASSED\n\n");
+ return true;
+}
+
+bool test_metadata_object()
+{
+ printf("\n+++ libFLAC++ unit test: metadata objects\n\n");
+
+ init_metadata_blocks_();
+
+ if(!test_metadata_object_streaminfo())
+ return false;
+
+ if(!test_metadata_object_padding())
+ return false;
+
+ if(!test_metadata_object_application())
+ return false;
+
+ if(!test_metadata_object_seektable())
+ return false;
+
+ if(!test_metadata_object_vorbiscomment())
+ return false;
+
+ if(!test_metadata_object_cuesheet())
+ return false;
+
+ if(!test_metadata_object_picture())
+ return false;
+
+ free_metadata_blocks_();
+
+ return true;
+}