FileDocCategorySizeDatePackage
CharsetEncoderTest.javaAPI DocAndroid 1.5 API7111Wed May 06 22:41:04 BST 2009org.apache.harmony.nio_char.tests.java.nio.charset

CharsetEncoderTest

public class CharsetEncoderTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtest_ConstructorLjava_nio_charset_CharsetFF()

tests
java.nio.charset.CharsetEncoder.CharsetEncoder( java.nio.charset.Charset, float, float)

        // Regression for HARMONY-141
        try {
            Charset cs = Charset.forName("UTF-8"); //$NON-NLS-1$
            new MockCharsetEncoderForHarmony141(cs, 1.1f, 1);
            fail("Assert 0: Should throw IllegalArgumentException."); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // expected
        }

        try {
            Charset cs = Charset.forName("ISO8859-1"); //$NON-NLS-1$
            new MockCharsetEncoderForHarmony141(cs, 1.1f, 1,
                    new byte[] { 0x1a });
            fail("Assert 1: Should throw IllegalArgumentException."); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // expected
        }
    
public voidtest_ConstructorLjava_nio_charset_CharsetNull()

tests
java.nio.charset.CharsetEncoder.CharsetEncoder( java.nio.charset.Charset, float, float)

        // Regression for HARMONY-491
        CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null, 1, 1);
        assertNull(ech.charset());
    
public voidtest_EncodeLjava_nio_CharBuffer()

        MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
        try {
            cs.encode(CharBuffer.wrap("AB"));
            fail("should throw CoderMalfunctionError");// NON-NLS-1$
        } catch (CoderMalfunctionError e) {
            // expected
        }
    
public voidtest_EncodeLjava_nio_CharBufferLjava_nio_ByteBufferB()

        CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
        CharBuffer in1 = CharBuffer.wrap("\ud800");
        CharBuffer in2 = CharBuffer.wrap("\udc00");
        ByteBuffer out = ByteBuffer.allocate(4);
        encoder.reset();
        CoderResult result = encoder.encode(in1, out, false);
        assertEquals(4, out.remaining());
        assertTrue(result.isUnderflow());
        result = encoder.encode(in2, out, true);
        assertEquals(4, out.remaining());
        assertTrue(result.isMalformed());