Merge "Fix location parsing accuracy" into oreo-cts-dev
diff --git a/tests/tests/media/src/android/media/cts/MediaMuxerTest.java b/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
index 15d08a3..fa09149 100644
--- a/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
@@ -480,6 +480,12 @@
// parsing String location and recover the location information in floats
// Make sure the tolerance is very small - due to rounding errors.
+ // Trim the trailing slash, if any.
+ int lastIndex = location.lastIndexOf('/');
+ if (lastIndex != -1) {
+ location = location.substring(0, lastIndex);
+ }
+
// Get the position of the -/+ sign in location String, which indicates
// the beginning of the longitude.
int minusIndex = location.lastIndexOf('-');
@@ -489,12 +495,8 @@
(minusIndex > 0 || plusIndex > 0));
int index = Math.max(minusIndex, plusIndex);
- float latitude = Float.parseFloat(location.substring(0, index - 1));
- int lastIndex = location.lastIndexOf('/', index);
- if (lastIndex == -1) {
- lastIndex = location.length();
- }
- float longitude = Float.parseFloat(location.substring(index, lastIndex - 1));
+ float latitude = Float.parseFloat(location.substring(0, index));
+ float longitude = Float.parseFloat(location.substring(index));
assertTrue("Incorrect latitude: " + latitude + " [" + location + "]",
Math.abs(latitude - LATITUDE) <= TOLERANCE);
assertTrue("Incorrect longitude: " + longitude + " [" + location + "]",
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index 6313621..ca89e1b 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -507,6 +507,12 @@
// Make sure the tolerance is very small - due to rounding errors?.
Log.v(TAG, "location: " + location);
+ // Trim the trailing slash, if any.
+ int lastIndex = location.lastIndexOf('/');
+ if (lastIndex != -1) {
+ location = location.substring(0, lastIndex);
+ }
+
// Get the position of the -/+ sign in location String, which indicates
// the beginning of the longtitude.
int index = location.lastIndexOf('-');
@@ -515,12 +521,8 @@
}
assertTrue("+ or - is not found", index != -1);
assertTrue("+ or - is only found at the beginning", index != 0);
- float latitude = Float.parseFloat(location.substring(0, index - 1));
- int lastIndex = location.lastIndexOf('/', index);
- if (lastIndex == -1) {
- lastIndex = location.length();
- }
- float longitude = Float.parseFloat(location.substring(index, lastIndex - 1));
+ float latitude = Float.parseFloat(location.substring(0, index));
+ float longitude = Float.parseFloat(location.substring(index));
assertTrue("Incorrect latitude: " + latitude, Math.abs(latitude - LATITUDE) <= TOLERANCE);
assertTrue("Incorrect longitude: " + longitude, Math.abs(longitude - LONGITUDE) <= TOLERANCE);
retriever.release();