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 import dalvik.annotation.TestLevel; 20 import dalvik.annotation.TestTargetClass; 21 import dalvik.annotation.TestTargetNew; 22 23 import android.content.Context; 24 import android.location.Criteria; 25 import android.location.LocationManager; 26 import android.location.LocationProvider; 27 import android.test.AndroidTestCase; 28 29 @TestTargetClass(LocationProvider.class) 30 public class LocationProviderTest extends AndroidTestCase { 31 private static final String PROVIDER_NAME = "location_provider_test"; 32 33 private LocationManager mLocationManager; 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 mLocationManager = 39 (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); 40 addTestProvider(PROVIDER_NAME); 41 } 42 43 @Override 44 protected void tearDown() throws Exception { 45 mLocationManager.removeTestProvider(PROVIDER_NAME); 46 super.tearDown(); 47 } 48 49 /** 50 * Adds a test provider with the given name. 51 */ 52 private void addTestProvider(String providerName) { 53 mLocationManager.addTestProvider( 54 providerName, 55 true, // requiresNetwork, 56 false, // requiresSatellite, 57 false, // requiresCell, 58 false, // hasMonetaryCost, 59 true, // supportsAltitude, 60 false, // supportsSpeed, 61 true, // supportsBearing, 62 Criteria.POWER_MEDIUM, // powerRequirement, 63 Criteria.ACCURACY_FINE); // accuracy 64 mLocationManager.setTestProviderEnabled(providerName, true); 65 } 66 67 @TestTargetNew( 68 level = TestLevel.COMPLETE, 69 method = "getName", 70 args = {} 71 ) 72 public void testGetName() { 73 LocationProvider locationProvider = mLocationManager.getProvider(PROVIDER_NAME); 74 assertEquals(PROVIDER_NAME, locationProvider.getName()); 75 } 76 77 @TestTargetNew( 78 level = TestLevel.COMPLETE, 79 method = "meetsCriteria", 80 args = {android.location.Criteria.class} 81 ) 82 public void testMeetsCriteria() { 83 LocationProvider locationProvider = mLocationManager.getProvider(PROVIDER_NAME); 84 85 Criteria criteria = new Criteria(); 86 criteria.setAltitudeRequired(true); 87 criteria.setBearingRequired(true); 88 assertTrue(locationProvider.meetsCriteria(criteria)); 89 } 90 } 91