1#!/bin/sh
2
3#  FLAC - Free Lossless Audio Codec
4#  Copyright (C) 2004,2005,2006,2007  Josh Coalson
5#
6#  This file is part the FLAC project.  FLAC is comprised of several
7#  components distributed under difference licenses.  The codec libraries
8#  are distributed under Xiph.Org's BSD-like license (see the file
9#  COPYING.Xiph in this distribution).  All other programs, libraries, and
10#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
11#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
12#  FLAC distribution contains at the top the terms under which it may be
13#  distributed.
14#
15#  Since this particular file is relevant to all components of FLAC,
16#  it may be distributed under the Xiph.Org license, which is the least
17#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
18#  distribution.
19
20die ()
21{
22	echo $* 1>&2
23	exit 1
24}
25
26if [ x = x"$1" ] ; then 
27	BUILD=debug
28else
29	BUILD="$1"
30fi
31
32LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
33LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
34export LD_LIBRARY_PATH
35PATH=../src/flac:$PATH
36PATH=../src/metaflac:$PATH
37PATH=../src/test_seeking:$PATH
38PATH=../src/test_streams:$PATH
39PATH=../obj/$BUILD/bin:$PATH
40
41if [ x"$FLAC__TEST_LEVEL" = x ] ; then
42	FLAC__TEST_LEVEL=1
43fi
44
45flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
46metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
47
48run_flac ()
49{
50	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
51		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=100 flac $*" >>test_seeking.valgrind.log
52		valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --log-fd=4 flac $* 4>>test_seeking.valgrind.log
53	else
54		flac $*
55	fi
56}
57
58run_metaflac ()
59{
60	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
61		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=100 metaflac $*" >>test_seeking.valgrind.log
62		valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --log-fd=4 metaflac $* 4>>test_seeking.valgrind.log
63	else
64		metaflac $*
65	fi
66}
67
68run_test_seeking ()
69{
70	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
71		echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=100 test_seeking $*" >>test_seeking.valgrind.log
72		valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --log-fd=4 test_seeking $* 4>>test_seeking.valgrind.log
73	else
74		test_seeking $*
75	fi
76}
77
78echo "Checking for --ogg support in flac..."
79if flac --ogg --silent --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
80	has_ogg=yes;
81	echo "flac --ogg works"
82else
83	has_ogg=no;
84	echo "flac --ogg doesn't work"
85fi
86
87
88echo "Generating streams..."
89if [ ! -f noise.raw ] ; then
90	test_streams || die "ERROR during test_streams"
91fi
92
93echo "generating FLAC files for seeking:"
94run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S- --output-name=tiny.flac noise8m32.raw || die "ERROR generating FLAC file"
95run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S- --output-name=small.flac noise.raw || die "ERROR generating FLAC file"
96run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S10x --output-name=tiny-s.flac noise8m32.raw || die "ERROR generating FLAC file"
97run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S10x --output-name=small-s.flac noise.raw || die "ERROR generating FLAC file"
98
99tiny_samples=`metaflac --show-total-samples tiny.flac`
100small_samples=`metaflac --show-total-samples small.flac`
101
102tiny_seek_count=100
103if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
104	small_seek_count=10000
105else
106	small_seek_count=100000
107fi
108
109for suffix in '' '-s' ; do
110	echo "testing tiny$suffix.flac:"
111	if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
112		die "ERROR: during test_seeking"
113	fi
114
115	echo "testing small$suffix.flac:"
116	if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
117		die "ERROR: during test_seeking"
118	fi
119
120	echo "removing sample count from tiny$suffix.flac and small$suffix.flac:"
121	if run_metaflac --no-filename --set-total-samples=0 tiny$suffix.flac small$suffix.flac ; then : ; else
122		die "ERROR: during metaflac"
123	fi
124
125	echo "testing tiny$suffix.flac with total_samples=0:"
126	if run_test_seeking tiny$suffix.flac $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
127		die "ERROR: during test_seeking"
128	fi
129
130	echo "testing small$suffix.flac with total_samples=0:"
131	if run_test_seeking small$suffix.flac $small_seek_count $small_samples noise.raw ; then : ; else
132		die "ERROR: during test_seeking"
133	fi
134done
135
136if [ $has_ogg = "yes" ] ; then
137
138	echo "generating Ogg FLAC files for seeking:"
139	run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 --output-name=tiny.oga --ogg noise8m32.raw || die "ERROR generating Ogg FLAC file"
140	run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 --output-name=small.oga --ogg noise.raw || die "ERROR generating Ogg FLAC file"
141	# seek tables are not used in Ogg FLAC
142
143	echo "testing tiny.oga:"
144	if run_test_seeking tiny.oga $tiny_seek_count $tiny_samples noise8m32.raw ; then : ; else
145		die "ERROR: during test_seeking"
146	fi
147
148	echo "testing small.oga:"
149	if run_test_seeking small.oga $small_seek_count $small_samples noise.raw ; then : ; else
150		die "ERROR: during test_seeking"
151	fi
152
153fi
154
155rm -f tiny.flac tiny.oga small.flac small.oga tiny-s.flac small-s.flac
156