diff --git a/data/gpx_test_data/track_with_timestamps.gpx b/data/gpx_test_data/track_with_timestamps.gpx new file mode 100644 index 0000000000..a5251c782f --- /dev/null +++ b/data/gpx_test_data/track_with_timestamps.gpx @@ -0,0 +1,31 @@ + + + + new + Cycling + + + 130.5 + + + + 0.0 + + + + 0.0 + + + + + + 131.5 + + + + 0.0 + + + + + diff --git a/data/gpx_test_data/track_with_timestamps_broken.gpx b/data/gpx_test_data/track_with_timestamps_broken.gpx new file mode 100644 index 0000000000..cc6614e1a0 --- /dev/null +++ b/data/gpx_test_data/track_with_timestamps_broken.gpx @@ -0,0 +1,29 @@ + + + + new + Cycling + + + 130.5 + + + + 0.0 + + + + 0.0 + + + + + 131.5 + + + + 0.0 + + + + diff --git a/data/gpx_test_data/track_without_timestamps.gpx b/data/gpx_test_data/track_without_timestamps.gpx new file mode 100644 index 0000000000..e7e2b3ffc8 --- /dev/null +++ b/data/gpx_test_data/track_without_timestamps.gpx @@ -0,0 +1,26 @@ + + + + new + Cycling + + + 130.5 + + + 0.0 + + + 0.0 + + + + + 131.5 + + + 0.0 + + + + diff --git a/kml/kml_tests/gpx_tests.cpp b/kml/kml_tests/gpx_tests.cpp index dd72be162b..7381fcb6e0 100644 --- a/kml/kml_tests/gpx_tests.cpp +++ b/kml/kml_tests/gpx_tests.cpp @@ -12,16 +12,12 @@ namespace gpx_tests { static kml::FileData loadGpxFromString(std::string_view content) { - try + TEST_NO_THROW( { kml::FileData dataFromText; kml::DeserializerGpx(dataFromText).Deserialize(MemReader(content)); return dataFromText; - } - catch (kml::DeserializerGpx::DeserializeException const & exc) - { - TEST(false, ("Exception raised", exc.what())); - } + }, ()); } static kml::FileData loadGpxFromFile(std::string const & file) { @@ -54,7 +50,7 @@ UNIT_TEST(Gpx_ImportExportEmpty_Test) importExportCompare("gpx_test_data/export_test_empty.gpx"); } -UNIT_TEST(Gpx_Test_Point) +UNIT_TEST(Gpx_Test_Point_With_Valid_Timestamp) { std::string_view constexpr input = R"( @@ -77,37 +73,23 @@ UNIT_TEST(Gpx_Test_Point) TEST_EQUAL(dataFromText, data, ()); } -UNIT_TEST(Gpx_Test_Route) +UNIT_TEST(Gpx_Test_Point_With_Invalid_Timestamp) { std::string_view constexpr input = R"( - - new - Cycling - - - 130.5 - - - 0.0 - - - 0.0 - - - - - 131.5 - - - 0.0 - - - - + + + Waypoint 1 + )"; - kml::FileData const dataFromText = loadGpxFromString(input); + TEST_ANY_THROW({ kml::FileData const dataFromText = loadGpxFromString(input); }, ()); +} + +UNIT_TEST(Gpx_Test_Track_Without_Timestamps) +{ + auto const fileName = "gpx_test_data/track_without_timestamps.gpx"; + kml::FileData const dataFromText = loadGpxFromFile(fileName); auto const & lines = dataFromText.m_tracksData[0].m_geometry.m_lines; TEST_EQUAL(lines.size(), 2, ()); { @@ -128,8 +110,48 @@ UNIT_TEST(Gpx_Test_Route) TEST_EQUAL(layer.m_color.m_rgba, kml::kDefaultTrackColor, ()); TEST_EQUAL(layer.m_color.m_predefinedColor, kml::PredefinedColor::None, ()); TEST_EQUAL(layer.m_lineWidth, kml::kDefaultTrackWidth, ()); + auto const & geometry = dataFromText.m_tracksData[0].m_geometry; + TEST_EQUAL(geometry.m_timestamps.size(), 2, ()); + TEST(geometry.m_timestamps[0].empty(), ()); + TEST(geometry.m_timestamps[1].empty(), ()); + TEST(!geometry.HasTimestamps(), ()); + TEST(!geometry.HasTimestampsFor(0), ()); + TEST(!geometry.HasTimestampsFor(1), ()); } +} +UNIT_TEST(Gpx_Test_Track_With_Timestamps) +{ + auto const fileName = "gpx_test_data/track_with_timestamps.gpx"; + kml::FileData const dataFromText = loadGpxFromFile(fileName); + auto const & geometry = dataFromText.m_tracksData[0].m_geometry; + TEST_EQUAL(geometry.m_lines.size(), 2, ()); + TEST_EQUAL(geometry.m_timestamps.size(), 2, ()); + TEST(geometry.IsValid(), ()); + TEST(geometry.HasTimestamps(), ()); + TEST(geometry.HasTimestampsFor(0), ()); + TEST(geometry.HasTimestampsFor(1), ()); +} + +UNIT_TEST(Gpx_Test_Track_With_Timestamps_Mismatch) +{ + auto const fileName = GetPlatform().TestsDataPathForFile("gpx_test_data/track_with_timestamps_broken.gpx"); + std::string text; + FileReader(fileName).ReadAsString(text); + try + { + kml::FileData dataFromText; + kml::DeserializerGpx(dataFromText).Deserialize(MemReader(text)); + TEST(false, ("DeserializeException should be raised")); + } + catch (kml::DeserializerGpx::DeserializeException const & exc) + { + TEST(true, ("Exception raised", exc.what())); + } + catch (std::exception const & exc) + { + TEST(false, ("DeserializeException should be raised")); + } } UNIT_TEST(Gpx_Altitude_Issues) @@ -179,8 +201,10 @@ UNIT_TEST(GpxStudio) UNIT_TEST(OsmTrack) { kml::FileData const dataFromFile = loadGpxFromFile("gpx_test_data/osm_track.gpx"); - auto line = dataFromFile.m_tracksData[0].m_geometry.m_lines[0]; + auto const & line = dataFromFile.m_tracksData[0].m_geometry.m_lines[0]; + auto const & timestamps = dataFromFile.m_tracksData[0].m_geometry.m_timestamps[0]; TEST_EQUAL(line.size(), 182, ()); + TEST_EQUAL(timestamps.size(), 182, ()); } UNIT_TEST(TowerCollector)