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

Commit 9b6f0e6e authored by Andrei Stingaceanu's avatar Andrei Stingaceanu Committed by android-build-merger
Browse files

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

am: e0857a58

Change-Id: I295b78a4397bb6409eef1963362b766c0ea78640
parents 411b7d9b e0857a58
Loading
Loading
Loading
Loading
+28 −4
Original line number Original line Diff line number Diff line
@@ -16,17 +16,26 @@


package android.text;
package android.text;


import junit.framework.TestCase;

import static android.text.Layout.Alignment.ALIGN_NORMAL;
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.
 * 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 DynamicLayout dl = new DynamicLayout("", new TextPaint(), 0, ALIGN_NORMAL, 0, 0, false);
    private static final int ___ = DynamicLayout.INVALID_BLOCK_INDEX;
    private static final int ___ = DynamicLayout.INVALID_BLOCK_INDEX;


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


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


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


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


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


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


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


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


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


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


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


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


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


    @Test
    public void testFrom2ReplaceFromFirstBlock() {
    public void testFrom2ReplaceFromFirstBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });
        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[] { ___, ___ } );
        assertState( new int[] { 3, 50 }, new int[] { ___, ___ } );
    }
    }


    @Test
    public void testFrom2ReplaceFromBottomBoundary() {
    public void testFrom2ReplaceFromBottomBoundary() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });
        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[] { ___, ___ } );
        assertState( new int[] { 10, 50 }, new int[] { ___, ___ } );
    }
    }


    @Test
    public void testFrom2ReplaceFromTopBoundary() {
    public void testFrom2ReplaceFromTopBoundary() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });
        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, ___ } );
        assertState( new int[] { 11, 50 }, new int[] { 123, ___ } );
    }
    }


    @Test
    public void testFrom2ReplaceFromSecondBlock() {
    public void testFrom2ReplaceFromSecondBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });
        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, ___, ___ } );
        assertState( new int[] { 11, 14-11, 50 }, new int[] { 123, ___, ___ } );
    }
    }


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


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


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


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


    @Test
    public void testFrom2RemoveFromSecondBlock() {
    public void testFrom2RemoveFromSecondBlock() {
        defineInitialState( new int[] { 10, 20 }, new int[] { 123, 456 });
        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, ___ } );
        assertState( new int[] { 11, 14-11 }, new int[] { 123, ___ } );
    }
    }


    @Test
    public void testFrom3ReplaceFromFirstBlock() {
    public void testFrom3ReplaceFromFirstBlock() {
        defineInitialState( new int[] { 10, 30, 60 }, new int[] { 123, 456, 789 });
        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[] { ___, ___ } );
        assertState( new int[] { 3, 50 }, new int[] { ___, ___ } );
    }
    }


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


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


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

import static org.junit.Assert.assertFalse;
import android.graphics.Canvas;
import static org.junit.Assert.assertNotNull;
import android.graphics.Paint;
import static org.junit.Assert.assertNull;
import android.graphics.Paint.FontMetricsInt;
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 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;
    private static final int WIDTH = 10000;


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



    @Test
    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) {
        }
    }

    public void testGetBlocksAlwaysNeedToBeRedrawn_replacementSpan() {
    public void testGetBlocksAlwaysNeedToBeRedrawn_replacementSpan() {
        final SpannableStringBuilder builder = new SpannableStringBuilder();
        final SpannableStringBuilder builder = new SpannableStringBuilder();
        final DynamicLayout layout = new DynamicLayout(builder, new TextPaint(), WIDTH,
        final DynamicLayout layout = new DynamicLayout(builder, new TextPaint(), WIDTH,
@@ -66,11 +66,17 @@ public class DynamicLayoutTest extends TestCase {
        builder.append("hijk lmn\n");
        builder.append("hijk lmn\n");
        assertNull(layout.getBlocksAlwaysNeedToBeRedrawn());
        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());
        assertNotNull(layout.getBlocksAlwaysNeedToBeRedrawn());
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(0));
        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(0));
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(1));
        assertTrue(layout.getBlocksAlwaysNeedToBeRedrawn().contains(1));


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


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


package android.text;
package android.text;


import static org.junit.Assert.assertEquals;

import android.support.test.filters.SmallTest;
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.
 * PackedIntVectorTest tests the features of android.util.PackedIntVector.
 */
 */
public class PackedIntVectorTest extends TestCase {

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

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


package android.text;
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.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);
    protected abstract Spannable newSpannableWithText(String text);


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


package android.text;
package android.text;


import static org.junit.Assert.assertEquals;

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


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


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


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


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


    @SmallTest
    @Test
    public void testAppend() throws Exception {
    public void testAppend() {
        Object o = new Object();
        Object o = new Object();
        SpannableString ss = new SpannableString("Test");
        SpannableString ss = new SpannableString("Test");
        ss.setSpan(o, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        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);
        assertEquals(1, ssb.getSpans(4, 8, Object.class).length);
    }
    }


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


        public void onSpanChanged(Spannable b, Object o, int s, int e,
        @Override
                                  int st, int en) { }
        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) { }
        public void onSpanRemoved(Spannable b, Object o, int s, int e) { }


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


        public void beforeTextChanged(CharSequence s, int start, int count,
        @Override
                                      int after) { }
        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 onTextChanged(CharSequence s, int start, int before, int count) {
            if (mExpect != 0) {
            if (mExpect != 0) {
                assertEquals(mSequence, mExpect);
                assertEquals(mSequence, mExpect);
                mExpect = mSequence - 1;
                mExpect = mSequence - 1;
            }
            }
        }
        }


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