1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.location.cts; 18 19 20 import android.content.Context; 21 import android.location.Criteria; 22 import android.location.LocationManager; 23 import android.location.LocationProvider; 24 import android.test.AndroidTestCase; 25 26 public class LocationProviderTest extends AndroidTestCase { 27 private static final String PROVIDER_NAME = "location_provider_test"; 28 29 private LocationManager mLocationManager; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 mLocationManager = 35 (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); 36 addTestProvider(PROVIDER_NAME); 37 } 38 39 @Override 40 protected void tearDown() throws Exception { 41 mLocationManager.removeTestProvider(PROVIDER_NAME); 42 super.tearDown(); 43 } 44 45 /** 46 * Adds a test provider with the given name. 47 */ 48 private void addTestProvider(String providerName) { 49 mLocationManager.addTestProvider( 50 providerName, 51 true, // requiresNetwork, 52 false, // requiresSatellite, 53 false, // requiresCell, 54 false, // hasMonetaryCost, 55 true, // supportsAltitude, 56 false, // supportsSpeed, 57 true, // supportsBearing, 58 Criteria.POWER_MEDIUM, // powerRequirement, 59 Criteria.ACCURACY_FINE); // accuracy 60 mLocationManager.setTestProviderEnabled(providerName, true); 61 } 62 63 public void testGetName() { 64 LocationProvider locationProvider = mLocationManager.getProvider(PROVIDER_NAME); 65 assertEquals(PROVIDER_NAME, locationProvider.getName()); 66 } 67 68 public void testMeetsCriteria() { 69 LocationProvider locationProvider = mLocationManager.getProvider(PROVIDER_NAME); 70 71 Criteria criteria = new Criteria(); 72 criteria.setAltitudeRequired(true); 73 criteria.setBearingRequired(true); 74 assertTrue(locationProvider.meetsCriteria(criteria)); 75 } 76 } 77