harmony-commits mailing list archives

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

URL: http://svn.apache.org/viewcvs?rev=382383&view=rev
Log:
Fix for HARMONY-141 (Constructors of java.nio.charset.CharsetEncoder do not validate arguments)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java?rev=382383&r1=382382&r2=382383&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
Thu Mar  2 05:55:46 2006
@@ -182,7 +182,11 @@
 			float maxBytesPerChar, byte[] replacement) {
 		if (averageBytesPerChar <= 0 || maxBytesPerChar <= 0) {
 			throw new IllegalArgumentException(
-					"Bytes number for one character must be positive."); //$NON-NLS-1$
+					"Bytes number for one character must be positive.");
+		}
+		if (averageBytesPerChar > maxBytesPerChar) {
+			throw new IllegalArgumentException(
+					"averageBytesPerChar is greater than maxBytesPerChar.");
 		}
 		this.cs = cs;
 		averBytes = averageBytesPerChar;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.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/AllTests.java?rev=382383&r1=382382&r2=382383&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java
Thu Mar  2 05:55:46 2006
@@ -28,6 +28,7 @@
 		TestSuite suite = new TestSuite(
 				"Test for org.apache.harmony.tests.java.nio.charset");
 		//$JUnit-BEGIN$
+		suite.addTestSuite(CharsetEncoderTest.class);
 		suite.addTestSuite(CharsetTest.class);
 		suite.addTestSuite(CharsetDecoderTest.class);
 		//$JUnit-END$

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.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/CharsetEncoderTest.java?rev=382383&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
Thu Mar  2 05:55:46 2006
@@ -0,0 +1,73 @@
+/* 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.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+
+import junit.framework.TestCase;
+
+public class CharsetEncoderTest extends TestCase {
+
+	/**
+	 * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
+	 *        java.nio.charset.Charset, float, float)
+	 */
+	public void test_ConstructorLjava_nio_charset_CharsetFF() {
+		// Regression for HARMONY-141
+		try {
+			Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$
+			new MockCharsetEncoderForHarmony141(cs, 1.1f, 1);
+			fail("Assert 0: Should throw IllegalArgumentException."); //$NON-NLS-1$
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+
+		try {
+			Charset cs = Charset.forName("ISO8859-1"); //$NON-NLS-1$
+			new MockCharsetEncoderForHarmony141(cs, 1.1f, 1,
+					new byte[] { 0x1a });
+			fail("Assert 1: Should throw IllegalArgumentException."); //$NON-NLS-1$
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * Helper for contructor tests
+	 */
+	public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder {
+
+		protected MockCharsetEncoderForHarmony141(Charset cs,
+				float averageBytesPerChar, float maxBytesPerChar) {
+			super(cs, averageBytesPerChar, maxBytesPerChar);
+		}
+
+		public MockCharsetEncoderForHarmony141(Charset cs,
+				float averageBytesPerChar, float maxBytesPerChar,
+				byte[] replacement) {
+			super(cs, averageBytesPerChar, maxBytesPerChar, replacement);
+		}
+
+		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+			return null;
+		}
+
+	}
+}



Mime
View raw message