diff options
author | Elliott Hughes <enh@google.com> | 2010-04-21 17:34:53 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-04-22 10:20:25 -0700 |
commit | 5779f05dd67ea322017c4ceb45270f5c6969d6b5 (patch) | |
tree | 4ce3be5fdba7dbfce0359d993fa6f3b1f2c2ce55 /luni | |
parent | cb109d3b97fb1f67b2e941ca22813986b6de97e0 (diff) | |
download | libcore-5779f05dd67ea322017c4ceb45270f5c6969d6b5.zip libcore-5779f05dd67ea322017c4ceb45270f5c6969d6b5.tar.gz libcore-5779f05dd67ea322017c4ceb45270f5c6969d6b5.tar.bz2 |
Update to the latest upstream collator tests.
I've pulled out the not-obviously-insane stuff we added, though I don't
know how useful it is. This change is mainly about reverting our broken
changes to these tests.
Bug: 2608750
Bug: 2608742
Change-Id: Ia4d0a7b12bfc5dfc3fad4b72254918acf74b418d
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/test/java/java/text/AllTests.java | 1 | ||||
-rw-r--r-- | luni/src/test/java/java/text/CollatorTest.java | 85 |
2 files changed, 86 insertions, 0 deletions
diff --git a/luni/src/test/java/java/text/AllTests.java b/luni/src/test/java/java/text/AllTests.java index 04a573d..240b745 100644 --- a/luni/src/test/java/java/text/AllTests.java +++ b/luni/src/test/java/java/text/AllTests.java @@ -22,6 +22,7 @@ import junit.framework.TestSuite; public class AllTests { public static final Test suite() { TestSuite suite = new TestSuite(); + suite.addTestSuite(java.text.CollatorTest.class); suite.addTestSuite(java.text.DateFormatSymbolsTest.class); suite.addTestSuite(java.text.DecimalFormatTest.class); suite.addTestSuite(java.text.DecimalFormatSymbolsTest.class); diff --git a/luni/src/test/java/java/text/CollatorTest.java b/luni/src/test/java/java/text/CollatorTest.java new file mode 100644 index 0000000..48c0eb1 --- /dev/null +++ b/luni/src/test/java/java/text/CollatorTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2010 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 java.text; + +import java.util.Locale; +import junit.framework.Test; +import junit.framework.TestSuite; + +public class CollatorTest extends junit.framework.TestCase { + public void test_setStrengthI() throws Exception { + Collator collator = Collator.getInstance(); + collator.setStrength(Collator.PRIMARY); + assertEquals(Collator.PRIMARY, collator.getStrength()); + collator.setStrength(Collator.SECONDARY); + assertEquals(Collator.SECONDARY, collator.getStrength()); + collator.setStrength(Collator.TERTIARY); + assertEquals(Collator.TERTIARY, collator.getStrength()); + collator.setStrength(Collator.IDENTICAL); + assertEquals(Collator.IDENTICAL, collator.getStrength()); + try { + collator.setStrength(-1); + fail("IllegalArgumentException was not thrown."); + } catch (IllegalArgumentException expected) { + } + } + + public void test_stackCorruption() throws Exception { + // This used to crash Android. + Collator mColl = Collator.getInstance(); + mColl.setStrength(Collator.PRIMARY); + mColl.getCollationKey("2d294f2d3739433565147655394f3762f3147312d3731641452f310"); + } + + public void test_collationKeySize() throws Exception { + // Test to verify that very large collation keys are not truncated. + StringBuilder b = new StringBuilder(); + for (int i = 0; i < 1024; i++) { + b.append("0123456789ABCDEF"); + } + String sixteen = b.toString(); + b.append("_THE_END"); + String sixteenplus = b.toString(); + + Collator mColl = Collator.getInstance(); + mColl.setStrength(Collator.PRIMARY); + + byte [] arr = mColl.getCollationKey(sixteen).toByteArray(); + int len = arr.length; + assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0); + len--; + String foo = new String(arr, 0, len, "iso8859-1"); + + arr = mColl.getCollationKey(sixteen).toByteArray(); + len = arr.length; + assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0); + len--; + String bar = new String(arr, 0, len, "iso8859-1"); + + assertTrue("Collation keys should differ", foo.equals(bar)); + } + + public void test_decompositionCompatibility() throws Exception { + Collator myCollator = Collator.getInstance(); + myCollator.setDecomposition(Collator.NO_DECOMPOSITION); + assertFalse("Error: \u00e0\u0325 should not equal to a\u0325\u0300 without decomposition", + myCollator.compare("\u00e0\u0325", "a\u0325\u0300") == 0); + myCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION); + assertTrue("Error: \u00e0\u0325 should equal to a\u0325\u0300 with decomposition", + myCollator.compare("\u00e0\u0325", "a\u0325\u0300") == 0); + } +} |