Changeset 18219 in josm for trunk/test/unit/org
- Timestamp:
- 2021-09-12T14:51:15+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/GpxWriterTest.java
r18037 r18219 15 15 import java.util.function.Consumer; 16 16 17 import org.junit.jupiter.api.Test; 17 18 import org.openstreetmap.josm.data.coor.LatLon; 18 19 import org.openstreetmap.josm.data.gpx.GpxConstants; … … 24 25 import org.openstreetmap.josm.data.gpx.WayPoint; 25 26 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 26 27 import org.junit.jupiter.api.Test;28 27 29 28 /** … … 40 39 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 41 40 try (GpxWriter writer = new GpxWriter(baos)) { 41 writer.setMetaTime(Instant.parse("2021-09-12T12:30:50.724Z")); 42 42 writer.write(gpx); 43 43 } … … 47 47 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n" + 48 48 " <metadata>\n" + 49 " <time>2021-09-12T12:30:50.724Z</time>\n" + 49 50 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 50 51 " </metadata>\n" + … … 121 122 122 123 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 123 GpxWriter writer = new GpxWriter(baos); 124 125 // CHECKSTYLE.OFF: LineLength 126 127 writer.write(data); 128 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 129 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 130 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 131 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 132 " xmlns:gpxd=\"http://josm.openstreetmap.de/gpx-drawing-extensions-1.0\"\n" + 133 " xmlns:test=\"http://example.com/testURI\"\n" + 134 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 135 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://josm.openstreetmap.de/gpx-drawing-extensions-1.0 http://josm.openstreetmap.de/gpx-drawing-extensions-1.0.xsd\">\n" + 136 " <metadata>\n" + 137 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 138 " <extensions>\n" + 139 " <knownprefix:foo>bar</knownprefix:foo>\n" + 140 " <josm:from-server>true</josm:from-server>\n" + 141 " <josm:layerPreferences>\n" + 142 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 143 " </josm:layerPreferences>\n" + 144 " </extensions>\n" + 145 " </metadata>\n" + 146 " <trk>\n" + 147 " <extensions>\n" + 148 " <gpxd:color>#FF0000</gpxd:color>\n" + 149 " </extensions>\n" + 150 " <trkseg>\n" + 151 " <extensions>\n" + 152 " <test:foo>extension of a segment</test:foo>\n" + 153 " </extensions>\n" + 154 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 155 " <extensions>\n" + 156 " <test:foo>extension of a waypoint</test:foo>\n" + 157 " </extensions>\n" + 158 " </trkpt>\n" + 159 " </trkseg>\n" + 160 " </trk>\n" + 161 "</gpx>", baos.toString()); 162 163 baos.reset(); 164 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 165 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 166 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 167 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 168 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 169 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 170 " xmlns:test=\"http://example.com/testURI\"\n" + 171 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 172 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 173 " <metadata>\n" + 174 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 175 " <extensions>\n" + 176 " <knownprefix:foo>bar</knownprefix:foo>\n" + 177 " <josm:from-server>true</josm:from-server>\n" + 178 " <josm:layerPreferences>\n" + 179 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 180 " </josm:layerPreferences>\n" + 181 " </extensions>\n" + 182 " </metadata>\n" + 183 " <trk>\n" + 184 " <extensions>\n" + 185 " <gpxx:TrackExtension>\n" + 186 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 187 " </gpxx:TrackExtension>\n" + 188 " </extensions>\n" + 189 " <trkseg>\n" + 190 " <extensions>\n" + 191 " <test:foo>extension of a segment</test:foo>\n" + 192 " </extensions>\n" + 193 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 194 " <extensions>\n" + 195 " <test:foo>extension of a waypoint</test:foo>\n" + 196 " </extensions>\n" + 197 " </trkpt>\n" + 198 " </trkseg>\n" + 199 " </trk>\n" + 200 "</gpx>", baos.toString()); 201 202 baos.reset(); 203 writer.write(data, null, false); 204 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 205 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 206 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 207 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 208 " xmlns:test=\"http://example.com/testURI\"\n" + 209 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 210 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd\">\n" + 211 " <metadata>\n" + 212 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 213 " <extensions>\n" + 214 " <knownprefix:foo>bar</knownprefix:foo>\n" + 215 " <josm:from-server>true</josm:from-server>\n" + 216 " </extensions>\n" + 217 " </metadata>\n" + 218 " <trk>\n" + 219 " <trkseg>\n" + 220 " <extensions>\n" + 221 " <test:foo>extension of a segment</test:foo>\n" + 222 " </extensions>\n" + 223 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 224 " <extensions>\n" + 225 " <test:foo>extension of a waypoint</test:foo>\n" + 226 " </extensions>\n" + 227 " </trkpt>\n" + 228 " </trkseg>\n" + 229 " </trk>\n" + 230 "</gpx>", baos.toString()); 231 232 baos.reset(); 233 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 234 // checked again to make sure that extensions are shown again after 235 // being hidden, even if they don't actually have to be converted 236 // (GPXD -> convertColor() -> GPXX -> hide() -> null -> show() -> GPXX) 237 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 238 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 239 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 240 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 241 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 242 " xmlns:test=\"http://example.com/testURI\"\n" + 243 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 244 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 245 " <metadata>\n" + 246 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 247 " <extensions>\n" + 248 " <knownprefix:foo>bar</knownprefix:foo>\n" + 249 " <josm:from-server>true</josm:from-server>\n" + 250 " <josm:layerPreferences>\n" + 251 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 252 " </josm:layerPreferences>\n" + 253 " </extensions>\n" + 254 " </metadata>\n" + 255 " <trk>\n" + 256 " <extensions>\n" + 257 " <gpxx:TrackExtension>\n" + 258 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 259 " </gpxx:TrackExtension>\n" + 260 " </extensions>\n" + 261 " <trkseg>\n" + 262 " <extensions>\n" + 263 " <test:foo>extension of a segment</test:foo>\n" + 264 " </extensions>\n" + 265 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 266 " <extensions>\n" + 267 " <test:foo>extension of a waypoint</test:foo>\n" + 268 " </extensions>\n" + 269 " </trkpt>\n" + 270 " </trkseg>\n" + 271 " </trk>\n" + 272 "</gpx>", baos.toString()); 273 274 // CHECKSTYLE.ON: LineLength 275 276 writer.close(); 124 try (GpxWriter writer = new GpxWriter(baos)) { 125 // CHECKSTYLE.OFF: LineLength 126 writer.setMetaTime(Instant.parse("2021-09-12T12:30:50.724Z")); 127 writer.write(data); 128 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 129 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 130 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 131 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 132 " xmlns:gpxd=\"http://josm.openstreetmap.de/gpx-drawing-extensions-1.0\"\n" + 133 " xmlns:test=\"http://example.com/testURI\"\n" + 134 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 135 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://josm.openstreetmap.de/gpx-drawing-extensions-1.0 http://josm.openstreetmap.de/gpx-drawing-extensions-1.0.xsd\">\n" + 136 " <metadata>\n" + 137 " <time>2021-09-12T12:30:50.724Z</time>\n" + 138 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 139 " <extensions>\n" + 140 " <knownprefix:foo>bar</knownprefix:foo>\n" + 141 " <josm:from-server>true</josm:from-server>\n" + 142 " <josm:layerPreferences>\n" + 143 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 144 " </josm:layerPreferences>\n" + 145 " </extensions>\n" + 146 " </metadata>\n" + 147 " <trk>\n" + 148 " <extensions>\n" + 149 " <gpxd:color>#FF0000</gpxd:color>\n" + 150 " </extensions>\n" + 151 " <trkseg>\n" + 152 " <extensions>\n" + 153 " <test:foo>extension of a segment</test:foo>\n" + 154 " </extensions>\n" + 155 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 156 " <extensions>\n" + 157 " <test:foo>extension of a waypoint</test:foo>\n" + 158 " </extensions>\n" + 159 " </trkpt>\n" + 160 " </trkseg>\n" + 161 " </trk>\n" + 162 "</gpx>", baos.toString()); 163 164 baos.reset(); 165 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 166 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 167 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 168 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 169 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 170 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 171 " xmlns:test=\"http://example.com/testURI\"\n" + 172 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 173 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 174 " <metadata>\n" + 175 " <time>2021-09-12T12:30:50.724Z</time>\n" + 176 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 177 " <extensions>\n" + 178 " <knownprefix:foo>bar</knownprefix:foo>\n" + 179 " <josm:from-server>true</josm:from-server>\n" + 180 " <josm:layerPreferences>\n" + 181 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 182 " </josm:layerPreferences>\n" + 183 " </extensions>\n" + 184 " </metadata>\n" + 185 " <trk>\n" + 186 " <extensions>\n" + 187 " <gpxx:TrackExtension>\n" + 188 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 189 " </gpxx:TrackExtension>\n" + 190 " </extensions>\n" + 191 " <trkseg>\n" + 192 " <extensions>\n" + 193 " <test:foo>extension of a segment</test:foo>\n" + 194 " </extensions>\n" + 195 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 196 " <extensions>\n" + 197 " <test:foo>extension of a waypoint</test:foo>\n" + 198 " </extensions>\n" + 199 " </trkpt>\n" + 200 " </trkseg>\n" + 201 " </trk>\n" + 202 "</gpx>", baos.toString()); 203 204 baos.reset(); 205 writer.write(data, null, false); 206 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 207 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 208 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 209 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 210 " xmlns:test=\"http://example.com/testURI\"\n" + 211 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 212 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd\">\n" + 213 " <metadata>\n" + 214 " <time>2021-09-12T12:30:50.724Z</time>\n" + 215 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 216 " <extensions>\n" + 217 " <knownprefix:foo>bar</knownprefix:foo>\n" + 218 " <josm:from-server>true</josm:from-server>\n" + 219 " </extensions>\n" + 220 " </metadata>\n" + 221 " <trk>\n" + 222 " <trkseg>\n" + 223 " <extensions>\n" + 224 " <test:foo>extension of a segment</test:foo>\n" + 225 " </extensions>\n" + 226 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 227 " <extensions>\n" + 228 " <test:foo>extension of a waypoint</test:foo>\n" + 229 " </extensions>\n" + 230 " </trkpt>\n" + 231 " </trkseg>\n" + 232 " </trk>\n" + 233 "</gpx>", baos.toString()); 234 235 baos.reset(); 236 writer.write(data, GpxConstants.ColorFormat.GPXX, true); 237 // checked again to make sure that extensions are shown again after 238 // being hidden, even if they don't actually have to be converted 239 // (GPXD -> convertColor() -> GPXX -> hide() -> null -> show() -> GPXX) 240 assertEqualsNewline("<?xml version='1.0' encoding='UTF-8'?>\n" + 241 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + 242 " xmlns:knownprefix=\"http://example.com/URI\"\n" + 243 " xmlns:josm=\"http://josm.openstreetmap.de/gpx-extensions-1.1\"\n" + 244 " xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n" + 245 " xmlns:test=\"http://example.com/testURI\"\n" + 246 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + 247 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://example.com/URI http://example.com/location.xsd http://josm.openstreetmap.de/gpx-extensions-1.1 http://josm.openstreetmap.de/gpx-extensions-1.1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd\">\n" + 248 " <metadata>\n" + 249 " <time>2021-09-12T12:30:50.724Z</time>\n" + 250 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>\n" + 251 " <extensions>\n" + 252 " <knownprefix:foo>bar</knownprefix:foo>\n" + 253 " <josm:from-server>true</josm:from-server>\n" + 254 " <josm:layerPreferences>\n" + 255 " <josm:entry key=\"foo\" value=\"bar\"/>\n" + 256 " </josm:layerPreferences>\n" + 257 " </extensions>\n" + 258 " </metadata>\n" + 259 " <trk>\n" + 260 " <extensions>\n" + 261 " <gpxx:TrackExtension>\n" + 262 " <gpxx:DisplayColor>Red</gpxx:DisplayColor>\n" + 263 " </gpxx:TrackExtension>\n" + 264 " </extensions>\n" + 265 " <trkseg>\n" + 266 " <extensions>\n" + 267 " <test:foo>extension of a segment</test:foo>\n" + 268 " </extensions>\n" + 269 " <trkpt lat=\"0.0\" lon=\"0.0\">\n" + 270 " <extensions>\n" + 271 " <test:foo>extension of a waypoint</test:foo>\n" + 272 " </extensions>\n" + 273 " </trkpt>\n" + 274 " </trkseg>\n" + 275 " </trk>\n" + 276 "</gpx>", baos.toString()); 277 278 // CHECKSTYLE.ON: LineLength 279 } 277 280 } 278 281 }
Note:
See TracChangeset
for help on using the changeset viewer.