blob: 86970a6d56197954f8962d7e4cf0a16a44e83663 [file] [log] [blame]
Josh Coalsond09958f2002-06-14 06:31:35 +00001#!/bin/sh
2
3# FLAC - Free Lossless Audio Codec
Erik de Castro Lopob1982fb2013-05-25 17:11:19 +10004# Copyright (C) 2002-2009 Josh Coalson
5# Copyright (C) 2011-2013 Xiph.Org Foundation
Josh Coalsond09958f2002-06-14 06:31:35 +00006#
Josh Coalsone8a76012003-02-07 00:14:32 +00007# This file is part the FLAC project. FLAC is comprised of several
Ulrich Klauercd4ddab2013-05-26 22:53:43 +02008# components distributed under different licenses. The codec libraries
Josh Coalsone8a76012003-02-07 00:14:32 +00009# are distributed under Xiph.Org's BSD-like license (see the file
10# COPYING.Xiph in this distribution). All other programs, libraries, and
11# plugins are distributed under the GPL (see COPYING.GPL). The documentation
12# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the
13# FLAC distribution contains at the top the terms under which it may be
14# distributed.
Josh Coalsond09958f2002-06-14 06:31:35 +000015#
Josh Coalsone8a76012003-02-07 00:14:32 +000016# Since this particular file is relevant to all components of FLAC,
17# it may be distributed under the Xiph.Org license, which is the least
18# restrictive of those mentioned above. See the file COPYING.Xiph in this
19# distribution.
Josh Coalsond09958f2002-06-14 06:31:35 +000020
Josh Coalson6218b342002-12-12 03:58:18 +000021die ()
22{
23 echo $* 1>&2
24 exit 1
25}
26
Josh Coalsonff151cc2006-08-28 03:39:45 +000027if [ x = x"$1" ] ; then
Josh Coalsonb43d3cb2004-11-09 01:28:05 +000028 BUILD=debug
29else
30 BUILD="$1"
31fi
32
Josh Coalsonff151cc2006-08-28 03:39:45 +000033# change to 'false' to show all flac/metaflac output (useful for debugging)
34if true ; then
35 SILENT='--silent'
36 TOTALLY_SILENT='--totally-silent'
37else
38 SILENT=''
39 TOTALLY_SILENT=''
40fi
Josh Coalsond09958f2002-06-14 06:31:35 +000041
Josh Coalsonff151cc2006-08-28 03:39:45 +000042LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH
Josh Coalsonff151cc2006-08-28 03:39:45 +000043LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH
44LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH
45LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
46LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
47LD_LIBRARY_PATH=`pwd`/../src/share/utf8/.libs:$LD_LIBRARY_PATH
Erik de Castro Lopo85d5c532013-01-02 22:37:42 +110048LD_LIBRARY_PATH=`pwd`/../objs/$BUILD/lib:$LD_LIBRARY_PATH
Josh Coalsonff151cc2006-08-28 03:39:45 +000049export LD_LIBRARY_PATH
Cristian Rodríguez95f0f752012-04-17 22:12:45 -030050export MALLOC_CHECK_=3
Erik de Castro Lopo4f241612013-04-25 12:31:50 +100051export MALLOC_PERTURB_=$((1$(date +%N) % 255 + 1))
Josh Coalsonff151cc2006-08-28 03:39:45 +000052PATH=`pwd`/../src/flac:$PATH
53PATH=`pwd`/../src/metaflac:$PATH
Erik de Castro Lopo85d5c532013-01-02 22:37:42 +110054PATH=`pwd`/../objs/$BUILD/bin:$PATH
Josh Coalsonff151cc2006-08-28 03:39:45 +000055
Josh Coalson412a0372007-08-29 00:38:16 +000056if echo a | (grep -E '(a|b)') >/dev/null 2>&1
57 then EGREP='grep -E'
58 else EGREP='egrep'
59fi
60
Josh Coalsonff151cc2006-08-28 03:39:45 +000061testdir="metaflac-test-files"
62flacfile="metaflac.flac"
Josh Coalsond09958f2002-06-14 06:31:35 +000063
Josh Coalson6218b342002-12-12 03:58:18 +000064flac --help 1>/dev/null 2>/dev/null || die "ERROR can't find flac executable"
65metaflac --help 1>/dev/null 2>/dev/null || die "ERROR can't find metaflac executable"
Josh Coalson16a16e22002-06-15 05:14:04 +000066
Josh Coalson34c1ea82002-12-04 04:57:33 +000067run_flac ()
68{
Josh Coalsonde9091e2006-05-25 02:48:22 +000069 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
Martijn van Beurdenf6585b02013-04-21 23:12:16 +020070 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 flac $*" >>test_metaflac.valgrind.log
71 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 flac $* 4>>test_metaflac.valgrind.log
Josh Coalson34c1ea82002-12-04 04:57:33 +000072 else
73 flac $*
74 fi
75}
76
77run_metaflac ()
78{
Josh Coalsonde9091e2006-05-25 02:48:22 +000079 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
Martijn van Beurdenf6585b02013-04-21 23:12:16 +020080 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
81 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 4>>test_metaflac.valgrind.log
Josh Coalson34c1ea82002-12-04 04:57:33 +000082 else
83 metaflac $*
84 fi
85}
Josh Coalson2858ff32002-10-11 06:22:43 +000086
Josh Coalsonff151cc2006-08-28 03:39:45 +000087run_metaflac_silent ()
Josh Coalsond09958f2002-06-14 06:31:35 +000088{
Josh Coalsonff151cc2006-08-28 03:39:45 +000089 if [ -z "$SILENT" ] ; then
90 run_metaflac $*
91 else
92 if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
Martijn van Beurdenf6585b02013-04-21 23:12:16 +020093 echo "valgrind --leak-check=yes --show-reachable=yes --num-callers=50 metaflac $*" >>test_metaflac.valgrind.log
94 valgrind --leak-check=yes --show-reachable=yes --num-callers=50 --log-fd=4 metaflac $* 2>/dev/null 4>>test_metaflac.valgrind.log
Josh Coalsonff151cc2006-08-28 03:39:45 +000095 else
96 metaflac $* 2>/dev/null
97 fi
98 fi
Josh Coalsond09958f2002-06-14 06:31:35 +000099}
100
101check_flac ()
102{
Josh Coalson6218b342002-12-12 03:58:18 +0000103 run_flac --silent --test $flacfile || die "ERROR in $flacfile" 1>&2
Josh Coalsond09958f2002-06-14 06:31:35 +0000104}
105
Josh Coalsonff151cc2006-08-28 03:39:45 +0000106echo "Generating stream..."
107bytes=80000
108if dd if=/dev/zero ibs=1 count=$bytes | flac --force --verify -0 --input-size=$bytes --output-name=$flacfile --force-raw-format --endian=big --sign=signed --channels=1 --bps=8 --sample-rate=8000 - ; then
109 chmod +w $flacfile
110else
111 die "ERROR during generation"
112fi
113
Josh Coalsond09958f2002-06-14 06:31:35 +0000114check_flac
Josh Coalson16a16e22002-06-15 05:14:04 +0000115
Josh Coalsonff151cc2006-08-28 03:39:45 +0000116echo
Josh Coalson16a16e22002-06-15 05:14:04 +0000117
Josh Coalsonff151cc2006-08-28 03:39:45 +0000118filter ()
119{
120 # minor danger, changing vendor strings will change the length of the
121 # VORBIS_COMMENT block, but if we add "^ length: " to the patterns,
122 # we lose info about PADDING size that we need
Josh Coalsonb02574e2006-09-26 00:43:48 +0000123 # grep pattern 1: remove vendor string
124 # grep pattern 2: remove minimum/maximum frame and block size from STREAMINFO
125 # grep pattern 3: remove hexdump data from PICTURE metadata blocks
126 # sed pattern 1: remove stream offset values from SEEKTABLE points
Josh Coalson412a0372007-08-29 00:38:16 +0000127 $EGREP -v '^ vendor string: |^ m..imum .....size: |^ 0000[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]: ' | sed -e 's/, stream_offset.*//'
Josh Coalsonff151cc2006-08-28 03:39:45 +0000128}
129metaflac_test ()
130{
131 case="$1"
132 desc="$2"
133 args="$3"
134 expect="$testdir/$case-expect.meta"
135 echo -n "test $case: $desc... "
136 run_metaflac $args $flacfile | filter > $testdir/out.meta || die "ERROR running metaflac"
Josh Coalson412a0372007-08-29 00:38:16 +0000137 diff -w $expect $testdir/out.meta > /dev/null 2>&1 || die "ERROR: metadata does not match expected $expect"
Josh Coalsonff151cc2006-08-28 03:39:45 +0000138 echo OK
139}
Josh Coalson16a16e22002-06-15 05:14:04 +0000140
Josh Coalsonff151cc2006-08-28 03:39:45 +0000141metaflac_test case00 "--list" "--list"
142
143metaflac_test case01 "STREAMINFO --show-* shortcuts" "
144 --show-md5sum
145 --show-min-blocksize
146 --show-max-blocksize
147 --show-min-framesize
148 --show-max-framesize
149 --show-sample-rate
150 --show-channels
151 --show-bps
152 --show-total-samples"
153
154run_metaflac --preserve-modtime --add-padding=12345 $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000155check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000156metaflac_test case02 "--add-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000157
Josh Coalsonc6ea43b2002-10-26 04:28:11 +0000158# some flavors of /bin/sh (e.g. Darwin's) won't even handle quoted spaces, so we underscore:
Josh Coalsonff151cc2006-08-28 03:39:45 +0000159run_metaflac --set-tag="ARTIST=The_artist_formerly_known_as_the_artist..." $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000160check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000161metaflac_test case03 "--set-tag=ARTIST" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000162
Josh Coalsonff151cc2006-08-28 03:39:45 +0000163run_metaflac --set-tag="ARTIST=Chuck_Woolery" $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000164check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000165metaflac_test case04 "--set-tag=ARTIST" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000166
Josh Coalsonff151cc2006-08-28 03:39:45 +0000167run_metaflac --set-tag="ARTIST=Vern" $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000168check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000169metaflac_test case05 "--set-tag=ARTIST" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000170
Josh Coalsonff151cc2006-08-28 03:39:45 +0000171run_metaflac --set-tag="TITLE=He_who_smelt_it_dealt_it" $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000172check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000173metaflac_test case06 "--set-tag=TITLE" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000174
Josh Coalsonff151cc2006-08-28 03:39:45 +0000175metaflac_test case07 "--show-vendor-tag --show-tag=ARTIST" "--show-vendor-tag --show-tag=ARTIST"
Josh Coalsonc6ea43b2002-10-26 04:28:11 +0000176
Josh Coalsonff151cc2006-08-28 03:39:45 +0000177run_metaflac --remove-first-tag=ARTIST $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000178check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000179metaflac_test case08 "--remove-first-tag=ARTIST" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000180
Josh Coalsonff151cc2006-08-28 03:39:45 +0000181run_metaflac --remove-tag=ARTIST $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000182check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000183metaflac_test case09 "--remove-tag=ARTIST" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000184
Josh Coalsonff151cc2006-08-28 03:39:45 +0000185metaflac_test case10 "--list --block-type=VORBIS_COMMENT" "--list --block-type=VORBIS_COMMENT"
186metaflac_test case11 "--list --block-number=0" "--list --block-number=0"
187metaflac_test case12 "--list --block-number=1,2,999" "--list --block-number=1,2,999"
188metaflac_test case13 "--list --block-type=VORBIS_COMMENT,PADDING" "--list --block-type=VORBIS_COMMENT,PADDING"
189metaflac_test case14 "--list --except-block-type=SEEKTABLE,VORBIS_COMMENT" "--list --except-block-type=SEEKTABLE,VORBIS_COMMENT"
190metaflac_test case15 "--list --except-block-type=STREAMINFO" "--list --except-block-type=STREAMINFO"
Josh Coalsonc6ea43b2002-10-26 04:28:11 +0000191
Josh Coalsonff151cc2006-08-28 03:39:45 +0000192run_metaflac --add-padding=4321 $flacfile $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000193check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000194metaflac_test case16 "--add-padding=4321 * 2" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000195
Josh Coalsonff151cc2006-08-28 03:39:45 +0000196run_metaflac --merge-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000197check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000198metaflac_test case17 "--merge-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000199
Josh Coalsonff151cc2006-08-28 03:39:45 +0000200run_metaflac --add-padding=0 $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000201check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000202metaflac_test case18 "--add-padding=0" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000203
Josh Coalsonff151cc2006-08-28 03:39:45 +0000204run_metaflac --sort-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000205check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000206metaflac_test case19 "--sort-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000207
Josh Coalsonff151cc2006-08-28 03:39:45 +0000208run_metaflac --add-padding=0 $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000209check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000210metaflac_test case20 "--add-padding=0" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000211
Josh Coalsonff151cc2006-08-28 03:39:45 +0000212run_metaflac --remove-all-tags $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000213check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000214metaflac_test case21 "--remove-all-tags" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000215
Josh Coalsonff151cc2006-08-28 03:39:45 +0000216run_metaflac --remove --block-number=1,99 --dont-use-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000217check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000218metaflac_test case22 "--remove --block-number=1,99 --dont-use-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000219
Josh Coalsonff151cc2006-08-28 03:39:45 +0000220run_metaflac --remove --block-number=99 --dont-use-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000221check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000222metaflac_test case23 "--remove --block-number=99 --dont-use-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000223
Josh Coalsonff151cc2006-08-28 03:39:45 +0000224run_metaflac --remove --block-type=PADDING $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000225check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000226metaflac_test case24 "--remove --block-type=PADDING" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000227
Josh Coalsonff151cc2006-08-28 03:39:45 +0000228run_metaflac --remove --block-type=PADDING --dont-use-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000229check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000230metaflac_test case25 "--remove --block-type=PADDING --dont-use-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000231
Josh Coalsonff151cc2006-08-28 03:39:45 +0000232run_metaflac --add-padding=0 $flacfile $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000233check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000234metaflac_test case26 "--add-padding=0 * 2" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000235
Josh Coalsonff151cc2006-08-28 03:39:45 +0000236run_metaflac --remove --except-block-type=PADDING $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000237check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000238metaflac_test case27 "--remove --except-block-type=PADDING" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000239
Josh Coalsonff151cc2006-08-28 03:39:45 +0000240run_metaflac --remove-all $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000241check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000242metaflac_test case28 "--remove-all" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000243
Josh Coalsonff151cc2006-08-28 03:39:45 +0000244run_metaflac --remove-all --dont-use-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000245check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000246metaflac_test case29 "--remove-all --dont-use-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000247
Josh Coalsonff151cc2006-08-28 03:39:45 +0000248run_metaflac --remove-all --dont-use-padding $flacfile
Josh Coalson16a16e22002-06-15 05:14:04 +0000249check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000250metaflac_test case30 "--remove-all --dont-use-padding" "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000251
Josh Coalsonff151cc2006-08-28 03:39:45 +0000252run_metaflac --set-tag="f=0123456789abcdefghij" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000253check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000254metaflac_test case31 "--set-tag=..." "--list"
Josh Coalson16a16e22002-06-15 05:14:04 +0000255
Josh Coalsonff151cc2006-08-28 03:39:45 +0000256run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000257check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000258metaflac_test case32 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000259
Josh Coalsonff151cc2006-08-28 03:39:45 +0000260run_metaflac --remove-all-tags --set-tag="f=0123456789abcde" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000261check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000262metaflac_test case33 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000263
Josh Coalsonff151cc2006-08-28 03:39:45 +0000264run_metaflac --remove-all-tags --set-tag="f=0" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000265check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000266metaflac_test case34 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000267
Josh Coalsonff151cc2006-08-28 03:39:45 +0000268run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000269check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000270metaflac_test case35 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000271
Josh Coalsonff151cc2006-08-28 03:39:45 +0000272run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghi" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000273check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000274metaflac_test case36 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000275
Josh Coalsonff151cc2006-08-28 03:39:45 +0000276run_metaflac --remove-all-tags --set-tag="f=0123456789" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000277check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000278metaflac_test case37 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000279
Josh Coalsonff151cc2006-08-28 03:39:45 +0000280run_metaflac --remove-all-tags --set-tag="f=0123456789abcdefghij" $flacfile
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000281check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000282metaflac_test case38 "--remove-all-tags --set-tag=..." "--list"
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000283
Josh Coalsonff151cc2006-08-28 03:39:45 +0000284echo "TITLE=Tittle" | run_metaflac --import-tags-from=- $flacfile
Josh Coalsond4f62342002-09-05 05:38:22 +0000285check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000286metaflac_test case39 "--import-tags-from=-" "--list"
Josh Coalsond4f62342002-09-05 05:38:22 +0000287
288cat > vc.txt << EOF
289artist=Fartist
290artist=artits
291EOF
Josh Coalsonff151cc2006-08-28 03:39:45 +0000292run_metaflac --import-tags-from=vc.txt $flacfile
Josh Coalsond4f62342002-09-05 05:38:22 +0000293check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000294metaflac_test case40 "--import-tags-from=[FILE]" "--list"
Josh Coalsond4f62342002-09-05 05:38:22 +0000295
296rm vc.txt
297
Josh Coalsonff151cc2006-08-28 03:39:45 +0000298run_metaflac --add-replay-gain $flacfile
299check_flac
300metaflac_test case41 "--add-replay-gain" "--list"
301
302run_metaflac --remove-replay-gain $flacfile
303check_flac
304metaflac_test case42 "--remove-replay-gain" "--list"
305
Josh Coalsonb02574e2006-09-26 00:43:48 +0000306# CUESHEET blocks
Josh Coalson3c75a392002-11-27 04:46:14 +0000307cs_in=cuesheets/good.000.cue
308cs_out=metaflac.cue
309cs_out2=metaflac2.cue
Josh Coalsonff151cc2006-08-28 03:39:45 +0000310run_metaflac --import-cuesheet-from="$cs_in" $flacfile
Josh Coalson3c75a392002-11-27 04:46:14 +0000311check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000312metaflac_test case43 "--import-cuesheet-from" "--list"
313run_metaflac --export-cuesheet-to=$cs_out $flacfile
314run_metaflac --remove --block-type=CUESHEET $flacfile
Josh Coalson3c75a392002-11-27 04:46:14 +0000315check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000316metaflac_test case44 "--remove --block-type=CUESHEET" "--list"
317run_metaflac --import-cuesheet-from=$cs_out $flacfile
Josh Coalson3c75a392002-11-27 04:46:14 +0000318check_flac
Josh Coalsonff151cc2006-08-28 03:39:45 +0000319metaflac_test case45 "--import-cuesheet-from" "--list"
320run_metaflac --export-cuesheet-to=$cs_out2 $flacfile
Josh Coalson3c75a392002-11-27 04:46:14 +0000321echo "comparing cuesheets:"
Josh Coalson6218b342002-12-12 03:58:18 +0000322diff $cs_out $cs_out2 || die "ERROR, cuesheets should be identical"
Josh Coalson3c75a392002-11-27 04:46:14 +0000323echo identical
324
325rm -f $cs_out $cs_out2
326
Josh Coalsonb02574e2006-09-26 00:43:48 +0000327# PICTURE blocks
328ncase=46
329for f in \
330 0.gif \
331 1.gif \
332 2.gif \
333; do
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000334 run_metaflac --import-picture-from="|image/gif|$f||pictures/$f" $flacfile
Josh Coalsonb02574e2006-09-26 00:43:48 +0000335 check_flac
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000336 metaflac_test "case$ncase" "--import-picture-from" "--list"
Josh Coalsonb02574e2006-09-26 00:43:48 +0000337 ncase=`expr $ncase + 1`
338done
339for f in \
340 0.jpg \
341 4.jpg \
342; do
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000343 run_metaflac --import-picture-from="4|image/jpeg|$f||pictures/$f" $flacfile
Josh Coalsonb02574e2006-09-26 00:43:48 +0000344 check_flac
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000345 metaflac_test "case$ncase" "--import-picture-from" "--list"
Josh Coalsonb02574e2006-09-26 00:43:48 +0000346 ncase=`expr $ncase + 1`
347done
348for f in \
349 0.png \
350 1.png \
351 2.png \
352 3.png \
353 4.png \
354 5.png \
355 6.png \
356 7.png \
357 8.png \
358; do
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000359 run_metaflac --import-picture-from="5|image/png|$f||pictures/$f" $flacfile
Josh Coalsonb02574e2006-09-26 00:43:48 +0000360 check_flac
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000361 metaflac_test "case$ncase" "--import-picture-from" "--list"
Josh Coalsonb02574e2006-09-26 00:43:48 +0000362 ncase=`expr $ncase + 1`
363done
Josh Coalsona65fd932006-10-03 01:02:44 +0000364[ $ncase = 60 ] || die "expected case# to be 60"
Josh Coalson989f2672006-11-02 03:40:44 +0000365
366fn=export-picture-check
367echo -n "Testing --export-picture-to... "
368run_metaflac --export-picture-to=$fn $flacfile
369check_flac
370cmp $fn pictures/0.gif || die "ERROR, exported picture file and original differ"
371echo OK
372rm -f $fn
373echo -n "Testing --block-number --export-picture-to... "
374run_metaflac --block-number=9 --export-picture-to=$fn $flacfile
375check_flac
376cmp $fn pictures/0.png || die "ERROR, exported picture file and original differ"
377echo OK
378rm -f $fn
379
Josh Coalsonb02574e2006-09-26 00:43:48 +0000380run_metaflac --remove --block-type=PICTURE $flacfile
381check_flac
382metaflac_test case60 "--remove --block-type=PICTURE" "--list"
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000383run_metaflac --import-picture-from="1|image/png|standard_icon|32x32x24|pictures/0.png" $flacfile
Josh Coalsonb02574e2006-09-26 00:43:48 +0000384check_flac
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000385metaflac_test case61 "--import-picture-from" "--list"
386run_metaflac --import-picture-from="2|image/png|icon|64x64x24|pictures/1.png" $flacfile
Josh Coalsonb02574e2006-09-26 00:43:48 +0000387check_flac
Josh Coalsonaec8bb32006-11-02 04:06:56 +0000388metaflac_test case62 "--import-picture-from" "--list"
Josh Coalsonb02574e2006-09-26 00:43:48 +0000389
390# UNKNOWN blocks
Josh Coalson6b4dfd02003-01-11 06:23:16 +0000391echo -n "Testing FLAC file with unknown metadata... "
392cp -p metaflac.flac.in $flacfile
Josh Coalson43bb14d2003-01-16 07:21:20 +0000393# remove the VORBIS_COMMENT block so vendor string changes don't interfere with the comparison:
394run_metaflac --remove --block-type=VORBIS_COMMENT --dont-use-padding $flacfile
Josh Coalson6b4dfd02003-01-11 06:23:16 +0000395cmp $flacfile metaflac.flac.ok || die "ERROR, $flacfile and metaflac.flac.ok differ"
396echo OK
397
Erik de Castro Lopof20770e2012-03-19 07:44:11 +1100398# Replay gain tests - Test the rates which have specific filter table entries
399# and verify that harmonics can be processed correctly.
400
401tonegenerator ()
402{
Erik de Castro Lopo69c44a52013-04-25 13:53:21 +1000403 # When using GAWK, use --lint=posix to identify non-POSIX awk usages.
Erik de Castro Lopof20770e2012-03-19 07:44:11 +1100404 awk -- '
405 BEGIN {
406 samplerate = '$1';
407
408 tone = 1000;
409 duration = 1;
410 bitspersample = 24;
411
Erik de Castro Lopo69c44a52013-04-25 13:53:21 +1000412 samplemidpoint = 1;
413 for (sps = 0 ; sps < bitspersample - 1 ; sps++) {
414 samplemidpoint *= 2;
415 }
416
Erik de Castro Lopof20770e2012-03-19 07:44:11 +1100417 samplerange = samplemidpoint - 1;
418
419 pi = 4 * atan2(1,1);
420
421 for (ix = 0; ix < duration * samplerate; ++ix) {
422 sample = sin(2 * pi * tone * ix / samplerate);
423 sample *= samplerange;
424 sample += samplemidpoint;
425 sample = int(sample);
426 for (bx = 0; bx < bitspersample/8; ++bx) {
427 byte[bx] = sample % 256;
428 sample /= 256;
429 }
430 while (bx--) {
431 printf("%c", byte[bx]);
432 }
433 }
434
435 }' /dev/null |
436 flac --silent \
437 --endian=big --channels=1 --bps=24 --sample-rate=$1 --sign=unsigned -
438}
439
440REPLAYGAIN_FREQ=
441REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.73"
442REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.93"
443REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.93"
444REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-12.98"
445REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.27"
446REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.41"
447REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77"
448REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82"
449REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 28000/-14.06"
450REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 32000/-14.08"
451REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 36000/-14.12"
452REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 37800/-14.18"
453REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 44100/-14.17"
454REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 48000/-14.16:1:2:4"
455
Martijn van Beurden690205b2013-04-25 15:20:23 +0200456set -e
457
Erik de Castro Lopof20770e2012-03-19 07:44:11 +1100458for ACTION in $REPLAYGAIN_FREQ ; do
459 if [ -n "${ACTION##*:*}" ] ; then
460 HARMONICS=1
461 else
462 HARMONICS="${ACTION#*:}"
463 fi
464 FREQ="${ACTION%%/*}"
465 GAIN="${ACTION#*/}"
466 GAIN="${GAIN%%:*}"
467 while [ -n "$HARMONICS" ] ; do
468 MULTIPLE="${HARMONICS%%:*}"
469 if [ x"$MULTIPLE" = x"$HARMONICS" ] ; then
470 HARMONICS=
471 else
472 HARMONICS="${HARMONICS#*:}"
473 fi
474 RATE=$(($MULTIPLE * FREQ))
475 [ $MULTIPLE -eq 1 -o -n "${REPLAYGAIN_FREQ##* $RATE/*}" ] || break
476 echo -n "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... "
477 tonegenerator $RATE > $flacfile
478 run_metaflac --add-replay-gain $flacfile
479 run_metaflac --list $flacfile | grep REPLAYGAIN.*GAIN= |
480 while read -r REPLAYGAIN ; do
481 MEASUREDGAIN="${REPLAYGAIN##*=}"
482 MEASUREDGAIN="${MEASUREDGAIN%% *}"
483 if [ x"$MEASUREDGAIN" != x"$GAIN" ] ; then
484 die "ERROR, Expected $GAIN db instead of $REPLAYGAIN"
485 fi
486 done
487 echo OK
488 done
489done
490
491
Josh Coalsonb02574e2006-09-26 00:43:48 +0000492rm -f $testdir/out.flac $testdir/out.meta
Josh Coalsonff151cc2006-08-28 03:39:45 +0000493
Josh Coalsondaaf0a42002-06-18 05:25:41 +0000494exit 0