From: Olyutorskii Date: Sun, 7 May 2017 16:30:47 +0000 (+0900) Subject: add UCS4 test to StreamDecoder unit test X-Git-Tag: fromMercurial~35 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=82892ce298535d8e17a808cece9f2392f12714a6;p=jindolf%2FJinParser.git add UCS4 test to StreamDecoder unit test --- diff --git a/src/test/java/jp/sourceforge/jindolf/parser/StreamDecoderTest.java b/src/test/java/jp/sourceforge/jindolf/parser/StreamDecoderTest.java index 311f5db..54f060e 100644 --- a/src/test/java/jp/sourceforge/jindolf/parser/StreamDecoderTest.java +++ b/src/test/java/jp/sourceforge/jindolf/parser/StreamDecoderTest.java @@ -189,6 +189,48 @@ public class StreamDecoderTest { } + /** + * Test of decode method, of class StreamDecoder. + * @throws IOException + * @throws DecodeException + */ + @Test + public void testDecodeUCS4() throws IOException, DecodeException { + System.out.println("decode"); + + Charset cs; + CharsetDecoder decoder; + + StreamDecoder sd; + InputStream is; + TestHandler handler; + + cs = Charset.forName("UTF-8"); + + handler = new TestHandler(); + + decoder = cs.newDecoder(); + sd = new StreamDecoder(decoder, 4, 4); + sd.setDecodeHandler(handler); + is = byteStream(0x41, 0x42, 0xe3, 0x81, 0x82, 0x46); + handler.clear(); + sd.decode(is); + assertEquals("[ST][CH]ABあF[EN]", handler.toString()); + + // malformed + is = byteStream(0x41, 0x42, 0xc2, 0xc0, 0x45); + handler.clear(); + sd.decode(is); + assertEquals("[ST][CH]AB[ER]c2[ER]c0[CH]E[EN]", handler.toString()); + + // SMP character U+1F411 [SHEEP] + is = byteStream(0x41, 0x42, 0xf0, 0x9f, 0x90, 0x91, 0x47); + handler.clear(); + sd.decode(is); + assertEquals("[ST][CH]AB\ud83d\udc11G[EN]", handler.toString()); + + } + static ByteArrayInputStream byteStream(int... array){ byte[] ba = new byte[array.length];