File: test_encoding_utf8

package info (click to toggle)
gpsbabel 1.10.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,680 kB
  • sloc: cpp: 104,866; xml: 9,686; sh: 1,792; ansic: 1,086; perl: 520; tcl: 74; makefile: 18
file content (118 lines) | stat: -rwxr-xr-x 4,350 bytes parent folder | download | duplicates (4)
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
#!/bin/bash
# this file should be encoded in utf8

BASEPATH=`dirname $0`
PNAME=${PNAME:-${BASEPATH}/gpsbabel}
REFERENCE=${BASEPATH}/reference

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

errorcount=0

cmap=$(locale charmap)
if [ "${cmap}" == "UTF-8" ] ; then

echo "Running utf-8 file name encoding test"
filenamebase=test_encoding_fileαβγ

# test input file name mangling with gpsbabel::File
  echo "testing input file name with gpsbabel::File"
  rm -f ${TMPDIR}/test_encoding_file*
  cp ${REFERENCE}/bounds-test.gpx ${TMPDIR}/${filenamebase}.gpx
  ${PNAME} -i gpx -f ${TMPDIR}/${filenamebase}.gpx -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
    echo "ERROR: The input file name was mangled."
    errorcount=`expr $errorcount + 1`
  }

# test output file name mangling with gpsbabel::File
  echo "testing output file name with gpsbabel::File"
  rm -f ${TMPDIR}/test_encoding_file*
  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o kml -F ${TMPDIR}/${filenamebase}.kml
  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.kml 2>/dev/null | wc -l)
  if [ $count -lt 1 ]; then
    echo "ERROR: The output file name was mangled."
    errorcount=`expr $errorcount + 1`
  fi

# test input file name mangling with gbfile stdapi
  echo "testing input file name with gbfile stdapi"
  rm -f ${TMPDIR}/test_encoding_file*
  cp ${REFERENCE}/unicsv_subsec.csv ${TMPDIR}/${filenamebase}.csv
  ${PNAME} -i unicsv -f ${TMPDIR}/${filenamebase}.csv -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
    echo "ERROR: The input file name was mangled."
    errorcount=`expr $errorcount + 1`
  }

# test output file name mangling with gbfile stdapi
  echo "testing output file name with gbfile stdapi"
  rm -f ${TMPDIR}/test_encoding_file*
  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o unicsv -F ${TMPDIR}/${filenamebase}.csv
  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.csv 2>/dev/null | wc -l)
  if [ $count -lt 1 ]; then
    echo "ERROR: The output file name was mangled."
    errorcount=`expr $errorcount + 1`
  fi

# test input file name mangling with gbfile gzapi
  echo "testing input file name with gbfile gzapi"
  rm -f ${TMPDIR}/test_encoding_file*
  cp ${REFERENCE}/sample.gtm.gz ${TMPDIR}/${filenamebase}.gtm.gz
  ${PNAME} -i gtm -f ${TMPDIR}/${filenamebase}.gtm.gz -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
    echo "ERROR: The input file name was mangled."
    errorcount=`expr $errorcount + 1`
  }

# test output file name mangling with gbfile gzapi
  echo "testing output file name with gbfile gzapi"
  rm -f ${TMPDIR}/test_encoding_file*
  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o gtm -F ${TMPDIR}/${filenamebase}.gtm.gz
  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.gtm.gz 2>/dev/null | wc -l)
  if [ $count -lt 1 ]; then
    echo "ERROR: The output file name was mangled."
    errorcount=`expr $errorcount + 1`
  fi

# test input file name mangling with shape files
  echo "testing input file name with shape files"
  rm -f ${TMPDIR}/test_encoding_file*
  for ext in cpg dbf prj shp shx
  do
    cp ${REFERENCE}/gis.osm_railways_free_1.${ext} ${TMPDIR}/${filenamebase}.${ext}
  done
  ${PNAME} -r -i shape -f ${TMPDIR}/${filenamebase}.shp -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
    echo "ERROR: The input file name was mangled."
    errorcount=`expr $errorcount + 1`
  }

# test output file name mangling with shape files
  echo "testing output file name with shape files"
  rm -f ${TMPDIR}/test_encoding_file*
  ${PNAME} -r -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
  for ext in cpg dbf shp shx
  do
    count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
    if [ $count -lt 1 ]; then
      echo "ERROR: The output file name was mangled."
      errorcount=`expr $errorcount + 1`
    fi
  done
  rm -f ${TMPDIR}/test_encoding_file*
  ${PNAME} -w -i gpx -f ${REFERENCE}/bounds-test.gpx -o shape -F ${TMPDIR}/${filenamebase}.shp
  for ext in cpg dbf shp shx
  do
    count=$(ls -1 -l ${TMPDIR}/${filenamebase}.${ext} 2>/dev/null | wc -l)
    if [ $count -lt 1 ]; then
      echo "ERROR: The output file name was mangled."
      errorcount=`expr $errorcount + 1`
    fi
  done

# TODO: add tests to cover formats that use other open methods.

else
  echo "$0 cannot run without the UTF-8 charmap."
fi

exit $errorcount