| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # Survex test suite - cavern tests |
|---|
| 4 | # Copyright (C) 1999-2004,2005 Olly Betts |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | |
|---|
| 20 | testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'` |
|---|
| 21 | |
|---|
| 22 | # allow us to run tests standalone more easily |
|---|
| 23 | : ${srcdir="$testdir"} |
|---|
| 24 | |
|---|
| 25 | # force VERBOSE if we're run on a subset of tests |
|---|
| 26 | test -n "$*" && VERBOSE=1 |
|---|
| 27 | |
|---|
| 28 | test -x "$testdir"/../src/cavern || testdir=. |
|---|
| 29 | |
|---|
| 30 | : ${CAVERN="$testdir"/../src/cavern} |
|---|
| 31 | : ${DIFFPOS="$testdir"/../src/diffpos} |
|---|
| 32 | : ${CAD3D="$testdir"/../src/cad3d} |
|---|
| 33 | |
|---|
| 34 | : ${TESTS=${*-"singlefix singlereffix oneleg midpoint noose cross firststn\ |
|---|
| 35 | deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\ |
|---|
| 36 | lengthunits angleunits cmd_truncate cmd_case cmd_fix cmd_solve\ |
|---|
| 37 | cmd_entrance cmd_sd cmd_sd_bad cmd_fix_bad cmd_set cmd_set_bad\ |
|---|
| 38 | beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\ |
|---|
| 39 | expobug require export export2 includecomment\ |
|---|
| 40 | self_loop self_eq_loop reenterwarn cmd_default cmd_prefix\ |
|---|
| 41 | singlefixerr singlereffixerr\ |
|---|
| 42 | begin_no_end end_no_begin end_no_begin_nest require_fail\ |
|---|
| 43 | exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\ |
|---|
| 44 | exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\ |
|---|
| 45 | hanging_cpt badinc badinc2 non_existant_file ONELEG\ |
|---|
| 46 | stnsurvey1 stnsurvey2 stnsurvey3\ |
|---|
| 47 | tapelessthandepth longname chinabug chinabug2\ |
|---|
| 48 | multinormal multinormignall multidiving multicylpolar multicartesian\ |
|---|
| 49 | multinosurv multinormalbad multibug\ |
|---|
| 50 | cmd_title cmd_titlebad cmd_dummy cmd_infer\ |
|---|
| 51 | cartes diving cylpolar normal normignall nosurv cmd_flags bad_cmd_flags\ |
|---|
| 52 | plumb unusedstation exportnakedbegin oldestyle bugdz baddatacylpolar\ |
|---|
| 53 | badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug omitclino back\ |
|---|
| 54 | notentranceorexport inferunknown inferexports bad_units_factor\ |
|---|
| 55 | percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\ |
|---|
| 56 | nosurveyhanging datapassage\ |
|---|
| 57 | lech level 2fixbug declination.dat ignore.dat dot17 3dcorner surfequate"}} |
|---|
| 58 | |
|---|
| 59 | for file in $TESTS ; do |
|---|
| 60 | # how many warnings to expect |
|---|
| 61 | warn= |
|---|
| 62 | # how many errors to expect |
|---|
| 63 | error= |
|---|
| 64 | case $file in |
|---|
| 65 | singlefix) pos=yes ; warn=1;; |
|---|
| 66 | singlereffix) pos=yes ; warn=0 ;; |
|---|
| 67 | oneleg) pos=yes ; warn=0 ;; |
|---|
| 68 | midpoint) pos=yes ; warn=0 ;; |
|---|
| 69 | noose) pos=yes ; warn=0 ;; |
|---|
| 70 | cross) pos=yes ; warn=0 ;; |
|---|
| 71 | firststn) pos=yes ; warn=0 ;; |
|---|
| 72 | deltastar) pos=yes ; warn=0 ;; |
|---|
| 73 | deltastar2) pos=yes ; warn=0 ;; |
|---|
| 74 | bug3) pos=yes ; warn=0 ;; |
|---|
| 75 | calibrate_tape) pos=yes ; warn=0 ;; |
|---|
| 76 | nosurvey2) pos=yes ; warn=0 ;; |
|---|
| 77 | cartesian) pos=yes ; warn=0 ;; |
|---|
| 78 | cartesian2) pos=yes ; warn=0 ;; |
|---|
| 79 | lengthunits) pos=yes ; warn=0 ;; |
|---|
| 80 | angleunits) pos=yes ; warn=0 ;; |
|---|
| 81 | cmd_truncate) pos=yes ; warn=0 ;; |
|---|
| 82 | cmd_case) pos=yes ; warn=0 ;; |
|---|
| 83 | cmd_fix) pos=yes ; warn=1 ;; |
|---|
| 84 | cmd_fix_bad) pos=fail ; error=10 ;; |
|---|
| 85 | cmd_solve) pos=yes ; warn=0 ;; |
|---|
| 86 | cmd_entrance) pos=no ; warn=0 ;; |
|---|
| 87 | cmd_sd) pos=no ; warn=0 ;; |
|---|
| 88 | cmd_sd_bad) pos=fail ; error=7 ;; |
|---|
| 89 | cmd_set) pos=no ; warn=0 ;; |
|---|
| 90 | cmd_set_bad) pos=fail ; error=7 ;; |
|---|
| 91 | beginroot) pos=no ;; |
|---|
| 92 | revcomplist) pos=no ; warn=0 ;; |
|---|
| 93 | break_replace_pfx) pos=no ; warn=0 ;; |
|---|
| 94 | bug0) pos=no ; warn=0 ;; |
|---|
| 95 | bug1) pos=no ; warn=0 ;; |
|---|
| 96 | bug2) pos=no ; warn=0 ;; |
|---|
| 97 | bug4) pos=no ; warn=0 ;; |
|---|
| 98 | bug5) pos=no ; warn=0 ;; |
|---|
| 99 | expobug) pos=no ; warn=0 ;; |
|---|
| 100 | require) pos=no ; warn=0 ;; |
|---|
| 101 | export) pos=no ; warn=0 ;; |
|---|
| 102 | export2) pos=no ; warn=0 ;; |
|---|
| 103 | includecomment) pos=no ; warn=0 ;; |
|---|
| 104 | self_loop) pos=fail ; warn=0 ;; |
|---|
| 105 | self_eq_loop) pos=no ; warn=1 ;; |
|---|
| 106 | reenterwarn) pos=no ; warn=2 ;; |
|---|
| 107 | cmd_default) pos=no ; warn=3 ;; |
|---|
| 108 | singlereffixerr) pos=no ; warn=0 ;; |
|---|
| 109 | cmd_prefix) pos=no ; warn=1 ;; |
|---|
| 110 | singlefixerr) pos=no ; warn=1 ;; |
|---|
| 111 | tapelessthandepth) pos=no ; warn=1 ;; |
|---|
| 112 | chinabug2) pos=no ; warn=0 ;; |
|---|
| 113 | longname) pos=no ; warn=0 ;; |
|---|
| 114 | chinabug) pos=fail ;; |
|---|
| 115 | begin_no_end) pos=fail ;; |
|---|
| 116 | end_no_begin) pos=fail ;; |
|---|
| 117 | end_no_begin_nest) pos=fail ;; |
|---|
| 118 | require_fail) pos=fail ;; |
|---|
| 119 | exporterr1) pos=fail ;; |
|---|
| 120 | exporterr2) pos=fail ;; |
|---|
| 121 | exporterr3) pos=fail ;; |
|---|
| 122 | exporterr4) pos=fail ;; |
|---|
| 123 | exporterr5) pos=fail ;; |
|---|
| 124 | exporterr1b) pos=fail ;; |
|---|
| 125 | exporterr2b) pos=fail ;; |
|---|
| 126 | exporterr3b) pos=fail ;; |
|---|
| 127 | exporterr6) pos=fail ;; |
|---|
| 128 | exporterr6b) pos=fail ;; |
|---|
| 129 | hanging_cpt) pos=fail ;; |
|---|
| 130 | badinc) pos=fail ;; |
|---|
| 131 | badinc2) pos=fail ;; |
|---|
| 132 | non_existant_file) pos=fail ;; |
|---|
| 133 | ONELEG) pos=fail ;; |
|---|
| 134 | stnsurvey1) pos=fail ;; |
|---|
| 135 | stnsurvey2) pos=fail ;; |
|---|
| 136 | stnsurvey3) pos=fail ;; |
|---|
| 137 | multinormal) pos=yes ; warn=0 ;; |
|---|
| 138 | multinormignall) pos=yes ; warn=0 ;; |
|---|
| 139 | multidiving) pos=yes ; warn=0 ;; |
|---|
| 140 | multicylpolar) pos=yes ; warn=0 ;; |
|---|
| 141 | multicartesian) pos=yes ; warn=0 ;; |
|---|
| 142 | multinosurv) pos=yes ; warn=0 ;; |
|---|
| 143 | multinormalbad) pos=fail ;; |
|---|
| 144 | multibug) pos=no ; warn=0 ;; |
|---|
| 145 | cmd_title) pos=no ; warn=0 ;; |
|---|
| 146 | cmd_titlebad) pos=fail ; error=4 ;; |
|---|
| 147 | cmd_dummy) pos=no ; warn=0 ;; |
|---|
| 148 | cmd_infer) pos=yes ; warn=0 ;; |
|---|
| 149 | cartes) pos=yes ; warn=0 ;; |
|---|
| 150 | diving) pos=yes ; warn=0 ;; |
|---|
| 151 | cylpolar) pos=yes ; warn=0 ;; |
|---|
| 152 | normal) pos=yes ; warn=0 ;; |
|---|
| 153 | normignall) pos=yes ; warn=0 ;; |
|---|
| 154 | nosurv) pos=yes ; warn=0 ;; |
|---|
| 155 | cmd_flags) pos=no ; warn=0 ;; |
|---|
| 156 | bad_cmd_flags) pos=fail ; error=19 ;; |
|---|
| 157 | plumb) pos=yes ; warn=0 ;; |
|---|
| 158 | unusedstation) pos=no ; warn=2 ;; |
|---|
| 159 | oldestyle) pos=no ; warn=1 ;; |
|---|
| 160 | exportnakedbegin) pos=fail ;; |
|---|
| 161 | bugdz) pos=yes ; warn=0 ;; |
|---|
| 162 | baddatacylpolar) pos=fail ; error=1 ;; |
|---|
| 163 | badnewline) pos=fail ; error=2 ;; |
|---|
| 164 | badquantities) pos=fail ; error=11 ;; |
|---|
| 165 | imgoffbyone) pos=yes ;; # don't actually care about coords, just the names |
|---|
| 166 | infereqtopofil) pos=yes ; warn=0 ;; |
|---|
| 167 | 3sdfixbug) pos=yes ; warn=0 ;; |
|---|
| 168 | omitclino) pos=yes ; warn=0 ;; |
|---|
| 169 | back) pos=yes; warn=0 ;; |
|---|
| 170 | notentranceorexport) pos=fail; warn=0 ;; |
|---|
| 171 | inferunknown) pos=fail; error=1 ;; |
|---|
| 172 | inferexports) pos=no; warn=0 ;; |
|---|
| 173 | bad_units_factor) pos=fail; error=5 ;; |
|---|
| 174 | percent_gradient) pos=yes; warn=0 ;; |
|---|
| 175 | dotinsurvey) pos=no; warn=0 ;; |
|---|
| 176 | leandroclino) pos=yes; warn=0 ;; |
|---|
| 177 | lowsd) pos=no; warn=0 ;; |
|---|
| 178 | revdir) pos=yes; warn=0 ;; |
|---|
| 179 | gettokennullderef) pos=fail ;; |
|---|
| 180 | lech) pos=no; warn=0 ;; |
|---|
| 181 | level) pos=yes; warn=0 ;; |
|---|
| 182 | 2fixbug) pos=no; warn=0 ;; |
|---|
| 183 | declination.dat|ignore.dat) pos=yes; warn=0 ;; |
|---|
| 184 | dot17) pos=yes; warn=0 ;; |
|---|
| 185 | 3dcorner) pos=yes; warn=0 ;; |
|---|
| 186 | surfequate) pos=dxf; warn=0 ;; |
|---|
| 187 | nosurveyhanging) pos=fail ;; |
|---|
| 188 | datapassage) pos=no; warn=0 ;; |
|---|
| 189 | *) echo "Warning: don't know how to run test '$file' - skipping it" |
|---|
| 190 | file='' ;; |
|---|
| 191 | esac |
|---|
| 192 | |
|---|
| 193 | if test -n "$file" ; then |
|---|
| 194 | echo "$file" |
|---|
| 195 | case $file in |
|---|
| 196 | *.*) |
|---|
| 197 | input="$srcdir/$file" |
|---|
| 198 | posfile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.pos/'` |
|---|
| 199 | dxffile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.dxf/'` ;; |
|---|
| 200 | *) |
|---|
| 201 | input="$srcdir/$file.svx" |
|---|
| 202 | posfile="$srcdir/$file.pos" |
|---|
| 203 | dxffile="$srcdir/$file.dxf" ;; |
|---|
| 204 | esac |
|---|
| 205 | rm -f tmp.* |
|---|
| 206 | $CAVERN "$input" --output=tmp > tmp.out |
|---|
| 207 | exitcode=$? |
|---|
| 208 | test -n "$VERBOSE" && cat tmp.out |
|---|
| 209 | if test fail = "$pos" ; then |
|---|
| 210 | # success gives 0, signal (128 + <signal number>) |
|---|
| 211 | test $exitcode = 1 || exit 1 |
|---|
| 212 | else |
|---|
| 213 | test $exitcode = 0 || exit 1 |
|---|
| 214 | fi |
|---|
| 215 | if test -n "$warn" ; then |
|---|
| 216 | w=`sed '$!d;$s/^Done.*/0/;s/[^0-9]*\([0-9]*\).*/\1/' tmp.out` |
|---|
| 217 | test x"$w" = x"$warn" || exit 1 |
|---|
| 218 | fi |
|---|
| 219 | if test -n "$error" ; then |
|---|
| 220 | e=`sed '$!d;$s/^Done.*/0/;s/[^0-9]*[0-9][0-9]*[^0-9][^0-9]*\([0-9][0-9]*\).*/\1/;s/\(.*[^0-9].*\)/0/' tmp.out` |
|---|
| 221 | test x"$e" = x"$error" || exit 1 |
|---|
| 222 | fi |
|---|
| 223 | nan=`sed 's/.*\<[Nn]a[Nn]m\?\>.*/x/p;d' tmp.out` |
|---|
| 224 | if test -n "$nan" ; then |
|---|
| 225 | exit 1 |
|---|
| 226 | fi |
|---|
| 227 | |
|---|
| 228 | case $pos in |
|---|
| 229 | yes) |
|---|
| 230 | if test -n "$VERBOSE" ; then |
|---|
| 231 | $DIFFPOS tmp.3d "$posfile" || exit 1 |
|---|
| 232 | else |
|---|
| 233 | $DIFFPOS tmp.3d "$posfile" > /dev/null || exit 1 |
|---|
| 234 | fi ;; |
|---|
| 235 | dxf) |
|---|
| 236 | if test -n "$VERBOSE" ; then |
|---|
| 237 | $CAD3D tmp.3d tmp.dxf || exit 1 |
|---|
| 238 | diff tmp.dxf "$dxffile" || exit 1 |
|---|
| 239 | else |
|---|
| 240 | $CAD3D tmp.3d tmp.dxf > /dev/null || exit 1 |
|---|
| 241 | cmp -s tmp.dxf "$dxffile" || exit 1 |
|---|
| 242 | fi ;; |
|---|
| 243 | no) |
|---|
| 244 | test -f tmp.3d || exit 1 ;; |
|---|
| 245 | fail) |
|---|
| 246 | test -f tmp.3d && exit 1 ;; |
|---|
| 247 | *) |
|---|
| 248 | echo "Bad value for pos: '$pos'" ; exit 1 ;; |
|---|
| 249 | esac |
|---|
| 250 | rm -f tmp.* |
|---|
| 251 | fi |
|---|
| 252 | done |
|---|
| 253 | test -n "$VERBOSE" && echo "Test passed" |
|---|
| 254 | exit 0 |
|---|