harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r396968 [4/5] - in /incubator/harmony/enhanced/classlib/trunk: modules/text/make/common/ modules/text/src/test/java/org/apache/harmony/tests/java/text/ modules/text/src/test/java/org/apache/harmony/tests/text/ modules/text/src/test/java/org...
Date Tue, 25 Apr 2006 20:03:48 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,44 @@
+/* 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 org.apache.harmony.text.tests.java.text;
+
+public class MessageFormatFieldTest extends junit.framework.TestCase {
+	/**
+	 * @tests java.text.MessageFormat$Field#Field(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// protected constructor
+	}
+
+	/**
+	 * @tests java.text.MessageFormat$Field#readResolve()
+	 */
+	public void test_readResolve() {
+		// test for method java.lang.Object readResolve()
+
+		// see serialization stress tests:
+		// implemented in
+		// SerializationStressTest4.test_writeObject_MessageFormat_Field()
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+	protected void doneSuite() {
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,754 @@
+/* Copyright 2006 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 org.apache.harmony.text.tests.java.text;
+
+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.DecimalFormat;
+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 tests.support.Support_MessageFormat;
+
+import junit.framework.TestCase;
+
+public class MessageFormatTest extends TestCase {
+
+    private MessageFormat format1, format2, format3;
+
+    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)
+     */
+    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)
+     */
+    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();
+        assertTrue("null formats", formats != null);
+        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")));
+        assertTrue("Wrong string format", formats[4] == null);
+
+        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()));
+
+        assertTrue("Simple string", new MessageFormat("Test message").format(
+                new Object[0]).equals("Test message"));
+
+        try {
+            result = new MessageFormat("Don't").format(new Object[0]);
+            assertTrue("Should not throw IllegalArgumentException: " + result,
+                    "Dont".equals(result));
+        } catch (Exception e) {
+            fail("Unexpected exception: " + e);
+        }
+
+        MessageFormat format2 = null;
+        try {
+            format2 = new MessageFormat("Invalid {1,foobar} format descriptor!");
+            fail("Expected test_ConstructorLjava_lang_String to throw IAE.");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        } catch (Throwable ex) {
+            fail("Expected test_ConstructorLjava_lang_String to throw IAE, not a "
+                    + ex.getClass().getName());
+        }
+
+        try {
+            format2 = new MessageFormat(
+                    "Invalid {1,date,invalid-spec} format descriptor!");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        } catch (Throwable ex) {
+            fail("Expected test_ConstructorLjava_lang_String to throw IAE, not a "
+                    + ex.getClass().getName());
+        }
+
+        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)
+     */
+    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}");
+        assertTrue("Invalid number", format.format(
+                new Object[] { new Integer(46) }).equals("xx 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");
+        assertTrue("Found formats", format.toPattern().equals("nothing"));
+
+        format.applyPattern("{0}");
+        assertTrue("Wrong format", format.getFormats()[0] == null);
+        assertTrue("Wrong pattern", format.toPattern().equals("{0}"));
+
+        format.applyPattern("{0, \t\u001ftime }");
+        assertTrue("Wrong time format", format.getFormats()[0]
+                .equals(DateFormat.getTimeInstance()));
+        assertTrue("Wrong time pattern", format.toPattern().equals("{0,time}"));
+        format.applyPattern("{0,Time, Short\n}");
+        assertTrue("Wrong short time format", format.getFormats()[0]
+                .equals(DateFormat.getTimeInstance(DateFormat.SHORT)));
+        assertTrue("Wrong short time pattern", format.toPattern().equals(
+                "{0,time,short}"));
+        format.applyPattern("{0,TIME,\nmedium  }");
+        assertTrue("Wrong medium time format", format.getFormats()[0]
+                .equals(DateFormat.getTimeInstance(DateFormat.MEDIUM)));
+        assertTrue("Wrong medium time pattern", format.toPattern().equals(
+                "{0,time}"));
+        format.applyPattern("{0,time,LONG}");
+        assertTrue("Wrong long time format", format.getFormats()[0]
+                .equals(DateFormat.getTimeInstance(DateFormat.LONG)));
+        assertTrue("Wrong long time pattern", format.toPattern().equals(
+                "{0,time,long}"));
+        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)));
+        assertTrue("Wrong full time pattern", format.toPattern().equals(
+                "{0,time,full}"));
+        format.setLocale(Locale.getDefault());
+
+        format.applyPattern("{0, date}");
+        assertTrue("Wrong date format", format.getFormats()[0]
+                .equals(DateFormat.getDateInstance()));
+        assertTrue("Wrong date pattern", format.toPattern().equals("{0,date}"));
+        format.applyPattern("{0, date, short}");
+        assertTrue("Wrong short date format", format.getFormats()[0]
+                .equals(DateFormat.getDateInstance(DateFormat.SHORT)));
+        assertTrue("Wrong short date pattern", format.toPattern().equals(
+                "{0,date,short}"));
+        format.applyPattern("{0, date, medium}");
+        assertTrue("Wrong medium date format", format.getFormats()[0]
+                .equals(DateFormat.getDateInstance(DateFormat.MEDIUM)));
+        assertTrue("Wrong medium date pattern", format.toPattern().equals(
+                "{0,date}"));
+        format.applyPattern("{0, date, long}");
+        assertTrue("Wrong long date format", format.getFormats()[0]
+                .equals(DateFormat.getDateInstance(DateFormat.LONG)));
+        assertTrue("Wrong long date pattern", format.toPattern().equals(
+                "{0,date,long}"));
+        format.applyPattern("{0, date, full}");
+        assertTrue("Wrong full date format", format.getFormats()[0]
+                .equals(DateFormat.getDateInstance(DateFormat.FULL)));
+        assertTrue("Wrong full date pattern", format.toPattern().equals(
+                "{0,date,full}"));
+
+        format.applyPattern("{0, date, MMM d {hh:mm:ss}}");
+        assertTrue("Wrong time/date format", ((SimpleDateFormat) (format
+                .getFormats()[0])).toPattern().equals(" MMM d {hh:mm:ss}"));
+        assertTrue("Wrong time/date pattern", format.toPattern().equals(
+                "{0,date, MMM d {hh:mm:ss}}"));
+
+        format.applyPattern("{0, number}");
+        assertTrue("Wrong number format", format.getFormats()[0]
+                .equals(NumberFormat.getNumberInstance()));
+        assertTrue("Wrong number pattern", format.toPattern().equals(
+                "{0,number}"));
+        format.applyPattern("{0, number, currency}");
+        assertTrue("Wrong currency number format", format.getFormats()[0]
+                .equals(NumberFormat.getCurrencyInstance()));
+        assertTrue("Wrong currency number pattern", format.toPattern().equals(
+                "{0,number,currency}"));
+        format.applyPattern("{0, number, percent}");
+        assertTrue("Wrong percent number format", format.getFormats()[0]
+                .equals(NumberFormat.getPercentInstance()));
+        assertTrue("Wrong percent number pattern", format.toPattern().equals(
+                "{0,number,percent}"));
+        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));
+        assertTrue("Wrong integer number pattern", format.toPattern().equals(
+                "{0,number,integer}"));
+
+        format.applyPattern("{0, number, {'#'}##0.0E0}");
+        assertTrue("Wrong pattern number format", ((DecimalFormat) (format
+                .getFormats()[0])).toPattern().equals("' {#}'##0.0E0"));
+        assertTrue("Wrong pattern number pattern", format.toPattern().equals(
+                "{0,number,' {#}'##0.0E0}"));
+
+        format.applyPattern("{0, choice,0#no|1#one|2#{1,number}}");
+        assertTrue("Wrong choice format",
+                ((ChoiceFormat) format.getFormats()[0]).toPattern().equals(
+                        "0.0#no|1.0#one|2.0#{1,number}"));
+        assertTrue("Wrong choice pattern", format.toPattern().equals(
+                "{0,choice,0.0#no|1.0#one|2.0#{1,number}}"));
+        assertTrue("Wrong formatted choice", format.format(
+                new Object[] { new Integer(2), new Float(3.6) }).equals("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
+        }
+    }
+
+    /**
+     * @tests java.text.MessageFormat#clone()
+     */
+    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));
+        assertTrue("Wrong answer", format.format(new Object[] {}).equals(
+                "{choice}{0}"));
+        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)
+     */
+    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#formatToCharacterIterator(java.lang.Object)
+     */
+    public void test_formatToCharacterIteratorLjava_lang_Object() {
+        // Test for method formatToCharacterIterator(java.lang.Object)
+        new Support_MessageFormat(
+                "test_formatToCharacterIteratorLjava_lang_Object")
+                .t_formatToCharacterIterator();
+    }
+
+    /**
+     * @tests java.text.MessageFormat#format(java.lang.Object[],
+     *        java.lang.StringBuffer, java.text.FieldPosition)
+     */
+    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(0));
+        assertTrue("Wrong result", buffer.toString().equals("54"));
+        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);
+        String result = format.format(new Object[] { new Double(1.6),
+                new Integer(3), date });
+        assertTrue("Choice not recursive:\n" + expected + "\n" + result,
+                expected.equals(result));
+    }
+
+    /**
+     * @tests java.text.MessageFormat#format(java.lang.Object,
+     *        java.lang.StringBuffer, java.text.FieldPosition)
+     */
+    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();
+    }
+
+    /**
+     * @tests java.text.MessageFormat#getFormats()
+     */
+    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()
+     */
+    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#setFormatByArgumentIndex(int,
+     *        java.text.Format)
+     */
+    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#setFormatsByArgumentIndex(java.text.Format[])
+     */
+    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)
+     */
+    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));
+        assertTrue("Wrong variable result", result[0].equals("c"));
+    }
+
+    /**
+     * @tests java.text.MessageFormat#setLocale(java.util.Locale)
+     */
+    public void test_setLocaleLjava_util_Locale() {
+        // Test for method void
+        // java.text.MessageFormat.setLocale(java.util.Locale)
+        MessageFormat format = new MessageFormat("date {0,date}");
+        String pattern = ((SimpleDateFormat) format.getFormats()[0])
+                .toPattern();
+        format.setLocale(Locale.CHINA);
+        assertTrue("Wrong locale1", format.getLocale().equals(Locale.CHINA));
+        assertTrue("Wrong locale2", format.getFormats()[0]
+                .equals(new SimpleDateFormat(pattern, Locale.CHINA)));
+        format.applyPattern("{1,date}");
+        assertTrue("Wrong locale3", format.getFormats()[0].equals(DateFormat
+                .getDateInstance(DateFormat.DEFAULT, Locale.CHINA)));
+    }
+
+    /**
+     * @tests java.text.MessageFormat#toPattern()
+     */
+    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() {
+        // 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() {
+    }
+    
+    
+    
+    
+    
+	/**
+	 * @tests java.text.MessageFormat(java.util.Locale)
+	 */
+	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)
+	 */
+	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]);
+	} 
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,44 @@
+/* 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 org.apache.harmony.text.tests.java.text;
+
+public class NumberFormatFieldTest extends junit.framework.TestCase {
+	/**
+	 * @tests java.text.NumberFormat$Field#Field(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// protected constructor
+	}
+
+	/**
+	 * @tests java.text.NumberFormat$Field#readResolve()
+	 */
+	public void test_readResolve() {
+		// test for method java.lang.Object readResolve()
+
+		// see serialization stress tests:
+		// implemented in
+		// SerializationStressTest4.test_writeObject_NumberFormat_Field()
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+
+	protected void doneSuite() {
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,232 @@
+/* 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 org.apache.harmony.text.tests.java.text;
+
+import java.text.ChoiceFormat;
+import java.text.DecimalFormat;
+import java.text.FieldPosition;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Currency;
+import java.util.Locale;
+
+public class NumberFormatTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.text.NumberFormat#format(java.lang.Object,
+	 *        java.lang.StringBuffer, java.text.FieldPosition)
+	 */
+	public void test_formatLjava_lang_ObjectLjava_lang_StringBufferLjava_text_FieldPosition() {
+		FieldPosition pos;
+		StringBuffer out;
+		DecimalFormat format = (DecimalFormat) NumberFormat
+				.getInstance(Locale.US);
+
+		pos = new FieldPosition(0);
+		out = format.format(new Long(Long.MAX_VALUE), new StringBuffer(), pos);
+		assertTrue("Wrong result L1: " + out, out.toString().equals(
+				"9,223,372,036,854,775,807"));
+
+		pos = new FieldPosition(0);
+		out = format.format(new Long(Long.MIN_VALUE), new StringBuffer(), pos);
+		assertTrue("Wrong result L2: " + out, out.toString().equals(
+				"-9,223,372,036,854,775,808"));
+
+		pos = new FieldPosition(0);
+		out = format.format(new java.math.BigInteger(String
+				.valueOf(Long.MAX_VALUE)), new StringBuffer(), pos);
+		assertTrue("Wrong result BI1: " + out, out.toString().equals(
+				"9,223,372,036,854,775,807"));
+
+		pos = new FieldPosition(0);
+		out = format.format(new java.math.BigInteger(String
+				.valueOf(Long.MIN_VALUE)), new StringBuffer(), pos);
+		assertTrue("Wrong result BI2: " + out, out.toString().equals(
+				"-9,223,372,036,854,775,808"));
+
+		java.math.BigInteger big;
+		pos = new FieldPosition(0);
+		big = new java.math.BigInteger(String.valueOf(Long.MAX_VALUE))
+				.add(new java.math.BigInteger("1"));
+		out = format.format(big, new StringBuffer(), pos);
+		assertTrue("Wrong result BI3: " + out, out.toString().equals(
+				"9,223,372,036,854,776,000"));
+
+		pos = new FieldPosition(0);
+		big = new java.math.BigInteger(String.valueOf(Long.MIN_VALUE))
+				.add(new java.math.BigInteger("-1"));
+		out = format.format(big, new StringBuffer(), pos);
+		assertTrue("Wrong result BI4: " + out, out.toString().equals(
+				"-9,223,372,036,854,776,000"));
+
+		pos = new FieldPosition(0);
+		out = format.format(new java.math.BigDecimal("51.348"),
+				new StringBuffer(), pos);
+		assertTrue("Wrong result BD1: " + out, out.toString().equals("51.348"));
+
+		pos = new FieldPosition(0);
+		out = format.format(new java.math.BigDecimal("51"), new StringBuffer(),
+				pos);
+		assertTrue("Wrong result BD2: " + out, out.toString().equals("51"));
+
+	}
+
+	/**
+	 * @tests java.text.NumberFormat#getIntegerInstance()
+	 */
+	public void test_getIntegerInstance() {
+		// Test for method java.text.NumberFormat getIntegerInstance()
+		Locale origLocale = Locale.getDefault();
+		Locale.setDefault(Locale.US);
+
+		DecimalFormat format = (DecimalFormat) NumberFormat
+				.getIntegerInstance();
+
+		assertEquals(
+				"Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern",
+				"#,##0", format.toPattern());
+		assertEquals(
+				"Test2: NumberFormat.getIntegerInstance().format(35.76) returned wrong value",
+				"36", format.format(35.76));
+		try {
+			assertEquals(
+					"Test3: NumberFormat.getIntegerInstance().parse(\"35.76\") returned wrong number",
+					new Long(35), format.parse("35.76"));
+			assertEquals(
+					"Test4: NumberFormat.getIntegerInstance().parseObject(\"35.76\") returned wrong number",
+					new Long(35), format.parseObject("35.76"));
+		} catch (ParseException e) {
+			fail("Unexpected exception" + e);
+		}
+		Locale.setDefault(origLocale);
+	}
+
+	/**
+	 * @tests java.text.NumberFormat#getIntegerInstance(java.util.Locale)
+	 */
+	public void test_getIntegerInstanceLjava_util_Locale() {
+		// Test for method java.text.NumberFormat
+		// getIntegerInstance(java.util.Locale)
+		Locale usLocale = Locale.US;
+		Locale arLocale = new Locale("ar", "AE");
+
+		DecimalFormat format = (DecimalFormat) NumberFormat
+				.getIntegerInstance(usLocale);
+		assertEquals(
+				"Test1: NumberFormat.getIntegerInstance().toPattern() returned wrong pattern",
+				"#,##0", format.toPattern());
+		assertEquals(
+				"Test2: NumberFormat.getIntegerInstance().format(-35.76) returned wrong value",
+				"-36", format.format(-35.76));
+		try {
+			assertEquals(
+					"Test3: NumberFormat.getIntegerInstance().parse(\"-36\") returned wrong number",
+					new Long(-36), format.parse("-36"));
+			assertEquals(
+					"Test4: NumberFormat.getIntegerInstance().parseObject(\"-36\") returned wrong number",
+					new Long(-36), format.parseObject("-36"));
+		} catch (ParseException e) {
+			fail("Unexpected exception" + e);
+		}
+		assertEquals(
+				"Test5: NumberFormat.getIntegerInstance().getMaximumFractionDigits() returned wrong value",
+				0, format.getMaximumFractionDigits());
+		assertEquals(
+				"Test6: NumberFormat.getIntegerInstance().isParseIntegerOnly() returned wrong value",
+				true, format.isParseIntegerOnly());
+
+		// try with a locale that has a different integer pattern
+		format = (DecimalFormat) NumberFormat.getIntegerInstance(arLocale);
+		assertEquals(
+				"Test7: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).toPattern() returned wrong pattern",
+				"#,##0;#,##0-", format.toPattern());
+		assertEquals(
+				"Test8: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).format(-35.76) returned wrong value",
+				"36-", format.format(-35.76));
+		try {
+			assertEquals(
+					"Test9: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).parse(\"-36-\") returned wrong number",
+					new Long(-36), format.parse("36-"));
+			assertEquals(
+					"Test10: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).parseObject(\"36-\") returned wrong number",
+					new Long(-36), format.parseObject("36-"));
+		} catch (ParseException e) {
+			fail("Unexpected exception" + e);
+		}
+		assertEquals(
+				"Test11: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).getMaximumFractionDigits() returned wrong value",
+				0, format.getMaximumFractionDigits());
+		assertEquals(
+				"Test12: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).isParseIntegerOnly() returned wrong value",
+				true, format.isParseIntegerOnly());
+	}
+
+	/**
+	 * @tests java.text.NumberFormat#getCurrency()
+	 */
+	public void test_getCurrency() {
+		// Test for method java.util.Currency getCurrency()
+
+		// a subclass that supports currency formatting
+		Currency currH = Currency.getInstance("HUF");
+		NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
+		assertTrue("Returned incorrect currency", format.getCurrency() == currH);
+
+		// a subclass that doesn't support currency formatting
+		ChoiceFormat cformat = new ChoiceFormat(
+				"0#Less than one|1#one|1<Between one and two|2<Greater than two");
+		try {
+			((NumberFormat) cformat).getCurrency();
+			fail("Expected UnsupportedOperationException");
+		} catch (UnsupportedOperationException e) {
+		}
+	}
+
+	/**
+	 * @tests java.text.NumberFormat#getMaximumIntegerDigits()
+	 */
+	public void test_getMaximumIntegerDigits() {
+		NumberFormat format = NumberFormat.getInstance();
+		format.setMaximumIntegerDigits(2);
+		assertTrue("Wrong result", format.format(123).equals("23"));
+	}
+
+	/**
+	 * @tests java.text.NumberFormat#setCurrency(java.util.Currency)
+	 */
+	public void test_setCurrencyLjava_util_Currency() {
+		// Test for method void setCurrency(java.util.Currency)
+		// a subclass that supports currency formatting
+		Currency currA = Currency.getInstance("ARS");
+		NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
+		format.setCurrency(currA);
+		assertTrue("Returned incorrect currency", format.getCurrency() == currA);
+
+		// a subclass that doesn't support currency formatting
+		ChoiceFormat cformat = new ChoiceFormat(
+				"0#Less than one|1#one|1<Between one and two|2<Greater than two");
+		try {
+			((NumberFormat) cformat).setCurrency(currA);
+			fail("Expected UnsupportedOperationException");
+		} catch (UnsupportedOperationException e) {
+		}
+	}
+
+	protected void setUp() {
+	}
+
+	protected void tearDown() {
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,64 @@
+/* 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 org.apache.harmony.text.tests.java.text;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+
+public class ParseExceptionTest extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.text.ParseException#ParseException(java.lang.String, int)
+	 */
+	public void test_ConstructorLjava_lang_StringI() {
+		// Test for method java.text.ParseException(java.lang.String, int)
+		// SM
+		try {
+			DateFormat df = DateFormat.getInstance();
+			df.parse("HelloWorld");
+		} catch (ParseException e) {
+			return;
+		}
+		fail("ParseException not created/thrown.");
+	}
+
+	/**
+	 * @tests java.text.ParseException#getErrorOffset()
+	 */
+	public void test_getErrorOffset() {
+		// Test for method int java.text.ParseException.getErrorOffset()
+		// SM
+		try {
+			DateFormat df = DateFormat.getInstance();
+			df.parse("1999HelloWorld");
+		} catch (ParseException e) {
+			assertTrue("getErrorOffsetFailed.", e.getErrorOffset() == 4);
+		}
+	}
+
+	/**
+	 * 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() {
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParseExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,121 @@
+/* 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 org.apache.harmony.text.tests.java.text;
+
+import java.text.ParsePosition;
+
+public class ParsePositionTest extends junit.framework.TestCase {
+
+	ParsePosition pp;
+
+	/**
+	 * @tests java.text.ParsePosition#ParsePosition(int)
+	 */
+	public void test_ConstructorI() {
+		// Test for method java.text.ParsePosition(int)
+		try {
+			ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE);
+			assertTrue("Initialization failed.",
+					pp1.getIndex() == Integer.MIN_VALUE);
+			assertTrue("Initialization failed.", pp1.getErrorIndex() == -1);
+		} catch (Exception e) {
+			fail("Constructor failed.");
+		}
+
+	}
+
+	/**
+	 * @tests java.text.ParsePosition#equals(java.lang.Object)
+	 */
+	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()
+	 */
+	public void test_getErrorIndex() {
+		// Test for method int java.text.ParsePosition.getErrorIndex()
+		pp.setErrorIndex(56);
+		assertTrue("getErrorIndex failed.", pp.getErrorIndex() == 56);
+	}
+
+	/**
+	 * @tests java.text.ParsePosition#getIndex()
+	 */
+	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()
+	 */
+	public void test_hashCode() {
+		// Test for method int java.text.ParsePosition.hashCode()
+		assertTrue("Wrong hashCode returned", (pp.hashCode() == pp.getIndex()
+				+ pp.getErrorIndex()));
+	}
+
+	/**
+	 * @tests java.text.ParsePosition#setErrorIndex(int)
+	 */
+	public void test_setErrorIndexI() {
+		// Test for method void java.text.ParsePosition.setErrorIndex(int)
+		pp.setErrorIndex(4564);
+		assertTrue("setErrorIndex failed.", pp.getErrorIndex() == 4564);
+	}
+
+	/**
+	 * @tests java.text.ParsePosition#setIndex(int)
+	 */
+	public void test_setIndexI() {
+		// Test for method void java.text.ParsePosition.setIndex(int)
+		pp.setIndex(4564);
+		assertTrue("setErrorIndex failed.", pp.getIndex() == 4564);
+	}
+
+	/**
+	 * @tests java.text.ParsePosition#toString()
+	 */
+	public void test_toString() {
+		// Test for method java.lang.String java.text.ParsePosition.toString()
+		assertTrue("toString failed.", pp.toString().equals(
+				"java.text.ParsePosition[index=2147483647, errorIndex=-1]"));
+	}
+
+	/**
+	 * 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() {
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java?rev=396968&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java Tue Apr 25 13:03:30 2006
@@ -0,0 +1,258 @@
+/*
+ * Copyright 2006 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 org.apache.harmony.text.tests.java.text;
+
+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() {
+        {
+            Locale locale = new Locale("es", "", "TRADITIONAL");
+            RuleBasedCollator coll = (RuleBasedCollator) Collator
+                    .getInstance(locale);
+            String source = "cha";
+            CollationElementIterator iterator = coll
+                    .getCollationElementIterator(source);
+            int[] e_offset = { 0, 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);
+            }
+        }
+    }
+
+    /*
+     * Class under test for java.text.CollationElementIterator
+     * getCollationElementIterator(java.text.CharacterIterator)
+     */
+    public void testGetCollationElementIteratorCharacterIterator() {
+        {
+            Locale locale = new Locale("es", "", "TRADITIONAL");
+            RuleBasedCollator coll = (RuleBasedCollator) Collator
+                    .getInstance(locale);
+            String text = "cha";
+            StringCharacterIterator source = new StringCharacterIterator(text);
+            CollationElementIterator iterator = coll
+                    .getCollationElementIterator(source);
+            int[] e_offset = { 0, 2, 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);
+            }
+        }
+    }
+
+    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 coll2 = Collator.getInstance();
+        assertFalse(coll.equals("A", "\uFF21"));
+    }
+
+    public void testGetAvaiableLocales() {
+        // 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);
+        int hashCode = key.hashCode();
+
+        CollationKey key2 = coll.getCollationKey("abc");
+
+        assertEquals(0, key.compareTo(key2));
+        Object key3 = key2;
+        assertEquals(0, key.compareTo(key3));
+        assertTrue(key.equals(key2));
+
+        byte[] bytes = key.toByteArray();
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/RuleBasedCollatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message