add test_picture to grabbag tests
[platform/upstream/flac.git] / test / test_seeking.sh
1 #!/bin/sh
2
3 #  FLAC - Free Lossless Audio Codec
4 #  Copyright (C) 2004,2005,2006  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
20 die ()
21 {
22         echo $* 1>&2
23         exit 1
24 }
25
26 if [ x = x"$1" ] ; then 
27         BUILD=debug
28 else
29         BUILD="$1"
30 fi
31
32 LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
33 LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH
34 export LD_LIBRARY_PATH
35 PATH=../src/flac:$PATH
36 PATH=../src/metaflac:$PATH
37 PATH=../src/test_seeking:$PATH
38 PATH=../src/test_streams:$PATH
39 PATH=../obj/$BUILD/bin:$PATH
40
41 flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
42 metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
43
44 run_flac ()
45 {
46         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
47                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 flac $* 4>>test_seeking.valgrind.log
48         else
49                 flac $*
50         fi
51 }
52
53 run_metaflac ()
54 {
55         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
56                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 metaflac $* 4>>test_seeking.valgrind.log
57         else
58                 metaflac $*
59         fi
60 }
61
62 run_test_seeking ()
63 {
64         if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
65                 valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 test_seeking $* 4>>test_seeking.valgrind.log
66         else
67                 test_seeking $*
68         fi
69 }
70
71 echo "Checking for --ogg support in flac..."
72 if 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
73         has_ogg=yes;
74         echo "flac --ogg works"
75 else
76         has_ogg=no;
77         echo "flac --ogg doesn't work"
78 fi
79
80
81 echo "Generating streams..."
82 if [ ! -f noise.raw ] ; then
83         test_streams || die "ERROR during test_streams"
84 fi
85
86 echo "generating FLAC files for seeking:"
87 run_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"
88 run_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"
89 run_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"
90 run_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"
91
92 tiny_samples=`metaflac --show-total-samples tiny.flac`
93 small_samples=`metaflac --show-total-samples small.flac`
94
95 for suffix in '' '-s' ; do
96         echo "testing tiny$suffix.flac:"
97         if run_test_seeking tiny$suffix.flac 100 $tiny_samples ; then : ; else
98                 die "ERROR: during test_seeking"
99         fi
100
101         echo "testing small$suffix.flac:"
102         if run_test_seeking small$suffix.flac 1000 $small_samples ; then : ; else
103                 die "ERROR: during test_seeking"
104         fi
105
106         echo "removing sample count from tiny$suffix.flac and small$suffix.flac:"
107         if run_metaflac --no-filename --set-total-samples=0 tiny$suffix.flac small$suffix.flac ; then : ; else
108                 die "ERROR: during metaflac"
109         fi
110
111         echo "testing tiny$suffix.flac with total_samples=0:"
112         if run_test_seeking tiny$suffix.flac 100 $tiny_samples ; then : ; else
113                 die "ERROR: during test_seeking"
114         fi
115
116         echo "testing small$suffix.flac with total_samples=0:"
117         if run_test_seeking small$suffix.flac 1000 $small_samples ; then : ; else
118                 die "ERROR: during test_seeking"
119         fi
120 done
121
122 if [ $has_ogg = "yes" ] ; then
123
124         echo "generating Ogg FLAC files for seeking:"
125         run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 --output-name=tiny.ogg --ogg noise8m32.raw || die "ERROR generating Ogg FLAC file"
126         run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 --output-name=small.ogg --ogg noise.raw || die "ERROR generating Ogg FLAC file"
127         # seek tables are not used in Ogg FLAC
128
129         echo "testing tiny.ogg:"
130         if run_test_seeking tiny.ogg 100 $tiny_samples ; then : ; else
131                 die "ERROR: during test_seeking"
132         fi
133
134         echo "testing small.ogg:"
135         if run_test_seeking small.ogg 1000 $small_samples ; then : ; else
136                 die "ERROR: during test_seeking"
137         fi
138
139 fi
140
141 rm -f tiny.flac tiny.ogg small.flac small.ogg tiny-s.flac small-s.flac