harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r442965 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset: ./ spi/
Date Wed, 13 Sep 2006 12:43:16 GMT
Author: smishura
Date: Wed Sep 13 05:43:16 2006
New Revision: 442965

URL: http://svn.apache.org/viewvc?view=rev&rev=442965
Log:
Set eol-style=native

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java   (contents, props changed)
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java   (contents, props changed)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java?view=diff&rev=442965&r1=442964&r2=442965
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java Wed Sep 13 05:43:16 2006
@@ -1,231 +1,231 @@
-/* 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.nio_char.tests.java.nio.charset;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderMalfunctionError;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-
-import junit.framework.TestCase;
-
-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 void test_decode() throws CharacterCodingException {
-		// Regression for HARMONY-33
-//		ByteBuffer bb = ByteBuffer.allocate(1);
-//		bb.put(0, (byte) 77);
-//		CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
-//		decoder.onMalformedInput(CodingErrorAction.REPLACE);
-//		decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
-//		decoder.decode(bb);
-
-		// Regression for HARMONY-67
-//		byte[] b = new byte[] { (byte) 1 };
-//		ByteBuffer buf = ByteBuffer.wrap(b);
-//		CharBuffer charbuf = Charset.forName("UTF-16").decode(buf);
-//		assertEquals("Assert 0: charset UTF-16", 1, charbuf.length());
-//
-//		charbuf = Charset.forName("UTF-16BE").decode(buf);
-//		assertEquals("Assert 1: charset UTF-16BE", 0, charbuf.length());
-//
-//		charbuf = Charset.forName("UTF-16LE").decode(buf);
-//		assertEquals("Assert 2: charset UTF16LE", 0, charbuf.length());
-		
-		// Regression for HARMONY-99
-		CharsetDecoder decoder2 = Charset.forName("UTF-16").newDecoder();
-		decoder2.onMalformedInput(CodingErrorAction.REPORT);
-		decoder2.onUnmappableCharacter(CodingErrorAction.REPORT);
-		ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
-		try {
-			decoder2.decode(in);
-			fail("Assert 3: MalformedInputException should have thrown");
-		} catch (MalformedInputException e) {
-			//expected
-		} 
-	}
-	
-    /*
-     * Test malfunction decode(ByteBuffer)
-     */
-    public void test_decodeLjava_nio_ByteBuffer() throws Exception {
-		MockMalfunctionCharset cs1 = new MockMalfunctionCharset(
-				"Harmony-124-1", null); //$NON-NLS-1$
-		try {
-			cs1.newDecoder().onMalformedInput(CodingErrorAction.REPLACE)
-					.onUnmappableCharacter(CodingErrorAction.REPLACE).decode(
-							ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
-			fail("Assert 0: should throw CoderMalfunctionError");  // NON-NLS-1$
-		} catch (CoderMalfunctionError e) {
-			// expected
-		}
-
-		MockMalfunctionCharset cs2 = new MockMalfunctionCharset(
-				"Harmony-124-2", null); //$NON-NLS-1$
-		try {
-			cs2.decode(ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
-			fail("Assert 1: Charset.decode should throw CoderMalfunctionError");  // NON-NLS-1
-		} catch (CoderMalfunctionError e) {
-			// expected
-		}
-	}
-    
-	/*
-	 * Mock charset class with malfunction decode & encode.
-	 */
-	static final class MockMalfunctionCharset extends Charset {
-
-		public MockMalfunctionCharset(String canonicalName, String[] aliases) {
-			super(canonicalName, aliases);
-		}
-
-		public boolean contains(Charset cs) {
-			return false;
-		}
-
-		public CharsetDecoder newDecoder() {
-			return new MockMalfunctionDecoder(this);
-		}
-
-		public CharsetEncoder newEncoder() {
-			return new MockMalfunctionEncoder(this);
-		}
-	}
-
-	/*
-	 * Mock decoder. decodeLoop always throws unexpected exception.
-	 */
-	static class MockMalfunctionDecoder extends java.nio.charset.CharsetDecoder {
-
-		public MockMalfunctionDecoder(Charset cs) {
-			super(cs, 1, 10);
-		}
-
-		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-			throw new BufferOverflowException();
-		}
-	}
-
-	/*
-	 * Mock encoder. encodeLoop always throws unexpected exception.
-	 */
-	static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
-
-		public MockMalfunctionEncoder(Charset cs) {
-			super(cs, 1, 3, new byte[] { (byte) '?' });
-		}
-
-		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
-			throw new BufferOverflowException();
-		}
-	} 
-	
-	/*
-	 * Test the method decode(ByteBuffer) .
-	 */
-	public void testDecodeLjava_nio_ByteBuffer_ReplaceOverflow()
-			throws Exception {
-		String replaceString = "a";
-		Charset cs = Charset.forName("UTF-8");
-		MockMalformedDecoder decoder = new MockMalformedDecoder(cs);
-		decoder.onMalformedInput(CodingErrorAction.REPLACE);
-		decoder.replaceWith(replaceString);
-		CharBuffer out = CharBuffer.allocate(1);
-		// MockMalformedDecoder treats the second byte '0x38' as malformed,
-		// but "out" doesn't have enough space for replace string.
-		ByteBuffer in = ByteBuffer.wrap(new byte[] { 0x45, 0x38, 0x45, 0x45 });
-		CoderResult result = decoder.decode(in, out, false);
-		assertTrue(result.isOverflow());
-
-		// allocate enough space for "out"
-		out = CharBuffer.allocate(10);
-		// replace string should be put into "out" firstly,
-		// and then decode "in".
-		result = decoder.decode(in, out, true);
-		out.flip();
-		assertTrue(result.isUnderflow());
-		// TODO: the following assertion fails on the Reference Impl -- see HARMONY-148
-		assertEquals("abb", out.toString());
-	}
-
-	/*
-	 * Mock decoder. It treats byte whose value is less than "0x40" as
-	 * malformed.
-	 */
-	static class MockMalformedDecoder extends java.nio.charset.CharsetDecoder {
-
-		public MockMalformedDecoder(Charset cs) {
-			super(cs, 1, 10);
-		}
-
-		/*
-		 * It treats byte whose value is less than "0x40" as malformed.
-		 * Otherwise, it's decoded as 'b'.
-		 */
-		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-			while (in.hasRemaining()) {
-				byte b = in.get();
-				if (b < 0x40) {
-					return CoderResult.malformedForLength(1);
-				}
-				if (!out.hasRemaining()) {
-					return CoderResult.OVERFLOW;
-				}
-				out.put((char) 'b');
-			}
-			return CoderResult.UNDERFLOW;
-		}
-	}
-}
+/* 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.nio_char.tests.java.nio.charset;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderMalfunctionError;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.MalformedInputException;
+
+import junit.framework.TestCase;
+
+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 void test_decode() throws CharacterCodingException {
+		// Regression for HARMONY-33
+//		ByteBuffer bb = ByteBuffer.allocate(1);
+//		bb.put(0, (byte) 77);
+//		CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
+//		decoder.onMalformedInput(CodingErrorAction.REPLACE);
+//		decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+//		decoder.decode(bb);
+
+		// Regression for HARMONY-67
+//		byte[] b = new byte[] { (byte) 1 };
+//		ByteBuffer buf = ByteBuffer.wrap(b);
+//		CharBuffer charbuf = Charset.forName("UTF-16").decode(buf);
+//		assertEquals("Assert 0: charset UTF-16", 1, charbuf.length());
+//
+//		charbuf = Charset.forName("UTF-16BE").decode(buf);
+//		assertEquals("Assert 1: charset UTF-16BE", 0, charbuf.length());
+//
+//		charbuf = Charset.forName("UTF-16LE").decode(buf);
+//		assertEquals("Assert 2: charset UTF16LE", 0, charbuf.length());
+		
+		// Regression for HARMONY-99
+		CharsetDecoder decoder2 = Charset.forName("UTF-16").newDecoder();
+		decoder2.onMalformedInput(CodingErrorAction.REPORT);
+		decoder2.onUnmappableCharacter(CodingErrorAction.REPORT);
+		ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
+		try {
+			decoder2.decode(in);
+			fail("Assert 3: MalformedInputException should have thrown");
+		} catch (MalformedInputException e) {
+			//expected
+		} 
+	}
+	
+    /*
+     * Test malfunction decode(ByteBuffer)
+     */
+    public void test_decodeLjava_nio_ByteBuffer() throws Exception {
+		MockMalfunctionCharset cs1 = new MockMalfunctionCharset(
+				"Harmony-124-1", null); //$NON-NLS-1$
+		try {
+			cs1.newDecoder().onMalformedInput(CodingErrorAction.REPLACE)
+					.onUnmappableCharacter(CodingErrorAction.REPLACE).decode(
+							ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
+			fail("Assert 0: should throw CoderMalfunctionError");  // NON-NLS-1$
+		} catch (CoderMalfunctionError e) {
+			// expected
+		}
+
+		MockMalfunctionCharset cs2 = new MockMalfunctionCharset(
+				"Harmony-124-2", null); //$NON-NLS-1$
+		try {
+			cs2.decode(ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
+			fail("Assert 1: Charset.decode should throw CoderMalfunctionError");  // NON-NLS-1
+		} catch (CoderMalfunctionError e) {
+			// expected
+		}
+	}
+    
+	/*
+	 * Mock charset class with malfunction decode & encode.
+	 */
+	static final class MockMalfunctionCharset extends Charset {
+
+		public MockMalfunctionCharset(String canonicalName, String[] aliases) {
+			super(canonicalName, aliases);
+		}
+
+		public boolean contains(Charset cs) {
+			return false;
+		}
+
+		public CharsetDecoder newDecoder() {
+			return new MockMalfunctionDecoder(this);
+		}
+
+		public CharsetEncoder newEncoder() {
+			return new MockMalfunctionEncoder(this);
+		}
+	}
+
+	/*
+	 * Mock decoder. decodeLoop always throws unexpected exception.
+	 */
+	static class MockMalfunctionDecoder extends java.nio.charset.CharsetDecoder {
+
+		public MockMalfunctionDecoder(Charset cs) {
+			super(cs, 1, 10);
+		}
+
+		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+			throw new BufferOverflowException();
+		}
+	}
+
+	/*
+	 * Mock encoder. encodeLoop always throws unexpected exception.
+	 */
+	static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
+
+		public MockMalfunctionEncoder(Charset cs) {
+			super(cs, 1, 3, new byte[] { (byte) '?' });
+		}
+
+		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+			throw new BufferOverflowException();
+		}
+	} 
+	
+	/*
+	 * Test the method decode(ByteBuffer) .
+	 */
+	public void testDecodeLjava_nio_ByteBuffer_ReplaceOverflow()
+			throws Exception {
+		String replaceString = "a";
+		Charset cs = Charset.forName("UTF-8");
+		MockMalformedDecoder decoder = new MockMalformedDecoder(cs);
+		decoder.onMalformedInput(CodingErrorAction.REPLACE);
+		decoder.replaceWith(replaceString);
+		CharBuffer out = CharBuffer.allocate(1);
+		// MockMalformedDecoder treats the second byte '0x38' as malformed,
+		// but "out" doesn't have enough space for replace string.
+		ByteBuffer in = ByteBuffer.wrap(new byte[] { 0x45, 0x38, 0x45, 0x45 });
+		CoderResult result = decoder.decode(in, out, false);
+		assertTrue(result.isOverflow());
+
+		// allocate enough space for "out"
+		out = CharBuffer.allocate(10);
+		// replace string should be put into "out" firstly,
+		// and then decode "in".
+		result = decoder.decode(in, out, true);
+		out.flip();
+		assertTrue(result.isUnderflow());
+		// TODO: the following assertion fails on the Reference Impl -- see HARMONY-148
+		assertEquals("abb", out.toString());
+	}
+
+	/*
+	 * Mock decoder. It treats byte whose value is less than "0x40" as
+	 * malformed.
+	 */
+	static class MockMalformedDecoder extends java.nio.charset.CharsetDecoder {
+
+		public MockMalformedDecoder(Charset cs) {
+			super(cs, 1, 10);
+		}
+
+		/*
+		 * It treats byte whose value is less than "0x40" as malformed.
+		 * Otherwise, it's decoded as 'b'.
+		 */
+		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+			while (in.hasRemaining()) {
+				byte b = in.get();
+				if (b < 0x40) {
+					return CoderResult.malformedForLength(1);
+				}
+				if (!out.hasRemaining()) {
+					return CoderResult.OVERFLOW;
+				}
+				out.put((char) 'b');
+			}
+			return CoderResult.UNDERFLOW;
+		}
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java?view=diff&rev=442965&r1=442964&r2=442965
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java Wed Sep 13 05:43:16 2006
@@ -1,168 +1,168 @@
-/* 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.nio_char.tests.java.nio.charset;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderMalfunctionError;
-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
-		}
-	}
-
-    /**
-     * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
-     *        java.nio.charset.Charset, float, float)
-     */
-    public void test_ConstructorLjava_nio_charset_CharsetNull() {
-        // Regression for HARMONY-491
-        CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null, 1, 1);
-        assertNull(ech.charset());
-    }
-
-    /**
-     * 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;
-		}
-	}
-
-    public static class MockCharsetEncoderForHarmony491 extends CharsetEncoder {
-
-        public MockCharsetEncoderForHarmony491(Charset arg0, float arg1,
-                float arg2) {
-            super(arg0, arg1, arg2);
-        }
-
-        protected CoderResult encodeLoop(CharBuffer arg0, ByteBuffer arg1) {
-            return null;
-        }
-
-        public boolean isLegalReplacement(byte[] arg0) {
-            return true;
-        }
-    }
-
-    /*
-     * Test malfunction encode(CharBuffer)
-     */
-	public void test_EncodeLjava_nio_CharBuffer() throws Exception {
-		MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
-		try {
-			cs.encode(CharBuffer.wrap("AB"));
-			fail("should throw CoderMalfunctionError");// NON-NLS-1$
-		} catch (CoderMalfunctionError e) {
-			// expected
-		}
-	}
-
-	/*
-	 * Mock charset class with malfunction decode & encode.
-	 */
-	static final class MockMalfunctionCharset extends Charset {
-
-		public MockMalfunctionCharset(String canonicalName, String[] aliases) {
-			super(canonicalName, aliases);
-		}
-
-		public boolean contains(Charset cs) {
-			return false;
-		}
-
-		public CharsetDecoder newDecoder() {
-			return Charset.forName("UTF-8").newDecoder();
-		}
-
-		public CharsetEncoder newEncoder() {
-			return new MockMalfunctionEncoder(this);
-		}
-	}
-
-	/*
-	 * Mock encoder. encodeLoop always throws unexpected exception.
-	 */
-	static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
-
-		public MockMalfunctionEncoder(Charset cs) {
-			super(cs, 1, 3, new byte[] { (byte) '?' });
-		}
-
-		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
-			throw new BufferOverflowException();
-		}
-	}
-
-	/*
-	 * Test reserve bytes encode(CharBuffer,ByteBuffer,boolean)
-	 */
-	public void test_EncodeLjava_nio_CharBufferLjava_nio_ByteBufferB() {
-		CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
-		CharBuffer in1 = CharBuffer.wrap("\ud800");
-		CharBuffer in2 = CharBuffer.wrap("\udc00");
-		ByteBuffer out = ByteBuffer.allocate(4);
-		encoder.reset();
-		CoderResult result = encoder.encode(in1, out, false);
-		assertEquals(4, out.remaining());
-		assertTrue(result.isUnderflow());
-		result = encoder.encode(in2, out, true);
-		assertEquals(0, out.remaining());
-		assertTrue(result.isUnderflow());
-	}
-}
+/* 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.nio_char.tests.java.nio.charset;
+
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderMalfunctionError;
+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
+		}
+	}
+
+    /**
+     * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
+     *        java.nio.charset.Charset, float, float)
+     */
+    public void test_ConstructorLjava_nio_charset_CharsetNull() {
+        // Regression for HARMONY-491
+        CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null, 1, 1);
+        assertNull(ech.charset());
+    }
+
+    /**
+     * 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;
+		}
+	}
+
+    public static class MockCharsetEncoderForHarmony491 extends CharsetEncoder {
+
+        public MockCharsetEncoderForHarmony491(Charset arg0, float arg1,
+                float arg2) {
+            super(arg0, arg1, arg2);
+        }
+
+        protected CoderResult encodeLoop(CharBuffer arg0, ByteBuffer arg1) {
+            return null;
+        }
+
+        public boolean isLegalReplacement(byte[] arg0) {
+            return true;
+        }
+    }
+
+    /*
+     * Test malfunction encode(CharBuffer)
+     */
+	public void test_EncodeLjava_nio_CharBuffer() throws Exception {
+		MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
+		try {
+			cs.encode(CharBuffer.wrap("AB"));
+			fail("should throw CoderMalfunctionError");// NON-NLS-1$
+		} catch (CoderMalfunctionError e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Mock charset class with malfunction decode & encode.
+	 */
+	static final class MockMalfunctionCharset extends Charset {
+
+		public MockMalfunctionCharset(String canonicalName, String[] aliases) {
+			super(canonicalName, aliases);
+		}
+
+		public boolean contains(Charset cs) {
+			return false;
+		}
+
+		public CharsetDecoder newDecoder() {
+			return Charset.forName("UTF-8").newDecoder();
+		}
+
+		public CharsetEncoder newEncoder() {
+			return new MockMalfunctionEncoder(this);
+		}
+	}
+
+	/*
+	 * Mock encoder. encodeLoop always throws unexpected exception.
+	 */
+	static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
+
+		public MockMalfunctionEncoder(Charset cs) {
+			super(cs, 1, 3, new byte[] { (byte) '?' });
+		}
+
+		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+			throw new BufferOverflowException();
+		}
+	}
+
+	/*
+	 * Test reserve bytes encode(CharBuffer,ByteBuffer,boolean)
+	 */
+	public void test_EncodeLjava_nio_CharBufferLjava_nio_ByteBufferB() {
+		CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
+		CharBuffer in1 = CharBuffer.wrap("\ud800");
+		CharBuffer in2 = CharBuffer.wrap("\udc00");
+		ByteBuffer out = ByteBuffer.allocate(4);
+		encoder.reset();
+		CoderResult result = encoder.encode(in1, out, false);
+		assertEquals(4, out.remaining());
+		assertTrue(result.isUnderflow());
+		result = encoder.encode(in2, out, true);
+		assertEquals(0, out.remaining());
+		assertTrue(result.isUnderflow());
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java?view=diff&rev=442965&r1=442964&r2=442965
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java Wed Sep 13 05:43:16 2006
@@ -1,296 +1,296 @@
-/* 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.nio_char.tests.java.nio.charset;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.IllegalCharsetNameException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-public class CharsetTest extends TestCase {
-
-	// Will contain names of charsets registered with IANA
-	Set knownRegisteredCharsets = new HashSet();
-
-	// Will contain names of charsets not known to be registered with IANA
-	Set unknownRegisteredCharsets = new HashSet();
-
-	/**
-	 * JUnit set-up method
-	 */
-	public void setUp() {
-		// Populate the known charset vars
-		Set names = Charset.availableCharsets().keySet();
-		for (Iterator nameItr = names.iterator(); nameItr.hasNext();) {
-			String name = (String) nameItr.next();
-			if (name.toLowerCase().startsWith("x-"))
-				unknownRegisteredCharsets.add(name);
-			else
-				knownRegisteredCharsets.add(name);
-		}
-	}
-
-	/**
-	 * @tests java.nio.charset.Charset#isRegistered()
-	 */
-	public void test_isRegistered() {
-		// Regression for HARMONY-45
-		for (Iterator nameItr = knownRegisteredCharsets.iterator(); nameItr.hasNext();) {
-			String name = (String) nameItr.next();
-			assertTrue("Assert 0: isRegistered() failed for " + name,
-					Charset.forName(name).isRegistered());
-		}
-		for (Iterator nameItr = unknownRegisteredCharsets.iterator(); nameItr.hasNext();) {
-			String name = (String) nameItr.next();
-			assertFalse("Assert 0: isRegistered() failed for " + name,
-					Charset.forName(name).isRegistered());
-		}
-	}
-	
-	/**
-	 * @tests java.nio.charset.Charset#isSupported(String)
-	 */
-	public void testIsSupported_EmptyString() {
-		// Regression for HARMONY-113
-		try {
-			Charset.isSupported("");
-			fail("Assert 0: Should throw IllegalCharsetNameException");
-		} catch (IllegalCharsetNameException e) {
-			// Expected
-		}
-	}
-	
-    /**
-	 * @tests java.nio.charset.Charset#defaultCharset()
-	 */
-	public void test_defaultCharset() {
-		String charsetName = null;
-		String defaultCharsetName = null;
-		Properties oldProps = (Properties) System.getProperties().clone();
-		try {
-			// Normal behavior
-			charsetName = "UTF-8"; //$NON-NLS-1$
-			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
-			defaultCharsetName = Charset.defaultCharset().name();
-			assertEquals(charsetName, defaultCharsetName);
-
-			charsetName = "ISO-8859-1"; //$NON-NLS-1$
-			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
-			defaultCharsetName = Charset.defaultCharset().name();
-			assertEquals(charsetName, defaultCharsetName);
-
-			System.setProperties(oldProps);
-
-			// Unsupported behavior
-			charsetName = "IMPOSSIBLE-8"; //$NON-NLS-1$
-			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
-			defaultCharsetName = Charset.defaultCharset().name();
-			assertEquals("UTF-8", defaultCharsetName);
-
-			System.setProperties(oldProps);
-
-			// Null behavior
-			try {
-				Properties currentProps = System.getProperties();
-				currentProps.remove("file.encoding");//$NON-NLS-1$
-				Charset.defaultCharset().name();
-				fail("Should throw illegal IllegalArgumentException");//$NON-NLS-1$
-			} catch (IllegalArgumentException e) {
-				// expected
-			}
-			System.setProperties(oldProps);
-
-			// IllegalCharsetName behavior
-			try {
-				charsetName = "IMP~~OSSIBLE-8"; //$NON-NLS-1$
-				System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
-				Charset.defaultCharset().name();
-				fail("Should throw IllegalCharsetNameException");//$NON-NLS-1$
-			} catch (IllegalCharsetNameException e) {
-				// expected
-			}
-		} finally {
-			System.setProperties(oldProps);
-		}
-	}
-	
-    /**
-	 * @tests java.nio.charset.Charset#forName(java.lang.String)
-	 */
-	public void test_forNameLjava_lang_String() {
-		/*
-		 * invoke forName two times with the same canonical name, it
-		 * should return the same reference.
-		 */
-		Charset cs1 = Charset.forName("UTF-8");
-		Charset cs2 = Charset.forName("UTF-8");
-		assertSame(cs1, cs2);
-
-		/*
-		 * test forName: invoke forName two times for the same Charset using
-		 * canonical name and alias, it should return the same reference.
-		 */
-		Charset cs3 = Charset.forName("ASCII");
-		Charset cs4 = Charset.forName("US-ASCII");
-		assertSame(cs3, cs4);
-	}
-	
-	/*
-     * test cached decoder
-     */
-    public void test_DecodeLjava_nio_ByteBuffer() throws Exception{
-            MockCharsetForDecoder cs1 = new MockCharsetForDecoder("CachedCharset",null);
-            MockCharsetForDecoder cs2 = new MockCharsetForDecoder("CachedCharset",null);
-            ByteBuffer in = ByteBuffer.wrap(new byte[]{0x00});
-            cs1.decode(in);
-            in.flip();
-            cs2.decode(in);
-            in.flip();
-    }
-    /*
-     * Mock Charset for cached decoder test
-     */
-    static class MockCharsetForDecoder extends Charset{
-
-            public MockCharsetForDecoder(String canonicalName, String[] aliases){
-                    super(canonicalName, aliases);
-            }
-
-            public boolean contains(Charset charset) {
-                    return false;
-            }
-
-            public CharsetEncoder newEncoder() {
-                    return null;
-            }
-
-            public CharsetDecoder newDecoder() {
-                    return new MockCachedDecoder(this);
-            }
-
-
-    }
-    /*
-     * Mock decoder. Only one caller is permitted.
-     */
-    static class MockCachedDecoder extends CharsetDecoder {
-            static MockCachedDecoder caller = null;
-
-            public MockCachedDecoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            /*
-             * Only one caller is permitted.
-             * If there's another caller, throw RuntimeException.
-             */
-            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-                    if(null == caller){
-                            caller = this;
-                    }else{
-                            if(caller != this){
-                                // Another instance
-                            	fail("should use the same instance");
-                            }
-                    }
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
-    /*
-     * test cached encoder
-     */
-    public void test_EncodeLjava_nio_CharBuffer() throws Exception {
-            MockCharsetForEncoder cs1 = new MockCharsetForEncoder("CachedCharset", null);
-            MockCharsetForEncoder cs2 = new MockCharsetForEncoder("CachedCharset", null);
-            CharBuffer in = CharBuffer.wrap("A");
-            cs1.encode(in);
-            in.flip();
-            cs2.encode(in);
-    }
-
-    /*
-     * Mock Charset for cached encoder test
-     */
-    static class MockCharsetForEncoder extends Charset {
-
-            public MockCharsetForEncoder(String canonicalName, String[] aliases) {
-                    super(canonicalName, aliases);
-            }
-
-            public boolean contains(Charset charset) {
-                    return false;
-            }
-
-            public CharsetDecoder newDecoder() {
-                    return new MockDecoderForEncoder(this);
-            }
-
-            public CharsetEncoder newEncoder() {
-                    return new MockCachedEncoder(this);
-            }
-    }
-
-    /*
-     * Mock encoder. Only one caller is permitted.
-     */
-    static class MockCachedEncoder extends CharsetEncoder {
-            static MockCachedEncoder caller = null;
-
-            public MockCachedEncoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            /*
-             * Only one caller is permitted.
-             */
-            protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
-                    if (null == caller) {
-                            caller = this;
-                    } else {
-                            if (caller != this) {
-                                    // Another instance
-                                    fail("should use the same instance");
-                            }
-                    }
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
-    /*
-     * Mock decoder for MockCachedEncoder.
-     */
-    static class MockDecoderForEncoder extends CharsetDecoder {
-            public MockDecoderForEncoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-                    in.position(in.limit());
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
-}
+/* 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.nio_char.tests.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.IllegalCharsetNameException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class CharsetTest extends TestCase {
+
+	// Will contain names of charsets registered with IANA
+	Set knownRegisteredCharsets = new HashSet();
+
+	// Will contain names of charsets not known to be registered with IANA
+	Set unknownRegisteredCharsets = new HashSet();
+
+	/**
+	 * JUnit set-up method
+	 */
+	public void setUp() {
+		// Populate the known charset vars
+		Set names = Charset.availableCharsets().keySet();
+		for (Iterator nameItr = names.iterator(); nameItr.hasNext();) {
+			String name = (String) nameItr.next();
+			if (name.toLowerCase().startsWith("x-"))
+				unknownRegisteredCharsets.add(name);
+			else
+				knownRegisteredCharsets.add(name);
+		}
+	}
+
+	/**
+	 * @tests java.nio.charset.Charset#isRegistered()
+	 */
+	public void test_isRegistered() {
+		// Regression for HARMONY-45
+		for (Iterator nameItr = knownRegisteredCharsets.iterator(); nameItr.hasNext();) {
+			String name = (String) nameItr.next();
+			assertTrue("Assert 0: isRegistered() failed for " + name,
+					Charset.forName(name).isRegistered());
+		}
+		for (Iterator nameItr = unknownRegisteredCharsets.iterator(); nameItr.hasNext();) {
+			String name = (String) nameItr.next();
+			assertFalse("Assert 0: isRegistered() failed for " + name,
+					Charset.forName(name).isRegistered());
+		}
+	}
+	
+	/**
+	 * @tests java.nio.charset.Charset#isSupported(String)
+	 */
+	public void testIsSupported_EmptyString() {
+		// Regression for HARMONY-113
+		try {
+			Charset.isSupported("");
+			fail("Assert 0: Should throw IllegalCharsetNameException");
+		} catch (IllegalCharsetNameException e) {
+			// Expected
+		}
+	}
+	
+    /**
+	 * @tests java.nio.charset.Charset#defaultCharset()
+	 */
+	public void test_defaultCharset() {
+		String charsetName = null;
+		String defaultCharsetName = null;
+		Properties oldProps = (Properties) System.getProperties().clone();
+		try {
+			// Normal behavior
+			charsetName = "UTF-8"; //$NON-NLS-1$
+			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
+			defaultCharsetName = Charset.defaultCharset().name();
+			assertEquals(charsetName, defaultCharsetName);
+
+			charsetName = "ISO-8859-1"; //$NON-NLS-1$
+			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
+			defaultCharsetName = Charset.defaultCharset().name();
+			assertEquals(charsetName, defaultCharsetName);
+
+			System.setProperties(oldProps);
+
+			// Unsupported behavior
+			charsetName = "IMPOSSIBLE-8"; //$NON-NLS-1$
+			System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
+			defaultCharsetName = Charset.defaultCharset().name();
+			assertEquals("UTF-8", defaultCharsetName);
+
+			System.setProperties(oldProps);
+
+			// Null behavior
+			try {
+				Properties currentProps = System.getProperties();
+				currentProps.remove("file.encoding");//$NON-NLS-1$
+				Charset.defaultCharset().name();
+				fail("Should throw illegal IllegalArgumentException");//$NON-NLS-1$
+			} catch (IllegalArgumentException e) {
+				// expected
+			}
+			System.setProperties(oldProps);
+
+			// IllegalCharsetName behavior
+			try {
+				charsetName = "IMP~~OSSIBLE-8"; //$NON-NLS-1$
+				System.setProperty("file.encoding", charsetName);//$NON-NLS-1$
+				Charset.defaultCharset().name();
+				fail("Should throw IllegalCharsetNameException");//$NON-NLS-1$
+			} catch (IllegalCharsetNameException e) {
+				// expected
+			}
+		} finally {
+			System.setProperties(oldProps);
+		}
+	}
+	
+    /**
+	 * @tests java.nio.charset.Charset#forName(java.lang.String)
+	 */
+	public void test_forNameLjava_lang_String() {
+		/*
+		 * invoke forName two times with the same canonical name, it
+		 * should return the same reference.
+		 */
+		Charset cs1 = Charset.forName("UTF-8");
+		Charset cs2 = Charset.forName("UTF-8");
+		assertSame(cs1, cs2);
+
+		/*
+		 * test forName: invoke forName two times for the same Charset using
+		 * canonical name and alias, it should return the same reference.
+		 */
+		Charset cs3 = Charset.forName("ASCII");
+		Charset cs4 = Charset.forName("US-ASCII");
+		assertSame(cs3, cs4);
+	}
+	
+	/*
+     * test cached decoder
+     */
+    public void test_DecodeLjava_nio_ByteBuffer() throws Exception{
+            MockCharsetForDecoder cs1 = new MockCharsetForDecoder("CachedCharset",null);
+            MockCharsetForDecoder cs2 = new MockCharsetForDecoder("CachedCharset",null);
+            ByteBuffer in = ByteBuffer.wrap(new byte[]{0x00});
+            cs1.decode(in);
+            in.flip();
+            cs2.decode(in);
+            in.flip();
+    }
+    /*
+     * Mock Charset for cached decoder test
+     */
+    static class MockCharsetForDecoder extends Charset{
+
+            public MockCharsetForDecoder(String canonicalName, String[] aliases){
+                    super(canonicalName, aliases);
+            }
+
+            public boolean contains(Charset charset) {
+                    return false;
+            }
+
+            public CharsetEncoder newEncoder() {
+                    return null;
+            }
+
+            public CharsetDecoder newDecoder() {
+                    return new MockCachedDecoder(this);
+            }
+
+
+    }
+    /*
+     * Mock decoder. Only one caller is permitted.
+     */
+    static class MockCachedDecoder extends CharsetDecoder {
+            static MockCachedDecoder caller = null;
+
+            public MockCachedDecoder(Charset cs) {
+                    super(cs, 1, 10);
+            }
+
+            /*
+             * Only one caller is permitted.
+             * If there's another caller, throw RuntimeException.
+             */
+            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+                    if(null == caller){
+                            caller = this;
+                    }else{
+                            if(caller != this){
+                                // Another instance
+                            	fail("should use the same instance");
+                            }
+                    }
+                    return CoderResult.UNDERFLOW;
+            }
+    }
+
+    /*
+     * test cached encoder
+     */
+    public void test_EncodeLjava_nio_CharBuffer() throws Exception {
+            MockCharsetForEncoder cs1 = new MockCharsetForEncoder("CachedCharset", null);
+            MockCharsetForEncoder cs2 = new MockCharsetForEncoder("CachedCharset", null);
+            CharBuffer in = CharBuffer.wrap("A");
+            cs1.encode(in);
+            in.flip();
+            cs2.encode(in);
+    }
+
+    /*
+     * Mock Charset for cached encoder test
+     */
+    static class MockCharsetForEncoder extends Charset {
+
+            public MockCharsetForEncoder(String canonicalName, String[] aliases) {
+                    super(canonicalName, aliases);
+            }
+
+            public boolean contains(Charset charset) {
+                    return false;
+            }
+
+            public CharsetDecoder newDecoder() {
+                    return new MockDecoderForEncoder(this);
+            }
+
+            public CharsetEncoder newEncoder() {
+                    return new MockCachedEncoder(this);
+            }
+    }
+
+    /*
+     * Mock encoder. Only one caller is permitted.
+     */
+    static class MockCachedEncoder extends CharsetEncoder {
+            static MockCachedEncoder caller = null;
+
+            public MockCachedEncoder(Charset cs) {
+                    super(cs, 1, 10);
+            }
+
+            /*
+             * Only one caller is permitted.
+             */
+            protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+                    if (null == caller) {
+                            caller = this;
+                    } else {
+                            if (caller != this) {
+                                    // Another instance
+                                    fail("should use the same instance");
+                            }
+                    }
+                    return CoderResult.UNDERFLOW;
+            }
+    }
+
+    /*
+     * Mock decoder for MockCachedEncoder.
+     */
+    static class MockDecoderForEncoder extends CharsetDecoder {
+            public MockDecoderForEncoder(Charset cs) {
+                    super(cs, 1, 10);
+            }
+
+            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+                    in.position(in.limit());
+                    return CoderResult.UNDERFLOW;
+            }
+    }
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java?view=diff&rev=442965&r1=442964&r2=442965
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java Wed Sep 13 05:43:16 2006
@@ -1,35 +1,35 @@
-/* Copyright 2004 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.nio_char.tests.java.nio.charset.spi;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
-
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(AllTests.suite());
-	}
-
-	public static Test suite() {
-		TestSuite suite = new TestSuite(
-				"Suite of tests for the java.nio.charset.spi package.");
-		// $JUnit-BEGIN$
-		suite.addTestSuite(CharsetProviderTest.class);
-		// $JUnit-END$
-		return suite;
-	}
-}
+/* Copyright 2004 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.nio_char.tests.java.nio.charset.spi;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AllTests.suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(
+				"Suite of tests for the java.nio.charset.spi package.");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(CharsetProviderTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java?view=diff&rev=442965&r1=442964&r2=442965
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java Wed Sep 13 05:43:16 2006
@@ -1,93 +1,93 @@
-/* Copyright 2004 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.nio_char.tests.java.nio.charset.spi;
-
-import java.nio.charset.Charset;
-import java.nio.charset.spi.CharsetProvider;
-import java.security.Permission;
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-/**
- * Test class java.nio.charset.spi.CharsetProvider.
- */
-public class CharsetProviderTest extends TestCase {
-
-	/*
-	 * Test the security check in the constructor.
-	 */
-	public void testConstructor() {
-		// with sufficient privilege
-		new MockCharsetProvider();
-
-		SecurityManager oldMan = System.getSecurityManager();
-		System.setSecurityManager(new MockSecurityManager());
-		// set a normal value
-		try {
-			new MockCharsetProvider();
-			fail("Should throw SecurityException!");
-		} catch (SecurityException e) {
-			// expected
-		} finally {
-			System.setSecurityManager(oldMan);
-		}
-	}
-
-	/*
-	 * Test the signature.
-	 */
-	static class MockCharsetProvider extends CharsetProvider {
-
-		public Charset charsetForName(String charsetName) {
-			return null;
-		}
-
-		public Iterator charsets() {
-			return null;
-		}
-	}
-
-	/*
-	 * Used to grant all permissions except charset provider access.
-	 */
-	public static class MockSecurityManager extends SecurityManager {
-
-		public MockSecurityManager() {
-		}
-
-		public void checkPermission(Permission perm) {
-			// grant all permissions except logging control
-			if (perm instanceof RuntimePermission) {
-				RuntimePermission rp = (RuntimePermission) perm;
-				if (rp.getName().equals("charsetProvider")) {
-					throw new SecurityException();
-				}
-			}
-		}
-
-		public void checkPermission(Permission perm, Object context) {
-			// grant all permissions except logging control
-			if (perm instanceof RuntimePermission) {
-				RuntimePermission rp = (RuntimePermission) perm;
-				if (rp.getName().equals("charsetProvider")) {
-					throw new SecurityException();
-				}
-			}
-		}
-	}
-
-}
+/* Copyright 2004 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.nio_char.tests.java.nio.charset.spi;
+
+import java.nio.charset.Charset;
+import java.nio.charset.spi.CharsetProvider;
+import java.security.Permission;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.nio.charset.spi.CharsetProvider.
+ */
+public class CharsetProviderTest extends TestCase {
+
+	/*
+	 * Test the security check in the constructor.
+	 */
+	public void testConstructor() {
+		// with sufficient privilege
+		new MockCharsetProvider();
+
+		SecurityManager oldMan = System.getSecurityManager();
+		System.setSecurityManager(new MockSecurityManager());
+		// set a normal value
+		try {
+			new MockCharsetProvider();
+			fail("Should throw SecurityException!");
+		} catch (SecurityException e) {
+			// expected
+		} finally {
+			System.setSecurityManager(oldMan);
+		}
+	}
+
+	/*
+	 * Test the signature.
+	 */
+	static class MockCharsetProvider extends CharsetProvider {
+
+		public Charset charsetForName(String charsetName) {
+			return null;
+		}
+
+		public Iterator charsets() {
+			return null;
+		}
+	}
+
+	/*
+	 * Used to grant all permissions except charset provider access.
+	 */
+	public static class MockSecurityManager extends SecurityManager {
+
+		public MockSecurityManager() {
+		}
+
+		public void checkPermission(Permission perm) {
+			// grant all permissions except logging control
+			if (perm instanceof RuntimePermission) {
+				RuntimePermission rp = (RuntimePermission) perm;
+				if (rp.getName().equals("charsetProvider")) {
+					throw new SecurityException();
+				}
+			}
+		}
+
+		public void checkPermission(Permission perm, Object context) {
+			// grant all permissions except logging control
+			if (perm instanceof RuntimePermission) {
+				RuntimePermission rp = (RuntimePermission) perm;
+				if (rp.getName().equals("charsetProvider")) {
+					throw new SecurityException();
+				}
+			}
+		}
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message