RESTRICT AUTOMERGE
Add CTS for Unicode spaces and line breaking
Bug: 140755449
Bug: 140453862
Bug: 140632678
Test: adb install -r out/host/linux-x86/cts/android-cts/testcases/CtsTextTestCases.apk
adb shell am instrument -w android.text.cts/android.support.test.runner.AndroidJUnitRunner
Change-Id: Ib304a347187d050f22967b87603863e4a1d1910f
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
index 1c5bcba..d1b7fc1 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
@@ -22,6 +22,8 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
import android.graphics.Typeface;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
@@ -1190,4 +1192,32 @@
.setEllipsize(TruncateAt.END).build();
layout.getPrimaryHorizontal(layout.getText().length());
}
+
+ // This is for b/140755449
+ @Test
+ public void testBidiVisibleEnd() {
+ TextPaint paint = new TextPaint();
+ // The default text size is too small and not useful for handling line breaks.
+ // Make it bigger.
+ paint.setTextSize(32);
+
+ final String input = "\u05D0aaaaaa\u3000 aaaaaa";
+ // To make line break happen, pass slightly shorter width from the full text width.
+ final int lineBreakWidth = (int) (paint.measureText(input) * 0.8);
+ final StaticLayout layout = StaticLayout.Builder.obtain(
+ input, 0, input.length(), paint, lineBreakWidth).build();
+
+ // Make sure getLineMax won't cause crashes.
+ // getLineMax eventually calls TextLine.measure which was the problematic method.
+ layout.getLineMax(0);
+
+ final Bitmap bmp = Bitmap.createBitmap(
+ layout.getWidth(),
+ layout.getHeight(),
+ Bitmap.Config.RGB_565);
+ final Canvas c = new Canvas(bmp);
+ // Make sure draw won't cause crashes.
+ // draw eventualy calls TextLine.draw which was the problematic method.
+ layout.draw(c);
+ }
}