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

Commit a87c3c0a authored by Doug Felt's avatar Doug Felt
Browse files

Fix 2566319, don't use package-protected members from Layout in test.

Change-Id: Ic3457e6857f03ba5550c5d82f22af2385a3c4b91
parent 75c66da2
Loading
Loading
Loading
Loading
+33 −23
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@

package android.text;

import android.test.suitebuilder.annotation.SmallTest;
import android.text.Layout.Directions;
import android.text.StaticLayoutTest.LayoutBuilder;
import android.util.Log;

import java.util.Arrays;
import java.util.Formatter;
@@ -33,9 +31,20 @@ public class StaticLayoutDirectionsTest extends TestCase {
        return new Directions(dirs);
    }

    private static final int LVL1_1 = 1 | (1 << Layout.RUN_LEVEL_SHIFT);
    private static final int LVL2_1 = 1 | (2 << Layout.RUN_LEVEL_SHIFT);
    private static final int LVL2_2 = 2 | (2 << Layout.RUN_LEVEL_SHIFT);
    // constants from Layout that are package-protected
    private static final int RUN_LENGTH_MASK = 0x03ffffff;
    private static final int RUN_LEVEL_SHIFT = 26;
    private static final int RUN_LEVEL_MASK = 0x3f;
    private static final int RUN_RTL_FLAG = 1 << RUN_LEVEL_SHIFT;

    private static final Directions DIRS_ALL_LEFT_TO_RIGHT =
        new Directions(new int[] { 0, RUN_LENGTH_MASK });
    private static final Directions DIRS_ALL_RIGHT_TO_LEFT =
        new Directions(new int[] { 0, RUN_LENGTH_MASK | RUN_RTL_FLAG });

    private static final int LVL1_1 = 1 | (1 << RUN_LEVEL_SHIFT);
    private static final int LVL2_1 = 1 | (2 << RUN_LEVEL_SHIFT);
    private static final int LVL2_2 = 2 | (2 << RUN_LEVEL_SHIFT);

    private static String[] texts = {
        "",
@@ -63,12 +72,12 @@ public class StaticLayoutDirectionsTest extends TestCase {
    // Expected directions are an array of start/length+level pairs,
    // in visual order from the leading margin.
    private static Directions[] expected = {
        Layout.DIRS_ALL_LEFT_TO_RIGHT,
        Layout.DIRS_ALL_LEFT_TO_RIGHT,
        Layout.DIRS_ALL_LEFT_TO_RIGHT,
        Layout.DIRS_ALL_LEFT_TO_RIGHT,
        DIRS_ALL_LEFT_TO_RIGHT,
        DIRS_ALL_LEFT_TO_RIGHT,
        DIRS_ALL_LEFT_TO_RIGHT,
        DIRS_ALL_LEFT_TO_RIGHT,
        dirs(0, 1, 1, LVL1_1),
        Layout.DIRS_ALL_LEFT_TO_RIGHT,
        DIRS_ALL_LEFT_TO_RIGHT,
        dirs(0, 2, 2, LVL1_1),
        dirs(0, 1, 2, LVL2_1, 1, LVL1_1),
        dirs(0, 1, 1, LVL1_1, 2, 1),
@@ -76,7 +85,7 @@ public class StaticLayoutDirectionsTest extends TestCase {
        dirs(0, 1, 4, LVL2_1, 3, LVL1_1, 2, LVL2_1, 1, LVL1_1),

        // rtl
        Layout.DIRS_ALL_RIGHT_TO_LEFT,
        DIRS_ALL_RIGHT_TO_LEFT,
        dirs(0, LVL1_1, 1, LVL2_1),
        dirs(0, LVL1_1, 1, LVL2_1),
        dirs(0, LVL1_1, 1, LVL2_1, 2, LVL1_1),
@@ -167,6 +176,7 @@ public class StaticLayoutDirectionsTest extends TestCase {
    }

    // utility, not really a test
    /*
    public void testMeasureText1() {
        LayoutBuilder b = StaticLayoutTest.builder();
        String text = "ABC"; // "abAB"
@@ -196,8 +206,8 @@ public class StaticLayoutDirectionsTest extends TestCase {
                }
            } while (!trailing);
        } while (dir > 0);
        
    }
    */

    // utility for displaying arrays in hex
    private static String hexArray(int[] array) {