Skip to content

Commit

Permalink
AuthoredActivityContent v2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2kai2kai2 committed Oct 27, 2023
1 parent c4fa5bb commit da4f0f3
Showing 1 changed file with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,99 @@ final class AuthoredActivityContentTest: XCTestCase {
XCTAssertEqual(activity.pois.count, 0) // v1 has no POIs
}

/// Tests parsing from GPX
/// Using `GPXSoundscapeSharedContentExtensions` v2
/// And minimal other details
func testParseGPXContentV2_00() throws {
let text = """
<gpx version="1.1">
<metadata>
<name>required name234</name>
<desc>required description567</desc>
<author>
<name>required author's name!!</name>
<!-- optionally other stuff here -->
</author>
<extensions>
<gpxsc:meta start="date???" end="date???" expires="false">
<!-- This is GPXSoundscapeSharedContentExtensions -->
<gpxsc:id>activity_id5678</gpxsc:id>
<!-- scavengerhunt is deprecated but is the only hard-coded behavior name -->
<gpxsc:behavior>scavengerhunt</gpxsc:behavior>
<!-- this is version 2, which uses the first route: <rte></rte> -->
<gpxsc:version>2</gpxsc:version>
<gpxsc:locale>en_US</gpxsc:locale>
</gpxsc:meta>
</extensions>
</metadata>
<rte>
<!-- v2 requires all points have names -->
<rtept lat="0" lon="0">
<!-- same internal schema as <wpt></wpt> -->
<!-- so same as in v1, we have optional properties and extensions -->
<name>first point</name>
<desc>point0</desc>
</rtept>
<rtept lat="1" lon="0">
<name>second point</name>
<desc>point1</desc>
</rtept>
</rte>
<wpt lat="0.5" lon="0">
<!-- for v2, top-level waypoints become POIs -->
<!-- they must have a name -->
<name>Cool POI</name>
<desc>is optional</desc>
</wpt>
</gpx>
"""
guard let parser = GPXParser(withRawString: text) else {
XCTFail("Failed to initialize GPXParser")
return
}
guard let root = parser.parsedData() else {
XCTFail("Failed to get parsedData")
return
}
guard let activity = AuthoredActivityContent.parse(gpx: root) else {
XCTFail("Failed to create AuthoredActivityContent from GPXRoot")
return
}

XCTAssertEqual(activity.id, "activity_id5678") // gpxsc:id
XCTAssertEqual(activity.type, AuthoredActivityType.orienteering)
XCTAssertEqual(activity.name, "required name234")
XCTAssertEqual(activity.creator, "required author's name!!")
XCTAssertEqual(activity.locale.identifier, "en_US")
// TODO: availability???? expiration?? image??
XCTAssertNotNil(activity.availability)
XCTAssertFalse(activity.expires)

// Note `activity.desc` and `activity.description` are different
// desc comes from the gpxsc:desc tag, whereas description is a generated text description
XCTAssertEqual(activity.desc, "required description567")

XCTAssertEqual(activity.waypoints.count, 2)
if let wpt0 = activity.waypoints.first, let wpt1 = activity.waypoints.last {
XCTAssertEqual(wpt0.coordinate, CLLocationCoordinate2DMake(0, 0))
XCTAssertEqual(wpt0.name, "first point")
XCTAssertEqual(wpt0.description, "point0")
XCTAssertEqual(wpt1.coordinate, CLLocationCoordinate2DMake(1, 0))
XCTAssertEqual(wpt1.name, "second point")
XCTAssertEqual(wpt1.description, "point1")
// TODO: optional waypoint properties
}

// POIs are the top-level waypoints
XCTAssertEqual(activity.pois.count, 1)
if let poi0 = activity.pois.first {
XCTAssertEqual(poi0.coordinate, CLLocationCoordinate2DMake(0.5, 0))
XCTAssertEqual(poi0.name, "Cool POI")
XCTAssertEqual(poi0.description, "is optional")
}
}

// TODO: test other stuff

}

0 comments on commit da4f0f3

Please sign in to comment.