File: testw

package info (click to toggle)
gpsbabel 1.3.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 15,956 kB
  • ctags: 9,083
  • sloc: ansic: 87,514; xml: 13,640; pascal: 6,981; sh: 3,770; makefile: 811; perl: 754; tcl: 74; objc: 7
file content (166 lines) | stat: -rwxr-xr-x 3,398 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

### cross format waypoint check ###

PNAME=${PNAME:-./gpsbabel}
REFGPX="reference/expertgps.gpx"	# reference file for all tests
EXCL="ozi vitosmt"			# exclude formats from test
CAPS=""
TEMPDIR=/tmp/gb-testw
CATALOG=/tmp/gb-testw.done
LOGFILE=/tmp/gb-testw.log

# options
vg=0
prep=0

function log_entry()
{
    touch $LOGFILE
    echo "-----------------------------------------------------------------------" >> ${LOGFILE}
    date >> ${LOGFILE}
    echo "$*" >> ${LOGFILE}
}

function try_run() # command line
{
    local CMD="$*"
    local RES=0
    
    [ $vg -ne 0 ] && CMD="valgrind -q $CMD"

    ${CMD} > $TEMPDIR/.result 2>&1
    RES=$?
    if [ $RES -ne 0 -o -s $TEMPDIR/.result ]; then
	if [ $RES -ne 0 ]; then
	    echo " -- Uhps --"
	    echo "-----------------------------------------------------------------------"
	    test -s $TEMPDIR/.result && cat $TEMPDIR/.result
	    echo "-----------------------------------------------------------------------"
	else
	    echo ""
	fi
	log_entry "cmd($RES): $CMD"
	test -s $TEMPDIR/.result && cat $TEMPDIR/.result >> ${LOGFILE}
	return 1
    else
	return 0
    fi
}

function STAGE_1 () # format
{
    local FMT=$1
    local CMD1 CMD2
    
    echo "$CAPS" |
    
    while read type caps format comment; do
    
	for i in $EXCL; do
	    if [ "$format" == "$i" ]; then
		caps="------"
	    fi
	done
	
	grep "$FMT & $format" ${CATALOG} > /dev/null && continue
	
	echo -n "testing \"$FMT\" with \"$format\" "
	
	case $caps in
	
	    -w*)
		echo -n "*"
		CMD1="${PNAME} -i $FMT -f $TEMPDIR/$FMT -o $format -F $TEMPDIR/$FMT.$format"
		try_run "${CMD1}" || continue
		;;
		
	    rw*)
		echo -n "*"
		CMD1="${PNAME} -i $FMT -f $TEMPDIR/$FMT -o $format -F $TEMPDIR/$FMT.$format"
		try_run "${CMD1}" || continue
		echo -n "*"
		CMD2="${PNAME} -i $format -f $TEMPDIR/$FMT.$format -o $FMT -F $TEMPDIR/$FMT.$format.$FMT"
		try_run "${CMD2}" || continue
		;;
	esac
	echo "*"
	echo "$FMT & $format" >> $CATALOG
    done
    return 0
}

function STAGE_0 ()
{
    echo "$CAPS" |
    
    while read type caps format comment; do
    
	for i in $EXCL; do
		if [ "$format" == "$i" ]; then
			caps="------"
		fi
	done
	
	case $caps in
	    rw*)
		CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/$format"
		try_run "${CMD}" || continue
		STAGE_1 $format || exit 1
		;;
	esac
	case $caps in
	    -w*)
		CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/$format"
		try_run "${CMD}" || continue
		;;
	esac
    done
    rm -f $TEMPDIR/.result
}

rm -rf $TEMPDIR > /dev/null
mkdir -p $TEMPDIR > /dev/null

while [ $# -gt 0 ]; do
    case $1 in
	-s|--start)	# remove catalog. run the full test.
	    rm -f $CATALOG
	    ;;
	-v|--valgrind)
	    vg=1
	    ;;
	-p|--prepare)	# prepare for valgrind check.
	    prep=1
	    ;;
	-c|--clean)
	    trap "rm -fr $TEMPDIR; exit 1" 0 1 2 3 15
	    ;;
	-r|--reference)
	    shift
	    REFGPX=$1
	    ;;
    esac
    shift
done

if [ $prep -ne 0 ]; then
    test -s Makefile && make clean
    CFLAGS="-O0" ./configure || exit 1	#  -O0 is suggested by vg.
    make || exit 1
    echo "All fine. You can do now a 'testw -v'"
    exit 0
fi

if test ! -s $REFGPX; then
    echo "GPX reference \"$REFGPX\" doesn't exist!"
    exit 1
fi

touch $CATALOG

log_entry "testw started."
echo "Catalog: $CATALOG" >> $LOGFILE

CAPS=`${PNAME} -^2 | grep "^file"`
STAGE_0