1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
#! /bin/sh
# check script for GNU Ocrad - Optical Character Recognition program
# Copyright (C) 2009-2024 Antonio Diaz Diaz.
#
# This script is free software: you have unlimited permission
# to copy, distribute, and modify it.
LC_ALL=C
export LC_ALL
objdir=`pwd`
testdir=`cd "$1" ; pwd`
OCRAD="${objdir}"/ocrad
OCRADCHECK="${objdir}"/ocradcheck
framework_failure() { echo "failure in testing framework" ; exit 1 ; }
if [ ! -f "${OCRAD}" ] || [ ! -x "${OCRAD}" ] ; then
echo "${OCRAD}: cannot execute"
exit 1
fi
if [ -d tmp ] ; then rm -rf tmp ; fi
mkdir tmp
cd "${objdir}"/tmp || framework_failure
in="${testdir}"/test.pbm
ouf="${testdir}"/test.ouf
txt="${testdir}"/test.txt
utxt="${testdir}"/test_utf8.txt
t2_png="${testdir}"/test2.png
t2_txt="${testdir}"/test2.txt
fail=0
test_failed() { fail=1 ; printf " $1" ; [ -z "$2" ] || printf "($2)" ; }
printf "testing ocrad-%s..." "$2"
"${OCRAD}" -q -T-0.1 "${in}" > /dev/null
[ $? = 1 ] || test_failed $LINENO
"${OCRAD}" -q -T 1.1 "${in}" > /dev/null
[ $? = 1 ] || test_failed $LINENO
"${OCRAD}" -q -u -2,-1,1,1 "${in}" > /dev/null
[ $? = 1 ] || test_failed $LINENO
"${OCRAD}" -q -u 1,1,1,1 "${in}" > /dev/null
[ $? = 1 ] || test_failed $LINENO
"${OCRAD}" "${in}" -o out || test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" "${in}" > out || test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" < "${in}" > out || test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -F utf8 "${in}" > out || test_failed $LINENO
cmp "${utxt}" out || test_failed $LINENO
"${OCRAD}" -F utf8 < "${in}" > out || test_failed $LINENO
cmp "${utxt}" out || test_failed $LINENO
"${OCRAD}" "${in}" -o a/b/c/out || test_failed $LINENO
cmp "${txt}" a/b/c/out || test_failed $LINENO
rm -rf a || framework_failure
"${OCRAD}" -q "${in}" -o a/b/c/
[ $? = 1 ] || test_failed $LINENO
[ ! -e a ] || test_failed $LINENO
"${OCRAD}" -E "${ouf}" "${in}" > out || test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -E "${ouf}" -F utf8 "${in}" > out || test_failed $LINENO
cmp "${utxt}" out || test_failed $LINENO
"${OCRAD}" -u 0,0,1,1 "${in}" > out
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -u 0,0,1,1 - < "${in}" > out
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -C -u 0,0,1,1 "${in}" > out
cmp "${in}" out || test_failed $LINENO
"${OCRAD}" -u -1,-1,1,1 "${in}" > out
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" - -u -1,-1,1,1 < "${in}" > out
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -C -u -1,-1,1,1 "${in}" > out
cmp "${in}" out || test_failed $LINENO
cat "${in}" "${in}" > in2 || framework_failure
cat "${txt}" "${txt}" > txt2 || framework_failure
"${OCRAD}" < in2 > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" "${in}" "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" "${in}" - < "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" - "${in}" < "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" - "${in}" - < "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" - - "${in}" < "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
"${OCRAD}" "${in}" - - < "${in}" > out || test_failed $LINENO
cmp txt2 out || test_failed $LINENO
cat "${utxt}" "${utxt}" > utxt2 || framework_failure
"${OCRAD}" -F utf8 < in2 > out || test_failed $LINENO
cmp utxt2 out || test_failed $LINENO
"${OCRAD}" -F utf8 "${in}" "${in}" > out || test_failed $LINENO
cmp utxt2 out || test_failed $LINENO
rm -f in2 txt2 utxt2 || framework_failure
test_chars()
{
for coord in ${coords} ; do
produced_chars="${produced_chars}`"${OCRAD}" -u${coord} "${in}"`" ||
test_failed $LINENO ${coord}
done
if [ "${produced_chars}" != "${expected_chars}" ] ; then
echo
echo "expected \"${expected_chars}\""
echo "produced \"${produced_chars}\""
fail=1
fi
}
# lines 1, 2, 3
coords=' 71,109,17,26 92,109,17,26 114,109,15,26 132,109,17,26
152,109,18,26 172,109,19,26 193,109,17,26 214,109,17,26
234,108,17,27 253,109,18,26 274,109,17,26 68,153,29,27
97,153,24,27 126,153,23,27 153,153,27,27 183,153,24,27
210,153,23,27 237,153,27,27 266,153,30,27 298,153,13,27
313,153,20,27 335,153,29,27 365,153,23,27 391,153,34,27
426,153,30,27 69,189,30,35 102,197,26,27 132,197,24,27
159,197,26,34 188,197,26,27 217,197,20,27 241,197,24,27
266,197,30,27 297,197,28,27 326,197,37,27 364,197,27,27
390,197,28,27 420,197,21,27'
expected_chars="0ol23456789ABcDEFGHIJKLMNopQRsTuvwxYz"
produced_chars=
test_chars
# lines 4, 5
coords=' 71,250,18,18 90,240,20,28 112,250,15,18 131,240,19,28
152,250,17,18 170,241,16,27 183,249,20,27 204,240,23,28
227,241,11,27 236,241,11,35 251,240,22,28 274,240,11,28
287,250,32,18 321,250,22,18 70,288,22,25 92,295,17,18
111,295,19,26 132,295,20,26 152,295,16,18 169,295,14,18
185,288,13,25 200,295,22,18 221,295,20,18 242,295,27,18
270,295,20,18 289,295,20,26 310,295,16,18'
expected_chars="abcdefghijklmnopqrstuvwxyz"
produced_chars=
test_chars
# line 7
coords=' 68,366,29,36 97,366,24,36 124,366,13,36 140,366,26,36
168,366,30,36 208,366,29,36 237,366,24,36 265,366,13,36
281,366,26,36 308,366,30,36 349,368,29,34 378,368,24,34
405,368,13,34 421,368,26,34 449,368,30,34'
expected_chars=""
produced_chars=
test_chars
# line 8
coords=' 68,410,29,36 97,410,24,36 124,410,13,36 140,410,26,36
167,410,30,36 208,410,29,36 238,410,20,36 259,410,28,36
288,412,28,34 317,410,21,36 355,419,18,27 377,419,14,27
392,419,20,35 414,421,20,33 435,419,16,27'
expected_chars="Ũݾ"
produced_chars=
test_chars
# line 9
coords=' 71,463,18,27 91,463,17,27 109,463,11,27 123,463,17,27
142,463,22,27 177,463,18,27 198,463,17,27 216,463,11,27
229,463,17,27 249,463,22,27 284,466,18,24 305,466,17,24
323,466,12,24 336,466,17,24 356,466,22,24 391,463,18,27
411,463,17,27 431,463,10,27 443,463,17,27 462,463,22,27'
expected_chars=""
produced_chars=
test_chars
# line 10
coords=' 71,508,5,27 97,509,19,26 120,505,17,35 174,508,27,27
216,508,10,31 230,508,9,31 244,508,15,15 264,516,19,19
333,508,11,27 367,516,19,19 413,516,19,19 438,508,14,27'
expected_chars="!#$&()*+/<>?"
produced_chars=
test_chars
# line 11
coords=' 70,552,25,27 99,552,9,31 113,552,15,27 133,552,9,31
148,552,17,15 205,552,8,31 223,552,3,27 236,552,9,31
250,552,18,6 272,558,5,29 285,554,12,15 301,566,19,10
325,554,11,11 341,557,19,22 365,554,11,15 381,558,15,29
400,561,15,26 417,552,23,35'
expected_chars="@[\\]^{|}~o"
produced_chars=
test_chars
"${OCRAD}" -C -t rotate90 "${in}" | "${OCRAD}" -t rotate270 > out ||
test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -C -t rotate180 "${in}" | "${OCRAD}" -t rotate180 > out ||
test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -C -t mirror_lr "${in}" | "${OCRAD}" -t mirror_lr > out ||
test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRAD}" -C -t mirror_tb "${in}" | "${OCRAD}" -t mirror_tb > out ||
test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
# test conversion to/from png
"${OCRAD}" -C7 "${in}" | "${OCRAD}" -C4 - > out || test_failed $LINENO
cmp "${in}" out || test_failed $LINENO
"${OCRAD}" -C8 "${in}" | "${OCRAD}" -C4 - > out || test_failed $LINENO
cmp "${in}" out || test_failed $LINENO
"${OCRAD}" -C7 "${in}" | "${OCRAD}" -C5 - > out7 || test_failed $LINENO
"${OCRAD}" -C8 "${in}" | "${OCRAD}" -C5 - > out8 || test_failed $LINENO
cmp out7 out8 || test_failed $LINENO
rm -f out7 out8 || framework_failure
"${OCRAD}" -i "${t2_png}" > out || test_failed $LINENO
cmp "${t2_txt}" out || test_failed $LINENO
for i in 1 2 3 4 5 6 7 8 ; do
"${OCRAD}" -i -C$i "${t2_png}" | "${OCRAD}" - > out || test_failed $LINENO $i
cmp "${t2_txt}" out || test_failed $LINENO $i
done
"${OCRADCHECK}" "${in}" > out || test_failed $LINENO
cmp "${txt}" out || test_failed $LINENO
"${OCRADCHECK}" --utf8 "${in}" > out || test_failed $LINENO
cmp "${utxt}" out || test_failed $LINENO
"${OCRADCHECK}" -i "${t2_png}" > out || test_failed $LINENO
cmp "${t2_txt}" out || test_failed $LINENO
"${OCRADCHECK}" -i -l "${t2_png}" > out || test_failed $LINENO
cmp "${t2_txt}" out || test_failed $LINENO
"${OCRADCHECK}" -i --utf8 "${t2_png}" > out || test_failed $LINENO
cmp "${t2_txt}" out || test_failed $LINENO
echo
if [ ${fail} = 0 ] ; then
echo "tests completed successfully."
cd "${objdir}" && rm -r tmp
else
echo "tests failed."
fi
exit ${fail}
|