Debian Codegraph @

tests/common

raw symbols SCIP
1 #!/bin/sh
2 # Test a command for presence and ability to output the sha1 hash of a file
3 is_hash() {
4 echo -n "checking for SHA1 hashing command ... "
5 if check_hash sha1sum; then
6 sha1sum=sha1sum
7 elif check_hash sha1; then
8 sha1sum=sha1
9 elif check_hash shasum; then
10 sha1sum=shasum
11 else
12 echo "no"
13 exit 1
14 fi
15 }
16 check_hash() {
17 which $1 &&
18 $1 </dev/null 2>/dev/null |
19 awk '{if ($1 != "da39a3ee5e6b4b0d3255bfef95601890afd80709") { exit 1; }}'
20 # Test some common commands to find the correct one for the system being tested on.
21 }
22
23 # test if MBROLA synthesizer is installed
24 is_mbrola() {
25 echo -n "checking if MBROLA is installed ... "
26 if [ "`which mbrola`" != "" ]; then
27 echo "yes"
28 else
29 echo "no"
30 exit
31 fi
32 }
33
34 # Check processed text by phonetic representation of the output
35 test_phon() {
36 TEST_LANG=$1
37 EXPECTED=$2
38 TEST_TEXT=$3
39 MESSAGE=$4
40 OPTIONS=$5
41
42 if [ "$MESSAGE" = "" ] ; then
43 MESSAGE=$TEST_TEXT
44 fi
45
46 echo "testing ${TEST_LANG} $MESSAGE"
47 RESULT=$(
48 ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} \
49 $VALGRIND src/espeak-ng -xq ${OPTIONS} -v ${TEST_LANG} "${TEST_TEXT}" || exit 1
50 )
51 if [ "x$RESULT" != "x$EXPECTED" ] ; then
52 echo "$RESULT != $EXPECTED"
53 if [ "$MESSAGE" = "Ignore" ] ; then
54 echo "... ignoring error"
55 else
56 exit 1
57 fi
58 fi
59 }
60
61 # Check generated wav file from processed text
62 test_wav () {
63 VOICE=$1
64 EXPECTED=$2
65 TEST_TEXT=$3
66 MESSAGE=$4
67
68 echo "testing ${VOICE} ${MESSAGE}"
69 RESULT=$(
70 ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} \
71 $VALGRIND src/espeak-ng -D --stdout -v ${VOICE} "${TEST_TEXT}" | $sha1sum | awk '{ print $1 }' || exit 1
72 )
73 if [ "x$RESULT" != "x$EXPECTED" ] ; then
74 echo "$RESULT != $EXPECTED"
75 if [ "$MESSAGE" = "Ignore" ] ; then
76 echo "... ignoring error"
77 else
78 exit 1
79 fi
80 fi
81 }
82
83 # Check generated wav file from processed text, where $EXPECTED is grep string
84 test_wav_grep () {
85 VOICE=$1
86 EXPECTED=$2
87 TEST_TEXT=$3
88 MESSAGE=$4
89 echo "testing ${VOICE} ${MESSAGE}"
90 $()
91 ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} \
92 $VALGRIND src/espeak-ng -D --stdout -v ${VOICE} "${TEST_TEXT}" \
93 > actual.txt || exit 1
94 < actual.txt $sha1sum | awk '{ print $1 }' > sum.txt
95 if [ "$MESSAGE" = "Ignore" ] ; then
96 cat sum.txt | grep -E "$EXPECTED" || (echo "... ignoring error" && true)
97 else
98 cat sum.txt | grep -E "$EXPECTED" || { printf "wrong hash: "; cat sum.txt; exit 1; }
99 fi
100 }
101
102 # Check generated wav file from list of phonemes
103 test_phwav() {
104 TEST_LANG=$1
105 EXPECTED=$2
106 TEST_TEXT=$3
107 test_wav $TEST_LANG $EXPECTED "[[$TEST_TEXT]]"
108 }
109
110 test_replace() {
111 TEST_LANG=$1
112 TEST_TEXT=$2
113 EXPECTED=$3
114 MESSAGE=$4
115
116 if [ "$MESSAGE" = "" ] ; then
117 MESSAGE=$TEST_TEXT
118 fi
119
120 echo "testing ${TEST_LANG}"
121 RESULT=$(
122 ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} \
123 $VALGRIND src/espeak-ng -Xq -v ${TEST_LANG} "${TEST_TEXT}" | \
124 grep -a -E "(Translate|Found:) " | sed -e 's/ \[.*][ ]*$//g' || exit 1
125 )
126 if [ "x$RESULT" != "x$EXPECTED" ] ; then
127 echo "$RESULT != $EXPECTED"
128 if [ "$MESSAGE" = "Ignore" ] ; then
129 echo "... ignoring error"
130 else
131 exit 1
132 fi
133 fi
134 }