harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r375969 - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src: main/java/java/text/ test/java/org/apache/harmony/tests/java/text/
Date Wed, 08 Feb 2006 14:08:20 GMT
Author: tellison
Date: Wed Feb  8 06:08:15 2006
New Revision: 375969

URL: http://svn.apache.org/viewcvs?rev=375969&view=rev
Log:
Fix for HARMONY-59 (java.text.MessageFormat.toPattern() causes IndexOutOfBoundsException in
StringBuffer.setLength method)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/ChoiceFormatTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
    incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java?rev=375969&r1=375968&r2=375969&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
Wed Feb  8 06:08:15 2006
@@ -366,6 +366,8 @@
 	public String toPattern() {
 		StringBuffer buffer = new StringBuffer();
 		for (int i = 0; i < choiceLimits.length; i++) {
+            if (i != 0) //if appending another format add OR symbol first
+                buffer.append('|');
 			String previous = String.valueOf(previousDouble(choiceLimits[i]));
 			String limit = String.valueOf(choiceLimits[i]);
 			if (previous.length() < limit.length()) {
@@ -381,9 +383,7 @@
 			buffer.append(choiceFormats[i]);
 			if (quote)
 				buffer.append('\'');
-			buffer.append('|');
 		}
-		buffer.setLength(buffer.length() - 1);
 		return buffer.toString();
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/AllTests.java?rev=375969&r1=375968&r2=375969&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/AllTests.java
Wed Feb  8 06:08:15 2006
@@ -31,6 +31,8 @@
 		//$JUnit-BEGIN$
 		suite.addTestSuite(RuleBasedCollatorTest.class);
 		suite.addTestSuite(BreakIteratorTest.class);
+		suite.addTestSuite(MessageFormatTest.class);
+		suite.addTestSuite(ChoiceFormatTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/ChoiceFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/ChoiceFormatTest.java?rev=375969&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/ChoiceFormatTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/ChoiceFormatTest.java
Wed Feb  8 06:08:15 2006
@@ -0,0 +1,69 @@
+/* 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.tests.java.text;
+
+import java.text.ChoiceFormat;
+
+import junit.framework.TestCase;
+
+public class ChoiceFormatTest extends TestCase {
+
+	/**
+	 * @tests java.text.ChoiceFormat#toPattern()
+	 */
+	public void test_toPattern() {
+		// Regression for HARMONY-59
+		ChoiceFormat cf = new ChoiceFormat("");
+		assertEquals("", cf.toPattern());
+
+		cf = new ChoiceFormat("-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
+		assertEquals("-1.0#NEGATIVE_ONE|0.0#ZERO|1.0#ONE|1.0<GREATER_THAN_ONE",
+				cf.toPattern());
+	}
+
+	/**
+	 * @tests java.text.ChoiceFormat#format(long)
+	 */
+	public void test_formatL() {
+		ChoiceFormat fmt = new ChoiceFormat(
+				"-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
+
+		assertEquals("NEGATIVE_ONE", fmt.format(Long.MIN_VALUE));
+		assertEquals("NEGATIVE_ONE", fmt.format(-1));
+		assertEquals("ZERO", fmt.format(0));
+		assertEquals("ONE", fmt.format(1));
+		assertEquals("GREATER_THAN_ONE", fmt.format(Long.MAX_VALUE));
+	}
+	
+	/**
+	 * @tests java.text.ChoiceFormat#format(double)
+	 */
+	public void test_formatD() {
+		ChoiceFormat fmt = new ChoiceFormat(
+				"-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");
+		assertEquals("NEGATIVE_ONE", fmt.format(Double.NEGATIVE_INFINITY));
+		assertEquals("NEGATIVE_ONE", fmt.format(-999999999D));
+		assertEquals("NEGATIVE_ONE", fmt.format(-1.1));
+		assertEquals("NEGATIVE_ONE", fmt.format(-1.0));
+		assertEquals("NEGATIVE_ONE", fmt.format(-0.9));
+		assertEquals("ZERO", fmt.format(0.0));
+		assertEquals("ZERO", fmt.format(0.9));
+		assertEquals("ONE", fmt.format(1.0));
+		assertEquals("GREATER_THAN_ONE", fmt.format(1.1));
+		assertEquals("GREATER_THAN_ONE", fmt.format(999999999D));
+		assertEquals("GREATER_THAN_ONE", fmt.format(Double.POSITIVE_INFINITY));
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java?rev=375969&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
Wed Feb  8 06:08:15 2006
@@ -0,0 +1,31 @@
+/* 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.tests.java.text;
+
+import java.text.MessageFormat;
+
+import junit.framework.TestCase;
+
+public class MessageFormatTest extends TestCase {
+
+	/**
+	 * @tests java.textMessageFormat#toPattern()
+	 */
+	public void test_toPattern() {
+		// Regression for HARMONY-59
+		new MessageFormat("CHOICE {1,choice}").toPattern();
+	}
+}



Mime
View raw message