1
1
//
2
- // GPXKit - MIT License - Copyright © 2024 Markus Müller. All rights reserved.
2
+ // GPXKit - MIT License - Copyright © 2025 Markus Müller. All rights reserved.
3
3
//
4
4
5
5
import Foundation
@@ -42,7 +42,7 @@ struct GPXExporterTests {
42
42
@Test
43
43
func testExportingAnEmptyTrackWithDateAndTitleResultsInAnEmptyGPXFile( ) throws {
44
44
let date = Date ( )
45
- let track = GPXTrack ( date: date, title: " Track title " , description: " Track description " , trackPoints: [ ] )
45
+ let track = GPXTrack ( date: date, title: " Track title " , description: " Track description " , trackPoints: [ ] , type : " cycling " )
46
46
let sut = GPXExporter ( track: track)
47
47
48
48
let expectedContent : GPXKit . XMLNode = XMLNode (
@@ -54,7 +54,8 @@ struct GPXExporterTests {
54
54
] ) ,
55
55
XMLNode ( name: GPXTags . track. rawValue, children: [
56
56
XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
57
- XMLNode ( name: GPXTags . description. rawValue, content: " Track description " )
57
+ XMLNode ( name: GPXTags . description. rawValue, content: " Track description " ) ,
58
+ XMLNode ( name: GPXTags . type. rawValue, content: " cycling " )
58
59
] )
59
60
]
60
61
)
@@ -67,7 +68,7 @@ struct GPXExporterTests {
67
68
@Test
68
69
func testItWillNotExportANilDescription( ) throws {
69
70
let date = Date ( )
70
- let track = GPXTrack ( date: date, title: " Track title " , description: nil , trackPoints: [ ] )
71
+ let track = GPXTrack ( date: date, title: " Track title " , description: nil , trackPoints: [ ] , type : nil )
71
72
let sut = GPXExporter ( track: track)
72
73
73
74
let expectedContent : GPXKit . XMLNode = XMLNode (
@@ -95,7 +96,8 @@ struct GPXExporterTests {
95
96
title: " Track title " ,
96
97
description: " Description " ,
97
98
trackPoints: [ ] ,
98
- keywords: [ " one " , " two " ]
99
+ keywords: [ " one " , " two " ] ,
100
+ type: " custom "
99
101
)
100
102
let sut = GPXExporter ( track: track, creatorName: " Custom creator name " )
101
103
@@ -108,7 +110,8 @@ struct GPXExporterTests {
108
110
] ) ,
109
111
XMLNode ( name: GPXTags . track. rawValue, children: [
110
112
XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
111
- XMLNode ( name: GPXTags . description. rawValue, content: " Description " )
113
+ XMLNode ( name: GPXTags . description. rawValue, content: " Description " ) ,
114
+ XMLNode ( name: GPXTags . type. rawValue, content: " custom " )
112
115
] )
113
116
]
114
117
)
@@ -119,14 +122,15 @@ struct GPXExporterTests {
119
122
}
120
123
121
124
@Test
122
- func testExportingANonEmptyTrackWithDates ( ) throws {
125
+ func testExportingANonEmptyTrackWithDatesAndType ( ) throws {
123
126
let date = Date ( )
124
127
let track = GPXTrack (
125
128
date: date,
126
129
title: " Track title " ,
127
130
description: " Non empty track " ,
128
131
trackPoints: givenTrackPoints ( 10 ) ,
129
- keywords: [ " keyword1 " , " keyword2 " , " keyword3 " ]
132
+ keywords: [ " keyword1 " , " keyword2 " , " keyword3 " ] ,
133
+ type: " cycling "
130
134
)
131
135
let sut = GPXExporter ( track: track)
132
136
@@ -143,6 +147,7 @@ struct GPXExporterTests {
143
147
XMLNode ( name: GPXTags . track. rawValue, children: [
144
148
XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
145
149
XMLNode ( name: GPXTags . description. rawValue, content: " Non empty track " ) ,
150
+ XMLNode ( name: GPXTags . type. rawValue, content: " cycling " ) ,
146
151
XMLNode (
147
152
name: GPXTags . trackSegment. rawValue,
148
153
children: track. trackPoints. map {
@@ -175,7 +180,8 @@ struct GPXExporterTests {
175
180
TrackPoint ( coordinate: . random, date: Date ( ) ) ,
176
181
TrackPoint ( coordinate: . random, date: Date ( ) ) ,
177
182
TrackPoint ( coordinate: . random, date: Date ( ) )
178
- ]
183
+ ] ,
184
+ type: " running "
179
185
)
180
186
let sut = GPXExporter ( track: track, shouldExportDate: false )
181
187
let expectedContent : GPXKit . XMLNode = XMLNode (
@@ -185,6 +191,7 @@ struct GPXExporterTests {
185
191
XMLNode ( name: GPXTags . metadata. rawValue) ,
186
192
XMLNode ( name: GPXTags . track. rawValue, children: [
187
193
XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
194
+ XMLNode ( name: GPXTags . type. rawValue, content: " running " ) ,
188
195
XMLNode (
189
196
name: GPXTags . trackSegment. rawValue,
190
197
children: track. trackPoints. map {
@@ -202,7 +209,7 @@ struct GPXExporterTests {
202
209
203
210
@Test
204
211
func testItWillNotExportNilWaypoints( ) throws {
205
- let track = GPXTrack ( date: Date ( ) , waypoints: nil , title: " Track title " , trackPoints: [ ] )
212
+ let track = GPXTrack ( date: Date ( ) , waypoints: nil , title: " Track title " , trackPoints: [ ] , type : nil )
206
213
let sut = GPXExporter ( track: track, shouldExportDate: false )
207
214
let expectedContent : GPXKit . XMLNode = XMLNode (
208
215
name: GPXTags . gpx. rawValue,
@@ -231,7 +238,7 @@ struct GPXExporterTests {
231
238
description: " Kreisel description "
232
239
)
233
240
]
234
- let track = GPXTrack ( date: Date ( ) , waypoints: waypoints, title: " Track title " , trackPoints: [ ] )
241
+ let track = GPXTrack ( date: Date ( ) , waypoints: waypoints, title: " Track title " , trackPoints: [ ] , type : " track type " )
235
242
let sut = GPXExporter ( track: track, shouldExportDate: false )
236
243
let expectedContent : GPXKit . XMLNode = XMLNode (
237
244
name: GPXTags . gpx. rawValue,
@@ -255,7 +262,8 @@ struct GPXExporterTests {
255
262
XMLNode ( name: GPXTags . description. rawValue, content: " Kreisel description " )
256
263
] ) ,
257
264
XMLNode ( name: GPXTags . track. rawValue, children: [
258
- XMLNode ( name: GPXTags . name. rawValue, content: track. title)
265
+ XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
266
+ XMLNode ( name: GPXTags . type. rawValue, content: " track type " )
259
267
] )
260
268
]
261
269
)
@@ -321,7 +329,8 @@ struct GPXExporterTests {
321
329
segments: [
322
330
. init( range: 0 ..< 5 , distance: points [ 0 ..< 5 ] . expectedDistance ( ) ) ,
323
331
. init( range: 5 ..< 10 , distance: points [ 5 ..< 10 ] . expectedDistance ( ) )
324
- ]
332
+ ] ,
333
+ type: " rowing "
325
334
)
326
335
let sut = GPXExporter ( track: track)
327
336
@@ -338,6 +347,7 @@ struct GPXExporterTests {
338
347
XMLNode ( name: GPXTags . track. rawValue, children: [
339
348
XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
340
349
XMLNode ( name: GPXTags . description. rawValue, content: " Non empty track " ) ,
350
+ XMLNode ( name: GPXTags . type. rawValue, content: " rowing " ) ,
341
351
XMLNode (
342
352
name: GPXTags . trackSegment. rawValue,
343
353
children: points [ 0 ..< 5 ] . map {
@@ -356,4 +366,29 @@ struct GPXExporterTests {
356
366
357
367
assertNodesAreEqual ( expectedContent, result)
358
368
}
369
+
370
+ @Test
371
+ func testItWillNotExportAnNonexistingTrackType( ) throws {
372
+ let date = Date ( )
373
+ let track = GPXTrack ( date: date, title: " Track title " , description: " Track description " , trackPoints: [ ] , type: nil )
374
+ let sut = GPXExporter ( track: track)
375
+
376
+ let expectedContent : GPXKit . XMLNode = XMLNode (
377
+ name: GPXTags . gpx. rawValue,
378
+ attributes: expectedHeaderAttributes ( ) ,
379
+ children: [
380
+ XMLNode ( name: GPXTags . metadata. rawValue, children: [
381
+ XMLNode ( name: GPXTags . time. rawValue, content: expectedString ( for: date) )
382
+ ] ) ,
383
+ XMLNode ( name: GPXTags . track. rawValue, children: [
384
+ XMLNode ( name: GPXTags . name. rawValue, content: track. title) ,
385
+ XMLNode ( name: GPXTags . description. rawValue, content: " Track description " )
386
+ ] )
387
+ ]
388
+ )
389
+
390
+ let result = try parseResult ( sut. xmlString)
391
+
392
+ assertNodesAreEqual ( expectedContent, result)
393
+ }
359
394
}
0 commit comments