Small test changes
1) Remove redundant tests better covered by CTS anyways 2) Enable framework tests on location client changes Test: presubmits Change-Id: I8ff777e48884eba994582531b7b3e63d9012e9ef
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
},
|
||||
{
|
||||
"name": "CtsLocationNoneTestCases"
|
||||
},
|
||||
{
|
||||
"name": "FrameworksMockingServicesTests",
|
||||
"options": [{
|
||||
"include-filter": "com.android.server.location"
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
android_test {
|
||||
name: "FrameworksLocationTests",
|
||||
// Include all test java files.
|
||||
srcs: ["src/**/*.java"],
|
||||
libs: [
|
||||
"android.test.runner",
|
||||
"android.test.base",
|
||||
],
|
||||
platform_apis: true,
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"core-test-rules",
|
||||
"guava",
|
||||
"mockito-target-minus-junit4",
|
||||
"frameworks-base-testutils",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
test_suites: ["device-tests"],
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.frameworks.locationtests">
|
||||
|
||||
<!-- location test permissions -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.frameworks.locationtests"
|
||||
android:label="Frameworks Location Tests" />
|
||||
</manifest>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<configuration description="Runs Frameworks Location API Tests.">
|
||||
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
|
||||
<option name="test-file-name" value="FrameworksLocationTests.apk" />
|
||||
</target_preparer>
|
||||
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
<option name="test-tag" value="FrameworksLocationTests" />
|
||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||
<option name="package" value="com.android.frameworks.locationtests" />
|
||||
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
|
||||
<option name="hidden-api-checks" value="false"/>
|
||||
</test>
|
||||
</configuration>
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.location;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
public class CountryTester extends AndroidTestCase {
|
||||
public void testCountryEquals() {
|
||||
Country countryA = new Country("US", Country.COUNTRY_SOURCE_NETWORK);
|
||||
Country countryB = new Country("US", Country.COUNTRY_SOURCE_LOCALE);
|
||||
Country countryC = new Country("CN", Country.COUNTRY_SOURCE_LOCALE);
|
||||
Country countryD = new Country("us", Country.COUNTRY_SOURCE_NETWORK);
|
||||
assertTrue(countryA.equalsIgnoreSource(countryB));
|
||||
assertFalse(countryA.equalsIgnoreSource(countryC));
|
||||
assertFalse(countryA.equals(countryC));
|
||||
assertTrue(countryA.equals(countryD));
|
||||
assertTrue(countryA.hashCode() == countryD.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package android.location;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.Suppress;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
@Suppress
|
||||
public class GeocoderTest extends AndroidTestCase {
|
||||
|
||||
public void testGeocoder() throws Exception {
|
||||
Locale locale = new Locale("en", "us");
|
||||
Geocoder g = new Geocoder(mContext, locale);
|
||||
|
||||
List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
|
||||
assertNotNull(addresses1);
|
||||
assertEquals(1, addresses1.size());
|
||||
|
||||
Address addr = addresses1.get(0);
|
||||
assertEquals("94305", addr.getFeatureName());
|
||||
assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
|
||||
assertEquals("USA", addr.getAddressLine(1));
|
||||
assertEquals("94305", addr.getPostalCode());
|
||||
assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
|
||||
|
||||
List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
|
||||
assertNotNull(addresses2);
|
||||
assertEquals(1, addresses2.size());
|
||||
|
||||
addr = addresses2.get(0);
|
||||
assertEquals("San Francisco", addr.getFeatureName());
|
||||
assertEquals("San Francisco, CA", addr.getAddressLine(0));
|
||||
assertEquals("United States", addr.getAddressLine(1));
|
||||
assertEquals("San Francisco", addr.getLocality());
|
||||
assertEquals("CA", addr.getAdminArea());
|
||||
assertEquals(null, addr.getPostalCode());
|
||||
|
||||
assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.location.LocationProvider;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.Suppress;
|
||||
import android.util.Log;
|
||||
|
||||
@Suppress
|
||||
public class LocationManagerTest extends AndroidTestCase {
|
||||
private static final String LOG_TAG = "LocationManagerTest";
|
||||
|
||||
private LocationManager manager;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
|
||||
assertNotNull(manager);
|
||||
}
|
||||
|
||||
public void testGetBogusProvider() {
|
||||
LocationProvider p = manager.getProvider("bogus");
|
||||
assertNull(p);
|
||||
}
|
||||
|
||||
public void testGetNetworkProvider() {
|
||||
LocationProvider p = manager.getProvider("network");
|
||||
assertNotNull(p);
|
||||
}
|
||||
|
||||
public void testGetGpsProvider() {
|
||||
LocationProvider p = manager.getProvider("gps");
|
||||
assertNotNull(p);
|
||||
}
|
||||
|
||||
public void testGetBestProviderEmptyCriteria() {
|
||||
String p = manager.getBestProvider(new Criteria(), true);
|
||||
assertNotNull(p);
|
||||
}
|
||||
|
||||
public void testGetBestProviderPowerCriteria() {
|
||||
Criteria c = new Criteria();
|
||||
c.setPowerRequirement(Criteria.POWER_HIGH);
|
||||
String p = manager.getBestProvider(c, true);
|
||||
assertNotNull(p);
|
||||
|
||||
c.setPowerRequirement(Criteria.POWER_MEDIUM);
|
||||
p = manager.getBestProvider(c, true);
|
||||
assertNotNull(p);
|
||||
|
||||
c.setPowerRequirement(Criteria.POWER_LOW);
|
||||
p = manager.getBestProvider(c, true);
|
||||
assertNotNull(p);
|
||||
|
||||
c.setPowerRequirement(Criteria.NO_REQUIREMENT);
|
||||
p = manager.getBestProvider(c, true);
|
||||
assertNotNull(p);
|
||||
}
|
||||
|
||||
public void testGpsTracklog() {
|
||||
LocationProvider p = manager.getProvider("gps");
|
||||
assertNotNull(p);
|
||||
|
||||
// TODO: test requestUpdates method
|
||||
}
|
||||
|
||||
public void testLocationConversions() {
|
||||
String loc1 = Location.convert(-80.075, Location.FORMAT_DEGREES);
|
||||
Log.i(LOG_TAG, "Input = " + (-80.075) + ", output = " + loc1);
|
||||
assertEquals("-80.075", loc1);
|
||||
|
||||
String loc1b = Location.convert(-80.0, Location.FORMAT_DEGREES);
|
||||
Log.i(LOG_TAG, "Input = " + (-80.0) + ", output = " + loc1b);
|
||||
assertEquals("-80", loc1b);
|
||||
|
||||
String loc2 = Location.convert(-80.085, Location.FORMAT_DEGREES);
|
||||
Log.i(LOG_TAG, "Input = " + (-80.085) + ", output = " + loc2);
|
||||
assertEquals("-80.085", loc2);
|
||||
|
||||
String loc3 = Location.convert(-80.085, Location.FORMAT_MINUTES);
|
||||
Log.i(LOG_TAG, "Input = " + (-80.085) + ", output = " + loc3);
|
||||
assertEquals("-80:5.1", loc3);
|
||||
|
||||
String loc4 = Location.convert(-80.085, Location.FORMAT_SECONDS);
|
||||
Log.i(LOG_TAG, "Input = " + (-80.085) + ", output = " + loc4);
|
||||
assertEquals("-80:5:6", loc4);
|
||||
|
||||
String loc5 = Location.convert(5 + 0.5f / 60.0f, Location.FORMAT_MINUTES);
|
||||
Log.i(LOG_TAG, "Input = 5:0.5, output = " + loc5);
|
||||
int index = loc5.indexOf(':');
|
||||
String loc5a = loc5.substring(0, index);
|
||||
Log.i(LOG_TAG, "loc5a = " + loc5a);
|
||||
assertTrue(loc5a.equals("5"));
|
||||
String loc5b = loc5.substring(index + 1);
|
||||
Log.i(LOG_TAG, "loc5b = " + loc5b);
|
||||
double minutes = Double.parseDouble(loc5b);
|
||||
Log.i(LOG_TAG, "minutes = " + minutes);
|
||||
assertTrue(Math.abs(minutes - 0.5) < 0.0001);
|
||||
|
||||
String loc6 = Location.convert(0.1, Location.FORMAT_DEGREES);
|
||||
Log.i(LOG_TAG, "loc6 = " + loc6);
|
||||
assertEquals(loc6, "0.1");
|
||||
|
||||
String loc7 = Location.convert(0.1, Location.FORMAT_MINUTES);
|
||||
Log.i(LOG_TAG, "loc7 = " + loc7);
|
||||
assertEquals(loc7, "0:6");
|
||||
|
||||
String loc8 = Location.convert(0.1, Location.FORMAT_SECONDS);
|
||||
Log.i(LOG_TAG, "loc8 = " + loc8);
|
||||
assertEquals(loc8, "0:6:0");
|
||||
}
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.location;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for android.location.Location
|
||||
*/
|
||||
@SmallTest
|
||||
public class LocationTest extends TestCase {
|
||||
|
||||
// ***** Tests for Location.convert
|
||||
public void testConvert_DegreesToDouble(){
|
||||
String testDegreesCoord = "-80.075";
|
||||
String message;
|
||||
double result;
|
||||
|
||||
result = Location.convert(testDegreesCoord);
|
||||
message = "degreesToDoubleTest: Double should be -80.075, actual value is " +
|
||||
String.valueOf(result);
|
||||
assertEquals(message, -80.075, result);
|
||||
}
|
||||
|
||||
public void testConvert_MinutesToDouble(){
|
||||
String testMinutesCoord = "-80:05.10000";
|
||||
String message;
|
||||
double result;
|
||||
|
||||
result = Location.convert(testMinutesCoord);
|
||||
message = "minutesToDoubleTest: Double should be -80.085, actual value is " +
|
||||
String.valueOf(result);
|
||||
assertEquals(message, -80.085, result);
|
||||
}
|
||||
|
||||
public void testConvert_SecondsToDouble(){
|
||||
String testSecondsCoord = "-80:04:03.00000";
|
||||
String message;
|
||||
double result;
|
||||
|
||||
result = Location.convert(testSecondsCoord);
|
||||
message = "secondsToDoubleTest: Double should be -80.0675, actual value is " +
|
||||
String.valueOf(result);
|
||||
assertEquals(message, -80.0675, result);
|
||||
}
|
||||
|
||||
public void testConvert_SecondsToDouble2(){
|
||||
String testSecondsCoord = "-80:4:3";
|
||||
String message;
|
||||
double result;
|
||||
|
||||
result = Location.convert(testSecondsCoord);
|
||||
message = "secondsToDouble2Test: Double should be -80.0675, actual value is " +
|
||||
String.valueOf(result);
|
||||
assertEquals(message, -80.0675, result);
|
||||
}
|
||||
|
||||
// Testing the Convert(Double, Int)
|
||||
public void testConvert_CoordinateToDegrees(){
|
||||
String message;
|
||||
String result;
|
||||
|
||||
result = Location.convert(-80.075, Location.FORMAT_DEGREES);
|
||||
message = "coordinateToDegreesTest: Should return a string -80.075, but returned " + result;
|
||||
assertEquals(message, "-80.075", result);
|
||||
}
|
||||
|
||||
public void testConvert_CoordinateToDegrees2(){
|
||||
String message;
|
||||
String result;
|
||||
result = Location.convert(-80.0, Location.FORMAT_DEGREES);
|
||||
message = "coordinateToDegrees2Test: Should return a string -80, but returned " + result;
|
||||
assertEquals(message, "-80", result);
|
||||
}
|
||||
|
||||
public void testConvert_CoordinateToMinutes(){
|
||||
String message;
|
||||
String result;
|
||||
double input = -80.085;
|
||||
result = Location.convert(input, Location.FORMAT_MINUTES);
|
||||
message = "coordinateToMinuteTest: Should return a string -80:5.1, but returned " +
|
||||
result;
|
||||
assertEquals(message, "-80:5.1", result);
|
||||
}
|
||||
|
||||
public void testConvert_CoordinateToMinutes2(){
|
||||
String message;
|
||||
String result;
|
||||
double input = -80;
|
||||
result = Location.convert(input, Location.FORMAT_MINUTES);
|
||||
message = "coordinateToMinute2Test: Should return a string -80:0, but returned " +
|
||||
result;
|
||||
assertEquals(message, "-80:0", result);
|
||||
}
|
||||
|
||||
public void testConvert_CoordinateToSeconds(){
|
||||
String message;
|
||||
String result;
|
||||
|
||||
result = Location.convert(-80.075, Location.FORMAT_SECONDS);
|
||||
message = "coordinateToSecondsTest: Should return a string -80:4:30, but returned " +
|
||||
result;
|
||||
assertEquals(message, "-80:4:30", result);
|
||||
}
|
||||
// **** end tests for Location.convert
|
||||
|
||||
|
||||
public void testBearingTo(){
|
||||
String message;
|
||||
float bearing;
|
||||
Location zeroLocation = new Location("");
|
||||
zeroLocation.setLatitude(0);
|
||||
zeroLocation.setLongitude(0);
|
||||
|
||||
Location testLocation = new Location("");
|
||||
testLocation.setLatitude(1000000);
|
||||
testLocation.setLongitude(0);
|
||||
|
||||
bearing = zeroLocation.bearingTo(zeroLocation);
|
||||
message = "bearingToTest: Bearing should be 0, actual value is " + String.valueOf(bearing);
|
||||
assertEquals(message, 0, bearing, 0);
|
||||
|
||||
bearing = zeroLocation.bearingTo(testLocation);
|
||||
message = "bearingToTest: Bearing should be 180, actual value is " +
|
||||
String.valueOf(bearing);
|
||||
assertEquals(message, 180, bearing, 0);
|
||||
|
||||
testLocation.setLatitude(0);
|
||||
testLocation.setLongitude(1000000);
|
||||
bearing = zeroLocation.bearingTo(testLocation);
|
||||
message = "bearingToTest: Bearing should be -90, actual value is " +
|
||||
String.valueOf(bearing);
|
||||
assertEquals(message, -90, bearing, 0);
|
||||
|
||||
//TODO: Test a Random Middle Value
|
||||
}
|
||||
|
||||
public void testDistanceTo() {
|
||||
String message;
|
||||
boolean result = true;
|
||||
float distance;
|
||||
Location zeroLocation = new Location("");
|
||||
zeroLocation.setLatitude(0);
|
||||
zeroLocation.setLongitude(0);
|
||||
|
||||
Location testLocation = new Location("");
|
||||
testLocation.setLatitude(1000000);
|
||||
testLocation.setLongitude(0);
|
||||
|
||||
distance = zeroLocation.distanceTo(zeroLocation);
|
||||
message = "distanceToTest: Distance should be 0, actual value is " +
|
||||
String.valueOf(distance);
|
||||
assertEquals(message, distance, 0, 0);
|
||||
|
||||
distance = zeroLocation.distanceTo(testLocation);
|
||||
message = "distanceToTest: Distance should be 8885140, actual value is " +
|
||||
String.valueOf(distance);
|
||||
assertEquals(message, distance, 8885140.0, 1);
|
||||
}
|
||||
|
||||
public void testAltitude() {
|
||||
String message;
|
||||
Location loc = new Location("");
|
||||
|
||||
loc.setAltitude(1);
|
||||
message = "altitudeTest: set/getAltitude to 1 didn't work.";
|
||||
assertEquals(message, loc.getAltitude(), 1, 0);
|
||||
message = "altitudeTest: hasAltitude (a) didn't work.";
|
||||
assertTrue(message, loc.hasAltitude());
|
||||
|
||||
loc.removeAltitude();
|
||||
message = "altitudeTest: hasAltitude (b) didn't work.";
|
||||
assertFalse(message, loc.hasAltitude());
|
||||
message = "altitudeTest: getAltitude didn't return 0 when there was no altitude.";
|
||||
assertEquals(message, loc.getAltitude(), 0, 0);
|
||||
}
|
||||
|
||||
public void testSpeed() {
|
||||
String message;
|
||||
Location loc = new Location("");
|
||||
|
||||
loc.setSpeed(1);
|
||||
message = "speedTest: set/getSpeed to 1 didn't work.";
|
||||
assertEquals(message, loc.getSpeed(), 1, 0);
|
||||
message = "speedTest: hasSpeed (a) didn't work.";
|
||||
assertTrue(message, loc.hasSpeed());
|
||||
|
||||
loc.removeSpeed();
|
||||
message = "speedTest: hasSpeed (b) didn't work.";
|
||||
assertFalse(message, loc.hasSpeed());
|
||||
message = "speedTest: getSpeed didn't return 0 when there was no speed.";
|
||||
assertEquals(message, loc.getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
public void testBearing() {
|
||||
String message;
|
||||
Location loc = new Location("");
|
||||
|
||||
loc.setBearing(1);
|
||||
message = "bearingTest: set/getBearing to 1 didn't work.";
|
||||
assertEquals(message, loc.getBearing(), 1, 0);
|
||||
message = "bearingTest: hasBearing (a) didn't work.";
|
||||
assertTrue(message, loc.hasBearing());
|
||||
|
||||
loc.removeBearing();
|
||||
message = "bearingTest: hasBearing (b) didn't work.";
|
||||
assertFalse(message, loc.hasBearing());
|
||||
message = "bearingTest: getBearing didn't return 0 when there was no bearing.";
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user