summaryrefslogtreecommitdiffstats
path: root/location/tests
diff options
context:
space:
mode:
authorNeal Nguyen <tommyn@google.com>2010-01-13 10:42:43 -0800
committerNeal Nguyen <tommyn@google.com>2010-01-29 13:35:51 -0800
commit1a44d5dcabc18cd5ef111f732ccff91683a1a093 (patch)
treee370267a65ba54a43e3026ff9b282cc4e3dad869 /location/tests
parent35ec7863e18ce3d242010b76a50df5a8c285325b (diff)
downloadframeworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.zip
frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.gz
frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.bz2
Phase 2 of test cleanup: moving test files from AndroidTests closer to their sources.
Most of these are file moves; a couple notable exceptions are the changes due to the move, and fixing up test code: - database/DatabaseCursorTest.java - database/DatabaseStatementTest.java - net/UriTest.java
Diffstat (limited to 'location/tests')
-rw-r--r--location/tests/locationtests/src/android/location/GeocoderTest.java64
-rw-r--r--location/tests/locationtests/src/android/location/LocationManagerTest.java132
2 files changed, 196 insertions, 0 deletions
diff --git a/location/tests/locationtests/src/android/location/GeocoderTest.java b/location/tests/locationtests/src/android/location/GeocoderTest.java
new file mode 100644
index 0000000..8a13a24
--- /dev/null
+++ b/location/tests/locationtests/src/android/location/GeocoderTest.java
@@ -0,0 +1,64 @@
+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);
+
+ }
+}
diff --git a/location/tests/locationtests/src/android/location/LocationManagerTest.java b/location/tests/locationtests/src/android/location/LocationManagerTest.java
new file mode 100644
index 0000000..0b8e61d
--- /dev/null
+++ b/location/tests/locationtests/src/android/location/LocationManagerTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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");
+ }
+}