add tests for libOggFLAC and libOggFLAC++
authorJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 20 Aug 2002 04:03:24 +0000 (04:03 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 20 Aug 2002 04:03:24 +0000 (04:03 +0000)
30 files changed:
Makefile.lite
src/Makefile.am
src/test_libOggFLAC++/Makefile.am [new file with mode: 0644]
src/test_libOggFLAC++/Makefile.lite [new file with mode: 0644]
src/test_libOggFLAC++/Makefile.vc [new file with mode: 0644]
src/test_libOggFLAC++/README [new file with mode: 0644]
src/test_libOggFLAC++/decoders.cc [new file with mode: 0644]
src/test_libOggFLAC++/decoders.h [new file with mode: 0644]
src/test_libOggFLAC++/encoders.cc [new file with mode: 0644]
src/test_libOggFLAC++/encoders.h [new file with mode: 0644]
src/test_libOggFLAC++/file_utils.c [new file with mode: 0644]
src/test_libOggFLAC++/file_utils.h [new file with mode: 0644]
src/test_libOggFLAC++/main.cc [new file with mode: 0644]
src/test_libOggFLAC/Makefile.am [new file with mode: 0644]
src/test_libOggFLAC/Makefile.lite [new file with mode: 0644]
src/test_libOggFLAC/Makefile.vc [new file with mode: 0644]
src/test_libOggFLAC/README [new file with mode: 0644]
src/test_libOggFLAC/decoders.c [new file with mode: 0644]
src/test_libOggFLAC/decoders.h [new file with mode: 0644]
src/test_libOggFLAC/encoders.c [new file with mode: 0644]
src/test_libOggFLAC/encoders.h [new file with mode: 0644]
src/test_libOggFLAC/file_utils.c [new file with mode: 0644]
src/test_libOggFLAC/file_utils.h [new file with mode: 0644]
src/test_libOggFLAC/main.c [new file with mode: 0644]
src/test_libOggFLAC/metadata_utils.c [new file with mode: 0644]
src/test_libOggFLAC/metadata_utils.h [new file with mode: 0644]
test/Makefile.am
test/Makefile.lite
test/test_libOggFLAC++.sh [new file with mode: 0755]
test/test_libOggFLAC.sh [new file with mode: 0755]

index 7209986..32cfcc2 100644 (file)
@@ -27,8 +27,8 @@
 # clean   : remove all non-distro files
 #
 
-.PHONY: doc libFLAC libFLAC++ libOggFLAC libOggFLAC++ share plugin_xmms flac metaflac test_libFLAC test_libFLAC++ test_streams
-all: doc libFLAC libFLAC++ libOggFLAC libOggFLAC++ share plugin_xmms flac metaflac test_libFLAC test_libFLAC++ test_streams
+.PHONY: doc libFLAC libFLAC++ libOggFLAC libOggFLAC++ share plugin_xmms flac metaflac test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_streams
+all: doc libFLAC libFLAC++ libOggFLAC libOggFLAC++ share plugin_xmms flac metaflac test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_streams
 
 DEFAULT_CONFIG = release
 
@@ -46,13 +46,13 @@ doc:
 libFLAC:
        (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
 
-libFLAC++:
+libFLAC++: libFLAC
        (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
 
-libOggFLAC:
+libOggFLAC: libFLAC
        (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
 
-libOggFLAC++:
+libOggFLAC++: libFLAC
        (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
 
 share:
@@ -76,6 +76,12 @@ test_libFLAC: libFLAC
 test_libFLAC++: libFLAC libFLAC++
        (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
 
+test_libOggFLAC: libFLAC libOggFLAC
+       (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
+
+test_libOggFLAC++: libFLAC libOggFLAC libOggFLAC++
+       (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG))
+
 test: debug
        (cd test ; $(MAKE) -f Makefile.lite)
 
@@ -91,5 +97,7 @@ clean:
        -(cd src/plugin_xmms ; $(MAKE) -f Makefile.lite clean)
        -(cd src/test_libFLAC ; $(MAKE) -f Makefile.lite clean)
        -(cd src/test_libFLAC++ ; $(MAKE) -f Makefile.lite clean)
+       -(cd src/test_libOggFLAC ; $(MAKE) -f Makefile.lite clean)
+       -(cd src/test_libOggFLAC++ ; $(MAKE) -f Makefile.lite clean)
        -(cd src/test_streams ; $(MAKE) -f Makefile.lite clean)
        -(cd test ; $(MAKE) -f Makefile.lite clean)
index 1248f3b..063ead4 100644 (file)
@@ -21,7 +21,8 @@ endif
 
 if FLaC__HAS_OGG
 OGGFLAC_DIRS = libOggFLAC libOggFLAC++
-#@@@ tests not written yet: OGGFLAC_TEST_DIRS = test_libOggFLAC test_libOggFLAC++
+#@@@@ tests not written yet: test_libOggFLAC++
+OGGFLAC_TEST_DIRS = test_libOggFLAC
 endif
 
 EXTRA_DIST = \
diff --git a/src/test_libOggFLAC++/Makefile.am b/src/test_libOggFLAC++/Makefile.am
new file mode 100644 (file)
index 0000000..ad3b6b2
--- /dev/null
@@ -0,0 +1,34 @@
+#  test_libOggFLAC++ - Unit tester for libOggFLAC++
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+EXTRA_DIST = \
+       Makefile.lite \
+       Makefile.vc \
+       README
+
+CFLAGS = @CFLAGS@ @OGG_CFLAGS@
+
+noinst_PROGRAMS = test_libOggFLAC++
+test_libOggFLAC___LDADD = $(top_builddir)/src/libOggFLAC++/libOggFLAC++.la $(top_builddir)/src/libOggFLAC/libOggFLAC.la $(top_builddir)/src/libFLAC/libFLAC.la @OGG_LIBS@ -lm
+test_libOggFLAC___SOURCES = \
+       decoders.cc \
+       encoders.cc \
+       file_utils.c \
+       main.cc \
+       decoders.h \
+       encoders.h \
+       file_utils.h
diff --git a/src/test_libOggFLAC++/Makefile.lite b/src/test_libOggFLAC++/Makefile.lite
new file mode 100644 (file)
index 0000000..ab8db48
--- /dev/null
@@ -0,0 +1,36 @@
+#  test_libOggFLAC++ - Unit tester for libOggFLAC++
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#
+# GNU makefile
+#
+
+PROGRAM_NAME = test_libOggFLAC++
+#@@@ TODO: conditionalize ogg lib path and -logg
+INCLUDES     = -I../../include
+LIBS         = -lOggFLAC++ -lOggFLAC -lFLAC -L$(HOME)/local/lib -logg -lm
+OBJS = \
+       decoders.o \
+       encoders.o \
+       file_utils.o \
+       main.o
+
+include ../../build/exe.mk
+
+LINK = $(CCC) $(LINKAGE)
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/src/test_libOggFLAC++/Makefile.vc b/src/test_libOggFLAC++/Makefile.vc
new file mode 100644 (file)
index 0000000..10692be
--- /dev/null
@@ -0,0 +1,64 @@
+#  test_libOggFLAC++ - Unit tester for libOggFLAC++\r
+#  Copyright (C) 2002  Josh Coalson\r
+#\r
+#  This program is free software; you can redistribute it and/or\r
+#  modify it under the terms of the GNU General Public License\r
+#  as published by the Free Software Foundation; either version 2\r
+#  of the License, or (at your option) any later version.\r
+#\r
+#  This program is distributed in the hope that it will be useful,\r
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+#  GNU General Public License for more details.\r
+#\r
+#  You should have received a copy of the GNU General Public License\r
+#  along with this program; if not, write to the Free Software\r
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+\r
+!include <win32.mak>\r
+\r
+SUFFIXES = .cc\r
+\r
+!IFDEF DEBUG\r
+.c.obj:\r
+       $(cc) $(cdebug) $(cflags) /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX /Od /D "_DEBUG" $<\r
+!else\r
+.c.obj:\r
+       $(cc) /O2 $(crelease) $(cflags) /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX -DNODEBUG $<\r
+!endif\r
+\r
+!IFDEF DEBUG\r
+.cc.obj:\r
+       $(cc) /GR /D "_LIB" /GX $(cdebug) $(cflags) /I "..\..\include" -DSTRICT -YX /Od /D "_DEBUG" $<\r
+!else\r
+.cc.obj:\r
+       $(cc) /GR /D "_LIB" /O2 $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG $<\r
+!endif\r
+\r
+C_FILES= \\r
+       file_utils.c\r
+\r
+CC_FILES= \\r
+       decoders.cc \\r
+       encoders.cc \\r
+       main.cc\r
+\r
+C_OBJS= $(C_FILES:.c=.obj)\r
+CC_OBJS= $(CC_FILES:.cc=.obj)\r
+\r
+all: test_libOggFLAC++.exe\r
+\r
+# can't figure out how to get it to take .cc so we just hack it for now:\r
+decoders.obj: decoders.cc\r
+       $(cc) /GR /D "_LIB" /O2 $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP decoders.cc\r
+encoders.obj: encoders.cc\r
+       $(cc) /GR /D "_LIB" /O2 $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP encoders.cc\r
+main.obj: main.cc\r
+       $(cc) /GR /D "_LIB" /O2 $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP main.cc\r
+\r
+test_libOggFLAC++.exe: $(C_OBJS) $(CC_OBJS)\r
+       link.exe /libpath:"..\..\obj\lib" -out:../../obj/bin/$*.exe $(CC_OBJS) $(C_OBJS) libOggFLAC++.lib libOggFLAC.lib libFLAC.lib ogg_static.lib\r
+\r
+clean:\r
+       -del *.obj *.pch\r
+       -del ..\..\obj\bin\test_libOggFLAC++.exe\r
diff --git a/src/test_libOggFLAC++/README b/src/test_libOggFLAC++/README
new file mode 100644 (file)
index 0000000..3ca35b2
--- /dev/null
@@ -0,0 +1,4 @@
+NOTE: files file_utils.c and file_utils.h are copied from the
+../test_libOggFLAC directory.  It's too much pain to make a
+convenience library for these and CVS can't do soft links, so
+we put up with having two copies of these sources.
diff --git a/src/test_libOggFLAC++/decoders.cc b/src/test_libOggFLAC++/decoders.cc
new file mode 100644 (file)
index 0000000..1cc1258
--- /dev/null
@@ -0,0 +1,865 @@
+/* test_libOggFLAC++ - Unit tester for libOggFLAC++
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "decoders.h"
+extern "C" {
+#include "file_utils.h"
+}
+#include "FLAC/assert.h"
+#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal()
+#include "OggFLAC++/decoder.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
+static ::FLAC__StreamMetadata *expected_metadata_sequence_[6];
+static unsigned num_expected_;
+static const char *oggflacfilename_ = "metadata.ogg";
+static unsigned oggflacfilesize_;
+
+static bool die_(const char *msg)
+{
+       printf("ERROR: %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", (unsigned)size);
+               exit(1);
+       }
+       return x;
+}
+
+static void init_metadata_blocks_()
+{
+       /*
+               most of the actual numbers and data in the blocks don't matter,
+               we just want to make sure the decoder parses them correctly
+
+               remember, the metadata interface gets tested after the decoders,
+               so we do all the metadata manipulation here without it.
+       */
+
+       /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
+    streaminfo_.is_last = false;
+    streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
+    streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
+    streaminfo_.data.stream_info.min_blocksize = 576;
+    streaminfo_.data.stream_info.max_blocksize = 576;
+    streaminfo_.data.stream_info.min_framesize = 0;
+    streaminfo_.data.stream_info.max_framesize = 0;
+    streaminfo_.data.stream_info.sample_rate = 44100;
+    streaminfo_.data.stream_info.channels = 1;
+    streaminfo_.data.stream_info.bits_per_sample = 8;
+    streaminfo_.data.stream_info.total_samples = 0;
+       memset(streaminfo_.data.stream_info.md5sum, 0, 16);
+
+    padding_.is_last = false;
+    padding_.type = ::FLAC__METADATA_TYPE_PADDING;
+    padding_.length = 1234;
+
+    seektable_.is_last = false;
+    seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
+       seektable_.data.seek_table.num_points = 2;
+    seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
+       seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
+       seektable_.data.seek_table.points[0].sample_number = 0;
+       seektable_.data.seek_table.points[0].stream_offset = 0;
+       seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+       seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
+       seektable_.data.seek_table.points[1].stream_offset = 1000;
+       seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+
+    application1_.is_last = false;
+    application1_.type = ::FLAC__METADATA_TYPE_APPLICATION;
+    application1_.length = 8;
+       memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
+       application1_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
+       memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
+
+    application2_.is_last = false;
+    application2_.type = ::FLAC__METADATA_TYPE_APPLICATION;
+    application2_.length = 4;
+       memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
+       application2_.data.application.data = 0;
+
+    vorbiscomment_.is_last = true;
+    vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
+    vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
+       vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
+       vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(8);
+       memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
+       vorbiscomment_.data.vorbis_comment.num_comments = 2;
+       vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
+       vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
+       vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5);
+       memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
+       vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
+       vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
+}
+
+static void free_metadata_blocks_()
+{
+       free(seektable_.data.seek_table.points);
+       free(application1_.data.application.data);
+       free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
+       free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
+       free(vorbiscomment_.data.vorbis_comment.comments);
+}
+
+static bool generate_file_()
+{
+       printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
+
+       expected_metadata_sequence_[0] = &padding_;
+       expected_metadata_sequence_[1] = &seektable_;
+       expected_metadata_sequence_[2] = &application1_;
+       expected_metadata_sequence_[3] = &application2_;
+       expected_metadata_sequence_[4] = &vorbiscomment_;
+       num_expected_ = 5;
+
+       if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
+               return die_("creating the encoded file"); 
+
+       return true;
+}
+
+
+class DecoderCommon {
+public:
+       FILE *file_;
+       unsigned current_metadata_number_;
+       bool ignore_errors_;
+       bool error_occurred_;
+
+       DecoderCommon(): file_(0), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { }
+       ::FLAC__StreamDecoderReadStatus common_read_callback_(FLAC__byte buffer[], unsigned *bytes);
+       ::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__StreamDecoderReadStatus DecoderCommon::common_read_callback_(FLAC__byte buffer[], unsigned *bytes)
+{
+       if(error_occurred_)
+               return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+
+       if(feof(file_))
+               return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+    else if(*bytes > 0) {
+        unsigned bytes_read = ::fread(buffer, 1, *bytes, file_);
+        if(bytes_read == 0) {
+            if(feof(file_))
+                return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+            else
+                return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+        }
+        else {
+            *bytes = bytes_read;
+            return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+        }
+    }
+    else
+        return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
+}
+
+::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("%d... ", 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", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]);
+               error_occurred_ = true;
+       }
+}
+
+class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon {
+public:
+       StreamDecoder(): OggFLAC::Decoder::Stream(), DecoderCommon() { }
+       ~StreamDecoder() { }
+
+       // from OggFLAC::Decoder::Stream
+       ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
+       ::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 die(const char *msg = 0) const;
+
+       bool test_respond();
+};
+
+::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
+{
+       return common_read_callback_(buffer, bytes);
+}
+
+::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::die(const char *msg) const
+{
+       State state = get_state();
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
+
+       return false;
+}
+
+bool StreamDecoder::test_respond()
+{
+       printf("testing init()... ");
+       if(init() != ::OggFLAC__STREAM_DECODER_OK)
+               return die();
+       printf("OK\n");
+
+       current_metadata_number_ = 0;
+
+       if(::fseek(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", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing finish()... ");
+       finish();
+       printf("OK\n");
+
+       return true;
+}
+
+static bool test_stream_decoder()
+{
+       StreamDecoder *decoder;
+
+       printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::Stream\n\n");
+
+       //
+       // test new -> delete
+       //
+       printf("allocating decoder instance... ");
+       decoder = new StreamDecoder();
+       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");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("freeing decoder instance... ");
+       delete decoder;
+       printf("OK\n");
+
+       //
+       // test new -> init -> delete
+       //
+       printf("allocating decoder instance... ");
+       decoder = new StreamDecoder();
+       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");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing init()... ");
+       if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
+               return decoder->die();
+       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 StreamDecoder();
+       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");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing init()... ");
+       if(decoder->init() != ::OggFLAC__STREAM_DECODER_OK)
+               return decoder->die();
+       printf("OK\n");
+
+       printf("testing get_state()... ");
+       OggFLAC::Decoder::Stream::State state = decoder->get_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring());
+
+       printf("testing get_FLAC_stream_decoder_state()... ");
+       FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());
+
+       decoder->current_metadata_number_ = 0;
+       decoder->ignore_errors_ = false;
+       decoder->error_occurred_ = false;
+
+       printf("opening Ogg FLAC file... ");
+       decoder->file_ = ::fopen(oggflacfilename_, "rb");
+       if(0 == decoder->file_) {
+               printf("ERROR\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing process_until_end_of_metadata()... ");
+       if(!decoder->process_until_end_of_metadata())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing process_single()... ");
+       if(!decoder->process_single())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing flush()... ");
+       if(!decoder->flush())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       decoder->ignore_errors_ = true;
+       printf("testing process_single()... ");
+       if(!decoder->process_single())
+               return decoder->die("returned false");
+       printf("OK\n");
+       decoder->ignore_errors_ = false;
+
+       printf("testing process_until_end_of_stream()... ");
+       if(!decoder->process_until_end_of_stream())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing get_channels()... ");
+       {
+               unsigned 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()... ");
+       {
+               unsigned 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()... ");
+       {
+               unsigned 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()... ");
+       {
+               unsigned blocksize = decoder->get_blocksize();
+               /* value could be anything since we're at the last block, so accept any answer */
+               printf("returned %u... OK\n", blocksize);
+       }
+
+       printf("testing get_channel_assignment()... ");
+       {
+               ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment();
+               printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]);
+       }
+
+       printf("testing reset()... ");
+       if(!decoder->reset())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       decoder->current_metadata_number_ = 0;
+
+       printf("rewinding input... ");
+       if(::fseek(decoder->file_, 0, SEEK_SET) < 0) {
+               printf("FAILED, errno = %d\n", errno);
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing process_until_end_of_stream()... ");
+       if(!decoder->process_until_end_of_stream())
+               return decoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing finish()... ");
+       decoder->finish();
+       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;
+       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_;
+
+       if(!decoder->test_respond())
+               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(!decoder->test_respond())
+               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_;
+       expected_metadata_sequence_[num_expected_++] = &seektable_;
+       expected_metadata_sequence_[num_expected_++] = &application1_;
+       expected_metadata_sequence_[num_expected_++] = &application2_;
+
+       if(!decoder->test_respond())
+               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;
+       expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+       expected_metadata_sequence_[num_expected_++] = &padding_;
+       expected_metadata_sequence_[num_expected_++] = &seektable_;
+       expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+       if(!decoder->test_respond())
+               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;
+       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_;
+
+       if(!decoder->test_respond())
+               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;
+       expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+       expected_metadata_sequence_[num_expected_++] = &padding_;
+       expected_metadata_sequence_[num_expected_++] = &seektable_;
+       expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+       if(!decoder->test_respond())
+               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(!decoder->test_respond())
+               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(!decoder->test_respond())
+               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(!decoder->test_respond())
+               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(!decoder->test_respond())
+               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;
+       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_;
+
+       if(!decoder->test_respond())
+               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(!decoder->test_respond())
+               return false;
+
+       /* done, now leave the sequence the way we found it... */
+       num_expected_ = 0;
+       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_;
+
+       ::fclose(decoder->file_);
+
+       printf("freeing decoder instance... ");
+       delete decoder;
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+bool test_decoders()
+{
+       init_metadata_blocks_();
+       if(!generate_file_())
+               return false;
+
+       if(!test_stream_decoder())
+               return false;
+
+       (void) file_utils__remove_file(oggflacfilename_);
+       free_metadata_blocks_();
+
+       return true;
+}
diff --git a/src/test_libOggFLAC++/decoders.h b/src/test_libOggFLAC++/decoders.h
new file mode 100644 (file)
index 0000000..4c06cfe
--- /dev/null
@@ -0,0 +1,24 @@
+/* test_libOggFLAC++ - Unit tester for libOggFLAC++
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H
+#define OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H
+
+bool test_decoders();
+
+#endif
diff --git a/src/test_libOggFLAC++/encoders.cc b/src/test_libOggFLAC++/encoders.cc
new file mode 100644 (file)
index 0000000..58172b5
--- /dev/null
@@ -0,0 +1,458 @@
+/* test_libOggFLAC++ - Unit tester for libOggFLAC++
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "encoders.h"
+extern "C" {
+#include "file_utils.h"
+}
+#include "FLAC/assert.h"
+#include "OggFLAC++/encoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
+static ::FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_ };
+static const unsigned num_metadata_ = 5;
+
+static void *malloc_or_die_(size_t size)
+{
+       void *x = malloc(size);
+       if(0 == x) {
+               fprintf(stderr, "ERROR: out of memory allocating %u bytes\n", (unsigned)size);
+               exit(1);
+       }
+       return x;
+}
+
+static void init_metadata_blocks_()
+{
+       /*
+               most of the actual numbers and data in the blocks don't matter,
+               we just want to make sure the encoder encodes them correctly
+
+               remember, the metadata interface gets tested after the encoders,
+               so we do all the metadata manipulation here without it.
+       */
+
+       /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
+    streaminfo_.is_last = false;
+    streaminfo_.type = ::FLAC__METADATA_TYPE_STREAMINFO;
+    streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
+    streaminfo_.data.stream_info.min_blocksize = 576;
+    streaminfo_.data.stream_info.max_blocksize = 576;
+    streaminfo_.data.stream_info.min_framesize = 0;
+    streaminfo_.data.stream_info.max_framesize = 0;
+    streaminfo_.data.stream_info.sample_rate = 44100;
+    streaminfo_.data.stream_info.channels = 1;
+    streaminfo_.data.stream_info.bits_per_sample = 8;
+    streaminfo_.data.stream_info.total_samples = 0;
+       memset(streaminfo_.data.stream_info.md5sum, 0, 16);
+
+    padding_.is_last = false;
+    padding_.type = ::FLAC__METADATA_TYPE_PADDING;
+    padding_.length = 1234;
+
+    seektable_.is_last = false;
+    seektable_.type = ::FLAC__METADATA_TYPE_SEEKTABLE;
+       seektable_.data.seek_table.num_points = 2;
+    seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
+       seektable_.data.seek_table.points = (::FLAC__StreamMetadata_SeekPoint*)malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(::FLAC__StreamMetadata_SeekPoint));
+       seektable_.data.seek_table.points[0].sample_number = 0;
+       seektable_.data.seek_table.points[0].stream_offset = 0;
+       seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+       seektable_.data.seek_table.points[1].sample_number = ::FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
+       seektable_.data.seek_table.points[1].stream_offset = 1000;
+       seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+
+    application1_.is_last = false;
+    application1_.type = ::FLAC__METADATA_TYPE_APPLICATION;
+    application1_.length = 8;
+       memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
+       application1_.data.application.data = (FLAC__byte*)malloc_or_die_(4);
+       memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
+
+    application2_.is_last = false;
+    application2_.type = ::FLAC__METADATA_TYPE_APPLICATION;
+    application2_.length = 4;
+       memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
+       application2_.data.application.data = 0;
+
+    vorbiscomment_.is_last = true;
+    vorbiscomment_.type = ::FLAC__METADATA_TYPE_VORBIS_COMMENT;
+    vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
+       vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
+       vorbiscomment_.data.vorbis_comment.vendor_string.entry = (FLAC__byte*)malloc_or_die_(8);
+       memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
+       vorbiscomment_.data.vorbis_comment.num_comments = 2;
+       vorbiscomment_.data.vorbis_comment.comments = (::FLAC__StreamMetadata_VorbisComment_Entry*)malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(::FLAC__StreamMetadata_VorbisComment_Entry));
+       vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
+       vorbiscomment_.data.vorbis_comment.comments[0].entry = (FLAC__byte*)malloc_or_die_(5);
+       memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
+       vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
+       vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
+}
+
+static void free_metadata_blocks_()
+{
+       free(seektable_.data.seek_table.points);
+       free(application1_.data.application.data);
+       free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
+       free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
+       free(vorbiscomment_.data.vorbis_comment.comments);
+}
+
+class StreamEncoder : public OggFLAC::Encoder::Stream {
+public:
+       StreamEncoder(): OggFLAC::Encoder::Stream() { }
+       ~StreamEncoder() { }
+
+       // from OggFLAC::Encoder::Stream
+       ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
+
+       bool die(const char *msg = 0) const;
+};
+
+::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
+{
+       (void)buffer, (void)bytes, (void)samples, (void)current_frame;
+
+       return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+bool StreamEncoder::die(const char *msg) const
+{
+       State state = get_state();
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
+       if(state == ::OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
+               FLAC::Encoder::Stream::State state_ = get_FLAC_stream_encoder_state();
+               printf("      FLAC stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
+               if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
+                       FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
+                       printf("      verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
+               }
+       }
+
+       return false;
+}
+
+static bool test_stream_encoder()
+{
+       StreamEncoder *encoder;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::Stream\n\n");
+
+       printf("allocating encoder instance... ");
+       encoder = new StreamEncoder();
+       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");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing set_verify()... ");
+       if(!encoder->set_verify(true))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_streamable_subset()... ");
+       if(!encoder->set_streamable_subset(true))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_mid_side_stereo()... ");
+       if(!encoder->set_do_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_loose_mid_side_stereo()... ");
+       if(!encoder->set_loose_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_channels()... ");
+       if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_bits_per_sample()... ");
+       if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_sample_rate()... ");
+       if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_blocksize()... ");
+       if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_lpc_order()... ");
+       if(!encoder->set_max_lpc_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_qlp_coeff_precision()... ");
+       if(!encoder->set_qlp_coeff_precision(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_qlp_coeff_prec_search()... ");
+       if(!encoder->set_do_qlp_coeff_prec_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_escape_coding()... ");
+       if(!encoder->set_do_escape_coding(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_exhaustive_model_search()... ");
+       if(!encoder->set_do_exhaustive_model_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_min_residual_partition_order()... ");
+       if(!encoder->set_min_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_residual_partition_order()... ");
+       if(!encoder->set_max_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_rice_parameter_search_dist()... ");
+       if(!encoder->set_rice_parameter_search_dist(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_total_samples_estimate()... ");
+       if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_metadata()... ");
+       if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing init()... ");
+       if(encoder->init() != ::OggFLAC__STREAM_ENCODER_OK)
+               return encoder->die();
+       printf("OK\n");
+
+       printf("testing get_state()... ");
+       OggFLAC::Encoder::Stream::State state = encoder->get_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
+
+       printf("testing get_FLAC_stream_encoder_state()... ");
+       FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::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", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
+
+       {
+               FLAC__uint64 absolute_sample;
+               unsigned frame_number;
+               unsigned channel;
+               unsigned 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 %u, 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 %u, 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 %u, 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 %u, 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 %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
+               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 encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing process_interleaved()... ");
+       if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing finish()... ");
+       encoder->finish();
+       printf("OK\n");
+
+       printf("freeing encoder instance... ");
+       delete encoder;
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+bool test_encoders()
+{
+       init_metadata_blocks_();
+
+       if(!test_stream_encoder())
+               return false;
+
+       free_metadata_blocks_();
+
+       return true;
+}
diff --git a/src/test_libOggFLAC++/encoders.h b/src/test_libOggFLAC++/encoders.h
new file mode 100644 (file)
index 0000000..05fe956
--- /dev/null
@@ -0,0 +1,24 @@
+/* test_libOggFLAC++ - Unit tester for libOggFLAC++
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H
+#define OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H
+
+bool test_encoders();
+
+#endif
diff --git a/src/test_libOggFLAC++/file_utils.c b/src/test_libOggFLAC++/file_utils.c
new file mode 100644 (file)
index 0000000..2f8e7c7
--- /dev/null
@@ -0,0 +1,168 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "file_utils.h"
+#include "FLAC/assert.h"
+#include "OggFLAC/stream_encoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#if defined _MSC_VER || defined __MINGW32__
+#include <io.h> /* for chmod(), unlink */
+#endif
+#include <sys/stat.h> /* for stat(), chmod() */
+#if defined _WIN32 && !defined __CYGWIN__
+#else
+#include <unistd.h> /* for unlink() */
+#endif
+
+#ifdef min
+#undef min
+#endif
+#define min(a,b) ((a)<(b)?(a):(b))
+
+typedef struct {
+       FILE *file;
+} encoder_client_struct;
+
+static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+{
+       encoder_client_struct *ecd = (encoder_client_struct*)client_data;
+
+       (void)encoder, (void)samples, (void)current_frame;
+
+       if(fwrite(buffer, 1, bytes, ecd->file) != bytes)
+               return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
+       else
+               return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+FLAC__bool file_utils__change_stats(const char *filename, FLAC__bool read_only)
+{
+       struct stat stats;
+
+       if(0 == stat(filename, &stats)) {
+#if !defined _MSC_VER && !defined __MINGW32__
+               if(read_only) {
+                       stats.st_mode &= ~S_IWUSR;
+                       stats.st_mode &= ~S_IWGRP;
+                       stats.st_mode &= ~S_IWOTH;
+               }
+               else {
+                       stats.st_mode |= S_IWUSR;
+                       stats.st_mode |= S_IWGRP;
+                       stats.st_mode |= S_IWOTH;
+               }
+#else
+               if(read_only)
+                       stats.st_mode &= ~S_IWRITE;
+               else
+                       stats.st_mode |= S_IWRITE;
+#endif
+               if(0 != chmod(filename, stats.st_mode))
+                       return false;
+       }
+       else
+               return false;
+
+       return true;
+}
+
+FLAC__bool file_utils__remove_file(const char *filename)
+{
+       return file_utils__change_stats(filename, /*read_only=*/false) && 0 == unlink(filename);
+}
+
+FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
+{
+       FLAC__int32 samples[1024];
+       OggFLAC__StreamEncoder *encoder;
+       encoder_client_struct encoder_client_data;
+       unsigned i, n;
+
+       FLAC__ASSERT(0 != output_filename);
+       FLAC__ASSERT(0 != streaminfo);
+       FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO);
+       FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0));
+
+       if(0 == (encoder_client_data.file = fopen(output_filename, "wb")))
+               return false;
+
+       encoder = OggFLAC__stream_encoder_new();
+       if(0 == encoder) {
+               fclose(encoder_client_data.file);
+               return false;
+       }
+
+       OggFLAC__stream_encoder_set_verify(encoder, true);
+       OggFLAC__stream_encoder_set_streamable_subset(encoder, true);
+       OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
+       OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false);
+       OggFLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels);
+       OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample);
+       OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate);
+       OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize);
+       OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0);
+       OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0);
+       OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false);
+       OggFLAC__stream_encoder_set_do_escape_coding(encoder, false);
+       OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false);
+       OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0);
+       OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0);
+       OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0);
+       OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
+       OggFLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
+       OggFLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_);
+       OggFLAC__stream_encoder_set_client_data(encoder, &encoder_client_data);
+
+       if(OggFLAC__stream_encoder_init(encoder) != OggFLAC__STREAM_ENCODER_OK) {
+               fclose(encoder_client_data.file);
+               return false;
+       }
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       while(length > 0) {
+               n = min(length, sizeof(samples) / sizeof(FLAC__int32));
+
+               if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, n)) {
+                       fclose(encoder_client_data.file);
+                       return false;
+               }
+
+               length -= n;
+       }
+
+       OggFLAC__stream_encoder_finish(encoder);
+
+       fclose(encoder_client_data.file);
+
+       OggFLAC__stream_encoder_delete(encoder);
+
+       if(0 != output_filesize) {
+               struct stat filestats;
+
+               if(stat(output_filename, &filestats) != 0)
+                       return false;
+               else
+                       *output_filesize = (unsigned)filestats.st_size;
+       }
+
+       return true;
+}
diff --git a/src/test_libOggFLAC++/file_utils.h b/src/test_libOggFLAC++/file_utils.h
new file mode 100644 (file)
index 0000000..3a20403
--- /dev/null
@@ -0,0 +1,30 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H
+#define OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H
+
+#include "FLAC/format.h"
+
+FLAC__bool file_utils__change_stats(const char *filename, FLAC__bool read_only);
+
+FLAC__bool file_utils__remove_file(const char *filename);
+
+FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata);
+
+#endif
diff --git a/src/test_libOggFLAC++/main.cc b/src/test_libOggFLAC++/main.cc
new file mode 100644 (file)
index 0000000..b024f8b
--- /dev/null
@@ -0,0 +1,33 @@
+/* test_libOggFLAC++ - Unit tester for libOggFLAC++
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "decoders.h"
+#include "encoders.h"
+
+int main(int argc, char *argv[])
+{
+       (void)argc, (void)argv;
+
+       if(!test_encoders())
+               return 1;
+
+       if(!test_decoders())
+               return 1;
+
+       return 0;
+}
diff --git a/src/test_libOggFLAC/Makefile.am b/src/test_libOggFLAC/Makefile.am
new file mode 100644 (file)
index 0000000..cf50fce
--- /dev/null
@@ -0,0 +1,36 @@
+#  test_libOggFLAC - Unit tester for libOggFLAC
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+EXTRA_DIST = \
+       Makefile.lite \
+       Makefile.vc
+
+CFLAGS = @CFLAGS@ @OGG_CFLAGS@
+INCLUDES = 
+
+noinst_PROGRAMS = test_libOggFLAC
+test_libOggFLAC_LDADD = $(top_builddir)/src/libOggFLAC/libOggFLAC.la $(top_builddir)/src/libOggFLAC/libFLAC.la @OGG_LIBS@ -lm
+test_libOggFLAC_SOURCES = \
+       decoders.c \
+       encoders.c \
+       file_utils.c \
+       main.c \
+       metadata_utils.c \
+       decoders.h \
+       encoders.h \
+       file_utils.h \
+       metadata_utils.h
diff --git a/src/test_libOggFLAC/Makefile.lite b/src/test_libOggFLAC/Makefile.lite
new file mode 100644 (file)
index 0000000..f171d64
--- /dev/null
@@ -0,0 +1,35 @@
+#  test_libOggFLAC - Unit tester for libOggFLAC
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#
+# GNU makefile
+#
+
+PROGRAM_NAME = test_libOggFLAC
+#@@@ TODO: conditionalize ogg lib path and -logg
+INCLUDES     = -I../../include
+LIBS         = -lOggFLAC -lFLAC -lm -L$(HOME)/local/lib -logg
+OBJS = \
+       decoders.o \
+       encoders.o \
+       file_utils.o \
+       main.o \
+       metadata_utils.o
+
+include ../../build/exe.mk
+
+# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/src/test_libOggFLAC/Makefile.vc b/src/test_libOggFLAC/Makefile.vc
new file mode 100644 (file)
index 0000000..5187b9e
--- /dev/null
@@ -0,0 +1,44 @@
+#  test_libOggFLAC - Unit tester for libOggFLAC\r
+#  Copyright (C) 2002  Josh Coalson\r
+#\r
+#  This program is free software; you can redistribute it and/or\r
+#  modify it under the terms of the GNU General Public License\r
+#  as published by the Free Software Foundation; either version 2\r
+#  of the License, or (at your option) any later version.\r
+#\r
+#  This program is distributed in the hope that it will be useful,\r
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+#  GNU General Public License for more details.\r
+#\r
+#  You should have received a copy of the GNU General Public License\r
+#  along with this program; if not, write to the Free Software\r
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+\r
+!include <win32.mak>\r
+\r
+!IFDEF DEBUG\r
+.c.obj:\r
+       $(cc) $(cdebug) $(cflags) /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX /Od /D "_DEBUG" $<\r
+!else\r
+.c.obj:\r
+       $(cc) /O2 $(crelease) $(cflags) /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX -DNODEBUG $<\r
+!endif\r
+\r
+C_FILES= \\r
+       decoders.c \\r
+       encoders.c \\r
+       file_utils.c \\r
+       main.c \\r
+       metadata_utils.c\r
+\r
+OBJS= $(C_FILES:.c=.obj)\r
+\r
+all: test_libOggFLAC.exe\r
+\r
+test_libOggFLAC.exe: $(OBJS)\r
+       link.exe /libpath:"..\..\obj\lib" -out:../../obj/bin/$*.exe $(OBJS) libOggFLAC.lib libFLAC.lib ogg_static.lib\r
+\r
+clean:\r
+       -del *.obj *.pch\r
+       -del ..\..\obj\bin\test_libOggFLAC.exe\r
diff --git a/src/test_libOggFLAC/README b/src/test_libOggFLAC/README
new file mode 100644 (file)
index 0000000..9e00a22
--- /dev/null
@@ -0,0 +1,7 @@
+NOTE: files metadata_utils.c and metadata_utils.h are copied from
+the ../test_libFLAC directory.  It's too much pain to make a
+convenience library for these and CVS can't do soft links, so
+we put up with having two copies of these sources.
+
+file_utils.c and file_utils.h are also copies, with trivial
+changes, for use in this package.
diff --git a/src/test_libOggFLAC/decoders.c b/src/test_libOggFLAC/decoders.c
new file mode 100644 (file)
index 0000000..0e5a463
--- /dev/null
@@ -0,0 +1,813 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "decoders.h"
+#include "file_utils.h"
+#include "metadata_utils.h"
+#include "FLAC/assert.h"
+#include "OggFLAC/stream_decoder.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct {
+       FILE *file;
+       unsigned current_metadata_number;
+       FLAC__bool ignore_errors;
+       FLAC__bool error_occurred;
+} stream_decoder_client_data_struct;
+
+static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
+static FLAC__StreamMetadata *expected_metadata_sequence_[6];
+static unsigned num_expected_;
+static const char *oggflacfilename_ = "metadata.ogg";
+static unsigned oggflacfilesize_;
+
+static FLAC__bool die_(const char *msg)
+{
+       printf("ERROR: %s\n", msg);
+       return false;
+}
+
+static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamDecoder *decoder)
+{
+       OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder);
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]);
+       if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
+               FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
+               printf("      FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
+       }
+
+       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", (unsigned)size);
+               exit(1);
+       }
+       return x;
+}
+
+static void init_metadata_blocks_()
+{
+       /*
+               most of the actual numbers and data in the blocks don't matter,
+               we just want to make sure the decoder parses them correctly
+
+               remember, the metadata interface gets tested after the decoders,
+               so we do all the metadata manipulation here without it.
+       */
+
+       /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
+    streaminfo_.is_last = false;
+    streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
+    streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
+    streaminfo_.data.stream_info.min_blocksize = 576;
+    streaminfo_.data.stream_info.max_blocksize = 576;
+    streaminfo_.data.stream_info.min_framesize = 0;
+    streaminfo_.data.stream_info.max_framesize = 0;
+    streaminfo_.data.stream_info.sample_rate = 44100;
+    streaminfo_.data.stream_info.channels = 1;
+    streaminfo_.data.stream_info.bits_per_sample = 8;
+    streaminfo_.data.stream_info.total_samples = 0;
+       memset(streaminfo_.data.stream_info.md5sum, 0, 16);
+
+    padding_.is_last = false;
+    padding_.type = FLAC__METADATA_TYPE_PADDING;
+    padding_.length = 1234;
+
+    seektable_.is_last = false;
+    seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
+       seektable_.data.seek_table.num_points = 2;
+    seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
+       seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
+       seektable_.data.seek_table.points[0].sample_number = 0;
+       seektable_.data.seek_table.points[0].stream_offset = 0;
+       seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+       seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
+       seektable_.data.seek_table.points[1].stream_offset = 1000;
+       seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+
+    application1_.is_last = false;
+    application1_.type = FLAC__METADATA_TYPE_APPLICATION;
+    application1_.length = 8;
+       memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
+       application1_.data.application.data = malloc_or_die_(4);
+       memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
+
+    application2_.is_last = false;
+    application2_.type = FLAC__METADATA_TYPE_APPLICATION;
+    application2_.length = 4;
+       memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
+       application2_.data.application.data = 0;
+
+    vorbiscomment_.is_last = true;
+    vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
+    vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
+       vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
+       vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
+       memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
+       vorbiscomment_.data.vorbis_comment.num_comments = 2;
+       vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
+       vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
+       vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
+       memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
+       vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
+       vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
+}
+
+static void free_metadata_blocks_()
+{
+       free(seektable_.data.seek_table.points);
+       free(application1_.data.application.data);
+       free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
+       free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
+       free(vorbiscomment_.data.vorbis_comment.comments);
+}
+
+static FLAC__bool generate_file_()
+{
+       printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
+
+       expected_metadata_sequence_[0] = &padding_;
+       expected_metadata_sequence_[1] = &seektable_;
+       expected_metadata_sequence_[2] = &application1_;
+       expected_metadata_sequence_[3] = &application2_;
+       expected_metadata_sequence_[4] = &vorbiscomment_;
+       num_expected_ = 5;
+
+       if(!file_utils__generate_oggflacfile(oggflacfilename_, &oggflacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
+               return die_("creating the encoded file"); 
+
+       return true;
+}
+
+static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
+{
+       stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
+
+       (void)decoder;
+
+       if(0 == dcd) {
+               printf("ERROR: client_data in read callback is NULL\n");
+               return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+       }
+
+       if(dcd->error_occurred)
+               return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+
+       if(feof(dcd->file))
+               return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+    else if(*bytes > 0) {
+        unsigned bytes_read = fread(buffer, 1, *bytes, dcd->file);
+        if(bytes_read == 0) {
+            if(feof(dcd->file))
+                return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+            else
+                return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+        }
+        else {
+            *bytes = bytes_read;
+            return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+        }
+    }
+    else
+        return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
+}
+
+static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
+{
+       stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
+
+       (void)decoder, (void)buffer;
+
+       if(0 == dcd) {
+               printf("ERROR: client_data in write callback is NULL\n");
+               return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+       }
+
+       if(dcd->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;
+}
+
+static void stream_decoder_metadata_callback_(const OggFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
+{
+       stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
+
+       (void)decoder;
+
+       if(0 == dcd) {
+               printf("ERROR: client_data in metadata callback is NULL\n");
+               return;
+       }
+
+       if(dcd->error_occurred)
+               return;
+
+       printf("%d... ", dcd->current_metadata_number);
+       fflush(stdout);
+
+       if(dcd->current_metadata_number >= num_expected_) {
+               (void)die_("got more metadata blocks than expected");
+               dcd->error_occurred = true;
+       }
+       else {
+               if(!compare_block_(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
+                       (void)die_("metadata block mismatch");
+                       dcd->error_occurred = true;
+               }
+       }
+       dcd->current_metadata_number++;
+}
+
+static void stream_decoder_error_callback_(const OggFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+{
+       stream_decoder_client_data_struct *dcd = (stream_decoder_client_data_struct*)client_data;
+
+       (void)decoder;
+
+       if(0 == dcd) {
+               printf("ERROR: client_data in error callback is NULL\n");
+               return;
+       }
+
+       if(!dcd->ignore_errors) {
+               printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
+               dcd->error_occurred = true;
+       }
+}
+
+static FLAC__bool stream_decoder_test_respond_(OggFLAC__StreamDecoder *decoder, stream_decoder_client_data_struct *dcd)
+{
+       if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
+               return die_s_("at OggFLAC__stream_decoder_set_read_callback(), returned false", decoder);
+
+       if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
+               return die_s_("at OggFLAC__stream_decoder_set_write_callback(), returned false", decoder);
+
+       if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
+               return die_s_("at OggFLAC__stream_decoder_set_metadata_callback(), returned false", decoder);
+
+       if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
+               return die_s_("at OggFLAC__stream_decoder_set_error_callback(), returned false", decoder);
+
+       if(!OggFLAC__stream_decoder_set_client_data(decoder, dcd))
+               return die_s_("at OggFLAC__stream_decoder_set_client_data(), returned false", decoder);
+
+       printf("testing OggFLAC__stream_decoder_init()... ");
+       if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
+               return die_s_(0, decoder);
+       printf("OK\n");
+
+       dcd->current_metadata_number = 0;
+
+       if(fseek(dcd->file, 0, SEEK_SET) < 0) {
+               printf("FAILED rewinding input, errno = %d\n", errno);
+               return false;
+       }
+
+       printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_finish()... ");
+       OggFLAC__stream_decoder_finish(decoder);
+       printf("OK\n");
+
+       return true;
+}
+
+static FLAC__bool test_stream_decoder()
+{
+       OggFLAC__StreamDecoder *decoder;
+       OggFLAC__StreamDecoderState state;
+       stream_decoder_client_data_struct decoder_client_data;
+
+       printf("\n+++ libOggFLAC unit test: OggFLAC__StreamDecoder\n\n");
+
+       printf("testing OggFLAC__stream_decoder_new()... ");
+       decoder = OggFLAC__stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_delete()... ");
+       OggFLAC__stream_decoder_delete(decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_new()... ");
+       decoder = OggFLAC__stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_init()... ");
+       if(OggFLAC__stream_decoder_init(decoder) == OggFLAC__STREAM_DECODER_OK)
+               return die_s_(0, decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_delete()... ");
+       OggFLAC__stream_decoder_delete(decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+
+       printf("testing OggFLAC__stream_decoder_new()... ");
+       decoder = OggFLAC__stream_decoder_new();
+       if(0 == decoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_read_callback()... ");
+       if(!OggFLAC__stream_decoder_set_read_callback(decoder, stream_decoder_read_callback_))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_write_callback()... ");
+       if(!OggFLAC__stream_decoder_set_write_callback(decoder, stream_decoder_write_callback_))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_callback()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_callback(decoder, stream_decoder_metadata_callback_))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_error_callback()... ");
+       if(!OggFLAC__stream_decoder_set_error_callback(decoder, stream_decoder_error_callback_))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_client_data()... ");
+       if(!OggFLAC__stream_decoder_set_client_data(decoder, &decoder_client_data))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_init()... ");
+       if(OggFLAC__stream_decoder_init(decoder) != OggFLAC__STREAM_DECODER_OK)
+               return die_s_(0, decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_get_state()... ");
+       state = OggFLAC__stream_decoder_get_state(decoder);
+       printf("returned state = %u (%s)... OK\n", state, OggFLAC__StreamDecoderStateString[state]);
+
+       decoder_client_data.current_metadata_number = 0;
+       decoder_client_data.ignore_errors = false;
+       decoder_client_data.error_occurred = false;
+
+       printf("opening Ogg FLAC file... ");
+       decoder_client_data.file = fopen(oggflacfilename_, "rb");
+       if(0 == decoder_client_data.file) {
+               printf("ERROR\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_process_until_end_of_metadata()... ");
+       if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_process_single()... ");
+       if(!OggFLAC__stream_decoder_process_single(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_flush()... ");
+       if(!OggFLAC__stream_decoder_flush(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       decoder_client_data.ignore_errors = true;
+       printf("testing OggFLAC__stream_decoder_process_single()... ");
+       if(!OggFLAC__stream_decoder_process_single(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+       decoder_client_data.ignore_errors = false;
+
+       printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_get_channels()... ");
+       {
+               unsigned channels = OggFLAC__stream_decoder_get_channels(decoder);
+               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 OggFLAC__stream_decoder_get_bits_per_sample()... ");
+       {
+               unsigned bits_per_sample = OggFLAC__stream_decoder_get_bits_per_sample(decoder);
+               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 OggFLAC__stream_decoder_get_sample_rate()... ");
+       {
+               unsigned sample_rate = OggFLAC__stream_decoder_get_sample_rate(decoder);
+               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 OggFLAC__stream_decoder_get_blocksize()... ");
+       {
+               unsigned blocksize = OggFLAC__stream_decoder_get_blocksize(decoder);
+               /* value could be anything since we're at the last block, so accept any answer */
+               printf("returned %u... OK\n", blocksize);
+       }
+
+       printf("testing OggFLAC__stream_decoder_get_channel_assignment()... ");
+       {
+               FLAC__ChannelAssignment ca = OggFLAC__stream_decoder_get_channel_assignment(decoder);
+               printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
+       }
+
+       printf("testing OggFLAC__stream_decoder_reset()... ");
+       if(!OggFLAC__stream_decoder_reset(decoder)) {
+               state = OggFLAC__stream_decoder_get_state(decoder);
+               printf("FAILED, returned false, state = %u (%s)\n", state, FLAC__StreamDecoderStateString[state]);
+               return false;
+       }
+       printf("OK\n");
+
+       decoder_client_data.current_metadata_number = 0;
+
+       printf("rewinding input... ");
+       if(fseek(decoder_client_data.file, 0, SEEK_SET) < 0) {
+               printf("FAILED, errno = %d\n", errno);
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
+       if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_finish()... ");
+       OggFLAC__stream_decoder_finish(decoder);
+       printf("OK\n");
+
+       /*
+        * respond all
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       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_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * respond all, ignore VORBIS_COMMENT
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       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_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * respond all, ignore APPLICATION
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+       expected_metadata_sequence_[num_expected_++] = &padding_;
+       expected_metadata_sequence_[num_expected_++] = &seektable_;
+       expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * respond all, ignore APPLICATION id of app#1
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       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_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * respond all, ignore APPLICATION id of app#1 & app#2
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &streaminfo_;
+       expected_metadata_sequence_[num_expected_++] = &padding_;
+       expected_metadata_sequence_[num_expected_++] = &seektable_;
+       expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all, respond VORBIS_COMMENT
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all, respond APPLICATION
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &application1_;
+       expected_metadata_sequence_[num_expected_++] = &application2_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all, respond APPLICATION id of app#1
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &application1_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all, respond APPLICATION id of app#1 & app#2
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &application1_;
+       expected_metadata_sequence_[num_expected_++] = &application2_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * respond all, ignore APPLICATION, respond APPLICATION id of app#1
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       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_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /*
+        * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
+        */
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
+       if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
+               return die_s_("returned false", decoder);
+       printf("OK\n");
+
+       num_expected_ = 0;
+       expected_metadata_sequence_[num_expected_++] = &application2_;
+
+       if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
+               return false;
+
+       /* done, now leave the sequence the way we found it... */
+       num_expected_ = 0;
+       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_;
+
+       printf("testing OggFLAC__stream_decoder_delete()... ");
+       OggFLAC__stream_decoder_delete(decoder);
+       printf("OK\n");
+
+       fclose(decoder_client_data.file);
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+FLAC__bool test_decoders()
+{
+       init_metadata_blocks_();
+       if(!generate_file_())
+               return false;
+
+       if(!test_stream_decoder())
+               return false;
+
+       (void) file_utils__remove_file(oggflacfilename_);
+       free_metadata_blocks_();
+
+       return true;
+}
diff --git a/src/test_libOggFLAC/decoders.h b/src/test_libOggFLAC/decoders.h
new file mode 100644 (file)
index 0000000..f9f2fd7
--- /dev/null
@@ -0,0 +1,26 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLAC_DECODERS_H
+#define OggFLAC__TEST_LIBOGGFLAC_DECODERS_H
+
+#include "FLAC/ordinals.h"
+
+FLAC__bool test_decoders();
+
+#endif
diff --git a/src/test_libOggFLAC/encoders.c b/src/test_libOggFLAC/encoders.c
new file mode 100644 (file)
index 0000000..547c870
--- /dev/null
@@ -0,0 +1,452 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "encoders.h"
+#include "file_utils.h"
+#include "FLAC/assert.h"
+#include "OggFLAC/stream_encoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
+static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_ };
+static const unsigned num_metadata_ = 5;
+static const char *oggflacfilename_ = "metadata.ogg";
+
+static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamEncoder *encoder)
+{
+       OggFLAC__StreamEncoderState state = OggFLAC__stream_encoder_get_state(encoder);
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
+       if(state == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
+               FLAC__StreamEncoderState state_ = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
+               printf("      FLAC stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
+               if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
+                       FLAC__StreamDecoderState dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
+                       printf("      verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
+               }
+       }
+
+       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", (unsigned)size);
+               exit(1);
+       }
+       return x;
+}
+
+static void init_metadata_blocks_()
+{
+       /*
+               most of the actual numbers and data in the blocks don't matter,
+               we just want to make sure the encoder encodes them correctly
+
+               remember, the metadata interface gets tested after the encoders,
+               so we do all the metadata manipulation here without it.
+       */
+
+       /* min/max_framesize and md5sum don't get written at first, so we have to leave them 0 */
+    streaminfo_.is_last = false;
+    streaminfo_.type = FLAC__METADATA_TYPE_STREAMINFO;
+    streaminfo_.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
+    streaminfo_.data.stream_info.min_blocksize = 576;
+    streaminfo_.data.stream_info.max_blocksize = 576;
+    streaminfo_.data.stream_info.min_framesize = 0;
+    streaminfo_.data.stream_info.max_framesize = 0;
+    streaminfo_.data.stream_info.sample_rate = 44100;
+    streaminfo_.data.stream_info.channels = 1;
+    streaminfo_.data.stream_info.bits_per_sample = 8;
+    streaminfo_.data.stream_info.total_samples = 0;
+       memset(streaminfo_.data.stream_info.md5sum, 0, 16);
+
+    padding_.is_last = false;
+    padding_.type = FLAC__METADATA_TYPE_PADDING;
+    padding_.length = 1234;
+
+    seektable_.is_last = false;
+    seektable_.type = FLAC__METADATA_TYPE_SEEKTABLE;
+       seektable_.data.seek_table.num_points = 2;
+    seektable_.length = seektable_.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
+       seektable_.data.seek_table.points = malloc_or_die_(seektable_.data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
+       seektable_.data.seek_table.points[0].sample_number = 0;
+       seektable_.data.seek_table.points[0].stream_offset = 0;
+       seektable_.data.seek_table.points[0].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+       seektable_.data.seek_table.points[1].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
+       seektable_.data.seek_table.points[1].stream_offset = 1000;
+       seektable_.data.seek_table.points[1].frame_samples = streaminfo_.data.stream_info.min_blocksize;
+
+    application1_.is_last = false;
+    application1_.type = FLAC__METADATA_TYPE_APPLICATION;
+    application1_.length = 8;
+       memcpy(application1_.data.application.id, "\xfe\xdc\xba\x98", 4);
+       application1_.data.application.data = malloc_or_die_(4);
+       memcpy(application1_.data.application.data, "\xf0\xe1\xd2\xc3", 4);
+
+    application2_.is_last = false;
+    application2_.type = FLAC__METADATA_TYPE_APPLICATION;
+    application2_.length = 4;
+       memcpy(application2_.data.application.id, "\x76\x54\x32\x10", 4);
+       application2_.data.application.data = 0;
+
+    vorbiscomment_.is_last = true;
+    vorbiscomment_.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
+    vorbiscomment_.length = (4 + 8) + 4 + (4 + 5) + (4 + 0);
+       vorbiscomment_.data.vorbis_comment.vendor_string.length = 8;
+       vorbiscomment_.data.vorbis_comment.vendor_string.entry = malloc_or_die_(8);
+       memcpy(vorbiscomment_.data.vorbis_comment.vendor_string.entry, "flac 1.x", 8);
+       vorbiscomment_.data.vorbis_comment.num_comments = 2;
+       vorbiscomment_.data.vorbis_comment.comments = malloc_or_die_(vorbiscomment_.data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
+       vorbiscomment_.data.vorbis_comment.comments[0].length = 5;
+       vorbiscomment_.data.vorbis_comment.comments[0].entry = malloc_or_die_(5);
+       memcpy(vorbiscomment_.data.vorbis_comment.comments[0].entry, "ab=cd", 5);
+       vorbiscomment_.data.vorbis_comment.comments[1].length = 0;
+       vorbiscomment_.data.vorbis_comment.comments[1].entry = 0;
+}
+
+static void free_metadata_blocks_()
+{
+       free(seektable_.data.seek_table.points);
+       free(application1_.data.application.data);
+       free(vorbiscomment_.data.vorbis_comment.vendor_string.entry);
+       free(vorbiscomment_.data.vorbis_comment.comments[0].entry);
+       free(vorbiscomment_.data.vorbis_comment.comments);
+}
+
+static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+{
+       (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
+       return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+static FLAC__bool test_stream_encoder()
+{
+       OggFLAC__StreamEncoder *encoder;
+       OggFLAC__StreamEncoderState state;
+       FLAC__StreamEncoderState state_;
+       FLAC__StreamDecoderState dstate;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libOggFLAC unit test: OggFLAC__StreamEncoder\n\n");
+
+       printf("testing OggFLAC__stream_encoder_new()... ");
+       encoder = OggFLAC__stream_encoder_new();
+       if(0 == encoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_verify()... ");
+       if(!OggFLAC__stream_encoder_set_verify(encoder, true))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_streamable_subset()... ");
+       if(!OggFLAC__stream_encoder_set_streamable_subset(encoder, true))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_do_mid_side_stereo()... ");
+       if(!OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_loose_mid_side_stereo()... ");
+       if(!OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_channels()... ");
+       if(!OggFLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_bits_per_sample()... ");
+       if(!OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_sample_rate()... ");
+       if(!OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_blocksize()... ");
+       if(!OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_max_lpc_order()... ");
+       if(!OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_qlp_coeff_precision()... ");
+       if(!OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
+       if(!OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_do_escape_coding()... ");
+       if(!OggFLAC__stream_encoder_set_do_escape_coding(encoder, false))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_do_exhaustive_model_search()... ");
+       if(!OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_min_residual_partition_order()... ");
+       if(!OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_max_residual_partition_order()... ");
+       if(!OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_rice_parameter_search_dist()... ");
+       if(!OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_total_samples_estimate()... ");
+       if(!OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_metadata()... ");
+       if(!OggFLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_write_callback()... ");
+       if(!OggFLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_set_client_data()... ");
+       if(!OggFLAC__stream_encoder_set_client_data(encoder, 0))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_init()... ");
+       if(OggFLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
+               return die_s_(0, encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_state()... ");
+       state = OggFLAC__stream_encoder_get_state(encoder);
+       printf("returned state = %u (%s)... OK\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
+
+       printf("testing OggFLAC__stream_encoder_get_FLAC_stream_encoder_state()... ");
+       state_ = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
+       printf("returned state = %u (%s)... OK\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
+
+       printf("testing OggFLAC__stream_encoder_get_verify_decoder_state()... ");
+       dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
+       printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
+
+       {
+               FLAC__uint64 absolute_sample;
+               unsigned frame_number;
+               unsigned channel;
+               unsigned sample;
+               FLAC__int32 expected;
+               FLAC__int32 got;
+
+               printf("testing OggFLAC__stream_encoder_get_verify_decoder_error_stats()... ");
+               OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
+               printf("OK\n");
+       }
+
+       printf("testing OggFLAC__stream_encoder_get_verify()... ");
+       if(OggFLAC__stream_encoder_get_verify(encoder) != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_streamable_subset()... ");
+       if(OggFLAC__stream_encoder_get_streamable_subset(encoder) != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_do_mid_side_stereo()... ");
+       if(OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_loose_mid_side_stereo()... ");
+       if(OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_channels()... ");
+       if(OggFLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, OggFLAC__stream_encoder_get_channels(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_bits_per_sample()... ");
+       if(OggFLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__stream_encoder_get_bits_per_sample(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_sample_rate()... ");
+       if(OggFLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, OggFLAC__stream_encoder_get_sample_rate(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_blocksize()... ");
+       if(OggFLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, OggFLAC__stream_encoder_get_blocksize(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_max_lpc_order()... ");
+       if(OggFLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_lpc_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_qlp_coeff_precision()... ");
+       (void)OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder);
+       /* we asked the encoder to auto select this so we accept anything */
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
+       if(OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_do_escape_coding()... ");
+       if(OggFLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_do_exhaustive_model_search()... ");
+       if(OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_min_residual_partition_order()... ");
+       if(OggFLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_min_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_max_residual_partition_order()... ");
+       if(OggFLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_rice_parameter_search_dist()... ");
+       if(OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_get_total_samples_estimate()... ");
+       if(OggFLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
+               printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, OggFLAC__stream_encoder_get_total_samples_estimate(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       printf("testing OggFLAC__stream_encoder_process()... ");
+       if(!OggFLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_process_interleaved()... ");
+       if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_s_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_finish()... ");
+       OggFLAC__stream_encoder_finish(encoder);
+       printf("OK\n");
+
+       printf("testing OggFLAC__stream_encoder_delete()... ");
+       OggFLAC__stream_encoder_delete(encoder);
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+FLAC__bool test_encoders()
+{
+       init_metadata_blocks_();
+
+       if(!test_stream_encoder())
+               return false;
+
+       (void) file_utils__remove_file(oggflacfilename_);
+       free_metadata_blocks_();
+
+       return true;
+}
diff --git a/src/test_libOggFLAC/encoders.h b/src/test_libOggFLAC/encoders.h
new file mode 100644 (file)
index 0000000..9732be9
--- /dev/null
@@ -0,0 +1,26 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H
+#define OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H
+
+#include "FLAC/ordinals.h"
+
+FLAC__bool test_encoders();
+
+#endif
diff --git a/src/test_libOggFLAC/file_utils.c b/src/test_libOggFLAC/file_utils.c
new file mode 100644 (file)
index 0000000..2f8e7c7
--- /dev/null
@@ -0,0 +1,168 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "file_utils.h"
+#include "FLAC/assert.h"
+#include "OggFLAC/stream_encoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#if defined _MSC_VER || defined __MINGW32__
+#include <io.h> /* for chmod(), unlink */
+#endif
+#include <sys/stat.h> /* for stat(), chmod() */
+#if defined _WIN32 && !defined __CYGWIN__
+#else
+#include <unistd.h> /* for unlink() */
+#endif
+
+#ifdef min
+#undef min
+#endif
+#define min(a,b) ((a)<(b)?(a):(b))
+
+typedef struct {
+       FILE *file;
+} encoder_client_struct;
+
+static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+{
+       encoder_client_struct *ecd = (encoder_client_struct*)client_data;
+
+       (void)encoder, (void)samples, (void)current_frame;
+
+       if(fwrite(buffer, 1, bytes, ecd->file) != bytes)
+               return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
+       else
+               return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+FLAC__bool file_utils__change_stats(const char *filename, FLAC__bool read_only)
+{
+       struct stat stats;
+
+       if(0 == stat(filename, &stats)) {
+#if !defined _MSC_VER && !defined __MINGW32__
+               if(read_only) {
+                       stats.st_mode &= ~S_IWUSR;
+                       stats.st_mode &= ~S_IWGRP;
+                       stats.st_mode &= ~S_IWOTH;
+               }
+               else {
+                       stats.st_mode |= S_IWUSR;
+                       stats.st_mode |= S_IWGRP;
+                       stats.st_mode |= S_IWOTH;
+               }
+#else
+               if(read_only)
+                       stats.st_mode &= ~S_IWRITE;
+               else
+                       stats.st_mode |= S_IWRITE;
+#endif
+               if(0 != chmod(filename, stats.st_mode))
+                       return false;
+       }
+       else
+               return false;
+
+       return true;
+}
+
+FLAC__bool file_utils__remove_file(const char *filename)
+{
+       return file_utils__change_stats(filename, /*read_only=*/false) && 0 == unlink(filename);
+}
+
+FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
+{
+       FLAC__int32 samples[1024];
+       OggFLAC__StreamEncoder *encoder;
+       encoder_client_struct encoder_client_data;
+       unsigned i, n;
+
+       FLAC__ASSERT(0 != output_filename);
+       FLAC__ASSERT(0 != streaminfo);
+       FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO);
+       FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0));
+
+       if(0 == (encoder_client_data.file = fopen(output_filename, "wb")))
+               return false;
+
+       encoder = OggFLAC__stream_encoder_new();
+       if(0 == encoder) {
+               fclose(encoder_client_data.file);
+               return false;
+       }
+
+       OggFLAC__stream_encoder_set_verify(encoder, true);
+       OggFLAC__stream_encoder_set_streamable_subset(encoder, true);
+       OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
+       OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false);
+       OggFLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels);
+       OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample);
+       OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate);
+       OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize);
+       OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0);
+       OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0);
+       OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false);
+       OggFLAC__stream_encoder_set_do_escape_coding(encoder, false);
+       OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false);
+       OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0);
+       OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0);
+       OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0);
+       OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
+       OggFLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
+       OggFLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_);
+       OggFLAC__stream_encoder_set_client_data(encoder, &encoder_client_data);
+
+       if(OggFLAC__stream_encoder_init(encoder) != OggFLAC__STREAM_ENCODER_OK) {
+               fclose(encoder_client_data.file);
+               return false;
+       }
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       while(length > 0) {
+               n = min(length, sizeof(samples) / sizeof(FLAC__int32));
+
+               if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, n)) {
+                       fclose(encoder_client_data.file);
+                       return false;
+               }
+
+               length -= n;
+       }
+
+       OggFLAC__stream_encoder_finish(encoder);
+
+       fclose(encoder_client_data.file);
+
+       OggFLAC__stream_encoder_delete(encoder);
+
+       if(0 != output_filesize) {
+               struct stat filestats;
+
+               if(stat(output_filename, &filestats) != 0)
+                       return false;
+               else
+                       *output_filesize = (unsigned)filestats.st_size;
+       }
+
+       return true;
+}
diff --git a/src/test_libOggFLAC/file_utils.h b/src/test_libOggFLAC/file_utils.h
new file mode 100644 (file)
index 0000000..3a20403
--- /dev/null
@@ -0,0 +1,30 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H
+#define OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H
+
+#include "FLAC/format.h"
+
+FLAC__bool file_utils__change_stats(const char *filename, FLAC__bool read_only);
+
+FLAC__bool file_utils__remove_file(const char *filename);
+
+FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata);
+
+#endif
diff --git a/src/test_libOggFLAC/main.c b/src/test_libOggFLAC/main.c
new file mode 100644 (file)
index 0000000..7f3bc56
--- /dev/null
@@ -0,0 +1,33 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include "decoders.h"
+#include "encoders.h"
+
+int main(int argc, char *argv[])
+{
+       (void)argc, (void)argv;
+
+       if(!test_encoders())
+               return 1;
+
+       if(!test_decoders())
+               return 1;
+
+       return 0;
+}
diff --git a/src/test_libOggFLAC/metadata_utils.c b/src/test_libOggFLAC/metadata_utils.c
new file mode 100644 (file)
index 0000000..c6367bb
--- /dev/null
@@ -0,0 +1,247 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+ * These are not tests, just utility functions used by the metadata tests
+ */
+
+#include "metadata_utils.h"
+#include "FLAC/metadata.h"
+#include <stdio.h>
+#include <stdlib.h> /* for malloc() */
+#include <string.h> /* for memcmp() */
+
+FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy)
+{
+       if(blockcopy->min_blocksize != block->min_blocksize) {
+               printf("FAILED, min_blocksize mismatch, expected %u, got %u\n", block->min_blocksize, blockcopy->min_blocksize);
+               return false;
+    }
+       if(blockcopy->max_blocksize != block->max_blocksize) {
+               printf("FAILED, max_blocksize mismatch, expected %u, got %u\n", block->max_blocksize, blockcopy->max_blocksize);
+               return false;
+    }
+       if(blockcopy->min_framesize != block->min_framesize) {
+               printf("FAILED, min_framesize mismatch, expected %u, got %u\n", block->min_framesize, blockcopy->min_framesize);
+               return false;
+    }
+       if(blockcopy->max_framesize != block->max_framesize) {
+               printf("FAILED, max_framesize mismatch, expected %u, got %u\n", block->max_framesize, blockcopy->max_framesize);
+               return false;
+    }
+       if(blockcopy->sample_rate != block->sample_rate) {
+               printf("FAILED, sample_rate mismatch, expected %u, got %u\n", block->sample_rate, blockcopy->sample_rate);
+               return false;
+    }
+       if(blockcopy->channels != block->channels) {
+               printf("FAILED, channels mismatch, expected %u, got %u\n", block->channels, blockcopy->channels);
+               return false;
+    }
+       if(blockcopy->bits_per_sample != block->bits_per_sample) {
+               printf("FAILED, bits_per_sample mismatch, expected %u, got %u\n", block->bits_per_sample, blockcopy->bits_per_sample);
+               return false;
+    }
+       if(blockcopy->total_samples != block->total_samples) {
+               printf("FAILED, total_samples mismatch, expected %llu, got %llu\n", block->total_samples, blockcopy->total_samples);
+               return false;
+    }
+       if(0 != memcmp(blockcopy->md5sum, block->md5sum, sizeof(block->md5sum))) {
+               printf("FAILED, md5sum mismatch, expected %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X, got %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
+                       (unsigned)block->md5sum[0],
+                       (unsigned)block->md5sum[1],
+                       (unsigned)block->md5sum[2],
+                       (unsigned)block->md5sum[3],
+                       (unsigned)block->md5sum[4],
+                       (unsigned)block->md5sum[5],
+                       (unsigned)block->md5sum[6],
+                       (unsigned)block->md5sum[7],
+                       (unsigned)block->md5sum[8],
+                       (unsigned)block->md5sum[9],
+                       (unsigned)block->md5sum[10],
+                       (unsigned)block->md5sum[11],
+                       (unsigned)block->md5sum[12],
+                       (unsigned)block->md5sum[13],
+                       (unsigned)block->md5sum[14],
+                       (unsigned)block->md5sum[15],
+                       (unsigned)blockcopy->md5sum[0],
+                       (unsigned)blockcopy->md5sum[1],
+                       (unsigned)blockcopy->md5sum[2],
+                       (unsigned)blockcopy->md5sum[3],
+                       (unsigned)blockcopy->md5sum[4],
+                       (unsigned)blockcopy->md5sum[5],
+                       (unsigned)blockcopy->md5sum[6],
+                       (unsigned)blockcopy->md5sum[7],
+                       (unsigned)blockcopy->md5sum[8],
+                       (unsigned)blockcopy->md5sum[9],
+                       (unsigned)blockcopy->md5sum[10],
+                       (unsigned)blockcopy->md5sum[11],
+                       (unsigned)blockcopy->md5sum[12],
+                       (unsigned)blockcopy->md5sum[13],
+                       (unsigned)blockcopy->md5sum[14],
+                       (unsigned)blockcopy->md5sum[15]
+               );
+               return false;
+    }
+       return true;
+}
+
+FLAC__bool compare_block_data_padding_(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, unsigned block_length)
+{
+       /* we don't compare the padding guts */
+       (void)block, (void)blockcopy, (void)block_length;
+       return true;
+}
+
+FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, unsigned block_length)
+{
+       if(block_length < sizeof(block->id)) {
+               printf("FAILED, bad block length = %u\n", block_length);
+               return false;
+       }
+       if(0 != memcmp(blockcopy->id, block->id, sizeof(block->id))) {
+               printf("FAILED, id mismatch, expected %02X%02X%02X%02X, got %02X%02X%02X%02X\n",
+                       (unsigned)block->id[0],
+                       (unsigned)block->id[1],
+                       (unsigned)block->id[2],
+                       (unsigned)block->id[3],
+                       (unsigned)blockcopy->id[0],
+                       (unsigned)blockcopy->id[1],
+                       (unsigned)blockcopy->id[2],
+                       (unsigned)blockcopy->id[3]
+               );
+               return false;
+    }
+       if(0 == block->data || 0 == blockcopy->data) {
+               if(block->data != blockcopy->data) {
+                       printf("FAILED, data mismatch (%s's data pointer is null)\n", 0==block->data?"original":"copy");
+                       return false;
+               }
+               else if(block_length - sizeof(block->id) > 0) {
+                       printf("FAILED, data pointer is null but block length is not 0\n");
+                       return false;
+               }
+       }
+       else {
+               if(block_length - sizeof(block->id) == 0) {
+                       printf("FAILED, data pointer is not null but block length is 0\n");
+                       return false;
+               }
+               else if(0 != memcmp(blockcopy->data, block->data, block_length - sizeof(block->id))) {
+                       printf("FAILED, data mismatch\n");
+                       return false;
+               }
+       }
+       return true;
+}
+
+FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy)
+{
+       unsigned i;
+       if(blockcopy->num_points != block->num_points) {
+               printf("FAILED, num_points mismatch, expected %u, got %u\n", block->num_points, blockcopy->num_points);
+               return false;
+    }
+       for(i = 0; i < block->num_points; i++) {
+               if(blockcopy->points[i].sample_number != block->points[i].sample_number) {
+                       printf("FAILED, points[%u].sample_number mismatch, expected %llu, got %llu\n", i, block->points[i].sample_number, blockcopy->points[i].sample_number);
+                       return false;
+               }
+               if(blockcopy->points[i].stream_offset != block->points[i].stream_offset) {
+                       printf("FAILED, points[%u].stream_offset mismatch, expected %llu, got %llu\n", i, block->points[i].stream_offset, blockcopy->points[i].stream_offset);
+                       return false;
+               }
+               if(blockcopy->points[i].frame_samples != block->points[i].frame_samples) {
+                       printf("FAILED, points[%u].frame_samples mismatch, expected %u, got %u\n", i, block->points[i].frame_samples, blockcopy->points[i].frame_samples);
+                       return false;
+               }
+       }
+       return true;
+}
+
+FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy)
+{
+       unsigned i;
+       if(blockcopy->vendor_string.length != block->vendor_string.length) {
+               printf("FAILED, vendor_string.length mismatch, expected %u, got %u\n", block->vendor_string.length, blockcopy->vendor_string.length);
+               return false;
+    }
+       if(0 == block->vendor_string.entry || 0 == blockcopy->vendor_string.entry) {
+               if(block->vendor_string.entry != blockcopy->vendor_string.entry) {
+                       printf("FAILED, vendor_string.entry mismatch\n");
+                       return false;
+               }
+       }
+       else if(0 != memcmp(blockcopy->vendor_string.entry, block->vendor_string.entry, block->vendor_string.length)) {
+               printf("FAILED, vendor_string.entry mismatch\n");
+               return false;
+    }
+       if(blockcopy->num_comments != block->num_comments) {
+               printf("FAILED, num_comments mismatch, expected %u, got %u\n", block->num_comments, blockcopy->num_comments);
+               return false;
+    }
+       for(i = 0; i < block->num_comments; i++) {
+               if(blockcopy->comments[i].length != block->comments[i].length) {
+                       printf("FAILED, comments[%u].length mismatch, expected %u, got %u\n", i, block->comments[i].length, blockcopy->comments[i].length);
+                       return false;
+               }
+               if(0 == block->comments[i].entry || 0 == blockcopy->comments[i].entry) {
+                       if(block->comments[i].entry != blockcopy->comments[i].entry) {
+                               printf("FAILED, comments[%u].entry mismatch\n", i);
+                               return false;
+                       }
+               }
+               else {
+                       if(0 != memcmp(blockcopy->comments[i].entry, block->comments[i].entry, block->comments[i].length)) {
+                               printf("FAILED, comments[%u].entry mismatch\n", i);
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+FLAC__bool compare_block_(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy)
+{
+       if(blockcopy->type != block->type) {
+               printf("FAILED, type mismatch, expected %s, got %s\n", FLAC__MetadataTypeString[block->type], FLAC__MetadataTypeString[blockcopy->type]);
+               return false;
+    }
+       if(blockcopy->is_last != block->is_last) {
+               printf("FAILED, is_last mismatch, expected %u, got %u\n", (unsigned)block->is_last, (unsigned)blockcopy->is_last);
+               return false;
+    }
+       if(blockcopy->length != block->length) {
+               printf("FAILED, length mismatch, expected %u, got %u\n", block->length, blockcopy->length);
+               return false;
+    }
+       switch(block->type) {
+               case FLAC__METADATA_TYPE_STREAMINFO:
+                       return compare_block_data_streaminfo_(&block->data.stream_info, &blockcopy->data.stream_info);
+               case FLAC__METADATA_TYPE_PADDING:
+                       return compare_block_data_padding_(&block->data.padding, &blockcopy->data.padding, block->length);
+               case FLAC__METADATA_TYPE_APPLICATION:
+                       return compare_block_data_application_(&block->data.application, &blockcopy->data.application, block->length);
+               case FLAC__METADATA_TYPE_SEEKTABLE:
+                       return compare_block_data_seektable_(&block->data.seek_table, &blockcopy->data.seek_table);
+               case FLAC__METADATA_TYPE_VORBIS_COMMENT:
+                       return compare_block_data_vorbiscomment_(&block->data.vorbis_comment, &blockcopy->data.vorbis_comment);
+               default:
+                       printf("FAILED, invalid block type %u\n", (unsigned)block->type);
+                       return false;
+       }
+}
diff --git a/src/test_libOggFLAC/metadata_utils.h b/src/test_libOggFLAC/metadata_utils.h
new file mode 100644 (file)
index 0000000..52c0713
--- /dev/null
@@ -0,0 +1,43 @@
+/* test_libOggFLAC - Unit tester for libOggFLAC
+ * Copyright (C) 2002  Josh Coalson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef OggFLAC__TEST_LIBOGGFLAC_METADATA_H
+#define OggFLAC__TEST_LIBOGGFLAC_METADATA_H
+
+/*
+ * These are not tests, just utility functions used by the metadata tests
+ */
+
+#include "FLAC/format.h"
+#include <stdio.h>
+#include <stdlib.h> /* for malloc() */
+#include <string.h> /* for memcmp() */
+
+FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block, const FLAC__StreamMetadata_StreamInfo *blockcopy);
+
+FLAC__bool compare_block_data_padding_(const FLAC__StreamMetadata_Padding *block, const FLAC__StreamMetadata_Padding *blockcopy, unsigned block_length);
+
+FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block, const FLAC__StreamMetadata_Application *blockcopy, unsigned block_length);
+
+FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block, const FLAC__StreamMetadata_SeekTable *blockcopy);
+
+FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block, const FLAC__StreamMetadata_VorbisComment *blockcopy);
+
+FLAC__bool compare_block_(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy);
+
+#endif
index abe037f..7d6d4af 100644 (file)
 #  along with this program; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-TESTS = ./test_libFLAC.sh ./test_libFLAC++.sh ./test_metaflac.sh ./test_streams.sh ./test_bins.sh
+TESTS = \
+       ./test_libFLAC.sh \
+       ./test_libFLAC++.sh \
+       ./test_libOggFLAC.sh \
+       ./test_libOggFLAC++.sh \
+       ./test_metaflac.sh \
+       ./test_streams.sh \
+       ./test_bins.sh
 
 EXTRA_DIST = \
        test_libFLAC.sh \
        test_libFLAC++.sh \
+       test_libOggFLAC.sh \
+       test_libOggFLAC++.sh \
        test_metaflac.sh \
        test_streams.sh \
        test_bins.sh
index d8b22f0..963e81d 100644 (file)
@@ -21,6 +21,8 @@
 all: clean
        ./test_libFLAC.sh
        ./test_libFLAC++.sh
+       ./test_libOggFLAC.sh
+       ./test_libOggFLAC++.sh
        ./test_metaflac.sh
        ./test_streams.sh
        ./test_bins.sh
diff --git a/test/test_libOggFLAC++.sh b/test/test_libOggFLAC++.sh
new file mode 100755 (executable)
index 0000000..f61fed1
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+#  FLAC - Free Lossless Audio Codec
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is part of FLAC; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+LD_LIBRARY_PATH=../src/libOggFLAC++/.libs:../src/libOggFLAC/.libs:../src/libFLAC/.libs:../obj/lib:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH
+PATH=../src/test_libOggFLAC++:../obj/bin:$PATH
+export PATH
+
+if test_libOggFLAC++ ; then : ; else
+       echo "ERROR during test_libOggFLAC++" 1>&2
+       exit 1
+fi
diff --git a/test/test_libOggFLAC.sh b/test/test_libOggFLAC.sh
new file mode 100755 (executable)
index 0000000..95b0efd
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+#  FLAC - Free Lossless Audio Codec
+#  Copyright (C) 2002  Josh Coalson
+#
+#  This program is part of FLAC; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+LD_LIBRARY_PATH=../src/libOggFLAC/.libs../src/libFLAC/.libs:../obj/lib:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH
+PATH=../src/test_libOggFLAC:../obj/bin:$PATH
+export PATH
+
+if test_libOggFLAC ; then : ; else
+       echo "ERROR during test_libOggFLAC" 1>&2
+       exit 1
+fi