1. Generalplus Technology Inc.
  2. Untitled project
  3. android_cts

Commits

Scott Su <>  committed 415a96a

AI 145020: CTS: add test case for URLSpan, TypefaceSpan and UnderlineSpan

Automated import of CL 145020

  • Participants
  • Parent commits e86a2ed
  • Branches master

Comments (0)

Files changed (7)

File tests/AndroidManifest.xml

View file
             </intent-filter>
         </activity>
 
+        <activity android:name="android.text.style.cts.URLSpanStubActivity"
+            android:label="URLSpanStubActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name="android.text.style.cts.MockURLSpanTestActivity"
+            android:label="MockURLSpanTestActivity"
+            android:launchMode="singleTask"
+            android:alwaysRetainTaskState="true"
+            android:configChanges="orientation|keyboardHidden">
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+                <data android:scheme="ctstest" />
+            </intent-filter>
+        </activity>
+
     </application>
 
 </manifest>

File tests/res/layout/urlspan_layout.xml

View file
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * 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.
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical">
+
+    <TextView android:id="@+id/url"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:paddingLeft="4dip"
+        android:focusable="true"
+        android:focusableInTouchMode="true"
+        android:text="@string/text_view_hello"/>
+
+</LinearLayout>

File tests/src/android/text/style/cts/MockURLSpanTestActivity.java

View file
+/*
+ * Copyright (C) 2009 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 com.android.cts.stub.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * A Mock application for {@link URLSpan} test.
+ */
+public class MockURLSpanTestActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.urlspan_layout);
+    }
+}

File tests/src/android/text/style/cts/URLSpanStubActivity.java

View file
+/*
+ * 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 com.android.cts.stub.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * A minimal application for {@link URLSpan} test.
+ */
+public class URLSpanStubActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.urlspan_layout);
+    }
+}

File tests/tests/text/src/android/text/style/cts/TypefaceSpanTest.java

View file
+/*
+ * 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.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+import android.graphics.Typeface;
+import android.os.Parcel;
+import android.text.TextPaint;
+import android.text.style.TypefaceSpan;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(TypefaceSpan.class)
+public class TypefaceSpanTest extends TestCase {
+    private static final String FAMILY = "monospace";
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of TypefaceSpan.",
+            method = "TypefaceSpan",
+            args = {java.lang.String.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of TypefaceSpan.",
+            method = "TypefaceSpan",
+            args = {android.os.Parcel.class}
+        )
+    })
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testConstructor() {
+        TypefaceSpan t = new TypefaceSpan(FAMILY);
+
+        final Parcel p = Parcel.obtain();
+        t.writeToParcel(p, 0);
+        p.setDataPosition(0);
+        new TypefaceSpan(p);
+        p.recycle();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test getFamily().",
+        method = "getFamily",
+        args = {}
+    )
+    public void testGetFamily() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+        assertEquals(FAMILY, typefaceSpan.getFamily());
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test updateMeasureState(TextPaint paint).",
+        method = "updateMeasureState",
+        args = {android.text.TextPaint.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "should add @throws NullPointerException clause" +
+            " into javadoc when input TextPaint is null")
+    public void testUpdateMeasureState() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+
+        TextPaint tp = new TextPaint();
+        assertNull(tp.getTypeface());
+
+        typefaceSpan.updateMeasureState(tp);
+
+        assertNotNull(tp.getTypeface());
+        // the style should be default style.
+        assertEquals(Typeface.NORMAL, tp.getTypeface().getStyle());
+
+        try {
+            typefaceSpan.updateMeasureState(null);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected, test success.
+        }
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test updateDrawState(TextPaint ds).",
+        method = "updateDrawState",
+        args = {android.text.TextPaint.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "should add @throws NullPointerException clause" +
+            " into javadoc when input TextPaint is null")
+    public void testUpdateDrawState() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+
+        TextPaint tp = new TextPaint();
+        assertNull(tp.getTypeface());
+
+        typefaceSpan.updateDrawState(tp);
+
+        assertNotNull(tp.getTypeface());
+        // the style should be default style.
+        assertEquals(Typeface.NORMAL, tp.getTypeface().getStyle());
+
+        try {
+            typefaceSpan.updateDrawState(null);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected, test success.
+        }
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test describeContents().",
+        method = "describeContents",
+        args = {}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testDescribeContents() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+        typefaceSpan.describeContents();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test getSpanTypeId().",
+        method = "getSpanTypeId",
+        args = {}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testGetSpanTypeId() {
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+        typefaceSpan.getSpanTypeId();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test writeToParcel(Parcel dest, int flags).",
+        method = "writeToParcel",
+        args = {Parcel.class, int.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testWriteToParcel() {
+        Parcel p = Parcel.obtain();
+        TypefaceSpan typefaceSpan = new TypefaceSpan(FAMILY);
+        typefaceSpan.writeToParcel(p, 0);
+        p.setDataPosition(0);
+        TypefaceSpan t = new TypefaceSpan(p);
+        assertEquals(FAMILY, t.getFamily());
+        p.recycle();
+    }
+}

File tests/tests/text/src/android/text/style/cts/URLSpanTest.java

View file
+/*
+ * 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 com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.app.Instrumentation.ActivityMonitor;
+import android.os.Parcel;
+import android.test.ActivityInstrumentationTestCase2;
+import android.text.style.URLSpan;
+import android.widget.TextView;
+
+@TestTargetClass(URLSpan.class)
+public class URLSpanTest extends ActivityInstrumentationTestCase2<URLSpanStubActivity> {
+    // The scheme of TEST_URL must be "ctstest" to launch MockURLSpanTestActivity
+    private static final String TEST_URL = "ctstest://urlSpan/test";
+    private Activity mActivity;
+
+    public URLSpanTest() {
+        super("com.android.cts.stub", URLSpanStubActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of URLSpan.",
+            method = "URLSpan",
+            args = {java.lang.String.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of URLSpan.",
+            method = "URLSpan",
+            args = {android.os.Parcel.class}
+        )
+    })
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testConstructor() {
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+
+        final Parcel p = Parcel.obtain();
+        urlSpan.writeToParcel(p, 0);
+        p.setDataPosition(0);
+        new URLSpan(p);
+        p.recycle();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test getURL().",
+        method = "getURL",
+        args = {}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testGetURL() {
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+        assertEquals(TEST_URL, urlSpan.getURL());
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test onClick(View widget).",
+        method = "onClick",
+        args = {android.view.View.class}
+    )
+    public void testOnClick() {
+        final URLSpan urlSpan = new URLSpan(TEST_URL);
+        final TextView textView = (TextView) mActivity.findViewById(R.id.url);
+
+        Instrumentation instrumentation = getInstrumentation();
+        ActivityMonitor am = instrumentation.addMonitor(MockURLSpanTestActivity.class.getName(),
+                null, false);
+
+        try {
+            runTestOnUiThread(new Runnable() {
+                public void run() {
+                    urlSpan.onClick(textView);
+                }
+            });
+        } catch (Throwable e) {
+            fail("Exception error!");
+        }
+
+        Activity newActivity = am.waitForActivityWithTimeout(5000);
+        assertNotNull(newActivity);
+        newActivity.finish();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test onClick(View widget).",
+        method = "onClick",
+        args = {android.view.View.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "should add @throws NullPointerException clause" +
+            " into javadoc when input View is null")
+    public void testOnClickFailure() {
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+
+        try {
+            urlSpan.onClick(null);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected, test success.
+        }
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test describeContents().",
+        method = "describeContents",
+        args = {}
+    )
+    public void testDescribeContents() {
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+        urlSpan.describeContents();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test getSpanTypeId().",
+        method = "getSpanTypeId",
+        args = {}
+    )
+    public void testGetSpanTypeId() {
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+        urlSpan.getSpanTypeId();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test writeToParcel(Parcel dest, int flags).",
+        method = "writeToParcel",
+        args = {Parcel.class, int.class}
+    )
+    public void testWriteToParcel() {
+        Parcel p = Parcel.obtain();
+        URLSpan urlSpan = new URLSpan(TEST_URL);
+        urlSpan.writeToParcel(p, 0);
+        p.setDataPosition(0);
+        URLSpan u = new URLSpan(p);
+        assertEquals(TEST_URL, u.getURL());
+        p.recycle();
+    }
+}

File tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java

View file
+/*
+ * 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.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
+import android.os.Parcel;
+import android.text.TextPaint;
+import android.text.style.UnderlineSpan;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(UnderlineSpan.class)
+public class UnderlineSpanTest extends TestCase {
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of UnderlineSpan.",
+            method = "UnderlineSpan",
+            args = {}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            notes = "Test constructor(s) of UnderlineSpan.",
+            method = "UnderlineSpan",
+            args = {android.os.Parcel.class}
+        )
+    })
+    @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
+    public void testConstructor() {
+        new UnderlineSpan();
+
+        final Parcel p = Parcel.obtain();
+        new UnderlineSpan(p);
+        p.recycle();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test {@link UnderlineSpan#updateDrawState(TextPaint)}",
+        method = "updateDrawState",
+        args = {android.text.TextPaint.class}
+    )
+    @ToBeFixed(bug = "1695243", explanation = "should add @throws NullPointerException clause" +
+        " into javadoc when input TextPaint is null")
+    public void testUpdateDrawState() {
+        UnderlineSpan underlineSpan = new UnderlineSpan();
+
+        TextPaint tp = new TextPaint();
+        tp.setUnderlineText(false);
+        assertFalse(tp.isUnderlineText());
+
+        underlineSpan.updateDrawState(tp);
+        assertTrue(tp.isUnderlineText());
+
+        try {
+            underlineSpan.updateDrawState(null);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+            // expected, test success.
+        }
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test describeContents().",
+        method = "describeContents",
+        args = {}
+    )
+    public void testDescribeContents() {
+        UnderlineSpan underlineSpan = new UnderlineSpan();
+        underlineSpan.describeContents();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test getSpanTypeId().",
+        method = "getSpanTypeId",
+        args = {}
+    )
+    public void testGetSpanTypeId() {
+        UnderlineSpan underlineSpan = new UnderlineSpan();
+        underlineSpan.getSpanTypeId();
+    }
+
+    @TestTargetNew(
+        level = TestLevel.COMPLETE,
+        notes = "Test writeToParcel(Parcel dest, int flags).",
+        method = "writeToParcel",
+        args = {Parcel.class, int.class}
+    )
+    public void testWriteToParcel() {
+        Parcel p = Parcel.obtain();
+        UnderlineSpan underlineSpan = new UnderlineSpan();
+        underlineSpan.writeToParcel(p, 0);
+        new UnderlineSpan(p);
+        p.recycle();
+    }
+}