You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testo 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env sh
  2. GPSBABEL_FREEZE_TIME=y
  3. export GPSBABEL_FREEZE_TIME
  4. # Turn on GNU libc instrumentation.
  5. MALLOC_CHECK_=2
  6. export MALLOC_CHECK_
  7. # Testcases are written for English/US locale (by default)
  8. LC_ALL=en_US.UTF-8
  9. export LC_ALL
  10. BASEPATH=`dirname $0`
  11. PNAME=${PNAME:-${BASEPATH}/gpsbabel}
  12. DIFF=${DIFF:-diff}
  13. REFERENCE=${BASEPATH}/reference
  14. # OD=${OD:-od -Ax -txC -v}
  15. if [ -x /usr/bin/hexdump ] ; then
  16. OD=${OD:-hexdump -v -C}
  17. else
  18. OD=${OD:-od -Ax -txC -v}
  19. fi
  20. XMLWF=xmlwf
  21. # set up a variable so we can skip extra tests when running valgrind
  22. echo "${PNAME}" | grep -q valgrind
  23. RUNNINGVALGRIND=$?
  24. TMPDIR=${GBTEMP:-/tmp}/gpsbabel.$$
  25. mkdir -p $TMPDIR
  26. trap "rm -fr $TMPDIR" 0 1 2 3 15
  27. bincompare()
  28. {
  29. rm -f ${TMPDIR}/bc1
  30. rm -f ${TMPDIR}/bc2
  31. ${OD} $1 >${TMPDIR}/bc1
  32. ${OD} $2 >${TMPDIR}/bc2
  33. ${DIFF} ${TMPDIR}/bc1 ${TMPDIR}/bc2 || {
  34. echo ERROR binary comparing $*
  35. errorcount=`expr $errorcount + 1`
  36. #exit 1
  37. }
  38. }
  39. compare()
  40. {
  41. ${DIFF} -u -b -w $* || {
  42. echo ERROR comparing $*
  43. errorcount=`expr $errorcount + 1`
  44. #exit 1
  45. }
  46. }
  47. sort_and_compare()
  48. {
  49. sort $1 > $TMPDIR/s1
  50. sort $2 > $TMPDIR/s2
  51. compare $TMPDIR/s1 $TMPDIR/s2
  52. }
  53. gpsbabel()
  54. {
  55. ${PNAME} $* || {
  56. echo "$PNAME returned error $?"
  57. echo "($PNAME $*)"
  58. errorcount=`expr $errorcount + 1`
  59. #exit 1
  60. }
  61. }
  62. utf8bomcheck()
  63. {
  64. if [ ${RUNNINGVALGRIND} -ne 0 ]; then
  65. if [ "$(dd if=$1 bs=1 count=3 2>/dev/null)" = $'\xef\xbb\xbf' ]; then
  66. echo "ERROR: UTF-8 BOM found in $1"
  67. errorcount=`expr $errorcount + 1`
  68. fi
  69. fi
  70. }
  71. xmlwfcheck()
  72. {
  73. if [ ${RUNNINGVALGRIND} -ne 0 ]; then
  74. if which ${XMLWF} >/dev/null 2>&1; then
  75. # xmlwf is a bit lame, exit status is always 0
  76. rm -f ${TMPDIR}/xmlwf.out
  77. ${XMLWF} $1 2>&1 | tee ${TMPDIR}/xmlwf.out
  78. if [ -s ${TMPDIR}/xmlwf.out ]; then
  79. echo "ERROR: xml is not well-formed in $1"
  80. errorcount=`expr $errorcount + 1`
  81. fi
  82. fi
  83. fi
  84. }
  85. # Some formats are just too boring to test. The ones that
  86. # are xcsv include
  87. # garmin301
  88. # garmin_poi
  89. # gpsdrivetrack
  90. # nima
  91. # mapconverter
  92. # geonet
  93. # saplus
  94. # s_and_t
  95. # xmap2006
  96. # cambridge
  97. # cup
  98. errorcount=0
  99. if [ $# -ge 1 ]; then
  100. while [ $# -ge 1 ];
  101. do
  102. t=${BASEPATH}/testo.d/$1.test
  103. echo Running $t
  104. . $t
  105. shift;
  106. done
  107. else
  108. for i in ${BASEPATH}/testo.d/*.test
  109. do
  110. echo Running $i
  111. . $i
  112. done
  113. fi
  114. # Multiple tests produce these files in addition to gpx.test and kml.test,
  115. # e.g. tpo.test has produced problematic gpx and kml files.
  116. # For this reason this check isn't incorporated into each test.
  117. # reference/basecamp.gpx has a UTF-8 BOM which is useful for verifying this test.
  118. #cp reference/basecamp.gpx ${TMPDIR}
  119. #cp LineStyles.gpx.badchar ${TMPDIR}/bad.gpx
  120. XMLS=$(find ${TMPDIR} -name "*.gpx" -o -name "*.kml")
  121. if [ ${RUNNINGVALGRIND} -ne 0 ]; then
  122. echo "Running UTF-8 BOM test"
  123. for i in ${XMLS}
  124. do
  125. utf8bomcheck $i
  126. done
  127. fi
  128. if [ ${RUNNINGVALGRIND} -ne 0 ]; then
  129. if which ${XMLWF} >/dev/null 2>&1; then
  130. echo "Running well-formed XML test"
  131. for i in ${XMLS}
  132. do
  133. xmlwfcheck $i
  134. done
  135. else
  136. echo "Skipping well-formed XML test"
  137. fi
  138. fi
  139. exit $errorcount