summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-04-01 18:21:38 -0700
committerBrett Chabot <brettchabot@android.com>2010-04-01 18:31:11 -0700
commit0dc59e78e18493aecd37427531d093e800846c3e (patch)
treef78a49ef7fdeb85648a93444850f06b4243a9555 /graphics
parent2d8234b73d11fdc2178232cabad3ffaa23723405 (diff)
downloadframeworks_base-0dc59e78e18493aecd37427531d093e800846c3e.zip
frameworks_base-0dc59e78e18493aecd37427531d093e800846c3e.tar.gz
frameworks_base-0dc59e78e18493aecd37427531d093e800846c3e.tar.bz2
More framework tests cleanup.
Move all tests for android.* classes from tests/AndroidTests and tests/CoreTests into framework/base/<core|graphics>/tests. Consolidate all tests for java.* classes to tests/CoreTests. Eventually hopefully these will be moved to dalvik/ somewhere. Remove tests/AndroidTests entirely. Change-Id: I86584d086ab7bd045bb38a10b699907805298a95
Diffstat (limited to 'graphics')
-rw-r--r--graphics/tests/graphicstests/res/color/color1.xml20
-rw-r--r--graphics/tests/graphicstests/res/color/color_no_default.xml19
-rw-r--r--graphics/tests/graphicstests/res/values/colors.xml24
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java69
-rw-r--r--graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java98
-rw-r--r--graphics/tests/graphicstests/src/android/view/MockView.java25
6 files changed, 255 insertions, 0 deletions
diff --git a/graphics/tests/graphicstests/res/color/color1.xml b/graphics/tests/graphicstests/res/color/color1.xml
new file mode 100644
index 0000000..87034fa
--- /dev/null
+++ b/graphics/tests/graphicstests/res/color/color1.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:color="@color/testcolor1"/>
+ <item android:color="@color/testcolor2"/>
+</selector>
diff --git a/graphics/tests/graphicstests/res/color/color_no_default.xml b/graphics/tests/graphicstests/res/color/color_no_default.xml
new file mode 100644
index 0000000..41a9b5d
--- /dev/null
+++ b/graphics/tests/graphicstests/res/color/color_no_default.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:color="@color/testcolor1"/>
+</selector>
diff --git a/graphics/tests/graphicstests/res/values/colors.xml b/graphics/tests/graphicstests/res/values/colors.xml
new file mode 100644
index 0000000..7559e65
--- /dev/null
+++ b/graphics/tests/graphicstests/res/values/colors.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 2006, 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.
+*/
+-->
+<resources>
+ <color name="testcolor1">#ff00ff00</color>
+ <color name="testcolor2">#ffff0000</color>
+ <color name="failColor">#ff0000ff</color>
+</resources>
+
diff --git a/graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java b/graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java
new file mode 100644
index 0000000..eb1025c
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2007 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.graphics;
+
+import com.android.frameworks.graphicstests.R;
+
+import android.content.res.Resources;
+import android.content.res.ColorStateList;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Tests of {@link android.graphics.ColorStateList}
+ */
+
+public class ColorStateListTest extends AndroidTestCase {
+
+ private Resources mResources;
+ private int mFailureColor;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mResources = mContext.getResources();
+ mFailureColor = mResources.getColor(R.color.failColor);
+ }
+
+ @SmallTest
+ public void testStateIsInList() throws Exception {
+ ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
+ int[] focusedState = {android.R.attr.state_focused};
+ int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
+ assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
+ }
+
+ @SmallTest
+ public void testEmptyState() throws Exception {
+ ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
+ int[] emptyState = {};
+ int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
+ assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
+ }
+
+ @SmallTest
+ public void testGetColor() throws Exception {
+ int defaultColor = mResources.getColor(R.color.color1);
+ assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
+ }
+
+ @SmallTest
+ public void testGetColorWhenListHasNoDefault() throws Exception {
+ int defaultColor = mResources.getColor(R.color.color_no_default);
+ assertEquals(mResources.getColor(R.color.testcolor1), defaultColor);
+ }
+}
diff --git a/graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java b/graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java
new file mode 100644
index 0000000..0d9f72e
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2007 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.graphics.drawable;
+
+import junit.framework.TestCase;
+
+import android.R;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.util.StateSet;
+import android.view.MockView;
+
+/**
+ * Tests for StateListDrawable
+ *
+ */
+
+public class StateListDrawableTest extends TestCase {
+
+ private StateListDrawable slDrawable;
+ private MockDrawable mockFocusedDrawable;
+ private MockDrawable mockCheckedDrawable;
+ private MockView mockView;
+ private MockDrawable mockDefaultDrawable;
+
+
+ // Re-enable tests when we are running in the framework-test directory which allows
+ // access to package private access for MockView
+
+ public void broken_testFocusScenarioSetStringWildcardFirst() throws Exception {
+ int focusedStateSet[] = {R.attr.state_focused};
+ int checkedStateSet[] = {R.attr.state_checked};
+ slDrawable.addState(StateSet.WILD_CARD,
+ mockDefaultDrawable);
+ slDrawable.addState(checkedStateSet, mockCheckedDrawable);
+ slDrawable.addState(focusedStateSet, mockFocusedDrawable);
+ mockView.requestFocus();
+ mockView.getBackground().draw(null);
+ assertTrue(mockDefaultDrawable.wasDrawn);
+ }
+
+ public void broken_testFocusScenarioStateSetWildcardLast() throws Exception {
+ int focusedStateSet[] = {R.attr.state_focused};
+ int checkedStateSet[] = {R.attr.state_checked};
+ slDrawable.addState(checkedStateSet, mockCheckedDrawable);
+ slDrawable.addState(focusedStateSet, mockFocusedDrawable);
+ slDrawable.addState(StateSet.WILD_CARD,
+ mockDefaultDrawable);
+ mockView.requestFocus();
+ mockView.getBackground().draw(null);
+ assertTrue(mockFocusedDrawable.wasDrawn);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ slDrawable = new StateListDrawable();
+ mockFocusedDrawable = new MockDrawable();
+ mockCheckedDrawable = new MockDrawable();
+ mockDefaultDrawable = new MockDrawable();
+ mockView = new MockView();
+ mockView.setBackgroundDrawable(slDrawable);
+ }
+
+ static class MockDrawable extends Drawable {
+
+ public boolean wasDrawn = false;
+
+ public void draw(Canvas canvas) {
+ wasDrawn = true;
+ }
+
+ public void setAlpha(int alpha) {
+ }
+
+ public void setColorFilter(ColorFilter cf) {
+ }
+
+ public int getOpacity() {
+ return android.graphics.PixelFormat.UNKNOWN;
+ }
+ }
+
+}
diff --git a/graphics/tests/graphicstests/src/android/view/MockView.java b/graphics/tests/graphicstests/src/android/view/MockView.java
new file mode 100644
index 0000000..1d416bd
--- /dev/null
+++ b/graphics/tests/graphicstests/src/android/view/MockView.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2007 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.view;
+
+/**
+ * Mock View class for testing
+ */
+
+public class MockView extends View{
+
+}