am cbd66b79: am 4f024787: Merge "Add Basic PreferenceActivityTest" into froyo

* commit 'cbd66b7946414c313ec38d6f56dde942293e451e':
  Add Basic PreferenceActivityTest
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 16b81c9..9e3f0a5 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -47,6 +47,7 @@
 	CtsOsTestCases \
 	CtsPermissionTestCases \
 	CtsPermission2TestCases \
+	CtsPreferenceTestCases \
 	CtsProviderTestCases \
 	CtsSaxTestCases \
 	CtsSpeechTestCases \
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index f3b4137..3f11bd1 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -37,6 +37,7 @@
     <classpathentry kind="src" path="cts/tests/tests/performance5/src"/>
     <classpathentry kind="src" path="cts/tests/tests/permission/src"/>
     <classpathentry kind="src" path="cts/tests/tests/permission2/src"/>
+    <classpathentry kind="src" path="cts/tests/tests/preference/src"/>
     <classpathentry kind="src" path="cts/tests/tests/provider/src"/>
     <classpathentry kind="src" path="cts/tests/tests/speech/src"/>
     <classpathentry kind="src" path="cts/tests/tests/telephony/src"/>
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 1c79ece..43eb5fc 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -932,6 +932,11 @@
 
         <activity android:name="android.opengl.cts.OpenGlEsVersionStubActivity"/>
 
+        <activity android:name="android.preference.cts.PreferenceStubActivity">
+            <meta-data android:name="android.preference" 
+                    android:resource="@xml/preferences_from_intent" />
+        </activity>
+
     </application>
 
     <!--Test for PackageManager, please put this at the very beginning-->
diff --git a/tests/res/xml/preferences_from_intent.xml b/tests/res/xml/preferences_from_intent.xml
new file mode 100644
index 0000000..0911403
--- /dev/null
+++ b/tests/res/xml/preferences_from_intent.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+    <CheckBoxPreference android:key="check_box_preference_from_intent"
+        android:defaultValue="false"
+        android:title="Check box preference"
+        android:summary="This is a check box preference."
+        />
+</PreferenceScreen>
diff --git a/tests/res/xml/preferences_from_resource.xml b/tests/res/xml/preferences_from_resource.xml
new file mode 100644
index 0000000..d954032
--- /dev/null
+++ b/tests/res/xml/preferences_from_resource.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+    <CheckBoxPreference android:key="check_box_preference_from_resource"
+        android:defaultValue="false"
+        android:title="Check box preference"
+        android:summary="This is a check box preference."
+        />
+</PreferenceScreen>
diff --git a/tests/src/android/preference/cts/PreferenceStubActivity.java b/tests/src/android/preference/cts/PreferenceStubActivity.java
new file mode 100644
index 0000000..4b6062b
--- /dev/null
+++ b/tests/src/android/preference/cts/PreferenceStubActivity.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2010 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 android.preference.cts;
+
+import android.preference.PreferenceActivity;
+
+public class PreferenceStubActivity extends PreferenceActivity {
+}
diff --git a/tests/tests/preference/Android.mk b/tests/tests/preference/Android.mk
new file mode 100644
index 0000000..886c166
--- /dev/null
+++ b/tests/tests/preference/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2010 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
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsPreferenceTestCases
+
+LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/preference/AndroidManifest.xml b/tests/tests/preference/AndroidManifest.xml
new file mode 100644
index 0000000..af57c86
--- /dev/null
+++ b/tests/tests/preference/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2010 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.cts.preference">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+                     android:targetPackage="com.android.cts.stub"
+                     android:label="CTS tests of android.os"/>
+
+</manifest>
+
diff --git a/tests/tests/preference/src/android/preference/cts/PreferenceActivityTest.java b/tests/tests/preference/src/android/preference/cts/PreferenceActivityTest.java
new file mode 100644
index 0000000..b0d5448
--- /dev/null
+++ b/tests/tests/preference/src/android/preference/cts/PreferenceActivityTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2010 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 android.preference.cts;
+
+import com.android.cts.stub.R;
+
+import android.content.Intent;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceActivityTest
+        extends ActivityInstrumentationTestCase2<PreferenceStubActivity> {
+
+    private PreferenceActivity mActivity;
+
+    public PreferenceActivityTest() {
+        super(PreferenceStubActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    public void testAddPreferencesFromIntent() {
+        assertNull(mActivity.findPreference("check_box_preference_from_intent"));
+
+        Intent intent = new Intent(mActivity, PreferenceStubActivity.class);
+        mActivity.addPreferencesFromIntent(intent);
+
+        assertNotNull(mActivity.findPreference("check_box_preference_from_intent"));
+    }
+
+    public void testAddPreferencesFromResource() {
+        assertNull(mActivity.findPreference("check_box_preference_from_resource"));
+
+        mActivity.addPreferencesFromResource(R.xml.preferences_from_resource);
+
+        assertNotNull(mActivity.findPreference("check_box_preference_from_resource"));
+    }
+
+    public void testGetPreferenceManager() {
+        assertNotNull(mActivity.getPreferenceManager());
+    }
+
+    public void testGetPreferenceScreen() {
+        assertNull(mActivity.getPreferenceScreen());
+
+        PreferenceManager prefManager = mActivity.getPreferenceManager();
+        PreferenceScreen prefScreen = prefManager.createPreferenceScreen(mActivity);
+        mActivity.setPreferenceScreen(prefScreen);
+
+        assertEquals(prefScreen, mActivity.getPreferenceScreen());
+    }
+}
\ No newline at end of file