You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC
svn commit: r386058 [44/49] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/archive/make/common/ modules/archive/src/test/java/tests/
modules/archive/src/test/java/tests/api/
modules/archive/src/test/java/tests/api/java/ modules/archive/...
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BreakIteratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BreakIteratorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BreakIteratorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/BreakIteratorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,291 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+import java.text.BreakIterator;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO Type description
+ *
+ */
+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);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testConsts() {
+ assertEquals(-1, BreakIterator.DONE);
+ }
+
+ 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));
+ }
+
+ public void testClone() {
+ BreakIterator cloned = (BreakIterator) iterator.clone();
+ assertNotSame(cloned, iterator);
+ assertEquals(cloned, iterator);
+ }
+
+ public void testCurrent() {
+ assertEquals(0, iterator.current());
+ iterator.setText(TEXT);
+ assertEquals(iterator.first(), iterator.current());
+ }
+
+ public void testFirst() {
+ assertEquals(0, iterator.first());
+ iterator.setText(TEXT);
+ assertEquals(0, iterator.first());
+ }
+
+ 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) {
+ }
+ }
+
+ 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) {
+ }
+ }
+
+ public void testLast() {
+ assertEquals(0, iterator.last());
+ iterator.setText(TEXT);
+ assertEquals(TEXT.length(), iterator.last());
+ }
+
+ /*
+ * Class under test for int next()
+ */
+ public void testNext() {
+ assertEquals(BreakIterator.DONE, iterator.next());
+ iterator.setText(TEXT);
+ assertEquals(2, iterator.next());
+ }
+
+ /*
+ * Class under test for int next(int)
+ */
+ 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()));
+ }
+
+ 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) {
+ }
+ }
+
+ public void testPrevious() {
+ assertEquals(-1, iterator.previous());
+ iterator.setText(TEXT);
+ assertEquals(-1, iterator.previous());
+ iterator.last();
+ assertEquals(TEXT.length() - 1, iterator.previous());
+ }
+
+ // public void testGetAvailableLocales() {
+ // Locale[] locales = BreakIterator.getAvailableLocales();
+ // }
+
+ /*
+ * Class under test for BreakIterator getCharacterInstance()
+ */
+ public void testGetCharacterInstance() {
+ BreakIterator.getCharacterInstance();
+ }
+
+ /*
+ * Class under test for BreakIterator getCharacterInstance(Locale)
+ */
+ public void testGetCharacterInstanceLocale() {
+ BreakIterator it = BreakIterator.getCharacterInstance(Locale.US);
+ BreakIterator it2 = BreakIterator.getCharacterInstance(Locale.CHINA);
+ assertEquals(it, it2);
+ }
+
+ /*
+ * Class under test for BreakIterator getLineInstance()
+ */
+ public void testGetLineInstance() {
+ BreakIterator it = BreakIterator.getLineInstance();
+ }
+
+ /*
+ * Class under test for BreakIterator getLineInstance(Locale)
+ */
+ public void testGetLineInstanceLocale() {
+ BreakIterator it = BreakIterator.getLineInstance(Locale.US);
+ BreakIterator.getLineInstance(new Locale("bad locale"));
+ }
+
+ /*
+ * Class under test for BreakIterator getSentenceInstance()
+ */
+ public void testGetSentenceInstance() {
+ BreakIterator it = BreakIterator.getSentenceInstance();
+ }
+
+ /*
+ * Class under test for BreakIterator getSentenceInstance(Locale)
+ */
+ public void testGetSentenceInstanceLocale() {
+ BreakIterator it = BreakIterator.getSentenceInstance(Locale.US);
+ }
+
+ public void testGetText() {
+ assertEquals(new StringCharacterIterator(""), iterator.getText());
+ iterator.setText(TEXT);
+ assertEquals(new StringCharacterIterator(TEXT), iterator.getText());
+ }
+
+ /*
+ * Class under test for BreakIterator getWordInstance()
+ */
+ public void testGetWordInstance() {
+ BreakIterator it = BreakIterator.getWordInstance();
+ }
+
+ /*
+ * Class under test for BreakIterator getWordInstance(Locale)
+ */
+ public void testGetWordInstanceLocale() {
+ BreakIterator it = BreakIterator.getWordInstance(Locale.US);
+ }
+
+ /*
+ * Class under test for void setText(CharacterIterator)
+ */
+ 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)
+ */
+ public void testSetTextString() {
+ try {
+ iterator.setText((String) null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ iterator.setText("abc");
+ CharacterIterator it = new StringCharacterIterator("abc");
+ assertEquals(it, iterator.getText());
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/ChoiceFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/ChoiceFormatTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/ChoiceFormatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/ChoiceFormatTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,391 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+import java.text.ChoiceFormat;
+import java.text.FieldPosition;
+import java.text.MessageFormat;
+import java.text.ParsePosition;
+
+public class ChoiceFormatTest extends junit.framework.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[])
+ */
+ 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)
+ */
+ 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)
+ */
+ 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" }));
+ }
+
+ /**
+ * @tests java.text.ChoiceFormat#clone()
+ */
+ 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)
+ */
+ 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)
+ */
+ 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();
+ assertTrue("Wrong choice for -1", r.equals("Less than one"));
+ buf.setLength(0);
+ r = f1.format(0, buf, field).toString();
+ assertTrue("Wrong choice for 0", r.equals("Less than one"));
+ buf.setLength(0);
+ r = f1.format(1, buf, field).toString();
+ assertTrue("Wrong choice for 1", r.equals("one"));
+ buf.setLength(0);
+ r = f1.format(2, buf, field).toString();
+ assertTrue("Wrong choice for 2", r.equals("Between one and two"));
+ buf.setLength(0);
+ r = f1.format(3, buf, field).toString();
+ assertTrue("Wrong choice for 3", r.equals("Greater than two"));
+ }
+
+ /**
+ * @tests java.text.ChoiceFormat#format(long, java.lang.StringBuffer,
+ * java.text.FieldPosition)
+ */
+ 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();
+ assertTrue("Wrong choice for 0.5", r.equals("Less than one"));
+ buf.setLength(0);
+ r = f1.format(1.5, buf, field).toString();
+ assertTrue("Wrong choice for 1.5", r.equals("Between one and two"));
+ buf.setLength(0);
+ r = f1.format(2.5, buf, field).toString();
+ assertTrue("Wrong choice for 2.5", r.equals("Greater than two"));
+ }
+
+ /**
+ * @tests java.text.ChoiceFormat#getFormats()
+ */
+ 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()
+ */
+ 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()
+ */
+ 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)
+ */
+ 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)
+ */
+ 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)
+ */
+ 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");
+ assertTrue("Case insensitive", format
+ .parse("One", new ParsePosition(0)).intValue() == 0);
+
+ 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));
+ assertTrue("Wrong position ~16", pos.getIndex() == 16);
+ pos = new ParsePosition(0);
+ assertTrue("Incorrect result", Double.isNaN(f1.parse("12one", pos)
+ .doubleValue()));
+ assertTrue("Wrong position ~0", pos.getIndex() == 0);
+ pos = new ParsePosition(2);
+ result = f1.parse("12one and two", pos);
+ assertTrue("Not a Double2", result instanceof Double);
+ assertTrue("Ignored parse position", result.doubleValue() == 1.0);
+ assertTrue("Wrong position ~5", pos.getIndex() == 5);
+ }
+
+ /**
+ * @tests java.text.ChoiceFormat#previousDouble(double)
+ */
+ 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[])
+ */
+ 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()
+ */
+ public void test_toPattern() {
+ // Test for method java.lang.String java.text.ChoiceFormat.toPattern()
+
+ MessageFormat mf = new MessageFormat("CHOICE {1,choice}");
+ String ptrn = mf.toPattern();
+ assertTrue("Unused message format returning incorrect pattern", ptrn
+ .equals("CHOICE {1,choice,}"));
+
+ 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"));
+
+ ChoiceFormat 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();
+ assertTrue("Return value should be empty string for invalid pattern",
+ ptrn.length() == 0);
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationElementIteratorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationElementIteratorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationElementIteratorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationElementIteratorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,205 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+import java.text.CollationElementIterator;
+import java.text.Collator;
+import java.text.ParseException;
+import java.text.RuleBasedCollator;
+
+import java.util.Locale;
+
+import java.text.StringCharacterIterator;
+
+import junit.framework.TestCase;
+
+/**
+ * Test CollationElementIterator
+ *
+ * Only test normal condition.
+ *
+ */
+public class CollationElementIteratorTest extends TestCase {
+
+ private RuleBasedCollator coll;
+
+ protected void setUp() {
+ coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
+ }
+
+ 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);
+ }
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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();
+ }
+
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ public void testSetOffset() {
+ RuleBasedCollator rbColl = (RuleBasedCollator) Collator
+ .getInstance(new Locale("es", "", "TRADITIONAL"));
+ String text = "cha";
+ CollationElementIterator iterator = rbColl
+ .getCollationElementIterator(text);
+ iterator.setOffset(1);
+ assertEquals(0, iterator.getOffset());
+ }
+
+ /*
+ * Class under test for void setText(java.lang.String)
+ */
+ 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(0, iterator.getOffset());
+ }
+
+ /*
+ * Class under test for void setText(java.text.CharacterIterator)
+ */
+ 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(0, iterator.getOffset());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationKeyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationKeyTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationKeyTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollationKeyTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,128 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.CollationKey;
+import java.text.Collator;
+import java.text.ParseException;
+import java.text.RuleBasedCollator;
+import java.util.Arrays;
+
+public class CollationKeyTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.text.CollationKey#compareTo(java.text.CollationKey)
+ */
+ public void test_compareToLjava_text_CollationKey() {
+ Collator collator = Collator.getInstance();
+ collator.setStrength(Collator.PRIMARY);
+ CollationKey key1 = collator.getCollationKey("abc");
+ CollationKey key2 = collator.getCollationKey("ABC");
+ assertTrue("Should be equal", key1.compareTo(key2) == 0);
+ }
+
+ /**
+ * @tests java.text.CollationKey#compareTo(java.lang.Object)
+ */
+ 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");
+ assertTrue("Should be equal", key1.compareTo(key2) == 0);
+ }
+
+ /**
+ * @tests java.text.CollationKey#equals(java.lang.Object)
+ */
+ 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()
+ */
+ 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()
+ */
+ 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());
+ }
+
+ /**
+ * @tests java.text.CollationKey#toByteArray()
+ */
+ public void test_toByteArray() {
+ // Test for method byte [] java.text.CollationKey.toByteArray()
+ Collator collator = Collator.getInstance();
+ collator.setStrength(Collator.PRIMARY);
+ CollationKey key1 = collator.getCollationKey("abc");
+ byte[] bytes = key1.toByteArray();
+ assertTrue("Not enough bytes", bytes.length >= 3);
+
+ try {
+ collator = new RuleBasedCollator("= 1 , 2 ; 3 , 4 < 5 ; 6 , 7");
+ } catch (ParseException e) {
+ fail("ParseException");
+ return;
+ }
+ bytes = collator.getCollationKey("1234567").toByteArray();
+ /*
+ * CollationElementIterator it =
+ * ((RuleBasedCollator)collator).getCollationElementIterator("1234567");
+ * int order; while ((order = it.next()) !=
+ * CollationElementIterator.NULLORDER) {
+ * System.out.println(Integer.toHexString(order)); } for (int i=0; i<bytes.length;
+ * i+=2) { System.out.print(Integer.toHexString(bytes[i]) +
+ * Integer.toHexString(bytes[i+1]) + " "); } System.out.println();
+ */
+ byte[] result = new byte[] { 0, 2, 0, 2, 0, 2, 0, 0, 0, 3, 0, 3, 0, 1,
+ 0, 2, 0, 2, 0, 0, 0, 4, 0, 4, 0, 1, 0, 1, 0, 2 };
+ assertTrue("Wrong bytes", Arrays.equals(bytes, result));
+ }
+
+ /**
+ * 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollatorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollatorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/CollatorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,278 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.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";
+ assertTrue("a) Failed on equivalence", c.compare(o, o2) == 0);
+ 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";
+ assertTrue("b) Failed on identical", c.compare(o, o2) == 0);
+ o = "e";
+ o2 = "e";
+ assertTrue("b) Failed on equivalence", c.compare(o, o2) == 0);
+
+ 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";
+ assertTrue("c) Failed on tertiary difference", c.compare(o, o2) == 0);
+ o = "\u0001";
+ o2 = "\u0002";
+ assertTrue("c) Failed on identical", c.compare(o, o2) == 0);
+ o = "e";
+ o2 = "e";
+ assertTrue("c) Failed on equivalence", c.compare(o, o2) == 0);
+
+ c.setStrength(Collator.PRIMARY);
+ o = "E";
+ o2 = "F";
+ assertTrue("d) Failed on primary difference", c.compare(o, o2) < 0);
+ o = "e";
+ o2 = "\u00e9";
+ assertTrue("d) Failed on secondary difference", c.compare(o, o2) == 0);
+ o = "e";
+ o2 = "E";
+ assertTrue("d) Failed on tertiary difference", c.compare(o, o2) == 0);
+ o = "\u0001";
+ o2 = "\u0002";
+ assertTrue("d) Failed on identical", c.compare(o, o2) == 0);
+ o = "e";
+ o2 = "e";
+ assertTrue("d) Failed on equivalence", c.compare(o, o2) == 0);
+
+ 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()
+ */
+ public void 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
+ System.out.print(locales[i] + ",");
+ 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()
+ */
+ public void test_getDecomposition() {
+ RuleBasedCollator collator;
+ try {
+ collator = new RuleBasedCollator("; \u0300 < a, A < b < c < d");
+ } catch (ParseException e) {
+ fail("ParseException");
+ return;
+ }
+ assertTrue("Wrong default",
+ collator.getDecomposition() == Collator.CANONICAL_DECOMPOSITION);
+ }
+
+ /**
+ * @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)
+ */
+ public void 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);
+ }
+
+ protected void setUp() {
+ }
+
+ protected void tearDown() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatFieldTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatFieldTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatFieldTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatFieldTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,197 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.text;
+
+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;
+
+public class DateFormatFieldTest extends junit.framework.TestCase {
+
+ static class MyField extends DateFormat.Field {
+ 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)
+ */
+ 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)
+ */
+ 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()
+ */
+ 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)
+ */
+ 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()
+ */
+ 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, field2;
+
+ // 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 {
+ field2 = (MyField) 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) {
+ }
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatSymbolsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatSymbolsTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatSymbolsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatSymbolsTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,340 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.DateFormatSymbols;
+import java.util.Arrays;
+import java.util.Locale;
+
+public class DateFormatSymbolsTest extends junit.framework.TestCase {
+
+ private DateFormatSymbols dfs;
+
+ /**
+ * @tests java.text.DateFormatSymbols#DateFormatSymbols()
+ */
+ public void test_Constructor() {
+ // Test for method java.text.DateFormatSymbols()
+ // Used in tests
+ try {
+ new DateFormatSymbols();
+ } catch (Exception e) {
+ fail("Constructor failed.");
+ }
+ }
+
+ /**
+ * @tests java.text.DateFormatSymbols#DateFormatSymbols(java.util.Locale)
+ */
+ public void test_ConstructorLjava_util_Locale() {
+ // Test for method java.text.DateFormatSymbols(java.util.Locale)
+ try {
+ new DateFormatSymbols(new Locale("en", "us"));
+ } catch (Exception e) {
+ fail("Constructor failed.");
+ }
+ }
+
+ /**
+ * @tests java.text.DateFormatSymbols#clone()
+ */
+ 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)
+ */
+ 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()
+ */
+ 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()
+ */
+ 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()
+ */
+ public void test_getLocalPatternChars() {
+ // Test for method java.lang.String
+ // java.text.DateFormatSymbols.getLocalPatternChars()
+ String retVal = dfs.getLocalPatternChars();
+
+ String val = "GyMdkHmsSEDFwWahKzZ";
+
+ assertTrue("Returned incorrect pattern string", retVal.equals(val));
+ }
+
+ /**
+ * @tests java.text.DateFormatSymbols#getMonths()
+ */
+ 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", "" };
+ if (retVal.length != val.length)
+ fail("Returned wrong array: " + 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()
+ */
+ 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", "" };
+ 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#getShortWeekdays()
+ */
+ 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()
+ */
+ 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()
+ */
+ 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()
+ */
+ public void test_hashCode() {
+ // Test for method int java.text.DateFormatSymbols.hashCode()
+ int hc1 = hashCode();
+ int hc2 = hashCode();
+ assertTrue("hashCode() returned negative number", hc1 >= 0);
+ assertTrue("hashCode() returned inconsistent number", hc1 == hc2);
+ }
+
+ /**
+ * @tests java.text.DateFormatSymbols#setAmPmStrings(java.lang.String[])
+ */
+ 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[])
+ */
+ 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)
+ */
+ 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));
+ }
+
+ /**
+ * @tests java.text.DateFormatSymbols#setMonths(java.lang.String[])
+ */
+ 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[])
+ */
+ 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[])
+ */
+ 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[])
+ */
+ 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[][])
+ */
+ 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() {
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/tests/api/java/text/DateFormatTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,398 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.text;
+
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+public class DateFormatTest extends junit.framework.TestCase {
+
+ /**
+ * @tests java.text.DateFormat#clone()
+ */
+ 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()
+ */
+ 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);
+ }
+ assertTrue("Missing locales", english && german);
+ }
+
+ /**
+ * @tests java.text.DateFormat#getCalendar()
+ */
+ 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()
+ */
+ 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)
+ */
+ 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);
+ }
+
+ /**
+ * @tests java.text.DateFormat#getDateInstance(int, java.util.Locale)
+ */
+ 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);
+ }
+
+ /**
+ * @tests java.text.DateFormat#getDateTimeInstance()
+ */
+ 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)
+ */
+ 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);
+ }
+
+ 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)
+ */
+ 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);
+ }
+
+ /**
+ * @tests java.text.DateFormat#getInstance()
+ */
+ 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()
+ */
+ 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()
+ */
+ 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)
+ */
+ 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);
+ }
+
+ /**
+ * @tests java.text.DateFormat#getTimeInstance(int, java.util.Locale)
+ */
+ 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);
+ }
+
+ /**
+ * @tests java.text.DateFormat#setCalendar(java.util.Calendar)
+ */
+ 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)
+ */
+ public void test_setNumberFormatLjava_text_NumberFormat() {
+ DateFormat format = DateFormat.getInstance();
+ NumberFormat f1 = NumberFormat.getInstance();
+ format.setNumberFormat(f1);
+ assertTrue("Not identical NumberFormat", f1 == format.getNumberFormat());
+ }
+}