diff options
author | David Christie <dnchrist@google.com> | 2015-10-27 16:55:58 -0700 |
---|---|---|
committer | David Christie <dnchrist@google.com> | 2015-10-27 18:09:53 -0700 |
commit | 923b2602583021b97ac7a8dcbca8395e309b938e (patch) | |
tree | 2dbbb782370dbe0f6dbab5007831f634756b1053 /location/tests | |
parent | ab253faa47de946b311522925c9875d2cccaaff5 (diff) |
Make Location objects take less memory.
-Use bitmask for has*** methods.
-Use ThreadLocal for caching intermediate computations
rather than preallocating memory in every Location
Change-Id: If2fa17bfd59511ec0b809f4b7d7cd8028360c340
Diffstat (limited to 'location/tests')
-rw-r--r-- | location/tests/locationtests/src/android/location/LocationTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/location/tests/locationtests/src/android/location/LocationTest.java b/location/tests/locationtests/src/android/location/LocationTest.java index 847ac7a000be..dc8d0f7b3876 100644 --- a/location/tests/locationtests/src/android/location/LocationTest.java +++ b/location/tests/locationtests/src/android/location/LocationTest.java @@ -16,6 +16,7 @@ package android.location; +import android.os.Parcel; import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; @@ -225,6 +226,40 @@ public class LocationTest extends TestCase { assertEquals(message, loc.getBearing(), 0, 0); } + public void testParcel() { + final double expectedLat = 33; + final double expectedLon = -122; + final float expectedAccuracy = 15; + final float expectedSpeed = 5; + Location loc = new Location("test"); + loc.setLatitude(expectedLat); + loc.setLongitude(expectedLon); + loc.setAccuracy(expectedAccuracy); + loc.setSpeed(expectedSpeed); + + // Serialize location object into bytes via parcelable capability + Parcel parcel = Parcel.obtain(); + loc.writeToParcel(parcel, 0); + byte[] rawBytes = parcel.marshall(); + parcel.recycle(); + + // Turn the bytes back into a location object + parcel = Parcel.obtain(); + parcel.unmarshall(rawBytes, 0, rawBytes.length); + parcel.setDataPosition(0); + Location deserialized = Location.CREATOR.createFromParcel(parcel); + parcel.recycle(); + + assertEquals(expectedLat, deserialized.getLatitude()); + assertEquals(expectedLon, deserialized.getLongitude()); + assertEquals(expectedAccuracy, deserialized.getAccuracy()); + assertTrue(deserialized.hasAccuracy()); + assertEquals(expectedSpeed, deserialized.getSpeed()); + assertTrue(deserialized.hasSpeed()); + assertFalse(deserialized.hasBearing()); + assertFalse(deserialized.hasAltitude()); + assertFalse(deserialized.isFromMockProvider()); + } } |