Anonymous avatar Anonymous committed 735530d

AI 145022: CTS: add test cases for android.text.style.CharacterStyle and ClickableSpan

Automated import of CL 145022

Comments (0)

Files changed (2)

tests/tests/text/src/android/text/style/cts/CharacterStyleTest.java

+/*
+ * Copyright (C) 2008 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.text.style.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
+import android.text.TextPaint;
+import android.text.style.CharacterStyle;
+import android.text.style.MetricAffectingSpan;
+import android.text.style.SuperscriptSpan;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(CharacterStyle.class)
+public class CharacterStyleTest extends TestCase {
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test {@link CharacterStyle#wrap(CharacterStyle)}",
+        method = "wrap",
+        args = {android.text.style.CharacterStyle.class}
+    )
+    public void testWrap() {
+        // use a MetricAffectingSpan
+        MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan();
+
+        CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan);
+        assertNotNull(result);
+        assertSame(metricAffectingSpan, result.getUnderlying());
+        assertNotSame(metricAffectingSpan, result);
+
+        // use a no-MetricAffectingSpan
+        CharacterStyle characterStyle = new MyCharacterStyle();
+        result = CharacterStyle.wrap(characterStyle);
+        assertNotNull(result);
+        assertTrue(result instanceof CharacterStyle);
+        assertSame(characterStyle, result.getUnderlying());
+        assertNotSame(characterStyle, result);
+
+        result = CharacterStyle.wrap((MetricAffectingSpan) null);
+        assertNotNull(result);
+        assertTrue(result instanceof CharacterStyle);
+
+        result = CharacterStyle.wrap((CharacterStyle) null);
+        assertNotNull(result);
+        assertTrue(result instanceof CharacterStyle);
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test {@link CharacterStyle#getUnderlying()}",
+        method = "getUnderlying",
+        args = {}
+    )
+    public void testGetUnderlying() {
+        CharacterStyle expected = new MyCharacterStyle();
+        assertSame(expected, expected.getUnderlying());
+
+        MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan();
+        CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan);
+        assertNotNull(result);
+        assertTrue(result instanceof MetricAffectingSpan);
+        assertSame(metricAffectingSpan, result.getUnderlying());
+    }
+
+    /**
+     * MyCharacterStyle for test.
+     */
+    private class MyCharacterStyle extends CharacterStyle {
+        @Override
+        public void updateDrawState(TextPaint tp) {
+            // implement abstract method.
+        }
+    }
+}

tests/tests/text/src/android/text/style/cts/ClickableSpanTest.java

+/*
+ * Copyright (C) 2008 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.text.style.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.ToBeFixed;
+
+import android.graphics.Color;
+import android.text.TextPaint;
+import android.text.style.ClickableSpan;
+import android.view.View;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(ClickableSpan.class)
+public class ClickableSpanTest extends TestCase {
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test {@link ClickableSpan#updateDrawState(TextPaint)}",
+        method = "updateDrawState",
+        args = {android.text.TextPaint.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "should add @throws clause into javadoc of " +
+            "ClickableSpan#updateDrawState(TextPaint) when the input TextPaint is null")
+    public void testUpdateDrawState() {
+        ClickableSpan clickableSpan = new MyClickableSpan();
+
+        TextPaint tp = new TextPaint();
+        tp.linkColor = Color.RED;
+        tp.setUnderlineText(false);
+        assertFalse(tp.isUnderlineText());
+
+        clickableSpan.updateDrawState(tp);
+        assertEquals(Color.RED, tp.getColor());
+        assertTrue(tp.isUnderlineText());
+
+        tp.linkColor = Color.BLUE;
+        clickableSpan.updateDrawState(tp);
+        assertEquals(Color.BLUE, tp.getColor());
+        assertTrue(tp.isUnderlineText());
+
+        try {
+            clickableSpan.updateDrawState(null);
+            fail("should throw NullPointerException when TextPaint is null.");
+        } catch (NullPointerException e) {
+            // expected, test success.
+        }
+    }
+
+    /**
+     * MyClickableSpan for test.
+     */
+    private class MyClickableSpan extends ClickableSpan {
+        @Override
+        public void onClick(View widget) {
+            // implement abstract method.
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.