summaryrefslogtreecommitdiffstats
path: root/text/src
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-04-21 17:34:53 -0700
committerElliott Hughes <enh@google.com>2010-04-22 10:20:25 -0700
commit5779f05dd67ea322017c4ceb45270f5c6969d6b5 (patch)
tree4ce3be5fdba7dbfce0359d993fa6f3b1f2c2ce55 /text/src
parentcb109d3b97fb1f67b2e941ca22813986b6de97e0 (diff)
downloadlibcore-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 'text/src')
-rw-r--r--text/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java701
-rw-r--r--text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java291
2 files changed, 284 insertions, 708 deletions
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java
index 71ee510..92225d7 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java
@@ -16,500 +16,261 @@
*/
package org.apache.harmony.text.tests.java.text;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import java.io.UnsupportedEncodingException;
-import java.text.CollationKey;
import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;
import java.util.Locale;
-@TestTargetClass(Collator.class)
public class CollatorTest extends junit.framework.TestCase {
- /**
- * @tests java.text.Collator#clone()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clone",
- args = {}
- )
- public void test_clone() {
- Collator c = Collator.getInstance(Locale.GERMAN);
- Collator c2 = (Collator) c.clone();
- assertTrue("Clones answered false to equals", c.equals(c2));
- assertTrue("Clones were equivalent", c != c2);
- }
-
- /**
- * @tests java.text.Collator#compare(java.lang.Object, java.lang.Object)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compare",
- args = {java.lang.Object.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setStrength",
- args = {int.class}
- )
- })
- public void test_compareLjava_lang_ObjectLjava_lang_Object() {
- Collator c = Collator.getInstance(Locale.FRENCH);
- Object o, o2;
-
- c.setStrength(Collator.IDENTICAL);
- o = "E";
- o2 = "F";
- assertTrue("a) Failed on primary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "\u00e9";
- assertTrue("a) Failed on secondary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "E";
- assertTrue("a) Failed on tertiary difference", c.compare(o, o2) < 0);
- o = "\u0001";
- o2 = "\u0002";
- assertTrue("a) Failed on identical", c.compare(o, o2) < 0);
- o = "e";
- o2 = "e";
- assertEquals("a) Failed on equivalence", 0, c.compare(o, o2));
- assertTrue("a) Failed on primary expansion",
- c.compare("\u01db", "v") < 0);
-
- c.setStrength(Collator.TERTIARY);
- o = "E";
- o2 = "F";
- assertTrue("b) Failed on primary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "\u00e9";
- assertTrue("b) Failed on secondary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "E";
- assertTrue("b) Failed on tertiary difference", c.compare(o, o2) < 0);
- o = "\u0001";
- o2 = "\u0002";
- assertEquals("b) Failed on identical", 0, c.compare(o, o2));
- o = "e";
- o2 = "e";
- assertEquals("b) Failed on equivalence", 0, c.compare(o, o2));
-
- c.setStrength(Collator.SECONDARY);
- o = "E";
- o2 = "F";
- assertTrue("c) Failed on primary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "\u00e9";
- assertTrue("c) Failed on secondary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "E";
- assertEquals("c) Failed on tertiary difference", 0, c.compare(o, o2));
- o = "\u0001";
- o2 = "\u0002";
- assertEquals("c) Failed on identical", 0, c.compare(o, o2));
- o = "e";
- o2 = "e";
- assertEquals("c) Failed on equivalence", 0, c.compare(o, o2));
-
- c.setStrength(Collator.PRIMARY);
- o = "E";
- o2 = "F";
- assertTrue("d) Failed on primary difference", c.compare(o, o2) < 0);
- o = "e";
- o2 = "\u00e9";
- assertEquals("d) Failed on secondary difference", 0, c.compare(o, o2));
- o = "e";
- o2 = "E";
- assertEquals("d) Failed on tertiary difference", 0, c.compare(o, o2));
- o = "\u0001";
- o2 = "\u0002";
- assertEquals("d) Failed on identical", 0, c.compare(o, o2));
- o = "e";
- o2 = "e";
- assertEquals("d) Failed on equivalence", 0, c.compare(o, o2));
-
- try {
- c.compare("e", new StringBuffer("Blah"));
- } catch (ClassCastException e) {
- // correct
- return;
- }
- fail("Failed to throw ClassCastException");
- }
+ /**
+ * @tests java.text.Collator#clone()
+ */
+ public void test_clone() {
+ Collator c = Collator.getInstance(Locale.GERMAN);
+ Collator c2 = (Collator) c.clone();
+ assertTrue("Clones answered false to equals", c.equals(c2));
+ assertTrue("Clones were equivalent", c != c2);
+ }
- /**
- * @tests java.text.Collator#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- Collator c = Collator.getInstance(Locale.ENGLISH);
- Collator c2 = (Collator) c.clone();
- assertTrue("Cloned collators not equal", c.equals(c2));
- c2.setStrength(Collator.SECONDARY);
- assertTrue("Collators with different strengths equal", !c.equals(c2));
- }
+ /**
+ * @tests java.text.Collator#compare(java.lang.Object, java.lang.Object)
+ */
+ public void test_compareLjava_lang_ObjectLjava_lang_Object() {
+ Collator c = Collator.getInstance(Locale.FRENCH);
+ Object o, o2;
- /**
- * @tests java.text.Collator#equals(java.lang.String, java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setStrength",
- args = {int.class}
- )
- })
- public void test_equalsLjava_lang_StringLjava_lang_String() {
- Collator c = Collator.getInstance(Locale.FRENCH);
+ c.setStrength(Collator.IDENTICAL);
+ o = "E";
+ o2 = "F";
+ assertTrue("a) Failed on primary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "\u00e9";
+ assertTrue("a) Failed on secondary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "E";
+ assertTrue("a) Failed on tertiary difference", c.compare(o, o2) < 0);
+ o = "\u0001";
+ o2 = "\u0002";
+ assertTrue("a) Failed on identical", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "e";
+ assertEquals("a) Failed on equivalence", 0, c.compare(o, o2));
+ assertTrue("a) Failed on primary expansion",
+ c.compare("\u01db", "v") < 0);
- c.setStrength(Collator.IDENTICAL);
- assertTrue("a) Failed on primary difference", !c.equals("E", "F"));
- assertTrue("a) Failed on secondary difference", !c
- .equals("e", "\u00e9"));
- assertTrue("a) Failed on tertiary difference", !c.equals("e", "E"));
- assertTrue("a) Failed on identical", !c.equals("\u0001", "\u0002"));
- assertTrue("a) Failed on equivalence", c.equals("e", "e"));
+ c.setStrength(Collator.TERTIARY);
+ o = "E";
+ o2 = "F";
+ assertTrue("b) Failed on primary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "\u00e9";
+ assertTrue("b) Failed on secondary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "E";
+ assertTrue("b) Failed on tertiary difference", c.compare(o, o2) < 0);
+ o = "\u0001";
+ o2 = "\u0002";
+ assertEquals("b) Failed on identical", 0, c.compare(o, o2));
+ o = "e";
+ o2 = "e";
+ assertEquals("b) Failed on equivalence", 0, c.compare(o, o2));
- c.setStrength(Collator.TERTIARY);
- assertTrue("b) Failed on primary difference", !c.equals("E", "F"));
- assertTrue("b) Failed on secondary difference", !c
- .equals("e", "\u00e9"));
- assertTrue("b) Failed on tertiary difference", !c.equals("e", "E"));
- assertTrue("b) Failed on identical", c.equals("\u0001", "\u0002"));
- assertTrue("b) Failed on equivalence", c.equals("e", "e"));
+ c.setStrength(Collator.SECONDARY);
+ o = "E";
+ o2 = "F";
+ assertTrue("c) Failed on primary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "\u00e9";
+ assertTrue("c) Failed on secondary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "E";
+ assertEquals("c) Failed on tertiary difference", 0, c.compare(o, o2));
+ o = "\u0001";
+ o2 = "\u0002";
+ assertEquals("c) Failed on identical", 0, c.compare(o, o2));
+ o = "e";
+ o2 = "e";
+ assertEquals("c) Failed on equivalence", 0, c.compare(o, o2));
- c.setStrength(Collator.SECONDARY);
- assertTrue("c) Failed on primary difference", !c.equals("E", "F"));
- assertTrue("c) Failed on secondary difference", !c
- .equals("e", "\u00e9"));
- assertTrue("c) Failed on tertiary difference", c.equals("e", "E"));
- assertTrue("c) Failed on identical", c.equals("\u0001", "\u0002"));
- assertTrue("c) Failed on equivalence", c.equals("e", "e"));
+ c.setStrength(Collator.PRIMARY);
+ o = "E";
+ o2 = "F";
+ assertTrue("d) Failed on primary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "\u00e9";
+ assertEquals("d) Failed on secondary difference", 0, c.compare(o, o2));
+ o = "e";
+ o2 = "E";
+ assertEquals("d) Failed on tertiary difference", 0, c.compare(o, o2));
+ o = "\u0001";
+ o2 = "\u0002";
+ assertEquals("d) Failed on identical", 0, c.compare(o, o2));
+ o = "e";
+ o2 = "e";
+ assertEquals("d) Failed on equivalence", 0, c.compare(o, o2));
- c.setStrength(Collator.PRIMARY);
- assertTrue("d) Failed on primary difference", !c.equals("E", "F"));
- assertTrue("d) Failed on secondary difference", c.equals("e", "\u00e9"));
- assertTrue("d) Failed on tertiary difference", c.equals("e", "E"));
- assertTrue("d) Failed on identical", c.equals("\u0001", "\u0002"));
- assertTrue("d) Failed on equivalence", c.equals("e", "e"));
- }
+ try {
+ c.compare("e", new StringBuffer("Blah"));
+ } catch (ClassCastException e) {
+ // correct
+ return;
+ }
+ fail("Failed to throw ClassCastException");
+ }
- /**
- * @tests java.text.Collator#getAvailableLocales()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getAvailableLocales",
- args = {}
- )
- public void test_getAvailableLocales() {
- Locale[] locales = Collator.getAvailableLocales();
- assertTrue("No locales", locales.length > 0);
- boolean hasUS = false;
- for (int i = locales.length; --i >= 0;) {
- Collator c1 = Collator.getInstance(locales[i]);
- assertTrue("Doesn't work", c1.compare("a", "b") < 0);
- assertTrue("Wrong decomposition",
- c1.getDecomposition() == Collator.NO_DECOMPOSITION);
- assertTrue("Wrong strength", c1.getStrength() == Collator.TERTIARY);
- // The default decomposition for collators created with getInstance
- // is NO_DECOMPOSITION where collators created from rules have
- // CANONICAL_DECOMPOSITION. Verified on RI.
- c1.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
- if (locales[i].equals(Locale.US)) {
- hasUS = true;
- }
- if (c1 instanceof RuleBasedCollator) {
- String rule = "";
- Collator temp = null;
- try {
- rule = ((RuleBasedCollator) c1).getRules();
- temp = new RuleBasedCollator(rule);
- } catch (ParseException e) {
- fail(e.getMessage() + " for rule: \"" + rule + "\"");
- }
- assertTrue("Can't recreate: " + locales[i], temp.equals(c1));
- }
- }
- assertTrue("en_US locale not available", hasUS);
- }
+ /**
+ * @tests java.text.Collator#equals(java.lang.Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ Collator c = Collator.getInstance(Locale.ENGLISH);
+ Collator c2 = (Collator) c.clone();
+ assertTrue("Cloned collators not equal", c.equals(c2));
+ c2.setStrength(Collator.SECONDARY);
+ assertTrue("Collators with different strengths equal", !c.equals(c2));
+ }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Collator",
- args = {}
- )
- public void test_Constructor() {
- TestCollator collator = new TestCollator();
- assertEquals(Collator.TERTIARY, collator.getStrength());
- }
-
- /**
- * @tests java.text.Collator#getDecomposition()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getDecomposition",
- args = {}
- )
- public void test_getDecomposition() {
- RuleBasedCollator collator;
- try {
- collator = new RuleBasedCollator("; \u0300 < a, A < b < c < d");
- } catch (ParseException e) {
- fail("ParseException");
- return;
- }
- assertTrue("Wrong default",
- collator.getDecomposition() == Collator.CANONICAL_DECOMPOSITION);
-
- collator.setDecomposition(Collator.NO_DECOMPOSITION);
- assertEquals(Collator.NO_DECOMPOSITION, collator.getDecomposition());
+ /**
+ * @tests java.text.Collator#equals(java.lang.String, java.lang.String)
+ */
+ public void test_equalsLjava_lang_StringLjava_lang_String() {
+ Collator c = Collator.getInstance(Locale.FRENCH);
- // BEGIN android-removed
- // Android doesn't support full decomposition
- // collator.setDecomposition(Collator.FULL_DECOMPOSITION);
- // assertEquals(Collator.FULL_DECOMPOSITION, collator.getDecomposition());
- // EN android-removed
- }
+ c.setStrength(Collator.IDENTICAL);
+ assertTrue("a) Failed on primary difference", !c.equals("E", "F"));
+ assertTrue("a) Failed on secondary difference", !c
+ .equals("e", "\u00e9"));
+ assertTrue("a) Failed on tertiary difference", !c.equals("e", "E"));
+ assertTrue("a) Failed on identical", !c.equals("\u0001", "\u0002"));
+ assertTrue("a) Failed on equivalence", c.equals("e", "e"));
- /**
- * @tests java.text.Collator#getInstance()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {}
- )
- public void test_getInstance() {
- Collator c1 = Collator.getInstance();
- Collator c2 = Collator.getInstance(Locale.getDefault());
- assertTrue("Wrong locale", c1.equals(c2));
- }
+ c.setStrength(Collator.TERTIARY);
+ assertTrue("b) Failed on primary difference", !c.equals("E", "F"));
+ assertTrue("b) Failed on secondary difference", !c
+ .equals("e", "\u00e9"));
+ assertTrue("b) Failed on tertiary difference", !c.equals("e", "E"));
+ assertTrue("b) Failed on identical", c.equals("\u0001", "\u0002"));
+ assertTrue("b) Failed on equivalence", c.equals("e", "e"));
- /**
- * @tests java.text.Collator#getInstance(java.util.Locale)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {java.util.Locale.class}
- )
- public void test_getInstanceLjava_util_Locale() {
- assertTrue("Used to test", true);
- }
+ c.setStrength(Collator.SECONDARY);
+ assertTrue("c) Failed on primary difference", !c.equals("E", "F"));
+ assertTrue("c) Failed on secondary difference", !c
+ .equals("e", "\u00e9"));
+ assertTrue("c) Failed on tertiary difference", c.equals("e", "E"));
+ assertTrue("c) Failed on identical", c.equals("\u0001", "\u0002"));
+ assertTrue("c) Failed on equivalence", c.equals("e", "e"));
- /**
- * @tests java.text.Collator#getStrength()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getStrength",
- args = {}
- )
- public void test_getStrength() {
- RuleBasedCollator collator;
- try {
- collator = new RuleBasedCollator("; \u0300 < a, A < b < c < d");
- } catch (ParseException e) {
- fail("ParseException");
- return;
- }
- assertTrue("Wrong default", collator.getStrength() == Collator.TERTIARY);
- }
+ c.setStrength(Collator.PRIMARY);
+ assertTrue("d) Failed on primary difference", !c.equals("E", "F"));
+ assertTrue("d) Failed on secondary difference", c.equals("e", "\u00e9"));
+ assertTrue("d) Failed on tertiary difference", c.equals("e", "E"));
+ assertTrue("d) Failed on identical", c.equals("\u0001", "\u0002"));
+ assertTrue("d) Failed on equivalence", c.equals("e", "e"));
+ }
- /**
- * @tests java.text.Collator#setDecomposition(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDecomposition",
- args = {int.class}
- )
- public void test_setDecompositionI() {
- Collator c = Collator.getInstance(Locale.FRENCH);
- c.setStrength(Collator.IDENTICAL);
- c.setDecomposition(Collator.NO_DECOMPOSITION);
- assertFalse("Collator should not be using decomposition", c.equals(
- "\u212B", "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL
- // LETTER A WITH RING ABOVE"
- c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
- assertTrue("Collator should be using decomposition", c.equals("\u212B",
- "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL LETTER A WITH
- // RING ABOVE"
- // BEGIN android-removed
- // Android doesn't support FULL_DECOMPOSITION
- // c.setDecomposition(Collator.FULL_DECOMPOSITION);
- // assertTrue("Should be equal under full decomposition", c.equals(
- // "\u2163", "IV")); // roman number "IV"
- // END android-removed
-
- try {
- c.setDecomposition(-1);
- fail("IllegalArgumentException should be thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
+ /**
+ * @tests java.text.Collator#getAvailableLocales()
+ */
+ //FIXME This test fails on Harmony ClassLibrary
+ public void failing_test_getAvailableLocales() {
+ Locale[] locales = Collator.getAvailableLocales();
+ assertTrue("No locales", locales.length > 0);
+ boolean english = false, german = false;
+ for (int i = locales.length; --i >= 0;) {
+ if (locales[i].equals(Locale.ENGLISH))
+ english = true;
+ if (locales[i].equals(Locale.GERMAN))
+ german = true;
+ // Output the working locale to help diagnose a hang
+ Collator c1 = Collator.getInstance(locales[i]);
+ assertTrue("Doesn't work", c1.compare("a", "b") < 0);
+ assertTrue("Wrong decomposition",
+ c1.getDecomposition() == Collator.NO_DECOMPOSITION);
+ assertTrue("Wrong strength", c1.getStrength() == Collator.TERTIARY);
+ if (c1 instanceof RuleBasedCollator) {
+ try {
+ new RuleBasedCollator(((RuleBasedCollator) c1).getRules());
+ } catch (ParseException e) {
+ fail("ParseException");
+ }
+ // assertTrue("Can't recreate: " + locales[i], temp.equals(c1));
+ }
+ }
+ assertTrue("Missing locales", english && german);
+ }
- /**
- * @tests java.text.Collator#setStrength(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "setStrength",
- args = {int.class}
- )
- public void test_setStrengthI() {
- // Functionality is verified in compare and equals tests.
- 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 iae) {
- //expected
- }
- }
- // Regression test for Android bug
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test.",
- method = "setStrength",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test.",
- method = "getCollationKey",
- args = {java.lang.String.class}
- )
- })
- public void test_stackCorruption() {
- Collator mColl = Collator.getInstance();
- mColl.setStrength(Collator.PRIMARY);
- mColl.getCollationKey("2d294f2d3739433565147655394f3762f3147312d3731641452f310");
- }
-
- // Test to verify that very large collation keys are not truncated.
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't verify null as a parameter.",
- method = "getCollationKey",
- args = {java.lang.String.class}
- )
- public void test_collationKeySize() {
- 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);
+ /**
+ * @tests java.text.Collator#getDecomposition()
+ */
+ //FIXME This test fails on Harmony ClassLibrary
+ public void failing_test_getDecomposition() {
+ RuleBasedCollator collator;
+ try {
+ collator = new RuleBasedCollator("; \u0300 < a, A < b < c < d");
+ } catch (ParseException e) {
+ fail("ParseException");
+ return;
+ }
+ assertTrue("Wrong default",
+ collator.getDecomposition() == Collator.CANONICAL_DECOMPOSITION);
+ }
- try {
- 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");
+ /**
+ * @tests java.text.Collator#getInstance()
+ */
+ public void test_getInstance() {
+ Collator c1 = Collator.getInstance();
+ Collator c2 = Collator.getInstance(Locale.getDefault());
+ assertTrue("Wrong locale", c1.equals(c2));
+ }
- 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));
- } catch (UnsupportedEncodingException ex) {
- fail("UnsupportedEncodingException");
- }
- }
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "setDecomposition",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "compare",
- args = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void test_decompositionCompatibility() {
- 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);
- }
-
- class TestCollator extends Collator {
+ /**
+ * @tests java.text.Collator#getInstance(java.util.Locale)
+ */
+ public void test_getInstanceLjava_util_Locale() {
+ assertTrue("Used to test", true);
+ }
- @Override
- public int compare(String source, String target) {
- return 0;
- }
+ /**
+ * @tests java.text.Collator#getStrength()
+ */
+ public void test_getStrength() {
+ RuleBasedCollator collator;
+ try {
+ collator = new RuleBasedCollator("; \u0300 < a, A < b < c < d");
+ } catch (ParseException e) {
+ fail("ParseException");
+ return;
+ }
+ assertTrue("Wrong default", collator.getStrength() == Collator.TERTIARY);
+ }
- @Override
- public CollationKey getCollationKey(String source) {
- return null;
- }
+ /**
+ * @tests java.text.Collator#setDecomposition(int)
+ */
+ //FIXME This test fails on Harmony ClassLibrary
+ public void failing_test_setDecompositionI() {
+ Collator c = Collator.getInstance(Locale.FRENCH);
+ c.setStrength(Collator.IDENTICAL);
+ c.setDecomposition(Collator.NO_DECOMPOSITION);
+ assertTrue("Collator should not be using decomposition", !c.equals(
+ "\u212B", "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL
+ // LETTER A WITH RING ABOVE"
+ c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
+ assertTrue("Collator should be using decomposition", c.equals("\u212B",
+ "\u00C5")); // "ANGSTROM SIGN" and "LATIN CAPITAL LETTER A WITH
+ // RING ABOVE"
+ assertTrue("Should not be equal under canonical decomposition", !c
+ .equals("\u2163", "IV")); // roman number "IV"
+ c.setDecomposition(Collator.FULL_DECOMPOSITION);
+ assertTrue("Should be equal under full decomposition", c.equals(
+ "\u2163", "IV")); // roman number "IV"
+ }
- @Override
- public int hashCode() {
- return 0;
- }
-
- }
+ /**
+ * @tests java.text.Collator#setStrength(int)
+ */
+ public void test_setStrengthI() {
+ assertTrue("Used to test", true);
+ }
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
index 68452e66..5b8146c 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
@@ -17,15 +17,6 @@
package org.apache.harmony.text.tests.java.text;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import junit.framework.TestCase;
-
import java.text.CharacterIterator;
import java.text.CollationElementIterator;
import java.text.CollationKey;
@@ -35,83 +26,24 @@ import java.text.RuleBasedCollator;
import java.text.StringCharacterIterator;
import java.util.Locale;
-@TestTargetClass(RuleBasedCollator.class)
-public class RuleBasedCollatorTest extends TestCase {
-
- /**
- * @tests java.text.RuleBasedCollator#RuleBasedCollator(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "RuleBasedCollator",
- args = {java.lang.String.class}
- )
- public void test_constrLRuleBasedCollatorLjava_lang_String() {
- RuleBasedCollator rbc;
- try {
- rbc = new RuleBasedCollator("<a< b< c< d");
- assertNotSame("RuleBasedCollator object is null", null, rbc);
- } catch (java.text.ParseException pe) {
- fail("java.text.ParseException is thrown for correct string");
- }
-
- try {
- rbc = new RuleBasedCollator("<a< '&'b< \u0301< d");
- assertNotSame("RuleBasedCollator object is null", null, rbc);
- } catch (java.text.ParseException pe) {
- fail("java.text.ParseException is thrown for correct string");
- }
-
- try {
- new RuleBasedCollator(null);
- fail("No Exception is thrown for correct string");
- } catch (java.text.ParseException pe) {
- fail("java.lang.NullPointerException is not thrown for correct string");
- } catch (java.lang.NullPointerException npe) {
-
- }
+import junit.framework.TestCase;
-// Commented since fails agains RI and Android, too:
-//
-// // Android allows to pass empty rules to a collator. It results in
-// // a collator with default UCA rules.
-// try {
-// new RuleBasedCollator("");
-// } catch (java.text.ParseException pe) {
-// fail("java.text.ParseException is thrown for empty string");
-// }
+public class RuleBasedCollatorTest extends TestCase {
- try {
- new RuleBasedCollator("1234567%$#845");
- fail("java.text.ParseException is not thrown for wrong rules");
- } catch (java.text.ParseException pe) {
- }
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test. Doesn't verify positive functionality.",
- method = "getCollationKey",
- args = {java.lang.String.class}
- )
- public void test_getCollationKeyLjava_lang_String() {
- // Regression test for HARMONY-28
- String source = null;
- RuleBasedCollator rbc = null;
- try {
- String Simple = "< a< b< c< d";
- rbc = new RuleBasedCollator(Simple);
- } catch (ParseException e) {
- fail("Assert 0: Unexpected format exception " + e);
- }
- CollationKey ck = rbc.getCollationKey(source);
- assertNull("Assert 1: getCollationKey (null) does not return null", ck);
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
+ public void test_getCollationKeyLjava_lang_String() {
+ // Regression test for HARMONY-28
+ String source = null;
+ RuleBasedCollator rbc = null;
+ try {
+ String Simple = "< a< b< c< d";
+ rbc = new RuleBasedCollator(Simple);
+ } catch (ParseException e) {
+ fail("Assert 0: Unexpected format exception " + e);
+ }
+ CollationKey ck = rbc.getCollationKey(source);
+ assertNull("Assert 1: getCollationKey (null) does not return null", ck);
+ }
+
public void testHashCode() throws ParseException {
{
String rule = "< a < b < c < d";
@@ -126,12 +58,7 @@ public class RuleBasedCollatorTest extends TestCase {
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clone",
- args = {}
- )
+
public void testClone() throws ParseException {
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(Locale.US);
@@ -145,17 +72,12 @@ public class RuleBasedCollatorTest extends TestCase {
/*
* Class under test for boolean equals(java.lang.Object)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "equals",
- args = {java.lang.Object.class}
- )
public void testEqualsObject() throws ParseException {
String rule = "< a < b < c < d < e";
RuleBasedCollator coll = new RuleBasedCollator(rule);
assertEquals(Collator.TERTIARY, coll.getStrength());
- assertEquals(Collator.CANONICAL_DECOMPOSITION, coll.getDecomposition());
+ assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
RuleBasedCollator other = new RuleBasedCollator(rule);
assertTrue(coll.equals(other));
@@ -164,33 +86,18 @@ public class RuleBasedCollatorTest extends TestCase {
coll.setStrength(Collator.TERTIARY);
coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
- assertTrue(coll.equals(other));
+ assertFalse(coll.equals(other));
}
/*
* Class under test for int compare(java.lang.String, java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compare",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void testCompareStringString() throws ParseException {
String rule = "< c < b < a";
RuleBasedCollator coll = new RuleBasedCollator(rule);
assertEquals(-1, coll.compare("c", "a"));
- assertEquals(-1, coll.compare("a", "d"));
- assertEquals(1, coll.compare("3", "1"));
- assertEquals(1, coll.compare("A", "1"));
- assertEquals(0, coll.compare("A", "A"));
}
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't verify null as a parameter.",
- method = "getCollationKey",
- args = {java.lang.String.class}
- )
+
public void testGetCollationKey() {
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(Locale.GERMAN);
@@ -204,12 +111,7 @@ public class RuleBasedCollatorTest extends TestCase {
assertTrue(coll.compare(source, source2) > 0);
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getRules",
- args = {}
- )
+
public void testGetRules() throws ParseException {
String rule = "< a = b < c";
RuleBasedCollator coll = new RuleBasedCollator(rule);
@@ -220,12 +122,6 @@ public class RuleBasedCollatorTest extends TestCase {
* Class under test for java.text.CollationElementIterator
* getCollationElementIterator(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCollationElementIterator",
- args = {java.lang.String.class}
- )
public void testGetCollationElementIteratorString() throws Exception {
{
Locale locale = new Locale("es", "", "TRADITIONAL");
@@ -234,11 +130,11 @@ public class RuleBasedCollatorTest extends TestCase {
String source = "cha";
CollationElementIterator iterator = coll
.getCollationElementIterator(source);
- int[] e_offset = { 0, 1, 2 };
+ int[] e_offset = { 0, 1, 2 ,3};
int offset = iterator.getOffset();
int i = 0;
assertEquals(e_offset[i++], offset);
- while (offset != source.length() - 1) {
+ while (offset != source.length()) {
iterator.next();
offset = iterator.getOffset();
assertEquals(e_offset[i++], offset);
@@ -262,12 +158,12 @@ public class RuleBasedCollatorTest extends TestCase {
assertEquals(e_offset[i++], offset);
}
}
- // Regression for HARMONY-1352
+ //Regression for HARMONY-1352
try {
new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((String)null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
- // expected
+ //expected
}
}
@@ -275,29 +171,24 @@ public class RuleBasedCollatorTest extends TestCase {
* Class under test for java.text.CollationElementIterator
* getCollationElementIterator(java.text.CharacterIterator)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getCollationElementIterator",
- args = {java.text.CharacterIterator.class}
- )
public void testGetCollationElementIteratorCharacterIterator() throws Exception {
{
- Locale locale = new Locale("cs", "CZ", "");
+ Locale locale = new Locale("es", "", "TRADITIONAL");
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(locale);
String text = "cha";
StringCharacterIterator source = new StringCharacterIterator(text);
CollationElementIterator iterator = coll
.getCollationElementIterator(source);
- int[] e_offset = { 0, 2 };
+ int[] e_offset = { 0, 1, 2, 3 };
int offset = iterator.getOffset();
int i = 0;
assertEquals(e_offset[i++], offset);
- while (offset != text.length() - 1) {
+ while (offset != text.length()) {
iterator.next();
offset = iterator.getOffset();
- assertEquals(e_offset[i], offset);
- i++;
+ // System.out.println(offset);
+ assertEquals(e_offset[i++], offset);
}
}
@@ -319,28 +210,15 @@ public class RuleBasedCollatorTest extends TestCase {
assertEquals(e_offset[i++], offset);
}
}
- // Regression for HARMONY-1352
+ //Regression for HARMONY-1352
try {
new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator)null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
- // expected
+ //expected
}
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't verify setStrength method with PRIMARY, SECONDARY, TERTIARY or IDENTICAL values as a parameter; doesn't verify thatsetStrength method can throw IllegalArgumentException.",
- method = "setStrength",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't verify setStrength method with PRIMARY, SECONDARY, TERTIARY or IDENTICAL values as a parameter; doesn't verify thatsetStrength method can throw IllegalArgumentException.",
- method = "getStrength",
- args = {}
- )
- })
+
public void testStrength() {
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(Locale.US);
@@ -350,45 +228,16 @@ public class RuleBasedCollatorTest extends TestCase {
}
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDecomposition",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDecomposition",
- args = {}
- )
- })
+
public void testDecomposition() {
RuleBasedCollator coll = (RuleBasedCollator) Collator
.getInstance(Locale.US);
-
- int [] decompositions = {Collator.NO_DECOMPOSITION,
- Collator.CANONICAL_DECOMPOSITION};
-
- for (int decom:decompositions) {
- coll.setDecomposition(decom);
- assertEquals(decom, coll.getDecomposition());
- }
-
- try {
- coll.setDecomposition(-1);
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
+ for (int i = 0; i < 2; i++) {
+ coll.setDecomposition(i);
+ assertEquals(i, coll.getDecomposition());
}
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {}
- )
+
public void testCollator_GetInstance() {
Collator coll = Collator.getInstance();
Object obj1 = "a";
@@ -398,29 +247,15 @@ public class RuleBasedCollatorTest extends TestCase {
Collator.getInstance();
assertFalse(coll.equals("A", "\uFF21"));
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getAvailableLocales",
- args = {}
- )
- public void testGetAvaiableLocales() {
- Locale[] locales = Collator.getAvailableLocales();
- boolean isUS = false;
- for (int i = 0; i < locales.length; i++) {
- if(locales[i].equals(Locale.US))
- isUS = true;
- }
- assertTrue("No Locale.US in the array.", isUS);
+
+ public void testGetAvailableLocales() {
+ // Locale[] locales = Collator.getAvailableLocales();
+ // for (int i = 0; i < locales.length; i++) {
+ // Locale locale = locales[i];
+ // }
}
// Test CollationKey
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCollationKey",
- args = {java.lang.String.class}
- )
public void testCollationKey() {
Collator coll = Collator.getInstance(Locale.US);
String text = "abc";
@@ -435,14 +270,8 @@ public class RuleBasedCollatorTest extends TestCase {
/**
* @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verifies RuleBasedCollator(java.lang.String) constructor with null as a parameter.",
- method = "RuleBasedCollator",
- args = {java.lang.String.class}
- )
public void testNullPointerException() throws Exception {
- // Regression for HARMONY-241
+ //Regression for HARMONY-241
try {
new RuleBasedCollator(null);
fail("Constructor RuleBasedCollator(null) "
@@ -453,14 +282,8 @@ public class RuleBasedCollatorTest extends TestCase {
/**
* @tests java.text.RuleBasedCollator.compare(java.lang.String, java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verifies null as parameters.",
- method = "compare",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void testCompareNull() throws Exception {
- // Regression for HARMONY-836
+ //Regression for HARMONY-836
try {
new RuleBasedCollator("< a").compare(null, null);
fail("RuleBasedCollator.compare(null, null) "
@@ -471,24 +294,16 @@ public class RuleBasedCollatorTest extends TestCase {
/**
* @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verifies empty string as a parameter.",
- method = "RuleBasedCollator",
- args = {java.lang.String.class}
- )
- @AndroidOnly("Android uses icu for collating. " +
- "Icu has default UCA rules it uses to collate. " +
- "To create a default instance with these rules an empty " +
- "rule has to be passed to icu. This behavior is different " +
- "from the RI which would throw an exception.")
public void testEmptyStringException() {
+ //Regression for HARMONY-241
try {
- RuleBasedCollator coll = new RuleBasedCollator("");
- assertTrue(coll.equals(new RuleBasedCollator("")));
- } catch (ParseException e) {
+ new RuleBasedCollator("");
fail("Constructor RuleBasedCollator(\"\") "
- + "should NOT throw ParseException.");
+ + "should throw ParseException");
+ } catch (ParseException e) {
+ assertEquals("java.text.ParseException", e.getClass().getName());
+ assertEquals(0, e.getErrorOffset());
}
}
+
}