FileDocCategorySizeDatePackage
UTF16CharsetDecoderTest.javaAPI DocAndroid 1.5 API6594Wed May 06 22:41:04 BST 2009tests.api.java.nio.charset

UTF16CharsetDecoderTest

public class UTF16CharsetDecoderTest extends AbstractCharsetDecoderTestCase

Fields Summary
boolean
bigEndian
Constructors Summary
Methods Summary
java.nio.ByteBuffergetExceptionByteArray()

        return null;
    
java.nio.ByteBuffergetMalformByteBuffer()

        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;
    
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 };
        }
    
java.nio.ByteBuffergetUnmappedByteBuffer()

        return null;
    
protected voidsetUp()


         
        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();
    
protected voidtearDown()

        super.tearDown();
    
public voidtestLittleEndian()

        bigEndian = false;
        implTestDecodeByteBufferCharBufferboolean();
        decoder.reset();
        implTestDecodeByteBuffer();
        bigEndian = true;
    
public voidtestMultiStepDecode()

        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));
            assertFalse(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));
            assertTrue(decoder.decode(ByteBuffer.wrap(new byte[] { 0 }), out,
                    true).isMalformed());

        }