harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r382380 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src: main/java/java/nio/charset/CharsetDecoder.java test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Date Thu, 02 Mar 2006 13:38:52 GMT
Author: tellison
Date: Thu Mar  2 05:38:50 2006
New Revision: 382380

URL: http://svn.apache.org/viewcvs?rev=382380&view=rev
Log:
Fix for HARMONY-142 (java.nio.charset.CharsetDecoder constructor doesn't throw IllegalArgumentException
when averageCharsPerByte is greater than maxCharsPerByte)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java?rev=382380&r1=382379&r2=382380&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
Thu Mar  2 05:38:50 2006
@@ -156,7 +156,11 @@
 			float maxCharsPerByte) {
 		if (averageCharsPerByte <= 0 || maxCharsPerByte <= 0) {
 			throw new IllegalArgumentException(
-					"Characters number for one byte must be positive."); //$NON-NLS-1$
+					"Characters number for one byte must be positive.");
+		}
+		if(averageCharsPerByte > maxCharsPerByte){
+			throw new IllegalArgumentException(
+					"averageCharsPerByte is greater than maxCharsPerByte");
 		}
 		averChars = averageCharsPerByte;
 		maxChars = maxCharsPerByte;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java?rev=382380&r1=382379&r2=382380&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Thu Mar  2 05:38:50 2006
@@ -31,10 +31,39 @@
 
 public class CharsetDecoderTest extends TestCase {
 
+    /**
+	 * @tests java.nio.charset.CharsetDecoder.CharsetDecoder(Charset, float,
+	 *        float)
+	 */
+	public void test_ConstructorLjava_nio_charset_CharsetFF() {
+		// Regression for HARMONY-142
+		try {
+			Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$
+			new MockCharsetDecoderForHarmony142(cs, 1.1f, 1);
+			fail("Assert 0: Should throw IllegalArgumentException."); //$NON-NLS-1$
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * MockCharsetDecoderForHarmony142: for constructor test
+	 */
+	static class MockCharsetDecoderForHarmony142 extends CharsetDecoder {
+		protected MockCharsetDecoderForHarmony142(Charset cs,
+				float averageBytesPerChar, float maxBytesPerChar) {
+			super(cs, averageBytesPerChar, maxBytesPerChar);
+		}
+
+		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+			return null;
+		}
+	}
+ 
 	/**
 	 * @tests java.nio.charset.CharsetDecoder#decode(java.nio.ByteBuffer)
 	 */
-	public static void test_decode() throws CharacterCodingException {
+	public void test_decode() throws CharacterCodingException {
 		// Regression for HARMONY-33
 //		ByteBuffer bb = ByteBuffer.allocate(1);
 //		bb.put(0, (byte) 77);



Mime
View raw message