Move long string test from TextView to StaticLayoutTest

We need to test measurement of very long strings to exercise a
potential stack overflow (bug 13506939). As of M, changes to the text
stack meant that we were not actually exercising the method in
question. In addition, the test required a huge amount of memory,
which was causing problems on low-RAM devices. This patch moves the
test from TextViewTest to StaticLayoutTest (which is a more direct
invocation), and also changes the text string so that it can be
measured more quickly and with less memory than before.

Bug: 25806062
Change-Id: I450b35c18a0b99a8fdfd37218518d8d2e01c3c90
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
index c6f4049..329db88 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
@@ -59,6 +59,10 @@
     private StaticLayout mDefaultLayout;
     private TextPaint mDefaultPaint;
 
+    private class TestingTextPaint extends TextPaint {
+        // need to have a subclass to insure measurement happens in Java and not C++
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -975,4 +979,18 @@
             assertEquals(testLabel, 6, layout.getOffsetToRightOf(7));
         }
     }
+
+    public void testVeryLargeString() {
+        final int MAX_COUNT = 1 << 21;
+        final int WORD_SIZE = 32;
+        char[] longText = new char[MAX_COUNT];
+        for (int n = 0; n < MAX_COUNT; n++) {
+            longText[n] = (n % WORD_SIZE) == 0 ? ' ' : 'm';
+        }
+        String longTextString = new String(longText);
+        TextPaint paint = new TestingTextPaint();
+        StaticLayout layout = new StaticLayout(longTextString, paint, DEFAULT_OUTER_WIDTH,
+                DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, true);
+        assertNotNull(layout);
+    }
 }
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 01938c2..829171c 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -3512,21 +3512,6 @@
         assertEquals(1, mTextView.getImeActionId());
     }
 
-    public void testSetTextLong() {
-        mActivity.runOnUiThread(new Runnable() {
-            public void run() {
-                final int MAX_COUNT = 1 << 21;
-                char[] longText = new char[MAX_COUNT];
-                for (int n = 0; n < MAX_COUNT; n++) {
-                    longText[n] = 'm';
-                }
-                mTextView = findTextView(R.id.textview_text);
-                mTextView.setText(new String(longText));
-            }
-        });
-        mInstrumentation.waitForIdleSync();
-    }
-
     @UiThreadTest
     public void testSetExtractedText() {
         mTextView = findTextView(R.id.textview_text);