|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Diagnostics;
|
3 | 4 | using System.IO;
|
4 | 5 | using System.Linq;
|
@@ -344,7 +345,7 @@ public void TimestampsShouldPreserveFractionalSecondsWithinDefinedPrecision()
|
344 | 345 | </wpt>
|
345 | 346 | </gpx>
|
346 | 347 | ";
|
347 |
| - string text = GpxFile.Parse(GpxText, null). BuildString(null); |
| 348 | + string text = GpxFile.Parse(GpxText, null).BuildString(null); |
348 | 349 |
|
349 | 350 | Assert.Contains("1234-05-06T07:08:09.7654321Z", text);
|
350 | 351 | Assert.Contains("5432-10-10T11:22:33.8765432Z", text); // DateTime resolution is 100ns, so the value gets rounded to 7 digits
|
@@ -502,5 +503,106 @@ public void OverlongDataUrisShouldBeAccepted_OptIn(int totalUriLength)
|
502 | 503 | string text = file.BuildString(null);
|
503 | 504 | Assert.Contains(uriText, text);
|
504 | 505 | }
|
| 506 | + |
| 507 | + [Fact] |
| 508 | + [Regression] |
| 509 | + [GitHubIssue(41)] |
| 510 | + public void ChildElementWithUnexpectedNameShouldBeIgnored_OptIn() |
| 511 | + { |
| 512 | + const string GpxText = @" |
| 513 | +<gpx version='1.1' creator='S Health_0.2' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'> |
| 514 | + <metadate>2020-07-31T03:01:31Z</metadate> |
| 515 | + <trk> |
| 516 | + <name>20200731_090010.gpx</name> |
| 517 | + <trkseg> |
| 518 | + <trkpt lat='32.737328' lon='35.65718'> |
| 519 | + <ele>346.0538</ele> |
| 520 | + <time>2020-07-31T03:01:31Z</time> |
| 521 | + </trkpt> |
| 522 | + </trkseg> |
| 523 | + </trk> |
| 524 | + <exerciseinfo> |
| 525 | + <exercisetype>11007</exercisetype> |
| 526 | + </exerciseinfo> |
| 527 | +</gpx> |
| 528 | +"; |
| 529 | + Assert.ThrowsAny<XmlException>(() => GpxFile.Parse(GpxText, null)); |
| 530 | + |
| 531 | + var gpx = GpxFile.Parse(GpxText, new GpxReaderSettings { IgnoreUnexpectedChildrenOfTopLevelElement = true }); |
| 532 | + var trk = Assert.Single(gpx.Tracks); |
| 533 | + var trkseg = Assert.Single(trk.Segments); |
| 534 | + var trkpt = Assert.Single(trkseg.Waypoints); |
| 535 | + Assert.Equal(new GpxLatitude(32.737328), trkpt.Latitude); |
| 536 | + Assert.Equal(new GpxLongitude(35.65718), trkpt.Longitude); |
| 537 | + } |
| 538 | + |
| 539 | + [Fact] |
| 540 | + [Regression] |
| 541 | + [GitHubIssue(41)] |
| 542 | + public void MetadataOutOfOrderShouldBeIgnored_OptIn() |
| 543 | + { |
| 544 | + const string GpxText = @" |
| 545 | +<gpx version='1.1' creator='HarelM' n0:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd' xmlns='http://www.topografix.com/GPX/1/1' n1:xsi='http://www.w3.org/2001/XMLSchema-instance' n1:gpx1='http://www.topografix.com/GPX/1/0' n1:ogt10='http://gpstracker.android.sogeti.n1/GPX/1/0' xmlns:n0='xsi' xmlns:n1='xmlns'> |
| 546 | + <trk> |
| 547 | + <name>20200731_090010.gpx</name> |
| 548 | + <trkseg> |
| 549 | + <trkpt lat='32.737328' lon='35.65718'> |
| 550 | + <ele>346.0538</ele> |
| 551 | + <time>2020-07-31T03:01:31Z</time> |
| 552 | + </trkpt> |
| 553 | + </trkseg> |
| 554 | + </trk> |
| 555 | + <metadata> |
| 556 | + <link href='somelink.com' /> |
| 557 | + </metadata> |
| 558 | +</gpx> |
| 559 | +"; |
| 560 | + Assert.ThrowsAny<XmlException>(() => GpxFile.Parse(GpxText, null)); |
| 561 | + |
| 562 | + var gpx = GpxFile.Parse(GpxText, new GpxReaderSettings { IgnoreUnexpectedChildrenOfTopLevelElement = true }); |
| 563 | + Assert.Equal("HarelM", gpx.Metadata.Creator); |
| 564 | + Assert.True(gpx.Metadata.IsTrivial); // metadata element came too late |
| 565 | + } |
| 566 | + |
| 567 | + [Fact] |
| 568 | + [Regression] |
| 569 | + [GitHubIssue(41)] |
| 570 | + public void ExtraMetadataOrExtensionsShouldBeIgnored_OptIn() |
| 571 | + { |
| 572 | + const string GpxText = @" |
| 573 | +<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.1' creator='airbreather'> |
| 574 | + <metadata> |
| 575 | + <desc>desc1</desc> |
| 576 | + <name>name1</name> |
| 577 | + </metadata> |
| 578 | + <extensions xmlns='http://www.example.com'> |
| 579 | + <element1 /> |
| 580 | + <element2 /> |
| 581 | + </extensions> |
| 582 | + <wpt lat='0.1' lon='2.3' /> |
| 583 | + <rte><rtept lat='4.5' lon='6.7' /></rte> |
| 584 | + <trk><trkseg><trkpt lat='8.9' lon='10.11' /></trkseg></trk> |
| 585 | + <metadata> |
| 586 | + <desc>desc2</desc> |
| 587 | + <keywords>kwds2</keywords> |
| 588 | + </metadata> |
| 589 | + <extensions xmlns='http://www.example.com'> |
| 590 | + <element2 /> |
| 591 | + <element3 /> |
| 592 | + </extensions> |
| 593 | +</gpx> |
| 594 | +"; |
| 595 | + Assert.ThrowsAny<XmlException>(() => GpxFile.Parse(GpxText, null)); |
| 596 | + |
| 597 | + var gpx = GpxFile.Parse(GpxText, new GpxReaderSettings { IgnoreUnexpectedChildrenOfTopLevelElement = true }); |
| 598 | + Assert.Equal("airbreather", gpx.Metadata.Creator); |
| 599 | + Assert.Equal("desc1", gpx.Metadata.Description); |
| 600 | + Assert.Equal("name1", gpx.Metadata.Name); |
| 601 | + Assert.Null(gpx.Metadata.Keywords); |
| 602 | + var extensions = Assert.IsAssignableFrom<IEnumerable<XElement>>(gpx.Extensions).ToArray(); |
| 603 | + Assert.Contains(extensions, e => e.Name == XName.Get("element1", "http://www.example.com")); |
| 604 | + Assert.Contains(extensions, e => e.Name == XName.Get("element2", "http://www.example.com")); |
| 605 | + Assert.DoesNotContain(extensions, e => e.Name == XName.Get("element3", "http://www.example.com")); |
| 606 | + } |
505 | 607 | }
|
506 | 608 | }
|
0 commit comments