GPS Location Test

Verify that the previously set GPS Location via geo fix command
is set properly.

Change-Id: If160a8379d93a813402bf8622b279feac4f5f110
diff --git a/tools/emulator/test-apps/GpsLocationTest/Android.mk b/tools/emulator/test-apps/GpsLocationTest/Android.mk
new file mode 100644
index 0000000..35c9443
--- /dev/null
+++ b/tools/emulator/test-apps/GpsLocationTest/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2011 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.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := GpsLocationTest
+
+LOCAL_SDK_VERSION := 4
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tools/emulator/test-apps/GpsLocationTest/AndroidManifest.xml b/tools/emulator/test-apps/GpsLocationTest/AndroidManifest.xml
new file mode 100644
index 0000000..901855e
--- /dev/null
+++ b/tools/emulator/test-apps/GpsLocationTest/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="com.android.emulator.gps.test"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-sdk android:minSdkVersion="4" />
+    <instrumentation android:targetPackage="com.android.emulator.gps.test"
+                     android:name="android.test.InstrumentationTestRunner" />
+    <application  android:label="GPS Location Test">
+        <uses-library android:name="android.test.runner" />
+    </application>
+</manifest>
\ No newline at end of file
diff --git a/tools/emulator/test-apps/GpsLocationTest/src/com/android/emulator/gps/test/GpsLocationTest.java b/tools/emulator/test-apps/GpsLocationTest/src/com/android/emulator/gps/test/GpsLocationTest.java
new file mode 100644
index 0000000..c0ea0fa
--- /dev/null
+++ b/tools/emulator/test-apps/GpsLocationTest/src/com/android/emulator/gps/test/GpsLocationTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 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 com.android.emulator.gps.test;
+
+import android.content.Context;
+import android.location.Location;
+import android.location.LocationManager;
+import android.test.AndroidTestCase;
+
+/**
+ * GPS Location Test
+ *
+ * Test the GPS API by verifying the previously set location
+ */
+public class GpsLocationTest extends AndroidTestCase {
+
+    private LocationManager locationManager;
+
+    /**
+     * Prior to running this test the GPS location must be set to the following
+     * longitude and latitude coordinates via the geo fix command
+     */
+    private static final double LONGITUDE = -122.08345770835876;
+    private static final double LATITUDE = 37.41991859119417;
+
+    @Override
+    protected void setUp() throws Exception {
+        locationManager = (LocationManager) getContext().
+            getSystemService(Context.LOCATION_SERVICE);
+        assertNotNull(locationManager);
+    }
+
+    /**
+     * verify that the last location equals to the location set
+     * via geo fix command
+     */
+    public void testCurrentLocationGivenLocation(){
+        Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+        assertNotNull(lastLocation);
+        assertEquals(lastLocation.getLongitude(), LONGITUDE);
+        assertEquals(lastLocation.getLatitude(), LATITUDE);
+    }
+}