harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386058 [42/49] - in /incubator/harmony/enhanced/classlib/trunk: make/ modules/archive/make/common/ modules/archive/src/test/java/tests/ modules/archive/src/test/java/tests/api/ modules/archive/src/test/java/tests/api/java/ modules/archive/...
Date Wed, 15 Mar 2006 11:47:39 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,885 @@
+/* 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 tests.api.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.nio.charset.UnsupportedCharsetException;
+import java.nio.charset.spi.CharsetProvider;
+import java.security.Permission;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.nio.Charset.
+ */
+public class CharsetTest extends TestCase {
+
+	static MockCharset charset1 = new MockCharset("mockCharset00",
+			new String[] { "mockCharset01", "mockCharset02" });
+
+	static MockCharset charset2 = new MockCharset("mockCharset10",
+			new String[] { "mockCharset11", "mockCharset12" });
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Test the required 6 charsets are supported.
+	 */
+	public void testRequiredCharsetSupported() {
+		assertTrue(Charset.isSupported("US-ASCII"));
+		assertTrue(Charset.isSupported("ASCII"));
+		assertTrue(Charset.isSupported("ISO-8859-1"));
+		assertTrue(Charset.isSupported("ISO8859_1"));
+		assertTrue(Charset.isSupported("UTF-8"));
+		assertTrue(Charset.isSupported("UTF8"));
+		assertTrue(Charset.isSupported("UTF-16"));
+		assertTrue(Charset.isSupported("UTF-16BE"));
+		assertTrue(Charset.isSupported("UTF-16LE"));
+
+		Charset c1 = Charset.forName("US-ASCII");
+		assertEquals(Charset.forName("US-ASCII").name(), "US-ASCII");
+		assertEquals(Charset.forName("ASCII").name(), "US-ASCII");
+		assertEquals(Charset.forName("ISO-8859-1").name(), "ISO-8859-1");
+		assertEquals(Charset.forName("ISO8859_1").name(), "ISO-8859-1");
+		assertEquals(Charset.forName("UTF-8").name(), "UTF-8");
+		assertEquals(Charset.forName("UTF8").name(), "UTF-8");
+		assertEquals(Charset.forName("UTF-16").name(), "UTF-16");
+		assertEquals(Charset.forName("UTF-16BE").name(), "UTF-16BE");
+		assertEquals(Charset.forName("UTF-16LE").name(), "UTF-16LE");
+
+		assertNotSame(Charset.availableCharsets(), Charset.availableCharsets());
+		// assertSame(Charset.forName("US-ASCII"), Charset.availableCharsets()
+		// .get("US-ASCII"));
+		// assertSame(Charset.forName("US-ASCII"), c1);
+		assertTrue(Charset.availableCharsets().containsKey("US-ASCII"));
+		assertTrue(Charset.availableCharsets().containsKey("ISO-8859-1"));
+		assertTrue(Charset.availableCharsets().containsKey("UTF-8"));
+		assertTrue(Charset.availableCharsets().containsKey("UTF-16"));
+		assertTrue(Charset.availableCharsets().containsKey("UTF-16BE"));
+		assertTrue(Charset.availableCharsets().containsKey("UTF-16LE"));
+	}
+
+	/*
+	 * Test the method isSupported(String) with null.
+	 */
+	public void testIsSupported_Null() {
+		try {
+			Charset.isSupported(null);
+			fail("Should throw IllegalArgumentException!");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method isSupported(String) with empty string.
+	 * 
+	 */
+	public void testIsSupported_EmptyString() {
+		try {
+			Charset.isSupported("");
+		} catch (IllegalArgumentException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the method isSupported(String) with a string starting with ".".
+	 * 
+	 */
+	public void testIsSupported_InvalidInitialCharacter() {
+		try {
+			Charset.isSupported(".char");
+		} catch (IllegalArgumentException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the method isSupported(String) with illegal charset name.
+	 */
+	public void testIsSupported_IllegalName() {
+		try {
+			Charset.isSupported(" ///#$$");
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method isSupported(String) with not supported charset name.
+	 */
+	public void testIsSupported_NotSupported() {
+		assertFalse(Charset.isSupported("impossible"));
+	}
+
+	/*
+	 * Test the method forName(String) with null.
+	 */
+	public void testForName_Null() {
+		try {
+			Charset.forName(null);
+			fail("Should throw IllegalArgumentException!");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method forName(String) with empty string.
+	 */
+	public void testForName_EmptyString() {
+		try {
+			Charset.forName("");
+			fail("Should throw IllegalArgumentException!");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method forName(String) with a string starting with ".".
+	 */
+	public void testForName_InvalidInitialCharacter() {
+		try {
+			Charset.forName(".char");
+			fail("Should throw IllegalArgumentException!");
+		} catch (IllegalArgumentException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method forName(String) with illegal charset name.
+	 */
+	public void testForName_IllegalName() {
+		try {
+			Charset.forName(" ///#$$");
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method forName(String) with not supported charset name.
+	 */
+	public void testForName_NotSupported() {
+		try {
+			Charset.forName("impossible");
+			fail("Should throw UnsupportedCharsetException!");
+		} catch (UnsupportedCharsetException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the constructor with normal parameter values.
+	 */
+	public void testConstructor_Normal() {
+		final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_";
+		MockCharset c = new MockCharset(mockName, new String[] { "mock" });
+		assertEquals(c.name(), mockName);
+		assertEquals(c.displayName(), mockName);
+		assertEquals(c.displayName(Locale.getDefault()), mockName);
+		assertEquals(c.aliases().toArray()[0], "mock");
+		assertEquals(c.aliases().toArray().length, 1);
+	}
+
+	/*
+	 * Test the constructor with empty canonical name.
+	 * 
+	 */
+	public void testConstructor_EmptyCanonicalName() {
+		try {
+			new MockCharset("", new String[0]);
+		} catch (IllegalCharsetNameException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the constructor with illegal canonical name: starting with neither a
+	 * digit nor a letter.
+	 * 
+	 */
+	public void testConstructor_IllegalCanonicalName_Initial() {
+		try {
+			new MockCharset("-123", new String[] { "mock" });
+		} catch (IllegalCharsetNameException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the constructor with illegal canonical name, illegal character in
+	 * the middle.
+	 */
+	public void testConstructor_IllegalCanonicalName_Middle() {
+		try {
+			new MockCharset("1%%23", new String[] { "mock" });
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+		try {
+			new MockCharset("1//23", new String[] { "mock" });
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the constructor with null canonical name.
+	 */
+	public void testConstructor_NullCanonicalName() {
+		try {
+			MockCharset c = new MockCharset(null, new String[] { "mock" });
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the constructor with null aliases.
+	 */
+	public void testConstructor_NullAliases() {
+		MockCharset c = new MockCharset("mockChar", null);
+		assertEquals(c.name(), "mockChar");
+		assertEquals(c.displayName(), "mockChar");
+		assertEquals(c.displayName(Locale.getDefault()), "mockChar");
+		assertEquals(c.aliases().toArray().length, 0);
+	}
+
+	/*
+	 * Test the constructor with a null aliases.
+	 */
+	public void testConstructor_NullAliase() {
+		try {
+			new MockCharset("mockChar", new String[] { "mock", null });
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the constructor with no aliases.
+	 */
+	public void testConstructor_NoAliases() {
+		MockCharset c = new MockCharset("mockChar", new String[0]);
+		assertEquals(c.name(), "mockChar");
+		assertEquals(c.displayName(), "mockChar");
+		assertEquals(c.displayName(Locale.getDefault()), "mockChar");
+		assertEquals(c.aliases().toArray().length, 0);
+	}
+
+	/*
+	 * Test the constructor with empty aliases.
+	 * 
+	 */
+	public void testConstructor_EmptyAliases() {
+		try {
+			new MockCharset("mockChar", new String[] { "" });
+		} catch (IllegalCharsetNameException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the constructor with illegal aliases: starting with neither a digit
+	 * nor a letter.
+	 * 
+	 */
+	public void testConstructor_IllegalAliases_Initial() {
+		try {
+			new MockCharset("mockChar", new String[] { "mock", "-123" });
+		} catch (IllegalCharsetNameException e) {
+			fail("Should not throw IllegalArgumentException!");
+		}
+	}
+
+	/*
+	 * Test the constructor with illegal aliase, illegal character in the
+	 * middle.
+	 */
+	public void testConstructor_IllegalAliases_Middle() {
+		try {
+			new MockCharset("mockChar", new String[] { "mock", "22##ab" });
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+		try {
+			new MockCharset("mockChar", new String[] { "mock", "22%%ab" });
+			fail("Should throw IllegalCharsetNameException!");
+		} catch (IllegalCharsetNameException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method aliases() with multiple aliases. Most conditions have
+	 * been tested in the testcases for the constructors.
+	 */
+	public void testAliases_Multiple() {
+		final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_";
+		MockCharset c = new MockCharset("mockChar", new String[] { "mock",
+				mockName, "mock2" });
+		assertEquals(c.name(), "mockChar");
+		assertEquals(3, c.aliases().size());
+		assertTrue(c.aliases().contains("mock"));
+		assertTrue(c.aliases().contains(mockName));
+		assertTrue(c.aliases().contains("mock2"));
+
+		try {
+			c.aliases().clear();
+			fail("Should throw UnsupportedOperationException!");
+		} catch (UnsupportedOperationException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method aliases() with duplicate aliases, one same with its
+	 * canonical name.
+	 */
+	public void testAliases_Duplicate() {
+		final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_";
+		MockCharset c = new MockCharset("mockChar", new String[] { "mockChar",
+				"mock", mockName, "mock", "mockChar", "mock", "mock2" });
+		assertEquals(c.name(), "mockChar");
+		assertEquals(4, c.aliases().size());
+		assertTrue(c.aliases().contains("mockChar"));
+		assertTrue(c.aliases().contains("mock"));
+		assertTrue(c.aliases().contains(mockName));
+		assertTrue(c.aliases().contains("mock2"));
+	}
+
+	/*
+	 * Test the method canEncode(). Test the default return value.
+	 */
+	public void testCanEncode() {
+		MockCharset c = new MockCharset("mock", null);
+		assertTrue(c.canEncode());
+	}
+
+	/*
+	 * Test the method isRegistered(). Test the default return value.
+	 */
+	public void testIsRegistered() {
+		MockCharset c = new MockCharset("mock", null);
+		assertTrue(c.isRegistered());
+	}
+
+	/*
+	 * The name() method has been tested by the testcases for the constructor.
+	 */
+	public void testName() {
+		// already covered by testConstructor_XXX series
+	}
+
+	/*
+	 * The displayName() method have been tested by the testcases for the
+	 * constructor.
+	 */
+	public void testDisplayName() {
+		// already covered by testConstructor_XXX series
+	}
+
+	/*
+	 * Test displayName(Locale) with null.
+	 */
+	public void testDisplayName_Locale_Null() {
+		MockCharset c = new MockCharset("mock", null);
+		assertEquals("mock", c.displayName(null));
+	}
+
+	/*
+	 * Test the method compareTo(Object) with normal conditions.
+	 */
+	public void testCompareTo_Normal() {
+		MockCharset c1 = new MockCharset("mock", null);
+		assertTrue(c1.compareTo(c1) == 0);
+
+		MockCharset c2 = new MockCharset("Mock", null);
+		assertTrue(c1.compareTo(c2) == 0);
+
+		c2 = new MockCharset("mock2", null);
+		assertTrue(c1.compareTo(c2) < 0);
+		assertTrue(c2.compareTo(c1) > 0);
+
+		c2 = new MockCharset("mack", null);
+		assertTrue(c1.compareTo(c2) > 0);
+		assertTrue(c2.compareTo(c1) < 0);
+
+		c2 = new MockCharset("m.", null);
+		assertTrue(c1.compareTo(c2) > 0);
+		assertTrue(c2.compareTo(c1) < 0);
+
+		c2 = new MockCharset("m:", null);
+		assertTrue(c1.compareTo(c2) == "mock".compareToIgnoreCase("m:"));
+		assertTrue(c2.compareTo(c1) == "m:".compareToIgnoreCase("mock"));
+
+		c2 = new MockCharset("m-", null);
+		assertTrue(c1.compareTo(c2) > 0);
+		assertTrue(c2.compareTo(c1) < 0);
+
+		c2 = new MockCharset("m_", null);
+		assertTrue(c1.compareTo(c2) > 0);
+		assertTrue(c2.compareTo(c1) < 0);
+	}
+
+	/*
+	 * Test the method compareTo(Object) with null param.
+	 */
+	public void testCompareTo_Null() {
+		MockCharset c1 = new MockCharset("mock", null);
+		try {
+			c1.compareTo(null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method compareTo(Object) with non-charset param.
+	 */
+	public void testCompareTo_NonCharsetObject() {
+		MockCharset c1 = new MockCharset("mock", null);
+		try {
+			c1.compareTo("test");
+			fail("Should throw ClassCastException!");
+		} catch (ClassCastException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method compareTo(Object) with another kind of charset object.
+	 */
+	public void testCompareTo_DiffCharsetClass() {
+		MockCharset c1 = new MockCharset("mock", null);
+		MockCharset2 c2 = new MockCharset2("Mock", new String[] { "myname" });
+		assertEquals(0, c1.compareTo(c2));
+		assertEquals(0, c2.compareTo(c1));
+	}
+
+	/*
+	 * Test the method equals(Object) with null param.
+	 */
+	public void testEquals_Normal() {
+		MockCharset c1 = new MockCharset("mock", null);
+		MockCharset2 c2 = new MockCharset2("mock", null);
+		assertTrue(c1.equals(c2));
+		assertTrue(c2.equals(c1));
+
+		c2 = new MockCharset2("Mock", null);
+		assertFalse(c1.equals(c2));
+		assertFalse(c2.equals(c1));
+	}
+
+	/*
+	 * Test the method equals(Object) with normal conditions.
+	 */
+	public void testEquals_Null() {
+		MockCharset c1 = new MockCharset("mock", null);
+		assertFalse(c1.equals(null));
+	}
+
+	/*
+	 * Test the method equals(Object) with another kind of charset object.
+	 */
+	public void testEquals_NonCharsetObject() {
+		MockCharset c1 = new MockCharset("mock", null);
+		assertFalse(c1.equals("test"));
+	}
+
+	/*
+	 * Test the method equals(Object) with another kind of charset object.
+	 */
+	public void testEquals_DiffCharsetClass() {
+		MockCharset c1 = new MockCharset("mock", null);
+		MockCharset2 c2 = new MockCharset2("mock", null);
+		assertTrue(c1.equals(c2));
+		assertTrue(c2.equals(c1));
+	}
+
+	/*
+	 * Test the method hashCode().
+	 */
+	public void testHashCode_DiffCharsetClass() {
+		MockCharset c1 = new MockCharset("mock", null);
+		assertEquals(c1.hashCode(), "mock".hashCode());
+
+		final String mockName = "mockChar1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:-_";
+		c1 = new MockCharset(mockName, new String[] { "mockChar", "mock",
+				mockName, "mock", "mockChar", "mock", "mock2" });
+		assertEquals(c1.hashCode(), mockName.hashCode());
+	}
+
+	/*
+	 * Test the method encode(CharBuffer) under normal condition.
+	 */
+	public void testEncode_CharBuffer_Normal() throws Exception {
+		MockCharset c1 = new MockCharset("mock", null);
+		ByteBuffer bb = c1.encode(CharBuffer.wrap("abcdefg"));
+		assertEquals(new String(bb.array(), "iso8859-1"), "abcdefg");
+		bb = c1.encode(CharBuffer.wrap(""));
+		assertEquals(new String(bb.array(), "iso8859-1"), "");
+	}
+
+	/*
+	 * Test the method encode(CharBuffer) with an unmappable char.
+	 */
+	public void testEncode_CharBuffer_Unmappable() throws Exception {
+		Charset c1 = Charset.forName("iso8859-1");
+		ByteBuffer bb = c1.encode(CharBuffer.wrap("abcd\u5D14efg"));
+		assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
+				+ new String(c1.newEncoder().replacement(), "iso8859-1")
+				+ "efg");
+	}
+
+	/*
+	 * Test the method encode(CharBuffer) with null CharBuffer.
+	 */
+	public void testEncode_CharBuffer_NullCharBuffer() {
+		MockCharset c = new MockCharset("mock", null);
+		try {
+			c.encode((CharBuffer) null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method encode(CharBuffer) with null encoder.
+	 */
+	public void testEncode_CharBuffer_NullEncoder() {
+		MockCharset2 c = new MockCharset2("mock2", null);
+		try {
+			c.encode(CharBuffer.wrap("hehe"));
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method encode(String) under normal condition.
+	 */
+	public void testEncode_String_Normal() throws Exception {
+		MockCharset c1 = new MockCharset("mock", null);
+		ByteBuffer bb = c1.encode("abcdefg");
+		assertEquals(new String(bb.array(), "iso8859-1"), "abcdefg");
+		bb = c1.encode("");
+		assertEquals(new String(bb.array(), "iso8859-1"), "");
+	}
+
+	/*
+	 * Test the method encode(String) with an unmappable char.
+	 */
+	public void testEncode_String_Unmappable() throws Exception {
+		Charset c1 = Charset.forName("iso8859-1");
+		ByteBuffer bb = c1.encode("abcd\u5D14efg");
+		assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
+				+ new String(c1.newEncoder().replacement(), "iso8859-1")
+				+ "efg");
+	}
+
+	/*
+	 * Test the method encode(String) with null CharBuffer.
+	 */
+	public void testEncode_String_NullString() {
+		MockCharset c = new MockCharset("mock", null);
+		try {
+			c.encode((String) null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method encode(String) with null encoder.
+	 */
+	public void testEncode_String_NullEncoder() {
+
+		MockCharset2 c = new MockCharset2("mock2", null);
+		try {
+			c.encode("hehe");
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method decode(ByteBuffer) under normal condition.
+	 */
+	public void testDecode_Normal() throws Exception {
+		MockCharset c1 = new MockCharset("mock", null);
+		CharBuffer cb = c1.decode(ByteBuffer.wrap("abcdefg"
+				.getBytes("iso8859-1")));
+		assertEquals(new String(cb.array()), "abcdefg");
+		cb = c1.decode(ByteBuffer.wrap("".getBytes("iso8859-1")));
+		assertEquals(new String(cb.array()), "");
+	}
+
+	/*
+	 * Test the method decode(ByteBuffer) with a malformed input.
+	 */
+	public void testDecode_Malformed() throws Exception {
+		Charset c1 = Charset.forName("iso8859-1");
+		CharBuffer cb = c1.decode(ByteBuffer.wrap("abcd\u5D14efg"
+				.getBytes("iso8859-1")));
+		byte[] replacement = c1.newEncoder().replacement();
+		assertEquals(new String(cb.array()), "abcd" + new String(replacement)
+				+ "efg");
+	}
+
+	/*
+	 * Test the method decode(ByteBuffer) with null CharBuffer.
+	 */
+	public void testDecode_NullByteBuffer() {
+		MockCharset c = new MockCharset("mock", null);
+		try {
+			c.decode(null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method decode(ByteBuffer) with null encoder.
+	 */
+	public void testDecode_NullDecoder() {
+		MockCharset2 c = new MockCharset2("mock2", null);
+		try {
+			c.decode(ByteBuffer.wrap("hehe".getBytes()));
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method toString().
+	 */
+	public void testToString() {
+		MockCharset c1 = new MockCharset("mock", null);
+		assertTrue(-1 != c1.toString().indexOf("mock"));
+	}
+
+	/*
+	 * Mock charset class.
+	 */
+	static final class MockCharset extends Charset {
+
+		public MockCharset(String canonicalName, String[] aliases) {
+			super(canonicalName, aliases);
+		}
+
+		public boolean contains(Charset cs) {
+			return false;
+		}
+
+		public CharsetDecoder newDecoder() {
+			return new MockDecoder(this);
+		}
+
+		public CharsetEncoder newEncoder() {
+			return new MockEncoder(this);
+		}
+	}
+
+	/*
+	 * Another mock charset class.
+	 */
+	static class MockCharset2 extends Charset {
+
+		public MockCharset2(String canonicalName, String[] aliases) {
+			super(canonicalName, aliases);
+		}
+
+		public boolean contains(Charset cs) {
+			return false;
+		}
+
+		public CharsetDecoder newDecoder() {
+			return null;
+		}
+
+		public CharsetEncoder newEncoder() {
+			return null;
+		}
+	}
+
+	/*
+	 * Mock encoder.
+	 */
+	static class MockEncoder extends java.nio.charset.CharsetEncoder {
+
+		public MockEncoder(Charset cs) {
+			super(cs, 1, 3, new byte[] { (byte) '?' });
+		}
+
+		protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+			while (in.remaining() > 0) {
+				out.put((byte) in.get());
+				// out.put((byte) '!');
+			}
+			return CoderResult.UNDERFLOW;
+		}
+	}
+
+	/*
+	 * Mock decoder.
+	 */
+	static class MockDecoder extends java.nio.charset.CharsetDecoder {
+
+		public MockDecoder(Charset cs) {
+			super(cs, 1, 10);
+		}
+
+		protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+			while (in.remaining() > 0) {
+				out.put((char) in.get());
+			}
+			return CoderResult.UNDERFLOW;
+		}
+	}
+
+	/*
+	 * Mock charset provider.
+	 */
+	public static class MockCharsetProvider extends CharsetProvider {
+
+		public Charset charsetForName(String charsetName) {
+			if ("MockCharset00".equalsIgnoreCase(charsetName)
+					|| "MockCharset01".equalsIgnoreCase(charsetName)
+					|| "MockCharset02".equalsIgnoreCase(charsetName)) {
+				return new MockCharset("mockCharset00", new String[] {
+						"mockCharset01", "mockCharset02" });
+			}
+			return null;
+		}
+
+		public Iterator charsets() {
+			Vector v = new Vector();
+			v.add(new MockCharset("mockCharset00", new String[] {
+					"mockCharset01", "mockCharset02" }));
+			return v.iterator();
+		}
+	}
+
+	/*
+	 * Another mock charset provider.
+	 */
+	public static class MockCharsetProvider2 extends CharsetProvider {
+
+		public Charset charsetForName(String charsetName) {
+			if ("MockCharset10".equalsIgnoreCase(charsetName)
+					|| "MockCharset11".equals(charsetName)
+					|| "MockCharset12".equalsIgnoreCase(charsetName)) {
+				return charset2;
+			}
+			return null;
+		}
+
+		public Iterator charsets() {
+			Vector v = new Vector();
+			v.add(charset2);
+			return v.iterator();
+		}
+	}
+
+	/*
+	 * Another mock charset provider providing build-in charset "ascii".
+	 */
+	public static class MockCharsetProvider3 extends CharsetProvider {
+
+		public Charset charsetForName(String charsetName) {
+			if ("US-ASCII".equalsIgnoreCase(charsetName)
+					|| "ASCII".equalsIgnoreCase(charsetName)) {
+				return new MockCharset("US-ASCII", new String[] { "ASCII" });
+			}
+			return null;
+		}
+
+		public Iterator charsets() {
+			Vector v = new Vector();
+			v.add(new MockCharset("US-ASCII", new String[] { "ASCII" }));
+			return v.iterator();
+		}
+	}
+
+	/*
+	 * 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();
+				}
+			}
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionError.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionError.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionError.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionErrorTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionErrorTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionErrorTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderMalfunctionErrorTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,67 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.charset.CoderMalfunctionError;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Test java.nio.CoderMalfunctionError.
+ */
+public class CoderMalfunctionErrorTest extends TestCase {
+
+	/*
+	 * Test constructor with normal param.
+	 */
+	public void testConstructor_Normal() {
+		Exception ex = new Exception();
+		CoderMalfunctionError e = new CoderMalfunctionError(ex);
+		assertSame(ex, e.getCause());
+	}
+
+	/*
+	 * Test constructor with null param.
+	 */
+	public void testConstructor_Null() {
+		CoderMalfunctionError e = new CoderMalfunctionError(null);
+		assertNull(e.getCause());
+	}
+
+	/*
+	 * Test serialization/deserialization.
+	 */
+	public void testSerialization() throws Exception {
+		CoderMalfunctionError ex = new CoderMalfunctionError(null);
+
+		CoderMalfunctionError deEx = (CoderMalfunctionError) SerializationTester
+				.getDeserilizedObject(ex);
+		assertEquals(null, deEx.getCause());
+	}
+
+	/*
+	 * Test serialization/deserialization.
+	 */
+	public void testSerializationCompatibility() throws Exception {
+		CoderMalfunctionError ex = new CoderMalfunctionError(null);
+
+		CoderMalfunctionError deEx = (CoderMalfunctionError) SerializationTester
+				.readObject(ex,
+						"tests/api/java/nio/charset/CoderMalfunctionError.ser");
+		assertEquals(null, deEx.getCause());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CoderResultTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,264 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.charset.CoderResult;
+import java.nio.charset.MalformedInputException;
+import java.nio.charset.UnmappableCharacterException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.nio.charset.CoderResult.
+ */
+public class CoderResultTest extends TestCase {
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Test the constant OVERFLOW and UNDERFLOW.
+	 */
+	public void testConstants() throws Exception {
+		assertNotSame(CoderResult.OVERFLOW, CoderResult.UNDERFLOW);
+
+		assertNotNull(CoderResult.OVERFLOW);
+		assertFalse(CoderResult.OVERFLOW.isError());
+		assertFalse(CoderResult.OVERFLOW.isMalformed());
+		assertFalse(CoderResult.OVERFLOW.isUnderflow());
+		assertFalse(CoderResult.OVERFLOW.isUnmappable());
+		assertTrue(CoderResult.OVERFLOW.isOverflow());
+		assertTrue(CoderResult.OVERFLOW.toString().indexOf("OVERFLOW") != -1);
+		try {
+			CoderResult.OVERFLOW.throwException();
+			fail("Should throw BufferOverflowException");
+		} catch (BufferOverflowException ex) {
+			// expected
+		}
+		try {
+			CoderResult.OVERFLOW.length();
+			fail("Should throw UnsupportedOperationException");
+		} catch (UnsupportedOperationException ex) {
+			// expected
+		}
+
+		assertNotNull(CoderResult.UNDERFLOW);
+		assertFalse(CoderResult.UNDERFLOW.isError());
+		assertFalse(CoderResult.UNDERFLOW.isMalformed());
+		assertTrue(CoderResult.UNDERFLOW.isUnderflow());
+		assertFalse(CoderResult.UNDERFLOW.isUnmappable());
+		assertFalse(CoderResult.UNDERFLOW.isOverflow());
+		assertTrue(CoderResult.UNDERFLOW.toString().indexOf("UNDERFLOW") != -1);
+		try {
+			CoderResult.UNDERFLOW.throwException();
+			fail("Should throw BufferOverflowException");
+		} catch (BufferUnderflowException ex) {
+			// expected
+		}
+		try {
+			CoderResult.UNDERFLOW.length();
+			fail("Should throw UnsupportedOperationException");
+		} catch (UnsupportedOperationException ex) {
+			// expected
+		}
+	}
+
+	/**
+	 * Test method isError().
+	 * 
+	 */
+	public void testIsError() {
+		assertFalse(CoderResult.UNDERFLOW.isError());
+		assertFalse(CoderResult.OVERFLOW.isError());
+		assertTrue(CoderResult.malformedForLength(1).isError());
+		assertTrue(CoderResult.unmappableForLength(1).isError());
+	}
+
+	/**
+	 * Test method isMalformed().
+	 * 
+	 */
+	public void testIsMalformed() {
+		assertFalse(CoderResult.UNDERFLOW.isMalformed());
+		assertFalse(CoderResult.OVERFLOW.isMalformed());
+		assertTrue(CoderResult.malformedForLength(1).isMalformed());
+		assertFalse(CoderResult.unmappableForLength(1).isMalformed());
+	}
+
+	/**
+	 * Test method isMalformed().
+	 * 
+	 */
+	public void testIsUnmappable() {
+		assertFalse(CoderResult.UNDERFLOW.isUnmappable());
+		assertFalse(CoderResult.OVERFLOW.isUnmappable());
+		assertFalse(CoderResult.malformedForLength(1).isUnmappable());
+		assertTrue(CoderResult.unmappableForLength(1).isUnmappable());
+	}
+
+	/**
+	 * Test method isOverflow().
+	 * 
+	 */
+	public void testIsOverflow() {
+		assertFalse(CoderResult.UNDERFLOW.isOverflow());
+		assertTrue(CoderResult.OVERFLOW.isOverflow());
+		assertFalse(CoderResult.malformedForLength(1).isOverflow());
+		assertFalse(CoderResult.unmappableForLength(1).isOverflow());
+	}
+
+	/**
+	 * Test method isUnderflow().
+	 * 
+	 */
+	public void testIsUnderflow() {
+		assertTrue(CoderResult.UNDERFLOW.isUnderflow());
+		assertFalse(CoderResult.OVERFLOW.isUnderflow());
+		assertFalse(CoderResult.malformedForLength(1).isUnderflow());
+		assertFalse(CoderResult.unmappableForLength(1).isUnderflow());
+	}
+
+	/**
+	 * Test method length().
+	 * 
+	 */
+	public void testLength() {
+		try {
+			CoderResult.UNDERFLOW.length();
+			fail("Should throw UnsupportedOperationException");
+		} catch (UnsupportedOperationException ex) {
+			// expected
+		}
+		try {
+			CoderResult.OVERFLOW.length();
+			fail("Should throw UnsupportedOperationException");
+		} catch (UnsupportedOperationException ex) {
+			// expected
+		}
+
+		assertEquals(CoderResult.malformedForLength(1).length(), 1);
+		assertEquals(CoderResult.unmappableForLength(1).length(), 1);
+	}
+
+	/**
+	 * Test method malformedForLength(int).
+	 * 
+	 */
+	public void testMalformedForLength() {
+		assertNotNull(CoderResult.malformedForLength(Integer.MAX_VALUE));
+		assertNotNull(CoderResult.malformedForLength(1));
+		assertSame(CoderResult.malformedForLength(1), CoderResult
+				.malformedForLength(1));
+		assertNotSame(CoderResult.malformedForLength(1), CoderResult
+				.unmappableForLength(1));
+		assertNotSame(CoderResult.malformedForLength(2), CoderResult
+				.malformedForLength(1));
+		try {
+			CoderResult.malformedForLength(-1);
+			fail("Should throw IllegalArgumentException");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+		try {
+			CoderResult.malformedForLength(0);
+			fail("Should throw IllegalArgumentException");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+	}
+
+	/**
+	 * Test method unmappableForLength(int).
+	 * 
+	 */
+	public void testUnmappableForLength() {
+		assertNotNull(CoderResult.unmappableForLength(Integer.MAX_VALUE));
+		assertNotNull(CoderResult.unmappableForLength(1));
+		assertSame(CoderResult.unmappableForLength(1), CoderResult
+				.unmappableForLength(1));
+		assertNotSame(CoderResult.unmappableForLength(2), CoderResult
+				.unmappableForLength(1));
+		try {
+			CoderResult.unmappableForLength(-1);
+			fail("Should throw IllegalArgumentException");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+		try {
+			CoderResult.unmappableForLength(0);
+			fail("Should throw IllegalArgumentException");
+		} catch (IllegalArgumentException ex) {
+			// expected
+		}
+	}
+
+	/**
+	 * Test method throwException().
+	 * 
+	 */
+	public void testThrowException() throws Exception {
+		try {
+			CoderResult.OVERFLOW.throwException();
+			fail("Should throw BufferOverflowException");
+		} catch (BufferOverflowException ex) {
+			// expected
+		}
+		try {
+			CoderResult.UNDERFLOW.throwException();
+			fail("Should throw BufferOverflowException");
+		} catch (BufferUnderflowException ex) {
+			// expected
+		}
+		try {
+			CoderResult.malformedForLength(1).throwException();
+			fail("Should throw MalformedInputException");
+		} catch (MalformedInputException ex) {
+			assertEquals(ex.getInputLength(), 1);
+		}
+		try {
+			CoderResult.unmappableForLength(1).throwException();
+			fail("Should throw UnmappableCharacterException");
+		} catch (UnmappableCharacterException ex) {
+			assertEquals(ex.getInputLength(), 1);
+		}
+	}
+
+	/**
+	 * Test method toString().
+	 * 
+	 */
+	public void testToString() throws Exception {
+		assertTrue(CoderResult.OVERFLOW.toString().indexOf("OVERFLOW") != -1);
+		assertTrue(CoderResult.UNDERFLOW.toString().indexOf("UNDERFLOW") != -1);
+		assertTrue(CoderResult.malformedForLength(666).toString()
+				.indexOf("666") != -1);
+		assertTrue(CoderResult.unmappableForLength(666).toString().indexOf(
+				"666") != -1);
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/CodingErrorActionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,61 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.charset.CodingErrorAction;
+
+import junit.framework.TestCase;
+
+/**
+ * Test class java.nio.charset.CodingErrorAction
+ */
+public class CodingErrorActionTest extends TestCase {
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/*
+	 * Test the constants.
+	 */
+	public void testIGNORE() {
+		assertNotNull(CodingErrorAction.IGNORE);
+		assertNotNull(CodingErrorAction.REPLACE);
+		assertNotNull(CodingErrorAction.REPORT);
+		assertNotSame(CodingErrorAction.IGNORE, CodingErrorAction.REPLACE);
+		assertNotSame(CodingErrorAction.IGNORE, CodingErrorAction.REPORT);
+		assertNotSame(CodingErrorAction.REPLACE, CodingErrorAction.REPORT);
+	}
+
+	/*
+	 * Test the method toString().
+	 */
+	public void testToString() {
+		assertTrue(CodingErrorAction.IGNORE.toString().indexOf("IGNORE") != -1);
+		assertTrue(CodingErrorAction.REPLACE.toString().indexOf("REPLACE") != -1);
+		assertTrue(CodingErrorAction.REPORT.toString().indexOf("REPORT") != -1);
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ConcreteCharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ConcreteCharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ConcreteCharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ConcreteCharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,158 @@
+package tests.api.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+
+import junit.framework.TestCase;
+
+/**
+ * Super class for concrete charset test suites.
+ */
+public abstract class ConcreteCharsetTest extends TestCase {
+
+	// the canonical name of this charset
+	protected final String canonicalName;
+
+	// the aliases set
+	protected final String[] aliases;
+
+	// canEncode
+	protected final boolean canEncode;
+
+	// isRegistered
+	protected final boolean isRegistered;
+
+	// charset instance
+	protected Charset testingCharset;
+
+	/*
+	 * Initialize the field "testingCharset" here.
+	 * 
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		this.testingCharset = Charset.forName(this.canonicalName);
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Constructor for ConcreteCharsetTest.
+	 * 
+	 */
+	public ConcreteCharsetTest(String arg0, String canonicalName,
+			String[] aliases, boolean canEncode, boolean isRegistered) {
+		super(arg0);
+		this.canonicalName = canonicalName;
+		this.canEncode = canEncode;
+		this.isRegistered = isRegistered;
+		this.aliases = aliases;
+	}
+
+	/*
+	 * Test canEncode.
+	 */
+	public void testCanEncode() {
+		assertEquals(this.canEncode, this.testingCharset.canEncode());
+	}
+
+	/*
+	 * Test isRegistered.
+	 */
+	public void testIsRegistered() {
+		assertEquals(this.isRegistered, this.testingCharset.isRegistered());
+	}
+
+	/*
+	 * Test name.
+	 */
+	public void testName() {
+		assertEquals(this.canonicalName, this.testingCharset.name());
+		// assertEquals(this.canonicalName, this.testingCharset.displayName());
+		// assertEquals(this.canonicalName,
+		// this.testingCharset.displayName(null));
+	}
+
+	/*
+	 * Test aliases.
+	 */
+	public void testAliases() {
+		for (int i = 0; i < this.aliases.length; i++) {
+			Charset c = Charset.forName(this.aliases[i]);
+			assertEquals(this.canonicalName, c.name());
+			// TODO
+			// assertTrue(this.testingCharset.aliases().contains(this.aliases[i]));
+		}
+	}
+
+	/*
+	 * Test the method encode(String) with null.
+	 */
+	public void testEncode_String_Null() {
+		try {
+			this.testingCharset.encode((String) null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test the method encode(CharBuffer) with null.
+	 */
+	public void testEncode_CharBuffer_Null() {
+		try {
+			this.testingCharset.encode((CharBuffer) null);
+			fail("Should throw NullPointerException!");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/*
+	 * Test encoding.
+	 */
+	protected void internalTestEncode(String input, byte[] output) {
+		ByteBuffer bb = this.testingCharset.encode(input);
+		int i = 0;
+		bb.rewind();
+		while (bb.hasRemaining() && i < output.length) {
+			assertEquals(output[i], bb.get());
+			i++;
+		}
+		assertFalse(bb.hasRemaining());
+		assertEquals(output.length, i);
+	}
+
+	/*
+	 * Test encoding.
+	 */
+	public abstract void testEncode_Normal();
+
+	/*
+	 * Test decoding.
+	 */
+	protected void internalTestDecode(byte[] input, char[] output) {
+		CharBuffer chb = this.testingCharset.decode(ByteBuffer.wrap(input));
+		int i = 0;
+		chb.rewind();
+		while (chb.hasRemaining() && i < output.length) {
+			assertEquals(output[i], chb.get());
+			i++;
+		}
+		assertFalse(chb.hasRemaining());
+		assertEquals(output.length, i);
+	}
+
+	/*
+	 * Test decoding.
+	 */
+	public abstract void testDecode_Normal();
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,63 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+/**
+ * test gb18030 decoder
+ */
+public class GBCharsetDecoderTest extends CharsetDecoderTest {
+
+	protected void setUp() throws Exception {
+		cs = Charset.forName("gb18030");
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetDecoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	// // FIXME: give up this tests
+	// public void testDefaultCharsPerByte(){
+	// //assertTrue(decoder.averageCharsPerByte() == 1);
+	// //assertTrue(decoder.maxCharsPerByte() == 1);
+	// assertEquals(decoder.averageCharsPerByte(), 0.25, 0.001);
+	// assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+	// }
+
+	ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+		return null;
+	}
+
+	ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+		ByteBuffer buffer = ByteBuffer.allocate(20);
+		buffer.put(new byte[] { (byte) 0xd8, 0 });
+		buffer.put(unibytes);
+		buffer.flip();
+		return buffer;
+	}
+
+	ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+		return null;
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/GBCharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,94 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+
+/**
+ * test case specific activity of gb18030 charset encoder
+ */
+public class GBCharsetEncoderTest extends CharsetEncoderTest {
+
+	// charset for gb180303
+	private static final Charset CS = Charset.forName("gb18030");
+
+	/*
+	 * @see CharsetEncoderTest#setUp()
+	 */
+	protected void setUp() throws Exception {
+		cs = CS;
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetEncoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testCanEncodechar() throws CharacterCodingException {
+		// normal case for utfCS
+		assertTrue(encoder.canEncode('\u0077'));
+		assertTrue(encoder.canEncode('\uc2a3'));
+
+		// for non-mapped char
+		assertTrue(encoder.canEncode('\uc2c0'));
+	}
+
+	/*
+	 * Class under test for boolean canEncode(CharSequence)
+	 */
+	public void testCanEncodeCharSequence() {
+		assertTrue(encoder.canEncode(""));
+		// surrogate char
+
+		// valid surrogate pair
+		assertTrue(encoder.canEncode("\ud800\udc00"));
+		// invalid surrogate pair
+		assertFalse(encoder.canEncode("\ud800\udb00"));
+		assertFalse(encoder.canEncode("\ud800"));
+	}
+
+	public void testSpecificDefaultValue() {
+		// FIXME: different here!
+		assertTrue(encoder.maxBytesPerChar() == 4);
+		assertTrue(encoder.averageBytesPerChar() == 2.5);
+
+		// assertTrue(encoder.averageBytesPerChar() == 3);
+		// assertTrue(encoder.maxBytesPerChar() == 2);
+
+	}
+
+	CharBuffer getMalformedCharBuffer() {
+		return CharBuffer.wrap("\ud800 buffer");
+	}
+
+	CharBuffer getUnmapCharBuffer() {
+		return null;
+	}
+
+	CharBuffer getExceptionCharBuffer() {
+		return null;
+	}
+
+	protected byte[] getIllegalByteArray() {
+		return new byte[] { (byte) 0xd8, (byte) 0x00 };
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,60 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+/**
+ * test ISO-8859-1 decoder
+ */
+public class ISOCharsetDecoderTest extends CharsetDecoderTest {
+
+	protected void setUp() throws Exception {
+		cs = Charset.forName("iso-8859-1");
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetDecoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	// FIXME: give up this tests
+	// public void testDefaultCharsPerByte(){
+	// assertTrue(decoder.averageCharsPerByte() == 1);
+	// assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+	// }
+
+	ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+		// TODO how onmap?
+		return null;
+
+	}
+
+	ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+		// TODO how malform
+		return null;
+	}
+
+	ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+		return null;
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,111 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.UnmappableCharacterException;
+
+/**
+ * test case specific activity of iso-8859-1 charset encoder
+ */
+public class ISOCharsetEncoderTest extends CharsetEncoderTest {
+
+	// charset for iso-8859-1
+	private static final Charset CS = Charset.forName("iso-8859-1");
+
+	/*
+	 * @see CharsetEncoderTest#setUp()
+	 */
+	protected void setUp() throws Exception {
+		cs = CS;
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetEncoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testCanEncodeCharSequence() {
+		// normal case for isoCS
+		assertTrue(encoder.canEncode("\u0077"));
+		assertFalse(encoder.canEncode("\uc2a3"));
+		assertFalse(encoder.canEncode("\ud800\udc00"));
+		try {
+			encoder.canEncode(null);
+		} catch (NullPointerException e) {
+		}
+		assertTrue(encoder.canEncode(""));
+	}
+
+	public void testCanEncodeICUBug() {
+		assertFalse(encoder.canEncode((char) '\ud800'));
+		assertFalse(encoder.canEncode((String) "\ud800"));
+	}
+
+	public void testCanEncodechar() throws CharacterCodingException {
+		assertTrue(encoder.canEncode('\u0077'));
+		assertFalse(encoder.canEncode('\uc2a3'));
+	}
+
+	public void testSpecificDefaultValue() {
+		assertTrue(encoder.averageBytesPerChar() == 1);
+		assertTrue(encoder.maxBytesPerChar() == 1);
+	}
+
+	CharBuffer getMalformedCharBuffer() {
+		return CharBuffer.wrap("\ud800 buffer");
+	}
+
+	CharBuffer getUnmapCharBuffer() {
+		return CharBuffer.wrap("\ud800\udc00 buffer");
+	}
+
+	CharBuffer getExceptionCharBuffer() {
+		return null;
+	}
+
+	protected byte[] getIllegalByteArray() {
+		return null;
+	}
+
+	public void testMultiStepEncode() throws CharacterCodingException {
+		encoder.onMalformedInput(CodingErrorAction.REPORT);
+		encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+		try {
+			encoder.encode(CharBuffer.wrap("\ud800\udc00"));
+			fail("should unmappable");
+		} catch (UnmappableCharacterException e) {
+		}
+		encoder.reset();
+		ByteBuffer out = ByteBuffer.allocate(10);
+		assertTrue(encoder.encode(CharBuffer.wrap("\ud800"), out, true)
+				.isMalformed());
+		encoder.flush(out);
+		encoder.reset();
+		out = ByteBuffer.allocate(10);
+		assertSame(CoderResult.UNDERFLOW, encoder.encode(CharBuffer
+				.wrap("\ud800"), out, false));
+		assertTrue(encoder.encode(CharBuffer.wrap("\udc00"), out, true)
+				.isMalformed());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/ISOCharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,57 @@
+/* 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 tests.api.java.nio.charset;
+
+/**
+ * Test ISO-8859-1.
+ */
+public class ISOCharsetTest extends ConcreteCharsetTest {
+
+	/**
+	 * Constructor.
+	 */
+	public ISOCharsetTest(String arg0) {
+		super(arg0, "ISO-8859-1", new String[] { "iso-ir-100", "8859_1",
+				"ISO_8859-1", "ISO8859_1", "819", "csISOLatin1", "IBM-819",
+				"ISO_8859-1:1987", "latin1", "cp819", "ISO8859-1", "IBM819",
+				"ISO_8859_1", "l1" }, true, true);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+	 */
+	public void testEncode_Normal() {
+		String input = "ab\u5D14\u654F";
+		byte[] output = new byte[] { 97, 98,
+				this.testingCharset.newEncoder().replacement()[0],
+				this.testingCharset.newEncoder().replacement()[0] };
+		internalTestEncode(input, output);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+	 */
+	public void testDecode_Normal() {
+		byte[] input = new byte[] { 97, 98, 63, 63 };
+		char[] output = "ab??".toCharArray();
+		internalTestDecode(input, output);
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameException.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameException.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/IllegalCharsetNameExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,76 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.charset.IllegalCharsetNameException;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Test class IllegalCharsetNameException.
+ */
+public class IllegalCharsetNameExceptionTest extends TestCase {
+
+	public void testConstructor() {
+		IllegalCharsetNameException ex = new IllegalCharsetNameException(
+				"impossible");
+		assertTrue(ex instanceof IllegalArgumentException);
+		assertNull(ex.getCause());
+		assertEquals(ex.getCharsetName(), "impossible");
+		assertTrue(ex.getMessage().indexOf("impossible") != -1);
+
+		ex = new IllegalCharsetNameException("ascii");
+		assertNull(ex.getCause());
+		assertEquals(ex.getCharsetName(), "ascii");
+		assertTrue(ex.getMessage().indexOf("ascii") != -1);
+
+		ex = new IllegalCharsetNameException("");
+		assertNull(ex.getCause());
+		assertEquals(ex.getCharsetName(), "");
+		ex.getMessage();
+
+		ex = new IllegalCharsetNameException(null);
+		assertNull(ex.getCause());
+		assertEquals(ex.getCharsetName(), null);
+		assertTrue(ex.getMessage().indexOf("null") != -1);
+
+	}
+
+	/*
+	 * Test serialization/deserialization.
+	 */
+	public void testSerialization() throws Exception {
+		IllegalCharsetNameException ex = new IllegalCharsetNameException(
+				"charsetName");
+
+		IllegalCharsetNameException deEx = (IllegalCharsetNameException) SerializationTester
+				.getDeserilizedObject(ex);
+	}
+
+	/*
+	 * Test serialization/deserialization
+	 */
+	public void testSerializationCompatibility() throws Exception {
+		IllegalCharsetNameException ex = new IllegalCharsetNameException(
+				"charsetName");
+
+		IllegalCharsetNameException deEx = (IllegalCharsetNameException) SerializationTester
+				.readObject(ex,
+						"tests/api/java/nio/charset/IllegalCharsetNameException.ser");
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputException.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputException.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputException.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputExceptionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/MalformedInputExceptionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,71 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.MalformedInputException;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ * Test class MalformedInputException.
+ */
+public class MalformedInputExceptionTest extends TestCase {
+
+	public void testConstructor() {
+		MalformedInputException ex = new MalformedInputException(3);
+		assertTrue(ex instanceof CharacterCodingException);
+		assertNull(ex.getCause());
+		assertEquals(ex.getInputLength(), 3);
+		assertTrue(ex.getMessage().indexOf("3") != -1);
+
+		ex = new MalformedInputException(-3);
+		assertNull(ex.getCause());
+		assertEquals(ex.getInputLength(), -3);
+		assertTrue(ex.getMessage().indexOf("-3") != -1);
+
+		ex = new MalformedInputException(0);
+		assertNull(ex.getCause());
+		assertEquals(ex.getInputLength(), 0);
+		assertTrue(ex.getMessage().indexOf("0") != -1);
+	}
+
+	/*
+	 * Test serialization/deserialization.
+	 */
+	public void testSerialization() throws Exception {
+		MalformedInputException ex = new MalformedInputException(11);
+
+		MalformedInputException deEx = (MalformedInputException) SerializationTester
+				.getDeserilizedObject(ex);
+		assertEquals(11, deEx.getInputLength());
+	}
+
+	/*
+	 * Test serialization/deserialization compatibility with reference
+	 * implementation.
+	 */
+	public void testSerializationCompatibility() throws Exception {
+		MalformedInputException ex = new MalformedInputException(11);
+
+		MalformedInputException deEx = (MalformedInputException) SerializationTester
+				.readObject(ex,
+						"tests/api/java/nio/charset/MalformedInputException.ser");
+		assertEquals(11, deEx.getInputLength());
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,73 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+/**
+ * 
+ */
+public class UTF16BECharsetDecoderTest extends CharsetDecoderTest {
+
+	protected void setUp() throws Exception {
+		cs = Charset.forName("utf-16be");
+		unibytes = new byte[] { 0, 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101,
+				0, 114 };
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetDecoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	// FIXME: give up this tests
+	// public void testDefaultCharsPerByte() {
+	// // assertTrue(decoder.averageCharsPerByte() == 1);
+	// // assertTrue(decoder.maxCharsPerByte() == 1);
+	// assertEquals(decoder.averageCharsPerByte(), 0.5, 0.001);
+	// assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+	// }
+
+	ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+		// no unmap byte buffer
+		return null;
+	}
+
+	ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+		// FIXME: different here, RI can parse 0xd8d8
+		// ByteBuffer buffer = ByteBuffer.allocate(100);
+		// buffer.put((byte)0xd8);
+		// buffer.put((byte)0xd8);
+		// buffer.put(unibytes);
+		// buffer.flip();
+		// return buffer;
+		return null;
+	}
+
+	ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+		return null;
+	}
+
+	byte[] getUnibytes() {
+		return new byte[] { 0, 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
+				114 };
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,119 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+
+/**
+ * TODO type def
+ */
+public class UTF16BECharsetEncoderTest extends CharsetEncoderTest {
+
+	// charset for utf-16be
+	private static final Charset CS = Charset.forName("utf-16be");
+
+	/*
+	 * @see CharsetEncoderTest#setUp()
+	 */
+	protected void setUp() throws Exception {
+		cs = CS;
+		specifiedReplacement = new byte[] { -1, -3 };
+		unibytes = new byte[] { 0, 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101,
+				0, 114 };
+
+		// unibytesWithRep = new byte[] {(byte)0xff, (byte)0xfd,0, 32, 0, 98, 0,
+		// 117, 0, 102, 0, 102, 0, 101, 0, 114};
+
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetEncoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testCharsetEncoderCharsetfloatfloat() {
+		// this constructor is invalid for UTF16LE CharsetEncoder
+	}
+
+	public void testCanEncodechar() throws CharacterCodingException {
+		// normal case for utfCS
+		assertTrue(encoder.canEncode('\u0077'));
+		assertTrue(encoder.canEncode('\uc2a3'));
+
+		// for non-mapped char
+		assertTrue(encoder.canEncode('\uc2c0'));
+
+	}
+
+	public void testCanEncodeCharSequence() {
+		// normal case for utfCS
+		assertTrue(encoder.canEncode("\u0077"));
+		assertTrue(encoder.canEncode("\uc2a3"));
+		assertTrue(encoder.canEncode(""));
+
+		// for non-mapped char
+		assertTrue(encoder.canEncode("\uc2c0"));
+
+		// surrogate char for unicode
+		// 1st byte: d800-dbff
+		// 2nd byte: dc00-dfff
+		// valid surrogate pair
+		assertTrue(encoder.canEncode("\ud800\udc00"));
+		// invalid surrogate pair
+		assertFalse(encoder.canEncode("\ud800\udb00"));
+	}
+
+	public void testCanEncodeICUBug() {
+		assertFalse(encoder.canEncode("\ud800"));
+	}
+
+	public void testSpecificDefaultValue() {
+		assertTrue(encoder.averageBytesPerChar() == 2);
+		assertTrue(encoder.maxBytesPerChar() == 2);
+	}
+
+	CharBuffer getMalformedCharBuffer() {
+		return CharBuffer.wrap("\ud800 buffer");
+	}
+
+	CharBuffer getUnmapCharBuffer() {
+		return null;
+	}
+
+	CharBuffer getExceptionCharBuffer() {
+		return null;
+	}
+
+	public void testIsLegalReplacementEmptyArray() {
+		assertTrue(encoder.isLegalReplacement(new byte[0]));
+	}
+
+	protected byte[] getIllegalByteArray() {
+		// FIXME: different here
+		// cannot replace by 0xd8d8, but RI can
+		// return new byte[]{(byte)0xd8, (byte)0xd8};
+		return new byte[] { 0 };
+	}
+
+	protected byte[] getLegalByteArray() {
+		return new byte[] { (byte) 0x00, (byte) 0xd8 };
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16BECharsetTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,52 @@
+/* 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 tests.api.java.nio.charset;
+
+/**
+ * Test UTF-16BE.
+ */
+public class UTF16BECharsetTest extends ConcreteCharsetTest {
+
+	/**
+	 * Constructor.
+	 */
+	public UTF16BECharsetTest(String arg0) {
+		super(arg0, "UTF-16BE", new String[] { "X-UTF-16BE", "UTF_16BE" },
+				true, true); // "ISO-10646-UCS-2"
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testEncode_Normal()
+	 */
+	public void testEncode_Normal() {
+		String input = "ab\u5D14\u654F";
+		byte[] output = new byte[] { 0, 97, 0, 98, 93, 20, 101, 79 };
+		internalTestEncode(input, output);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see tests.api.java.nio.charset.ConcreteCharsetTest#testDecode_Normal()
+	 */
+	public void testDecode_Normal() {
+		byte[] input = new byte[] { 0, 97, 0, 98, 93, 20, 101, 79 };
+		char[] output = "ab\u5D14\u654F".toCharArray();
+		internalTestDecode(input, output);
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetDecoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,151 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * 
+ */
+public class UTF16CharsetDecoderTest extends CharsetDecoderTest {
+
+	boolean bigEndian = true;
+
+	protected void setUp() throws Exception {
+		cs = Charset.forName("utf-16");
+		unibytes = new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
+				114, 0 };
+		bom = "\ufeff";
+
+		// unibytes = new byte[] {-1, -2, 0, 32, 0, 98, 0, 117, 0, 102, 0, 102,
+		// 0, 101, 0, 114};
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetDecoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	byte[] getUnibytes() {
+		// FIXME: different here
+		// if don't specified BOM
+		// ICU default is LE
+		// JDK default is BE
+
+		// maybe start with 0xFEFF, which means big endian
+		// 0xFFFE, which means little endian
+		if (bigEndian) {
+			return new byte[] { -1, -2, 32, 0, 98, 0, 117, 0, 102, 0, 102, 0,
+					101, 0, 114, 0 };
+		} else {
+			unibytes = new byte[] { 0, 32, 0, 98, 0, 117, 0, 102, 0, 102, 0,
+					101, 0, 114 };
+			return new byte[] { -2, -1, 0, 32, 0, 98, 0, 117, 0, 102, 0, 102,
+					0, 101, 0, 114 };
+		}
+	}
+
+	public void testMultiStepDecode() throws CharacterCodingException {
+		if (!cs.name().equals("mock")) {
+			decoder.onMalformedInput(CodingErrorAction.REPORT);
+			decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+			CharBuffer out = CharBuffer.allocate(10);
+			assertTrue(decoder.decode(
+					ByteBuffer.wrap(new byte[] { -1, -2, 32, 0, 98 }), out,
+					true).isMalformed());
+
+			decoder.flush(out);
+			decoder.reset();
+			out.clear();
+			assertSame(CoderResult.UNDERFLOW, decoder.decode(ByteBuffer
+					.wrap(new byte[] { -1, -2, 32, 0 }), out, false));
+			assertTrue(decoder.decode(ByteBuffer.wrap(new byte[] { 98 }), out,
+					true).isMalformed());
+
+			decoder.flush(out);
+			decoder.reset();
+			out.clear();
+			assertSame(CoderResult.UNDERFLOW, decoder.decode(ByteBuffer
+					.wrap(new byte[] { -1, -2, 32, 0, 98 }), out, false));
+			assertTrue(decoder
+					.decode(ByteBuffer.wrap(new byte[] {}), out, true)
+					.isMalformed());
+
+			decoder.flush(out);
+			decoder.reset();
+			out.clear();
+			assertFalse(decoder.decode(
+					ByteBuffer.wrap(new byte[] { -1, -2, 32, 0, 98, 0 }), out,
+					true).isError());
+
+			decoder.flush(out);
+			decoder.reset();
+			out.clear();
+			assertSame(CoderResult.UNDERFLOW, decoder.decode(ByteBuffer
+					.wrap(new byte[] { -1, -2, 32, 0, 98 }), out, false));
+			assertFalse(decoder.decode(ByteBuffer.wrap(new byte[] { 0 }), out,
+					true).isMalformed());
+
+		}
+	}
+
+	public void testLittleEndian() throws CharacterCodingException,
+			UnsupportedEncodingException {
+		bigEndian = false;
+		implTestDecodeByteBufferCharBufferboolean();
+		decoder.reset();
+		implTestDecodeByteBuffer();
+		bigEndian = true;
+	}
+
+	// FIXME: give up this tests
+	// public void testDefaultCharsPerByte() {
+	// // assertTrue(decoder.averageCharsPerByte() == 1);
+	// // assertTrue(decoder.maxCharsPerByte() == 1);
+	// assertEquals(decoder.averageCharsPerByte(), 0.5, 0.001);
+	// assertEquals(decoder.maxCharsPerByte(), 2, 0.001);
+	// }
+
+	ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
+		return null;
+	}
+
+	ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
+		return null;
+		// FIXME: different here, RI can parse 0xd8d8
+		// ByteBuffer buffer = ByteBuffer.allocate(100);
+		// buffer.put((byte) -1);
+		// buffer.put((byte) -2);
+		// buffer.put((byte) 0xdc);
+		// buffer.put((byte) 0xdc);
+		// buffer.put(unibytes);
+		// buffer.flip();
+		// return buffer;
+	}
+
+	ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF16CharsetEncoderTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,137 @@
+/* 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 tests.api.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+
+/**
+ * TODO type def
+ */
+public class UTF16CharsetEncoderTest extends CharsetEncoderTest {
+
+	// charset for utf-16
+	// charset for utf-16be
+	private static final Charset CS = Charset.forName("utf-16");
+
+	private static final CharsetDecoder decoder = CS.newDecoder();
+
+	/*
+	 * @see CharsetEncoderTest#setUp()
+	 */
+	protected void setUp() throws Exception {
+		cs = CS;
+		specifiedReplacement = new byte[] { -3, -1 };
+		surrogate = new byte[] { -1, -2 };
+		unibytes = new byte[] { 32, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0,
+				114, 0 };
+		unibytesWithRep = new byte[] { -3, -1, 32, 0, 98, 0, 117, 0, 102, 0,
+				102, 0, 101, 0, 114, 0 };
+		super.setUp();
+	}
+
+	/*
+	 * @see CharsetEncoderTest#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testCharsetEncoderCharsetfloatfloat() {
+		// this constructor is invalid for UTF16LE CharsetEncoder
+	}
+
+	public void testCanEncodechar() throws CharacterCodingException {
+		// normal case for utfCS
+		assertTrue(encoder.canEncode('\u0077'));
+		assertTrue(encoder.canEncode('\uc2a3'));
+
+		// for non-mapped char
+		assertTrue(encoder.canEncode('\uc2c0'));
+	}
+
+	public void testCanEncodeCharSequence() {
+		// normal case for utfCS
+		assertTrue(encoder.canEncode("\u0077"));
+		assertTrue(encoder.canEncode("\uc2a3"));
+		assertTrue(encoder.canEncode(""));
+
+		// for non-mapped char
+		assertTrue(encoder.canEncode("\uc2c0"));
+
+		// surrogate char for unicode
+		// 1st byte: d800-dbff
+		// 2nd byte: dc00-dfff
+		// valid surrogate pair
+		assertTrue(encoder.canEncode("\ud800\udc00"));
+		// invalid surrogate pair
+		assertFalse(encoder.canEncode("\ud800\udb00"));
+	}
+
+	public void testCanEncodeICUBug() {
+		assertFalse(encoder.canEncode('\ud800'));
+		assertFalse(encoder.canEncode("\ud800"));
+	}
+
+	public void testSpecificDefaultValue() {
+		assertEquals(encoder.averageBytesPerChar(), 2, 0.001);
+		// assertTrue(encoder.maxBytesPerChar() == 4);
+		// FIXME: different here!
+		assertEquals(encoder.maxBytesPerChar(), 2, 0.001);
+	}
+
+	CharBuffer getMalformedCharBuffer() {
+		return CharBuffer.wrap("\ud800 buffer");
+	}
+
+	CharBuffer getUnmapCharBuffer() {
+		return null;
+	}
+
+	CharBuffer getExceptionCharBuffer() {
+		return null;
+	}
+
+	public void testIsLegalReplacementEmptyArray() {
+		assertTrue(encoder.isLegalReplacement(new byte[0]));
+	}
+
+	protected byte[] getIllegalByteArray() {
+		return new byte[] { 0x00 };
+	}
+
+	protected byte[] getLegalByteArray() {
+		// FIXME: Different Here!
+		// return new byte[]{(byte)0xd8, 0x00};
+		return new byte[] { (byte) 0x00, (byte) 0xd8 };
+	}
+
+	void assertByteArray(ByteBuffer out, byte[] expected) {
+		out = out.duplicate();
+		if (out.position() > 0) {
+			out.flip();
+		}
+		try {
+			assertEquals(decoder.decode(out), decoder.decode(ByteBuffer
+					.wrap(expected)));
+		} catch (CharacterCodingException e) {
+			fail(e.toString());
+		}
+	}
+}



Mime
View raw message