Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0857a58 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move text coretests to JUnit (1)" into oc-dev

parents 2b0d0671 e1a7d0d7
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -16,17 +16,26 @@

package android.text;

import junit.framework.TestCase;

import static android.text.Layout.Alignment.ALIGN_NORMAL;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Tests DynamciLayout updateBlocks method.
 * Tests DynamicLayout updateBlocks method.
 *
 * Requires disabling access checks in the vm since this calls package-private APIs.
 *
 */
public class DynamicLayoutBlocksTest extends TestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class DynamicLayoutBlocksTest {
    private DynamicLayout dl = new DynamicLayout("", new TextPaint(), 0, ALIGN_NORMAL, 0, 0, false);
    private static final int ___ = DynamicLayout.INVALID_BLOCK_INDEX;

@@ -88,6 +97,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState(sizes, ids);
    }

    @Test
    public void testFrom0() {
        defineInitialState( new int[] { 0 }, new int[] { 123 });

@@ -101,6 +111,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 10 } );
    }

    @Test
    public void testFrom1ReplaceByEmpty() {
        defineInitialState( new int[] { 100 }, new int[] { 123 });

@@ -126,6 +137,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 100 } );
    }

    @Test
    public void testFrom1ReplaceFromFirstLine() {
        defineInitialState( new int[] { 100 }, new int[] { 123 });

@@ -142,6 +154,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 20 } );
    }

    @Test
    public void testFrom1ReplaceFromCenter() {
        defineInitialState( new int[] { 100 }, new int[] { 123 });

@@ -158,6 +171,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 20, 50 } );
    }

    @Test
    public void testFrom1ReplaceFromEnd() {
        defineInitialState( new int[] { 100 }, new int[] { 123 });

@@ -171,6 +185,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 100, 10 } );
    }

    @Test
    public void testFrom2ReplaceFromFirstLine() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -187,6 +202,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 50 }, new int[] { ___ } );
    }

    @Test
    public void testFrom2ReplaceFromFirstBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -203,6 +219,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 3, 50 }, new int[] { ___, ___ } );
    }

    @Test
    public void testFrom2ReplaceFromBottomBoundary() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -216,6 +233,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 10, 50 }, new int[] { ___, ___ } );
    }

    @Test
    public void testFrom2ReplaceFromTopBoundary() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -229,6 +247,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 11, 50 }, new int[] { 123, ___ } );
    }

    @Test
    public void testFrom2ReplaceFromSecondBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -242,6 +261,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 11, 14-11, 50 }, new int[] { 123, ___, ___ } );
    }

    @Test
    public void testFrom2RemoveFromFirst() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -258,6 +278,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 0 }, new int[] { ___ } );
    }

    @Test
    public void testFrom2RemoveFromFirstBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -274,6 +295,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 4 }, new int[] { ___ } );
    }

    @Test
    public void testFrom2RemoveFromSecondBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });

@@ -284,6 +306,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 11, 14-11 }, new int[] { 123, ___ } );
    }

    @Test
    public void testFrom3ReplaceFromFirstBlock() {
        defineInitialState( new int[] { 10, 30, 60 }, new int[] { 123, 456, 789 });

@@ -306,6 +329,7 @@ public class DynamicLayoutBlocksTest extends TestCase {
        assertState( new int[] { 3, 50 }, new int[] { ___, ___ } );
    }

    @Test
    public void testFrom3ReplaceFromSecondBlock() {
        defineInitialState( new int[] { 10, 30, 60 }, new int[] { 123, 456, 789 });

+28 −21
Original line number Diff line number Diff line
@@ -17,16 +17,28 @@
package android.text;

import static android.text.Layout.Alignment.ALIGN_NORMAL;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.style.ReplacementSpan;
import junit.framework.TestCase;

public class DynamicLayoutTest extends TestCase {
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class DynamicLayoutTest {
    private static final int WIDTH = 10000;

    @Test
    public void testGetBlocksAlwaysNeedToBeRedrawn_en() {
        final SpannableStringBuilder builder = new SpannableStringBuilder();
        final DynamicLayout layout = new DynamicLayout(builder, new TextPaint(), WIDTH,
@@ -42,19 +54,7 @@ public class DynamicLayoutTest extends TestCase {
        assertNull(layout.getBlocksAlwaysNeedToBeRedrawn());
    }


    private static class MockReplacementSpan extends ReplacementSpan {
        @Override
        public int getSize(Paint paint, CharSequence text, int start, int end, FontMetricsInt fm) {
            return 10;
        }

        @Override
        public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
                int y, int bottom, Paint paint) {
        }
    }

    @Test
    public void testGetBlocksAlwaysNeedToBeRedrawn_replacementSpan() {
        final SpannableStringBuilder builder = new SpannableStringBuilder();
        final DynamicLayout layout = new DynamicLayout(builder, new TextPaint(), WIDTH,
@@ -66,11 +66,17 @@ public class DynamicLayoutTest extends TestCase {
        builder.append("hijk lmn\n");
        assertNull(layout.getBlocksAlwaysNeedToBeRedrawn());

        builder.setSpan(new MockReplacementSpan(), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ReplacementSpan mockReplacementSpan = mock(ReplacementSpan.class);
        when(mockReplacementSpan.getSize(any(), any(), any(), any(), any()))
            .thenReturn(10);
        doNothing().when(mockReplacementSpan)
            .draw(any(), any(), any(), any(), any(), any(), any(), any(), any());

        builder.setSpan(mockReplacementSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        assertNotNull(layout.getBlocksAlwaysNeedToBeRedrawn());
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(0));

        builder.setSpan(new MockReplacementSpan(), 9, 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(mockReplacementSpan, 9, 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(0));
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(1));

@@ -83,6 +89,7 @@ public class DynamicLayoutTest extends TestCase {
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().isEmpty());
    }

    @Test
    public void testGetBlocksAlwaysNeedToBeRedrawn_thai() {
        final SpannableStringBuilder builder = new SpannableStringBuilder();
        final DynamicLayout layout = new DynamicLayout(builder, new TextPaint(), WIDTH,
+10 −4
Original line number Diff line number Diff line
@@ -16,17 +16,23 @@

package android.text;

import static org.junit.Assert.assertEquals;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * PackedIntVectorTest tests the features of android.util.PackedIntVector.
 */
public class PackedIntVectorTest extends TestCase {

@SmallTest
    public void testBasic() throws Exception {
@RunWith(AndroidJUnit4.class)
public class PackedIntVectorTest {

    @Test
    public void testBasic() {
        for (int width = 0; width < 10; width++) {
            PackedIntVector p = new PackedIntVector(width);
            int[] ins = new int[width];
+9 −4
Original line number Diff line number Diff line
@@ -16,15 +16,20 @@

package android.text;

import android.test.InstrumentationTestCase;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.MediumTest;

public abstract class SpannableTest extends InstrumentationTestCase {
import org.junit.Test;
import org.junit.runner.RunWith;

@MediumTest
@RunWith(AndroidJUnit4.class)
public abstract class SpannableTest {

    protected abstract Spannable newSpannableWithText(String text);

    @MediumTest
    @Test
    public void testGetSpans() {
        Spannable spannable = newSpannableWithText("abcdef");
        Object emptySpan = new Object();
+30 −19
Original line number Diff line number Diff line
@@ -16,34 +16,40 @@

package android.text;

import static org.junit.Assert.assertEquals;

import android.graphics.Typeface;
import android.os.Parcel;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.style.CharacterStyle;
import android.text.style.StyleSpan;
import android.text.style.TextAppearanceSpan;
import android.text.style.TypefaceSpan;

import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * SpannedTest tests some features of Spanned
 */
public class SpannedTest extends TestCase {
@SmallTest
@RunWith(AndroidJUnit4.class)
public class SpannedTest {
    private int mExpect;

    @SmallTest
    public void testSpannableString() throws Exception {
    @Test
    public void testSpannableString() {
        checkPriority(new SpannableString("the quick brown fox"));
    }

    @SmallTest
    public void testSpannableStringBuilder() throws Exception {
    @Test
    public void testSpannableStringBuilder() {
        checkPriority2(new SpannableStringBuilder("the quick brown fox"));
    }

    @SmallTest
    public void testAppend() throws Exception {
    @Test
    public void testAppend() {
        Object o = new Object();
        SpannableString ss = new SpannableString("Test");
        ss.setSpan(o, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
@@ -61,7 +67,7 @@ public class SpannedTest extends TestCase {
        assertEquals(1, ssb.getSpans(4, 8, Object.class).length);
    }

    @SmallTest
    @Test
    public void testWrapParcel() {
        SpannableString s = new SpannableString("Hello there world");
        CharacterStyle mark = new StyleSpan(Typeface.BOLD);
@@ -162,10 +168,13 @@ public class SpannedTest extends TestCase {
            mSequence = sequence;
        }

        public void onSpanChanged(Spannable b, Object o, int s, int e,
                                  int st, int en) { }
        @Override
        public void onSpanChanged(Spannable b, Object o, int s, int e, int st, int en) { }

        @Override
        public void onSpanRemoved(Spannable b, Object o, int s, int e) { }

        @Override
        public void onSpanAdded(Spannable b, Object o, int s, int e) {
            if (mExpect != 0) {
                assertEquals(mSequence, mExpect);
@@ -173,16 +182,18 @@ public class SpannedTest extends TestCase {
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) { }
        public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mExpect != 0) {
                assertEquals(mSequence, mExpect);
                mExpect = mSequence - 1;
            }
        }

        @Override
        public void afterTextChanged(Editable s) { }
    }
}
Loading