FileDocCategorySizeDatePackage
LocationManagerTest.javaAPI DocAndroid 5.1 API4635Thu Mar 12 22:22:30 GMT 2015android.location

LocationManagerTest

public class LocationManagerTest extends android.test.AndroidTestCase

Fields Summary
private static final String
LOG_TAG
private android.location.LocationManager
manager
Constructors Summary
Methods Summary
public voidsetUp()


    
         
        super.setUp();
        manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
        assertNotNull(manager);
    
public voidtestGetBestProviderEmptyCriteria()

        String p = manager.getBestProvider(new Criteria(), true);
        assertNotNull(p);
    
public voidtestGetBestProviderPowerCriteria()

        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 voidtestGetBogusProvider()

        LocationProvider p = manager.getProvider("bogus");
        assertNull(p);
    
public voidtestGetGpsProvider()

        LocationProvider p = manager.getProvider("gps");
        assertNotNull(p);
    
public voidtestGetNetworkProvider()

        LocationProvider p = manager.getProvider("network");
        assertNotNull(p);
    
public voidtestGpsTracklog()

        LocationProvider p = manager.getProvider("gps");
        assertNotNull(p);

        // TODO: test requestUpdates method
    
public voidtestLocationConversions()

        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");