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.GpsSatellite; 22 import android.location.GpsStatus; 23 import android.location.LocationManager; 24 import android.test.AndroidTestCase; 25 26 import java.util.Iterator; 27 28 public class GpsStatusTest extends AndroidTestCase { 29 private GpsStatus mGpsStatus; 30 31 @Override 32 protected void setUp() throws Exception { 33 super.setUp(); 34 LocationManager lm = 35 (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); 36 mGpsStatus = lm.getGpsStatus(null); 37 } 38 39 public void testGetSatellites() { 40 Iterable<GpsSatellite> satellites = mGpsStatus.getSatellites(); 41 assertNotNull(satellites); 42 43 final int maxSatellites = mGpsStatus.getMaxSatellites(); 44 assertTrue(maxSatellites > 0); 45 46 // check the total number of satellites 47 int count = 0; 48 for (Iterator<GpsSatellite> iterator = satellites.iterator(); 49 iterator.hasNext(); 50 iterator.next()) { 51 count++; 52 if (count > maxSatellites) { 53 // the real total could not be larger than maxSatellites 54 fail("Found more satellites than: " + maxSatellites); 55 } 56 } 57 } 58 59 public void testGetTimeToFirstFix() { 60 // make sure there is no exception. 61 mGpsStatus.getTimeToFirstFix(); 62 } 63 } 64