Skip to content

Commit

Permalink
Merge branch 'upload_waypoints'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Oct 14, 2023
2 parents b133b9b + a4d3d69 commit f604bba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/androidTest/java/de/blau/android/gpx/GpxUploadTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.blau.android.gpx;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

Expand Down Expand Up @@ -137,10 +139,30 @@ public void uploadGpx() {
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
UiObject2 menuButton = TestUtils.getLayerButton(device, GPX_FILE, LayerDialogTest.MENU_BUTTON);
menuButton.click();
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_information), true, false));
assertTrue(TestUtils.findText(device, false, "112", 500, true));
assertTrue(TestUtils.findText(device, false, "79", 500, true));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
menuButton = TestUtils.getLayerButton(device, GPX_FILE, LayerDialogTest.MENU_BUTTON);
menuButton.click();
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.menu_gps_upload), true, false));
mockServer.enqueue("userdetails");
mockServer.enqueue("200");
assertTrue(TestUtils.clickResource(device, false, "android:id/button1", true));
assertTrue(TestUtils.textGone(device, "Uploading", 5000));

try {
mockServer.takeRequest();
String upload = mockServer.takeRequest().getUtf8Body();
int gpxStart = upload.indexOf("<?xml");
Track track = new Track(main, false);
track.importFromGPX(new ByteArrayInputStream(upload.substring(gpxStart).getBytes()));
assertEquals(79, track.getWayPoints().size());
assertEquals(112, track.getTrackPoints().size());
} catch (InterruptedException e) {
fail(e.getMessage());
}
} finally {
TestUtils.deleteFile(main, GPX_FILE);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/blau/android/gpx/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ public void markNewSegment() {
*
* @param outputStream the stream we are writing to
* @throws XmlPullParserException
* @throws IOException
* @throws IOException if writing to the stream fails
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParserException, IllegalArgumentException, IllegalStateException, IOException {
public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParserException, IOException {
XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
serializer.setOutput(outputStream, OsmXml.UTF_8);
serializer.startDocument(OsmXml.UTF_8, null);
Expand All @@ -471,6 +471,9 @@ public void exportToGPX(@NonNull OutputStream outputStream) throws XmlPullParser
serializer.attribute(null, "xsi:schemaLocation", "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd");
serializer.attribute(null, "version", "1.0");
serializer.attribute(null, "creator", "Vespucci");
for (WayPoint wt : getWayPoints()) {
wt.toXml(serializer, this);
}
serializer.startTag(null, TRK_ELEMENT);
serializer.startTag(null, TRKSEG_ELEMENT);
boolean hasPoints = false;
Expand Down

0 comments on commit f604bba

Please sign in to comment.