diff --git a/graphics/tests/graphicstests/res/color/color1.xml b/core/tests/coretests/res/color/color1.xml similarity index 100% rename from graphics/tests/graphicstests/res/color/color1.xml rename to core/tests/coretests/res/color/color1.xml diff --git a/graphics/tests/graphicstests/res/color/color_no_default.xml b/core/tests/coretests/res/color/color_no_default.xml similarity index 100% rename from graphics/tests/graphicstests/res/color/color_no_default.xml rename to core/tests/coretests/res/color/color_no_default.xml diff --git a/graphics/tests/graphicstests/res/drawable-nodpi/landscape.png b/core/tests/coretests/res/drawable-nodpi/landscape.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable-nodpi/landscape.png rename to core/tests/coretests/res/drawable-nodpi/landscape.png diff --git a/graphics/tests/graphicstests/res/drawable/test128x96.png b/core/tests/coretests/res/drawable/test128x96.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test128x96.png rename to core/tests/coretests/res/drawable/test128x96.png diff --git a/graphics/tests/graphicstests/res/drawable/test16x12.png b/core/tests/coretests/res/drawable/test16x12.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test16x12.png rename to core/tests/coretests/res/drawable/test16x12.png diff --git a/graphics/tests/graphicstests/res/drawable/test256x192.png b/core/tests/coretests/res/drawable/test256x192.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test256x192.png rename to core/tests/coretests/res/drawable/test256x192.png diff --git a/graphics/tests/graphicstests/res/drawable/test320x240.png b/core/tests/coretests/res/drawable/test320x240.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test320x240.png rename to core/tests/coretests/res/drawable/test320x240.png diff --git a/graphics/tests/graphicstests/res/drawable/test32x24.png b/core/tests/coretests/res/drawable/test32x24.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test32x24.png rename to core/tests/coretests/res/drawable/test32x24.png diff --git a/graphics/tests/graphicstests/res/drawable/test64x48.png b/core/tests/coretests/res/drawable/test64x48.png similarity index 100% rename from graphics/tests/graphicstests/res/drawable/test64x48.png rename to core/tests/coretests/res/drawable/test64x48.png diff --git a/core/tests/coretests/res/values/colors.xml b/core/tests/coretests/res/values/colors.xml index f881660249f25..f01af8421515a 100644 --- a/core/tests/coretests/res/values/colors.xml +++ b/core/tests/coretests/res/values/colors.xml @@ -23,4 +23,7 @@ #ff0000ff #ff00ff00 #ffffff00 + #ff00ff00 + #ffff0000 + #ff0000ff diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java b/core/tests/coretests/src/android/graphics/BitmapFactoryTest.java similarity index 100% rename from graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java rename to core/tests/coretests/src/android/graphics/BitmapFactoryTest.java index 09820efefedaa..e9e2a4d098f0c 100644 --- a/graphics/tests/graphicstests/src/android/graphics/BitmapFactoryTest.java +++ b/core/tests/coretests/src/android/graphics/BitmapFactoryTest.java @@ -19,11 +19,11 @@ package android.graphics; import android.os.ParcelFileDescriptor; import android.test.suitebuilder.annotation.SmallTest; +import junit.framework.TestCase; + import java.io.ByteArrayOutputStream; import java.io.FileDescriptor; -import junit.framework.TestCase; - public class BitmapFactoryTest extends TestCase { diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java b/core/tests/coretests/src/android/graphics/BitmapTest.java similarity index 99% rename from graphics/tests/graphicstests/src/android/graphics/BitmapTest.java rename to core/tests/coretests/src/android/graphics/BitmapTest.java index c2dbfd3659646..3666dddb0782e 100644 --- a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java +++ b/core/tests/coretests/src/android/graphics/BitmapTest.java @@ -17,6 +17,7 @@ package android.graphics; import android.test.suitebuilder.annotation.SmallTest; + import junit.framework.TestCase; diff --git a/graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java b/core/tests/coretests/src/android/graphics/ColorStateListTest.java similarity index 98% rename from graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java rename to core/tests/coretests/src/android/graphics/ColorStateListTest.java index eb1025c36c187..374d1421bdbc7 100644 --- a/graphics/tests/graphicstests/src/android/graphics/ColorStateListTest.java +++ b/core/tests/coretests/src/android/graphics/ColorStateListTest.java @@ -16,13 +16,13 @@ package android.graphics; -import com.android.frameworks.graphicstests.R; - -import android.content.res.Resources; import android.content.res.ColorStateList; +import android.content.res.Resources; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; +import com.android.frameworks.coretests.R; + /** * Tests of {@link android.graphics.ColorStateList} */ diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java b/core/tests/coretests/src/android/graphics/GraphicsPerformanceTests.java similarity index 98% rename from graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java rename to core/tests/coretests/src/android/graphics/GraphicsPerformanceTests.java index f60ac7bdb5e5c..164c1aa770bd6 100644 --- a/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java +++ b/core/tests/coretests/src/android/graphics/GraphicsPerformanceTests.java @@ -16,19 +16,15 @@ package android.graphics; -import junit.framework.Assert; import android.content.Context; import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Paint; import android.test.AndroidTestCase; import android.test.PerformanceTestCase; import android.test.suitebuilder.annotation.Suppress; -import android.util.Log; -import com.android.frameworks.graphicstests.R; +import com.android.frameworks.coretests.R; + +import junit.framework.Assert; /** * Graphics Performance Tests diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java b/core/tests/coretests/src/android/graphics/GraphicsTests.java similarity index 100% rename from graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java rename to core/tests/coretests/src/android/graphics/GraphicsTests.java diff --git a/core/tests/coretests/src/android/graphics/PaintTest.java b/core/tests/coretests/src/android/graphics/PaintTest.java index 2a3d463463c08..5811ca0fd2660 100644 --- a/core/tests/coretests/src/android/graphics/PaintTest.java +++ b/core/tests/coretests/src/android/graphics/PaintTest.java @@ -156,4 +156,213 @@ public class PaintTest extends InstrumentationTestCase { } } } + + public void testGetTextRunAdvances() { + { + // LTR + String text = "abcdef"; + assertGetTextRunAdvances(text, 0, text.length(), 0, text.length(), false, true); + assertGetTextRunAdvances(text, 1, text.length() - 1, 0, text.length(), false, false); + } + { + // RTL + final String text = + "\u0645\u0627\u0020\u0647\u064A\u0020\u0627\u0644\u0634" + + "\u0641\u0631\u0629\u0020\u0627\u0644\u0645\u0648\u062D" + + "\u062F\u0629\u0020\u064A\u0648\u0646\u064A\u0643\u0648" + + "\u062F\u061F"; + assertGetTextRunAdvances(text, 0, text.length(), 0, text.length(), true, true); + assertGetTextRunAdvances(text, 1, text.length() - 1, 0, text.length(), true, false); + } + } + + private void assertGetTextRunAdvances(String str, int start, int end, + int contextStart, int contextEnd, boolean isRtl, boolean compareWithOtherMethods) { + Paint p = new Paint(); + + final int count = end - start; + final float[][] advanceArrays = new float[4][count]; + + final float advance = p.getTextRunAdvances(str, start, end, contextStart, contextEnd, + isRtl, advanceArrays[0], 0); + + char chars[] = str.toCharArray(); + final float advance_c = p.getTextRunAdvances(chars, start, count, contextStart, + contextEnd - contextStart, isRtl, advanceArrays[1], 0); + assertEquals(advance, advance_c, 1.0f); + + for (int c = 1; c < count; ++c) { + final float firstPartAdvance = p.getTextRunAdvances(str, start, start + c, + contextStart, contextEnd, isRtl, advanceArrays[2], 0); + final float secondPartAdvance = p.getTextRunAdvances(str, start + c, end, + contextStart, contextEnd, isRtl, advanceArrays[2], c); + assertEquals(advance, firstPartAdvance + secondPartAdvance, 1.0f); + + + final float firstPartAdvance_c = p.getTextRunAdvances(chars, start, c, + contextStart, contextEnd - contextStart, isRtl, advanceArrays[3], 0); + final float secondPartAdvance_c = p.getTextRunAdvances(chars, start + c, + count - c, contextStart, contextEnd - contextStart, isRtl, + advanceArrays[3], c); + assertEquals(advance, firstPartAdvance_c + secondPartAdvance_c, 1.0f); + assertEquals(firstPartAdvance, firstPartAdvance_c, 1.0f); + assertEquals(secondPartAdvance, secondPartAdvance_c, 1.0f); + + for (int i = 1; i < advanceArrays.length; i++) { + for (int j = 0; j < count; j++) { + assertEquals(advanceArrays[0][j], advanceArrays[i][j], 1.0f); + } + } + + // Compare results with measureText, getRunAdvance, and getTextWidths. + if (compareWithOtherMethods && start == contextStart && end == contextEnd) { + assertEquals(advance, p.measureText(str, start, end), 1.0f); + assertEquals(advance, p.getRunAdvance( + str, start, end, contextStart, contextEnd, isRtl, end), 1.0f); + + final float[] widths = new float[count]; + p.getTextWidths(str, start, end, widths); + for (int i = 0; i < count; i++) { + assertEquals(advanceArrays[0][i], widths[i], 1.0f); + } + } + } + } + + public void testGetTextRunAdvances_invalid() { + Paint p = new Paint(); + String text = "test"; + + try { + p.getTextRunAdvances((String)null, 0, 0, 0, 0, false, null, 0); + fail("Should throw an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + } + + try { + p.getTextRunAdvances((CharSequence)null, 0, 0, 0, 0, false, null, 0); + fail("Should throw an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + } + + try { + p.getTextRunAdvances((char[])null, 0, 0, 0, 0, false, null, 0); + fail("Should throw an IllegalArgumentException."); + } catch (IllegalArgumentException e) { + } + + try { + p.getTextRunAdvances(text, 0, text.length(), 0, text.length(), false, + new float[text.length() - 1], 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + try { + p.getTextRunAdvances(text, 0, text.length(), 0, text.length(), false, + new float[text.length()], 1); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + // 0 > contextStart + try { + p.getTextRunAdvances(text, 0, text.length(), -1, text.length(), false, null, 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + // contextStart > start + try { + p.getTextRunAdvances(text, 0, text.length(), 1, text.length(), false, null, 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + // start > end + try { + p.getTextRunAdvances(text, 1, 0, 0, text.length(), false, null, 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + // end > contextEnd + try { + p.getTextRunAdvances(text, 0, text.length(), 0, text.length() - 1, false, null, 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + + // contextEnd > text.length + try { + p.getTextRunAdvances(text, 0, text.length(), 0, text.length() + 1, false, null, 0); + fail("Should throw an IndexOutOfBoundsException."); + } catch (IndexOutOfBoundsException e) { + } + } + + public void testMeasureTextBidi() { + Paint p = new Paint(); + { + String bidiText = "abc \u0644\u063A\u0629 def"; + p.setBidiFlags(Paint.BIDI_LTR); + float width = p.measureText(bidiText, 0, 4); + p.setBidiFlags(Paint.BIDI_RTL); + width += p.measureText(bidiText, 4, 7); + p.setBidiFlags(Paint.BIDI_LTR); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + { + String bidiText = "abc \u0644\u063A\u0629 def"; + p.setBidiFlags(Paint.BIDI_DEFAULT_LTR); + float width = p.measureText(bidiText, 0, 4); + width += p.measureText(bidiText, 4, 7); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + { + String bidiText = "abc \u0644\u063A\u0629 def"; + p.setBidiFlags(Paint.BIDI_FORCE_LTR); + float width = p.measureText(bidiText, 0, 4); + width += p.measureText(bidiText, 4, 7); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + { + String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; + p.setBidiFlags(Paint.BIDI_RTL); + float width = p.measureText(bidiText, 0, 4); + p.setBidiFlags(Paint.BIDI_LTR); + width += p.measureText(bidiText, 4, 7); + p.setBidiFlags(Paint.BIDI_RTL); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + { + String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; + p.setBidiFlags(Paint.BIDI_DEFAULT_RTL); + float width = p.measureText(bidiText, 0, 4); + width += p.measureText(bidiText, 4, 7); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + { + String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; + p.setBidiFlags(Paint.BIDI_FORCE_RTL); + float width = p.measureText(bidiText, 0, 4); + width += p.measureText(bidiText, 4, 7); + width += p.measureText(bidiText, 7, bidiText.length()); + assertEquals(width, p.measureText(bidiText), 1.0f); + } + } + + public void testSetGetWordSpacing() { + Paint p = new Paint(); + assertEquals(0.0f, p.getWordSpacing()); // The default value should be 0. + p.setWordSpacing(1.0f); + assertEquals(1.0f, p.getWordSpacing()); + p.setWordSpacing(-2.0f); + assertEquals(-2.0f, p.getWordSpacing()); + } } diff --git a/graphics/tests/graphicstests/src/android/graphics/PathTest.java b/core/tests/coretests/src/android/graphics/PathTest.java similarity index 99% rename from graphics/tests/graphicstests/src/android/graphics/PathTest.java rename to core/tests/coretests/src/android/graphics/PathTest.java index 96200bc099f9f..78e4959da92a6 100644 --- a/graphics/tests/graphicstests/src/android/graphics/PathTest.java +++ b/core/tests/coretests/src/android/graphics/PathTest.java @@ -17,6 +17,7 @@ package android.graphics; import android.test.suitebuilder.annotation.SmallTest; + import junit.framework.TestCase; diff --git a/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java b/core/tests/coretests/src/android/graphics/ThreadBitmapTest.java similarity index 97% rename from graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java rename to core/tests/coretests/src/android/graphics/ThreadBitmapTest.java index 84bdc5683ac6f..909a8d97df512 100644 --- a/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java +++ b/core/tests/coretests/src/android/graphics/ThreadBitmapTest.java @@ -16,10 +16,10 @@ package android.graphics; -import junit.framework.TestCase; -import android.graphics.Bitmap; import android.test.suitebuilder.annotation.LargeTest; +import junit.framework.TestCase; + public class ThreadBitmapTest extends TestCase { @Override diff --git a/graphics/tests/graphicstests/src/android/graphics/VariationParserTest.java b/core/tests/coretests/src/android/graphics/VariationParserTest.java similarity index 99% rename from graphics/tests/graphicstests/src/android/graphics/VariationParserTest.java rename to core/tests/coretests/src/android/graphics/VariationParserTest.java index c7a46a3697720..a2ead405b1bcf 100644 --- a/graphics/tests/graphicstests/src/android/graphics/VariationParserTest.java +++ b/core/tests/coretests/src/android/graphics/VariationParserTest.java @@ -18,9 +18,11 @@ package android.graphics; import android.test.suitebuilder.annotation.SmallTest; import android.text.FontConfig; -import java.util.List; + import junit.framework.TestCase; +import java.util.List; + public class VariationParserTest extends TestCase { diff --git a/graphics/tests/graphicstests/src/android/graphics/drawable/IconTest.java b/core/tests/coretests/src/android/graphics/drawable/IconTest.java similarity index 99% rename from graphics/tests/graphicstests/src/android/graphics/drawable/IconTest.java rename to core/tests/coretests/src/android/graphics/drawable/IconTest.java index d3e1a431c3099..cf132890d9676 100644 --- a/graphics/tests/graphicstests/src/android/graphics/drawable/IconTest.java +++ b/core/tests/coretests/src/android/graphics/drawable/IconTest.java @@ -26,14 +26,13 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; +import com.android.frameworks.coretests.R; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; -import java.lang.Override; -import java.util.Arrays; import java.util.ArrayList; - -import com.android.frameworks.graphicstests.R; +import java.util.Arrays; public class IconTest extends AndroidTestCase { public static final String TAG = IconTest.class.getSimpleName(); diff --git a/graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java b/core/tests/coretests/src/android/graphics/drawable/StateListDrawableTest.java similarity index 100% rename from graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java rename to core/tests/coretests/src/android/graphics/drawable/StateListDrawableTest.java index 0d9f72e87cebd..03a9c25229844 100644 --- a/graphics/tests/graphicstests/src/android/graphics/drawable/StateListDrawableTest.java +++ b/core/tests/coretests/src/android/graphics/drawable/StateListDrawableTest.java @@ -16,14 +16,14 @@ package android.graphics.drawable; -import junit.framework.TestCase; - import android.R; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.util.StateSet; import android.view.MockView; +import junit.framework.TestCase; + /** * Tests for StateListDrawable * diff --git a/graphics/tests/graphicstests/src/android/view/MockView.java b/core/tests/coretests/src/android/view/MockView.java similarity index 100% rename from graphics/tests/graphicstests/src/android/view/MockView.java rename to core/tests/coretests/src/android/view/MockView.java diff --git a/graphics/tests/graphicstests/Android.mk b/graphics/tests/graphicstests/Android.mk deleted file mode 100644 index 8ea44bdb7966b..0000000000000 --- a/graphics/tests/graphicstests/Android.mk +++ /dev/null @@ -1,15 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -# We only want this apk build for tests. -LOCAL_MODULE_TAGS := tests - -# Include all test java files. -LOCAL_SRC_FILES := $(call all-java-files-under, src) - -LOCAL_JAVA_LIBRARIES := android.test.runner -LOCAL_STATIC_JAVA_LIBRARIES := junit legacy-android-test -LOCAL_PACKAGE_NAME := FrameworksGraphicsTests - -include $(BUILD_PACKAGE) - diff --git a/graphics/tests/graphicstests/AndroidManifest.xml b/graphics/tests/graphicstests/AndroidManifest.xml deleted file mode 100644 index e019e2806a941..0000000000000 --- a/graphics/tests/graphicstests/AndroidManifest.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/graphics/tests/graphicstests/res/values/colors.xml b/graphics/tests/graphicstests/res/values/colors.xml deleted file mode 100644 index 7559e6580793d..0000000000000 --- a/graphics/tests/graphicstests/res/values/colors.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - #ff00ff00 - #ffff0000 - #ff0000ff - - diff --git a/graphics/tests/graphicstests/src/android/graphics/PaintTest.java b/graphics/tests/graphicstests/src/android/graphics/PaintTest.java deleted file mode 100644 index 318bfb6bfd39e..0000000000000 --- a/graphics/tests/graphicstests/src/android/graphics/PaintTest.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.graphics; - -import android.test.AndroidTestCase; - -public class PaintTest extends AndroidTestCase { - public void testGetTextRunAdvances() { - { - // LTR - String text = "abcdef"; - assertGetTextRunAdvances(text, 0, text.length(), 0, text.length(), false, true); - assertGetTextRunAdvances(text, 1, text.length() - 1, 0, text.length(), false, false); - } - { - // RTL - final String text = - "\u0645\u0627\u0020\u0647\u064A\u0020\u0627\u0644\u0634" + - "\u0641\u0631\u0629\u0020\u0627\u0644\u0645\u0648\u062D" + - "\u062F\u0629\u0020\u064A\u0648\u0646\u064A\u0643\u0648" + - "\u062F\u061F"; - assertGetTextRunAdvances(text, 0, text.length(), 0, text.length(), true, true); - assertGetTextRunAdvances(text, 1, text.length() - 1, 0, text.length(), true, false); - } - } - - private void assertGetTextRunAdvances(String str, int start, int end, - int contextStart, int contextEnd, boolean isRtl, boolean compareWithOtherMethods) { - Paint p = new Paint(); - - final int count = end - start; - final float[][] advanceArrays = new float[4][count]; - - final float advance = p.getTextRunAdvances(str, start, end, contextStart, contextEnd, - isRtl, advanceArrays[0], 0); - - char chars[] = str.toCharArray(); - final float advance_c = p.getTextRunAdvances(chars, start, count, contextStart, - contextEnd - contextStart, isRtl, advanceArrays[1], 0); - assertEquals(advance, advance_c, 1.0f); - - for (int c = 1; c < count; ++c) { - final float firstPartAdvance = p.getTextRunAdvances(str, start, start + c, - contextStart, contextEnd, isRtl, advanceArrays[2], 0); - final float secondPartAdvance = p.getTextRunAdvances(str, start + c, end, - contextStart, contextEnd, isRtl, advanceArrays[2], c); - assertEquals(advance, firstPartAdvance + secondPartAdvance, 1.0f); - - - final float firstPartAdvance_c = p.getTextRunAdvances(chars, start, c, - contextStart, contextEnd - contextStart, isRtl, advanceArrays[3], 0); - final float secondPartAdvance_c = p.getTextRunAdvances(chars, start + c, - count - c, contextStart, contextEnd - contextStart, isRtl, - advanceArrays[3], c); - assertEquals(advance, firstPartAdvance_c + secondPartAdvance_c, 1.0f); - assertEquals(firstPartAdvance, firstPartAdvance_c, 1.0f); - assertEquals(secondPartAdvance, secondPartAdvance_c, 1.0f); - - for (int i = 1; i < advanceArrays.length; i++) { - for (int j = 0; j < count; j++) { - assertEquals(advanceArrays[0][j], advanceArrays[i][j], 1.0f); - } - } - - // Compare results with measureText, getRunAdvance, and getTextWidths. - if (compareWithOtherMethods && start == contextStart && end == contextEnd) { - assertEquals(advance, p.measureText(str, start, end), 1.0f); - assertEquals(advance, p.getRunAdvance( - str, start, end, contextStart, contextEnd, isRtl, end), 1.0f); - - final float[] widths = new float[count]; - p.getTextWidths(str, start, end, widths); - for (int i = 0; i < count; i++) { - assertEquals(advanceArrays[0][i], widths[i], 1.0f); - } - } - } - } - - public void testGetTextRunAdvances_invalid() { - Paint p = new Paint(); - String text = "test"; - - try { - p.getTextRunAdvances((String)null, 0, 0, 0, 0, false, null, 0); - fail("Should throw an IllegalArgumentException."); - } catch (IllegalArgumentException e) { - } - - try { - p.getTextRunAdvances((CharSequence)null, 0, 0, 0, 0, false, null, 0); - fail("Should throw an IllegalArgumentException."); - } catch (IllegalArgumentException e) { - } - - try { - p.getTextRunAdvances((char[])null, 0, 0, 0, 0, false, null, 0); - fail("Should throw an IllegalArgumentException."); - } catch (IllegalArgumentException e) { - } - - try { - p.getTextRunAdvances(text, 0, text.length(), 0, text.length(), false, - new float[text.length() - 1], 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - try { - p.getTextRunAdvances(text, 0, text.length(), 0, text.length(), false, - new float[text.length()], 1); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - // 0 > contextStart - try { - p.getTextRunAdvances(text, 0, text.length(), -1, text.length(), false, null, 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - // contextStart > start - try { - p.getTextRunAdvances(text, 0, text.length(), 1, text.length(), false, null, 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - // start > end - try { - p.getTextRunAdvances(text, 1, 0, 0, text.length(), false, null, 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - // end > contextEnd - try { - p.getTextRunAdvances(text, 0, text.length(), 0, text.length() - 1, false, null, 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - - // contextEnd > text.length - try { - p.getTextRunAdvances(text, 0, text.length(), 0, text.length() + 1, false, null, 0); - fail("Should throw an IndexOutOfBoundsException."); - } catch (IndexOutOfBoundsException e) { - } - } - - public void testMeasureTextBidi() { - Paint p = new Paint(); - { - String bidiText = "abc \u0644\u063A\u0629 def"; - p.setBidiFlags(Paint.BIDI_LTR); - float width = p.measureText(bidiText, 0, 4); - p.setBidiFlags(Paint.BIDI_RTL); - width += p.measureText(bidiText, 4, 7); - p.setBidiFlags(Paint.BIDI_LTR); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - { - String bidiText = "abc \u0644\u063A\u0629 def"; - p.setBidiFlags(Paint.BIDI_DEFAULT_LTR); - float width = p.measureText(bidiText, 0, 4); - width += p.measureText(bidiText, 4, 7); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - { - String bidiText = "abc \u0644\u063A\u0629 def"; - p.setBidiFlags(Paint.BIDI_FORCE_LTR); - float width = p.measureText(bidiText, 0, 4); - width += p.measureText(bidiText, 4, 7); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - { - String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; - p.setBidiFlags(Paint.BIDI_RTL); - float width = p.measureText(bidiText, 0, 4); - p.setBidiFlags(Paint.BIDI_LTR); - width += p.measureText(bidiText, 4, 7); - p.setBidiFlags(Paint.BIDI_RTL); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - { - String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; - p.setBidiFlags(Paint.BIDI_DEFAULT_RTL); - float width = p.measureText(bidiText, 0, 4); - width += p.measureText(bidiText, 4, 7); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - { - String bidiText = "\u0644\u063A\u0629 abc \u0644\u063A\u0629"; - p.setBidiFlags(Paint.BIDI_FORCE_RTL); - float width = p.measureText(bidiText, 0, 4); - width += p.measureText(bidiText, 4, 7); - width += p.measureText(bidiText, 7, bidiText.length()); - assertEquals(width, p.measureText(bidiText), 1.0f); - } - } - - public void testSetGetWordSpacing() { - Paint p = new Paint(); - assertEquals(0.0f, p.getWordSpacing()); // The default value should be 0. - p.setWordSpacing(1.0f); - assertEquals(1.0f, p.getWordSpacing()); - p.setWordSpacing(-2.0f); - assertEquals(-2.0f, p.getWordSpacing()); - } -}