#
# Garmin GPS Database .gdb tests
#

rm -f ${TMPDIR}/gdb-*
gpsbabel -i gdb,via -f ${REFERENCE}/gdb-sample.gdb -o gpx -F ${TMPDIR}/gdb-sample.gpx
compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample.gpx

# check round trip from gdb to gdb for corruption.
# The Latin1 encoded character string "Völkerschlachtdenkmal" in the version 2 file
# gdb-sample.gdb can't be converted to a Qstring using the implicit fromUtf8()
# without corruption as 'ö' is '\xf6' in Latin1 which is illegal in UTF-8.
gpsbabel -i gdb,via -f ${REFERENCE}/gdb-sample.gdb -o gdb,ver=2 -F ${TMPDIR}/gdb-sample2.gdb
gpsbabel -i gdb -f ${TMPDIR}/gdb-sample2.gdb -o gpx -F ${TMPDIR}/gdb-sample2.gpx
compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample2.gpx

# again with gdb version 3.
gpsbabel -i gdb,via -f ${REFERENCE}/gdb-sample.gdb -o gdb,ver=3 -F ${TMPDIR}/gdb-sample3.gdb
gpsbabel -i gdb -f ${TMPDIR}/gdb-sample3.gdb -o gpx -F ${TMPDIR}/gdb-sample3.gpx
compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample3.gpx

gpsbabel -i gpx -f ${REFERENCE}/gdb-sample.gpx -o gdb,ver=1 -F ${TMPDIR}/gdb-sample.gdb
gpsbabel -i gdb -f ${TMPDIR}/gdb-sample.gdb -o gpx -F ${TMPDIR}/gdb-sample_v2.gpx
compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample_v2.gpx

gpsbabel -i gdb,via -f ${REFERENCE}/gdb-sample-v3.gdb -o gpx -F ${TMPDIR}/gdb-sample_v3.gpx
compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample_v3.gpx

# don't choke if autoroute information is present.
gpsbabel -i gdb,dropwpt -f ${REFERENCE}/gdb-sample-v3-autoroute.gdb -o gpx -F ${TMPDIR}/gdb-sample-v3-autoroute.gpx
compare ${REFERENCE}/gdb-sample-v3-autoroute.gpx ${TMPDIR}/gdb-sample-v3-autoroute.gpx

# test that the Route point Point names from the 'R' records match the Waypoint names from the 'W' records.
# the names in the csv input are all identical which forces the gdb writer to uniquify them.
gpsbabel -r  -i unicsv -f ${REFERENCE}/route/gdbroutenametest.csv -o gdb -F ${TMPDIR}/gdbroutenametest.gdb
# if we don't match the names we will get a fatal error:
# gdb: Route point mismatch!
#   "RoutePoint" from waypoints differs to "RoutePoint"
#   from route table by more than 1113.2 meters!
gpsbabel -r -i gdb -f ${TMPDIR}/gdbroutenametest.gdb -o unicsv -F ${TMPDIR}/gdbroutenametest.csv
compare ${REFERENCE}/route/gdbroutenametest~csv.csv ${TMPDIR}/gdbroutenametest.csv
