diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-09-28 13:14:24 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-09-28 13:14:24 -0700 |
commit | 9b9183241234af96e62ac8c5992b57e9ae6354e6 (patch) | |
tree | fbb8a120125b6a15d9dcaa9dab15906139fb713e | |
parent | 0f9bf4bdef9524a5e03d1cbdadc570269d703895 (diff) | |
parent | a055b2a5d62f7e8f879d2704edb261d43c3ac46c (diff) | |
download | libcore-9b9183241234af96e62ac8c5992b57e9ae6354e6.zip libcore-9b9183241234af96e62ac8c5992b57e9ae6354e6.tar.gz libcore-9b9183241234af96e62ac8c5992b57e9ae6354e6.tar.bz2 |
Merge "Remove java.text tests duplicated from Harmony" into gingerbread
42 files changed, 1681 insertions, 11642 deletions
diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java b/luni/src/test/java/libcore/java/text/OldAttributedCharacterIteratorAttributeTest.java index 054e243..58fc605 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorAttributeTest.java +++ b/luni/src/test/java/libcore/java/text/OldAttributedCharacterIteratorAttributeTest.java @@ -14,12 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; +package libcore.java.text; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,8 +25,7 @@ import java.io.ObjectOutputStream; import java.text.AttributedCharacterIterator; -@TestTargetClass(AttributedCharacterIterator.Attribute.class) -public class AttributedCharacterIteratorAttributeTest extends +public class OldAttributedCharacterIteratorAttributeTest extends junit.framework.TestCase { private class MockAttributedCharacterIteratorAttribute extends @@ -68,12 +62,6 @@ public class AttributedCharacterIteratorAttributeTest extends * Test of method * java.text.AttributedCharacterIterator.Attribute#AttributedCharacterIterator.Attribute(java.lang.String). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Attribute", - args = {java.lang.String.class} - ) public void test_Constructor() { try { new MockAttributedCharacterIteratorAttribute("test"); @@ -87,12 +75,6 @@ public class AttributedCharacterIteratorAttributeTest extends * Test of method * java.text.AttributedCharacterIterator.Attribute#equals(java.lang.Object). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) public void test_equalsLjava_lang_Object() { try { MockAttributedCharacterIteratorAttribute mac1 = new MockAttributedCharacterIteratorAttribute( @@ -119,12 +101,6 @@ public class AttributedCharacterIteratorAttributeTest extends * @tests java.text.AttributedCharacterIterator.Attribute#getName() Test of * method java.text.AttributedCharacterIterator.Attribute#getName(). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getName", - args = {} - ) public void test_getName() { try { MockAttributedCharacterIteratorAttribute mac1 = new MockAttributedCharacterIteratorAttribute( @@ -138,12 +114,6 @@ public class AttributedCharacterIteratorAttributeTest extends /** * @tests java.text.AttributedCharacterIterator.Attribute#hashCode() */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) public void test_hashCode() { try { MockAttributedCharacterIteratorAttribute mac1 = new MockAttributedCharacterIteratorAttribute( @@ -174,12 +144,6 @@ public class AttributedCharacterIteratorAttributeTest extends * of method * java.text.AttributedCharacterIterator.Attribute#readResolve(). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "readResolve", - args = {} - ) public void test_readResolve() { MockAttributedCharacterIteratorAttribute mac1 = new MockAttributedCharacterIteratorAttribute( "test"); @@ -231,12 +195,6 @@ public class AttributedCharacterIteratorAttributeTest extends * @tests java.text.AttributedCharacterIterator.Attribute#toString() Test of * method java.text.AttributedCharacterIterator.Attribute#toString(). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {} - ) public void test_toString() { MockAttributedCharacterIteratorAttribute mac1 = new MockAttributedCharacterIteratorAttribute( null); diff --git a/luni/src/test/java/libcore/java/text/OldAttributedCharacterIteratorTest.java b/luni/src/test/java/libcore/java/text/OldAttributedCharacterIteratorTest.java new file mode 100644 index 0000000..542468b --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldAttributedCharacterIteratorTest.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.AttributedCharacterIterator; +import java.text.AttributedString; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import junit.framework.TestCase; + +public class OldAttributedCharacterIteratorTest extends TestCase { + + AttributedCharacterIterator it; + String string = "test test"; + + public void test_getRunLimitLSet() { + AttributedString as = new AttributedString("test"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, + 3); + AttributedCharacterIterator it = as.getIterator(); + HashSet<AttributedCharacterIterator.Attribute> attr = + new HashSet<AttributedCharacterIterator.Attribute>(); + attr.add(AttributedCharacterIterator.Attribute.LANGUAGE); + assertEquals("non-null value limit", + 2, it.getRunLimit(attr)); + + as = new AttributedString("test"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null, + 2, 3); + it = as.getIterator(); + assertEquals("null value limit", + 4, it.getRunLimit(attr)); + + attr.add(AttributedCharacterIterator.Attribute.READING); + assertEquals("null value limit", + 4, it.getRunLimit(attr)); + } + + public void test_getAllAttributeKeys() { + AttributedString as = new AttributedString("test"); + AttributedCharacterIterator it = as.getIterator(); + Set<AttributedCharacterIterator.Attribute> emptyAttributes = + it.getAllAttributeKeys(); + assertTrue(emptyAttributes.isEmpty()); + + int attrCount = 10; + for(int i = 0 ; i < attrCount; i++) { + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "a"); + } + it = as.getIterator(); + Set<AttributedCharacterIterator.Attribute> attributes = + it.getAllAttributeKeys(); + for(AttributedCharacterIterator.Attribute attr:attributes) { + assertEquals(AttributedCharacterIterator.Attribute.LANGUAGE, attr); + } + } + + public void test_getAttributeLAttributedCharacterIterator_Attribute() { + + Object attribute = + it.getAttribute(AttributedCharacterIterator.Attribute.LANGUAGE); + assertEquals("ENGLISH", attribute); + + attribute = + it.getAttribute(AttributedCharacterIterator.Attribute.READING); + assertEquals("READ", attribute); + + assertNull(it.getAttribute(AttributedCharacterIterator. + Attribute.INPUT_METHOD_SEGMENT)); + } + + public void test_getAttributes() { + Map<AttributedCharacterIterator.Attribute, Object> attributes = + it.getAttributes(); + assertEquals(2, attributes.size()); + assertEquals("ENGLISH", + attributes.get(AttributedCharacterIterator.Attribute.LANGUAGE)); + assertEquals("READ", + attributes.get(AttributedCharacterIterator.Attribute.READING)); + + AttributedString as = new AttributedString("test"); + assertTrue(as.getIterator().getAttributes().isEmpty()); + } + + public void test_getRunLimit() { + int limit = it.getRunLimit(); + assertEquals(string.length(), limit); + + AttributedString as = new AttributedString(""); + assertEquals(0, as.getIterator().getRunLimit()); + + as = new AttributedString(new AttributedString("test text"). + getIterator(), 2, 7); + + AttributedCharacterIterator it = as.getIterator(); + assertEquals(5, it.getRunLimit()); + } + + public void test_getRunLimitLAttribute() { + AttributedString as = new AttributedString(""); + assertEquals(0, as.getIterator().getRunLimit( + AttributedCharacterIterator.Attribute.LANGUAGE)); + + as = new AttributedString("text"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "ENGLISH"); + + as.addAttribute(AttributedCharacterIterator.Attribute.READING, + "READ", 1, 3); + + assertEquals(4, as.getIterator().getRunLimit( + AttributedCharacterIterator.Attribute.LANGUAGE)); + + assertEquals(1, as.getIterator().getRunLimit( + AttributedCharacterIterator.Attribute.READING)); + } + + public void test_getRunStart() { + assertEquals(0, it.getRunStart()); + + AttributedString as = new AttributedString(""); + assertEquals(0, as.getIterator().getRunStart()); + + as = new AttributedString(new AttributedString("test text"). + getIterator(), 2, 7); + + AttributedCharacterIterator it = as.getIterator(); + + assertEquals(0, it.getRunStart()); + + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "GERMAN", 1, 2); + as.addAttribute(AttributedCharacterIterator.Attribute.READING, + "READ", 1, 3); + assertEquals(0, as.getIterator().getRunStart()); + } + + public void test_getRunStartLAttribute() { + assertEquals(0, it.getRunStart( + AttributedCharacterIterator.Attribute.LANGUAGE)); + + AttributedString as = new AttributedString("test text"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "GERMAN", 2, 5); + as.addAttribute(AttributedCharacterIterator.Attribute.READING, + "READ", 2, 7); + + assertEquals(0, as.getIterator().getRunStart( + AttributedCharacterIterator.Attribute.LANGUAGE)); + assertEquals(0, as.getIterator().getRunStart( + AttributedCharacterIterator.Attribute.READING)); + } + + public void test_getRunStartLjava_util_Set() { + AttributedString as = new AttributedString("test"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, + 3); + AttributedCharacterIterator it = as.getIterator(); + HashSet<AttributedCharacterIterator.Attribute> attr = + new HashSet<AttributedCharacterIterator.Attribute>(); + attr.add(AttributedCharacterIterator.Attribute.LANGUAGE); + assertEquals(0, it.getRunStart(attr)); + + as = new AttributedString("test"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "ENGLISH",1, 3); + it = as.getIterator(); + assertEquals(0, it.getRunStart(attr)); + + attr.add(AttributedCharacterIterator.Attribute.READING); + assertEquals(0, it.getRunStart(attr)); + + + } + + protected void setUp() { + + AttributedString as = new AttributedString(string); + + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "GERMAN"); + as.addAttribute(AttributedCharacterIterator.Attribute.READING, + "READ"); + as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, + "ENGLISH"); + + it = as.getIterator(); + } + + protected void tearDown() { + } +} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java b/luni/src/test/java/libcore/java/text/OldAttributedStringTest.java index 499ad85..d1e23b7 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedStringTest.java +++ b/luni/src/test/java/libcore/java/text/OldAttributedStringTest.java @@ -14,11 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; +package libcore.java.text; import java.text.AttributedCharacterIterator; import java.text.AttributedString; @@ -29,8 +25,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.WeakHashMap; -@TestTargetClass(AttributedString.class) -public class AttributedStringTest extends junit.framework.TestCase { +public class OldAttributedStringTest extends junit.framework.TestCase { static void assertEqualString (String msg, String expected, AttributedString attrString) { AttributedCharacterIterator it = attrString.getIterator(); @@ -42,27 +37,6 @@ public class AttributedStringTest extends junit.framework.TestCase { assertEquals(msg, expected, buf.toString()); } - /** - * @tests java.text.AttributedString#AttributedString(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "AttributedString", - args = {java.lang.String.class} - ) - public void test_ConstructorLjava_lang_String() { - String test = "Test string"; - AttributedString attrString = new AttributedString(test); - assertEqualString("String must match!", test, attrString); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Functional Test", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class} - ) public void test_ConstructorLAttributedCharacterIterator_1() { String testString = "Test string"; AttributedString attrString = new AttributedString(testString); @@ -71,27 +45,6 @@ public class AttributedStringTest extends junit.framework.TestCase { assertEqualString("String must match!", testString, attrString2); } - /** - * @tests java.text.AttributedString#AttributedString(AttributedCharacterIterator) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Regression for HARMONY-1354 (no functional test)", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class} - ) - public void test_ConstructorLAttributedCharacterIterator() { - // Regression for HARMONY-1354 - assertNotNull(new AttributedString( - new testAttributedCharacterIterator())); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Functional Test", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class, int.class, int.class} - ) public void test_ConstructorLAttributedCharacterIterator_2() { String testString = "Test string"; AttributedString attrString = new AttributedString(testString); @@ -108,12 +61,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * to consruct AttributedString using incorrect beginIndex. Case 3: * Try to consruct AttributedString using incorrect endIndex. */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "No functional test.", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class, int.class, int.class} - ) public void test_ConstructorLAttributedCharacterIteratorII() { // Regression for HARMONY-1355 @@ -141,12 +88,6 @@ public class AttributedStringTest extends junit.framework.TestCase { } } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Functional Test", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class, int.class, int.class, java.text.AttributedCharacterIterator.Attribute[].class} - ) public void test_ConstructorLAttributedCharacterIterator_3() { String testString = "Test string"; AttributedString attrString = new AttributedString(testString); @@ -170,12 +111,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * consruct AttributedString using incorrect endIndex. Case 4: Try to * consruct AttributedString using specified attributes. */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "No functional test.", - method = "AttributedString", - args = {java.text.AttributedCharacterIterator.class, int.class, int.class, java.text.AttributedCharacterIterator.Attribute[].class} - ) public void test_ConstructorLAttributedCharacterIteratorII$Ljava_text_AttributedCharacterIterator$Attribute() { // case 1: Try to consruct AttributedString. try { @@ -225,12 +160,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * AttributedString using 0-length text and not an empty Map * attributes. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "AttributedString", - args = {java.lang.String.class, java.util.Map.class} - ) public void test_ConstructorLjava_lang_StringLjava_util_Map() { String test = "Test string"; @@ -350,12 +279,6 @@ public class AttributedStringTest extends junit.framework.TestCase { return 'a'; } } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "addAttribute", - args = {java.text.AttributedCharacterIterator.Attribute.class, java.lang.Object.class, int.class, int.class} - ) public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_ObjectII() { AttributedString as = new AttributedString("test"); as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, @@ -401,12 +324,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * @tests java.text.AttributedString.addAttribute(AttributedCharacterIterator, * Object) */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "addAttribute", - args = {java.text.AttributedCharacterIterator.Attribute.class, java.lang.Object.class} - ) public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object() { // regression for Harmony-1244 AttributedString as = new AttributedString("123", new WeakHashMap()); @@ -439,12 +356,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * null-attributes to AttributesString. Case 3: Try to add attributes * to AttributesString using incorrect index. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "addAttributes", - args = {java.util.Map.class, int.class, int.class} - ) public void test_addAttributesLjava_util_MapII() { AttributedString as = new AttributedString("test"); Map<AttributedCharacterIterator.Attribute, String> whm = new WeakHashMap<AttributedCharacterIterator.Attribute, String>(); @@ -484,12 +395,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * @tests java.text.AttributedString#getIterator() Test of method * java.text.AttributedString#getIterator(). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIterator", - args = {} - ) public void test_getIterator() { String test = "Test string"; try { @@ -507,12 +412,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * Test of method * java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[]). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIterator", - args = {java.text.AttributedCharacterIterator.Attribute[].class} - ) public void test_getIterator$Ljava_text_AttributedCharacterIterator$Attribute() { String test = "Test string"; try { @@ -544,12 +443,6 @@ public class AttributedStringTest extends junit.framework.TestCase { * java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[], * int, int). */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIterator", - args = {java.text.AttributedCharacterIterator.Attribute[].class, int.class, int.class} - ) public void test_getIterator$Ljava_text_AttributedCharacterIterator$AttributeII() { String test = "Test string"; try { diff --git a/luni/src/test/java/libcore/java/text/OldBidiTest.java b/luni/src/test/java/libcore/java/text/OldBidiTest.java new file mode 100644 index 0000000..2e5fd21 --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldBidiTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.Bidi; +import junit.framework.TestCase; + +public class OldBidiTest extends TestCase { + + Bidi bd; + + public void testToString() { + try { + bd = new Bidi("bidi", 173); + assertNotNull("Bidi representation is null", bd.toString()); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + public void testCreateLineBidi_AndroidFailure() { + // This is a difference between ICU4C and the RI. ICU4C insists that 'limit' is strictly + // greater than 'start'. We have to paper over this in our Java code. + Bidi bidi = new Bidi("str", Bidi.DIRECTION_RIGHT_TO_LEFT); + bidi.createLineBidi(2, 2); + } + + public void testGetRunLevelLInt() { + bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT); + try { + assertEquals(0, bd.getRunLevel(0)); + assertEquals(0, bd.getRunLevel(bd.getRunCount())); + } catch (Exception e) { + fail("Unexpected exception: " + e); + } + + bd = new Bidi("text", Bidi.DIRECTION_RIGHT_TO_LEFT); + try { + assertEquals(2, bd.getRunLevel(0)); + } catch (Exception e) { + fail("Unexpected exception: " + e); + } + + bd = new Bidi("text", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); + try { + assertEquals(0, bd.getRunLevel(0)); + } catch (Exception e) { + fail("Unexpected exception: " + e); + } + } + + public void testGetRunStart() { + bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7, + (byte) -2, (byte) 3 }, 0, 3, + Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); + assertEquals(0, bd.getRunStart(0)); + assertEquals(1, bd.getRunStart(1)); + assertEquals(2, bd.getRunStart(2)); + + String LTR = "\u0061\u0062"; + String RTL = "\u05DC\u05DD"; + String newLine = "\n"; + String defText = LTR + newLine + RTL + LTR + RTL; + + int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 }, }; + + Bidi bi = new Bidi(defText, 0); + + final int count = bi.getRunCount(); + for (int i = 0; i < count; i++) { + assertEquals(expectedRuns[i][0], bi.getRunStart(i)); + } + } +} diff --git a/luni/src/test/java/libcore/java/text/OldBreakIteratorTest.java b/luni/src/test/java/libcore/java/text/OldBreakIteratorTest.java new file mode 100644 index 0000000..45f819b --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldBreakIteratorTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.BreakIterator; +import java.util.Locale; +import junit.framework.TestCase; + +public class OldBreakIteratorTest extends TestCase { + + BreakIterator iterator; + + protected void setUp() throws Exception { + super.setUp(); + iterator = BreakIterator.getCharacterInstance(Locale.US); + } + + public void testGetAvailableLocales() { + Locale[] locales = BreakIterator.getAvailableLocales(); + assertTrue("Array available locales is null", locales != null); + assertTrue("Array available locales is 0-length", + (locales != null && locales.length != 0)); + boolean found = false; + for (Locale l : locales) { + if (l.equals(Locale.US)) { + // expected + found = true; + } + } + assertTrue("At least locale " + Locale.US + " must be presented", found); + } + + public void testGetWordInstanceLocale() { + BreakIterator it1 = BreakIterator.getWordInstance(Locale.CANADA_FRENCH); + assertTrue("Incorrect BreakIterator", it1 != BreakIterator.getWordInstance()); + BreakIterator it2 = BreakIterator.getWordInstance(new Locale("bad locale")); + assertTrue("Incorrect BreakIterator", it2 != BreakIterator.getWordInstance()); + } +} diff --git a/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java b/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java new file mode 100644 index 0000000..9e98a56 --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldCollationElementIteratorTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.CollationElementIterator; +import java.text.Collator; +import java.text.RuleBasedCollator; +import java.util.Locale; +import junit.framework.TestCase; + +public class OldCollationElementIteratorTest extends TestCase { + + public void testPrevious() { + RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US); + String text = "abc"; + CollationElementIterator iterator = coll + .getCollationElementIterator(text); + int[] orders = new int[text.length()]; + int order = iterator.next(); + int i = 0; + while (order != CollationElementIterator.NULLORDER) { + orders[i++] = order; + order = iterator.next(); + } + + int offset = iterator.getOffset(); + assertEquals(text.length(), offset); + order = iterator.previous(); + + while (order != CollationElementIterator.NULLORDER) { + assertEquals(orders[--i], order); + order = iterator.previous(); + } + + assertEquals(0, iterator.getOffset()); + } +} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollationKeyTest.java b/luni/src/test/java/libcore/java/text/OldCollationKeyTest.java index a5ce29e..1fc8264 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollationKeyTest.java +++ b/luni/src/test/java/libcore/java/text/OldCollationKeyTest.java @@ -14,118 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; +package libcore.java.text; import java.text.CollationKey; import java.text.Collator; import java.text.ParseException; import java.text.RuleBasedCollator; -import java.util.Arrays; - -@TestTargetClass(CollationKey.class) -public class CollationKeyTest extends junit.framework.TestCase { - - /** - * @tests java.text.CollationKey#compareTo(java.text.CollationKey) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "compareTo", - args = {java.text.CollationKey.class} - ) - public void test_compareToLjava_text_CollationKey() { - Collator collator = Collator.getInstance(); - collator.setStrength(Collator.PRIMARY); - CollationKey key1 = collator.getCollationKey("abc"); - CollationKey key2 = collator.getCollationKey("ABC"); - assertEquals("Should be equal", 0, key1.compareTo(key2)); - } - /** - * @tests java.text.CollationKey#compareTo(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "compareTo", - args = {java.lang.Object.class} - ) - public void test_compareToLjava_lang_Object() { - // Test for method int - // java.text.CollationKey.compareTo(java.lang.Object) - Collator collator = Collator.getInstance(); - collator.setStrength(Collator.PRIMARY); - CollationKey key1 = collator.getCollationKey("abc"); - CollationKey key2 = collator.getCollationKey("ABC"); - assertEquals("Should be equal", 0, key1.compareTo(key2)); - } - - /** - * @tests java.text.CollationKey#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - Collator collator = Collator.getInstance(); - collator.setStrength(Collator.PRIMARY); - CollationKey key1 = collator.getCollationKey("abc"); - CollationKey key2 = collator.getCollationKey("ABC"); - assertTrue("Should be equal", key1.equals(key2)); - } - - /** - * @tests java.text.CollationKey#getSourceString() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getSourceString", - args = {} - ) - public void test_getSourceString() { - Collator collator = Collator.getInstance(); - collator.setStrength(Collator.PRIMARY); - assertTrue("Wrong source string1", collator.getCollationKey("abc") - .getSourceString() == "abc"); - assertTrue("Wrong source string2", collator.getCollationKey("ABC") - .getSourceString() == "ABC"); - } - - /** - * @tests java.text.CollationKey#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - Collator collator = Collator.getInstance(); - collator.setStrength(Collator.PRIMARY); - CollationKey key1 = collator.getCollationKey("abc"); - CollationKey key2 = collator.getCollationKey("ABC"); - assertTrue("Should be equal", key1.hashCode() == key2.hashCode()); - } +public class OldCollationKeyTest extends junit.framework.TestCase { - /** - * @tests java.text.CollationKey#toByteArray() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "toByteArray", - args = {} - ) public void test_toByteArray() { // Test for method byte [] java.text.CollationKey.toByteArray() Collator collator = Collator.getInstance(); diff --git a/luni/src/test/java/libcore/java/text/OldDateFormatTest.java b/luni/src/test/java/libcore/java/text/OldDateFormatTest.java new file mode 100644 index 0000000..3a3540c --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldDateFormatTest.java @@ -0,0 +1,486 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.DateFormat; +import java.text.FieldPosition; +import java.text.ParseException; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +public class OldDateFormatTest extends junit.framework.TestCase { + + private class MockDateFormat extends DateFormat { + + private static final long serialVersionUID = 1L; + + public MockDateFormat() { + super(); + } + + @Override + public Date parse(String source, ParsePosition pos) { + // it is a fake + return null; + } + + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, + FieldPosition fieldPosition) { + // it is a fake + return null; + } + } + + /** + * @tests java.text.DateFormat#DateFormat() Test of method + * java.text.DateFormat#DateFormat(). + */ + public void test_Constructor() { + try { + new MockDateFormat(); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#equals(java.lang.Object obj) Test of + * java.text.DateFormat#equals(java.lang.Object obj). + */ + public void test_equalsLjava_lang_Object() { + try { + DateFormat format = DateFormat.getInstance(); + DateFormat clone = (DateFormat) format.clone(); + assertTrue("Clone and parent are not equaled", format.equals(clone)); + assertTrue("Clone is equal to other object", !clone + .equals(DateFormat.getTimeInstance())); + format.setCalendar(Calendar.getInstance()); + assertTrue("Clone and parent are not equaled", format.equals(clone)); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#format(java.util.Date) Test of method + * java.text.DateFormat#format(java.util.Date). + */ + public void test_formatLjava_util_Date() { + try { + DateFormat format = DateFormat.getDateTimeInstance( + DateFormat.SHORT, DateFormat.SHORT, Locale.US); + Date current = new Date(); + String dtf = format.format(current); + SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy h:mm a"); + assertTrue("Incorrect date format", sdf.format(current).equals(dtf)); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#format(Object, StringBuffer, FieldPosition) + * Test of method java.text.DateFormat#format(Object, StringBuffer, + * FieldPosition) + */ + public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { + try { + DateFormat format = DateFormat.getDateTimeInstance( + DateFormat.SHORT, DateFormat.SHORT, Locale.US); + Date current = new Date(); + StringBuffer toAppend = new StringBuffer(); + FieldPosition fp = new FieldPosition(DateFormat.YEAR_FIELD); + StringBuffer sb = format.format(current, toAppend, fp); + SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy h:mm a"); + assertTrue("Incorrect date format", sdf.format(current).equals( + sb.toString())); + assertTrue("Incorrect beginIndex of filed position", fp + .getBeginIndex() == sb.lastIndexOf("/") + 1); + assertTrue("Incorrect endIndex of filed position", + fp.getEndIndex() == sb.lastIndexOf("/") + 3); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + public void test_getTimeZone() { + try { + DateFormat format = DateFormat.getInstance(); + TimeZone tz = format.getTimeZone(); + //if(1 == 1) + // throw new Exception(tz.getClass().getName()); + // We know we are not sun.util so: + // Redundant checking + //assertFalse("Incorrect zone info", tz.getClass().getName().equals( + // "sun.util.calendar.ZoneInfo")); + assertTrue("Incorrect time zone", tz.equals(format.getCalendar() + .getTimeZone())); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#hashCode() Test of method + * java.text.DateFormat#hashCode(). + */ + public void test_hashCode() { + try { + DateFormat df1 = DateFormat.getInstance(); + DateFormat df2 = (DateFormat) df1.clone(); + assertTrue("Hash codes of clones are not equal", + df1.hashCode() == df2.hashCode()); + assertTrue("Hash codes of different objects are the same", df1 + .hashCode() != DateFormat.getDateInstance().hashCode()); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#isLenient() Test of method + * java.text.DateFormat#isLenient(). + */ + public void test_isLenient() { + DateFormat df = DateFormat.getInstance(); + Calendar c = df.getCalendar(); + if (df.isLenient()) { + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + c.setLenient(false); + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + // expected + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } else { + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + // expected + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + c.setLenient(true); + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + } + + /** + * @tests java.text.DateFormat#parse(String) + */ + public void test_parseLString() { + DateFormat format = DateFormat.getInstance(); + + try { + format.parse("not a Date"); + fail("should throw ParseException first"); + } catch (ParseException pe) { + assertNotNull(pe.getMessage()); + } + + Date current = new Date(); + + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(current.getHours(), date.getHours()); + assertEquals(current.getMinutes(), date.getMinutes()); + assertEquals(0, date.getSeconds()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + try { + format.parse("27/08/1998"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + try { + format.parse("30/30/908 4:50, PDT"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + try { + format.parse("837039928046"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + format = DateFormat.getDateInstance(); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(0, date.getHours()); + assertEquals(0, date.getMinutes()); + assertEquals(0, date.getSeconds()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + try { + format.parse("Jan 16 1970"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + try { + format.parse("27/08/1998"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + format = DateFormat.getDateInstance(DateFormat.LONG); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(0, date.getHours()); + assertEquals(0, date.getMinutes()); + assertEquals(0, date.getSeconds()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + format = DateFormat.getDateInstance(DateFormat.MEDIUM); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(0, date.getHours()); + assertEquals(0, date.getMinutes()); + assertEquals(0, date.getSeconds()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + format = DateFormat.getTimeInstance(); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(1, date.getDate()); + assertEquals(0, date.getMonth()); + assertEquals(70, date.getYear()); + assertEquals(current.getHours(), date.getHours()); + assertEquals(current.getMinutes(), date.getMinutes()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + try { + format.parse("8:58:44"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + format = DateFormat.getDateTimeInstance(); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(current.getHours(), date.getHours()); + assertEquals(current.getMinutes(), date.getMinutes()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + try { + format.parse("January 31 1970 7:52:34 AM PST"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + try { + format.parse("January 31 1970"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + + format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); + try { + Date date = format.parse(format.format(current).toString()); + assertEquals(current.getDate(), date.getDate()); + assertEquals(current.getDay(), date.getDay()); + assertEquals(current.getMonth(), date.getMonth()); + assertEquals(current.getYear(), date.getYear()); + assertEquals(current.getHours(), date.getHours()); + assertEquals(current.getMinutes(), date.getMinutes()); + } catch(ParseException pe) { + fail("ParseException was thrown for current Date."); + } + + try { + format.parse("January 16, 1970 8:03:52 PM CET"); + fail("ParseException was not thrown."); + } catch(ParseException pe) { + //expected + } + } + + /** + * @tests java.text.DateFormat#parseObject(String, ParsePosition) Test of + * method java.text.DateFormat#parseObject(String, ParsePosition). + * Case 1: Try to parse correct data string. Case 2: Try to parse + * partialy correct data string. Case 3: Try to use argument + * ParsePosition as null. + */ + public void test_parseObjectLjava_lang_StringLjava_text_ParsePosition() { + DateFormat df = DateFormat.getInstance(); + try { + // case 1: Try to parse correct data string. + Date current = new Date(); + ParsePosition pp = new ParsePosition(0); + int parseIndex = pp.getIndex(); + Date result = (Date) df.parseObject(df.format(current), pp); + + assertEquals("Dates are different.", current.getDate(), result.getDate()); + assertEquals("Days are different.", current.getDay(), result.getDay()); + assertEquals("Months are different.", current.getMonth(), result.getMonth()); + assertEquals("Years are different.", current.getYear(), result.getYear()); + assertEquals("Hours are different", current.getHours(), result.getHours()); + assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes()); + + assertTrue("Parse operation return null", result != null); + assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex); + + // case 2: Try to parse partially correct data string. + pp.setIndex(0); + char[] cur = df.format(current).toCharArray(); + cur[cur.length / 2] = 'Z'; + String partialCorrect = new String(cur); + result = (Date) df.parseObject(partialCorrect, pp); + assertTrue("Parse operation return not-null", result == null); + assertTrue("ParseIndex is incorrect", pp.getIndex() == 0); + assertTrue("ParseErrorIndex is incorrect", + pp.getErrorIndex() == cur.length / 2); + + pp.setIndex(2); + char[] curDate = df.format(current).toCharArray(); + char [] newArray = new char[curDate.length + pp.getIndex()]; + for(int i = 0; i < curDate.length; i++) { + newArray[i + pp.getIndex()] = curDate[i]; + } + result = (Date) df.parseObject(new String(newArray), pp); + //assertEquals(current, result); + + assertEquals("Dates are different.", current.getDate(), result.getDate()); + assertEquals("Days are different.", current.getDay(), result.getDay()); + assertEquals("Months are different.", current.getMonth(), result.getMonth()); + assertEquals("Years are different.", current.getYear(), result.getYear()); + assertEquals("Hours are different", current.getHours(), result.getHours()); + assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes()); + + // case 3: Try to use argument ParsePosition as null. + try { + df.parseObject(df.format(current), null); + fail("Expected NullPointerException was not thrown"); + } catch (NullPointerException e) { + // expected + } + + assertNull(df.parseObject("test", pp)); + + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#setLenient(boolean) Test of method + * java.text.DateFormat#setLenient(boolean). + */ + public void test_setLenientZ() { + DateFormat df = DateFormat.getInstance(); + Calendar c = df.getCalendar(); + try { + c.setLenient(true); + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + c.setLenient(false); + try { + c.set(Calendar.DAY_OF_MONTH, 32); + c.get(Calendar.DAY_OF_MONTH); + fail("Expected IllegalArgumentException was not thrown"); + } catch (IllegalArgumentException e) { + // expected + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } catch (Exception e) { + fail("Uexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.DateFormat#setTimeZone(TimeZone) Test of method + * java.text.DateFormat#setTimeZone(TimeZone). + */ + public void test_setTimeZoneLjava_util_TimeZone() { + try { + DateFormat format = DateFormat.getInstance(); + TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); + format.setTimeZone(tz); + assertTrue("TimeZone is set incorrectly", tz.equals(format + .getTimeZone())); + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } +} diff --git a/luni/src/test/java/libcore/java/text/OldDecimalFormatSymbolsTest.java b/luni/src/test/java/libcore/java/text/OldDecimalFormatSymbolsTest.java new file mode 100644 index 0000000..0a6b77b --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldDecimalFormatSymbolsTest.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.io.ObjectInputStream; +import java.text.DecimalFormatSymbols; +import java.util.Locale; +import junit.framework.TestCase; + +public class OldDecimalFormatSymbolsTest extends TestCase { + + DecimalFormatSymbols dfs; + + protected void setUp() { + dfs = new DecimalFormatSymbols(); + } + + public void test_RIHarmony_compatible() throws Exception { + ObjectInputStream i = null; + try { + DecimalFormatSymbols symbols = new DecimalFormatSymbols( + Locale.FRANCE); + i = new ObjectInputStream( + getClass() + .getClassLoader() + .getResourceAsStream( + "serialization/java/text/DecimalFormatSymbols.ser")); + DecimalFormatSymbols symbolsD = (DecimalFormatSymbols) i + .readObject(); + assertEquals(symbols, symbolsD); + } catch(NullPointerException e) { + assertNotNull("Failed to load /serialization/java/text/" + + "DecimalFormatSymbols.ser", i); + } finally { + try { + if (i != null) { + i.close(); + } + } catch (Exception e) { + } + } + assertDecimalFormatSymbolsRIFrance(dfs); + } + + + public void test_Constructor() { + new DecimalFormatSymbols(); + } + + /** + * @tests java.text.DecimalFormatSymbols#DecimalFormatSymbols(java.util.Locale) + */ + public void test_ConstructorLjava_util_Locale() { + try { + new DecimalFormatSymbols(null); + fail("NullPointerException was not thrown."); + } catch(NullPointerException npe) { + //expected + } + } + + public void test_getMonetaryDecimalSeparator() { + dfs.setMonetaryDecimalSeparator(','); + assertEquals("Returned incorrect MonetaryDecimalSeparator symbol", + ',', dfs.getMonetaryDecimalSeparator()); + } + + public void test_hashCode() { + DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(); + DecimalFormatSymbols dfs2 = (DecimalFormatSymbols) dfs1.clone(); + assertTrue("Hash codes of equal object are equal", dfs2 + .hashCode() == dfs1.hashCode()); + dfs1.setInfinity("infinity_infinity"); + assertTrue("Hash codes of non-equal objects are equal", dfs2 + .hashCode() != dfs1.hashCode()); + } + + public void test_clone() { + // case 1: Compare of internal variables of cloned objects + DecimalFormatSymbols fs = new DecimalFormatSymbols(Locale.US); + DecimalFormatSymbols fsc = (DecimalFormatSymbols) fs.clone(); + assertEquals(fs.getCurrency(), fsc.getCurrency()); + + // case 2: Compare of clones + fs = new DecimalFormatSymbols(); + DecimalFormatSymbols fsc2 = (DecimalFormatSymbols) (fs.clone()); + // make sure the objects are equal + assertTrue("Object's clone isn't equal!", fs.equals(fsc2)); + + // case 3: + // change the content of the clone and make sure it's not equal + // anymore + // verifies that it's data is now distinct from the original + fs.setNaN("not-a-number"); + assertTrue("Object's changed clone should not be equal!", !fs.equals(fsc2)); + } + + public void test_setCurrencySymbolLjava_lang_String() { + dfs.setCurrencySymbol("$"); + assertEquals("Returned incorrect CurrencySymbol symbol", "$", dfs.getCurrencySymbol()); + } + + public void test_setMonetaryDecimalSeparatorC() { + dfs.setMonetaryDecimalSeparator('#'); + assertEquals("Returned incorrect MonetaryDecimalSeparator symbol", + '#', dfs.getMonetaryDecimalSeparator()); + } + + static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) { + // Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE + /* + * currency = [EUR] + * currencySymbol = [U+20ac] // EURO SIGN + * decimalSeparator = [,][U+002c] + * digit = [#][U+0023] + * groupingSeparator = [U+00a0] // NON-BREAKING SPACE + * infinity = [U+221e] // INFINITY + * internationalCurrencySymbol = [EUR] + * minusSign = [-][U+002d] + * monetaryDecimalSeparator = [,][U+002c] + * naN = [U+fffd] // REPLACEMENT CHARACTER + * patternSeparator = [;][U+003b] + * perMill = [U+2030] // PER MILLE + * percent = [%][U+0025] + * zeroDigit = [0][U+0030] + */ + assertEquals("EUR", dfs.getCurrency().getCurrencyCode()); + assertEquals("\u20AC", dfs.getCurrencySymbol()); + assertEquals(',', dfs.getDecimalSeparator()); + assertEquals('#', dfs.getDigit()); + assertEquals('\u00a0', dfs.getGroupingSeparator()); + assertEquals("\u221e", dfs.getInfinity()); + assertEquals("EUR", dfs.getInternationalCurrencySymbol()); + assertEquals('-', dfs.getMinusSign()); + assertEquals(',', dfs.getMonetaryDecimalSeparator()); + // RI's default NaN is U+FFFD, Harmony's is based on ICU + // This suggests an RI bug, assuming that non-UTF8 bytes are UTF8 and + // getting a conversion failure. + assertEquals("\uFFFD", dfs.getNaN()); + assertEquals('\u003b', dfs.getPatternSeparator()); + assertEquals('\u2030', dfs.getPerMill()); + assertEquals('%', dfs.getPercent()); + assertEquals('0', dfs.getZeroDigit()); + } +} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTestICU.java b/luni/src/test/java/libcore/java/text/OldDecimalFormatTestICU.java index 7f61077..205faac 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTestICU.java +++ b/luni/src/test/java/libcore/java/text/OldDecimalFormatTestICU.java @@ -14,19 +14,12 @@ * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.AndroidOnly; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; +package libcore.java.text; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; +import junit.framework.TestCase; /** * Test for additional features introduced by icu. These tests fail on the RI @@ -34,8 +27,7 @@ import java.util.Locale; * pattern. Api methods where not introduced to allow direct access of these * features. This would have changed the api too much. */ -@TestTargetClass(DecimalFormat.class) -public class DecimalFormatTestICU extends TestCase { +public class OldDecimalFormatTestICU extends TestCase { DecimalFormat format; @@ -43,21 +35,7 @@ public class DecimalFormatTestICU extends TestCase { format = (DecimalFormat) NumberFormat.getNumberInstance(); } - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Regression test.", - method = "format", - args = {java.lang.Object.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Regression test.", - method = "parse", - args = {java.lang.String.class} - ) - }) - @AndroidOnly("special feature of icu4c") + // AndroidOnly: special feature of icu4c public void test_sigDigitPatterns() throws Exception { DecimalFormat format = (DecimalFormat) NumberFormat .getInstance(Locale.US); @@ -92,21 +70,7 @@ public class DecimalFormatTestICU extends TestCase { } } - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Regression test.", - method = "format", - args = {java.lang.Object.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Regression test.", - method = "parse", - args = {java.lang.String.class} - ) - }) - @AndroidOnly("special feature of icu4c") + // AndroidOnly: special feature of icu4c public void test_paddingPattern() throws Exception { format.applyPattern("*x##,##,#,##0.0#"); assertEquals("xxxxxxxxx123.0", format.format(123)); @@ -139,21 +103,7 @@ public class DecimalFormatTestICU extends TestCase { } } - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Regression test.", - method = "format", - args = {java.lang.Object.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Regression test.", - method = "parse", - args = {java.lang.String.class} - ) - }) - @AndroidOnly("special feature of icu4c") + // AndroidOnly: special feature of icu4c public void test_positiveExponentSign() throws Exception { format.applyPattern("0.###E+0"); assertEquals("1E+2", format.format(100)); @@ -182,21 +132,7 @@ public class DecimalFormatTestICU extends TestCase { } } - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Verifies the grouping size.", - method = "format", - args = {java.lang.Object.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Verifies the grouping size.", - method = "parse", - args = {java.lang.String.class} - ) - }) - @AndroidOnly("special feature of icu4c") + // AndroidOnly: special feature of icu4c public void test_secondaryGroupingSize() throws Exception { format.applyPattern("#,##,###,####"); assertEquals("123,456,7890", format.format(1234567890)); diff --git a/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java b/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java new file mode 100644 index 0000000..b6fbd98 --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.DateFormat; +import java.text.FieldPosition; + +public class OldFieldPositionTest extends junit.framework.TestCase { + + public void test_hashCode() { + // Test for method int java.text.FieldPosition.hashCode() + FieldPosition fpos1 = new FieldPosition(1); + FieldPosition fpos2 = new FieldPosition(1); + assertTrue("test 1: hash codes are not equal for equal objects.", + fpos1.hashCode() == fpos2.hashCode()); + fpos1.setBeginIndex(5); + fpos1.setEndIndex(110); + assertTrue("test 2: hash codes are equal for non equal objects.", + fpos1.hashCode() != fpos2.hashCode()); + fpos2.setBeginIndex(5); + fpos2.setEndIndex(110); + assertTrue("test 3: hash codes are not equal for equal objects.", + fpos1.hashCode() == fpos2.hashCode()); + + FieldPosition fpos3 = new FieldPosition( + DateFormat.Field.DAY_OF_WEEK_IN_MONTH); + + assertTrue("test 4: hash codes are equal for non equal objects.", + fpos2.hashCode() != fpos3.hashCode()); + } + + public void test_setBeginIndexI() { + // Test for method void java.text.FieldPosition.setBeginIndex(int) + FieldPosition fpos = new FieldPosition(1); + fpos.setBeginIndex(2); + fpos.setEndIndex(3); + assertEquals("beginIndex should have been set to 2", 2, fpos + .getBeginIndex()); + + fpos.setBeginIndex(Integer.MAX_VALUE); + assertEquals("beginIndex should have been set to Integer.MAX_VALUE", + Integer.MAX_VALUE, fpos.getBeginIndex()); + + fpos.setBeginIndex(-1); + assertEquals("beginIndex should have been set to -1", + -1, fpos.getBeginIndex()); + } + + public void test_setEndIndexI() { + // Test for method void java.text.FieldPosition.setEndIndex(int) + FieldPosition fpos = new FieldPosition(1); + fpos.setEndIndex(3); + fpos.setBeginIndex(2); + assertEquals("EndIndex should have been set to 3", 3, fpos + .getEndIndex()); + + fpos.setEndIndex(Integer.MAX_VALUE); + assertEquals("endIndex should have been set to Integer.MAX_VALUE", + Integer.MAX_VALUE, fpos.getEndIndex()); + + fpos.setEndIndex(-1); + assertEquals("endIndex should have been set to -1", + -1, fpos.getEndIndex()); + } +} diff --git a/luni/src/test/java/tests/text/AllTests.java b/luni/src/test/java/libcore/java/text/OldFormatFieldTest.java index 0a77e67..e5d8e31 100644 --- a/luni/src/test/java/tests/text/AllTests.java +++ b/luni/src/test/java/libcore/java/text/OldFormatFieldTest.java @@ -15,21 +15,22 @@ * limitations under the License. */ -package tests.text; +package libcore.java.text; -import junit.framework.Test; -import junit.framework.TestSuite; +import java.text.Format; +import junit.framework.TestCase; -/** - * Test suite that includes all tests for the Text project. - * - */ -public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("All Text test suites"); - // $JUnit-BEGIN$ - suite.addTest(org.apache.harmony.text.tests.java.text.AllTests.suite()); - // $JUnit-END$ - return suite; +public class OldFormatFieldTest extends TestCase { + private class MockFormatField extends Format.Field { + + private static final long serialVersionUID = 1L; + + public MockFormatField(String name) { + super(name); + } + } + + public void test_Constructor() { + new MockFormatField("test"); } } diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FormatTest.java b/luni/src/test/java/libcore/java/text/OldFormatTest.java index 20862ef..0c74749 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FormatTest.java +++ b/luni/src/test/java/libcore/java/text/OldFormatTest.java @@ -15,24 +15,17 @@ * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; +package libcore.java.text; import java.text.AttributedCharacterIterator; import java.text.FieldPosition; import java.text.Format; import java.text.ParseException; import java.text.ParsePosition; +import junit.framework.TestCase; -@TestTargetClass(Format.class) -public class FormatTest extends TestCase { +public class OldFormatTest extends TestCase { private class MockFormat extends Format { public StringBuffer format(Object obj, StringBuffer toAppendTo, @@ -49,78 +42,30 @@ public class FormatTest extends TestCase { } } - /** - * @tests java.text.Format#format(Object) Test of method - * java.text.Format#format(Object). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Format", - args = {} - ) public void test_Constructor() { - try { - new MockFormat(); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } + new MockFormat(); } /** * @tests java.text.Format#clone() Test of method java.text.Format#clone(). * Compare of internal variables of cloned objects. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) public void test_clone() { - try { - // Compare of internal variables of cloned objects - Format fm = new MockFormat(); - Format fmc = (Format) fm.clone(); - assertEquals(fm.getClass(), fmc.getClass()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } + // Compare of internal variables of cloned objects + Format fm = new MockFormat(); + Format fmc = (Format) fm.clone(); + assertEquals(fm.getClass(), fmc.getClass()); } - /** - * @tests java.text.Format#format(java.lang.Object) Test of method - * java.text.Format#format(java.lang.Object). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Verifies that format(Object) calls format(Object, StringBuffer, FieldPosition) method.", - method = "format", - args = {java.lang.Object.class} - ) public void test_formatLjava_lang_Object() { - MockFormat mf = new MockFormat(); assertEquals("", mf.format("")); assertTrue("It calls an abstract metod format", true); } - /** - * @tests java.text.Format#formatToCharacterIterator(java.lang.Object) Test - * of method - * java.text.Format#formatToCharacterIterator(java.lang.Object). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "formatToCharacterIterator", - args = {java.lang.Object.class} - ) public void test_formatToCharacterIteratorLjava_lang_Object() { - MockFormat mf = new MockFormat(); - AttributedCharacterIterator aci = - mf.formatToCharacterIterator("Test 123 Test"); + AttributedCharacterIterator aci = mf.formatToCharacterIterator("Test 123 Test"); assertEquals(0, aci.getBeginIndex()); @@ -138,16 +83,6 @@ public class FormatTest extends TestCase { } } - /** - * @tests java.text.Format#parseObject(java.lang.String source) Test of - * method java.text.Format#parseObject(java.lang.String source). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Verifies that parseObject(String) method calls parseObject(String source, ParsePosition pos) method.", - method = "parseObject", - args = {java.lang.String.class} - ) public void test_parseObjectLjava_lang_String() { MockFormat mf = new MockFormat(); try { diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java b/luni/src/test/java/libcore/java/text/OldMessageFormatFieldTest.java index 5826924..3e60ef8 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java +++ b/luni/src/test/java/libcore/java/text/OldMessageFormatFieldTest.java @@ -14,14 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; +package libcore.java.text; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,18 +23,10 @@ import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.text.MessageFormat; +import junit.framework.TestCase; + +public class OldMessageFormatFieldTest extends TestCase { -@TestTargetClass(MessageFormat.Field.class) -public class MessageFormatFieldTest extends TestCase { - /** - * @tests java.text.MessageFormat$Field#Field(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class} - ) public void test_ConstructorLjava_lang_String() { // protected constructor String name = "new Message format"; @@ -52,15 +37,6 @@ public class MessageFormatFieldTest extends TestCase { assertEquals("field has wrong name", null, field.getName()); } - /** - * @tests java.text.MessageFormat$Field#readResolve() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "readResolve", - args = {} - ) public void test_readResolve() { // test for method java.lang.Object readResolve() diff --git a/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java b/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java new file mode 100644 index 0000000..7a80c80 --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldMessageFormatTest.java @@ -0,0 +1,462 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.ChoiceFormat; +import java.text.DateFormat; +import java.text.FieldPosition; +import java.text.Format; +import java.text.MessageFormat; +import java.text.NumberFormat; +import java.text.ParseException; +import java.text.ParsePosition; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; +import junit.framework.TestCase; +import tests.support.Support_MessageFormat; + +public class OldMessageFormatTest extends TestCase { + + private MessageFormat format1; + + protected void setUp() { + Locale.setDefault(Locale.US); + + // test with repeating formats and max argument index < max offset + String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}"; + format1 = new MessageFormat(pattern); + } + + public void test_applyPatternLjava_lang_String_AndroidFailure() { + MessageFormat format = new MessageFormat("test"); + format.setLocale(Locale.FRENCH); // use French since English has the + // same LONG and FULL time patterns + format.applyPattern("{0,time, Full}"); + assertEquals("Wrong full time pattern", "{0,time,full}", format + .toPattern()); + } + + public void test_formatToCharacterIteratorLjava_lang_Object() { + // Test for method formatToCharacterIterator(java.lang.Object) + new Support_MessageFormat( + "test_formatToCharacterIteratorLjava_lang_Object") + .t_formatToCharacterIterator(); + + try { + new MessageFormat("{1, number}").formatToCharacterIterator(null); + fail("NullPointerException was not thrown."); + } catch(NullPointerException npe) { + //expected + } + + try { + new MessageFormat("{0, time}").formatToCharacterIterator(new Object[]{""}); + fail("IllegalArgumentException was not thrown."); + } catch(IllegalArgumentException iae) { + //expected + } + } + + public void test_getLocale() { + try { + Locale[] l = { + Locale.FRANCE, + Locale.KOREA, + new Locale(Locale.FRANCE.getCountry(), Locale.FRANCE + .getLanguage()), new Locale("mk"), + new Locale("mk", "MK"), Locale.US, + new Locale("#ru", "@31230") }; + + String pattern = "getLocale test {0,number,#,####}"; + MessageFormat mf; + + for (int i = 0; i < 0; i++) { + mf = new MessageFormat(pattern, l[i]); + Locale result = mf.getLocale(); + assertEquals("Returned local: " + result + " instead of " + + l[i], l[i], result); + assertEquals("Returned language: " + result.getLanguage() + + " instead of " + l[i].getLanguage(), l[i] + .getLanguage(), result.getLanguage()); + assertEquals("Returned country: " + result.getCountry() + + " instead of " + l[i].getCountry(), + l[i].getCountry(), result.getCountry()); + } + + mf = new MessageFormat(pattern); + mf.setLocale(null); + Locale result = mf.getLocale(); + assertEquals("Returned local: " + result + " instead of null", + null, result); + } catch (Exception e) { + fail("unexpected exception " + e.toString()); + } + } + + /** + * @tests java.text.MessageFormat#setFormat(int, Format) Test of method + * java.text.MessageFormat#setFormat(int, Format). Case 1: Compare + * getFormats() results after calls to setFormat(). Case 2: Try to + * call setFormat() using incorrect index. + */ + public void test_setFormatILjava_text_Format() { + try { + // case 1: Compare getFormats() results after calls to setFormat() + MessageFormat f1 = (MessageFormat) format1.clone(); + f1.setFormat(0, DateFormat.getTimeInstance()); + f1.setFormat(1, DateFormat.getTimeInstance()); + f1.setFormat(2, NumberFormat.getInstance()); + f1.setFormat(3, new ChoiceFormat("0#off|1#on")); + f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot")); + f1.setFormat(5, DateFormat.getTimeInstance()); + + Format[] formats = f1.getFormats(); + formats = f1.getFormats(); + + Format[] correctFormats = new Format[] { + DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), + NumberFormat.getInstance(), new ChoiceFormat("0#off|1#on"), + new ChoiceFormat("1#few|2#ok|3#a lot"), + DateFormat.getTimeInstance() }; + + assertEquals("Test1A:Returned wrong number of formats:", + correctFormats.length, formats.length); + for (int i = 0; i < correctFormats.length; i++) { + assertEquals( + "Test1B:wrong format for pattern index " + i + ":", + correctFormats[i], formats[i]); + } + + // case 2: Try to setFormat using incorrect index + try { + f1.setFormat(-1, DateFormat.getDateInstance()); + fail("Expected ArrayIndexOutOfBoundsException was not thrown"); + f1.setFormat(f1.getFormats().length, DateFormat + .getDateInstance()); + fail("Expected ArrayIndexOutOfBoundsException was not thrown"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { + // Test for method java.lang.StringBuffer + // java.text.MessageFormat.format(java.lang.Object [], + // java.lang.StringBuffer, java.text.FieldPosition) + MessageFormat format = new MessageFormat("{1,number,integer}"); + StringBuffer buffer = new StringBuffer(); + format.format(new Object[] { "0", new Double(53.863) }, buffer, + new FieldPosition(MessageFormat.Field.ARGUMENT)); + assertEquals("Wrong result", "54", buffer.toString()); + + format.format(new Object[] { "0", new Double(53.863) }, buffer, + new FieldPosition(MessageFormat.Field.ARGUMENT)); + + assertEquals("Wrong result", "5454", buffer.toString()); + + buffer = new StringBuffer(); + format + .applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}"); + Date date = new Date(); + String expected = "one two " + + DateFormat.getTimeInstance().format(date); + format.format(new Object[] { new Double(1.6), + new Integer(3), date }, buffer, new FieldPosition(MessageFormat + .Field.ARGUMENT)); + assertEquals("Choice not recursive:\n" + expected + "\n" + buffer, + expected, buffer.toString()); + + StringBuffer str = format.format(new Object[] { new Double(0.6), + new Integer(3)}, buffer, null); + + assertEquals(expected + "zero", str.toString()); + assertEquals(expected + "zero", buffer.toString()); + + try { + format.format(new Object[] { "0", new Double(1), "" }, buffer, + new FieldPosition(MessageFormat.Field.ARGUMENT)); + fail("IllegalArgumentException was not thrown."); + } catch(IllegalArgumentException iae) { + //expected + } + + try { + format.format(new Object[] { "", new Integer(3)}, buffer, + new FieldPosition(MessageFormat.Field.ARGUMENT)); + fail("IllegalArgumentException was not thrown."); + } catch(IllegalArgumentException iae) { + //expected + } + } + + public void test_formatLjava_lang_StringLjava_lang_Object() { + int iCurrency = 123; + int iInteger = Integer.MIN_VALUE; + + Date date = new Date(12345678); + Object[] args = { date, iCurrency, iInteger }; + String resStr = "Date: Jan 1, 1970 Currency: $" + iCurrency + + ".00 Integer: -2,147,483,648"; + String pattern = "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}"; + String sFormat = MessageFormat.format(pattern, (Object[]) args); + assertEquals( + "format(String, Object[]) with valid parameters returns incorrect string: case 1", + sFormat, resStr); + + pattern = "abc {4, number, integer} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}"; + resStr = "abc -2,147,483,648 def Jan 1, 1970 ghi -2,147,483,648 jkl high mnop -2,147,483,648"; + Object[] args_ = { iInteger, 1, iInteger, date, iInteger }; + sFormat = MessageFormat.format(pattern, args_); + assertEquals( + "format(String, Object[]) with valid parameters returns incorrect string: case 1", + sFormat, resStr); + + try { + args = null; + MessageFormat.format(null, args); + fail("Doesn't throw IllegalArgumentException: null, null"); + } catch (Exception e) { + // expected + } + + try { + MessageFormat.format("Invalid {1,foobar} format descriptor!", + new Object[] {iInteger} ); + fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 1"); + } catch (IllegalArgumentException ex) { + // expected + } + + try { + MessageFormat.format( + "Invalid {1,date,invalid-spec} format descriptor!", new Object[]{""}); + fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 2"); + } catch (IllegalArgumentException ex) { + // expected + } + + try { + MessageFormat.format("{0,number,integer", new Object[] {iInteger}); + fail("Doesn't throw IllegalArgumentException, doesn't detect unmatched brackets"); + } catch (IllegalArgumentException ex) { + // expected + } + + try { + MessageFormat.format( + "Valid {1, date} format {0, number} descriptor!", new Object[]{ "" } ); + fail("Doesn't throw IllegalArgumentException with invalid Object array"); + } catch (IllegalArgumentException ex) { + // expected + } + } + + public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { + // Test for method java.lang.StringBuffer + // java.text.MessageFormat.format(java.lang.Object, + // java.lang.StringBuffer, java.text.FieldPosition) + new Support_MessageFormat( + "test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition") + .t_format_with_FieldPosition(); + + String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} " + + "hamburger{2,choice,1#|1<s}."; + MessageFormat format = new MessageFormat(pattern, Locale.US); + + Object[] objects = new Object[] { "", new Integer(3), 8, ""}; + + try { + format.format(objects, new StringBuffer(), + new FieldPosition(DateFormat.Field.AM_PM)); + fail("IllegalArgumentException was not thrown."); + } catch(IllegalArgumentException iae) { + //expected + } + } + + public void test_setFormats$Ljava_text_Format() { + try { + MessageFormat f1 = (MessageFormat) format1.clone(); + + // case 1: Test with repeating formats and max argument index < max + // offset + // compare getFormats() results after calls to setFormats(Format[]) + Format[] correctFormats = new Format[] { + DateFormat.getTimeInstance(), + new ChoiceFormat("0#off|1#on"), + DateFormat.getTimeInstance(), + NumberFormat.getCurrencyInstance(), + new ChoiceFormat("1#few|2#ok|3#a lot") }; + + f1.setFormats(correctFormats); + Format[] formats = f1.getFormats(); + + assertTrue("Test1A:Returned wrong number of formats:", + correctFormats.length <= formats.length); + for (int i = 0; i < correctFormats.length; i++) { + assertEquals("Test1B:wrong format for argument index " + i + + ":", correctFormats[i], formats[i]); + } + + // case 2: Try to pass null argument to setFormats(). + try { + f1.setFormats(null); + fail("Expected exception NullPointerException was not thrown"); + } catch (NullPointerException e) { + // expected + } + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + public void test_parseLjava_lang_String() throws ParseException { + String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}"; + MessageFormat mf = new MessageFormat(pattern); + String sToParse = "A $12,345.00 B 9:56:07 AM C 3,200% D 1/15/70 9:56 AM E on F Jan 1, 1970"; + Object[] result; + try { + result = mf.parse(sToParse); + + assertTrue("No result: " + result.length, result.length == 5); + assertTrue("Object 0 is not date", result[0] instanceof Date); + assertEquals("Object 1 is not stringr", result[1].toString(), "1.0"); + assertTrue("Object 2 is not date", result[2] instanceof Date); + assertEquals("Object 3 is not number", result[3].toString(), + "12345"); + assertEquals("Object 4 is not string", result[4].toString(), + "1/15/70 9:56 AM"); + + } catch (java.text.ParseException pe) { + fail("ParseException is thrown for incorrect string " + sToParse); + } + + sToParse = "xxdate is Feb 28, 1999"; + try { + result = format1.parse(sToParse); + fail("ParseException is thrown for incorrect string " + sToParse); + } catch (java.text.ParseException pe) { + // expected + } + + sToParse = "vm=Test, @3 4 6, 3 "; + mf = new MessageFormat("vm={0},{1},{2}"); + try { + result = mf.parse(sToParse); + assertTrue("No result: " + result.length, result.length == 3); + assertEquals("Object 0 is not string", result[0].toString(), "Test"); + assertEquals("Object 1 is not string", result[1].toString(), + " @3 4 6"); + assertEquals("Object 2 is not string", result[2].toString(), + " 3 "); + } catch (java.text.ParseException pe) { + fail("ParseException is thrown for correct string " + sToParse); + } + + try { + result = mf.parse(null); + fail("ParseException is not thrown for null " + sToParse); + } catch (java.text.ParseException pe) { + // expected + } + } + + /** + * @tests java.text.MessageFormat#parseObject(java.lang.String, + * java.text.ParsePosition) Test of method + * java.text.MessageFormat#parseObject(java.lang.String, + * java.text.ParsePosition). Case 1: Parsing of correct data string. + * Case 2: Parsing of partial correct data string. Case 3: Try to use + * argument ParsePosition as null. + */ + public void test_parseObjectLjava_lang_StringLjavajava_text_ParsePosition() { + MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}"); + try { + // case 1: Try to parse correct data string. + Object[] objs = { new Double(3.1415) }; + String result = mf.format(objs); + // result now equals "3.14, 3.1" + Object[] res = null; + ParsePosition pp = new ParsePosition(0); + int parseIndex = pp.getIndex(); + res = (Object[]) mf.parseObject(result, pp); + assertTrue("Parse operation return null", res != null); + assertTrue("parse operation return array with incorrect length", + 1 == res.length); + assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex); + assertTrue("Result object is incorrect", new Double(3.1) + .equals(res[0])); + + // case 2: Try to parse partially correct data string. + pp.setIndex(0); + char[] cur = result.toCharArray(); + cur[cur.length / 2] = 'Z'; + String partialCorrect = new String(cur); + res = (Object[]) mf.parseObject(partialCorrect, pp); + assertTrue("Parse operation return null", res == null); + assertTrue("ParseIndex is incorrect", pp.getIndex() == 0); + assertTrue("ParseErrorIndex is incorrect", + pp.getErrorIndex() == cur.length / 2); + + // case 3: Try to use argument ParsePosition as null. + try { + mf.parseObject(result, null); + fail("Expected NullPointerException was not thrown"); + } catch (NullPointerException e) { + // expected + } + } catch (Exception e) { + fail("Unexpected exception " + e.toString()); + } + } + + public void test_format_Object() { + // Regression for HARMONY-1875 + Locale.setDefault(Locale.CANADA); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + String pat = "text here {0,date,yyyyyyyyy} and here"; + Calendar c = Calendar.getInstance(); + String etalon = "text here 00000" + c.get(Calendar.YEAR) + " and here"; + MessageFormat obj = new MessageFormat(pat); + assertEquals(etalon, obj.format(new Object[] { new Date() })); + } + + public void test_parseLjava_lang_StringLjava_text_ParsePosition() { + ParsePosition pos = new ParsePosition(2); + + MessageFormat mf = new MessageFormat("{0}; {0}; {0}"); + String parse = "a; b; c"; + try { + mf.parse(parse, null); + fail("NullPointerException was not thrown."); + } catch(NullPointerException npe) { + //expected + } + + try { + mf.parse(null, pos); + } catch(NullPointerException npe) { + fail("NullPointerException was thrown."); + } + } +} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java b/luni/src/test/java/libcore/java/text/OldNumberFormatFieldTest.java index b4c484a..7c92bc2 100644 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java +++ b/luni/src/test/java/libcore/java/text/OldNumberFormatFieldTest.java @@ -14,13 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; +package libcore.java.text; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -30,17 +24,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.text.NumberFormat; -@TestTargetClass(NumberFormat.Field.class) -public class NumberFormatFieldTest extends junit.framework.TestCase { - /** - * @tests java.text.NumberFormat$Field#Field(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class} - ) +public class OldNumberFormatFieldTest extends junit.framework.TestCase { + public void test_ConstructorLjava_lang_String() { // protected constructor String name = "new number format"; @@ -51,15 +36,6 @@ public class NumberFormatFieldTest extends junit.framework.TestCase { assertEquals("field has wrong name", null, field.getName()); } - /** - * @tests java.text.NumberFormat$Field#readResolve() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "readResolve", - args = {} - ) public void test_readResolve() { // test for method java.lang.Object readResolve() diff --git a/luni/src/test/java/libcore/java/text/OldParsePositionTest.java b/luni/src/test/java/libcore/java/text/OldParsePositionTest.java new file mode 100644 index 0000000..4d67711 --- /dev/null +++ b/luni/src/test/java/libcore/java/text/OldParsePositionTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 libcore.java.text; + +import java.text.ParsePosition; + +public class OldParsePositionTest extends junit.framework.TestCase { + + ParsePosition pp = new ParsePosition(Integer.MAX_VALUE); + + public void test_hashCode() { + // Test for method int java.text.ParsePosition.hashCode() + ParsePosition pp1 = new ParsePosition(0); + ParsePosition pp2 = new ParsePosition(0); + assertTrue("hashCode returns non equal hash codes for equal objects.", + pp1.hashCode() == pp2.hashCode()); + pp1.setIndex(Integer.MAX_VALUE); + assertTrue("hashCode returns equal hash codes for non equal objects.", + pp1.hashCode() != pp2.hashCode()); + } + + public void test_getErrorIndex() { + // Test for method int java.text.ParsePosition.getErrorIndex() + pp.setErrorIndex(56); + assertEquals("getErrorIndex failed.", 56, pp.getErrorIndex()); + pp.setErrorIndex(Integer.MAX_VALUE); + assertEquals("getErrorIndex failed.", Integer.MAX_VALUE, + pp.getErrorIndex()); + assertEquals("getErrorIndex failed.", Integer.MAX_VALUE, + pp.getErrorIndex()); + } +} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AllTests.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/AllTests.java deleted file mode 100644 index fa5edc5..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AllTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("Suite org.apache.harmony.text.tests.java.text"); - //$JUnit-BEGIN$ - suite.addTestSuite(AnnotationTest.class); - suite.addTestSuite(AttributedCharacterIteratorAttributeTest.class); - suite.addTestSuite(AttributedCharacterIteratorTest.class); - suite.addTestSuite(AttributedStringTest.class); - suite.addTestSuite(BidiTest.class); - suite.addTestSuite(BreakIteratorTest.class); - suite.addTestSuite(ChoiceFormatTest.class); - suite.addTestSuite(CollationElementIteratorTest.class); - suite.addTestSuite(CollationKeyTest.class); - suite.addTestSuite(CollatorTest.class); - suite.addTestSuite(DataFormatFieldTest.class); - suite.addTestSuite(DateFormatSymbolsTest.class); - suite.addTestSuite(DateFormatTest.class); - suite.addTestSuite(DecimalFormatSymbolsTest.class); - suite.addTestSuite(DecimalFormatTestICU.class); - suite.addTestSuite(FieldPositionTest.class); - suite.addTestSuite(FormatFieldTest.class); - suite.addTestSuite(FormatTest.class); - suite.addTestSuite(MessageFormatFieldTest.class); - suite.addTestSuite(MessageFormatTest.class); - suite.addTestSuite(NormalizerTest.class); - suite.addTestSuite(NumberFormatFieldTest.class); - suite.addTestSuite(ParseExceptionTest.class); - suite.addTestSuite(ParsePositionTest.class); - suite.addTestSuite(RuleBasedCollatorTest.class); - suite.addTestSuite(StringCharacterIteratorTest.class); - //$JUnit-END$ - return suite; - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AnnotationTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/AnnotationTest.java deleted file mode 100644 index 1430d6e..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AnnotationTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.Annotation; - -@TestTargetClass(Annotation.class) -public class AnnotationTest extends TestCase { - - /** - * @tests java.text.Annotation(Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Annotation", - args = {java.lang.Object.class} - ) - public void testAnnotation() { - assertNotNull(new Annotation(null)); - assertNotNull(new Annotation("value")); - } - - /** - * @tests java.text.Annotation.getValue() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getValue", - args = {} - ) - public void testGetValue() { - Annotation a = new Annotation(null); - assertNull(a.getValue()); - a = new Annotation("value"); - assertEquals("value", a.getValue()); - } - - /** - * @tests java.text.Annotation.toString() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {} - ) - public void testToString() { - Annotation ant = new Annotation("HelloWorld"); - assertEquals("toString error.", - "java.text.Annotation[value=HelloWorld]", ant.toString()); - assertNotNull(new Annotation(null).toString()); - assertNotNull(new Annotation("value").toString()); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorTest.java deleted file mode 100644 index 3ae8bf0..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/AttributedCharacterIteratorTest.java +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; - -import java.text.AttributedCharacterIterator; -import java.text.AttributedString; -import java.text.CharacterIterator; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -@TestTargetClass(AttributedCharacterIterator.class) -public class AttributedCharacterIteratorTest extends junit.framework.TestCase { - - AttributedCharacterIterator it; - String string = "test test"; - - /**z dxthf jgznm rff - * @tests java.text.AttributedCharacterIterator#current() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "current", - args = {} - ) - public void test_current() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - assertEquals("Wrong first", 'T', it.current()); - it.next(); - assertEquals("Wrong second", 'e', it.current()); - for (int i = 0; i < 9; i++) - it.next(); - assertEquals("Wrong last", 'g', it.current()); - it.next(); - assertTrue("Wrong final", it.current() == CharacterIterator.DONE); - - it = attrString.getIterator(null, 2, 8); - assertEquals("Wrong first2", 's', it.current()); - } - - /** - * @tests java.text.AttributedCharacterIterator#first() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "first", - args = {} - ) - public void test_first() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - assertEquals("Wrong first1", 'T', it.first()); - it = attrString.getIterator(null, 0, 3); - assertEquals("Wrong first2", 'T', it.first()); - it = attrString.getIterator(null, 2, 8); - assertEquals("Wrong first3", 's', it.first()); - it = attrString.getIterator(null, 11, 11); - assertTrue("Wrong first4", it.first() == CharacterIterator.DONE); - } - - /** - * @tests java.text.AttributedCharacterIterator#getBeginIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getBeginIndex", - args = {} - ) - public void test_getBeginIndex() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(null, 2, 6); - assertEquals("Wrong begin index", 2, it.getBeginIndex()); - } - - /** - * @tests java.text.AttributedCharacterIterator#getEndIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getEndIndex", - args = {} - ) - public void test_getEndIndex() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(null, 2, 6); - assertEquals("Wrong begin index", 6, it.getEndIndex()); - } - - /** - * @tests java.text.AttributedCharacterIterator#getIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIndex", - args = {} - ) - public void test_getIndex() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - assertEquals("Wrong first", 0, it.getIndex()); - it.next(); - assertEquals("Wrong second", 1, it.getIndex()); - for (int i = 0; i < 9; i++) - it.next(); - assertEquals("Wrong last", 10, it.getIndex()); - it.next(); - assertEquals("Wrong final", 11, it.getIndex()); - } - - /** - * @tests java.text.AttributedCharacterIterator#last() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "last", - args = {} - ) - public void test_last() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - assertEquals("Wrong last1", 'g', it.last()); - it = attrString.getIterator(null, 0, 3); - assertEquals("Wrong last2", 's', it.last()); - it = attrString.getIterator(null, 2, 8); - assertEquals("Wrong last3", 'r', it.last()); - it = attrString.getIterator(null, 0, 0); - assertTrue("Wrong last4", it.last() == CharacterIterator.DONE); - } - - /** - * @tests java.text.AttributedCharacterIterator#next() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "next", - args = {} - ) - public void test_next() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - assertEquals("Wrong first", 'e', it.next()); - for (int i = 0; i < 8; i++) - it.next(); - assertEquals("Wrong last", 'g', it.next()); - assertTrue("Wrong final", it.next() == CharacterIterator.DONE); - - it = attrString.getIterator(null, 2, 8); - assertEquals("Wrong first2", 't', it.next()); - } - - /** - * @tests java.text.AttributedCharacterIterator#previous() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "previous", - args = {} - ) - public void test_previous() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - it.setIndex(11); - assertEquals("Wrong first", 'g', it.previous()); - } - - /** - * @tests java.text.AttributedCharacterIterator#setIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setIndex", - args = {int.class} - ) - public void test_setIndexI() { - String test = "Test 23ring"; - AttributedString attrString = new AttributedString(test); - AttributedCharacterIterator it = attrString.getIterator(); - it.setIndex(5); - assertEquals("Wrong first", '2', it.current()); - } - - /** - * @tests java.text.AttributedCharacterIterator#getRunLimit(java.text.AttributedCharacterIterator$Attribute) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunLimit", - args = {java.util.Set.class} - ) - public void test_getRunLimitLSet() { - AttributedString as = new AttributedString("test"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, - 3); - AttributedCharacterIterator it = as.getIterator(); - HashSet<AttributedCharacterIterator.Attribute> attr = - new HashSet<AttributedCharacterIterator.Attribute>(); - attr.add(AttributedCharacterIterator.Attribute.LANGUAGE); - assertEquals("non-null value limit", - 2, it.getRunLimit(attr)); - - as = new AttributedString("test"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null, - 2, 3); - it = as.getIterator(); - assertEquals("null value limit", - 4, it.getRunLimit(attr)); - - attr.add(AttributedCharacterIterator.Attribute.READING); - assertEquals("null value limit", - 4, it.getRunLimit(attr)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAllAttributeKeys", - args = {} - ) - public void test_getAllAttributeKeys() { - AttributedString as = new AttributedString("test"); - AttributedCharacterIterator it = as.getIterator(); - Set<AttributedCharacterIterator.Attribute> emptyAttributes = - it.getAllAttributeKeys(); - assertTrue(emptyAttributes.isEmpty()); - - int attrCount = 10; - for(int i = 0 ; i < attrCount; i++) { - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "a"); - } - it = as.getIterator(); - Set<AttributedCharacterIterator.Attribute> attributes = - it.getAllAttributeKeys(); - for(AttributedCharacterIterator.Attribute attr:attributes) { - assertEquals(AttributedCharacterIterator.Attribute.LANGUAGE, attr); - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAttribute", - args = {java.text.AttributedCharacterIterator.Attribute.class} - ) - public void test_getAttributeLAttributedCharacterIterator_Attribute() { - - Object attribute = - it.getAttribute(AttributedCharacterIterator.Attribute.LANGUAGE); - assertEquals("ENGLISH", attribute); - - attribute = - it.getAttribute(AttributedCharacterIterator.Attribute.READING); - assertEquals("READ", attribute); - - assertNull(it.getAttribute(AttributedCharacterIterator. - Attribute.INPUT_METHOD_SEGMENT)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAttributes", - args = {} - ) - public void test_getAttributes() { - Map<AttributedCharacterIterator.Attribute, Object> attributes = - it.getAttributes(); - assertEquals(2, attributes.size()); - assertEquals("ENGLISH", - attributes.get(AttributedCharacterIterator.Attribute.LANGUAGE)); - assertEquals("READ", - attributes.get(AttributedCharacterIterator.Attribute.READING)); - - AttributedString as = new AttributedString("test"); - assertTrue(as.getIterator().getAttributes().isEmpty()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "getRunLimit", - args = {} - ) - public void test_getRunLimit() { - int limit = it.getRunLimit(); - assertEquals(string.length(), limit); - - AttributedString as = new AttributedString(""); - assertEquals(0, as.getIterator().getRunLimit()); - - as = new AttributedString(new AttributedString("test text"). - getIterator(), 2, 7); - - AttributedCharacterIterator it = as.getIterator(); - assertEquals(5, it.getRunLimit()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunLimit", - args = {java.text.AttributedCharacterIterator.Attribute.class} - ) - public void test_getRunLimitLAttribute() { - AttributedString as = new AttributedString(""); - assertEquals(0, as.getIterator().getRunLimit( - AttributedCharacterIterator.Attribute.LANGUAGE)); - - as = new AttributedString("text"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "ENGLISH"); - - as.addAttribute(AttributedCharacterIterator.Attribute.READING, - "READ", 1, 3); - - assertEquals(4, as.getIterator().getRunLimit( - AttributedCharacterIterator.Attribute.LANGUAGE)); - - assertEquals(1, as.getIterator().getRunLimit( - AttributedCharacterIterator.Attribute.READING)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "getRunStart", - args = {} - ) - public void test_getRunStart() { - assertEquals(0, it.getRunStart()); - - AttributedString as = new AttributedString(""); - assertEquals(0, as.getIterator().getRunStart()); - - as = new AttributedString(new AttributedString("test text"). - getIterator(), 2, 7); - - AttributedCharacterIterator it = as.getIterator(); - - assertEquals(0, it.getRunStart()); - - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "GERMAN", 1, 2); - as.addAttribute(AttributedCharacterIterator.Attribute.READING, - "READ", 1, 3); - assertEquals(0, as.getIterator().getRunStart()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunStart", - args = {java.text.AttributedCharacterIterator.Attribute.class} - ) - public void test_getRunStartLAttribute() { - assertEquals(0, it.getRunStart( - AttributedCharacterIterator.Attribute.LANGUAGE)); - - AttributedString as = new AttributedString("test text"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "GERMAN", 2, 5); - as.addAttribute(AttributedCharacterIterator.Attribute.READING, - "READ", 2, 7); - - assertEquals(0, as.getIterator().getRunStart( - AttributedCharacterIterator.Attribute.LANGUAGE)); - assertEquals(0, as.getIterator().getRunStart( - AttributedCharacterIterator.Attribute.READING)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunStart", - args = {java.util.Set.class} - ) - public void test_getRunStartLjava_util_Set() { - AttributedString as = new AttributedString("test"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, - 3); - AttributedCharacterIterator it = as.getIterator(); - HashSet<AttributedCharacterIterator.Attribute> attr = - new HashSet<AttributedCharacterIterator.Attribute>(); - attr.add(AttributedCharacterIterator.Attribute.LANGUAGE); - assertEquals(0, it.getRunStart(attr)); - - as = new AttributedString("test"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "ENGLISH",1, 3); - it = as.getIterator(); - assertEquals(0, it.getRunStart(attr)); - - attr.add(AttributedCharacterIterator.Attribute.READING); - assertEquals(0, it.getRunStart(attr)); - - - } - - protected void setUp() { - - AttributedString as = new AttributedString(string); - - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "GERMAN"); - as.addAttribute(AttributedCharacterIterator.Attribute.READING, - "READ"); - as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, - "ENGLISH"); - - it = as.getIterator(); - } - - protected void tearDown() { - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java deleted file mode 100644 index 77ab191..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java +++ /dev/null @@ -1,2078 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 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.AttributedString; -import java.text.Bidi; -import java.util.Arrays; - -@TestTargetClass(Bidi.class) -public class BidiTest extends TestCase { - - Bidi bd; - - public static void assertRunArrayEquals(int[][] expected, Bidi bidi) { - assertEquals("different length", expected.length, bidi.getRunCount()); - - FORRUN: for (int i = 0; i < bidi.getRunCount(); i++) { - int[] butWas = new int[] { bidi.getRunStart(i), - bidi.getRunLimit(i), bidi.getRunLevel(i) }; - - for (int j = 0; j < expected.length; j++) { - if (expected[j][0] == butWas[0] && expected[j][1] == butWas[1] - && expected[j][2] == butWas[2]) { - continue FORRUN; - } - } - fail("expected [" + i + "] " + " start: " + butWas[0] + " limit: " - + butWas[1] + " level: " + butWas[2]); - } - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify positive case for Bidi(AttributedCharacterIterator paragraph).", - method = "Bidi", - args = {char[].class, int.class, byte[].class, int.class, int.class, int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify positive case for Bidi(AttributedCharacterIterator paragraph).", - method = "Bidi", - args = {java.text.AttributedCharacterIterator.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testNullPointerConstructor() { - try { - bd = new Bidi(null, Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(null, 0, new byte[] { 0 }, 0, 0, - Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(null); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - } - - bd = new Bidi("a".toCharArray(), 0, null, 0, 1, - Bidi.DIRECTION_RIGHT_TO_LEFT); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {char[].class, int.class, byte[].class, int.class, int.class, int.class} - ) - public void testBadLength() { - try { - bd = new Bidi("1".toCharArray(), 0, new byte[] { 0 }, 0, 20, - Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi("1234567".toCharArray(), 0, new byte[] { 0 }, 0, 4, - Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi("1234567".toCharArray(), 4, new byte[] { 0, 1, 2, 3, - 4 }, 0, 5, Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi("1234567".toCharArray(), 0, new byte[] { 0, 1, 2, 3, - 4 }, 4, 5, Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - // regression for HARMONY-1031 - try { - bd = new Bidi(new char[] { 't', 't', 't' }, -1, - new byte[] { 2, 2 }, 1, 1, 1); - fail("should be IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(new char[] { 't', 't', 't' }, 1, new byte[] { 2, 2 }, - -1, 1, 1); - fail("should be IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(new char[] { 't', 't', 't' }, 1, new byte[] { 2, 2 }, - 1, -1, 1); - fail("should be IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(new char[] {}, 5, new byte[] { 2, 2, 2, 2, 2, 2 }, 8, - Integer.MAX_VALUE, 5); - fail("should be IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - bd = new Bidi(null, 5, null, 8, Integer.MAX_VALUE, 5); - fail("should be IllegalArgumentException."); - } catch (IllegalArgumentException e) { - // expected - } - - bd = new Bidi(new char[] { 'o' }, 0, new byte[] { 2, 2 }, 2, 0, 2); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testEmptyParagraph() { - bd = new Bidi("", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(0, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 0, 0 } }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(0, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 0, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - - bd = new Bidi("", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(0, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 0, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(0, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 0, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - public void testSpaceParagraph() { - bd = new Bidi(" ", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(" ", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - - bd = new Bidi(" ", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(" ", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - public void testSimpleParagraph() { - bd = new Bidi("t", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("t", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("t", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - /** - * @tests java.text.Bidi#toString() Test of method java.text.Bidi#toString() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {} - ) - public void testToString() { - try { - bd = new Bidi("bidi", 173); - assertNotNull("Bidi representation is null", bd.toString()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify that these methods can return all possible flags.", - method = "Bidi", - args = {java.lang.String.class, int.class} - ) - }) - public void testBadFlags() { - bd = new Bidi("", 173); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(0, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 0, 0 }, }, bd); - assertTrue(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies IllegalArgumentException.", - method = "Bidi", - args = {char[].class, int.class, byte[].class, int.class, int.class, int.class} - ) - public void testBadEmbeddings() { - try { - bd = new Bidi("".toCharArray(), 0, new byte[] {}, 0, 1, - Bidi.DIRECTION_RIGHT_TO_LEFT); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - public void testOverrideEmbeddings() { - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7, - (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(7, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 7 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1, - (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1, - (byte) -2, (byte) -3 }, 0, 3, Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -1, - (byte) -2, (byte) -3 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - public void testDefaultEmbeddings() { - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) 0, - (byte) 0, (byte) 0 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(2, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 3, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - public void testRelativeEmbeddings() { - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) 1, - (byte) 2, (byte) 3 }, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(4, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 2, 2 }, { 2, 3, 4 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testSimpleHebrewParagraph() { - bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - - bd = new Bidi("\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - - bd = new Bidi("\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertFalse(bd.isMixed()); - assertTrue(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testSimpleBidiParagraph_1() { - bd = new Bidi("\u05D0a", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("\u05D0a", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("\u05D0a", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 0 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("\u05D0a", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testSimpleBidiParagraph_2() { - bd = new Bidi("a\u05D0", Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("a\u05D0", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("a\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(0, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 0 }, { 1, 2, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi("a\u05D0", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(2, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(2, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - /* - * spec reads: public static final int DIRECTION_RIGHT_TO_LEFT Constant - * indicating base direction is right-to-left. according to that, the method - * baseIsLeftToRight() here should return false. however, RI doesn't act so. - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testRIBug_1() { - bd = new Bidi("t", Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - // the base level it the essential cause - assertEquals(1, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - // this is essentially the same bug as Bug_1 - public void testRIBug_2() { - bd = new Bidi("\u05D0", Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(1, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(1, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {String.class, int.class} - ) - }) - public void testComplicatedBidi() { - bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a", - Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(9, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(2, bd.getLevelAt(2)); - assertEquals(2, bd.getLevelAt(3)); - assertEquals(2, bd.getLevelAt(4)); - assertEquals(1, bd.getLevelAt(5)); - assertEquals(1, bd.getLevelAt(6)); - assertEquals(1, bd.getLevelAt(7)); - assertEquals(2, bd.getLevelAt(8)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(5, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 }, - { 2, 5, 2 }, { 5, 8, 1 }, { 8, 9, 2 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {char[].class, int.class, byte[].class, int.class, int.class, int.class} - ) - }) - public void testComplicatedOverrideBidi() { - bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(), 0, - new byte[] { 0, 0, 0, -3, -3, 2, 2, 0, 3 }, 0, 9, - Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(9, bd.getLength()); - assertEquals(2, bd.getLevelAt(0)); - assertEquals(1, bd.getLevelAt(1)); - assertEquals(2, bd.getLevelAt(2)); - assertEquals(3, bd.getLevelAt(3)); - assertEquals(3, bd.getLevelAt(4)); - assertEquals(3, bd.getLevelAt(5)); - assertEquals(2, bd.getLevelAt(6)); - assertEquals(1, bd.getLevelAt(7)); - assertEquals(4, bd.getLevelAt(8)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(7, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 }, - { 2, 3, 2 }, { 3, 6, 3 }, { 6, 7, 2 }, { 7, 8, 1 }, - { 8, 9, 4 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "requiresBidi", - args = {char[].class, int.class, int.class} - ) - public void testRequiresBidi() { - try { - Bidi.requiresBidi(null, 0, 0); - fail("should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - try { - assertFalse(Bidi.requiresBidi(null, 0, 1)); - fail("should throw NPE"); - } catch (NullPointerException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 1)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), -1, 1)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, -1)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 1, -1)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, 0)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 7, 7)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, - Integer.MAX_VALUE)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - try { - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), - Integer.MAX_VALUE, 1)); - fail("should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - - assertFalse(Bidi.requiresBidi("".toCharArray(), 0, 0)); - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 1, 1)); - assertFalse(Bidi.requiresBidi("aaa".toCharArray(), 0, 2)); - assertFalse(Bidi.requiresBidi("\u05D0".toCharArray(), 1, 1)); - assertTrue(Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1)); - assertFalse(Bidi.requiresBidi("aa\u05D0a".toCharArray(), 0, 2)); - assertTrue(Bidi.requiresBidi("aa\u05D0a".toCharArray(), 1, 3)); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {char[].class, int.class, byte[].class, int.class, int.class, int.class} - ) - }) - public void testHebrewOverrideEmbeddings() { - bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0, - new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0, - new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0, - new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_LEFT_TO_RIGHT); - assertTrue(bd.baseIsLeftToRight()); - assertEquals(0, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(0, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - - bd = new Bidi(new char[] { '\u05D0', '\u05D0', '\u05D0' }, 0, - new byte[] { (byte) -1, (byte) -2, (byte) -3 }, 0, 3, - Bidi.DIRECTION_RIGHT_TO_LEFT); - assertFalse(bd.baseIsLeftToRight()); - assertEquals(1, bd.getBaseLevel()); - assertEquals(3, bd.getLength()); - assertEquals(1, bd.getLevelAt(0)); - assertEquals(2, bd.getLevelAt(1)); - assertEquals(3, bd.getLevelAt(2)); - assertEquals(1, bd.getLevelAt(1000)); - assertEquals(3, bd.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 1 }, { 1, 2, 2 }, - { 2, 3, 3 }, }, bd); - assertFalse(bd.isLeftToRight()); - assertTrue(bd.isMixed()); - assertFalse(bd.isRightToLeft()); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "createLineBidi", - args = {int.class, int.class} - ) - }) - public void testCreateLineBidi() { - bd = new Bidi("a\u05D0a\na\u05D0\"\u05D0a".toCharArray(), 0, - new byte[] { 0, 0, 0, -3, -3, 2, 2, 0, 3 }, 0, 9, - Bidi.DIRECTION_RIGHT_TO_LEFT); - Bidi line = bd.createLineBidi(2, 7); - assertFalse(line.baseIsLeftToRight()); - assertEquals(1, line.getBaseLevel()); - assertEquals(5, line.getLength()); - assertEquals(2, line.getLevelAt(0)); - assertEquals(1, line.getLevelAt(1)); - assertEquals(3, line.getLevelAt(2)); - assertEquals(3, line.getLevelAt(3)); - assertEquals(2, line.getLevelAt(4)); - assertEquals(1, line.getLevelAt(1000)); - assertEquals(4, line.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 1, 2 }, { 1, 2, 1 }, - { 2, 4, 3 }, { 4, 5, 2 }, }, line); - assertFalse(line.isLeftToRight()); - assertTrue(line.isMixed()); - assertFalse(line.isRightToLeft()); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies IllegalArgumentException.", - method = "createLineBidi", - args = {int.class, int.class} - ) - public void testCreateLineBidiInvalid() { - // regression for HARMONY-1050 - Bidi bidi = new Bidi("str", Bidi.DIRECTION_RIGHT_TO_LEFT); - try { - bidi.createLineBidi(-1, 1); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - bidi.createLineBidi(1, -1); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - bidi.createLineBidi(-1, -1); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - bidi.createLineBidi(2, 1); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - - // BEGIN android-removed - // Outsourced to _AndroidFailure: - // try { - // bidi.createLineBidi(2, 2); - // } catch (IllegalArgumentException expected) { - // } - // END android-removed - - try { - bidi.createLineBidi(2, 4); - fail("Expected IAE"); - } catch (IllegalArgumentException e) { - // Expected - } - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - method = "createLineBidi", - args = {int.class, int.class} - ) - public void testCreateLineBidi_AndroidFailure() { - // This is a difference between ICU4C and the RI. ICU4C insists that 'limit' is strictly - // greater than 'start'. We have to paper over this in our Java code. - Bidi bidi = new Bidi("str", Bidi.DIRECTION_RIGHT_TO_LEFT); - bidi.createLineBidi(2, 2); - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "baseIsLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLevelAt", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunCount", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isRightToLeft", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isLeftToRight", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "isMixed", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getBaseLevel", - args = {} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getLength", - args = {} - ) - }) - @AndroidOnly("ICU treats new lines different from RI.") - public void testIncompatibleLineAlgorithm() { - // ICU treat a new line as in the same run, however RI does not - bd = new Bidi("aaaaa".toCharArray(), 0, - new byte[] { -2, -1, -3, -3, -2 }, 0, 5, - Bidi.DIRECTION_RIGHT_TO_LEFT); - Bidi line = bd.createLineBidi(1, 4); - assertFalse(line.baseIsLeftToRight()); - assertEquals(1, line.getBaseLevel()); - assertEquals(3, line.getLength()); - assertEquals(1, line.getLevelAt(0)); - assertEquals(1, line.getLevelAt(1)); - assertEquals(1, line.getLevelAt(2)); - assertEquals(1, line.getLevelAt(1000)); - assertEquals(1, line.getRunCount()); - assertRunArrayEquals(new int[][] { { 0, 3, 1 }, }, line); - assertFalse(line.isLeftToRight()); - assertFalse(line.isMixed()); - assertTrue(line.isRightToLeft()); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "reorderVisually", - args = {byte[].class, int.class, java.lang.Object[].class, int.class, int.class} - ) - public void testReorderVisually() { - String[] init = new String[] { "a", "b", "c", "d" }; - String[] s = new String[4]; - - System.arraycopy(init, 0, s, 0, s.length); - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, 0, 4); - assertEquals("[c, b, a, d]", Arrays.asList(s).toString()); - - System.arraycopy(init, 0, s, 0, s.length); - Bidi.reorderVisually(new byte[] { 1, 3 }, 0, s, 1, 2); - assertEquals("[a, c, b, d]", Arrays.asList(s).toString()); - - System.arraycopy(init, 0, s, 0, s.length); - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 1, s, 1, 2); - assertEquals("[a, c, b, d]", Arrays.asList(s).toString()); - - System.arraycopy(init, 0, s, 0, s.length); - Bidi.reorderVisually(new byte[] { 2, 1, 2, 1 }, 1, s, 0, 3); - assertEquals("[c, b, a, d]", Arrays.asList(s).toString()); - - System.arraycopy(init, 0, s, 0, s.length); - Bidi.reorderVisually(new byte[] { 2, 1, 0, 1 }, 1, s, 0, 3); - assertEquals("[a, b, c, d]", Arrays.asList(s).toString()); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies exceptions.", - method = "reorderVisually", - args = {byte[].class, int.class, java.lang.Object[].class, int.class, int.class} - ) - public void testBadReorderVisually() { - String[] s = new String[] { "a", "b", "c", "d" }; - - try { - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, 0, 5); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, s, -1, 1); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, -1, s, 0, 1); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - Bidi.reorderVisually(null, 0, s, 0, 1); - fail("should throw NPE"); - } catch (NullPointerException e) { - // expected - } - - try { - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 0, null, 0, 1); - fail("should throw NPE"); - } catch (NullPointerException e) { - // expected - } - - try { - Bidi.reorderVisually(new byte[] { 2, 1, 3, 0 }, 1, s, 0, -1); - fail("should throw IAE"); - } catch (IllegalArgumentException e) { - // expected - } - - } - - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Regression test.", - method = "getRunLimit", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Regression test.", - method = "getRunStart", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Regression test.", - method = "getRunCount", - args = {} - ) - }) - public void testGetRuns() { - // Regression test for Harmony-1028 - - String LTR = "\u0061\u0062"; - String RTL = "\u05DC\u05DD"; - String newLine = "\n"; - String defText = LTR + newLine + RTL + LTR + RTL; - - int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 }, }; - - Bidi bi = new Bidi(defText, 0); - final int count = bi.getRunCount(); - for (int i = 0; i < count; i++) { - assertEquals(expectedRuns[i][0], bi.getRunStart(i)); - assertEquals(expectedRuns[i][1], bi.getRunLimit(i)); - } - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "getRunLimit", - args = {int.class} - ) - public void testGetRunLimit() { - bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT); - try { - assertTrue(4 == bd.getRunLimit(-1)); - } catch (IllegalArgumentException e) { - // Expected for illegal run limit - return; - } - // BEGIN android-changed: the RI doesn't throw. - // fail("Expected IllegalArgumentException to be thrown for invalid run limit"); - // END android-changed - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunLevel", - args = {int.class} - ) - public void testGetRunLevelLInt() { - bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT); - try { - assertEquals(0, bd.getRunLevel(0)); - assertEquals(0, bd.getRunLevel(bd.getRunCount())); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - - bd = new Bidi("text", Bidi.DIRECTION_RIGHT_TO_LEFT); - try { - assertEquals(2, bd.getRunLevel(0)); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - - bd = new Bidi("text", Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); - try { - assertEquals(0, bd.getRunLevel(0)); - } catch (Exception e) { - fail("Unexpected exception: " + e); - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getRunStart", - args = {int.class} - ) - public void testGetRunStart() { - bd = new Bidi(new char[] { 's', 's', 's' }, 0, new byte[] { (byte) -7, - (byte) -2, (byte) 3 }, 0, 3, - Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); - assertEquals(0, bd.getRunStart(0)); - assertEquals(1, bd.getRunStart(1)); - assertEquals(2, bd.getRunStart(2)); - - String LTR = "\u0061\u0062"; - String RTL = "\u05DC\u05DD"; - String newLine = "\n"; - String defText = LTR + newLine + RTL + LTR + RTL; - - int[][] expectedRuns = { { 0, 3 }, { 3, 5 }, { 5, 7 }, { 7, 9 }, }; - - Bidi bi = new Bidi(defText, 0); - - final int count = bi.getRunCount(); - for (int i = 0; i < count; i++) { - assertEquals(expectedRuns[i][0], bi.getRunStart(i)); - } - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "Bidi", - args = {java.text.AttributedCharacterIterator.class} - ) - public void testBidiConstructor_Iterator() { - AttributedString paragraph = new AttributedString("text"); - bd = new Bidi(paragraph.getIterator()); - try { - assertTrue(4 == bd.getRunLimit(1)); - } catch (IllegalArgumentException e) { - // Expected for illegal run limit - return; - } - // BEGIN android-changed: the RI doesn't throw. - // fail("Expected IllegalArgumentException to be thrown for invalid run limit"); - // END android-changed - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java deleted file mode 100644 index d3f9ed3..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.BreakIterator; -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; -import java.util.Locale; - -@TestTargetClass(BreakIterator.class) -public class BreakIteratorTest extends TestCase { - - private static final String TEXT = "a\u0308abc def, gh-12i?jkl.mno?"; - - BreakIterator iterator; - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - iterator = BreakIterator.getCharacterInstance(Locale.US); - } - @TestTargetNew( - level = TestLevel.TODO, - notes = "Verifies constant.", - method = "!Constants", - args = {} - ) - public void testConsts() { - assertEquals(-1, BreakIterator.DONE); - } - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCharacterInstance", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCharacterInstance", - args = {java.util.Locale.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getWordInstance", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLineInstance", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getSentenceInstance", - args = {} - ) - }) - public void testCache() { - BreakIterator newOne = BreakIterator.getCharacterInstance(Locale.US); - assertNotSame(newOne, iterator); - assertEquals(newOne, iterator); - - newOne = BreakIterator.getCharacterInstance(); - assertEquals(newOne, iterator); - - newOne = BreakIterator.getCharacterInstance(Locale.CHINA); - assertEquals(newOne, iterator); - - BreakIterator wordIterator = BreakIterator.getWordInstance(); - assertFalse(wordIterator.equals(iterator)); - - BreakIterator lineIterator = BreakIterator.getLineInstance(); - assertFalse(lineIterator.equals(iterator)); - - BreakIterator senteIterator = BreakIterator.getSentenceInstance(); - assertFalse(senteIterator.equals(iterator)); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void testClone() { - BreakIterator cloned = (BreakIterator) iterator.clone(); - assertNotSame(cloned, iterator); - assertEquals(cloned, iterator); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "current", - args = {} - ) - public void testCurrent() { - assertEquals(0, iterator.current()); - iterator.setText(TEXT); - assertEquals(iterator.first(), iterator.current()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "first", - args = {} - ) - public void testFirst() { - assertEquals(0, iterator.first()); - iterator.setText(TEXT); - assertEquals(0, iterator.first()); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "following", - args = {int.class} - ) - public void testFollowing() { - try { - iterator.following(1); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - iterator.setText(TEXT); - assertEquals(2, iterator.following(1)); - try { - assertEquals(0, iterator.following(-1)); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - try { - iterator.following(TEXT.length()); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isBoundary", - args = {int.class} - ) - public void testIsBoundary() { - try { - iterator.isBoundary(2); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - iterator.setText(TEXT); - assertTrue(iterator.isBoundary(2)); - assertFalse(iterator.isBoundary(1)); - assertTrue(iterator.isBoundary(0)); - try { - iterator.isBoundary(-1); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - try { - iterator.isBoundary(TEXT.length()); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "last", - args = {} - ) - public void testLast() { - assertEquals(0, iterator.last()); - iterator.setText(TEXT); - assertEquals(TEXT.length(), iterator.last()); - } - - /* - * Class under test for int next(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "next", - args = {int.class} - ) - public void testNextint() { - assertEquals(BreakIterator.DONE, iterator.next(3)); - iterator.setText(TEXT); - assertEquals(4, iterator.next(3)); - assertEquals(24, iterator.next(20)); - assertEquals(23, iterator.next(-1)); - assertEquals(-1, iterator.next(TEXT.length())); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "preceding", - args = {int.class} - ) - public void testPreceding() { - try { - iterator.preceding(2); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - iterator.setText(TEXT); - assertEquals(0, iterator.preceding(2)); - assertEquals(2, iterator.preceding(3)); - assertEquals(16, iterator.preceding(17)); - assertEquals(17, iterator.preceding(18)); - assertEquals(18, iterator.preceding(19)); - try { - iterator.preceding(-1); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - try { - iterator.preceding(TEXT.length()); - fail("should throw illegal argument exception"); - } catch (IllegalArgumentException e) { - } - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "previous", - args = {} - ) - public void testPrevious() { - assertEquals(-1, iterator.previous()); - iterator.setText(TEXT); - assertEquals(-1, iterator.previous()); - iterator.last(); - assertEquals(TEXT.length() - 1, iterator.previous()); - } - - /** - * @tests java.text.BreakIterator#getAvailableLocales(). Test of method - * java.text.BreakIterator#getAvailableLocales(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAvailableLocales", - args = {} - ) - public void testGetAvailableLocales() { - try { - Locale[] locales = BreakIterator.getAvailableLocales(); - assertTrue("Array available locales is null", locales != null); - assertTrue("Array available locales is 0-length", - (locales != null && locales.length != 0)); - boolean found = false; - for (Locale l : locales) { - if (l.equals(Locale.US)) { - // expected - found = true; - } - } - assertTrue("At least locale " + Locale.US + " must be presented", - found); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /* - * Class under test for BreakIterator getCharacterInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCharacterInstance", - args = {} - ) - public void testGetCharacterInstance() { - BreakIterator.getCharacterInstance(); - } - - /* - * Class under test for BreakIterator getCharacterInstance(Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Doesn't verify exception.", - method = "getCharacterInstance", - args = {java.util.Locale.class} - ) - public void testGetCharacterInstanceLocale() { - BreakIterator it = BreakIterator.getCharacterInstance(Locale.US); - BreakIterator it2 = BreakIterator.getCharacterInstance(Locale.CHINA); - assertEquals(it, it2); - } - - /* - * Class under test for BreakIterator getLineInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLineInstance", - args = {} - ) - public void testGetLineInstance() { - BreakIterator it = BreakIterator.getLineInstance(); - assertNotNull(it); - } - - /* - * @tests java.text.BreakIterator#getLineInstance(Locale) Class under test - * for BreakIterator getLineInstance(Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify exception.", - method = "getLineInstance", - args = {java.util.Locale.class} - ) - public void testGetLineInstanceLocale() { - try { - BreakIterator it1 = BreakIterator - .getLineInstance(Locale.CANADA_FRENCH); - assertTrue("Incorrect BreakIterator", it1 != BreakIterator - .getLineInstance()); - BreakIterator it2 = BreakIterator.getLineInstance(new Locale( - "bad locale")); - assertTrue("Incorrect BreakIterator", it2 != BreakIterator - .getLineInstance()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /* - * Class under test for BreakIterator getSentenceInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getSentenceInstance", - args = {} - ) - public void testGetSentenceInstance() { - BreakIterator it = BreakIterator.getSentenceInstance(); - assertNotNull(it); - } - - /* - * Class under test for BreakIterator getSentenceInstance(Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify exception.", - method = "getSentenceInstance", - args = {java.util.Locale.class} - ) - public void testGetSentenceInstanceLocale() { - BreakIterator it = BreakIterator.getSentenceInstance(Locale.US); - assertNotNull(it); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getText", - args = {} - ) - public void testGetText() { - assertEquals(new StringCharacterIterator(""), iterator.getText()); - iterator.setText(TEXT); - assertEquals(new StringCharacterIterator(TEXT), iterator.getText()); - } - - /* - * Class under test for BreakIterator getWordInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getWordInstance", - args = {} - ) - public void testGetWordInstance() { - BreakIterator it = BreakIterator.getWordInstance(); - assertNotNull(it); - } - - /* - * @tests java.text.BreakIterator#getWordInstance(Locale) Class under test - * for BreakIterator getWordInstance(Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Doesn't verify exception.", - method = "getWordInstance", - args = {java.util.Locale.class} - ) - public void testGetWordInstanceLocale() { - try { - BreakIterator it1 = BreakIterator - .getWordInstance(Locale.CANADA_FRENCH); - assertTrue("Incorrect BreakIterator", it1 != BreakIterator - .getWordInstance()); - BreakIterator it2 = BreakIterator.getWordInstance(new Locale( - "bad locale")); - assertTrue("Incorrect BreakIterator", it2 != BreakIterator - .getWordInstance()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /* - * Class under test for void setText(CharacterIterator) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.text.CharacterIterator.class} - ) - public void testSetTextCharacterIterator() { - try { - iterator.setText((CharacterIterator) null); - fail(); - } catch (NullPointerException e) { - } - CharacterIterator it = new StringCharacterIterator("abc"); - iterator.setText(it); - assertSame(it, iterator.getText()); - } - - /* - * Class under test for void setText(String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.lang.String.class} - ) - public void testSetTextString() { - try { - iterator.setText((String) null); - fail(); - } catch (NullPointerException e) { - } - iterator.setText("abc"); - CharacterIterator it = new StringCharacterIterator("abc"); - assertEquals(it, iterator.getText()); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "next", - args = {} - ) - public void test_next() { - // Regression test for HARMONY-30 - BreakIterator bi = BreakIterator.getWordInstance(Locale.US); - bi.setText("This is the test, WordInstance"); - int n = bi.first(); - n = bi.next(); - assertEquals("Assert 0: next() returns incorrect value ", 4, n); - - assertEquals(BreakIterator.DONE, iterator.next()); - iterator.setText(TEXT); - assertEquals(2, iterator.next()); - } - - /** - * @tests java.text.BreakIterator#getCharacterInstance(Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Verifies exception.", - method = "getCharacterInstance", - args = {java.util.Locale.class} - ) - public void testGetCharacterInstanceLocale_NPE() { - // Regression for HARMONY-265 - try { - BreakIterator.getCharacterInstance(null); - fail("BreakIterator.getCharacterInstance(null); should throw NullPointerException"); - } catch (NullPointerException e) { - } - } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies exception.", - method = "getLineInstance", - args = {java.util.Locale.class} - ) - public void testGetLineInstanceLocale_NPE() { - try { - BreakIterator.getLineInstance(null); - fail("BreakIterator.getLineInstance(null); should throw NullPointerException"); - } catch (NullPointerException e) { - } - } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies exception.", - method = "getSentenceInstance", - args = {java.util.Locale.class} - ) - public void testGetSentenceInstanceLocale_NPE() { - try { - BreakIterator.getSentenceInstance(null); - fail("BreakIterator.getSentenceInstance(null); should throw NullPointerException"); - } catch (NullPointerException e) { - } - } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies exception.", - method = "getWordInstance", - args = {java.util.Locale.class} - ) - public void testGetWordInstanceLocale_NPE() { - try { - BreakIterator.getWordInstance(null); - fail("BreakIterator.getWordInstance(null); should throw NullPointerException"); - } catch (NullPointerException e) { - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java deleted file mode 100644 index 9fd4660..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.ChoiceFormat; -import java.text.FieldPosition; -import java.text.MessageFormat; -import java.text.ParsePosition; - - -@TestTargetClass(ChoiceFormat.class) -public class ChoiceFormatTest extends TestCase { - - double[] limits = new double[] { 0, 1, ChoiceFormat.nextDouble(1), - ChoiceFormat.nextDouble(2) }; - - String[] formats = new String[] { "Less than one", "one", - "Between one and two", "Greater than two" }; - - ChoiceFormat f1 = new ChoiceFormat(limits, formats); - - /** - * @tests java.text.ChoiceFormat#ChoiceFormat(double[], java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "ChoiceFormat", - args = {double[].class, java.lang.String[].class} - ) - public void test_Constructor$D$Ljava_lang_String() { - // Test for method java.text.ChoiceFormat(double [], java.lang.String - // []) - String formattedString; - double[] appleLimits = { 1, 2, 3, 4, 5 }; - String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple", - "Large Apple", "Huge Apple" }; - ChoiceFormat cf = new ChoiceFormat(appleLimits, appleFormats); - - formattedString = cf.format(Double.NEGATIVE_INFINITY); - assertTrue("a) Incorrect format returned: " + formattedString, - formattedString.equals("Tiny Apple")); - formattedString = cf.format(0.5d); - assertTrue("b) Incorrect format returned: " + formattedString, - formattedString.equals("Tiny Apple")); - formattedString = cf.format(1d); - assertTrue("c) Incorrect format returned: " + formattedString, - formattedString.equals("Tiny Apple")); - formattedString = cf.format(1.5d); - assertTrue("d) Incorrect format returned: " + formattedString, - formattedString.equals("Tiny Apple")); - formattedString = cf.format(2d); - assertTrue("e) Incorrect format returned: " + formattedString, - formattedString.equals("Small Apple")); - formattedString = cf.format(2.5d); - assertTrue("f) Incorrect format returned: " + formattedString, - formattedString.equals("Small Apple")); - formattedString = cf.format(3d); - assertTrue("g) Incorrect format returned: " + formattedString, - formattedString.equals("Medium Apple")); - formattedString = cf.format(4d); - assertTrue("h) Incorrect format returned: " + formattedString, - formattedString.equals("Large Apple")); - formattedString = cf.format(5d); - assertTrue("i) Incorrect format returned: " + formattedString, - formattedString.equals("Huge Apple")); - formattedString = cf.format(5.5d); - assertTrue("j) Incorrect format returned: " + formattedString, - formattedString.equals("Huge Apple")); - formattedString = cf.format(6.0d); - assertTrue("k) Incorrect format returned: " + formattedString, - formattedString.equals("Huge Apple")); - formattedString = cf.format(Double.POSITIVE_INFINITY); - assertTrue("l) Incorrect format returned: " + formattedString, - formattedString.equals("Huge Apple")); - } - - /** - * @tests java.text.ChoiceFormat#ChoiceFormat(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "ChoiceFormat", - args = {java.lang.String.class} - ) - public void test_ConstructorLjava_lang_String() { - // Test for method java.text.ChoiceFormat(java.lang.String) - String formattedString; - String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange"; - ChoiceFormat cf = new ChoiceFormat(patternString); - - formattedString = cf.format(Double.NEGATIVE_INFINITY); - assertTrue("a) Incorrect format returned: " + formattedString, - formattedString.equals("Inverted Orange")); - formattedString = cf.format(-3); - assertTrue("b) Incorrect format returned: " + formattedString, - formattedString.equals("Inverted Orange")); - formattedString = cf.format(-2); - assertTrue("c) Incorrect format returned: " + formattedString, - formattedString.equals("Inverted Orange")); - formattedString = cf.format(-1); - assertTrue("d) Incorrect format returned: " + formattedString, - formattedString.equals("Inverted Orange")); - formattedString = cf.format(-0); - assertTrue("e) Incorrect format returned: " + formattedString, - formattedString.equals("No Orange")); - formattedString = cf.format(0); - assertTrue("f) Incorrect format returned: " + formattedString, - formattedString.equals("No Orange")); - formattedString = cf.format(0.1); - assertTrue("g) Incorrect format returned: " + formattedString, - formattedString.equals("Almost No Orange")); - formattedString = cf.format(1); - assertTrue("h) Incorrect format returned: " + formattedString, - formattedString.equals("Normal Orange")); - formattedString = cf.format(1.5); - assertTrue("i) Incorrect format returned: " + formattedString, - formattedString.equals("Normal Orange")); - formattedString = cf.format(2); - assertTrue("j) Incorrect format returned: " + formattedString, - formattedString.equals("Expensive Orange")); - formattedString = cf.format(3); - assertTrue("k) Incorrect format returned: " + formattedString, - formattedString.equals("Expensive Orange")); - formattedString = cf.format(Double.POSITIVE_INFINITY); - assertTrue("l) Incorrect format returned: " + formattedString, - formattedString.equals("Expensive Orange")); - - } - - /** - * @tests java.text.ChoiceFormat#applyPattern(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "applyPattern", - args = {java.lang.String.class} - ) - public void test_applyPatternLjava_lang_String() { - // Test for method void - // java.text.ChoiceFormat.applyPattern(java.lang.String) - ChoiceFormat f = (ChoiceFormat) f1.clone(); - f.applyPattern("0#0|1#1"); - assertTrue("Incorrect limits", java.util.Arrays.equals(f.getLimits(), - new double[] { 0, 1 })); - assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(), - new String[] { "0", "1" })); - - // Regression for Harmony 540 - double[] choiceLimits = { -1, 0, 1, ChoiceFormat.nextDouble(1) }; - String[] choiceFormats = { "is negative", "is zero or fraction", - "is one", "is more than 1" }; - - f = new ChoiceFormat(""); - f - .applyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); - assertTrue("Incorrect limits", java.util.Arrays.equals(f.getLimits(), - choiceLimits)); - assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(), - choiceFormats)); - - f = new ChoiceFormat(""); - try { - f - .applyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than 1"); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected - } - - f = new ChoiceFormat(""); - try { - f - .applyPattern("-1is negative|0#is zero or fraction|1#is one|1<is more than 1"); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected - } - - f = new ChoiceFormat(""); - f - .applyPattern("-1<is negative|0#is zero or fraction|1#is one|1<is more than 1"); - choiceLimits[0] = ChoiceFormat.nextDouble(-1); - assertTrue("Incorrect limits", java.util.Arrays.equals(f.getLimits(), - choiceLimits)); - assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(), - choiceFormats)); - - f = new ChoiceFormat(""); - f - .applyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); - String str = "org.apache.harmony.tests.java.text.ChoiceFormat"; - f.applyPattern(str); - String ptrn = f.toPattern(); - assertEquals("Return value should be empty string for invalid pattern", - 0, ptrn.length()); - } - - /** - * @tests java.text.ChoiceFormat#clone() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - // Test for method java.lang.Object java.text.ChoiceFormat.clone() - ChoiceFormat f = (ChoiceFormat) f1.clone(); - assertTrue("Not equal", f.equals(f1)); - f.setChoices(new double[] { 0, 1, 2 }, new String[] { "0", "1", "2" }); - assertTrue("Equal", !f.equals(f1)); - } - - /** - * @tests java.text.ChoiceFormat#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.text.ChoiceFormat.equals(java.lang.Object) - - String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange"; - double[] appleLimits = { 1, 2, 3, 4, 5 }; - String[] appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple", - "Large Apple", "Huge Apple" }; - double[] orangeLimits = { -2, 0, ChoiceFormat.nextDouble(0), 1, 2 }; - String[] orangeFormats = { "Inverted Orange", "No Orange", - "Almost No Orange", "Normal Orange", "Expensive Orange" }; - - ChoiceFormat appleChoiceFormat = new ChoiceFormat(appleLimits, - appleFormats); - ChoiceFormat orangeChoiceFormat = new ChoiceFormat(orangeLimits, - orangeFormats); - ChoiceFormat orangeChoiceFormat2 = new ChoiceFormat(patternString); - ChoiceFormat hybridChoiceFormat = new ChoiceFormat(appleLimits, - orangeFormats); - - assertTrue("Apples should not equal oranges", !appleChoiceFormat - .equals(orangeChoiceFormat)); - assertTrue("Different limit list--should not appear as equal", - !orangeChoiceFormat.equals(hybridChoiceFormat)); - assertTrue("Different format list--should not appear as equal", - !appleChoiceFormat.equals(hybridChoiceFormat)); - assertTrue("Should be equal--identical format", appleChoiceFormat - .equals(appleChoiceFormat)); - assertTrue("Should be equals--same limits, same formats", - orangeChoiceFormat.equals(orangeChoiceFormat2)); - - ChoiceFormat f2 = new ChoiceFormat( - "0#Less than one|1#one|1<Between one and two|2<Greater than two"); - assertTrue("Not equal", f1.equals(f2)); - } - - /** - * @tests java.text.ChoiceFormat#format(double, java.lang.StringBuffer, - * java.text.FieldPosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {double.class, java.lang.StringBuffer.class, java.text.FieldPosition.class} - ) - public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() { - // Test for method java.lang.StringBuffer - // java.text.ChoiceFormat.format(double, java.lang.StringBuffer, - // java.text.FieldPosition) - FieldPosition field = new FieldPosition(0); - StringBuffer buf = new StringBuffer(); - String r = f1.format(-1, buf, field).toString(); - assertEquals("Wrong choice for -1", "Less than one", r); - buf.setLength(0); - r = f1.format(0, buf, field).toString(); - assertEquals("Wrong choice for 0", "Less than one", r); - buf.setLength(0); - r = f1.format(1, buf, field).toString(); - assertEquals("Wrong choice for 1", "one", r); - buf.setLength(0); - r = f1.format(2, buf, field).toString(); - assertEquals("Wrong choice for 2", "Between one and two", r); - buf.setLength(0); - r = f1.format(3, buf, field).toString(); - assertEquals("Wrong choice for 3", "Greater than two", r); - - // Regression test for HARMONY-1081 - assertEquals(0, new ChoiceFormat("|").format(Double.NaN, - new StringBuffer(), new FieldPosition(6)).length()); - assertEquals(0, new ChoiceFormat("|").format(1, new StringBuffer(), - new FieldPosition(6)).length()); - assertEquals("Less than one", f1.format(Double.NaN, new StringBuffer(), - field).toString()); - } - - /** - * @tests java.text.ChoiceFormat#format(long, java.lang.StringBuffer, - * java.text.FieldPosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {long.class, java.lang.StringBuffer.class, java.text.FieldPosition.class} - ) - public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition() { - // Test for method java.lang.StringBuffer - // java.text.ChoiceFormat.format(long, java.lang.StringBuffer, - // java.text.FieldPosition) - FieldPosition field = new FieldPosition(0); - StringBuffer buf = new StringBuffer(); - String r = f1.format(0.5, buf, field).toString(); - assertEquals("Wrong choice for 0.5", "Less than one", r); - buf.setLength(0); - r = f1.format(1.5, buf, field).toString(); - assertEquals("Wrong choice for 1.5", "Between one and two", r); - buf.setLength(0); - r = f1.format(2.5, buf, field).toString(); - assertEquals("Wrong choice for 2.5", "Greater than two", r); - } - - /** - * @tests java.text.ChoiceFormat#getFormats() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getFormats", - args = {} - ) - public void test_getFormats() { - // Test for method java.lang.Object [] - // java.text.ChoiceFormat.getFormats() - String[] orgFormats = (String[]) formats.clone(); - String[] f = (String[]) f1.getFormats(); - assertTrue("Wrong formats", f.equals(formats)); - f[0] = "Modified"; - assertTrue("Formats copied", !f.equals(orgFormats)); - } - - /** - * @tests java.text.ChoiceFormat#getLimits() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLimits", - args = {} - ) - public void test_getLimits() { - // Test for method double [] java.text.ChoiceFormat.getLimits() - double[] orgLimits = (double[]) limits.clone(); - double[] l = f1.getLimits(); - assertTrue("Wrong limits", l.equals(limits)); - l[0] = 3.14527; - assertTrue("Limits copied", !l.equals(orgLimits)); - } - - /** - * @tests java.text.ChoiceFormat#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - // Test for method int java.text.ChoiceFormat.hashCode() - ChoiceFormat f2 = new ChoiceFormat( - "0#Less than one|1#one|1<Between one and two|2<Greater than two"); - assertTrue("Different hash", f1.hashCode() == f2.hashCode()); - } - - /** - * @tests java.text.ChoiceFormat#nextDouble(double) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "nextDouble", - args = {double.class} - ) - public void test_nextDoubleD() { - // Test for method double java.text.ChoiceFormat.nextDouble(double) - assertTrue("Not greater 5", ChoiceFormat.nextDouble(5) > 5); - assertTrue("Not greater 0", ChoiceFormat.nextDouble(0) > 0); - assertTrue("Not greater -5", ChoiceFormat.nextDouble(-5) > -5); - assertTrue("Not NaN", Double.isNaN(ChoiceFormat.nextDouble(Double.NaN))); - } - - /** - * @tests java.text.ChoiceFormat#nextDouble(double, boolean) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "nextDouble", - args = {double.class, boolean.class} - ) - public void test_nextDoubleDZ() { - // Test for method double java.text.ChoiceFormat.nextDouble(double, - // boolean) - assertTrue("Not greater 0", ChoiceFormat.nextDouble(0, true) > 0); - assertTrue("Not less 0", ChoiceFormat.nextDouble(0, false) < 0); - } - - /** - * @tests java.text.ChoiceFormat#parse(java.lang.String, - * java.text.ParsePosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class, java.text.ParsePosition.class} - ) - public void test_parseLjava_lang_StringLjava_text_ParsePosition() { - // Test for method java.lang.Number - // java.text.ChoiceFormat.parse(java.lang.String, - // java.text.ParsePosition) - ChoiceFormat format = new ChoiceFormat("1#one|2#two|3#three"); - assertEquals("Case insensitive", 0, format.parse("One", - new ParsePosition(0)).intValue()); - - ParsePosition pos = new ParsePosition(0); - Number result = f1.parse("Greater than two", pos); - assertTrue("Not a Double1", result instanceof Double); - assertTrue("Wrong value ~>2", result.doubleValue() == ChoiceFormat - .nextDouble(2)); - assertEquals("Wrong position ~16", 16, pos.getIndex()); - pos = new ParsePosition(0); - assertTrue("Incorrect result", Double.isNaN(f1.parse("12one", pos) - .doubleValue())); - assertEquals("Wrong position ~0", 0, pos.getIndex()); - pos = new ParsePosition(2); - result = f1.parse("12one and two", pos); - assertTrue("Not a Double2", result instanceof Double); - assertEquals("Ignored parse position", 1.0D, result.doubleValue(), 0.0D); - assertEquals("Wrong position ~5", 5, pos.getIndex()); - } - - /** - * @tests java.text.ChoiceFormat#previousDouble(double) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "previousDouble", - args = {double.class} - ) - public void test_previousDoubleD() { - // Test for method double java.text.ChoiceFormat.previousDouble(double) - assertTrue("Not less 5", ChoiceFormat.previousDouble(5) < 5); - assertTrue("Not less 0", ChoiceFormat.previousDouble(0) < 0); - assertTrue("Not less -5", ChoiceFormat.previousDouble(-5) < -5); - assertTrue("Not NaN", Double.isNaN(ChoiceFormat - .previousDouble(Double.NaN))); - } - - /** - * @tests java.text.ChoiceFormat#setChoices(double[], java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setChoices", - args = {double[].class, java.lang.String[].class} - ) - public void test_setChoices$D$Ljava_lang_String() { - // Test for method void java.text.ChoiceFormat.setChoices(double [], - // java.lang.String []) - ChoiceFormat f = (ChoiceFormat) f1.clone(); - double[] l = new double[] { 0, 1 }; - String[] fs = new String[] { "0", "1" }; - f.setChoices(l, fs); - assertTrue("Limits copied", f.getLimits() == l); - assertTrue("Formats copied", f.getFormats() == fs); - } - - /** - * @tests java.text.ChoiceFormat#toPattern() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toPattern", - args = {} - ) - public void test_toPattern() { - // Regression for HARMONY-59 - ChoiceFormat cf = new ChoiceFormat(""); - assertEquals("", cf.toPattern()); - - cf = new ChoiceFormat("-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); - assertEquals("-1.0#NEGATIVE_ONE|0.0#ZERO|1.0#ONE|1.0<GREATER_THAN_ONE", - cf.toPattern()); - - MessageFormat mf = new MessageFormat("CHOICE {1,choice}"); - String ptrn = mf.toPattern(); - assertEquals("Unused message format returning incorrect pattern", - "CHOICE {1,choice,}", ptrn); - - String pattern = f1.toPattern(); - assertTrue( - "Wrong pattern: " + pattern, - pattern - .equals("0.0#Less than one|1.0#one|1.0<Between one and two|2.0<Greater than two")); - - cf = new ChoiceFormat( - "-1#is negative| 0#is zero or fraction | 1#is one |1.0<is 1+|2#is two |2<is more than 2."); - String str = "org.apache.harmony.tests.java.lang.share.MyResources2"; - cf.applyPattern(str); - ptrn = cf.toPattern(); - assertEquals("Return value should be empty string for invalid pattern", - 0, ptrn.length()); - } - - /** - * @tests java.text.ChoiceFormat#format(long) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {long.class} - ) - public void test_formatL() { - ChoiceFormat fmt = new ChoiceFormat( - "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); - - assertEquals("NEGATIVE_ONE", fmt.format(Long.MIN_VALUE)); - assertEquals("NEGATIVE_ONE", fmt.format(-1)); - assertEquals("ZERO", fmt.format(0)); - assertEquals("ONE", fmt.format(1)); - assertEquals("GREATER_THAN_ONE", fmt.format(Long.MAX_VALUE)); - } - - /** - * @tests java.text.ChoiceFormat#format(double) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {double.class} - ) - public void test_formatD() { - ChoiceFormat fmt = new ChoiceFormat( - "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); - assertEquals("NEGATIVE_ONE", fmt.format(Double.NEGATIVE_INFINITY)); - assertEquals("NEGATIVE_ONE", fmt.format(-999999999D)); - assertEquals("NEGATIVE_ONE", fmt.format(-1.1)); - assertEquals("NEGATIVE_ONE", fmt.format(-1.0)); - assertEquals("NEGATIVE_ONE", fmt.format(-0.9)); - assertEquals("ZERO", fmt.format(0.0)); - assertEquals("ZERO", fmt.format(0.9)); - assertEquals("ONE", fmt.format(1.0)); - assertEquals("GREATER_THAN_ONE", fmt.format(1.1)); - assertEquals("GREATER_THAN_ONE", fmt.format(999999999D)); - assertEquals("GREATER_THAN_ONE", fmt.format(Double.POSITIVE_INFINITY)); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollationElementIteratorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollationElementIteratorTest.java deleted file mode 100644 index ebb954f..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollationElementIteratorTest.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.CollationElementIterator; -import java.text.Collator; -import java.text.RuleBasedCollator; -import java.text.StringCharacterIterator; -import java.util.Locale; - -/** - * Test CollationElementIterator - * - * Only test normal condition. - * - */ -@TestTargetClass(CollationElementIterator.class) -public class CollationElementIteratorTest extends TestCase { - - private RuleBasedCollator coll; - - protected void setUp() { - coll = (RuleBasedCollator) Collator.getInstance(Locale.US); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getOffset", - args = {} - ) - public void testGetOffset() { - String text = "abc"; - CollationElementIterator iterator = coll - .getCollationElementIterator(text); - int[] offsets = { 0, 1, 2, 3 }; - int offset = iterator.getOffset(); - int i = 0; - assertEquals(offsets[i++], offset); - while (offset != text.length()) { - iterator.next(); - offset = iterator.getOffset(); - assertEquals(offsets[i++], offset); - } - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "next", - args = {} - ) - public void testNext() { - String text = "abc"; - CollationElementIterator iterator = coll - .getCollationElementIterator(text); - int[] orders = new int[text.length()]; - int order = iterator.next(); - int i = 0; - while (order != CollationElementIterator.NULLORDER) { - orders[i++] = order; - order = iterator.next(); - } - - int offset = iterator.getOffset(); - assertEquals(text.length(), offset); - order = iterator.previous(); - - while (order != CollationElementIterator.NULLORDER) { - assertEquals(orders[--i], order); - order = iterator.previous(); - } - - assertEquals(0, iterator.getOffset()); - } - - /** - * @tests java.text.CollationElementIterator#previous() Test of method - * java.text.CollationElementIterator#previous(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "previous", - args = {} - ) - public void testPrevious() { - String text = "abc"; - CollationElementIterator iterator = coll - .getCollationElementIterator(text); - int[] orders = new int[text.length()]; - int order = iterator.next(); - int i = 0; - while (order != CollationElementIterator.NULLORDER) { - orders[i++] = order; - order = iterator.next(); - } - - int offset = iterator.getOffset(); - assertEquals(text.length(), offset); - order = iterator.previous(); - - while (order != CollationElementIterator.NULLORDER) { - assertEquals(orders[--i], order); - order = iterator.previous(); - } - - assertEquals(0, iterator.getOffset()); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "reset", - args = {} - ) - public void testReset() { - String text = "abc"; - CollationElementIterator iterator = coll - .getCollationElementIterator(text); - int[] orders = new int[text.length()]; - int order = iterator.next(); - int i = 0; - while (order != CollationElementIterator.NULLORDER) { - orders[i++] = order; - order = iterator.next(); - } - - int offset = iterator.getOffset(); - assertEquals(text.length(), offset); - - iterator.reset(); - assertEquals(0, iterator.getOffset()); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getMaxExpansion", - args = {int.class} - ) - public void testGetMaxExpansion() { - String text = "cha"; - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("es", "", "TRADITIONAL")); - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - int order = iterator.next(); - while (order != CollationElementIterator.NULLORDER) { - assertEquals(1, iterator.getMaxExpansion(order)); - order = iterator.next(); - } - - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "primaryOrder", - args = {int.class} - ) - public void testPrimaryOrder() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("de", "DE")); - String text = "\u00e6"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - int order = iterator.next(); - int pOrder = CollationElementIterator.primaryOrder(order); - CollationElementIterator iterator2 = rbColl - .getCollationElementIterator("ae"); - int order2 = iterator2.next(); - int pOrder2 = CollationElementIterator.primaryOrder(order2); - assertEquals(pOrder, pOrder2); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "secondaryOrder", - args = {int.class} - ) - public void testSecondaryOrder() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("fr", "FR")); - String text = "a\u00e0"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - int order = iterator.next(); - int sOrder1 = CollationElementIterator.secondaryOrder(order); - - order = iterator.next(); - int sOrder2 = CollationElementIterator.secondaryOrder(order); - - assertEquals(sOrder1, sOrder2); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "tertiaryOrder", - args = {int.class} - ) - public void testTertiaryOrder() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("fr", "FR")); - String text = "abAB"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - int order = iterator.next(); - int tOrder1 = CollationElementIterator.tertiaryOrder(order); - order = iterator.next(); - int tOrder2 = CollationElementIterator.tertiaryOrder(order); - assertEquals(tOrder1, tOrder2); - - order = iterator.next(); - tOrder1 = CollationElementIterator.tertiaryOrder(order); - order = iterator.next(); - tOrder2 = CollationElementIterator.tertiaryOrder(order); - assertEquals(tOrder1, tOrder2); - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setOffset", - args = {int.class} - ) - public void testSetOffset() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("es", "", "TRADITIONAL")); - String text = "cha"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - iterator.setOffset(1); - assertEquals(1, iterator.getOffset()); - } - - /* - * Class under test for void setText(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.lang.String.class} - ) - public void testSetTextString() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("es", "", "TRADITIONAL")); - String text = "caa"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - iterator.setOffset(1); - assertEquals(1, iterator.getOffset()); - iterator.setText("cha"); - iterator.setOffset(1); - assertEquals(1, iterator.getOffset()); - } - - /* - * Class under test for void setText(java.text.CharacterIterator) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.text.CharacterIterator.class} - ) - public void testSetTextCharacterIterator() { - RuleBasedCollator rbColl = (RuleBasedCollator) Collator - .getInstance(new Locale("es", "", "TRADITIONAL")); - String text = "caa"; - CollationElementIterator iterator = rbColl - .getCollationElementIterator(text); - iterator.setOffset(1); - assertEquals(1, iterator.getOffset()); - iterator.setText(new StringCharacterIterator("cha")); - iterator.setOffset(1); - assertEquals(1, iterator.getOffset()); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java deleted file mode 100644 index 9324069..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/CollatorTest.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.Collator; -import java.text.ParseException; -import java.text.RuleBasedCollator; -import java.util.Locale; - -public class CollatorTest extends junit.framework.TestCase { - - /** - * @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#compare(java.lang.Object, java.lang.Object) - */ - 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#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)); - } - - /** - * @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); - - 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); - 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); - 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); - 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#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#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); - } - - /** - * @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)); - } - - /** - * @tests java.text.Collator#getInstance(java.util.Locale) - */ - public void test_getInstanceLjava_util_Locale() { - assertTrue("Used to test", true); - } - - /** - * @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); - } - - /** - * @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" - } - - /** - * @tests java.text.Collator#setStrength(int) - */ - public void test_setStrengthI() { - assertTrue("Used to test", true); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java deleted file mode 100644 index ab26c39..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.text.DateFormat; -import java.text.DateFormat.Field; -import java.util.Calendar; - -@TestTargetClass(DateFormat.Field.class) -public class DataFormatFieldTest extends TestCase { - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class, int.class} - ) - public void test_ConstructorLjava_lang_StringLjava_lang_String() { - // Regression for HARMONY-178 - MyField field = new MyField("day of month", Calendar.ERA); - - assertEquals("field has wrong name", "day of month", field.getName()); - assertEquals("field has wrong Calendar field number", Calendar.ERA, - field.getCalendarField()); - - DateFormat.Field realField = DateFormat.Field - .ofCalendarField(Calendar.ERA); - assertSame("Modified calendar field with the same field number", - DateFormat.Field.ERA, realField); - - DateFormat.Field realField2 = DateFormat.Field - .ofCalendarField(Calendar.DAY_OF_MONTH); - assertSame("Modified calendar field with the same field number", - DateFormat.Field.DAY_OF_MONTH, realField2); - } - - static class MyField extends DateFormat.Field { - private static final long serialVersionUID = 1L; - - protected MyField(String fieldName, int calendarField) { - super(fieldName, calendarField); - } - - protected String getName() { - return super.getName(); - } - } - - /** - * @tests java.text.DateFormat$Field#Field(java.lang.String, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class, int.class} - ) - public void test_ConstructorLjava_lang_StringI() { - MyField field = new MyField("a field", Calendar.DAY_OF_WEEK); - - assertEquals("field has wrong name", "a field", field.getName()); - assertEquals("field has wrong Calendar field number", - Calendar.DAY_OF_WEEK, field.getCalendarField()); - - DateFormat.Field realField = DateFormat.Field - .ofCalendarField(Calendar.DAY_OF_WEEK); - assertSame("Modified calendar field with the same field number", - DateFormat.Field.DAY_OF_WEEK, realField); - } - - /** - * @tests java.text.DateFormat$Field#Field(java.lang.String, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class, int.class} - ) - public void test_Constructor2() { - MyField field = new MyField("day of month", Calendar.ERA); - - assertEquals("field has wrong name", "day of month", field.getName()); - assertEquals("field has wrong Calendar field number", Calendar.ERA, - field.getCalendarField()); - - DateFormat.Field realField = DateFormat.Field - .ofCalendarField(Calendar.ERA); - assertSame("Modified calendar field with the same field number", - DateFormat.Field.ERA, realField); - - DateFormat.Field realField2 = DateFormat.Field - .ofCalendarField(Calendar.DAY_OF_MONTH); - assertSame("Modified calendar field with the same field number", - DateFormat.Field.DAY_OF_MONTH, realField2); - } - - /** - * @tests java.text.DateFormat$Field#getCalendarField() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCalendarField", - args = {} - ) - public void test_getCalendarField() { - // Test for method int getCalendarField() - assertEquals("Field.AM_PM.getCalendarField() returned the wrong value", - Calendar.AM_PM, Field.AM_PM.getCalendarField()); - - // test special cases - assertEquals( - "Field.TIME_ZONE.getCalendarField() returned the wrong value", - -1, Field.TIME_ZONE.getCalendarField()); - assertEquals("Field.HOUR0.getCalendarField() returned the wrong value", - Calendar.HOUR, Field.HOUR0.getCalendarField()); - assertEquals("Field.HOUR1.getCalendarField() returned the wrong value", - -1, Field.HOUR1.getCalendarField()); - assertEquals( - "Field.HOUR_OF_DAY0.getCalendarField() returned the wrong value", - Calendar.HOUR_OF_DAY, Field.HOUR_OF_DAY0.getCalendarField()); - assertEquals( - "Field.HOUR_OF_DAY1.getCalendarField() returned the wrong value", - -1, Field.HOUR_OF_DAY1.getCalendarField()); - } - - /** - * @tests java.text.DateFormat$Field#ofCalendarField(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "ofCalendarField", - args = {int.class} - ) - public void test_ofCalendarFieldI() { - // Test for method static java.text.DateFormat.Field - // ofCalendarField(int) - assertSame("ofCalendarField(Calendar.AM_PM) returned the wrong value", - Field.AM_PM, Field.ofCalendarField(Calendar.AM_PM)); - - // test special cases - assertSame("ofCalendarField(Calendar.HOUR) returned the wrong value", - Field.HOUR0, Field.ofCalendarField(Calendar.HOUR)); - assertSame( - "ofCalendarField(Calendar.HOUR_OF_DAY) returned the wrong value", - Field.HOUR_OF_DAY0, Field.ofCalendarField(Calendar.HOUR_OF_DAY)); - - // test illegal args - try { - DateFormat.Field.ofCalendarField(-1); - fail("Expected IllegalArgumentException for ofCalendarField(-1)"); - } catch (IllegalArgumentException e) { - } - - try { - DateFormat.Field.ofCalendarField(Calendar.FIELD_COUNT); - fail("Expected IllegalArgumentException for ofCalendarField(Calendar.FIELD_COUNT)"); - } catch (IllegalArgumentException e) { - } - - // test Calendar fields that do not have corresponding DateFormat Fields - assertNull( - "ofCalendarField(Calendar.DST_OFFSET) returned the wrong value", - DateFormat.Field.ofCalendarField(Calendar.DST_OFFSET)); - assertNull( - "ofCalendarField(Calendar.ZONE_OFFSET) returned the wrong value", - DateFormat.Field.ofCalendarField(Calendar.ZONE_OFFSET)); - } - - /** - * @tests java.text.DateFormat$Field#readResolve() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "readResolve", - args = {} - ) - public void test_readResolve() { - // test for method java.lang.Object readResolve() - - // see serialization stress tests: - // implemented in - // SerializationStressTest4.test_writeObject_NumberFormat_Field() - - ObjectOutputStream out = null; - ObjectInputStream in = null; - try { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - out = new ObjectOutputStream(bytes); - - DateFormat.Field dfield, dfield2; - MyField field; - - // a regular instance of DateFormat.Field - dfield = DateFormat.Field.MILLISECOND; - - // a subclass instance with null name - field = new MyField(null, Calendar.AM_PM); - - out.writeObject(dfield); - out.writeObject(field); - - in = new ObjectInputStream(new ByteArrayInputStream(bytes - .toByteArray())); - - try { - dfield2 = (Field) in.readObject(); - assertSame("resolved incorrectly", dfield, dfield2); - } catch (IllegalArgumentException e) { - fail("Unexpected IllegalArgumentException: " + e); - } - - try { - in.readObject(); - fail("Expected InvalidObjectException for subclass instance with null name"); - } catch (InvalidObjectException e) { - } - - } catch (IOException e) { - fail("unexpected IOException" + e); - } catch (ClassNotFoundException e) { - fail("unexpected ClassNotFoundException" + e); - } finally { - try { - if (out != null) - out.close(); - if (in != null) - in.close(); - } catch (IOException e) { - } - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java deleted file mode 100644 index 46ebb1a..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java +++ /dev/null @@ -1,558 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.text.DateFormatSymbols; -import java.util.Arrays; -import java.util.Locale; - -@TestTargetClass(DateFormatSymbols.class) -public class DateFormatSymbolsTest extends junit.framework.TestCase { - - private DateFormatSymbols dfs; - - /** - * @tests java.text.DateFormatSymbols#DateFormatSymbols() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "DateFormatSymbols", - args = {} - ) - public void test_Constructor() { - // Test for method java.text.DateFormatSymbols() - // Used in tests - new DateFormatSymbols(); - } - - /** - * @tests java.text.DateFormatSymbols#DateFormatSymbols(java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "DateFormatSymbols", - args = {java.util.Locale.class} - ) - public void test_ConstructorLjava_util_Locale() { - // Test for method java.text.DateFormatSymbols(java.util.Locale) - new DateFormatSymbols(new Locale("en", "us")); - } - - /** - * @tests java.text.DateFormatSymbols#getAvailableLocales() - */ - public void test_getAvailableLocales_no_provider() throws Exception { - Locale[] locales = DateFormatSymbols.getAvailableLocales(); - assertNotNull(locales); - // must contain Locale.US - boolean flag = false; - for (Locale locale : locales) { - if (locale.equals(Locale.US)) { - flag = true; - break; - } - } - assertTrue(flag); - } - - /** - * @tests java.text.DateFormatSymbols#getInstance() - */ - public void test_getInstance() { - DateFormatSymbols.getInstance(); - assertEquals(new DateFormatSymbols(), DateFormatSymbols.getInstance()); - assertEquals(new DateFormatSymbols(Locale.getDefault()), - DateFormatSymbols.getInstance()); - - assertNotSame(DateFormatSymbols.getInstance(), DateFormatSymbols.getInstance()); - } - - public void test_getInstanceLjava_util_Locale() { - try { - DateFormatSymbols.getInstance(null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - assertEquals(new DateFormatSymbols(Locale.GERMANY), DateFormatSymbols - .getInstance(Locale.GERMANY)); - - Locale locale = new Locale("not exist language", "not exist country"); - DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale); - assertNotNull(symbols); - // BEGIN android-removed: this test is wrong, and confuses default locale with root locale. - // assertEquals(DateFormatSymbols.getInstance(), symbols); - // END android-removed - } - - /** - * @tests java.text.DateFormatSymbols#clone() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - // Test for method java.lang.Object java.text.DateFormatSymbols.clone() - DateFormatSymbols symbols = new DateFormatSymbols(); - DateFormatSymbols clone = (DateFormatSymbols) symbols.clone(); - assertTrue("Not equal", symbols.equals(clone)); - } - - /** - * @tests java.text.DateFormatSymbols#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.text.DateFormatSymbols.equals(java.lang.Object) - assertTrue("Equal object returned true", dfs.equals(dfs.clone())); - dfs.setLocalPatternChars("KKKKKKKKK"); - assertTrue("Un-Equal objects returned false", !dfs - .equals(new DateFormatSymbols())); - } - - /** - * @tests java.text.DateFormatSymbols#getAmPmStrings() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAmPmStrings", - args = {} - ) - public void test_getAmPmStrings() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getAmPmStrings() - String[] retVal = dfs.getAmPmStrings(); - String[] val = { "AM", "PM" }; - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getEras() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getEras", - args = {} - ) - public void test_getEras() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getEras() - String[] retVal = dfs.getEras(); - String[] val = { "BC", "AD" }; - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getLocalPatternChars() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLocalPatternChars", - args = {} - ) - public void test_getLocalPatternChars() { - // Test for method java.lang.String - // java.text.DateFormatSymbols.getLocalPatternChars() - String retVal = dfs.getLocalPatternChars(); - - String val = "GyMdkHmsSEDFwWahKzZ"; - // Harmony uses a different set of pattern chars - // String val = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV"; - - assertEquals("Returned incorrect pattern string", val, retVal); - } - - /** - * @tests java.text.DateFormatSymbols#getMonths() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getMonths", - args = {} - ) - public void test_getMonths() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getMonths() - String[] retVal = dfs.getMonths(); - String[] val = { "January", "February", "March", "April", "May", - "June", "July", "August", "September", "October", "November", - "December", ""}; - // Note: Harmony doesn't include "" at the end of the array - assertEquals("Returned wrong array: ", val.length, retVal.length); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getShortMonths() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getShortMonths", - args = {} - ) - public void test_getShortMonths() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getShortMonths() - String[] retVal = dfs.getShortMonths(); - String[] val = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", - "Aug", "Sep", "Oct", "Nov", "Dec", ""}; - // Note: Harmony doesn't include "" at the end of the array - assertEquals("Returned wrong array: ", val.length, retVal.length); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getShortWeekdays() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getShortWeekdays", - args = {} - ) - public void test_getShortWeekdays() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getShortWeekdays() - String[] retVal = dfs.getShortWeekdays(); - String[] val = { "", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getWeekdays() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getWeekdays", - args = {} - ) - public void test_getWeekdays() { - // Test for method java.lang.String [] - // java.text.DateFormatSymbols.getWeekdays() - String[] retVal = dfs.getWeekdays(); - String[] val = { "", "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" }; - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Array values do not match", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#getZoneStrings() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getZoneStrings", - args = {} - ) - public void test_getZoneStrings() { - // Test for method java.lang.String [][] - // java.text.DateFormatSymbols.getZoneStrings() - String[][] val = { { "XX" }, { "YY" } }; - dfs.setZoneStrings(val); - String[][] retVal = dfs.getZoneStrings(); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", Arrays - .equals(retVal[i], val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - // Test for method int java.text.DateFormatSymbols.hashCode() - int hc1 = dfs.hashCode(); - int hc2 = dfs.hashCode(); - assertTrue("hashCode() returned inconsistent number : " + hc1 + " - " - + hc2, hc1 == hc2); - - assertTrue("hashCode() returns different values for equal() objects", - dfs.hashCode() == dfs.clone().hashCode()); - } - - /** - * @tests java.text.DateFormatSymbols#setAmPmStrings(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setAmPmStrings", - args = {java.lang.String[].class} - ) - public void test_setAmPmStrings$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setAmPmStrings(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setAmPmStrings(val); - String[] retVal = dfs.getAmPmStrings(); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setEras(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setEras", - args = {java.lang.String[].class} - ) - public void test_setEras$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setEras(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setEras(val); - String[] retVal = dfs.getEras(); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setLocalPatternChars(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setLocalPatternChars", - args = {java.lang.String.class} - ) - public void test_setLocalPatternCharsLjava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setLocalPatternChars(java.lang.String) - dfs.setLocalPatternChars("GyMZZkHmsSEHHFwWahKz"); - String retVal = dfs.getLocalPatternChars(); - String val = "GyMZZkHmsSEHHFwWahKz"; - assertTrue("Returned incorrect pattern string", retVal.equals(val)); - - try { - // Regression for HARMONY-466 - new DateFormatSymbols().setLocalPatternChars(null); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - // expected - } - } - - /** - * @tests java.text.DateFormatSymbols#setMonths(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setMonths", - args = {java.lang.String[].class} - ) - public void test_setMonths$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setMonths(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setMonths(val); - String[] retVal = dfs.getMonths(); - assertTrue("Return is identical", retVal != dfs.getMonths()); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setShortMonths(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setShortMonths", - args = {java.lang.String[].class} - ) - public void test_setShortMonths$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setShortMonths(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setShortMonths(val); - String[] retVal = dfs.getShortMonths(); - assertTrue("Return is identical", retVal != dfs.getShortMonths()); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setShortWeekdays(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setShortWeekdays", - args = {java.lang.String[].class} - ) - public void test_setShortWeekdays$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setShortWeekdays(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setShortWeekdays(val); - String[] retVal = dfs.getShortWeekdays(); - assertTrue("Return is identical", retVal != dfs.getShortWeekdays()); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setWeekdays(java.lang.String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setWeekdays", - args = {java.lang.String[].class} - ) - public void test_setWeekdays$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setWeekdays(java.lang.String []) - String[] val = { "XX", "YY" }; - dfs.setWeekdays(val); - String[] retVal = dfs.getWeekdays(); - assertTrue("Return is identical", retVal != dfs.getWeekdays()); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings", retVal[i].equals(val[i])); - } - - /** - * @tests java.text.DateFormatSymbols#setZoneStrings(java.lang.String[][]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setZoneStrings", - args = {java.lang.String[][].class} - ) - public void test_setZoneStrings$$Ljava_lang_String() { - // Test for method void - // java.text.DateFormatSymbols.setZoneStrings(java.lang.String [][]) - String[][] val = { { "XX" }, { "YY" } }; - dfs.setZoneStrings(val); - String[][] retVal = dfs.getZoneStrings(); - assertTrue("get returns identical", retVal != dfs.getZoneStrings()); - assertTrue("get[0] returns identical", retVal[0] != dfs - .getZoneStrings()[0]); - assertTrue("get returned identical", retVal != val); - if (retVal.length != val.length) - fail("Returned wrong array"); - for (int i = 0; i < val.length; i++) - assertTrue("Failed to set strings: " + retVal[i], Arrays.equals( - retVal[i], val[i])); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - dfs = new DateFormatSymbols(new Locale("en", "us")); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Checks serialization mechanism.", - method = "!SerializationSelf", - args = {} - ) - public void test_serialization() throws Exception { - DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRANCE); - String[][] zoneStrings = symbols.getZoneStrings(); - assertNotNull(zoneStrings); - - // serialize - ByteArrayOutputStream byteOStream = new ByteArrayOutputStream(); - ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream); - objectOStream.writeObject(symbols); - - // and deserialize - ObjectInputStream objectIStream = new ObjectInputStream( - new ByteArrayInputStream(byteOStream.toByteArray())); - DateFormatSymbols symbolsD = (DateFormatSymbols) objectIStream - .readObject(); - - // The associated currency will not persist - String[][] zoneStringsD = symbolsD.getZoneStrings(); - assertNotNull(zoneStringsD); - assertEquals(symbols, symbolsD); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java deleted file mode 100644 index 1f7feea..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.text.DateFormat; -import java.text.DateFormatSymbols; -import java.text.FieldPosition; -import java.text.NumberFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -@TestTargetClass(DateFormat.class) -public class DateFormatTest extends junit.framework.TestCase { - - private class MockDateFormat extends DateFormat { - - private static final long serialVersionUID = 1L; - - public MockDateFormat() { - super(); - } - - @Override - public Date parse(String source, ParsePosition pos) { - // it is a fake - return null; - } - - @Override - public StringBuffer format(Date date, StringBuffer toAppendTo, - FieldPosition fieldPosition) { - // it is a fake - return null; - } - } - - /** - * @tests java.text.DateFormat#DateFormat() Test of method - * java.text.DateFormat#DateFormat(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "DateFormat", - args = {} - ) - public void test_Constructor() { - try { - new MockDateFormat(); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#equals(java.lang.Object obj) Test of - * java.text.DateFormat#equals(java.lang.Object obj). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - try { - DateFormat format = DateFormat.getInstance(); - DateFormat clone = (DateFormat) format.clone(); - assertTrue("Clone and parent are not equaled", format.equals(clone)); - assertTrue("Clone is equal to other object", !clone - .equals(DateFormat.getTimeInstance())); - format.setCalendar(Calendar.getInstance()); - assertTrue("Clone and parent are not equaled", format.equals(clone)); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#format(java.util.Date) Test of method - * java.text.DateFormat#format(java.util.Date). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {java.util.Date.class} - ) - public void test_formatLjava_util_Date() { - try { - DateFormat format = DateFormat.getDateTimeInstance( - DateFormat.SHORT, DateFormat.SHORT, Locale.US); - Date current = new Date(); - String dtf = format.format(current); - SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy h:mm a"); - assertTrue("Incorrect date format", sdf.format(current).equals(dtf)); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#format(Object, StringBuffer, FieldPosition) - * Test of method java.text.DateFormat#format(Object, StringBuffer, - * FieldPosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {java.lang.Object.class, java.lang.StringBuffer.class, java.text.FieldPosition.class} - ) - public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { - try { - DateFormat format = DateFormat.getDateTimeInstance( - DateFormat.SHORT, DateFormat.SHORT, Locale.US); - Date current = new Date(); - StringBuffer toAppend = new StringBuffer(); - FieldPosition fp = new FieldPosition(DateFormat.YEAR_FIELD); - StringBuffer sb = format.format(current, toAppend, fp); - SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy h:mm a"); - assertTrue("Incorrect date format", sdf.format(current).equals( - sb.toString())); - assertTrue("Incorrect beginIndex of filed position", fp - .getBeginIndex() == sb.lastIndexOf("/") + 1); - assertTrue("Incorrect endIndex of filed position", - fp.getEndIndex() == sb.lastIndexOf("/") + 3); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#clone() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - DateFormat format = DateFormat.getInstance(); - DateFormat clone = (DateFormat) format.clone(); - assertTrue("Clone not equal", format.equals(clone)); - clone.getNumberFormat().setMinimumFractionDigits(123); - assertTrue("Clone shares NumberFormat", !format.equals(clone)); - } - - /** - * @tests java.text.DateFormat#getAvailableLocales() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAvailableLocales", - args = {} - ) - public void test_getAvailableLocales() { - Locale[] locales = DateFormat.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; - DateFormat f1 = DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.SHORT, locales[i]); - assertTrue("Doesn't work", - f1.format(new Date()).getClass() == String.class); - } - // TODO: currently, it is not mandatory to have both English and German locales bug 1943269 - // assertTrue("Missing locales", english && german); - } - - /** - * @tests java.text.DateFormat#getCalendar() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCalendar", - args = {} - ) - public void test_getCalendar() { - DateFormat format = DateFormat.getInstance(); - Calendar cal1 = format.getCalendar(); - Calendar cal2 = format.getCalendar(); - assertTrue("Calendars not identical", cal1 == cal2); - } - - /** - * @tests java.text.DateFormat#getDateInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateInstance", - args = {} - ) - public void test_getDateInstance() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateInstance(); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default", f2.equals(DateFormat.getDateInstance( - DateFormat.DEFAULT, Locale.getDefault()))); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - /** - * @tests java.text.DateFormat#getDateInstance(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateInstance", - args = {int.class} - ) - public void test_getDateInstanceI() { - assertTrue("Default not medium", - DateFormat.DEFAULT == DateFormat.MEDIUM); - - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat - .getDateInstance(DateFormat.SHORT); - assertTrue("Wrong class1", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default1", f2.equals(DateFormat.getDateInstance( - DateFormat.SHORT, Locale.getDefault()))); - assertTrue("Wrong symbols1", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work1", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM); - assertTrue("Wrong class2", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default2", f2.equals(DateFormat.getDateInstance( - DateFormat.MEDIUM, Locale.getDefault()))); - assertTrue("Wrong symbols2", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work2", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG); - assertTrue("Wrong class3", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default3", f2.equals(DateFormat.getDateInstance( - DateFormat.LONG, Locale.getDefault()))); - assertTrue("Wrong symbols3", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work3", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.FULL); - assertTrue("Wrong class4", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default4", f2.equals(DateFormat.getDateInstance( - DateFormat.FULL, Locale.getDefault()))); - assertTrue("Wrong symbols4", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work4", - f2.format(new Date()).getClass() == String.class); - - // regression test for HARMONY-940 - try { - DateFormat.getDateInstance(77); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - /** - * @tests java.text.DateFormat#getDateInstance(int, java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateInstance", - args = {int.class, java.util.Locale.class} - ) - public void test_getDateInstanceILjava_util_Locale() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateInstance( - DateFormat.SHORT, Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.FULL, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - // regression test for HARMONY-940 - try { - DateFormat.getDateInstance(77, Locale.GERMAN); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - /** - * @tests java.text.DateFormat#getDateTimeInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateTimeInstance", - args = {} - ) - public void test_getDateTimeInstance() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat - .getDateTimeInstance(); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default", f2.equals(DateFormat.getDateTimeInstance( - DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault()))); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - private void testDateTime(int dStyle, int tStyle) { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat - .getDateTimeInstance(dStyle, tStyle); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - SimpleDateFormat date = (SimpleDateFormat) DateFormat.getDateInstance( - dStyle, Locale.getDefault()); - SimpleDateFormat time = (SimpleDateFormat) DateFormat.getTimeInstance( - tStyle, Locale.getDefault()); - assertTrue("Wrong default", f2.toPattern().equals( - date.toPattern() + " " + time.toPattern())); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - /** - * @tests java.text.DateFormat#getDateTimeInstance(int, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateTimeInstance", - args = {int.class, int.class} - ) - public void test_getDateTimeInstanceII() { - testDateTime(DateFormat.SHORT, DateFormat.SHORT); - testDateTime(DateFormat.SHORT, DateFormat.MEDIUM); - testDateTime(DateFormat.SHORT, DateFormat.LONG); - testDateTime(DateFormat.SHORT, DateFormat.FULL); - - testDateTime(DateFormat.MEDIUM, DateFormat.SHORT); - testDateTime(DateFormat.MEDIUM, DateFormat.MEDIUM); - testDateTime(DateFormat.MEDIUM, DateFormat.LONG); - testDateTime(DateFormat.MEDIUM, DateFormat.FULL); - - testDateTime(DateFormat.LONG, DateFormat.SHORT); - testDateTime(DateFormat.LONG, DateFormat.MEDIUM); - testDateTime(DateFormat.LONG, DateFormat.LONG); - testDateTime(DateFormat.LONG, DateFormat.FULL); - - testDateTime(DateFormat.FULL, DateFormat.SHORT); - testDateTime(DateFormat.FULL, DateFormat.MEDIUM); - testDateTime(DateFormat.FULL, DateFormat.LONG); - testDateTime(DateFormat.FULL, DateFormat.FULL); - - // regression test for HARMONY-940 - try { - DateFormat.getDateTimeInstance(77, 66); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - private void testDateTimeLocale(int dStyle, int tStyle) { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat - .getDateTimeInstance(dStyle, tStyle, Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - SimpleDateFormat date = (SimpleDateFormat) DateFormat.getDateInstance( - dStyle, Locale.GERMAN); - SimpleDateFormat time = (SimpleDateFormat) DateFormat.getTimeInstance( - tStyle, Locale.GERMAN); - assertTrue("Wrong default", f2.toPattern().equals( - date.toPattern() + " " + time.toPattern())); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - /** - * @tests java.text.DateFormat#getDateTimeInstance(int, int, - * java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDateTimeInstance", - args = {int.class, int.class, java.util.Locale.class} - ) - public void test_getDateTimeInstanceIILjava_util_Locale() { - testDateTimeLocale(DateFormat.SHORT, DateFormat.SHORT); - testDateTimeLocale(DateFormat.SHORT, DateFormat.MEDIUM); - testDateTimeLocale(DateFormat.SHORT, DateFormat.LONG); - testDateTimeLocale(DateFormat.SHORT, DateFormat.FULL); - - testDateTimeLocale(DateFormat.MEDIUM, DateFormat.SHORT); - testDateTimeLocale(DateFormat.MEDIUM, DateFormat.MEDIUM); - testDateTimeLocale(DateFormat.MEDIUM, DateFormat.LONG); - testDateTimeLocale(DateFormat.MEDIUM, DateFormat.FULL); - - testDateTimeLocale(DateFormat.LONG, DateFormat.SHORT); - testDateTimeLocale(DateFormat.LONG, DateFormat.MEDIUM); - testDateTimeLocale(DateFormat.LONG, DateFormat.LONG); - testDateTimeLocale(DateFormat.LONG, DateFormat.FULL); - - testDateTimeLocale(DateFormat.FULL, DateFormat.SHORT); - testDateTimeLocale(DateFormat.FULL, DateFormat.MEDIUM); - testDateTimeLocale(DateFormat.FULL, DateFormat.LONG); - testDateTimeLocale(DateFormat.FULL, DateFormat.FULL); - - // regression test for HARMONY-940 - try { - DateFormat.getDateTimeInstance(77, 66, Locale.GERMAN); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - /** - * @tests java.text.DateFormat#getInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getInstance", - args = {} - ) - public void test_getInstance() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getInstance(); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default", f2.equals(DateFormat.getDateTimeInstance( - DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()))); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - /** - * @tests java.text.DateFormat#getNumberFormat() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getNumberFormat", - args = {} - ) - public void test_getNumberFormat() { - DateFormat format = DateFormat.getInstance(); - NumberFormat nf1 = format.getNumberFormat(); - NumberFormat nf2 = format.getNumberFormat(); - assertTrue("NumberFormats not identical", nf1 == nf2); - } - - /** - * @tests java.text.DateFormat#getTimeInstance() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimeInstance", - args = {} - ) - public void test_getTimeInstance() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getTimeInstance(); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default", f2.equals(DateFormat.getTimeInstance( - DateFormat.DEFAULT, Locale.getDefault()))); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - } - - /** - * @tests java.text.DateFormat#getTimeInstance(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimeInstance", - args = {int.class} - ) - public void test_getTimeInstanceI() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat - .getTimeInstance(DateFormat.SHORT); - assertTrue("Wrong class1", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default1", f2.equals(DateFormat.getTimeInstance( - DateFormat.SHORT, Locale.getDefault()))); - assertTrue("Wrong symbols1", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work1", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.MEDIUM); - assertTrue("Wrong class2", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default2", f2.equals(DateFormat.getTimeInstance( - DateFormat.MEDIUM, Locale.getDefault()))); - assertTrue("Wrong symbols2", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work2", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.LONG); - assertTrue("Wrong class3", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default3", f2.equals(DateFormat.getTimeInstance( - DateFormat.LONG, Locale.getDefault()))); - assertTrue("Wrong symbols3", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work3", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.FULL); - assertTrue("Wrong class4", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong default4", f2.equals(DateFormat.getTimeInstance( - DateFormat.FULL, Locale.getDefault()))); - assertTrue("Wrong symbols4", f2.getDateFormatSymbols().equals( - new DateFormatSymbols())); - assertTrue("Doesn't work4", - f2.format(new Date()).getClass() == String.class); - - // regression test for HARMONY-940 - try { - DateFormat.getTimeInstance(77); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - /** - * @tests java.text.DateFormat#getTimeInstance(int, java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimeInstance", - args = {int.class, java.util.Locale.class} - ) - public void test_getTimeInstanceILjava_util_Locale() { - SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getTimeInstance( - DateFormat.SHORT, Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.MEDIUM, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.LONG, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - f2 = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.FULL, - Locale.GERMAN); - assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class); - assertTrue("Wrong symbols", f2.getDateFormatSymbols().equals( - new DateFormatSymbols(Locale.GERMAN))); - assertTrue("Doesn't work", - f2.format(new Date()).getClass() == String.class); - - try { - DateFormat.getTimeInstance(77, Locale.GERMAN); - fail("Should throw IAE"); - } catch (IllegalArgumentException iae) { - // expected - } - } - - /** - * @tests java.text.DateFormat#getTimeZone() Test of method - * java.text.DateFormat#getTimeZone(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimeZone", - args = {} - ) - public void test_getTimeZone() { - try { - DateFormat format = DateFormat.getInstance(); - TimeZone tz = format.getTimeZone(); - //if(1 == 1) - // throw new Exception(tz.getClass().getName()); - // We know we are not sun.util so: - // Redundant checking - //assertFalse("Incorrect zone info", tz.getClass().getName().equals( - // "sun.util.calendar.ZoneInfo")); - assertTrue("Incorrect time zone", tz.equals(format.getCalendar() - .getTimeZone())); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#hashCode() Test of method - * java.text.DateFormat#hashCode(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - try { - DateFormat df1 = DateFormat.getInstance(); - DateFormat df2 = (DateFormat) df1.clone(); - assertTrue("Hash codes of clones are not equal", - df1.hashCode() == df2.hashCode()); - assertTrue("Hash codes of different objects are the same", df1 - .hashCode() != DateFormat.getDateInstance().hashCode()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#isLenient() Test of method - * java.text.DateFormat#isLenient(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isLenient", - args = {} - ) - public void test_isLenient() { - DateFormat df = DateFormat.getInstance(); - Calendar c = df.getCalendar(); - if (df.isLenient()) { - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - c.setLenient(false); - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - fail("Expected IllegalArgumentException was not thrown"); - } catch (IllegalArgumentException e) { - // expected - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } else { - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - fail("Expected IllegalArgumentException was not thrown"); - } catch (IllegalArgumentException e) { - // expected - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - c.setLenient(true); - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - } - - /** - * @tests java.text.DateFormat#setCalendar(java.util.Calendar) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setCalendar", - args = {java.util.Calendar.class} - ) - public void test_setCalendarLjava_util_Calendar() { - DateFormat format = DateFormat.getInstance(); - Calendar cal = Calendar.getInstance(); - format.setCalendar(cal); - assertTrue("Not identical Calendar", cal == format.getCalendar()); - } - - /** - * @tests java.text.DateFormat#setNumberFormat(java.text.NumberFormat) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setNumberFormat", - args = {java.text.NumberFormat.class} - ) - public void test_setNumberFormatLjava_text_NumberFormat() { - DateFormat format = DateFormat.getInstance(); - NumberFormat f1 = NumberFormat.getInstance(); - format.setNumberFormat(f1); - assertTrue("Not identical NumberFormat", f1 == format.getNumberFormat()); - } - - /** - * @tests java.text.DateFormat#parse(String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class} - ) - public void test_parseLString() { - DateFormat format = DateFormat.getInstance(); - - try { - format.parse("not a Date"); - fail("should throw ParseException first"); - } catch (ParseException pe) { - assertNotNull(pe.getMessage()); - } - - Date current = new Date(); - - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(current.getHours(), date.getHours()); - assertEquals(current.getMinutes(), date.getMinutes()); - assertEquals(0, date.getSeconds()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - try { - format.parse("27/08/1998"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - try { - format.parse("30/30/908 4:50, PDT"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - try { - format.parse("837039928046"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - format = DateFormat.getDateInstance(); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(0, date.getHours()); - assertEquals(0, date.getMinutes()); - assertEquals(0, date.getSeconds()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - try { - format.parse("Jan 16 1970"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - try { - format.parse("27/08/1998"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - format = DateFormat.getDateInstance(DateFormat.LONG); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(0, date.getHours()); - assertEquals(0, date.getMinutes()); - assertEquals(0, date.getSeconds()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - format = DateFormat.getDateInstance(DateFormat.MEDIUM); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(0, date.getHours()); - assertEquals(0, date.getMinutes()); - assertEquals(0, date.getSeconds()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - format = DateFormat.getTimeInstance(); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(1, date.getDate()); - assertEquals(0, date.getMonth()); - assertEquals(70, date.getYear()); - assertEquals(current.getHours(), date.getHours()); - assertEquals(current.getMinutes(), date.getMinutes()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - try { - format.parse("8:58:44"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - format = DateFormat.getDateTimeInstance(); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(current.getHours(), date.getHours()); - assertEquals(current.getMinutes(), date.getMinutes()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - try { - format.parse("January 31 1970 7:52:34 AM PST"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - try { - format.parse("January 31 1970"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - - format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); - try { - Date date = format.parse(format.format(current).toString()); - assertEquals(current.getDate(), date.getDate()); - assertEquals(current.getDay(), date.getDay()); - assertEquals(current.getMonth(), date.getMonth()); - assertEquals(current.getYear(), date.getYear()); - assertEquals(current.getHours(), date.getHours()); - assertEquals(current.getMinutes(), date.getMinutes()); - } catch(ParseException pe) { - fail("ParseException was thrown for current Date."); - } - - try { - format.parse("January 16, 1970 8:03:52 PM CET"); - fail("ParseException was not thrown."); - } catch(ParseException pe) { - //expected - } - } - - /** - * @tests java.text.DateFormat#parseObject(String, ParsePosition) Test of - * method java.text.DateFormat#parseObject(String, ParsePosition). - * Case 1: Try to parse correct data string. Case 2: Try to parse - * partialy correct data string. Case 3: Try to use argument - * ParsePosition as null. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parseObject", - args = {java.lang.String.class, java.text.ParsePosition.class} - ) - public void test_parseObjectLjava_lang_StringLjava_text_ParsePosition() { - DateFormat df = DateFormat.getInstance(); - try { - // case 1: Try to parse correct data string. - Date current = new Date(); - ParsePosition pp = new ParsePosition(0); - int parseIndex = pp.getIndex(); - Date result = (Date) df.parseObject(df.format(current), pp); - - assertEquals("Dates are different.", current.getDate(), result.getDate()); - assertEquals("Days are different.", current.getDay(), result.getDay()); - assertEquals("Months are different.", current.getMonth(), result.getMonth()); - assertEquals("Years are different.", current.getYear(), result.getYear()); - assertEquals("Hours are different", current.getHours(), result.getHours()); - assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes()); - - assertTrue("Parse operation return null", result != null); - assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex); - - // case 2: Try to parse partially correct data string. - pp.setIndex(0); - char[] cur = df.format(current).toCharArray(); - cur[cur.length / 2] = 'Z'; - String partialCorrect = new String(cur); - result = (Date) df.parseObject(partialCorrect, pp); - assertTrue("Parse operation return not-null", result == null); - assertTrue("ParseIndex is incorrect", pp.getIndex() == 0); - assertTrue("ParseErrorIndex is incorrect", - pp.getErrorIndex() == cur.length / 2); - - pp.setIndex(2); - char[] curDate = df.format(current).toCharArray(); - char [] newArray = new char[curDate.length + pp.getIndex()]; - for(int i = 0; i < curDate.length; i++) { - newArray[i + pp.getIndex()] = curDate[i]; - } - result = (Date) df.parseObject(new String(newArray), pp); - //assertEquals(current, result); - - assertEquals("Dates are different.", current.getDate(), result.getDate()); - assertEquals("Days are different.", current.getDay(), result.getDay()); - assertEquals("Months are different.", current.getMonth(), result.getMonth()); - assertEquals("Years are different.", current.getYear(), result.getYear()); - assertEquals("Hours are different", current.getHours(), result.getHours()); - assertEquals("Minutes are diffetrent,", current.getMinutes(), result.getMinutes()); - - // case 3: Try to use argument ParsePosition as null. - try { - df.parseObject(df.format(current), null); - fail("Expected NullPointerException was not thrown"); - } catch (NullPointerException e) { - // expected - } - - assertNull(df.parseObject("test", pp)); - - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#setLenient(boolean) Test of method - * java.text.DateFormat#setLenient(boolean). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setLenient", - args = {boolean.class} - ) - public void test_setLenientZ() { - DateFormat df = DateFormat.getInstance(); - Calendar c = df.getCalendar(); - try { - c.setLenient(true); - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - c.setLenient(false); - try { - c.set(Calendar.DAY_OF_MONTH, 32); - c.get(Calendar.DAY_OF_MONTH); - fail("Expected IllegalArgumentException was not thrown"); - } catch (IllegalArgumentException e) { - // expected - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } catch (Exception e) { - fail("Uexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#setTimeZone(TimeZone) Test of method - * java.text.DateFormat#setTimeZone(TimeZone). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setTimeZone", - args = {java.util.TimeZone.class} - ) - public void test_setTimeZoneLjava_util_TimeZone() { - try { - DateFormat format = DateFormat.getInstance(); - TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - format.setTimeZone(tz); - assertTrue("TimeZone is set incorrectly", tz.equals(format - .getTimeZone())); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DateFormat#parse(String) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class} - ) - public void test_parse_LString() { - DateFormat format = DateFormat.getInstance(); - try { - format.parse("not a Date"); - fail("should throw ParseException first"); - } catch (ParseException e) { - assertNotNull(e.getMessage()); - } - } - - /** - * @tests java.text.DateFormat#setLenient(boolean) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "setLenient", - args = {boolean.class} - ) - public void test_setLenient() { - Date d = null; - DateFormat output = new SimpleDateFormat("MM/dd/yy"); - output.setLenient(false); - try { - d = output.parse("01/01/-1"); - fail("Should throw ParseException here."); - } catch (ParseException e) {} - } - -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java deleted file mode 100644 index 5c010f2..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java +++ /dev/null @@ -1,891 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import tests.support.Support_Locale; -import dalvik.annotation.AndroidOnly; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; - -import junit.framework.TestCase; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.NumberFormat; -import java.util.Currency; -import java.util.Locale; - -@TestTargetClass(DecimalFormatSymbols.class) -public class DecimalFormatSymbolsTest extends TestCase { - - DecimalFormatSymbols dfs; - - DecimalFormatSymbols dfsUS; - - /** - * @tests java.text.DecimalFormatSymbols#DecimalFormatSymbols() Test of - * method java.text.DecimalFormatSymbols#DecimalFormatSymbols(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "DecimalFormatSymbols", - args = {} - ) - public void test_Constructor() { - // Test for method java.text.DecimalFormatSymbols() - try { - new DecimalFormatSymbols(); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#DecimalFormatSymbols(java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "DecimalFormatSymbols", - args = {java.util.Locale.class} - ) - public void test_ConstructorLjava_util_Locale() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale("en", - "us")); - assertEquals("Returned incorrect symbols", '%', dfs.getPercent()); - - try { - new DecimalFormatSymbols(null); - fail("NullPointerException was not thrown."); - } catch(NullPointerException npe) { - //expected - } - } - - /** - * @tests java.text.DecimalFormatSymbols#getAvailableLocales() - */ - public void test_getAvailableLocales_no_provider() throws Exception { - Locale[] locales = DecimalFormatSymbols.getAvailableLocales(); - assertNotNull(locales); - // must contain Locale.US - boolean flag = false; - for (Locale locale : locales) { - if (locale.equals(Locale.US)) { - flag = true; - break; - } - } - assertTrue(flag); - } - - /** - * @tests java.text.DecimalFormatSymbols#getInstance() - */ - public void test_getInstance() { - assertEquals(new DecimalFormatSymbols(), DecimalFormatSymbols.getInstance()); - assertEquals(new DecimalFormatSymbols(Locale.getDefault()), - DecimalFormatSymbols.getInstance()); - - assertNotSame(DecimalFormatSymbols.getInstance(), DecimalFormatSymbols.getInstance()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getInstance(Locale) - */ - public void test_getInstanceLjava_util_Locale() { - try { - DecimalFormatSymbols.getInstance(null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - assertEquals(new DecimalFormatSymbols(Locale.GERMANY), DecimalFormatSymbols - .getInstance(Locale.GERMANY)); - - Locale locale = new Locale("not exist language", "not exist country"); - DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale); - assertNotNull(symbols); - // BEGIN android-removed: this test is wrong, and confuses default locale with root locale. - // assertEquals(DecimalFormatSymbols.getInstance(), symbols); - // END android-removed - } - - /** - * @tests java.text.DecimalFormatSymbols#clone() Test of method - * java.text.DecimalFormatSymbols#clone(). Case 1: Compare of - * internal variables of cloned objects. Case 2: Compare of clones. - * Case 3: Change the content of the clone. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - try { - // case 1: Compare of internal variables of cloned objects - DecimalFormatSymbols fs = new DecimalFormatSymbols(Locale.US); - DecimalFormatSymbols fsc = (DecimalFormatSymbols) fs.clone(); - assertEquals(fs.getCurrency(), fsc.getCurrency()); - - // case 2: Compare of clones - fs = new DecimalFormatSymbols(); - DecimalFormatSymbols fsc2 = (DecimalFormatSymbols) (fs.clone()); - // make sure the objects are equal - assertTrue("Object's clone isn't equal!", fs.equals(fsc2)); - - // case 3: - // change the content of the clone and make sure it's not equal - // anymore - // verifies that it's data is now distinct from the original - fs.setNaN("not-a-number"); - assertTrue("Object's changed clone should not be equal!", !fs - .equals(fsc2)); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - assertTrue("Equal objects returned false", dfs.equals(dfs.clone())); - dfs.setDigit('B'); - assertTrue("Un-Equal objects returned true", !dfs - .equals(new DecimalFormatSymbols())); - - } - - /** - * @tests java.text.DecimalFormatSymbols#getCurrency() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCurrency", - args = {} - ) - public void test_getCurrency() { - Locale csCzLocale = new Locale("cs", "CZ"); - Locale czLocale = new Locale("", "CZ"); - Locale csLocale = new Locale("cs", ""); - Locale deLocale = new Locale("de", "AT"); - Locale[] requiredLocales = {Locale.US, csCzLocale, czLocale, csLocale, deLocale}; - if (!Support_Locale.areLocalesAvailable(requiredLocales)) { - // locale dependent test, bug 1943269 - return; - } - Currency currency = Currency.getInstance("USD"); - assertEquals("Returned incorrect currency", - dfsUS.getCurrency(), currency); - - // use cs_CZ instead - //Currency currK = Currency.getInstance("KRW"); - Currency currC = Currency.getInstance("CZK"); - Currency currX = Currency.getInstance("XXX"); - Currency currE = Currency.getInstance("EUR"); - // Currency currF = Currency.getInstance("FRF"); - - - DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(csCzLocale); - assertTrue("Test1: Returned incorrect currency", - dfs1.getCurrency() == currC); - assertEquals("Test1: Returned incorrect currencySymbol", "K\u010d", dfs1 - .getCurrencySymbol()); - assertEquals("Test1: Returned incorrect intlCurrencySymbol", "CZK", - dfs1.getInternationalCurrencySymbol()); - - - dfs1 = new DecimalFormatSymbols(czLocale); - assertTrue("Test2: Returned incorrect currency", - dfs1.getCurrency() == currC); - // BEGIN android-changed - // ICU4.2.1, the currency symbol for CZK is changed from CZK to K\u010d in en.txt. - assertEquals("Test2: Returned incorrect currencySymbol", "K\u010d", dfs1 - .getCurrencySymbol()); - // END android-changed - assertEquals("Test2: Returned incorrect intlCurrencySymbol", "CZK", - dfs1.getInternationalCurrencySymbol()); - - dfs1 = new DecimalFormatSymbols(csLocale); - assertEquals("Test3: Returned incorrect currency", - currX, dfs1.getCurrency()); - assertEquals("Test3: Returned incorrect currencySymbol", "\u00a4", dfs1 - .getCurrencySymbol()); - assertEquals("Test3: Returned incorrect intlCurrencySymbol", "XXX", - dfs1.getInternationalCurrencySymbol()); - - dfs1 = new DecimalFormatSymbols(deLocale); - assertTrue("Test4: Returned incorrect currency", - dfs1.getCurrency() == currE); - assertEquals("Test4: Returned incorrect currencySymbol", "\u20ac", dfs1 - .getCurrencySymbol()); - assertEquals("Test4: Returned incorrect intlCurrencySymbol", "EUR", - dfs1.getInternationalCurrencySymbol()); - - // RI fails these tests since it doesn't have the PREEURO variant - // dfs1 = new DecimalFormatSymbols(new Locale("fr", "FR","PREEURO")); - // assertTrue("Test5: Returned incorrect currency", dfs1.getCurrency() - // == currF); - // assertTrue("Test5: Returned incorrect currencySymbol", - // dfs1.getCurrencySymbol().equals("F")); - // assertTrue("Test5: Returned incorrect intlCurrencySymbol", - // dfs1.getInternationalCurrencySymbol().equals("FRF")); - } - - /** - * @tests java.text.DecimalFormatSymbols#getCurrencySymbol() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getCurrencySymbol", - args = {} - ) - public void test_getCurrencySymbol() { - assertEquals("Returned incorrect currencySymbol", "$", dfsUS - .getCurrencySymbol()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getDecimalSeparator() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDecimalSeparator", - args = {} - ) - public void test_getDecimalSeparator() { - dfs.setDecimalSeparator('*'); - assertEquals("Returned incorrect DecimalSeparator symbol", '*', dfs - .getDecimalSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getDigit() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDigit", - args = {} - ) - public void test_getDigit() { - dfs.setDigit('*'); - assertEquals("Returned incorrect Digit symbol", '*', dfs.getDigit()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getExponentSeparator() - */ - public void test_getExponentSeparator() { - dfs.setExponentSeparator("EE"); - assertEquals("Returned incorrect Exponent Separator symbol", "EE", dfs - .getExponentSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getGroupingSeparator() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getGroupingSeparator", - args = {} - ) - public void test_getGroupingSeparator() { - dfs.setGroupingSeparator('*'); - assertEquals("Returned incorrect GroupingSeparator symbol", '*', dfs - .getGroupingSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getInfinity() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getInfinity", - args = {} - ) - public void test_getInfinity() { - dfs.setInfinity("&"); - assertTrue("Returned incorrect Infinity symbol", - dfs.getInfinity() == "&"); - } - - /** - * @tests java.text.DecimalFormatSymbols#getInternationalCurrencySymbol() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getInternationalCurrencySymbol", - args = {} - ) - public void test_getInternationalCurrencySymbol() { - assertEquals("Returned incorrect InternationalCurrencySymbol", "USD", - dfsUS.getInternationalCurrencySymbol()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getMinusSign() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getMinusSign", - args = {} - ) - public void test_getMinusSign() { - dfs.setMinusSign('&'); - assertEquals("Returned incorrect MinusSign symbol", '&', dfs - .getMinusSign()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getMonetaryDecimalSeparator() Test - * of method - * java.text.DecimalFormatSymbols#getMonetaryDecimalSeparator(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getMonetaryDecimalSeparator", - args = {} - ) - public void test_getMonetaryDecimalSeparator() { - try { - dfs.setMonetaryDecimalSeparator(','); - assertEquals("Returned incorrect MonetaryDecimalSeparator symbol", - ',', dfs.getMonetaryDecimalSeparator()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#getNaN() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getNaN", - args = {} - ) - public void test_getNaN() { - dfs.setNaN("NAN!!"); - assertEquals("Returned incorrect nan symbol", "NAN!!", dfs.getNaN()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getPatternSeparator() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getPatternSeparator", - args = {} - ) - public void test_getPatternSeparator() { - dfs.setPatternSeparator('X'); - assertEquals("Returned incorrect PatternSeparator symbol", 'X', dfs - .getPatternSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getPercent() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getPercent", - args = {} - ) - public void test_getPercent() { - dfs.setPercent('*'); - assertEquals("Returned incorrect Percent symbol", '*', dfs.getPercent()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getPerMill() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getPerMill", - args = {} - ) - public void test_getPerMill() { - dfs.setPerMill('#'); - assertEquals("Returned incorrect PerMill symbol", '#', dfs.getPerMill()); - } - - /** - * @tests java.text.DecimalFormatSymbols#getZeroDigit() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getZeroDigit", - args = {} - ) - public void test_getZeroDigit() { - dfs.setZeroDigit('*'); - assertEquals("Returned incorrect ZeroDigit symbol", '*', dfs - .getZeroDigit()); - } - - /** - * @tests java.text.DecimalFormatSymbols#hashCode() Test of method - * java.text.DecimalFormatSymbols#hashCode(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - @AndroidOnly("Succeeds against Android.") - public void test_hashCode() { - try { - DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(); - DecimalFormatSymbols dfs2 = (DecimalFormatSymbols) dfs1.clone(); - assertTrue("Hash codes of equal object are equal", dfs2 - .hashCode() == dfs1.hashCode()); - dfs1.setInfinity("infinity_infinity"); - assertTrue("Hash codes of non-equal objects are equal", dfs2 - .hashCode() != dfs1.hashCode()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#setCurrency(java.util.Currency) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setCurrency", - args = {java.util.Currency.class} - ) - public void test_setCurrencyLjava_util_Currency() { - Locale locale = Locale.CANADA; - DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat - .getCurrencyInstance(locale)).getDecimalFormatSymbols(); - - try { - dfs.setCurrency(null); - fail("Expected NullPointerException"); - } catch (NullPointerException e) { - } - - Currency currency = Currency.getInstance("JPY"); - dfs.setCurrency(currency); - - assertTrue("Returned incorrect currency", currency == dfs.getCurrency()); - assertEquals("Returned incorrect currency symbol", currency.getSymbol( - locale), dfs.getCurrencySymbol()); - assertTrue("Returned incorrect international currency symbol", currency - .getCurrencyCode().equals(dfs.getInternationalCurrencySymbol())); - } - - /** - * @tests java.text.DecimalFormatSymbols#setCurrencySymbol(java.lang.String) - * Test of method - * java.text.DecimalFormatSymbols#setCurrencySymbol(java.lang.String). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setCurrencySymbol", - args = {java.lang.String.class} - ) - public void test_setCurrencySymbolLjava_lang_String() { - try { - dfs.setCurrencySymbol("$"); - assertEquals("Returned incorrect CurrencySymbol symbol", "$", dfs - .getCurrencySymbol()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#setDecimalSeparator(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setDecimalSeparator", - args = {char.class} - ) - public void test_setDecimalSeparatorC() { - dfs.setDecimalSeparator('*'); - assertEquals("Returned incorrect DecimalSeparator symbol", '*', dfs - .getDecimalSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setDigit(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setDigit", - args = {char.class} - ) - public void test_setDigitC() { - dfs.setDigit('*'); - assertEquals("Returned incorrect Digit symbol", '*', dfs.getDigit()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setExponentSeparator(String) - */ - public void test_setExponentSeparator() { - try { - dfs.setExponentSeparator(null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - dfs.setExponentSeparator(""); - assertEquals("Returned incorrect Exponent Separator symbol", "", dfs - .getExponentSeparator()); - - dfs.setExponentSeparator("what ever you want"); - assertEquals("Returned incorrect Exponent Separator symbol", - "what ever you want", dfs.getExponentSeparator()); - - dfs.setExponentSeparator(" E "); - assertEquals("Returned incorrect Exponent Separator symbol", " E ", dfs - .getExponentSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setGroupingSeparator(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setGroupingSeparator", - args = {char.class} - ) - public void test_setGroupingSeparatorC() { - dfs.setGroupingSeparator('*'); - assertEquals("Returned incorrect GroupingSeparator symbol", '*', dfs - .getGroupingSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setInfinity(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setInfinity", - args = {java.lang.String.class} - ) - public void test_setInfinityLjava_lang_String() { - dfs.setInfinity("&"); - assertTrue("Returned incorrect Infinity symbol", - dfs.getInfinity() == "&"); - } - - /** - * @tests java.text.DecimalFormatSymbols#setInternationalCurrencySymbol(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setInternationalCurrencySymbol", - args = {java.lang.String.class} - ) - public void test_setInternationalCurrencySymbolLjava_lang_String() { - Locale locale = Locale.CANADA; - DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat - .getCurrencyInstance(locale)).getDecimalFormatSymbols(); - Currency currency = Currency.getInstance("JPY"); - dfs.setInternationalCurrencySymbol(currency.getCurrencyCode()); - - assertTrue("Test1: Returned incorrect currency", currency == dfs - .getCurrency()); - assertEquals("Test1: Returned incorrect currency symbol", currency - .getSymbol(locale), dfs.getCurrencySymbol()); - assertTrue("Test1: Returned incorrect international currency symbol", - currency.getCurrencyCode().equals( - dfs.getInternationalCurrencySymbol())); - - String symbol = dfs.getCurrencySymbol(); - dfs.setInternationalCurrencySymbol("bogus"); - assertNull("Test2: Returned incorrect currency", dfs.getCurrency()); - assertTrue("Test2: Returned incorrect currency symbol", dfs - .getCurrencySymbol().equals(symbol)); - assertEquals("Test2: Returned incorrect international currency symbol", - "bogus", dfs.getInternationalCurrencySymbol()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setMinusSign(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setMinusSign", - args = {char.class} - ) - public void test_setMinusSignC() { - dfs.setMinusSign('&'); - assertEquals("Returned incorrect MinusSign symbol", '&', dfs - .getMinusSign()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setMonetaryDecimalSeparator(char) - * Test of method - * java.text.DecimalFormatSymbols#setMonetaryDecimalSeparator(char). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setMonetaryDecimalSeparator", - args = {char.class} - ) - public void test_setMonetaryDecimalSeparatorC() { - try { - dfs.setMonetaryDecimalSeparator('#'); - assertEquals("Returned incorrect MonetaryDecimalSeparator symbol", - '#', dfs.getMonetaryDecimalSeparator()); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.DecimalFormatSymbols#setNaN(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setNaN", - args = {java.lang.String.class} - ) - public void test_setNaNLjava_lang_String() { - dfs.setNaN("NAN!!"); - assertEquals("Returned incorrect nan symbol", "NAN!!", dfs.getNaN()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setPatternSeparator(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setPatternSeparator", - args = {char.class} - ) - public void test_setPatternSeparatorC() { - dfs.setPatternSeparator('X'); - assertEquals("Returned incorrect PatternSeparator symbol", 'X', dfs - .getPatternSeparator()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setPercent(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setPercent", - args = {char.class} - ) - public void test_setPercentC() { - dfs.setPercent('*'); - assertEquals("Returned incorrect Percent symbol", '*', dfs.getPercent()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setPerMill(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setPerMill", - args = {char.class} - ) - public void test_setPerMillC() { - dfs.setPerMill('#'); - assertEquals("Returned incorrect PerMill symbol", '#', dfs.getPerMill()); - } - - /** - * @tests java.text.DecimalFormatSymbols#setZeroDigit(char) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setZeroDigit", - args = {char.class} - ) - public void test_setZeroDigitC() { - dfs.setZeroDigit('*'); - assertEquals("Set incorrect ZeroDigit symbol", '*', dfs.getZeroDigit()); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - dfs = new DecimalFormatSymbols(); - dfsUS = new DecimalFormatSymbols(new Locale("en", "us")); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } - - // Test serialization mechanism of DecimalFormatSymbols - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Checks serialization mechanism.", - method = "!SerializationSelf", - args = {} - ) - public void test_serialization() throws Exception { - DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRANCE); - Currency currency = symbols.getCurrency(); - assertNotNull(currency); - - // serialize - ByteArrayOutputStream byteOStream = new ByteArrayOutputStream(); - ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream); - objectOStream.writeObject(symbols); - - // and deserialize - ObjectInputStream objectIStream = new ObjectInputStream( - new ByteArrayInputStream(byteOStream.toByteArray())); - DecimalFormatSymbols symbolsD = (DecimalFormatSymbols) objectIStream - .readObject(); - - // The associated currency will not persist - currency = symbolsD.getCurrency(); - assertNotNull(currency); - } - - // Use RI to write DecimalFormatSymbols out, use Harmony to read - // DecimalFormatSymbols in. The read symbol will be equal with those - // instantiated inside Harmony. - - // This assertion will not come into existence the other way around. This is - // probably caused by different serialization mechanism used by RI and - // Harmony. - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Make sure all fields have non default values.", - method = "!SerializationGolden", - args = {} - ) - public void test_RIHarmony_compatible() throws Exception { - ObjectInputStream i = null; - try { - DecimalFormatSymbols symbols = new DecimalFormatSymbols( - Locale.FRANCE); - i = new ObjectInputStream( - getClass() - .getClassLoader() - .getResourceAsStream( - "serialization/java/text/DecimalFormatSymbols.ser")); - DecimalFormatSymbols symbolsD = (DecimalFormatSymbols) i - .readObject(); - assertEquals(symbols, symbolsD); - } catch(NullPointerException e) { - assertNotNull("Failed to load /serialization/java/text/" + - "DecimalFormatSymbols.ser", i); - } finally { - try { - if (i != null) { - i.close(); - } - } catch (Exception e) { - } - } - assertDecimalFormatSymbolsRIFrance(dfs); - } - - static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) { - // Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE - /* - * currency = [EUR] - * currencySymbol = [U+20ac] // EURO SIGN - * decimalSeparator = [,][U+002c] - * digit = [#][U+0023] - * groupingSeparator = [U+00a0] // NON-BREAKING SPACE - * infinity = [U+221e] // INFINITY - * internationalCurrencySymbol = [EUR] - * minusSign = [-][U+002d] - * monetaryDecimalSeparator = [,][U+002c] - * naN = [U+fffd] // REPLACEMENT CHARACTER - * patternSeparator = [;][U+003b] - * perMill = [U+2030] // PER MILLE - * percent = [%][U+0025] - * zeroDigit = [0][U+0030] - */ - assertEquals("EUR", dfs.getCurrency().getCurrencyCode()); - assertEquals("\u20AC", dfs.getCurrencySymbol()); - assertEquals(',', dfs.getDecimalSeparator()); - assertEquals('#', dfs.getDigit()); - assertEquals('\u00a0', dfs.getGroupingSeparator()); - assertEquals("\u221e", dfs.getInfinity()); - assertEquals("EUR", dfs.getInternationalCurrencySymbol()); - assertEquals('-', dfs.getMinusSign()); - assertEquals(',', dfs.getMonetaryDecimalSeparator()); - // RI's default NaN is U+FFFD, Harmony's is based on ICU - // This suggests an RI bug, assuming that non-UTF8 bytes are UTF8 and - // getting a conversion failure. - assertEquals("\uFFFD", dfs.getNaN()); - assertEquals('\u003b', dfs.getPatternSeparator()); - assertEquals('\u2030', dfs.getPerMill()); - assertEquals('%', dfs.getPercent()); - assertEquals('0', dfs.getZeroDigit()); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java deleted file mode 100644 index b137e8b..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FieldPositionTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.text.DateFormat; -import java.text.FieldPosition; - -@TestTargetClass(FieldPosition.class) -public class FieldPositionTest extends junit.framework.TestCase { - - /** - * @tests java.text.FieldPosition#FieldPosition(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "FieldPosition", - args = {int.class} - ) - public void test_ConstructorI() { - // Test for constructor java.text.FieldPosition(int) - FieldPosition fpos = new FieldPosition(DateFormat.MONTH_FIELD); - assertEquals("Test1: Constructor failed to set field identifier!", - DateFormat.MONTH_FIELD, fpos.getField()); - assertNull("Constructor failed to set field attribute!", fpos - .getFieldAttribute()); - } - - /** - * @tests java.text.FieldPosition#FieldPosition(java.text.Format$Field) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "FieldPosition", - args = {java.text.Format.Field.class} - ) - public void test_ConstructorLjava_text_Format$Field() { - // Test for constructor java.text.FieldPosition(Format.Field) - FieldPosition fpos = new FieldPosition(DateFormat.Field.MONTH); - assertSame("Constructor failed to set field attribute!", - DateFormat.Field.MONTH, fpos.getFieldAttribute()); - assertEquals("Test1: Constructor failed to set field identifier!", -1, - fpos.getField()); - } - - /** - * @tests java.text.FieldPosition#FieldPosition(java.text.Format$Field, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "FieldPosition", - args = {java.text.Format.Field.class, int.class} - ) - public void test_ConstructorLjava_text_Format$FieldI() { - // Test for constructor java.text.FieldPosition(Format.Field, int) - FieldPosition fpos = new FieldPosition(DateFormat.Field.MONTH, - DateFormat.MONTH_FIELD); - assertSame("Constructor failed to set field attribute!", - DateFormat.Field.MONTH, fpos.getFieldAttribute()); - assertEquals("Test1: Constructor failed to set field identifier!", - DateFormat.MONTH_FIELD, fpos.getField()); - - // test special cases - FieldPosition fpos2 = new FieldPosition(DateFormat.Field.HOUR1, - DateFormat.HOUR1_FIELD); - assertSame("Constructor failed to set field attribute!", - DateFormat.Field.HOUR1, fpos2.getFieldAttribute()); - assertEquals("Test2: Constructor failed to set field identifier!", - DateFormat.HOUR1_FIELD, fpos2.getField()); - - FieldPosition fpos3 = new FieldPosition(DateFormat.Field.TIME_ZONE, - DateFormat.MONTH_FIELD); - assertSame("Constructor failed to set field attribute!", - DateFormat.Field.TIME_ZONE, fpos3.getFieldAttribute()); - assertEquals("Test3: Constructor failed to set field identifier!", - DateFormat.MONTH_FIELD, fpos3.getField()); - } - - /** - * @tests java.text.FieldPosition#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.text.FieldPosition.equals(java.lang.Object) - FieldPosition fpos = new FieldPosition(1); - FieldPosition fpos1 = new FieldPosition(1); - assertTrue("Identical objects were not equal!", fpos.equals(fpos1)); - - FieldPosition fpos2 = new FieldPosition(2); - assertTrue("Objects with a different ID should not be equal!", !fpos - .equals(fpos2)); - - fpos.setBeginIndex(1); - fpos1.setBeginIndex(2); - assertTrue("Objects with a different beginIndex were still equal!", - !fpos.equals(fpos1)); - fpos1.setBeginIndex(1); - fpos1.setEndIndex(2); - assertTrue("Objects with a different endIndex were still equal!", !fpos - .equals(fpos1)); - - FieldPosition fpos3 = new FieldPosition(DateFormat.Field.ERA, 1); - assertTrue("Objects with a different attribute should not be equal!", - !fpos.equals(fpos3)); - FieldPosition fpos4 = new FieldPosition(DateFormat.Field.AM_PM, 1); - assertTrue("Objects with a different attribute should not be equal!", - !fpos3.equals(fpos4)); - } - - /** - * @tests java.text.FieldPosition#getBeginIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getBeginIndex", - args = {} - ) - public void test_getBeginIndex() { - // Test for method int java.text.FieldPosition.getBeginIndex() - FieldPosition fpos = new FieldPosition(1); - fpos.setEndIndex(3); - fpos.setBeginIndex(2); - assertEquals("getBeginIndex should have returned 2", 2, fpos - .getBeginIndex()); - } - - /** - * @tests java.text.FieldPosition#getEndIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getEndIndex", - args = {} - ) - public void test_getEndIndex() { - // Test for method int java.text.FieldPosition.getEndIndex() - FieldPosition fpos = new FieldPosition(1); - fpos.setBeginIndex(2); - fpos.setEndIndex(3); - assertEquals("getEndIndex should have returned 3", 3, fpos - .getEndIndex()); - } - - /** - * @tests java.text.FieldPosition#getField() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getField", - args = {} - ) - public void test_getField() { - // Test for method int java.text.FieldPosition.getField() - FieldPosition fpos = new FieldPosition(65); - assertEquals( - "FieldPosition(65) should have caused getField to return 65", - 65, fpos.getField()); - FieldPosition fpos2 = new FieldPosition(DateFormat.Field.MINUTE); - assertEquals( - "FieldPosition(DateFormat.Field.MINUTE) should have caused getField to return -1", - -1, fpos2.getField()); - } - - /** - * @tests java.text.FieldPosition#getFieldAttribute() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getFieldAttribute", - args = {} - ) - public void test_getFieldAttribute() { - // Test for method int java.text.FieldPosition.getFieldAttribute() - FieldPosition fpos = new FieldPosition(DateFormat.Field.TIME_ZONE); - assertTrue( - "FieldPosition(DateFormat.Field.TIME_ZONE) should have caused getFieldAttribute to return DateFormat.Field.TIME_ZONE", - fpos.getFieldAttribute() == DateFormat.Field.TIME_ZONE); - - FieldPosition fpos2 = new FieldPosition(DateFormat.TIMEZONE_FIELD); - assertNull( - "FieldPosition(DateFormat.TIMEZONE_FIELD) should have caused getFieldAttribute to return null", - fpos2.getFieldAttribute()); - } - - /** - * @tests java.text.FieldPosition#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - // Test for method int java.text.FieldPosition.hashCode() - FieldPosition fpos1 = new FieldPosition(1); - FieldPosition fpos2 = new FieldPosition(1); - assertTrue("test 1: hash codes are not equal for equal objects.", - fpos1.hashCode() == fpos2.hashCode()); - fpos1.setBeginIndex(5); - fpos1.setEndIndex(110); - assertTrue("test 2: hash codes are equal for non equal objects.", - fpos1.hashCode() != fpos2.hashCode()); - fpos2.setBeginIndex(5); - fpos2.setEndIndex(110); - assertTrue("test 3: hash codes are not equal for equal objects.", - fpos1.hashCode() == fpos2.hashCode()); - - FieldPosition fpos3 = new FieldPosition( - DateFormat.Field.DAY_OF_WEEK_IN_MONTH); - - assertTrue("test 4: hash codes are equal for non equal objects.", - fpos2.hashCode() != fpos3.hashCode()); - } - - /** - * @tests java.text.FieldPosition#setBeginIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setBeginIndex", - args = {int.class} - ) - public void test_setBeginIndexI() { - // Test for method void java.text.FieldPosition.setBeginIndex(int) - FieldPosition fpos = new FieldPosition(1); - fpos.setBeginIndex(2); - fpos.setEndIndex(3); - assertEquals("beginIndex should have been set to 2", 2, fpos - .getBeginIndex()); - - fpos.setBeginIndex(Integer.MAX_VALUE); - assertEquals("beginIndex should have been set to Integer.MAX_VALUE", - Integer.MAX_VALUE, fpos.getBeginIndex()); - - fpos.setBeginIndex(-1); - assertEquals("beginIndex should have been set to -1", - -1, fpos.getBeginIndex()); - } - - /** - * @tests java.text.FieldPosition#setEndIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setEndIndex", - args = {int.class} - ) - public void test_setEndIndexI() { - // Test for method void java.text.FieldPosition.setEndIndex(int) - FieldPosition fpos = new FieldPosition(1); - fpos.setEndIndex(3); - fpos.setBeginIndex(2); - assertEquals("EndIndex should have been set to 3", 3, fpos - .getEndIndex()); - - fpos.setEndIndex(Integer.MAX_VALUE); - assertEquals("endIndex should have been set to Integer.MAX_VALUE", - Integer.MAX_VALUE, fpos.getEndIndex()); - - fpos.setEndIndex(-1); - assertEquals("endIndex should have been set to -1", - -1, fpos.getEndIndex()); - } - - /** - * @tests java.text.FieldPosition#toString() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {} - ) - public void test_toString() { - // Test for method java.lang.String java.text.FieldPosition.toString() - FieldPosition fpos = new FieldPosition(1); - fpos.setBeginIndex(2); - fpos.setEndIndex(3); - // string format is not specified - assertNotNull( - "toString returned null", - fpos.toString()); - - FieldPosition fpos2 = new FieldPosition(DateFormat.Field.ERA); - fpos2.setBeginIndex(4); - fpos2.setEndIndex(5); - assertNotNull("ToString returned the wrong value:", - fpos2.toString()); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FormatFieldTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/FormatFieldTest.java deleted file mode 100644 index 0911b0b..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/FormatFieldTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.Format; - - -@TestTargetClass(Format.Field.class) -public class FormatFieldTest extends TestCase { - private class MockFormatField extends Format.Field { - - private static final long serialVersionUID = 1L; - - public MockFormatField(String name) { - super(name); - } - } - - /** - * @tests java.text.Format.Field#FormatField(java.lang.String) Test of - * method java.text.Format.Field#FormatField(java.lang.String). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "Field", - args = {java.lang.String.class} - ) - public void test_Constructor() { - try { - new MockFormatField("test"); - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java deleted file mode 100644 index ad45ab4..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java +++ /dev/null @@ -1,1327 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; - -import junit.framework.TestCase; - -import tests.support.Support_MessageFormat; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.text.ChoiceFormat; -import java.text.DateFormat; -import java.text.FieldPosition; -import java.text.Format; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; - -@TestTargetClass(MessageFormat.class) -public class MessageFormatTest extends TestCase { - - private MessageFormat format1, format2, format3; - - private Locale defaultLocale; - - private void checkSerialization(MessageFormat format) { - try { - ByteArrayOutputStream ba = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(ba); - out.writeObject(format); - out.close(); - ObjectInputStream in = new ObjectInputStream( - new ByteArrayInputStream(ba.toByteArray())); - MessageFormat read = (MessageFormat) in.readObject(); - assertTrue("Not equal: " + format.toPattern(), format.equals(read)); - } catch (IOException e) { - fail("Format: " + format.toPattern() + " caused IOException: " + e); - } catch (ClassNotFoundException e) { - fail("Format: " + format.toPattern() - + " caused ClassNotFoundException: " + e); - } - } - - /** - * @tests java.text.MessageFormat#MessageFormat(java.lang.String, - * java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "IllegalArgumentException is not verified.", - method = "MessageFormat", - args = {java.lang.String.class, java.util.Locale.class} - ) - public void test_ConstructorLjava_lang_StringLjava_util_Locale() { - // Test for method java.text.MessageFormat(java.lang.String, - // java.util.Locale) - Locale mk = new Locale("mk", "MK"); - MessageFormat format = new MessageFormat( - "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}", - mk); - - assertTrue("Wrong locale1", format.getLocale().equals(mk)); - assertTrue("Wrong locale2", format.getFormats()[0].equals(DateFormat - .getDateInstance(DateFormat.DEFAULT, mk))); - assertTrue("Wrong locale3", format.getFormats()[1].equals(NumberFormat - .getCurrencyInstance(mk))); - assertTrue("Wrong locale4", format.getFormats()[2].equals(NumberFormat - .getIntegerInstance(mk))); - } - - /** - * @tests java.text.MessageFormat#MessageFormat(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "MessageFormat", - args = {java.lang.String.class} - ) - public void test_ConstructorLjava_lang_String() { - // Test for method java.text.MessageFormat(java.lang.String) - MessageFormat format = new MessageFormat( - "abc {4,time} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}"); - assertTrue("Not a MessageFormat", - format.getClass() == MessageFormat.class); - Format[] formats = format.getFormats(); - assertNotNull("null formats", formats); - assertTrue("Wrong format count: " + formats.length, formats.length >= 5); - assertTrue("Wrong time format", formats[0].equals(DateFormat - .getTimeInstance())); - assertTrue("Wrong date format", formats[1].equals(DateFormat - .getDateInstance())); - assertTrue("Wrong number format", formats[2].equals(NumberFormat - .getInstance())); - assertTrue("Wrong choice format", formats[3].equals(new ChoiceFormat( - "0.0#low|1.0#high"))); - assertNull("Wrong string format", formats[4]); - - Date date = new Date(); - FieldPosition pos = new FieldPosition(-1); - StringBuffer buffer = new StringBuffer(); - format.format(new Object[] { "123", new Double(1.6), new Double(7.2), - date, date }, buffer, pos); - String result = buffer.toString(); - buffer.setLength(0); - buffer.append("abc "); - buffer.append(DateFormat.getTimeInstance().format(date)); - buffer.append(" def "); - buffer.append(DateFormat.getDateInstance().format(date)); - buffer.append(" ghi "); - buffer.append(NumberFormat.getInstance().format(new Double(7.2))); - buffer.append(" jkl high mnop 123"); - assertTrue("Wrong answer:\n" + result + "\n" + buffer, result - .equals(buffer.toString())); - - assertEquals("Simple string", "Test message", new MessageFormat( - "Test message").format(new Object[0])); - - result = new MessageFormat("Don't").format(new Object[0]); - assertTrue("Should not throw IllegalArgumentException: " + result, - "Dont".equals(result)); - - try { - new MessageFormat("Invalid {1,foobar} format descriptor!"); - fail("Expected test_ConstructorLjava_lang_String to throw IAE."); - } catch (IllegalArgumentException ex) { - // expected - } - - try { - new MessageFormat( - "Invalid {1,date,invalid-spec} format descriptor!"); - } catch (IllegalArgumentException ex) { - // expected - } - - checkSerialization(new MessageFormat("")); - checkSerialization(new MessageFormat("noargs")); - checkSerialization(new MessageFormat("{0}")); - checkSerialization(new MessageFormat("a{0}")); - checkSerialization(new MessageFormat("{0}b")); - checkSerialization(new MessageFormat("a{0}b")); - - // Regression for HARMONY-65 - try { - new MessageFormat("{0,number,integer"); - fail("Assert 0: Failed to detect unmatched brackets."); - } catch (IllegalArgumentException e) { - // expected - } - } - - /** - * @tests java.text.MessageFormat#applyPattern(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "applyPattern", - args = {java.lang.String.class} - ) - public void test_applyPatternLjava_lang_String() { - // Test for method void - // java.text.MessageFormat.applyPattern(java.lang.String) - MessageFormat format = new MessageFormat("test"); - format.applyPattern("xx {0}"); - assertEquals("Invalid number", "xx 46", format - .format(new Object[] { new Integer(46) })); - Date date = new Date(); - String result = format.format(new Object[] { date }); - String expected = "xx " + DateFormat.getInstance().format(date); - assertTrue("Invalid date:\n" + result + "\n" + expected, result - .equals(expected)); - format = new MessageFormat("{0,date}{1,time}{2,number,integer}"); - format.applyPattern("nothing"); - assertEquals("Found formats", "nothing", format.toPattern()); - - format.applyPattern("{0}"); - assertNull("Wrong format", format.getFormats()[0]); - assertEquals("Wrong pattern", "{0}", format.toPattern()); - - format.applyPattern("{0, \t\u001ftime }"); - assertTrue("Wrong time format", format.getFormats()[0] - .equals(DateFormat.getTimeInstance())); - assertEquals("Wrong time pattern", "{0,time}", format.toPattern()); - format.applyPattern("{0,Time, Short\n}"); - assertTrue("Wrong short time format", format.getFormats()[0] - .equals(DateFormat.getTimeInstance(DateFormat.SHORT))); - assertEquals("Wrong short time pattern", "{0,time,short}", format - .toPattern()); - format.applyPattern("{0,TIME,\nmedium }"); - assertTrue("Wrong medium time format", format.getFormats()[0] - .equals(DateFormat.getTimeInstance(DateFormat.MEDIUM))); - assertEquals("Wrong medium time pattern", "{0,time}", format - .toPattern()); - format.applyPattern("{0,time,LONG}"); - assertTrue("Wrong long time format", format.getFormats()[0] - .equals(DateFormat.getTimeInstance(DateFormat.LONG))); - assertEquals("Wrong long time pattern", "{0,time,long}", format - .toPattern()); - format.setLocale(Locale.FRENCH); // use French since English has the - // same LONG and FULL time patterns - format.applyPattern("{0,time, Full}"); - assertTrue("Wrong full time format", format.getFormats()[0] - .equals(DateFormat.getTimeInstance(DateFormat.FULL, - Locale.FRENCH))); -// Outsourced to _AndroidFailure: -// -// assertEquals("Wrong full time pattern", "{0,time,full}", format -// .toPattern()); - format.setLocale(Locale.getDefault()); - - format.applyPattern("{0, date}"); - assertTrue("Wrong date format", format.getFormats()[0] - .equals(DateFormat.getDateInstance())); - assertEquals("Wrong date pattern", "{0,date}", format.toPattern()); - format.applyPattern("{0, date, short}"); - assertTrue("Wrong short date format", format.getFormats()[0] - .equals(DateFormat.getDateInstance(DateFormat.SHORT))); - assertEquals("Wrong short date pattern", "{0,date,short}", format - .toPattern()); - format.applyPattern("{0, date, medium}"); - assertTrue("Wrong medium date format", format.getFormats()[0] - .equals(DateFormat.getDateInstance(DateFormat.MEDIUM))); - assertEquals("Wrong medium date pattern", "{0,date}", format - .toPattern()); - format.applyPattern("{0, date, long}"); - assertTrue("Wrong long date format", format.getFormats()[0] - .equals(DateFormat.getDateInstance(DateFormat.LONG))); - assertEquals("Wrong long date pattern", "{0,date,long}", format - .toPattern()); - format.applyPattern("{0, date, full}"); - assertTrue("Wrong full date format", format.getFormats()[0] - .equals(DateFormat.getDateInstance(DateFormat.FULL))); - assertEquals("Wrong full date pattern", "{0,date,full}", format - .toPattern()); - - format.applyPattern("{0, date, MMM d {hh:mm:ss}}"); - assertEquals("Wrong time/date format", " MMM d {hh:mm:ss}", - ((SimpleDateFormat) (format.getFormats()[0])).toPattern()); - assertEquals("Wrong time/date pattern", "{0,date, MMM d {hh:mm:ss}}", - format.toPattern()); - - format.applyPattern("{0, number}"); - assertTrue("Wrong number format", format.getFormats()[0] - .equals(NumberFormat.getNumberInstance())); - assertEquals("Wrong number pattern", "{0,number}", format.toPattern()); - format.applyPattern("{0, number, currency}"); - assertTrue("Wrong currency number format", format.getFormats()[0] - .equals(NumberFormat.getCurrencyInstance())); - assertEquals("Wrong currency number pattern", "{0,number,currency}", - format.toPattern()); - format.applyPattern("{0, number, percent}"); - assertTrue("Wrong percent number format", format.getFormats()[0] - .equals(NumberFormat.getPercentInstance())); - assertEquals("Wrong percent number pattern", "{0,number,percent}", - format.toPattern()); - format.applyPattern("{0, number, integer}"); - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumFractionDigits(0); - nf.setParseIntegerOnly(true); - assertTrue("Wrong integer number format", format.getFormats()[0] - .equals(nf)); - assertEquals("Wrong integer number pattern", "{0,number,integer}", - format.toPattern()); - - format.applyPattern("{0, number, {'#'}##0.0E0}"); - - /* - * TODO validate these assertions String actual = - * ((DecimalFormat)(format.getFormats()[0])).toPattern(); - * assertEquals("Wrong pattern number format", "' {#}'##0.0E0", actual); - * assertEquals("Wrong pattern number pattern", "{0,number,' - * {#}'##0.0E0}", format.toPattern()); - * - */ - - format.applyPattern("{0, choice,0#no|1#one|2#{1,number}}"); - assertEquals("Wrong choice format", - - "0.0#no|1.0#one|2.0#{1,number}", - ((ChoiceFormat) format.getFormats()[0]).toPattern()); - assertEquals("Wrong choice pattern", - "{0,choice,0.0#no|1.0#one|2.0#{1,number}}", format.toPattern()); - assertEquals("Wrong formatted choice", "3.6", format - .format(new Object[] { new Integer(2), new Float(3.6) })); - - try { - format.applyPattern("WRONG MESSAGE FORMAT {0,number,{}"); - fail("Expected IllegalArgumentException for invalid pattern"); - } catch (IllegalArgumentException e) { - } - - // Regression for HARMONY-65 - MessageFormat mf = new MessageFormat("{0,number,integer}"); - String badpattern = "{0,number,#"; - try { - mf.applyPattern(badpattern); - fail("Assert 0: Failed to detect unmatched brackets."); - } catch (IllegalArgumentException e) { - // expected - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "applyPattern", - args = {java.lang.String.class} - ) - public void test_applyPatternLjava_lang_String_AndroidFailure() { - MessageFormat format = new MessageFormat("test"); - format.setLocale(Locale.FRENCH); // use French since English has the - // same LONG and FULL time patterns - format.applyPattern("{0,time, Full}"); - assertEquals("Wrong full time pattern", "{0,time,full}", format - .toPattern()); - } - - /** - * @tests java.text.MessageFormat#clone() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - // Test for method java.lang.Object java.text.MessageFormat.clone() - MessageFormat format = new MessageFormat("'{'choice'}'{0}"); - MessageFormat clone = (MessageFormat) format.clone(); - assertTrue("Clone not equal", format.equals(clone)); - assertEquals("Wrong answer", "{choice}{0}", format - .format(new Object[] {})); - clone.setFormat(0, DateFormat.getInstance()); - assertTrue("Clone shares format data", !format.equals(clone)); - format = (MessageFormat) clone.clone(); - Format[] formats = clone.getFormats(); - ((SimpleDateFormat) formats[0]).applyPattern("adk123"); - assertTrue("Clone shares format data", !format.equals(clone)); - } - - /** - * @tests java.text.MessageFormat#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.text.MessageFormat.equals(java.lang.Object) - MessageFormat format1 = new MessageFormat("{0}"); - MessageFormat format2 = new MessageFormat("{1}"); - assertTrue("Should not be equal", !format1.equals(format2)); - format2.applyPattern("{0}"); - assertTrue("Should be equal", format1.equals(format2)); - SimpleDateFormat date = (SimpleDateFormat) DateFormat.getTimeInstance(); - format1.setFormat(0, DateFormat.getTimeInstance()); - format2.setFormat(0, new SimpleDateFormat(date.toPattern())); - assertTrue("Should be equal2", format1.equals(format2)); - } - - /** - * @tests java.text.MessageFormat#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - // Test for method - // int java.text.MessageFormat.hashCode() - assertEquals("Should be equal", 3648, new MessageFormat("rr", null) - .hashCode()); - } - - /** - * @tests java.text.MessageFormat#formatToCharacterIterator(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "formatToCharacterIterator", - args = {java.lang.Object.class} - ) - // FIXME This test fails on Harmony ClassLibrary - public void test_formatToCharacterIteratorLjava_lang_Object() { - // Test for method formatToCharacterIterator(java.lang.Object) - new Support_MessageFormat( - "test_formatToCharacterIteratorLjava_lang_Object") - .t_formatToCharacterIterator(); - - try { - new MessageFormat("{1, number}").formatToCharacterIterator(null); - fail("NullPointerException was not thrown."); - } catch(NullPointerException npe) { - //expected - } - - try { - new MessageFormat("{0, time}").formatToCharacterIterator(new Object[]{""}); - fail("IllegalArgumentException was not thrown."); - } catch(IllegalArgumentException iae) { - //expected - } - } - - /** - * @tests java.text.MessageFormat#format(java.lang.Object[], - * java.lang.StringBuffer, java.text.FieldPosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {java.lang.Object[].class, java.lang.StringBuffer.class, java.text.FieldPosition.class} - ) - public void test_format$Ljava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { - // Test for method java.lang.StringBuffer - // java.text.MessageFormat.format(java.lang.Object [], - // java.lang.StringBuffer, java.text.FieldPosition) - MessageFormat format = new MessageFormat("{1,number,integer}"); - StringBuffer buffer = new StringBuffer(); - format.format(new Object[] { "0", new Double(53.863) }, buffer, - new FieldPosition(MessageFormat.Field.ARGUMENT)); - assertEquals("Wrong result", "54", buffer.toString()); - - format.format(new Object[] { "0", new Double(53.863) }, buffer, - new FieldPosition(MessageFormat.Field.ARGUMENT)); - - assertEquals("Wrong result", "5454", buffer.toString()); - - buffer = new StringBuffer(); - format - .applyPattern("{0,choice,0#zero|1#one '{1,choice,2#two {2,time}}'}"); - Date date = new Date(); - String expected = "one two " - + DateFormat.getTimeInstance().format(date); - format.format(new Object[] { new Double(1.6), - new Integer(3), date }, buffer, new FieldPosition(MessageFormat - .Field.ARGUMENT)); - assertEquals("Choice not recursive:\n" + expected + "\n" + buffer, - expected, buffer.toString()); - - StringBuffer str = format.format(new Object[] { new Double(0.6), - new Integer(3)}, buffer, null); - - assertEquals(expected + "zero", str.toString()); - assertEquals(expected + "zero", buffer.toString()); - - try { - format.format(new Object[] { "0", new Double(1), "" }, buffer, - new FieldPosition(MessageFormat.Field.ARGUMENT)); - fail("IllegalArgumentException was not thrown."); - } catch(IllegalArgumentException iae) { - //expected - } - - try { - format.format(new Object[] { "", new Integer(3)}, buffer, - new FieldPosition(MessageFormat.Field.ARGUMENT)); - fail("IllegalArgumentException was not thrown."); - } catch(IllegalArgumentException iae) { - //expected - } - } - - /** - * @tests java.text.MessageFormat#format(java.lang.Object, - * java.lang.StringBuffer, java.text.FieldPosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {java.lang.Object.class, java.lang.StringBuffer.class, java.text.FieldPosition.class} - ) - public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() { - // Test for method java.lang.StringBuffer - // java.text.MessageFormat.format(java.lang.Object, - // java.lang.StringBuffer, java.text.FieldPosition) - new Support_MessageFormat( - "test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition") - .t_format_with_FieldPosition(); - - String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} " + - "hamburger{2,choice,1#|1<s}."; - MessageFormat format = new MessageFormat(pattern, Locale.US); - - Object[] objects = new Object[] { "", new Integer(3), 8, ""}; - - try { - format.format(objects, new StringBuffer(), - new FieldPosition(DateFormat.Field.AM_PM)); - fail("IllegalArgumentException was not thrown."); - } catch(IllegalArgumentException iae) { - //expected - } - } - - /** - * @tests java.text.MessageFormat#format(java.lang.String, - * java.lang.Object...) Test of method - * java.text.MessageFormat#format(java.lang.String, - * java.lang.Object...). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "format", - args = {java.lang.String.class, java.lang.Object[].class} - ) - public void test_formatLjava_lang_StringLjava_lang_Object() { - int iCurrency = 123; - int iInteger = Integer.MIN_VALUE; - - Date date = new Date(12345678); - Object[] args = { date, iCurrency, iInteger }; - String resStr = "Date: Jan 1, 1970 Currency: $" + iCurrency - + ".00 Integer: -2,147,483,648"; - String pattern = "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}"; - String sFormat = MessageFormat.format(pattern, (Object[]) args); - assertEquals( - "format(String, Object[]) with valid parameters returns incorrect string: case 1", - sFormat, resStr); - - pattern = "abc {4, number, integer} def {3,date} ghi {2,number} jkl {1,choice,0#low|1#high} mnop {0}"; - resStr = "abc -2,147,483,648 def Jan 1, 1970 ghi -2,147,483,648 jkl high mnop -2,147,483,648"; - Object[] args_ = { iInteger, 1, iInteger, date, iInteger }; - sFormat = MessageFormat.format(pattern, args_); - assertEquals( - "format(String, Object[]) with valid parameters returns incorrect string: case 1", - sFormat, resStr); - - try { - args = null; - MessageFormat.format(null, args); - fail("Doesn't throw IllegalArgumentException: null, null"); - } catch (Exception e) { - // expected - } - - try { - MessageFormat.format("Invalid {1,foobar} format descriptor!", - new Object[] {iInteger} ); - fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 1"); - } catch (IllegalArgumentException ex) { - // expected - } - - try { - MessageFormat.format( - "Invalid {1,date,invalid-spec} format descriptor!", new Object[]{""}); - fail("Doesn't throw IllegalArgumentException with invalid pattern as a parameter: case 2"); - } catch (IllegalArgumentException ex) { - // expected - } - - try { - MessageFormat.format("{0,number,integer", new Object[] {iInteger}); - fail("Doesn't throw IllegalArgumentException, doesn't detect unmatched brackets"); - } catch (IllegalArgumentException ex) { - // expected - } - - try { - MessageFormat.format( - "Valid {1, date} format {0, number} descriptor!", new Object[]{ "" } ); - fail("Doesn't throw IllegalArgumentException with invalid Object array"); - } catch (IllegalArgumentException ex) { - // expected - } - } - - /** - * @tests java.text.MessageFormat#getFormats() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getFormats", - args = {} - ) - public void test_getFormats() { - // Test for method java.text.Format [] - // java.text.MessageFormat.getFormats() - - // test with repeating formats and max argument index < max offset - Format[] formats = format1.getFormats(); - Format[] correctFormats = new Format[] { - NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), - NumberFormat.getPercentInstance(), null, - new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance(), }; - - assertEquals("Test1:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test with max argument index > max offset - formats = format2.getFormats(); - correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), - NumberFormat.getPercentInstance(), null, - new ChoiceFormat("0#off|1#on"), DateFormat.getDateInstance() }; - - assertEquals("Test2:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test with argument number being zero - formats = format3.getFormats(); - assertEquals("Test3: Returned wrong number of formats:", 0, - formats.length); - } - - /** - * @tests java.text.MessageFormat#getFormatsByArgumentIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getFormatsByArgumentIndex", - args = {} - ) - public void test_getFormatsByArgumentIndex() { - // Test for method java.text.Format [] test_getFormatsByArgumentIndex() - - // test with repeating formats and max argument index < max offset - Format[] formats = format1.getFormatsByArgumentIndex(); - Format[] correctFormats = new Format[] { DateFormat.getDateInstance(), - new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), - NumberFormat.getCurrencyInstance(), null }; - - assertEquals("Test1:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - // test with max argument index > max offset - formats = format2.getFormatsByArgumentIndex(); - correctFormats = new Format[] { DateFormat.getDateInstance(), - new ChoiceFormat("0#off|1#on"), null, - NumberFormat.getCurrencyInstance(), null, null, null, null, - DateFormat.getTimeInstance() }; - - assertEquals("Test2:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - // test with argument number being zero - formats = format3.getFormatsByArgumentIndex(); - assertEquals("Test3: Returned wrong number of formats:", 0, - formats.length); - } - - /** - * @tests java.text.MessageFormat#getLocale() Test of method - * java.text.MessageFormat#getLocale(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLocale", - args = {} - ) - public void test_getLocale() { - try { - Locale[] l = { - Locale.FRANCE, - Locale.KOREA, - new Locale(Locale.FRANCE.getCountry(), Locale.FRANCE - .getLanguage()), new Locale("mk"), - new Locale("mk", "MK"), Locale.US, - new Locale("#ru", "@31230") }; - - String pattern = "getLocale test {0,number,#,####}"; - MessageFormat mf; - - for (int i = 0; i < 0; i++) { - mf = new MessageFormat(pattern, l[i]); - Locale result = mf.getLocale(); - assertEquals("Returned local: " + result + " instead of " - + l[i], l[i], result); - assertEquals("Returned language: " + result.getLanguage() - + " instead of " + l[i].getLanguage(), l[i] - .getLanguage(), result.getLanguage()); - assertEquals("Returned country: " + result.getCountry() - + " instead of " + l[i].getCountry(), - l[i].getCountry(), result.getCountry()); - } - - mf = new MessageFormat(pattern); - mf.setLocale(null); - Locale result = mf.getLocale(); - assertEquals("Returned local: " + result + " instead of null", - null, result); - } catch (Exception e) { - fail("unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.MessageFormat#setFormat(int, Format) Test of method - * java.text.MessageFormat#setFormat(int, Format). Case 1: Compare - * getFormats() results after calls to setFormat(). Case 2: Try to - * call setFormat() using incorrect index. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setFormat", - args = {int.class, java.text.Format.class} - ) - public void test_setFormatILjava_text_Format() { - try { - // case 1: Compare getFormats() results after calls to setFormat() - MessageFormat f1 = (MessageFormat) format1.clone(); - f1.setFormat(0, DateFormat.getTimeInstance()); - f1.setFormat(1, DateFormat.getTimeInstance()); - f1.setFormat(2, NumberFormat.getInstance()); - f1.setFormat(3, new ChoiceFormat("0#off|1#on")); - f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot")); - f1.setFormat(5, DateFormat.getTimeInstance()); - - Format[] formats = f1.getFormats(); - formats = f1.getFormats(); - - Format[] correctFormats = new Format[] { - DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), - NumberFormat.getInstance(), new ChoiceFormat("0#off|1#on"), - new ChoiceFormat("1#few|2#ok|3#a lot"), - DateFormat.getTimeInstance() }; - - assertEquals("Test1A:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals( - "Test1B:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // case 2: Try to setFormat using incorrect index - try { - f1.setFormat(-1, DateFormat.getDateInstance()); - fail("Expected ArrayIndexOutOfBoundsException was not thrown"); - f1.setFormat(f1.getFormats().length, DateFormat - .getDateInstance()); - fail("Expected ArrayIndexOutOfBoundsException was not thrown"); - } catch (ArrayIndexOutOfBoundsException e) { - // expected - } - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.MessageFormat#setFormatByArgumentIndex(int, - * java.text.Format) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setFormatByArgumentIndex", - args = {int.class, java.text.Format.class} - ) - public void test_setFormatByArgumentIndexILjava_text_Format() { - // test for method setFormatByArgumentIndex(int, Format) - MessageFormat f1 = (MessageFormat) format1.clone(); - f1.setFormatByArgumentIndex(0, DateFormat.getTimeInstance()); - f1.setFormatByArgumentIndex(4, new ChoiceFormat("1#few|2#ok|3#a lot")); - - // test with repeating formats and max argument index < max offset - // compare getFormatsByArgumentIndex() results after calls to - // setFormatByArgumentIndex() - Format[] formats = f1.getFormatsByArgumentIndex(); - - Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), - new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), - NumberFormat.getCurrencyInstance(), - new ChoiceFormat("1#few|2#ok|3#a lot") }; - - assertEquals("Test1A:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1B:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - // compare getFormats() results after calls to - // setFormatByArgumentIndex() - formats = f1.getFormats(); - - correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), - new ChoiceFormat("1#few|2#ok|3#a lot"), - new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), }; - - assertEquals("Test1C:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1D:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test setting argumentIndexes that are not used - MessageFormat f2 = (MessageFormat) format2.clone(); - f2.setFormatByArgumentIndex(2, NumberFormat.getPercentInstance()); - f2.setFormatByArgumentIndex(4, DateFormat.getTimeInstance()); - - formats = f2.getFormatsByArgumentIndex(); - correctFormats = format2.getFormatsByArgumentIndex(); - - assertEquals("Test2A:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2B:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - formats = f2.getFormats(); - correctFormats = format2.getFormats(); - - assertEquals("Test2C:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2D:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test exceeding the argumentIndex number - MessageFormat f3 = (MessageFormat) format3.clone(); - f3.setFormatByArgumentIndex(1, NumberFormat.getCurrencyInstance()); - - formats = f3.getFormatsByArgumentIndex(); - assertEquals("Test3A:Returned wrong number of formats:", 0, - formats.length); - - formats = f3.getFormats(); - assertEquals("Test3B:Returned wrong number of formats:", 0, - formats.length); - } - - /** - * @tests java.text.MessageFormat#setFormats(Format[]) Test of method - * java.text.MessageFormat#setFormats(Format[]). Case 1: Test with - * repeating formats and max argument index < max offset compare - * getFormats() results after calls to setFormats(Format[]) Case 2: - * Try to pass null argument to setFormats(). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setFormats", - args = {java.text.Format[].class} - ) - public void test_setFormats$Ljava_text_Format() { - try { - MessageFormat f1 = (MessageFormat) format1.clone(); - - // case 1: Test with repeating formats and max argument index < max - // offset - // compare getFormats() results after calls to setFormats(Format[]) - Format[] correctFormats = new Format[] { - DateFormat.getTimeInstance(), - new ChoiceFormat("0#off|1#on"), - DateFormat.getTimeInstance(), - NumberFormat.getCurrencyInstance(), - new ChoiceFormat("1#few|2#ok|3#a lot") }; - - f1.setFormats(correctFormats); - Format[] formats = f1.getFormats(); - - assertTrue("Test1A:Returned wrong number of formats:", - correctFormats.length <= formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1B:wrong format for argument index " + i - + ":", correctFormats[i], formats[i]); - } - - // case 2: Try to pass null argument to setFormats(). - try { - f1.setFormats(null); - fail("Expected exception NullPointerException was not thrown"); - } catch (NullPointerException e) { - // expected - } - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - - /** - * @tests java.text.MessageFormat#setFormatsByArgumentIndex(java.text.Format[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setFormatsByArgumentIndex", - args = {java.text.Format[].class} - ) - public void test_setFormatsByArgumentIndex$Ljava_text_Format() { - // test for method setFormatByArgumentIndex(Format[]) - MessageFormat f1 = (MessageFormat) format1.clone(); - - // test with repeating formats and max argument index < max offset - // compare getFormatsByArgumentIndex() results after calls to - // setFormatsByArgumentIndex(Format[]) - Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), - new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), - NumberFormat.getCurrencyInstance(), - new ChoiceFormat("1#few|2#ok|3#a lot") }; - - f1.setFormatsByArgumentIndex(correctFormats); - Format[] formats = f1.getFormatsByArgumentIndex(); - - assertEquals("Test1A:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1B:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - // compare getFormats() results after calls to - // setFormatByArgumentIndex() - formats = f1.getFormats(); - correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), - new ChoiceFormat("1#few|2#ok|3#a lot"), - new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), }; - - assertEquals("Test1C:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test1D:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test setting argumentIndexes that are not used - MessageFormat f2 = (MessageFormat) format2.clone(); - Format[] inputFormats = new Format[] { DateFormat.getDateInstance(), - new ChoiceFormat("0#off|1#on"), - NumberFormat.getPercentInstance(), - NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), null, null, null, - DateFormat.getTimeInstance() }; - f2.setFormatsByArgumentIndex(inputFormats); - - formats = f2.getFormatsByArgumentIndex(); - correctFormats = format2.getFormatsByArgumentIndex(); - - assertEquals("Test2A:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2B:wrong format for argument index " + i + ":", - correctFormats[i], formats[i]); - } - - formats = f2.getFormats(); - correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), - DateFormat.getTimeInstance(), DateFormat.getDateInstance(), - null, new ChoiceFormat("0#off|1#on"), - DateFormat.getDateInstance() }; - - assertEquals("Test2C:Returned wrong number of formats:", - correctFormats.length, formats.length); - for (int i = 0; i < correctFormats.length; i++) { - assertEquals("Test2D:wrong format for pattern index " + i + ":", - correctFormats[i], formats[i]); - } - - // test exceeding the argumentIndex number - MessageFormat f3 = (MessageFormat) format3.clone(); - f3.setFormatsByArgumentIndex(inputFormats); - - formats = f3.getFormatsByArgumentIndex(); - assertEquals("Test3A:Returned wrong number of formats:", 0, - formats.length); - - formats = f3.getFormats(); - assertEquals("Test3B:Returned wrong number of formats:", 0, - formats.length); - - } - - /** - * @tests java.text.MessageFormat#parse(java.lang.String, - * java.text.ParsePosition) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class, java.text.ParsePosition.class} - ) - public void test_parseLjava_lang_StringLjava_text_ParsePosition() { - // Test for method java.lang.Object [] - // java.text.MessageFormat.parse(java.lang.String, - // java.text.ParsePosition) - MessageFormat format = new MessageFormat("date is {0,date,MMM d, yyyy}"); - ParsePosition pos = new ParsePosition(2); - Object[] result = (Object[]) format - .parse("xxdate is Feb 28, 1999", pos); - assertTrue("No result: " + result.length, result.length >= 1); - assertTrue("Wrong answer", ((Date) result[0]) - .equals(new GregorianCalendar(1999, Calendar.FEBRUARY, 28) - .getTime())); - - MessageFormat mf = new MessageFormat("vm={0},{1},{2}"); - result = mf.parse("vm=win,foo,bar", new ParsePosition(0)); - assertTrue("Invalid parse", result[0].equals("win") - && result[1].equals("foo") && result[2].equals("bar")); - - mf = new MessageFormat("{0}; {0}; {0}"); - String parse = "a; b; c"; - result = mf.parse(parse, new ParsePosition(0)); - assertEquals("Wrong variable result", "c", result[0]); - - try { - mf.parse(parse, null); - fail("NullPointerException was not thrown."); - } catch(NullPointerException npe) { - //expected - } - - try { - mf.parse(null, pos); - } catch(NullPointerException npe) { - fail("NullPointerException was thrown."); - } - } - - /** - * @tests java.text.MessageFormat#setLocale(java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setLocale", - args = {java.util.Locale.class} - ) - public void test_setLocaleLjava_util_Locale() { - // Test for method void - // java.text.MessageFormat.setLocale(java.util.Locale) - MessageFormat format = new MessageFormat("date {0,date}"); - format.setLocale(Locale.CHINA); - assertEquals("Wrong locale1", Locale.CHINA, format.getLocale()); - format.applyPattern("{1,date}"); - assertEquals("Wrong locale3", DateFormat.getDateInstance( - DateFormat.DEFAULT, Locale.CHINA), format.getFormats()[0]); - } - - /** - * @tests java.text.MessageFormat#toPattern() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toPattern", - args = {} - ) - public void test_toPattern() { - // Test for method java.lang.String java.text.MessageFormat.toPattern() - String pattern = "[{0}]"; - MessageFormat mf = new MessageFormat(pattern); - assertTrue("Wrong pattern", mf.toPattern().equals(pattern)); - - // Regression for HARMONY-59 - new MessageFormat("CHOICE {1,choice}").toPattern(); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - defaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - - // test with repeating formats and max argument index < max offset - String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}"; - format1 = new MessageFormat(pattern); - - // test with max argument index > max offset - pattern = "A {3, number, currency} B {8, time} C {0, number, percent} D {6} E {1,choice,0#off|1#on} F {0, date}"; - format2 = new MessageFormat(pattern); - - // test with argument number being zero - pattern = "A B C D E F"; - format3 = new MessageFormat(pattern); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - Locale.setDefault(defaultLocale); - } - - /** - * @tests java.text.MessageFormat(java.util.Locale) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Verifies IllegalArgumentException.", - method = "MessageFormat", - args = {java.lang.String.class, java.util.Locale.class} - ) - public void test_ConstructorLjava_util_Locale() { - // Regression for HARMONY-65 - try { - new MessageFormat("{0,number,integer", Locale.US); - fail("Assert 0: Failed to detect unmatched brackets."); - } catch (IllegalArgumentException e) { - // expected - } - } - - /** - * @tests java.text.MessageFormat#parse(java.lang.String) Test of method - * java.text.MessageFormat#parse(java.lang.String). - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class} - ) - public void test_parseLjava_lang_String() throws ParseException { - String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}"; - MessageFormat mf = new MessageFormat(pattern); - String sToParse = "A $12,345.00 B 9:56:07 AM C 3,200% D 1/15/70 9:56 AM E on F Jan 1, 1970"; - Object[] result; - try { - result = mf.parse(sToParse); - - assertTrue("No result: " + result.length, result.length == 5); - assertTrue("Object 0 is not date", result[0] instanceof Date); - assertEquals("Object 1 is not stringr", result[1].toString(), "1.0"); - assertTrue("Object 2 is not date", result[2] instanceof Date); - assertEquals("Object 3 is not number", result[3].toString(), - "12345"); - assertEquals("Object 4 is not string", result[4].toString(), - "1/15/70 9:56 AM"); - - } catch (java.text.ParseException pe) { - fail("ParseException is thrown for incorrect string " + sToParse); - } - - sToParse = "xxdate is Feb 28, 1999"; - try { - result = format1.parse(sToParse); - fail("ParseException is thrown for incorrect string " + sToParse); - } catch (java.text.ParseException pe) { - // expected - } - - sToParse = "vm=Test, @3 4 6, 3 "; - mf = new MessageFormat("vm={0},{1},{2}"); - try { - result = mf.parse(sToParse); - assertTrue("No result: " + result.length, result.length == 3); - assertEquals("Object 0 is not string", result[0].toString(), "Test"); - assertEquals("Object 1 is not string", result[1].toString(), - " @3 4 6"); - assertEquals("Object 2 is not string", result[2].toString(), - " 3 "); - } catch (java.text.ParseException pe) { - fail("ParseException is thrown for correct string " + sToParse); - } - - try { - result = mf.parse(null); - fail("ParseException is not thrown for null " + sToParse); - } catch (java.text.ParseException pe) { - // expected - } - } - - /** - * @tests java.text.MessageFormat#parseObject(java.lang.String, - * java.text.ParsePosition) Test of method - * java.text.MessageFormat#parseObject(java.lang.String, - * java.text.ParsePosition). Case 1: Parsing of correct data string. - * Case 2: Parsing of partial correct data string. Case 3: Try to use - * argument ParsePosition as null. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "parseObject", - args = {java.lang.String.class, java.text.ParsePosition.class} - ) - public void test_parseObjectLjava_lang_StringLjavajava_text_ParsePosition() { - MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}"); - try { - // case 1: Try to parse correct data string. - Object[] objs = { new Double(3.1415) }; - String result = mf.format(objs); - // result now equals "3.14, 3.1" - Object[] res = null; - ParsePosition pp = new ParsePosition(0); - int parseIndex = pp.getIndex(); - res = (Object[]) mf.parseObject(result, pp); - assertTrue("Parse operation return null", res != null); - assertTrue("parse operation return array with incorrect length", - 1 == res.length); - assertTrue("ParseIndex is incorrect", pp.getIndex() != parseIndex); - assertTrue("Result object is incorrect", new Double(3.1) - .equals(res[0])); - - // case 2: Try to parse partially correct data string. - pp.setIndex(0); - char[] cur = result.toCharArray(); - cur[cur.length / 2] = 'Z'; - String partialCorrect = new String(cur); - res = (Object[]) mf.parseObject(partialCorrect, pp); - assertTrue("Parse operation return null", res == null); - assertTrue("ParseIndex is incorrect", pp.getIndex() == 0); - assertTrue("ParseErrorIndex is incorrect", - pp.getErrorIndex() == cur.length / 2); - - // case 3: Try to use argument ParsePosition as null. - try { - mf.parseObject(result, null); - fail("Expected NullPointerException was not thrown"); - } catch (NullPointerException e) { - // expected - } - } catch (Exception e) { - fail("Unexpected exception " + e.toString()); - } - } - @TestTargetNew( - level = TestLevel.PARTIAL, - notes = "Regression test. Doesn't verifies exception.", - method = "format", - args = {java.lang.Object.class} - ) - public void test_format_Object() { - // Regression for HARMONY-1875 - Locale.setDefault(Locale.CANADA); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - String pat = "text here {0,date,yyyyyyyyy} and here"; - Calendar c = Calendar.getInstance(); - String etalon = "text here 00000" + c.get(Calendar.YEAR) + " and here"; - MessageFormat obj = new MessageFormat(pat); - assertEquals(etalon, obj.format(new Object[] { new Date() })); - } - - /** - * @tests java.text.MessageFormat#parse(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "parse", - args = {java.lang.String.class} - ) - public void test_parse() throws ParseException { - // Regression for HARMONY-63 - MessageFormat mf = new MessageFormat("{0,number,#,####}", Locale.US); - Object[] res = mf.parse("1,00,00"); - assertEquals("Assert 0: incorrect size of parsed data ", 1, res.length); - assertEquals("Assert 1: parsed value incorrectly", new Long(10000), (Long)res[0]); - } - - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "format", - args = {java.lang.String.class, java.lang.Object[].class} - ) - public void testHARMONY5323() { - Object []messageArgs = new Object[11]; - for (int i = 0; i < messageArgs.length; i++) - messageArgs[i] = "dumb"+i; - - String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs); - assertEquals(res, "bgcolor=\"dumb10\""); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java deleted file mode 100644 index 6cb38a2..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/NormalizerTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.Normalizer; -import java.text.Normalizer.Form; - -import junit.framework.TestCase; - -public class NormalizerTest extends TestCase { - /** - * @tests java.text.Normalizer.Form#values() - */ - public void test_form_values() throws Exception { - Form[] forms = Form.values(); - assertEquals(4, forms.length); - assertEquals(Form.NFD, forms[0]); - assertEquals(Form.NFC, forms[1]); - assertEquals(Form.NFKD, forms[2]); - assertEquals(Form.NFKC, forms[3]); - } - - /** - * @tests java.text.Normalizer.Form#valueOf(String) - */ - public void test_form_valueOfLjava_lang_String() { - try { - Form.valueOf(null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - assertEquals(Form.NFC, Form.valueOf("NFC")); - assertEquals(Form.NFD, Form.valueOf("NFD")); - assertEquals(Form.NFKC, Form.valueOf("NFKC")); - assertEquals(Form.NFKD, Form.valueOf("NFKD")); - - try { - Form.valueOf("not exist"); - fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - Form.valueOf("nfc"); - fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - Form.valueOf("NFC "); - fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } - } - - /** - * @tests java.text.Normalizer#isNormalized(CharSequence, Form) - */ - public void test_isNormalized() throws Exception { - String src = "\u00c1"; - assertTrue(Normalizer.isNormalized(src, Form.NFC)); - assertFalse(Normalizer.isNormalized(src, Form.NFD)); - assertTrue(Normalizer.isNormalized(src, Form.NFKC)); - assertFalse(Normalizer.isNormalized(src, Form.NFKD)); - - src = "\u0041\u0301"; - assertFalse(Normalizer.isNormalized(src, Form.NFC)); - assertTrue(Normalizer.isNormalized(src, Form.NFD)); - assertFalse(Normalizer.isNormalized(src, Form.NFKC)); - assertTrue(Normalizer.isNormalized(src, Form.NFKD)); - - src = "\ufb03"; - assertTrue(Normalizer.isNormalized(src, Form.NFC)); - assertTrue(Normalizer.isNormalized(src, Form.NFD)); - assertFalse(Normalizer.isNormalized(src, Form.NFKC)); - assertFalse(Normalizer.isNormalized(src, Form.NFKD)); - - src = "\u0066\u0066\u0069"; - assertTrue(Normalizer.isNormalized(src, Form.NFC)); - assertTrue(Normalizer.isNormalized(src, Form.NFD)); - assertTrue(Normalizer.isNormalized(src, Form.NFKC)); - assertTrue(Normalizer.isNormalized(src, Form.NFKD)); - - src = ""; - assertTrue(Normalizer.isNormalized(src, Form.NFC)); - assertTrue(Normalizer.isNormalized(src, Form.NFD)); - assertTrue(Normalizer.isNormalized(src, Form.NFKC)); - assertTrue(Normalizer.isNormalized(src, Form.NFKD)); - } - - /** - * @tests java.text.Normalizer#isNormalized(CharSequence, Form) - */ - public void test_isNormalized_exception() throws Exception { - try { - Normalizer.isNormalized(null, Form.NFC); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - try { - Normalizer.isNormalized("chars", null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - } - - /** - * @tests java.text.Normalizer#normalize(CharSequence, Form) - */ - public void test_normalize() throws Exception { - String src = "\u00c1"; - assertEquals("\u00c1", Normalizer.normalize(src, Form.NFC)); - assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFD)); - assertEquals("\u00c1", Normalizer.normalize(src, Form.NFKC)); - assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFKD)); - - src = "\u0041\u0301"; - assertEquals("\u00c1", Normalizer.normalize(src, Form.NFC)); - assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFD)); - assertEquals("\u00c1", Normalizer.normalize(src, Form.NFKC)); - assertEquals("\u0041\u0301", Normalizer.normalize(src, Form.NFKD)); - - src = "\ufb03"; - assertEquals("\ufb03", Normalizer.normalize(src, Form.NFC)); - assertEquals("\ufb03", Normalizer.normalize(src, Form.NFD)); - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKC)); - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKD)); - - src = "\u0066\u0066\u0069"; - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFC)); - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFD)); - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKC)); - assertEquals("\u0066\u0066\u0069", Normalizer.normalize(src, Form.NFKD)); - - src = ""; - assertEquals("", Normalizer.normalize(src, Form.NFC)); - assertEquals("", Normalizer.normalize(src, Form.NFD)); - assertEquals("", Normalizer.normalize(src, Form.NFKC)); - assertEquals("", Normalizer.normalize(src, Form.NFKD)); - } - - /** - * @tests java.text.Normalizer#normalize(CharSequence, Form) - */ - public void test_normalize_exception() throws Exception { - try { - Normalizer.normalize(null, Form.NFC); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - - try { - Normalizer.normalize("chars", null); - fail("Should throw NullPointerException"); - } catch (NullPointerException e) { - // expected - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java deleted file mode 100644 index 7b00110..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.text.DateFormat; -import java.text.ParseException; - -@TestTargetClass(ParseException.class) -public class ParseExceptionTest extends junit.framework.TestCase { - - /** - * @tests java.text.ParseException#ParseException(java.lang.String, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "ParseException", - args = {java.lang.String.class, int.class} - ) - public void test_ConstructorLjava_lang_StringI() { - try { - DateFormat df = DateFormat.getInstance(); - df.parse("HelloWorld"); - fail("ParseException not created/thrown."); - } catch (ParseException e) { - // expected - } - } - - /** - * @tests java.text.ParseException#getErrorOffset() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getErrorOffset", - args = {} - ) - public void test_getErrorOffset() { - try { - DateFormat df = DateFormat.getInstance(); - df.parse("1999HelloWorld"); - } catch (ParseException e) { - assertEquals("getErrorOffsetFailed.", 4, e.getErrorOffset()); - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java deleted file mode 100644 index e581a47..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.text.ParsePosition; - -@TestTargetClass(ParsePosition.class) -public class ParsePositionTest extends junit.framework.TestCase { - - ParsePosition pp; - - /** - * @tests java.text.ParsePosition#ParsePosition(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "ParsePosition", - args = {int.class} - ) - public void test_ConstructorI() { - // Test for method java.text.ParsePosition(int) - ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE); - assertTrue("Initialization failed.", - pp1.getIndex() == Integer.MIN_VALUE); - assertEquals("Initialization failed.", -1, pp1.getErrorIndex()); - } - - /** - * @tests java.text.ParsePosition#equals(java.lang.Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - // Test for method boolean - // java.text.ParsePosition.equals(java.lang.Object) - ParsePosition pp2 = new ParsePosition(43); - pp2.setErrorIndex(56); - assertTrue("equals failed.", !pp.equals(pp2)); - pp.setErrorIndex(56); - pp.setIndex(43); - assertTrue("equals failed.", pp.equals(pp2)); - } - - /** - * @tests java.text.ParsePosition#getErrorIndex() - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getErrorIndex", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setErrorIndex", - args = {int.class} - ) - }) - public void test_getErrorIndex() { - // Test for method int java.text.ParsePosition.getErrorIndex() - pp.setErrorIndex(56); - assertEquals("getErrorIndex failed.", 56, pp.getErrorIndex()); - pp.setErrorIndex(Integer.MAX_VALUE); - assertEquals("getErrorIndex failed.", Integer.MAX_VALUE, - pp.getErrorIndex()); - assertEquals("getErrorIndex failed.", Integer.MAX_VALUE, - pp.getErrorIndex()); - } - - /** - * @tests java.text.ParsePosition#getIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIndex", - args = {} - ) - public void test_getIndex() { - // Test for method int java.text.ParsePosition.getIndex() - assertTrue("getIndex failed.", pp.getIndex() == Integer.MAX_VALUE); - } - - /** - * @tests java.text.ParsePosition#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - // Test for method int java.text.ParsePosition.hashCode() - ParsePosition pp1 = new ParsePosition(0); - ParsePosition pp2 = new ParsePosition(0); - assertTrue("hashCode returns non equal hash codes for equal objects.", - pp1.hashCode() == pp2.hashCode()); - pp1.setIndex(Integer.MAX_VALUE); - assertTrue("hashCode returns equal hash codes for non equal objects.", - pp1.hashCode() != pp2.hashCode()); - } - - /** - * @tests java.text.ParsePosition#setErrorIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setErrorIndex", - args = {int.class} - ) - public void test_setErrorIndexI() { - // Test for method void java.text.ParsePosition.setErrorIndex(int) - pp.setErrorIndex(4564); - assertEquals("setErrorIndex failed.", 4564, pp.getErrorIndex()); - } - - /** - * @tests java.text.ParsePosition#setIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setIndex", - args = {int.class} - ) - public void test_setIndexI() { - // Test for method void java.text.ParsePosition.setIndex(int) - pp.setIndex(4564); - assertEquals("setErrorIndex failed.", 4564, pp.getIndex()); - } - - /** - * @tests java.text.ParsePosition#toString() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {} - ) - public void test_toString() { - // Test for method java.lang.String java.text.ParsePosition.toString() - // String format is not specified. - assertNotNull("toString returns null.", pp.toString()); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - - pp = new ParsePosition(Integer.MAX_VALUE); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java deleted file mode 100644 index 3931a2f..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.CharacterIterator; -import java.text.CollationElementIterator; -import java.text.CollationKey; -import java.text.Collator; -import java.text.ParseException; -import java.text.RuleBasedCollator; -import java.text.StringCharacterIterator; -import java.util.Locale; - -import junit.framework.TestCase; - -public class RuleBasedCollatorTest extends TestCase { - - 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"; - RuleBasedCollator coll = new RuleBasedCollator(rule); - assertEquals(rule.hashCode(), coll.hashCode()); - } - - { - String rule = "< a < b < c < d < e"; - RuleBasedCollator coll = new RuleBasedCollator(rule); - assertEquals(rule.hashCode(), coll.hashCode()); - } - - } - - public void testClone() throws ParseException { - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(Locale.US); - RuleBasedCollator clone = (RuleBasedCollator) coll.clone(); - assertNotSame(coll, clone); - assertEquals(coll.getRules(), clone.getRules()); - assertEquals(coll.getDecomposition(), clone.getDecomposition()); - assertEquals(coll.getStrength(), clone.getStrength()); - } - - /* - * Class under test for boolean equals(java.lang.Object) - */ - public void testEqualsObject() throws ParseException { - String rule = "< a < b < c < d < e"; - RuleBasedCollator coll = new RuleBasedCollator(rule); - - assertEquals(Collator.TERTIARY, coll.getStrength()); - assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition()); - RuleBasedCollator other = new RuleBasedCollator(rule); - assertTrue(coll.equals(other)); - - coll.setStrength(Collator.PRIMARY); - assertFalse(coll.equals(other)); - - coll.setStrength(Collator.TERTIARY); - coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION); - assertFalse(coll.equals(other)); - } - - /* - * Class under test for int compare(java.lang.String, java.lang.String) - */ - public void testCompareStringString() throws ParseException { - String rule = "< c < b < a"; - RuleBasedCollator coll = new RuleBasedCollator(rule); - assertEquals(-1, coll.compare("c", "a")); - } - - public void testGetCollationKey() { - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(Locale.GERMAN); - String source = "abc"; - CollationKey key1 = coll.getCollationKey(source); - assertEquals(source, key1.getSourceString()); - String source2 = "abb"; - CollationKey key2 = coll.getCollationKey(source2); - assertEquals(source2, key2.getSourceString()); - assertTrue(key1.compareTo(key2) > 0); - assertTrue(coll.compare(source, source2) > 0); - - } - - public void testGetRules() throws ParseException { - String rule = "< a = b < c"; - RuleBasedCollator coll = new RuleBasedCollator(rule); - assertEquals(rule, coll.getRules()); - } - - /* - * Class under test for java.text.CollationElementIterator - * getCollationElementIterator(java.lang.String) - */ - public void testGetCollationElementIteratorString() throws Exception { - { - Locale locale = new Locale("es", "", "TRADITIONAL"); - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(locale); - String source = "cha"; - CollationElementIterator iterator = coll - .getCollationElementIterator(source); - int[] e_offset = { 0, 1, 2 ,3}; - int offset = iterator.getOffset(); - int i = 0; - assertEquals(e_offset[i++], offset); - while (offset != source.length()) { - iterator.next(); - offset = iterator.getOffset(); - assertEquals(e_offset[i++], offset); - } - } - - { - Locale locale = new Locale("de", "DE"); - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(locale); - String source = "\u00E6b"; - CollationElementIterator iterator = coll - .getCollationElementIterator(source); - int[] e_offset = { 0, 1, 1, 2 }; - int offset = iterator.getOffset(); - int i = 0; - assertEquals(e_offset[i++], offset); - while (offset != source.length()) { - iterator.next(); - offset = iterator.getOffset(); - assertEquals(e_offset[i++], offset); - } - } - //Regression for HARMONY-1352 - try { - new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((String)null); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - //expected - } - } - - /* - * Class under test for java.text.CollationElementIterator - * getCollationElementIterator(java.text.CharacterIterator) - */ - public void testGetCollationElementIteratorCharacterIterator() throws Exception { - { - 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, 1, 2, 3 }; - int offset = iterator.getOffset(); - int i = 0; - assertEquals(e_offset[i++], offset); - while (offset != text.length()) { - iterator.next(); - offset = iterator.getOffset(); - // System.out.println(offset); - assertEquals(e_offset[i++], offset); - } - } - - { - Locale locale = new Locale("de", "DE"); - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(locale); - String text = "\u00E6b"; - StringCharacterIterator source = new StringCharacterIterator(text); - CollationElementIterator iterator = coll - .getCollationElementIterator(source); - int[] e_offset = { 0, 1, 1, 2 }; - int offset = iterator.getOffset(); - int i = 0; - assertEquals(e_offset[i++], offset); - while (offset != text.length()) { - iterator.next(); - offset = iterator.getOffset(); - assertEquals(e_offset[i++], offset); - } - } - //Regression for HARMONY-1352 - try { - new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator)null); - fail("NullPointerException expected"); - } catch (NullPointerException e) { - //expected - } - } - - public void testStrength() { - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(Locale.US); - for (int i = 0; i < 4; i++) { - coll.setStrength(i); - assertEquals(i, coll.getStrength()); - } - - } - - public void testDecomposition() { - RuleBasedCollator coll = (RuleBasedCollator) Collator - .getInstance(Locale.US); - for (int i = 0; i < 2; i++) { - coll.setDecomposition(i); - assertEquals(i, coll.getDecomposition()); - } - } - - public void testCollator_GetInstance() { - Collator coll = Collator.getInstance(); - Object obj1 = "a"; - Object obj2 = "b"; - assertEquals(-1, coll.compare(obj1, obj2)); - - Collator.getInstance(); - assertFalse(coll.equals("A", "\uFF21")); - } - - public void testGetAvailableLocales() { - // Locale[] locales = Collator.getAvailableLocales(); - // for (int i = 0; i < locales.length; i++) { - // Locale locale = locales[i]; - // } - } - - // Test CollationKey - public void testCollationKey() { - Collator coll = Collator.getInstance(Locale.US); - String text = "abc"; - CollationKey key = coll.getCollationKey(text); - key.hashCode(); - - CollationKey key2 = coll.getCollationKey("abc"); - - assertEquals(0, key.compareTo(key2)); - } - - /** - * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String) - */ - public void testNullPointerException() throws Exception { - //Regression for HARMONY-241 - try { - new RuleBasedCollator(null); - fail("Constructor RuleBasedCollator(null) " - + "should throw NullPointerException"); - } catch (NullPointerException e) {} - } - - /** - * @tests java.text.RuleBasedCollator.compare(java.lang.String, java.lang.String) - */ - public void testCompareNull() throws Exception { - //Regression for HARMONY-836 - try { - new RuleBasedCollator("< a").compare(null, null); - fail("RuleBasedCollator.compare(null, null) " - + "should throw NullPointerException"); - } catch (NullPointerException e) {} - } - - /** - * @tests java.text.RuleBasedCollator.RuleBasedCollator(java.lang.String) - */ - public void testEmptyStringException() { - //Regression for HARMONY-241 - try { - new RuleBasedCollator(""); - fail("Constructor RuleBasedCollator(\"\") " - + "should throw ParseException"); - } catch (ParseException e) { - assertEquals("java.text.ParseException", e.getClass().getName()); - assertEquals(0, e.getErrorOffset()); - } - } - -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/StringCharacterIteratorTest.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/StringCharacterIteratorTest.java deleted file mode 100644 index bce1706..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/StringCharacterIteratorTest.java +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; - -@TestTargetClass(StringCharacterIterator.class) -public class StringCharacterIteratorTest extends TestCase { - - /** - * @tests java.text.StringCharacterIterator.StringCharacterIterator(String, - * int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "StringCharacterIterator", - args = {java.lang.String.class, int.class} - ) - public void test_ConstructorI() { - assertNotNull(new StringCharacterIterator("value", 0)); - assertNotNull(new StringCharacterIterator("value", "value".length())); - assertNotNull(new StringCharacterIterator("", 0)); - try { - new StringCharacterIterator(null, 0); - fail("Assert 0: no null pointer"); - } catch (NullPointerException e) { - // expected - } - - try { - new StringCharacterIterator("value", -1); - fail("Assert 1: no illegal argument"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - new StringCharacterIterator("value", "value".length() + 1); - fail("Assert 2: no illegal argument"); - } catch (IllegalArgumentException e) { - // expected - } - } - - /** - * @tests java.text.StringCharacterIterator(String, int, int, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "StringCharacterIterator", - args = {java.lang.String.class, int.class, int.class, int.class} - ) - public void test_ConstructorIII() { - assertNotNull(new StringCharacterIterator("value", 0, "value".length(), - 0)); - assertNotNull(new StringCharacterIterator("value", 0, "value".length(), - 1)); - assertNotNull(new StringCharacterIterator("", 0, 0, 0)); - - try { - new StringCharacterIterator(null, 0, 0, 0); - fail("no null pointer"); - } catch (NullPointerException e) { - // Expected - } - - try { - new StringCharacterIterator("value", -1, "value".length(), 0); - fail("no illegal argument: invalid begin"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new StringCharacterIterator("value", 0, "value".length() + 1, 0); - fail("no illegal argument: invalid end"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new StringCharacterIterator("value", 2, 1, 0); - fail("no illegal argument: start greater than end"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new StringCharacterIterator("value", 2, 1, 2); - fail("no illegal argument: start greater than end"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new StringCharacterIterator("value", 2, 4, 1); - fail("no illegal argument: location greater than start"); - } catch (IllegalArgumentException e) { - // Expected - } - - try { - new StringCharacterIterator("value", 0, 2, 3); - fail("no illegal argument: location greater than start"); - } catch (IllegalArgumentException e) { - // Expected - } - } - - /** - * @tests java.text.StringCharacterIterator.equals(Object) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "equals", - args = {java.lang.Object.class} - ) - public void test_equalsLjava_lang_Object() { - StringCharacterIterator sci0 = new StringCharacterIterator("fixture"); - assertEquals(sci0, sci0); - assertFalse(sci0.equals(null)); - assertFalse(sci0.equals("fixture")); - - StringCharacterIterator sci1 = new StringCharacterIterator("fixture"); - assertEquals(sci0, sci1); - - sci1.next(); - assertFalse(sci0.equals(sci1)); - sci0.next(); - assertEquals(sci0, sci1); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - StringCharacterIterator it2 = new StringCharacterIterator("xxstinx", 2, - 6, 4); - assertTrue("Range is equal", !it1.equals(it2)); - StringCharacterIterator it3 = new StringCharacterIterator("testing", 2, - 6, 2); - it3.setIndex(4); - assertTrue("Not equal", it1.equals(it3)); - } - - /** - * @tests java.text.StringCharacterIterator.clone() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - StringCharacterIterator sci0 = new StringCharacterIterator("fixture"); - assertSame(sci0, sci0); - StringCharacterIterator sci1 = (StringCharacterIterator) sci0.clone(); - assertNotSame(sci0, sci1); - assertEquals(sci0, sci1); - - StringCharacterIterator it = new StringCharacterIterator("testing", 2, - 6, 4); - StringCharacterIterator clone = (StringCharacterIterator) it.clone(); - assertTrue("Clone not equal", it.equals(clone)); - } - - /** - * @tests java.text.StringCharacterIterator.current() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "current", - args = {} - ) - public void test_current() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals('f', fixture.current()); - fixture.next(); - assertEquals('i', fixture.current()); - - StringCharacterIterator it = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong current char", 'i', it.current()); - it.next(); - it.next(); - assertEquals("Doesn't return DONE", StringCharacterIterator.DONE, - it.current()); - it.next(); - assertEquals("Doesn't return DONE after next()", - StringCharacterIterator.DONE, - it.current()); - } - - /** - * @tests java.text.StringCharacterIterator.first() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "first", - args = {} - ) - public void test_first() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals('f', fixture.first()); - fixture.next(); - assertEquals('f', fixture.first()); - fixture = new StringCharacterIterator("fixture", 1); - assertEquals('f', fixture.first()); - fixture = new StringCharacterIterator("fixture", 1, "fixture".length(), - 2); - assertEquals('i', fixture.first()); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong first char", 's', it1.first()); - assertEquals("Wrong next char", 't', it1.next()); - it1 = new StringCharacterIterator("testing", 2, 2, 2); - assertTrue("Not DONE", it1.first() == CharacterIterator.DONE); - } - - /** - * @tests java.text.StringCharacterIterator.getBeginIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getBeginIndex", - args = {} - ) - public void test_getBeginIndex() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals(0, fixture.getBeginIndex()); - fixture = new StringCharacterIterator("fixture", 1); - assertEquals(0, fixture.getBeginIndex()); - fixture = new StringCharacterIterator("fixture", 1, "fixture".length(), - 2); - assertEquals(1, fixture.getBeginIndex()); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong begin index 2", 2, it1.getBeginIndex()); - } - - /** - * @tests java.text.StringCharacterIterator.getEndIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getEndIndex", - args = {} - ) - public void test_getEndIndex() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals("fixture".length(), fixture.getEndIndex()); - fixture = new StringCharacterIterator("fixture", 1); - assertEquals("fixture".length(), fixture.getEndIndex()); - fixture = new StringCharacterIterator("fixture", 1, "fixture".length(), - 2); - assertEquals("fixture".length(), fixture.getEndIndex()); - fixture = new StringCharacterIterator("fixture", 1, 4, 2); - assertEquals(4, fixture.getEndIndex()); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong end index 6", 6, it1.getEndIndex()); - } - - /** - * @tests java.text.StringCharacterIterator.getIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIndex", - args = {} - ) - public void testGetIndex() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals(0, fixture.getIndex()); - fixture = new StringCharacterIterator("fixture", 1); - assertEquals(1, fixture.getIndex()); - fixture = new StringCharacterIterator("fixture", 1, "fixture".length(), - 2); - assertEquals(2, fixture.getIndex()); - fixture = new StringCharacterIterator("fixture", 1, 4, 2); - assertEquals(2, fixture.getIndex()); - } - - /** - * @tests java.text.StringCharacterIterator.last() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "last", - args = {} - ) - public void testLast() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals('e', fixture.last()); - fixture.next(); - assertEquals('e', fixture.last()); - fixture = new StringCharacterIterator("fixture", 1); - assertEquals('e', fixture.last()); - fixture = new StringCharacterIterator("fixture", 1, "fixture".length(), - 2); - assertEquals('e', fixture.last()); - fixture = new StringCharacterIterator("fixture", 1, 4, 2); - assertEquals('t', fixture.last()); - } - - /** - * @tests java.text.StringCharacterIterator.next() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "next", - args = {} - ) - public void test_next() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals(0, fixture.getIndex()); - assertEquals('i', fixture.next()); - assertEquals(1, fixture.getIndex()); - assertEquals('x', fixture.next()); - assertEquals(2, fixture.getIndex()); - assertEquals('t', fixture.next()); - assertEquals(3, fixture.getIndex()); - assertEquals('u', fixture.next()); - assertEquals(4, fixture.getIndex()); - assertEquals('r', fixture.next()); - assertEquals(5, fixture.getIndex()); - assertEquals('e', fixture.next()); - assertEquals(6, fixture.getIndex()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(7, fixture.getIndex()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(7, fixture.getIndex()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(7, fixture.getIndex()); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 3); - char result = it1.next(); - assertEquals("Wrong next char1", 'i', result); - assertEquals("Wrong next char2", 'n', it1.next()); - assertTrue("Wrong next char3", it1.next() == CharacterIterator.DONE); - assertTrue("Wrong next char4", it1.next() == CharacterIterator.DONE); - int index = it1.getIndex(); - assertEquals("Wrong index", 6, index); - assertTrue("Wrong current char", - it1.current() == CharacterIterator.DONE); - } - - /** - * @tests java.text.StringCharacterIterator.previous() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "previous", - args = {} - ) - public void test_previous() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - assertEquals(CharacterIterator.DONE, fixture.previous()); - assertEquals('i', fixture.next()); - assertEquals('x', fixture.next()); - assertEquals('t', fixture.next()); - assertEquals('u', fixture.next()); - assertEquals('r', fixture.next()); - assertEquals('e', fixture.next()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(CharacterIterator.DONE, fixture.next()); - assertEquals(7, fixture.getIndex()); - assertEquals('e', fixture.previous()); - assertEquals(6, fixture.getIndex()); - assertEquals('r', fixture.previous()); - assertEquals(5, fixture.getIndex()); - assertEquals('u', fixture.previous()); - assertEquals(4, fixture.getIndex()); - assertEquals('t', fixture.previous()); - assertEquals(3, fixture.getIndex()); - assertEquals('x', fixture.previous()); - assertEquals(2, fixture.getIndex()); - assertEquals('i', fixture.previous()); - assertEquals(1, fixture.getIndex()); - assertEquals('f', fixture.previous()); - assertEquals(0, fixture.getIndex()); - assertEquals(CharacterIterator.DONE, fixture.previous()); - assertEquals(0, fixture.getIndex()); - - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong previous char1", 't', it1.previous()); - assertEquals("Wrong previous char2", 's', it1.previous()); - assertTrue("Wrong previous char3", - it1.previous() == CharacterIterator.DONE); - assertTrue("Wrong previous char4", - it1.previous() == CharacterIterator.DONE); - assertEquals("Wrong index", 2, it1.getIndex()); - assertEquals("Wrong current char", 's', it1.current()); - } - - /** - * @tests java.text.StringCharacterIterator.setIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setIndex", - args = {int.class} - ) - public void test_setIndex() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - while (fixture.next() != CharacterIterator.DONE) { - // empty - } - assertEquals("fixture".length(), fixture.getIndex()); - fixture.setIndex(0); - assertEquals(0, fixture.getIndex()); - assertEquals('f', fixture.current()); - fixture.setIndex("fixture".length() - 1); - assertEquals('e', fixture.current()); - try { - fixture.setIndex(-1); - fail("no illegal argument"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - fixture.setIndex("fixture".length() + 1); - fail("no illegal argument"); - } catch (IllegalArgumentException e) { - // expected - } - } - - /** - * @tests java.text.StringCharacterIterator.setText(String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.lang.String.class} - ) - public void test_setText() { - StringCharacterIterator fixture = new StringCharacterIterator("fixture"); - fixture.setText("fix"); - assertEquals('f', fixture.current()); - assertEquals('x', fixture.last()); - - try { - fixture.setText(null); - fail("no null pointer"); - } catch (NullPointerException e) { - // expected - } - } - - /** - * @tests java.text.StringCharacterIterator#StringCharacterIterator(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "StringCharacterIterator", - args = {java.lang.String.class} - ) - public void test_ConstructorLjava_lang_String() { - assertNotNull(new StringCharacterIterator("value")); - assertNotNull(new StringCharacterIterator("")); - try { - new StringCharacterIterator(null); - fail("Assert 0: no null pointer"); - } catch (NullPointerException e) { - // expected - } - - StringCharacterIterator it = new StringCharacterIterator("testing"); - assertEquals("Wrong begin index", 0, it.getBeginIndex()); - assertEquals("Wrong end index", 7, it.getEndIndex()); - assertEquals("Wrong current index", 0, it.getIndex()); - assertEquals("Wrong current char", 't', it.current()); - assertEquals("Wrong next char", 'e', it.next()); - } - - /** - * @tests java.text.StringCharacterIterator#StringCharacterIterator(java.lang.String, - * int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "StringCharacterIterator", - args = {java.lang.String.class, int.class} - ) - public void test_ConstructorLjava_lang_StringI() { - StringCharacterIterator it = new StringCharacterIterator("testing", 3); - assertEquals("Wrong begin index", 0, it.getBeginIndex()); - assertEquals("Wrong end index", 7, it.getEndIndex()); - assertEquals("Wrong current index", 3, it.getIndex()); - assertEquals("Wrong current char", 't', it.current()); - assertEquals("Wrong next char", 'i', it.next()); - } - - /** - * @tests java.text.StringCharacterIterator#StringCharacterIterator(java.lang.String, - * int, int, int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "StringCharacterIterator", - args = {java.lang.String.class, int.class, int.class, int.class} - ) - public void test_ConstructorLjava_lang_StringIII() { - StringCharacterIterator it = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong begin index", 2, it.getBeginIndex()); - assertEquals("Wrong end index", 6, it.getEndIndex()); - assertEquals("Wrong current index", 4, it.getIndex()); - assertEquals("Wrong current char", 'i', it.current()); - assertEquals("Wrong next char", 'n', it.next()); - } - - /** - * @tests java.text.StringCharacterIterator#getIndex() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getIndex", - args = {} - ) - public void test_getIndex() { - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong index 4", 4, it1.getIndex()); - it1.next(); - assertEquals("Wrong index 5", 5, it1.getIndex()); - it1.last(); - assertEquals("Wrong index 4/2", 5, it1.getIndex()); - } - - /** - * @tests java.text.StringCharacterIterator#hashCode() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hashCode", - args = {} - ) - public void test_hashCode() { - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - StringCharacterIterator it2 = new StringCharacterIterator("xxstinx", 2, - 6, 4); - assertTrue("Hash is equal", it1.hashCode() != it2.hashCode()); - StringCharacterIterator it3 = new StringCharacterIterator("testing", 2, - 6, 2); - assertTrue("Hash equal1", it1.hashCode() != it3.hashCode()); - it3 = new StringCharacterIterator("testing", 0, 6, 4); - assertTrue("Hash equal2", it1.hashCode() != it3.hashCode()); - it3 = new StringCharacterIterator("testing", 2, 5, 4); - assertTrue("Hash equal3", it1.hashCode() != it3.hashCode()); - it3 = new StringCharacterIterator("froging", 2, 6, 4); - assertTrue("Hash equal4", it1.hashCode() != it3.hashCode()); - - StringCharacterIterator sci0 = new StringCharacterIterator("fixture"); - assertEquals(sci0.hashCode(), sci0.hashCode()); - - StringCharacterIterator sci1 = new StringCharacterIterator("fixture"); - assertEquals(sci0.hashCode(), sci1.hashCode()); - - sci1.next(); - sci0.next(); - assertEquals(sci0.hashCode(), sci1.hashCode()); - } - - /** - * @tests java.text.StringCharacterIterator#last() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "last", - args = {} - ) - public void test_last() { - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 3); - assertEquals("Wrong last char", 'n', it1.last()); - assertEquals("Wrong previous char", 'i', it1.previous()); - it1 = new StringCharacterIterator("testing", 2, 2, 2); - assertTrue("Not DONE", it1.last() == CharacterIterator.DONE); - } - - /** - * @tests java.text.StringCharacterIterator#setIndex(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setIndex", - args = {int.class} - ) - public void test_setIndexI() { - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - assertEquals("Wrong result1", 's', it1.setIndex(2)); - char result = it1.next(); - assertTrue("Wrong next char: " + result, result == 't'); - assertTrue("Wrong result2", it1.setIndex(6) == CharacterIterator.DONE); - assertEquals("Wrong previous char", 'n', it1.previous()); - } - - /** - * @tests java.text.StringCharacterIterator#setText(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setText", - args = {java.lang.String.class} - ) - public void test_setTextLjava_lang_String() { - StringCharacterIterator it1 = new StringCharacterIterator("testing", 2, - 6, 4); - it1.setText("frog"); - assertEquals("Wrong begin index", 0, it1.getBeginIndex()); - assertEquals("Wrong end index", 4, it1.getEndIndex()); - assertEquals("Wrong current index", 0, it1.getIndex()); - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java deleted file mode 100644 index f75c117..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.Locale; -import java.util.Vector; - - -public class Support_DecimalFormat extends Support_Format { - - public Support_DecimalFormat(String p1) { - super(p1); - } - - @Override - public void runTest() { - t_formatToCharacterIterator(); - t_format_with_FieldPosition(); - } - - public static void main(String[] args) { - new Support_DecimalFormat("").runTest(); - } - - public void t_format_with_FieldPosition() { - DecimalFormat format = (DecimalFormat) NumberFormat - .getCurrencyInstance(Locale.US); - Number number = new Double(10000000.76); - String text = "$10,000,000.76"; - - t_FormatWithField(0, format, number, text, NumberFormat.Field.CURRENCY, - 0, 1); - t_FormatWithField(1, format, number, text, NumberFormat.Field.INTEGER, - 1, 11); - t_FormatWithField(2, format, number, text, - NumberFormat.Field.GROUPING_SEPARATOR, 3, 4); - t_FormatWithField(3, format, number, text, - NumberFormat.Field.DECIMAL_SEPARATOR, 11, 12); - t_FormatWithField(4, format, number, text, NumberFormat.Field.FRACTION, - 12, 14); - - // test fields that are not included in the formatted text - t_FormatWithField(5, format, number, text, NumberFormat.Field.SIGN, 0, - 0); - t_FormatWithField(6, format, number, text, NumberFormat.Field.EXPONENT, - 0, 0); - t_FormatWithField(7, format, number, text, - NumberFormat.Field.EXPONENT_SIGN, 0, 0); - t_FormatWithField(8, format, number, text, - NumberFormat.Field.EXPONENT_SYMBOL, 0, 0); - t_FormatWithField(9, format, number, text, NumberFormat.Field.PERCENT, - 0, 0); - t_FormatWithField(10, format, number, text, - NumberFormat.Field.PERMILLE, 0, 0); - - // test Exponential - format = new DecimalFormat("000000000.0#E0"); - text = "100000007.6E-1"; - t_FormatWithField(11, format, number, text, NumberFormat.Field.INTEGER, - 0, 9); - t_FormatWithField(12, format, number, text, - NumberFormat.Field.DECIMAL_SEPARATOR, 9, 10); - t_FormatWithField(13, format, number, text, - NumberFormat.Field.FRACTION, 10, 11); - t_FormatWithField(14, format, number, text, - NumberFormat.Field.EXPONENT_SYMBOL, 11, 12); - t_FormatWithField(15, format, number, text, - NumberFormat.Field.EXPONENT_SIGN, 12, 13); - t_FormatWithField(16, format, number, text, - NumberFormat.Field.EXPONENT, 13, 14); - - // test fields that are not included in the formatted text - t_FormatWithField(17, format, number, text, - NumberFormat.Field.GROUPING_SEPARATOR, 0, 0); - t_FormatWithField(18, format, number, text, NumberFormat.Field.SIGN, 0, - 0); - t_FormatWithField(19, format, number, text, - NumberFormat.Field.CURRENCY, 0, 0); - t_FormatWithField(20, format, number, text, NumberFormat.Field.PERCENT, - 0, 0); - t_FormatWithField(21, format, number, text, - NumberFormat.Field.PERMILLE, 0, 0); - - // test currency instance with TR Locale - number = new Double(350.76); - format = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale( - "tr", "TR")); - text = "351 TL"; - t_FormatWithField(22, format, number, text, NumberFormat.Field.INTEGER, - 0, 3); - t_FormatWithField(23, format, number, text, - NumberFormat.Field.CURRENCY, 4, 6); - - // test fields that are not included in the formatted text - t_FormatWithField(25, format, number, text, - NumberFormat.Field.GROUPING_SEPARATOR, 0, 0); - t_FormatWithField(26, format, number, text, - NumberFormat.Field.DECIMAL_SEPARATOR, 0, 0); - t_FormatWithField(27, format, number, text, NumberFormat.Field.SIGN, 0, - 0); - t_FormatWithField(28, format, number, text, - NumberFormat.Field.EXPONENT, 0, 0); - t_FormatWithField(29, format, number, text, - NumberFormat.Field.EXPONENT_SIGN, 0, 0); - t_FormatWithField(30, format, number, text, - NumberFormat.Field.EXPONENT_SYMBOL, 0, 0); - t_FormatWithField(31, format, number, text, NumberFormat.Field.PERCENT, - 0, 0); - t_FormatWithField(32, format, number, text, - NumberFormat.Field.PERMILLE, 0, 0); - - } - - public void t_formatToCharacterIterator() { - - Number number = new Double(350.76); - Number negativeNumber = new Double(-350.76); - - Locale us = Locale.US; - Locale tr = new Locale("tr", "TR"); - - // test number instance - t_Format(1, number, NumberFormat.getNumberInstance(us), - getNumberVectorUS()); - - // test integer instance - // testFormat(2, number, NumberFormat.getIntegerInstance(us), - // getPercentVectorUS()); - - // test percent instance - t_Format(3, number, NumberFormat.getPercentInstance(us), - getPercentVectorUS()); - - // test permille pattern - DecimalFormat format = new DecimalFormat("###0.##\u2030"); - t_Format(4, number, format, getPermilleVector()); - - // test exponential pattern with positive exponent - format = new DecimalFormat("00.0#E0"); - t_Format(5, number, format, getPositiveExponentVector()); - - // test exponential pattern with negative exponent - format = new DecimalFormat("0000.0#E0"); - t_Format(6, number, format, getNegativeExponentVector()); - - // test currency instance with US Locale - t_Format(7, number, NumberFormat.getCurrencyInstance(us), - getPositiveCurrencyVectorUS()); - - // test negative currency instance with US Locale - t_Format(8, negativeNumber, NumberFormat.getCurrencyInstance(us), - getNegativeCurrencyVectorUS()); - - // test currency instance with TR Locale - t_Format(9, number, NumberFormat.getCurrencyInstance(tr), - getPositiveCurrencyVectorTR()); - - // test negative currency instance with TR Locale - t_Format(10, negativeNumber, NumberFormat.getCurrencyInstance(tr), - getNegativeCurrencyVectorTR()); - - // test multiple grouping seperators - number = new Long(100300400); - t_Format(11, number, NumberFormat.getNumberInstance(us), - getNumberVector2US()); - - // test 0 - number = new Long(0); - t_Format(12, number, NumberFormat.getNumberInstance(us), - getZeroVector()); - } - - private static Vector<FieldContainer> getNumberVectorUS() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION)); - return v; - } - - private static Vector<FieldContainer> getPositiveCurrencyVectorTR() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(4, 6, NumberFormat.Field.CURRENCY)); - return v; - } - - private static Vector<FieldContainer> getNegativeCurrencyVectorTR() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN)); - v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(5, 7, NumberFormat.Field.CURRENCY)); - return v; - } - - private static Vector<FieldContainer> getPositiveCurrencyVectorUS() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 1, NumberFormat.Field.CURRENCY)); - v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION)); - return v; - } - - private static Vector<FieldContainer> getNegativeCurrencyVectorUS() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(1, 2, NumberFormat.Field.CURRENCY)); - v.add(new FieldContainer(2, 5, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(5, 6, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(6, 8, NumberFormat.Field.FRACTION)); - return v; - } - - private static Vector<FieldContainer> getPercentVectorUS() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(2, 3, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR)); - v.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(6, 7, NumberFormat.Field.PERCENT)); - return v; - } - - private static Vector<FieldContainer> getPermilleVector() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE)); - return v; - } - - private static Vector<FieldContainer> getNegativeExponentVector() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 4, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(5, 6, NumberFormat.Field.FRACTION)); - v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL)); - v.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN)); - v.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT)); - return v; - } - - private static Vector<FieldContainer> getPositiveExponentVector() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(3, 5, NumberFormat.Field.FRACTION)); - v.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL)); - v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT)); - return v; - } - - private static Vector<FieldContainer> getNumberVector2US() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR)); - v.add(new FieldContainer(3, 4, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR)); - v.add(new FieldContainer(7, 8, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER)); - return v; - } - - private static Vector<FieldContainer> getZeroVector() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER)); - return v; - } - -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java deleted file mode 100644 index 10cd071..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.AttributedCharacterIterator; -import java.text.FieldPosition; -import java.text.Format; -import java.text.AttributedCharacterIterator.Attribute; -import java.util.Iterator; -import java.util.Vector; -import junit.framework.TestCase; - -public class Support_Format extends TestCase { - - protected String text; - - public Support_Format(String p1) { - super(p1); - } - - protected void t_FormatWithField(int count, Format format, Object object, - String text, Format.Field field, int begin, int end) { - StringBuffer buffer = new StringBuffer(); - FieldPosition pos = new FieldPosition(field); - format.format(object, buffer, pos); - - // System.out.println(buffer); - // System.out.println(pos); - - if (text == null) { - assertEquals("Test " + count + ": incorrect formatted text", - this.text, buffer.toString()); - } else { - assertEquals("Test " + count + ": incorrect formatted text", text, - buffer.toString()); - } - - assertEquals("Test " + count + ": incorrect begin index for field " - + field, begin, pos.getBeginIndex()); - assertEquals("Test " + count + ": incorrect end index for field" - + field, end, pos.getEndIndex()); - } - - protected void t_Format(int count, Object object, Format format, - Vector<FieldContainer> expectedResults) { - // System.out.println(format.format(object)); - Vector<FieldContainer> results = findFields(format.formatToCharacterIterator(object)); - assertTrue("Test " + count - + ": Format returned incorrect CharacterIterator for " - + format.format(object), compare(results, expectedResults)); - } - - /** - * compares two vectors regardless of the order of their elements - */ - protected static boolean compare(Vector<FieldContainer> vector1, Vector<FieldContainer> vector2) { - return vector1.size() == vector2.size() && vector1.containsAll(vector2); - } - - /** - * finds attributes with regards to char index in this - * AttributedCharacterIterator, and puts them in a vector - * - * @param iterator - * @return a vector, each entry in this vector are of type FieldContainer , - * which stores start and end indexes and an attribute this range - * has - */ - protected static Vector<FieldContainer> findFields(AttributedCharacterIterator iterator) { - Vector<FieldContainer> result = new Vector<FieldContainer>(); - while (iterator.getIndex() != iterator.getEndIndex()) { - int start = iterator.getRunStart(); - int end = iterator.getRunLimit(); - - Iterator<Attribute> it = iterator.getAttributes().keySet().iterator(); - while (it.hasNext()) { - AttributedCharacterIterator.Attribute attribute = it.next(); - Object value = iterator.getAttribute(attribute); - result.add(new FieldContainer(start, end, attribute, value)); - // System.out.println(start + " " + end + ": " + attribute + ", - // " + value ); - // System.out.println("v.add(new FieldContainer(" + start +"," + - // end +"," + attribute+ "," + value+ "));"); - } - iterator.setIndex(end); - } - return result; - } - - protected static class FieldContainer { - int start, end; - - AttributedCharacterIterator.Attribute attribute; - - Object value; - - // called from support_decimalformat and support_simpledateformat tests - public FieldContainer(int start, int end, - AttributedCharacterIterator.Attribute attribute) { - this(start, end, attribute, attribute); - } - - // called from support_messageformat tests - public FieldContainer(int start, int end, Attribute attribute, int value) { - this(start, end, attribute, new Integer(value)); - } - - // called from support_messageformat tests - public FieldContainer(int start, int end, Attribute attribute, - Object value) { - this.start = start; - this.end = end; - this.attribute = attribute; - this.value = value; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof FieldContainer)) { - return false; - } - - FieldContainer fc = (FieldContainer) obj; - return (start == fc.start && end == fc.end - && attribute == fc.attribute && value.equals(fc.value)); - } - } -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java deleted file mode 100644 index d18e95b..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.DateFormat; -import java.text.MessageFormat; -import java.text.NumberFormat; -import java.text.MessageFormat.Field; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.Vector; - - -public class Support_MessageFormat extends Support_Format { - - public Support_MessageFormat(String p1) { - super(p1); - } - - @Override - public void runTest() { - t_formatToCharacterIterator(); - t_format_with_FieldPosition(); - } - - public static void main(String[] args) { - new Support_MessageFormat("").runTest(); - } - - public void t_format_with_FieldPosition() { - - String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!"; - MessageFormat format = new MessageFormat(pattern, Locale.US); - - Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime(); - Integer hamburgers = new Integer(8); - Object[] objects = new Object[] { hamburgers, new Double(3.5), - hamburgers, date, date }; - - super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!"; - - // test with MessageFormat.Field.ARGUMENT - t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15); - - // test other format fields that are included in the formatted text - t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0, - 0); - t_FormatWithField(3, format, objects, null, - NumberFormat.Field.FRACTION, 0, 0); - - // test fields that are not included in the formatted text - t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0); - t_FormatWithField(5, format, objects, null, - NumberFormat.Field.EXPONENT_SIGN, 0, 0); - } - - public void t_formatToCharacterIterator() { - - String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!"; - MessageFormat format = new MessageFormat(pattern, Locale.US); - - Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime(); - Integer hamburgers = new Integer(8); - Object[] objects = new Object[] { hamburgers, new Double(3.5), - hamburgers, date, date }; - - t_Format(1, objects, format, getMessageVector1()); - } - - private Vector<FieldContainer> getMessageVector1() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(3, 6, Field.ARGUMENT, 4)); - v.add(new FieldContainer(3, 6, DateFormat.Field.MONTH)); - v.add(new FieldContainer(6, 7, Field.ARGUMENT, 4)); - v.add(new FieldContainer(7, 9, Field.ARGUMENT, 4)); - v.add(new FieldContainer(7, 9, DateFormat.Field.DAY_OF_MONTH)); - v.add(new FieldContainer(9, 11, Field.ARGUMENT, 4)); - v.add(new FieldContainer(11, 15, Field.ARGUMENT, 4)); - v.add(new FieldContainer(11, 15, DateFormat.Field.YEAR)); - v.add(new FieldContainer(19, 20, Field.ARGUMENT, 3)); - v.add(new FieldContainer(19, 20, DateFormat.Field.HOUR1)); - v.add(new FieldContainer(20, 21, Field.ARGUMENT, 3)); - v.add(new FieldContainer(21, 23, Field.ARGUMENT, 3)); - v.add(new FieldContainer(21, 23, DateFormat.Field.MINUTE)); - v.add(new FieldContainer(23, 24, Field.ARGUMENT, 3)); - v.add(new FieldContainer(24, 26, Field.ARGUMENT, 3)); - v.add(new FieldContainer(24, 26, DateFormat.Field.SECOND)); - v.add(new FieldContainer(26, 27, Field.ARGUMENT, 3)); - v.add(new FieldContainer(27, 29, Field.ARGUMENT, 3)); - v.add(new FieldContainer(27, 29, DateFormat.Field.AM_PM)); - v.add(new FieldContainer(38, 39, Field.ARGUMENT, 2)); - v.add(new FieldContainer(38, 39, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(49, 50, Field.ARGUMENT, 2)); - v.add(new FieldContainer(61, 62, Field.ARGUMENT, 1)); - v.add(new FieldContainer(61, 62, NumberFormat.Field.INTEGER)); - v.add(new FieldContainer(62, 63, Field.ARGUMENT, 1)); - v.add(new FieldContainer(62, 63, NumberFormat.Field.DECIMAL_SEPARATOR)); - v.add(new FieldContainer(63, 64, Field.ARGUMENT, 1)); - v.add(new FieldContainer(63, 64, NumberFormat.Field.FRACTION)); - v.add(new FieldContainer(90, 106, Field.ARGUMENT, 0)); - return v; - } - -} diff --git a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java b/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java deleted file mode 100644 index 325dcce..0000000 --- a/luni/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.harmony.text.tests.java.text; - -import java.text.DateFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; -import java.text.DateFormat.Field; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; -import java.util.Vector; - -import org.apache.harmony.text.tests.java.text.Support_Format.FieldContainer; - - -public class Support_SimpleDateFormat extends Support_Format { - - public Support_SimpleDateFormat(String p1) { - super(p1); - } - - @Override - public void runTest() { - t_formatToCharacterIterator(); - t_format_with_FieldPosition(); - } - - public static void main(String[] args) { - new Support_SimpleDateFormat("").runTest(); - } - - public void t_format_with_FieldPosition() { - TimeZone tz = TimeZone.getTimeZone("EST"); - Calendar cal = new GregorianCalendar(tz); - cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01); - cal.set(Calendar.MILLISECOND, 0); - Date date = cal.getTime(); - SimpleDateFormat format = (SimpleDateFormat) DateFormat - .getDateInstance(DateFormat.DEFAULT, Locale.US); - format.setTimeZone(tz); - - // test with all pattern chars, and multiple occurances - format - .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ"); - - StringBuffer textbuffer = new StringBuffer( - "AD Anno Domini 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5 05"); - textbuffer - .append(" 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003 PM"); - textbuffer.append(" PM 5 005 GMT-05:00 GMT-05:00 -0500 GMT-05:00"); - - // to avoid passing the huge Stringbuffer each time. - super.text = textbuffer.toString(); - - // test if field positions are set correctly for these fields occuring - // multiple times. - t_FormatWithField(0, format, date, null, Field.ERA, 0, 2); - t_FormatWithField(1, format, date, null, Field.YEAR, 15, 17); - t_FormatWithField(2, format, date, null, Field.MONTH, 26, 27); - t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 45, 47); - t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 55, 57); - t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 65, 67); - t_FormatWithField(6, format, date, null, Field.HOUR1, 75, 76); - t_FormatWithField(7, format, date, null, Field.MINUTE, 84, 86); - t_FormatWithField(8, format, date, null, Field.SECOND, 91, 92); - t_FormatWithField(9, format, date, null, Field.MILLISECOND, 100, 101); - t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 109, 112); - t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 120, 123); - t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, - 132, 133); - t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 137, 139); - t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 144, 145); - t_FormatWithField(15, format, date, null, Field.AM_PM, 150, 152); - t_FormatWithField(16, format, date, null, Field.HOUR0, 158, 159); - t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 164, 173); - - // test fields that are not included in the formatted text - t_FormatWithField(18, format, date, null, - NumberFormat.Field.EXPONENT_SIGN, 0, 0); - - // test with simple example - format.applyPattern("h:m z"); - - super.text = "5:19 GMT-05:00"; - t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1); - t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4); - t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 14); - - // test fields that are not included in the formatted text - - t_FormatWithField(24, format, date, null, Field.ERA, 0, 0); - t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0); - t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0); - t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0); - t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0); - t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0); - t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0); - t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0); - t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0); - t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0); - t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, - 0, 0); - t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0); - t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0); - t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0); - t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0); - - t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT, - 0, 0); - - // test with simple example with pattern char Z - format.applyPattern("h:m Z z"); - super.text = "5:19 -0500 GMT-05:00"; - t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1); - t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4); - t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10); - } - - public void t_formatToCharacterIterator() { - TimeZone tz = TimeZone.getTimeZone("EST"); - Calendar cal = new GregorianCalendar(tz); - cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01); - cal.set(Calendar.MILLISECOND, 0); - Date date = cal.getTime(); - SimpleDateFormat format = (SimpleDateFormat) DateFormat - .getDateInstance(DateFormat.DEFAULT, Locale.US); - format.setTimeZone(tz); - - format.applyPattern("yyyyMMddHHmmss"); - t_Format(1, date, format, getDateVector1()); - - format.applyPattern("w W dd MMMM yyyy EEEE"); - t_Format(2, date, format, getDateVector2()); - - format.applyPattern("h:m z"); - t_Format(3, date, format, getDateVector3()); - - format.applyPattern("h:m Z"); - t_Format(5, date, format, getDateVector5()); - - // with all pattern chars, and multiple occurances - format - .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ"); - t_Format(4, date, format, getDateVector4()); - } - - private Vector<FieldContainer> getDateVector1() { - // "19990913171901" - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 4, Field.YEAR)); - v.add(new FieldContainer(4, 6, Field.MONTH)); - v.add(new FieldContainer(6, 8, Field.DAY_OF_MONTH)); - v.add(new FieldContainer(8, 10, Field.HOUR_OF_DAY0)); - v.add(new FieldContainer(10, 12, Field.MINUTE)); - v.add(new FieldContainer(12, 14, Field.SECOND)); - return v; - } - - private Vector<FieldContainer> getDateVector2() { - // "12 3 5 March 2002 Monday" - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 2, Field.WEEK_OF_YEAR)); - v.add(new FieldContainer(3, 4, Field.WEEK_OF_MONTH)); - v.add(new FieldContainer(5, 7, Field.DAY_OF_MONTH)); - v.add(new FieldContainer(8, 17, Field.MONTH)); - v.add(new FieldContainer(18, 22, Field.YEAR)); - v.add(new FieldContainer(23, 29, Field.DAY_OF_WEEK)); - return v; - } - - private Vector<FieldContainer> getDateVector3() { - // "5:19 EDT" - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 1, Field.HOUR1)); - v.add(new FieldContainer(2, 4, Field.MINUTE)); - v.add(new FieldContainer(5, 14, Field.TIME_ZONE)); - return v; - } - - private Vector<FieldContainer> getDateVector5() { - // "5:19 -0400" - Vector<FieldContainer> v = new Vector<FieldContainer>(); - v.add(new FieldContainer(0, 1, Field.HOUR1)); - v.add(new FieldContainer(2, 4, Field.MINUTE)); - v.add(new FieldContainer(5, 10, Field.TIME_ZONE)); - return v; - } - - private Vector<FieldContainer> getDateVector4() { - Vector<FieldContainer> v = new Vector<FieldContainer>(); - - // "AD AD 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5 - // 05 - // 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003 - // PM - // PM 5 005 EDT Eastern Daylight Time -0400 -0400" - v.add(new FieldContainer(0, 2, Field.ERA)); - v.add(new FieldContainer(3, 5, Field.ERA)); - v.add(new FieldContainer(6, 8, Field.YEAR)); - v.add(new FieldContainer(9, 11, Field.YEAR)); - v.add(new FieldContainer(12, 16, Field.YEAR)); - v.add(new FieldContainer(17, 18, Field.MONTH)); - v.add(new FieldContainer(19, 21, Field.MONTH)); - v.add(new FieldContainer(22, 25, Field.MONTH)); - v.add(new FieldContainer(26, 35, Field.MONTH)); - v.add(new FieldContainer(36, 38, Field.DAY_OF_MONTH)); - v.add(new FieldContainer(39, 41, Field.DAY_OF_MONTH)); - v.add(new FieldContainer(42, 45, Field.DAY_OF_MONTH)); - v.add(new FieldContainer(46, 48, Field.HOUR_OF_DAY1)); - v.add(new FieldContainer(49, 51, Field.HOUR_OF_DAY1)); - v.add(new FieldContainer(52, 55, Field.HOUR_OF_DAY1)); - v.add(new FieldContainer(56, 58, Field.HOUR_OF_DAY0)); - v.add(new FieldContainer(59, 61, Field.HOUR_OF_DAY0)); - v.add(new FieldContainer(62, 65, Field.HOUR_OF_DAY0)); - v.add(new FieldContainer(66, 67, Field.HOUR1)); - v.add(new FieldContainer(68, 70, Field.HOUR1)); - v.add(new FieldContainer(71, 74, Field.HOUR1)); - v.add(new FieldContainer(75, 77, Field.MINUTE)); - v.add(new FieldContainer(78, 81, Field.MINUTE)); - v.add(new FieldContainer(82, 83, Field.SECOND)); - v.add(new FieldContainer(84, 86, Field.SECOND)); - v.add(new FieldContainer(87, 90, Field.SECOND)); - v.add(new FieldContainer(91, 92, Field.MILLISECOND)); - v.add(new FieldContainer(93, 95, Field.MILLISECOND)); - v.add(new FieldContainer(96, 99, Field.MILLISECOND)); - v.add(new FieldContainer(100, 103, Field.DAY_OF_WEEK)); - v.add(new FieldContainer(104, 110, Field.DAY_OF_WEEK)); - v.add(new FieldContainer(111, 114, Field.DAY_OF_YEAR)); - v.add(new FieldContainer(115, 118, Field.DAY_OF_YEAR)); - v.add(new FieldContainer(119, 122, Field.DAY_OF_YEAR)); - v.add(new FieldContainer(123, 124, Field.DAY_OF_WEEK_IN_MONTH)); - v.add(new FieldContainer(125, 127, Field.DAY_OF_WEEK_IN_MONTH)); - v.add(new FieldContainer(128, 130, Field.WEEK_OF_YEAR)); - v.add(new FieldContainer(131, 134, Field.WEEK_OF_YEAR)); - v.add(new FieldContainer(135, 136, Field.WEEK_OF_MONTH)); - v.add(new FieldContainer(137, 140, Field.WEEK_OF_MONTH)); - v.add(new FieldContainer(141, 143, Field.AM_PM)); - v.add(new FieldContainer(145, 147, Field.AM_PM)); - v.add(new FieldContainer(149, 150, Field.HOUR0)); - v.add(new FieldContainer(151, 154, Field.HOUR0)); - v.add(new FieldContainer(155, 164, Field.TIME_ZONE)); - v.add(new FieldContainer(165, 174, Field.TIME_ZONE)); - v.add(new FieldContainer(175, 180, Field.TIME_ZONE)); - v.add(new FieldContainer(181, 186, Field.TIME_ZONE)); - return v; - } - -} diff --git a/luni/src/test/java/tests/AllTests.java b/luni/src/test/java/tests/AllTests.java index 33ff539..e7ad17a 100644 --- a/luni/src/test/java/tests/AllTests.java +++ b/luni/src/test/java/tests/AllTests.java @@ -51,7 +51,6 @@ public class AllTests suite.addTest(tests.sql.AllTests.suite()); suite.addTest(tests.SQLite.AllTests.suite()); suite.addTest(tests.suncompat.AllTests.suite()); - suite.addTest(tests.text.AllTests.suite()); suite.addTest(tests.xml.AllTests.suite()); suite.addTest(tests.api.org.apache.harmony.kernel.dalvik.AllTests.suite()); |