//! GPS track logs in GPX 1.0 / 1.1 (the open GPS Exchange Format, ): //! the timed track points of every ``, and the position at any moment for geotagging photos. //! //! What we use from the format: `` → `` → `` with optional `` //! (metres) and `"#; assert!(matches!(parse_gpx(wrong_close), Err(GpxError::Xml(_)))); assert!( parse_gpx("") .unwrap() .points .is_empty() ); let deep = "".to_string() + &"".repeat(100); assert_eq!(parse_gpx(&deep), Err(GpxError::TooComplex)); let many = "".to_string() + &"".repeat(MAX_TRACKS + 1) + ""; assert_eq!(parse_gpx(&many), Err(GpxError::TooComplex)); } #[test] fn tracks_are_told_apart_with_their_names() { let s = r#" Morning "#; let log = parse_gpx(s).unwrap(); assert_eq!(log.tracks, 3); assert_eq!(log.names, vec!["Morning".to_string(), String::new(), String::new()]); // sorted by time: the third track's point comes first assert_eq!(log.points.iter().map(|p| p.track).collect::>(), vec![2, 0, 0]); let first = log.only_track(0).unwrap(); assert_eq!((first.points.len(), first.tracks, first.names[0].as_str()), (2, 1, "Morning")); assert!(log.only_track(1).unwrap().points.is_empty(), "an empty track"); assert!(log.only_track(3).is_none()); // a different track is a different segment: never interpolated across assert_ne!(log.points[0].segment, log.points[1].segment); } #[test] fn hostile_points_are_left_out() { let s = r#"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx NaN "#; let log = parse_gpx(s).unwrap(); assert_eq!(log.points.len(), 3, "{:?}", log.points); assert_eq!(log.untimed, 1); assert!(log.points.iter().all(|p| p.latitude.is_finite() && p.longitude.is_finite())); assert_eq!((log.points[1].latitude, log.points[1].elevation), (90.0, None), "a NaN elevation is no elevation"); // out of order in the file, in order in the log assert_eq!((log.points[0].latitude, log.points[2].latitude), (6.0, 5.0)); assert_eq!(log.names[0].chars().count(), MAX_NAME_CHARS); // a single point: located at its own time only (within the gap) let one = parse_gpx(r#""#).unwrap(); assert_eq!(one.span(), Some((one.points[0].time, one.points[0].time))); assert!(one.locate(one.points[0].time + 10.0, 60.0).is_some()); assert!(one.locate(f64::NAN, 60.0).is_none()); } }