CharsetDecoderTestpublic class CharsetDecoderTest extends TestCase
Methods Summary |
---|
public void | testDecodeLjava_nio_ByteBuffer_ReplaceOverflow()
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());
assertEquals("bb", out.toString());
| 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
}
| public void | test_decode()
// 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
}
| public void | test_decodeLjava_nio_ByteBuffer()
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
}
|
|