You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/13 20:56:07 UTC
svn commit: r385639 -
/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Author: tellison
Date: Mon Mar 13 11:56:06 2006
New Revision: 385639
URL: http://svn.apache.org/viewcvs?rev=385639&view=rev
Log:
Apply test case patch for HARMONY-148 (java.nio.charset.CharsetDecoder: decode(in,out,endOfInput) method doesn't preserve replace string for successive decode invocation while "out" doesn't have engouh space for replace string.)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java?rev=385639&r1=385638&r2=385639&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java Mon Mar 13 11:56:06 2006
@@ -171,4 +171,61 @@
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;
+ }
+ }
}