harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r411111 - in /incubator/harmony/enhanced/classlib/trunk/modules/text: make/common/build.xml src/main/java/java/text/ChoiceFormat.java src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
Date Fri, 02 Jun 2006 09:55:02 GMT
Author: mloenko
Date: Fri Jun  2 02:55:01 2006
New Revision: 411111

URL: http://svn.apache.org/viewvc?rev=411111&view=rev
Log:
fixes for HARMONY-540
[classlib][text]Method applyPattern(String) of java.text.ChoiceFormat incorrectly throws IllegalArgumentException

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml
    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/text/tests/java/text/ChoiceFormatTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml?rev=411111&r1=411110&r2=411111&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/make/common/build.xml Fri Jun 
2 02:55:01 2006
@@ -100,7 +100,6 @@
 
                 <fileset dir="${hy.text.src.test.java}">
                     <include name="**/*Test.java"/>
-                    <exclude name="org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/CollationKeyTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/CollatorTest.java"/>
                     <exclude name="org/apache/harmony/text/tests/java/text/DecimalFormatTest.java"/>

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/ChoiceFormat.java?rev=411111&r1=411110&r2=411111&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
Fri Jun  2 02:55:01 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 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.
@@ -75,7 +75,6 @@
 	 *                then an error occurs parsing the pattern
 	 */
 	public void applyPattern(String template) {
-		boolean first = true;
 		double[] limits = new double[5];
 		Vector formats = new Vector();
 		int length = template.length(), limitCount = 0, index = 0;
@@ -100,8 +99,12 @@
 			position.setIndex(index);
 			Number value = format.parse(template, position);
 			index = skipWhitespace(template, position.getIndex());
-			if (position.getErrorIndex() != -1 || index >= length)
-				throw new IllegalArgumentException();
+			if (position.getErrorIndex() != -1 || index >= length) {
+                //Fix Harmony 540
+                choiceLimits = new double[0];
+                choiceFormats = new String[0];
+                return;
+            }
 			char ch = template.charAt(index++);
 			if (limitCount == limits.length) {
 				double[] newLimits = new double[limitCount * 2];
@@ -115,14 +118,11 @@
 				next = value.doubleValue();
 				break;
 			case '<':
-				if (first)
-					throw new IllegalArgumentException();
 				next = nextDouble(value.doubleValue());
 				break;
 			default:
 				throw new IllegalArgumentException();
 			}
-			first = false;
 			if (limitCount > 0 && next <= limits[limitCount - 1])
 				throw new IllegalArgumentException();
 			buffer.setLength(0);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java?rev=411111&r1=411110&r2=411111&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/ChoiceFormatTest.java
Fri Jun  2 02:55:01 2006
@@ -142,6 +142,50 @@
                 new double[] { 0, 1 }));
         assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(),
                 new String[] { "0", "1" }));
+        
+        //Regression for Harmony 540
+        double[] choiceLimits = { -1, 0, 1, ChoiceFormat.nextDouble(1) };
+        String[] choiceFormats = { "is negative", "is zero or fraction",
+                "is one", "is more than 1" };
+        
+        f = new ChoiceFormat("");
+        f.applyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1");
+        assertTrue("Incorrect limits", java.util.Arrays.equals(f.getLimits(),
+                choiceLimits));
+        assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(),
+                choiceFormats));
+        
+        f = new ChoiceFormat("");
+        try {
+            f.applyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than
1");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+        
+        f = new ChoiceFormat("");
+        try {
+            f.applyPattern("-1is negative|0#is zero or fraction|1#is one|1<is more than
1");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+        
+        f = new ChoiceFormat("");
+        f.applyPattern("-1<is negative|0#is zero or fraction|1#is one|1<is more than
1");
+        choiceLimits[0] = ChoiceFormat.nextDouble(-1);
+        assertTrue("Incorrect limits", java.util.Arrays.equals(f.getLimits(),
+                choiceLimits));
+        assertTrue("Incorrect formats", java.util.Arrays.equals(f.getFormats(),
+                choiceFormats));
+        
+        f = new ChoiceFormat("");
+        f.applyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1");
+        String str = "org.apache.harmony.tests.java.text.ChoiceFormat";
+        f.applyPattern(str);
+        String ptrn = f.toPattern();
+        assertEquals("Return value should be empty string for invalid pattern",
+                0, ptrn.length());
     }
 
     /**
@@ -351,20 +395,6 @@
         assertTrue("Formats copied", f.getFormats() == fs);
     }
 
-    /**
-     * 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() {
-    }
-    
 	/**
 	 * @tests java.text.ChoiceFormat#toPattern()
 	 */



Mime
View raw message