# -*- tcl -*- # gpx.test: tests for the gpx package. # # Copyright (c) 2010-2015 by Andreas Kupries # All rights reserved. # # RCS: @(#) $Id: gpx.test,v 1.2 2010/07/10 15:58:23 andreas_kupries Exp $ # ------------------------------------------------------------------------- if {[file exists testutilities.tcl]} { source testutilities.tcl } else { source [file join \ [file dirname [file dirname [file join [pwd] [info script]]]] \ devtools testutilities.tcl] } testsNeedTcl 8.5 testsNeedTcltest 2.0 testsNeed tdom 0.8 testing { useLocal gpx.tcl gpx } # ------------------------------------------------------------------------- set rawXML { Sample GPX file GPX data for testing Keith Vetter KLIMB Bike Mapping program text/html 2010 http://anywhere.com Garmin International text/html gpx test file 33.531 Trail head 31.128 Abandoned car First track GPS Tracklog 35.706 36.667 35.706 Second track GPS Tracklog 15.038 13.596 13.596 13.596 13.115 KLIMB Route 1 1 21.6 M1 Waypoint KLIMB node 22.9 23.5 23.8 23.5 23.5 M2 Waypoint KLIMB node } set gpxFile [tcltest::makeFile $rawXML testGPXfile.gpx] # ------------------------------------------------------------------------- test gpx-1.0 {create error} -body { gpx::Create } -returnCodes error \ -result {wrong # args: should be "gpx::Create gpxFilename ?rawXML?"} test gpx-1.1 {create error} -body { gpx::Create F XML X } -returnCodes error \ -result {wrong # args: should be "gpx::Create gpxFilename ?rawXML?"} test gpx-2.0 {create & destroy} -body { gpx::Cleanup [gpx::Create $gpxFile] } -result {} test gpx-2.1 {create & destroy} -body { gpx::Cleanup [gpx::Create {} $rawXML] } -result {} # ------------------------------------------------------------------------- # # GetGPXMetadata tests # set token [gpx::Create "" $rawXML] test gpx-3.0 {GetGPXMetadata simple} -body { llength [gpx::GetGPXMetadata $token] } -result 18 test gpx-3.1 {GetGPXMetadata item} -body { dict get [gpx::GetGPXMetadata $token] version } -result {1.1} test gpx-3.2 {GetGPXMetadata complex item} -body { dict get [gpx::GetGPXMetadata $token] link href } -result {http://www.garmin.com} # ------------------------------------------------------------------------- # # Waypoint tests # test gpx-4.0 {GetWaypointCount} -body { gpx::GetWaypointCount $token } -result {2} test gpx-4.1 {Waypoint location} -body { lrange [lindex [gpx::GetAllWaypoints $token] 0] 0 1 } -result {41.61629786 -70.61782860} test gpx-4.2 {first waypoint metadata} -body { llength [lindex [gpx::GetAllWaypoints $token] 0 2] } -result 6 test gpx-4.3 {first waypoint metadata item} -body { dict get [lindex [gpx::GetAllWaypoints $token] 0 2] ele } -result {33.531} test gpx-4.4 {second waypoint metadata} -body { llength [lindex [gpx::GetAllWaypoints $token] 1 2] } -result 6 test gpx-4.5 {second waypoint metadata item} -body { dict get [lindex [gpx::GetAllWaypoints $token] 1 2] name } -result {Abandoned car} #---------------------------------------------------------------------- # # Track tests # test gpx-5.0 {track count} -body { gpx::GetTrackCount $token } -result {2} test gpx-5.1 {track metadata} -body { llength [gpx::GetTrackMetadata $token 1] } -result 4 test gpx-5.2 {track metadata item} -body { dict get [gpx::GetTrackMetadata $token 1] name } -result {First track} test gpx-5.3 {total track points} -body { llength [gpx::GetTrackPoints $token 1] } -result {3} test gpx-5.4 {total track points second track} -body { llength [gpx::GetTrackPoints $token 2] } -result {5} test gpx-5.5 {first track first point location} -body { lrange [lindex [gpx::GetTrackPoints $token 1] 0] 0 1 } -result {41.61716028 -70.61758477} test gpx-5.6 {first track first point metadata} -body { llength [lindex [gpx::GetTrackPoints $token 1] 0 2] } -result 4 test gpx-5.7 {first track first point metadata item} -body { dict get [lindex [gpx::GetTrackPoints $token 1] 0 2] ele } -result {35.706} test gpx-5.8 {second track last point location} -body { lrange [lindex [gpx::GetTrackPoints $token 2] end] 0 1 } -result {41.64344785 -70.60210507} test gpx-5.9 {second track last point metadata} -body { llength [lindex [gpx::GetTrackPoints $token 2] end 2] } -result 4 test gpx-5.10 {second track last point metadata item} -body { dict get [lindex [gpx::GetTrackPoints $token 2] end 2] ele } -result {13.115} #---------------------------------------------------------------------- # # Route tests # test gpx-6.0 {route count} -body { gpx::GetRouteCount $token } -result 1 test gpx-6.1 {route metadata} -body { llength [gpx::GetRouteMetadata $token 1] } -result 4 test gpx-6.2 {route metadata item} -body { dict get [gpx::GetRouteMetadata $token 1] name } -result {KLIMB Route 1} test gpx-6.3 {total route points} -body { llength [gpx::GetRoutePoints $token 1] } -result 6 test gpx-6.4 {route first point location} -body { lrange [lindex [gpx::GetRoutePoints $token 1] 0] 0 1 } -result {41.64383611111111 -70.60295833333333} test gpx-6.5 {route first point metadata} -body { llength [lindex [gpx::GetRoutePoints $token 1] 0 2] } -result 10 test gpx-6.6 {route first point metadata item} -body { dict get [lindex [gpx::GetRoutePoints $token 1] 0 2] type } -result {KLIMB node} test gpx-6.7 {route second point metadata} -body { llength [lindex [gpx::GetRoutePoints $token 1] 1 2] } -result 2 test gpx-6.8 {route last point location} -body { lrange [lindex [gpx::GetRoutePoints $token 1] end] 0 1 } -result {41.64293055555555 -70.6038611111111} test gpx-6.8 {route last point metadata} -body { llength [lindex [gpx::GetRoutePoints $token 1] end 2] } -result 10 test gpx-6.9 {route last point metadata item} -body { dict get [lindex [gpx::GetRoutePoints $token 1] end 2] desc } -result {Node 2} #---------------------------------------------------------------------- gpx::Cleanup $token tcltest::removeFile $gpxFile unset rawXML gpxFile token #---------------------------------------------------------------------- testsuiteCleanup return