rename directory test_unit to test_libFLAC

This commit is contained in:
Josh Coalson
2002-06-07 05:54:21 +00:00
parent bd1d9b9eee
commit 7d21785223
19 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2000,2001,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.
CFLAGS = @CFLAGS@
INCLUDES = -I$(top_srcdir)/src/libFLAC/include
noinst_PROGRAMS = test_libFLAC
test_libFLAC = $(top_builddir)/src/libFLAC/libFLAC.la -lm
test_libFLAC_SOURCES = \
bitbuffer.c \
decoders.c \
encoders.c \
file_utils.c \
main.c \
metadata.c \
metadata_manip.c \
metadata_object.c \
metadata_utils.c \
bitbuffer.h \
decoders.h \
encoders.h \
file_utils.h \
metadata.h \
metadata_utils.h

View File

@@ -0,0 +1,38 @@
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2000,2001,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_libFLAC
INCLUDES = -I../libFLAC/include -I../../include
LIBS = -lFLAC -lm
OBJS = \
bitbuffer.o \
decoders.o \
encoders.o \
file_utils.o \
main.o \
metadata.o \
metadata_manip.o \
metadata_object.o \
metadata_utils.o
include ../../build/exe.mk
# DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@@ -0,0 +1,48 @@
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2001,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 <win32.mak>
!IFDEF DEBUG
.c.obj:
$(cc) $(cdebug) $(cflags) /I "..\libFLAC\include" /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX /Od /D "_DEBUG" $<
!else
.c.obj:
$(cc) /O2 $(crelease) $(cflags) /I "..\libFLAC\include" /I "..\..\include" /I ".\include" -DSTRICT -DVERSION=\"1.0.3\" -YX -DNODEBUG $<
!endif
C_FILES= \
bitbuffer.c \
decoders.c \
encoders.c \
file_utils.c \
main.c \
metadata.c \
metadata_manip.c \
metadata_object.c \
metadata_utils.c
OBJS= $(C_FILES:.c=.obj)
all: test_libFLAC.exe
test_libFLAC.exe: $(OBJS)
link.exe /libpath:"..\..\obj\lib" -out:../../obj/bin/$*.exe $(OBJS) libFLAC.lib
clean:
-del *.obj *.pch
-del ..\..\obj\bin\test_libFLAC.exe

View File

@@ -0,0 +1,662 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000,2001,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 "FLAC/assert.h"
#include "private/bitbuffer.h" /* from the libFLAC private include area */
#include <stdio.h>
#include <string.h> /* for memcmp() */
/*
* WATCHOUT! Since FLAC__BitBuffer is a private structure, we use a copy of
* the definition here to get at the internals. Make sure this is kept up
* to date with what is in ../libFLAC/bitbuffer.c
*/
struct FLAC__BitBuffer {
FLAC__blurb *buffer;
unsigned capacity; /* in blurbs */
unsigned blurbs, bits;
unsigned total_bits; /* must always == FLAC__BITS_PER_BLURB*blurbs+bits */
unsigned consumed_blurbs, consumed_bits;
unsigned total_consumed_bits; /* must always == FLAC__BITS_PER_BLURB*consumed_blurbs+consumed_bits */
FLAC__uint16 read_crc16;
#if FLAC__BITS_PER_BLURB == 32
unsigned crc16_align;
#endif
FLAC__blurb save_head, save_tail;
};
static FLAC__bool dummy_read_callback(FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)buffer, (void)bytes, (void)client_data;
return true;
}
FLAC__bool test_bitbuffer()
{
FLAC__BitBuffer *bb, *bb_zero, *bb_one, *bbcopy;
FLAC__bool ok;
unsigned i, j;
static FLAC__byte test_pattern1[19] = { 0xaa, 0xf0, 0xaa, 0xbe, 0xaa, 0xaa, 0xaa, 0xa8, 0x30, 0x0a, 0xaa, 0xaa, 0xaa, 0xad, 0xea, 0xdb, 0xee, 0xfa, 0xce };
FLAC__ASSERT(FLAC__BITS_PER_BLURB == 8);
printf("\n+++ unit test: bitbuffer\n\n");
printf("testing new... OK\n");
bb = FLAC__bitbuffer_new();
bb_zero = FLAC__bitbuffer_new();
bb_one = FLAC__bitbuffer_new();
bbcopy = FLAC__bitbuffer_new();
printf("testing init... OK\n");
FLAC__bitbuffer_init(bb);
FLAC__bitbuffer_init(bb_zero);
FLAC__bitbuffer_init(bb_one);
FLAC__bitbuffer_init(bbcopy);
printf("testing clear... ");
ok = FLAC__bitbuffer_clear(bb) && FLAC__bitbuffer_clear(bb_zero) && FLAC__bitbuffer_clear(bb_one) && FLAC__bitbuffer_clear(bbcopy);
printf("%s\n", ok?"OK":"FAILED");
if(!ok)
return false;
printf("setting up bb_one... ");
ok = FLAC__bitbuffer_write_raw_uint32(bb_one, 1, 7) && FLAC__bitbuffer_read_raw_uint32(bb_one, &i, 6, dummy_read_callback, 0);
printf("%s\n", ok?"OK":"FAILED");
if(!ok)
return false;
FLAC__bitbuffer_dump(bb_one, stdout);
printf("capacity = %u\n", bb->capacity);
printf("testing zeroes, raw_uint32*... ");
ok =
FLAC__bitbuffer_write_raw_uint32(bb, 0x1, 1) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0x1, 2) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0xa, 5) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0xf0, 8) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0x2aa, 10) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0xf, 4) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0xaaaaaaaa, 32) &&
FLAC__bitbuffer_write_zeroes(bb, 4) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0x3, 2) &&
FLAC__bitbuffer_write_zeroes(bb, 8) &&
FLAC__bitbuffer_write_raw_uint64(bb, 0xaaaaaaaadeadbeef, 64) &&
FLAC__bitbuffer_write_raw_uint32(bb, 0xace, 12)
;
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 0) {
printf("FAILED bit count %u != 0\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing raw_uint32 some more... ");
ok = FLAC__bitbuffer_write_raw_uint32(bb, 0x3d, 6);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 6) {
printf("FAILED bit count %u != 6\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x3d) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_zero)... ");
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_zero);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 6) {
printf("FAILED bit count %u != 6\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x3d) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_one)... ");
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_one);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1));
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 7) {
printf("FAILED bit count %u != 7\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x7b) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_one again)... ");
(void)FLAC__bitbuffer_write_raw_uint32(bb_one, 1, 1);
(void)FLAC__bitbuffer_read_raw_uint32(bb_one, &i, 1, dummy_read_callback, 0);
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_one);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+1);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 0) {
printf("FAILED bit count %u != 0\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-1] != 0xf7) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_four)... ");
(void)FLAC__bitbuffer_clear(bb_one);
(void)FLAC__bitbuffer_write_raw_uint32(bb_one, 8, 4);
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_one);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)+1) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+1);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 4) {
printf("FAILED bit count %u != 4\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs] != 0x08) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_eight)... ");
(void)FLAC__bitbuffer_read_raw_uint32(bb_one, &i, 4, dummy_read_callback, 0);
(void)FLAC__bitbuffer_write_raw_uint32(bb_one, 0xaa, 8);
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_one);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)+2) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+2);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 4) {
printf("FAILED bit count %u != 4\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-1] != 0x8a || bb->buffer[bb->blurbs] != 0x0a) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing concatenate_aligned (bb_seventeen)... ");
(void)FLAC__bitbuffer_write_raw_uint32(bb_one, 0x155, 9);
ok = FLAC__bitbuffer_concatenate_aligned(bb, bb_one);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->blurbs != sizeof(test_pattern1)+4) {
printf("FAILED byte count %u != %u\n", bb->blurbs, sizeof(test_pattern1)+4);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->bits != 5) {
printf("FAILED bit count %u != 5\n", bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(bb->total_bits != 8*bb->blurbs+bb->bits) {
printf("FAILED total_bits count %u != %u (%u:%u)\n", bb->total_bits, 8*bb->blurbs+bb->bits, bb->blurbs, bb->bits);
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
if(memcmp(bb->buffer, test_pattern1, sizeof(FLAC__byte)*sizeof(test_pattern1)) != 0 || bb->buffer[bb->blurbs-3] != 0x8a || bb->buffer[bb->blurbs-2] != 0xaa || bb->buffer[bb->blurbs-1] != 0xaa || bb->buffer[bb->blurbs] != 0x15) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("OK\n");
FLAC__bitbuffer_dump(bb, stdout);
printf("testing utf8_uint32(0x00000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000000);
ok = bb->total_bits == 8 && bb->buffer[0] == 0;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x0000007F)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x0000007F);
ok = bb->total_bits == 8 && bb->buffer[0] == 0x7F;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x00000080)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000080);
ok = bb->total_bits == 16 && bb->buffer[0] == 0xC2 && bb->buffer[1] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x000007FF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x000007FF);
ok = bb->total_bits == 16 && bb->buffer[0] == 0xDF && bb->buffer[1] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x00000800)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00000800);
ok = bb->total_bits == 24 && bb->buffer[0] == 0xE0 && bb->buffer[1] == 0xA0 && bb->buffer[2] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x0000FFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x0000FFFF);
ok = bb->total_bits == 24 && bb->buffer[0] == 0xEF && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x00010000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00010000);
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF0 && bb->buffer[1] == 0x90 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x001FFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x001FFFFF);
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF7 && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x00200000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x00200000);
ok = bb->total_bits == 40 && bb->buffer[0] == 0xF8 && bb->buffer[1] == 0x88 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x03FFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x03FFFFFF);
ok = bb->total_bits == 40 && bb->buffer[0] == 0xFB && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x04000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x04000000);
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFC && bb->buffer[1] == 0x84 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint32(0x7FFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint32(bb, 0x7FFFFFFF);
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFD && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000000000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000000);
ok = bb->total_bits == 8 && bb->buffer[0] == 0;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x000000000000007F)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000000000007F);
ok = bb->total_bits == 8 && bb->buffer[0] == 0x7F;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000000000080)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000080);
ok = bb->total_bits == 16 && bb->buffer[0] == 0xC2 && bb->buffer[1] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x00000000000007FF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x00000000000007FF);
ok = bb->total_bits == 16 && bb->buffer[0] == 0xDF && bb->buffer[1] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000000000800)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000000800);
ok = bb->total_bits == 24 && bb->buffer[0] == 0xE0 && bb->buffer[1] == 0xA0 && bb->buffer[2] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x000000000000FFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000000000FFFF);
ok = bb->total_bits == 24 && bb->buffer[0] == 0xEF && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000000010000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000010000);
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF0 && bb->buffer[1] == 0x90 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x00000000001FFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x00000000001FFFFF);
ok = bb->total_bits == 32 && bb->buffer[0] == 0xF7 && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000000200000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000000200000);
ok = bb->total_bits == 40 && bb->buffer[0] == 0xF8 && bb->buffer[1] == 0x88 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000003FFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000003FFFFFF);
ok = bb->total_bits == 40 && bb->buffer[0] == 0xFB && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000004000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000004000000);
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFC && bb->buffer[1] == 0x84 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x000000007FFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x000000007FFFFFFF);
ok = bb->total_bits == 48 && bb->buffer[0] == 0xFD && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000080000000)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000080000000);
ok = bb->total_bits == 56 && bb->buffer[0] == 0xFE && bb->buffer[1] == 0x82 && bb->buffer[2] == 0x80 && bb->buffer[3] == 0x80 && bb->buffer[4] == 0x80 && bb->buffer[5] == 0x80 && bb->buffer[6] == 0x80;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing utf8_uint64(0x0000000FFFFFFFFF)... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_utf8_uint64(bb, 0x0000000FFFFFFFFF);
ok = bb->total_bits == 56 && bb->buffer[0] == 0xFE && bb->buffer[1] == 0xBF && bb->buffer[2] == 0xBF && bb->buffer[3] == 0xBF && bb->buffer[4] == 0xBF && bb->buffer[5] == 0xBF && bb->buffer[6] == 0xBF;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("testing grow... ");
FLAC__bitbuffer_clear(bb);
FLAC__bitbuffer_write_raw_uint32(bb, 0xa, 4);
j = bb->capacity;
for(i = 0; i < j; i++)
FLAC__bitbuffer_write_raw_uint32(bb, 0xaa, 8);
ok = bb->total_bits = i*8+4 && bb->buffer[0] == 0xaa && bb->buffer[i] == 0xa;
printf("%s\n", ok?"OK":"FAILED");
if(!ok) {
FLAC__bitbuffer_dump(bb, stdout);
return false;
}
printf("capacity = %u\n", bb->capacity);
printf("testing clone... ");
ok = FLAC__bitbuffer_clone(bbcopy, bb);
if(!ok) {
printf("FAILED\n");
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return false;
}
if(bb->blurbs != bbcopy->blurbs) {
printf("FAILED byte count %u != %u\n", bb->blurbs, bbcopy->blurbs);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return false;
}
if(bb->bits != bbcopy->bits) {
printf("FAILED bit count %u != %u\n", bb->bits, bbcopy->bits);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return false;
}
if(bb->total_bits != bbcopy->total_bits) {
printf("FAILED total_bits count %u != %u\n", bb->total_bits, bbcopy->total_bits);
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return false;
}
if(memcmp(bb->buffer, bbcopy->buffer, sizeof(FLAC__byte)*bb->capacity) != 0) {
printf("FAILED pattern match\n");
FLAC__bitbuffer_dump(bb, stdout);
FLAC__bitbuffer_dump(bbcopy, stdout);
return false;
}
printf("OK\n");
printf("testing free... OK\n");
FLAC__bitbuffer_free(bb);
FLAC__bitbuffer_free(bbcopy);
printf("\nPASSED!\n");
return true;
}

View File

@@ -0,0 +1,26 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000,2001,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 FLAC__TEST_LIBFLAC_BITBUFFER_H
#define FLAC__TEST_LIBFLAC_BITBUFFER_H
#include "FLAC/ordinals.h"
FLAC__bool test_bitbuffer();
#endif

1959
src/test_libFLAC/decoders.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 FLAC__TEST_LIBFLAC_DECODERS_H
#define FLAC__TEST_LIBFLAC_DECODERS_H
#include "FLAC/ordinals.h"
FLAC__bool test_decoders();
#endif

410
src/test_libFLAC/encoders.c Normal file
View File

@@ -0,0 +1,410 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 "FLAC/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 *flacfilename_ = "metadata.flac";
static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
{
FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
if(msg)
printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)state, FLAC__StreamEncoderStateString[state]);
else
printf("FAILED, state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[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 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 encoder_write_callback_(const FLAC__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_OK;
}
static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
static FLAC__bool test_stream_encoder()
{
FLAC__StreamEncoder *encoder;
FLAC__StreamEncoderState state;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1] = { samples };
unsigned i;
printf("\n+++ unit test: FLAC__StreamEncoder\n\n");
printf("testing FLAC__stream_encoder_new()... ");
encoder = FLAC__stream_encoder_new();
if(0 == encoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_channels()... ");
if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
if(!FLAC__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 FLAC__stream_encoder_set_sample_rate()... ");
if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_blocksize()... ");
if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_metadata()... ");
if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_write_callback()... ");
if(!FLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
if(!FLAC__stream_encoder_set_metadata_callback(encoder, encoder_metadata_callback_))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_set_client_data()... ");
if(!FLAC__stream_encoder_set_client_data(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_init()... ");
if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
return die_s_(0, encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_get_state()... ");
state = FLAC__stream_encoder_get_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_channels()... ");
if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_sample_rate()... ");
if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_blocksize()... ");
if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
(void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
/* we asked the encoder to auto select this so we accept anything */
printf("OK\n");
printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
return false;
}
printf("OK\n");
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
printf("testing FLAC__stream_encoder_process()... ");
if(!FLAC__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 FLAC__stream_encoder_process_interleaved()... ");
if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_finish()... ");
FLAC__stream_encoder_finish(encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_delete()... ");
FLAC__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(flacfilename_);
free_metadata_blocks_();
return true;
}

View File

@@ -0,0 +1,26 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 FLAC__TEST_LIBFLAC_ENCODERS_H
#define FLAC__TEST_LIBFLAC_ENCODERS_H
#include "FLAC/ordinals.h"
FLAC__bool test_encoders();
#endif

View File

@@ -0,0 +1,173 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 "FLAC/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 FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
encoder_client_struct *ecd = (encoder_client_struct*)client_data;
(void)encoder, (void)samples, (void)current_frame;
if(fwrite(buffer, 1, bytes, ecd->file) != bytes)
return FLAC__STREAM_ENCODER_WRITE_FATAL_ERROR;
else
return FLAC__STREAM_ENCODER_WRITE_OK;
}
static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
FLAC__bool file_utils__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_flacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetaData *streaminfo, FLAC__StreamMetaData **metadata, unsigned num_metadata)
{
FLAC__int32 samples[1024];
FLAC__StreamEncoder *encoder;
encoder_client_struct encoder_client_data;
unsigned i, n;
FLAC__ASSERT(0 != output_filename);
FLAC__ASSERT(0 != streaminfo);
FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO);
FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0));
if(0 == (encoder_client_data.file = fopen(output_filename, "wb")))
return false;
encoder = FLAC__stream_encoder_new();
if(0 == encoder) {
fclose(encoder_client_data.file);
return false;
}
FLAC__stream_encoder_set_streamable_subset(encoder, true);
FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false);
FLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels);
FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample);
FLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate);
FLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize);
FLAC__stream_encoder_set_max_lpc_order(encoder, 0);
FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0);
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false);
FLAC__stream_encoder_set_do_escape_coding(encoder, false);
FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false);
FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0);
FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0);
FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0);
FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
FLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_);
FLAC__stream_encoder_set_metadata_callback(encoder, encoder_metadata_callback_);
FLAC__stream_encoder_set_client_data(encoder, &encoder_client_data);
if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK) {
fclose(encoder_client_data.file);
return false;
}
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
while(length > 0) {
n = min(length, sizeof(samples) / sizeof(FLAC__int32));
if(!FLAC__stream_encoder_process_interleaved(encoder, samples, n)) {
fclose(encoder_client_data.file);
return false;
}
length -= n;
}
FLAC__stream_encoder_finish(encoder);
fclose(encoder_client_data.file);
FLAC__stream_encoder_delete(encoder);
if(0 != output_filesize) {
struct stat filestats;
if(stat(output_filename, &filestats) != 0)
return false;
else
*output_filesize = (unsigned)filestats.st_size;
}
return true;
}

View File

@@ -0,0 +1,30 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 FLAC__TEST_LIBFLAC_FILE_UTILS_H
#define FLAC__TEST_LIBFLAC_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_flacfile(const char *output_filename, unsigned *output_filesize, unsigned length, const FLAC__StreamMetaData *streaminfo, FLAC__StreamMetaData **metadata, unsigned num_metadata);
#endif

41
src/test_libFLAC/main.c Normal file
View File

@@ -0,0 +1,41 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000,2001,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 "bitbuffer.h"
#include "decoders.h"
#include "encoders.h"
#include "metadata.h"
int main(int argc, char *argv[])
{
(void)argc, (void)argv;
if(!test_bitbuffer())
return 1;
if(!test_encoders())
return 1;
if(!test_decoders())
return 1;
if(!test_metadata())
return 1;
return 0;
}

69
src/test_libFLAC/matrix Normal file
View File

@@ -0,0 +1,69 @@
#if 0
level 1
4 delete middle block nopad
1 delete middle block pad
1 delete last block nopad
1 delete last block pad
1 insert middle block nopad
1 insert middle block equalpad
1 insert middle block smallpad
1 insert middle block smallpad+1
1 insert middle block biggerpad
1 insert last block X
1 set middle block smaller nopad
1 set middle block smaller pad
1 set last block smaller nopad
1 set last block smaller pad
1 set middle block bigger nopad
1 set middle block bigger equalpad
1 set middle block bigger smallpad
1 set middle block bigger smallpad+1
1 set middle block bigger biggerpad
1 set last block bigger nopad
1 set middle block equal X
2 set last block equal X
level 2
FLAC__bool FLAC__metadata_chain_write()
1 newsize==oldsize
newsize>oldsize
b no use_padding
c use_padding, last block is not padding
g use_padding, last block is padding of insufficient length
h use_padding, last block is padding, but padding header straddles border (can't do it)
j use_padding, last block is padding of exact sufficient length (padding totally consumed)
i use_padding, last block is padding of abundant length (padding is reduced)
newsize<oldsize
a no use_padding
d use_padding, last block is not padding, delta is < 4
e use_padding, last block is not padding, delta is >= 4
f use_padding, last block is padding
void FLAC__metadata_chain_merge_padding(FLAC__MetaData_Chain *chain);
void FLAC__metadata_chain_sort_padding(FLAC__MetaData_Chain *chain);
S:34 A:1234
a:shrink A->30 write nopad
S:34 A:30
b:grow A->32 write nopad
S:34 A:32
c:grow A->40 write pad
S:34 A:40
d:shrink A->37 write pad
S:34 A:37
e:shrink A->33 write pad
S:34 A:33 P:0
f:shrink A->20 write pad
S:34 A:20 P:13
g:grow A->40 write pad
S:34 A:40 P:13
h:grow A->54 write pad
S:34 A:54 P:13
i:grow A->60 write pad
S:34 A:60 P:7
j:grow A->71 write pad
S:34 A:71
#endif

View File

@@ -0,0 +1,36 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 "metadata.h"
#include <stdio.h>
extern int test_metadata_object();
extern int test_metadata_file_manipulation();
FLAC__bool test_metadata()
{
if(!test_metadata_object())
return false;
if(!test_metadata_file_manipulation())
return false;
printf("\nPASSED!\n");
return true;
}

View File

@@ -0,0 +1,26 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 FLAC__TEST_LIBFLAC_METADATA_H
#define FLAC__TEST_LIBFLAC_METADATA_H
#include "FLAC/ordinals.h"
FLAC__bool test_metadata();
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,778 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 "FLAC/assert.h"
#include "FLAC/metadata.h"
#include "metadata_utils.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
static FLAC__byte *make_dummydata_(FLAC__byte *dummydata, unsigned len)
{
FLAC__byte *ret;
if(0 == (ret = (FLAC__byte*)malloc(len))) {
printf("FAILED, malloc error\n");
exit(1);
}
else
memcpy(ret, dummydata, len);
return ret;
}
static FLAC__bool compare_seekpoint_array_(const FLAC__StreamMetaData_SeekPoint *from, const FLAC__StreamMetaData_SeekPoint *to, unsigned n)
{
unsigned i;
FLAC__ASSERT(0 != from);
FLAC__ASSERT(0 != to);
for(i = 0; i < n; i++) {
if(from[i].sample_number != to[i].sample_number) {
printf("FAILED, point[%u].sample_number mismatch, expected %llu, got %llu\n", i, to[i].sample_number, from[i].sample_number);
return false;
}
if(from[i].stream_offset != to[i].stream_offset) {
printf("FAILED, point[%u].stream_offset mismatch, expected %llu, got %llu\n", i, to[i].stream_offset, from[i].stream_offset);
return false;
}
if(from[i].frame_samples != to[i].frame_samples) {
printf("FAILED, point[%u].frame_samples mismatch, expected %u, got %u\n", i, to[i].frame_samples, from[i].frame_samples);
return false;
}
}
return true;
}
static FLAC__bool check_seektable_(const FLAC__StreamMetaData *block, unsigned num_points, const FLAC__StreamMetaData_SeekPoint *array)
{
const unsigned expected_length = num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
if(block->data.seek_table.num_points != num_points) {
printf("FAILED, expected %u point, got %u\n", num_points, block->data.seek_table.num_points);
return false;
}
if(0 == array) {
if(0 != block->data.seek_table.points) {
printf("FAILED, 'points' pointer is not null\n");
return false;
}
}
else {
if(!compare_seekpoint_array_(block->data.seek_table.points, array, num_points))
return false;
}
printf("OK\n");
return true;
}
static void entry_new_(FLAC__StreamMetaData_VorbisComment_Entry *entry, const char *field)
{
entry->length = strlen(field);
entry->entry = (FLAC__byte*)malloc(entry->length);
FLAC__ASSERT(0 != entry->entry);
memcpy(entry->entry, field, entry->length);
}
static void entry_clone_(FLAC__StreamMetaData_VorbisComment_Entry *entry)
{
FLAC__byte *x = (FLAC__byte*)malloc(entry->length);
FLAC__ASSERT(0 != x);
memcpy(x, entry->entry, entry->length);
entry->entry = x;
}
static void vc_calc_len_(FLAC__StreamMetaData *block)
{
const FLAC__StreamMetaData_VorbisComment *vc = &block->data.vorbis_comment;
unsigned i;
block->length = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
block->length += vc->vendor_string.length;
block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
for(i = 0; i < vc->num_comments; i++) {
block->length += FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
block->length += vc->comments[i].length;
}
}
static void vc_resize_(FLAC__StreamMetaData *block, unsigned num)
{
FLAC__StreamMetaData_VorbisComment *vc = &block->data.vorbis_comment;
if(vc->num_comments != 0) {
FLAC__ASSERT(0 != vc->comments);
if(num < vc->num_comments) {
unsigned i;
for(i = num; i < vc->num_comments; i++) {
if(0 != vc->comments[i].entry)
free(vc->comments[i].entry);
}
}
}
if(num == 0) {
if(0 != vc->comments) {
free(vc->comments);
vc->comments = 0;
}
}
else {
vc->comments = (FLAC__StreamMetaData_VorbisComment_Entry*)realloc(vc->comments, sizeof(FLAC__StreamMetaData_VorbisComment_Entry)*num);
FLAC__ASSERT(0 != vc->comments);
if(num > vc->num_comments)
memset(vc->comments+vc->num_comments, 0, sizeof(FLAC__StreamMetaData_VorbisComment_Entry)*(num-vc->num_comments));
}
vc->num_comments = num;
vc_calc_len_(block);
}
static void vc_set_vs_new_(FLAC__StreamMetaData_VorbisComment_Entry *entry, FLAC__StreamMetaData *block, const char *field)
{
entry_new_(entry, field);
block->data.vorbis_comment.vendor_string = *entry;
vc_calc_len_(block);
}
static void vc_set_new_(FLAC__StreamMetaData_VorbisComment_Entry *entry, FLAC__StreamMetaData *block, unsigned pos, const char *field)
{
entry_new_(entry, field);
block->data.vorbis_comment.comments[pos] = *entry;
vc_calc_len_(block);
}
static void vc_insert_new_(FLAC__StreamMetaData_VorbisComment_Entry *entry, FLAC__StreamMetaData *block, unsigned pos, const char *field)
{
vc_resize_(block, block->data.vorbis_comment.num_comments+1);
memmove(&block->data.vorbis_comment.comments[pos+1], &block->data.vorbis_comment.comments[pos], sizeof(FLAC__StreamMetaData_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-1-pos));
vc_set_new_(entry, block, pos, field);
vc_calc_len_(block);
}
static void vc_delete_(FLAC__StreamMetaData *block, unsigned pos)
{
if(0 != block->data.vorbis_comment.comments[pos].entry)
free(block->data.vorbis_comment.comments[pos].entry);
memmove(&block->data.vorbis_comment.comments[pos], &block->data.vorbis_comment.comments[pos+1], sizeof(FLAC__StreamMetaData_VorbisComment_Entry)*(block->data.vorbis_comment.num_comments-pos-1));
block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].entry = 0;
block->data.vorbis_comment.comments[block->data.vorbis_comment.num_comments-1].length = 0;
vc_resize_(block, block->data.vorbis_comment.num_comments-1);
vc_calc_len_(block);
}
FLAC__bool test_metadata_object()
{
FLAC__StreamMetaData *block, *blockcopy, *vorbiscomment;
FLAC__StreamMetaData_SeekPoint seekpoint_array[4];
FLAC__StreamMetaData_VorbisComment_Entry entry;
unsigned i, expected_length, seekpoints;
static FLAC__byte dummydata[4] = { 'a', 'b', 'c', 'd' };
printf("\n+++ unit test: metadata objects (libFLAC)\n\n");
printf("testing STREAMINFO\n");
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
expected_length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
FLAC__metadata_object_delete(block);
printf("OK\n");
printf("testing PADDING\n");
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
expected_length = 0;
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
FLAC__metadata_object_delete(block);
printf("OK\n");
printf("testing APPLICATION\n");
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
expected_length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
printf("OK\n");
printf("testing FLAC__metadata_object_application_set_data(copy)... ");
if(!FLAC__metadata_object_application_set_data(block, dummydata, sizeof(dummydata), true/*copy*/)) {
printf("FAILED, returned false\n");
return false;
}
expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
printf("FAILED, data mismatch\n");
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
printf("OK\n");
printf("testing FLAC__metadata_object_application_set_data(own)... ");
if(!FLAC__metadata_object_application_set_data(block, make_dummydata_(dummydata, sizeof(dummydata)), sizeof(dummydata), false/*own*/)) {
printf("FAILED, returned false\n");
return false;
}
expected_length = (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8) + sizeof(dummydata);
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
if(0 != memcmp(block->data.application.data, dummydata, sizeof(dummydata))) {
printf("FAILED, data mismatch\n");
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
FLAC__metadata_object_delete(block);
printf("OK\n");
printf("testing SEEKTABLE\n");
for(i = 0; i < 4; i++) {
seekpoint_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
seekpoint_array[i].stream_offset = 0;
seekpoint_array[i].frame_samples = 0;
}
seekpoints = 0;
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
if(!check_seektable_(block, seekpoints, 0))
return false;
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
printf("OK\n");
seekpoints = 2;
printf("testing FLAC__metadata_object_seektable_resize_points(grow to %u)...", seekpoints);
if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoints = 1;
printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
printf("testing FLAC__metadata_object_seektable_is_legal()...");
if(!FLAC__metadata_object_seektable_is_legal(block)) {
printf("FAILED, returned false\n");
return false;
}
printf("OK\n");
seekpoints = 0;
printf("testing FLAC__metadata_object_seektable_resize_points(shrink to %u)...", seekpoints);
if(!FLAC__metadata_object_seektable_resize_points(block, seekpoints)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, 0))
return false;
seekpoints++;
printf("testing FLAC__metadata_object_seektable_insert_point() on empty array...");
if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoint_array[0].sample_number = 1;
seekpoints++;
printf("testing FLAC__metadata_object_seektable_insert_point() on beginning of non-empty array...");
if(!FLAC__metadata_object_seektable_insert_point(block, 0, seekpoint_array[0])) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoint_array[1].sample_number = 2;
seekpoints++;
printf("testing FLAC__metadata_object_seektable_insert_point() on middle of non-empty array...");
if(!FLAC__metadata_object_seektable_insert_point(block, 1, seekpoint_array[1])) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoint_array[3].sample_number = 3;
seekpoints++;
printf("testing FLAC__metadata_object_seektable_insert_point() on end of non-empty array...");
if(!FLAC__metadata_object_seektable_insert_point(block, 3, seekpoint_array[3])) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
printf("OK\n");
seekpoint_array[2].sample_number = seekpoint_array[3].sample_number;
seekpoints--;
printf("testing FLAC__metadata_object_seektable_delete_point() on middle of array...");
if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoints--;
printf("testing FLAC__metadata_object_seektable_delete_point() on end of array...");
if(!FLAC__metadata_object_seektable_delete_point(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
seekpoints--;
printf("testing FLAC__metadata_object_seektable_delete_point() on beginning of array...");
if(!FLAC__metadata_object_seektable_delete_point(block, 0)) {
printf("FAILED, returned false\n");
return false;
}
if(!check_seektable_(block, seekpoints, seekpoint_array+1))
return false;
printf("testing FLAC__metadata_object_seektable_set_point()...");
FLAC__metadata_object_seektable_set_point(block, 0, seekpoint_array[0]);
if(!check_seektable_(block, seekpoints, seekpoint_array))
return false;
printf("testing VORBIS_COMMENT\n");
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
expected_length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN + FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8;
if(block->length != expected_length) {
printf("FAILED, bad length, expected %u, got %u\n", expected_length, block->length);
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
vorbiscomment = FLAC__metadata_object_copy(block);
if(0 == vorbiscomment) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
vc_resize_(vorbiscomment, 2);
printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(grow to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
vc_resize_(vorbiscomment, 1);
printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
vc_resize_(vorbiscomment, 0);
printf("testing FLAC__metadata_object_vorbiscomment_resize_comments(shrink to %u)...", vorbiscomment->data.vorbis_comment.num_comments);
if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, vorbiscomment->data.vorbis_comment.num_comments)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on empty array...");
vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on beginning of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on middle of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(copy) on end of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/true)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
blockcopy = FLAC__metadata_object_copy(block);
if(0 == blockcopy) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(block, blockcopy))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(blockcopy);
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
vc_delete_(vorbiscomment, 2);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
vc_delete_(vorbiscomment, 2);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
vc_delete_(vorbiscomment, 0);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_set_comment(copy)...");
vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/true);
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(copy)...");
vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/true);
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(vorbiscomment);
FLAC__metadata_object_delete(block);
printf("OK\n");
printf("testing FLAC__metadata_object_new()... ");
block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
if(0 == block) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing FLAC__metadata_object_copy()... ");
vorbiscomment = FLAC__metadata_object_copy(block);
if(0 == vorbiscomment) {
printf("FAILED, returned NULL\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on empty array...");
vc_insert_new_(&entry, vorbiscomment, 0, "name1=field1");
entry_clone_(&entry);
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on beginning of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 0, "name2=field2");
entry_clone_(&entry);
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 0, entry, /*copy=*/false)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on middle of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 1, "name3=field3");
entry_clone_(&entry);
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 1, entry, /*copy=*/false)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_insert_comment(own) on end of non-empty array...");
vc_insert_new_(&entry, vorbiscomment, 3, "name4=field4");
entry_clone_(&entry);
if(!FLAC__metadata_object_vorbiscomment_insert_comment(block, 3, entry, /*copy=*/false)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on middle of array...");
vc_delete_(vorbiscomment, 2);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on end of array...");
vc_delete_(vorbiscomment, 2);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 2)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_delete_comment() on beginning of array...");
vc_delete_(vorbiscomment, 0);
if(!FLAC__metadata_object_vorbiscomment_delete_comment(block, 0)) {
printf("FAILED, returned false\n");
return false;
}
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_set_comment(own)...");
vc_set_new_(&entry, vorbiscomment, 0, "name5=field5");
entry_clone_(&entry);
FLAC__metadata_object_vorbiscomment_set_comment(block, 0, entry, /*copy=*/false);
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_vorbiscomment_set_vendor_string(own)...");
vc_set_vs_new_(&entry, vorbiscomment, "name6=field6");
entry_clone_(&entry);
FLAC__metadata_object_vorbiscomment_set_vendor_string(block, entry, /*copy=*/false);
if(!compare_block_(vorbiscomment, block))
return false;
printf("OK\n");
printf("testing FLAC__metadata_object_delete()... ");
FLAC__metadata_object_delete(vorbiscomment);
FLAC__metadata_object_delete(block);
printf("OK\n");
return true;
}

View File

@@ -0,0 +1,247 @@
/* test_libFLAC - Unit tester for libFLAC
* 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;
}
}

View File

@@ -0,0 +1,43 @@
/* test_libFLAC - Unit tester for libFLAC
* 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 FLAC__TEST_LIBFLAC_METADATA_H
#define FLAC__TEST_LIBFLAC_METADATA_H
/*
* These are not tests, just utility functions used by the metadata tests
*/
#include "FLAC/format.h"
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcmp() */
FLAC__bool 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