File: testo

package info (click to toggle)
gpsbabel 1.7.0%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100,408 kB
  • sloc: cpp: 104,725; xml: 14,055; sh: 4,699; ansic: 2,062; makefile: 960; perl: 681; tcl: 138; javascript: 9
file content (181 lines) | stat: -rwxr-xr-x 3,595 bytes parent folder | download
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
#!/usr/bin/env sh

GPSBABEL_FREEZE_TIME=y
export GPSBABEL_FREEZE_TIME

# Turn on GNU libc instrumentation.
MALLOC_CHECK_=2
export MALLOC_CHECK_

# Testcases are written for English/US locale (by default)
LC_ALL=en_US.UTF-8
export LC_ALL

BASEPATH=`dirname $0`
PNAME=${PNAME:-${BASEPATH}/gpsbabel}
DIFF=${DIFF:-diff}
REFERENCE=${BASEPATH}/reference
# OD=${OD:-od -Ax -txC -v}
if [ -x /usr/bin/hexdump ] ; then
	OD=${OD:-hexdump -v -C}
else
	OD=${OD:-od -Ax -txC -v}
fi
XMLWF=xmlwf
# set up a variable so we can skip extra tests when running valgrind
echo "${PNAME}" | grep -q valgrind
RUNNINGVALGRIND=$?

TMPDIR=${GBTEMP:-/tmp}/gpsbabel.$$
mkdir -p $TMPDIR
trap "rm -fr $TMPDIR" 0 1 2 3 15

bincompare()
{
	rm -f ${TMPDIR}/bc1
		rm -f ${TMPDIR}/bc2
		${OD} $1 >${TMPDIR}/bc1
		${OD} $2 >${TMPDIR}/bc2
		${DIFF} ${TMPDIR}/bc1 ${TMPDIR}/bc2 || {
		echo ERROR binary comparing $*
		errorcount=`expr $errorcount + 1`
		#exit 1
	}
}

compare()
{
	${DIFF} -u -b -w $* ||  {
		echo ERROR comparing $*
		errorcount=`expr $errorcount + 1`
		#exit 1
	}
}

compare_nole()
{
	${DIFF} -u --strip-trailing-cr $* ||  {
		echo ERROR comparing $*
		errorcount=`expr $errorcount + 1`
		#exit 1
	}
}

compare_with_alternate()
{
	${DIFF} -u -b -w $1 $3 1>${TMPDIR}/compare.log ||  {
		${DIFF} -u -b -w $2 $3 || {
			echo ERROR comparing with alternate $2 to $3
			cat ${TMPDIR}/compare.log
			rm -f ${TMPDIR}/compare.log
			echo ERROR comparing with alternate $1 to $3
			errorcount=`expr $errorcount + 1`
			#exit 1
		}
	}
}

sort_and_compare()
{
	sort $1 > $TMPDIR/s1
	sort $2 > $TMPDIR/s2
	compare $TMPDIR/s1 $TMPDIR/s2
}

gpsbabel()
{
	${PNAME} "$@" || {
		echo "$PNAME returned error $?"
		echo "($PNAME $@)"
		errorcount=`expr $errorcount + 1`
		#exit 1
	}
}

utf8bomcheck()
{
  if [ ${RUNNINGVALGRIND} -ne  0 ]; then
    if [ "$(dd if=$1 bs=1 count=3 2>/dev/null)" = $'\xef\xbb\xbf' ]; then
      echo "ERROR: UTF-8 BOM found in $1"
      errorcount=`expr $errorcount + 1`
    fi
  fi
}

xmlwfcheck()
{
  if [ ${RUNNINGVALGRIND} -ne 0 ]; then
    if which ${XMLWF} >/dev/null 2>&1; then
      # xmlwf is a bit lame, exit status is always 0
      rm -f ${TMPDIR}/xmlwf.out
      ${XMLWF} $1 2>&1 | tee ${TMPDIR}/xmlwf.out
      if [ -s ${TMPDIR}/xmlwf.out ]; then
        echo "ERROR: xml is not well-formed in $1"
        errorcount=`expr $errorcount + 1`
      fi
    fi
  fi
}

# Some formats are just too boring to test.   The ones that
# are xcsv include
# garmin301
# garmin_poi
# gpsdrivetrack
# nima
# mapconverter
# geonet
# saplus
# s_and_t
# xmap2006
# cambridge
# cup

errorcount=0

if [ $# -ge 1 ]; then
  while [ $# -ge 1 ];
  do
    t=${BASEPATH}/testo.d/$1.test
    echo Running $t
    . $t
    shift;
  done
else
  for i in ${BASEPATH}/testo.d/*.test
  do
    echo Running $i
    . $i
  done
fi

# Multiple tests produce these files in addition to gpx.test and kml.test,
# e.g. tpo.test has produced problematic gpx and kml files.
# For this reason this check isn't incorporated into each test.

# reference/basecamp.gpx has a UTF-8 BOM which is useful for verifying this test.
#cp reference/basecamp.gpx ${TMPDIR}
#cp LineStyles.gpx.badchar ${TMPDIR}/bad.gpx
XMLS=$(find ${TMPDIR} -name "*.gpx" -o -name "*.kml")

if [ ${RUNNINGVALGRIND} -ne  0 ]; then
  echo "Running UTF-8 BOM test"
  for i in ${XMLS}
  do
    utf8bomcheck $i
  done
fi

if [ ${RUNNINGVALGRIND} -ne  0 ]; then
  if which ${XMLWF} >/dev/null 2>&1; then
    echo "Running well-formed XML test"
    for i in ${XMLS}
    do
      xmlwfcheck $i
    done
  else
    echo "Skipping well-formed XML test"
  fi
fi

exit $errorcount