1 54 package org.w3c.tidy; 55 56 import java.io.ByteArrayInputStream ; 57 import java.io.InputStream ; 58 59 import junit.framework.TestCase; 60 61 62 66 public class StreamInImplTest extends TestCase 67 { 68 69 72 private StreamInImpl in; 73 74 77 private Lexer lexer; 78 79 82 protected void setUp() throws Exception 83 { 84 super.setUp(); 85 86 InputStream stream = new ByteArrayInputStream (new byte[]{0}); 87 88 Report report = new Report(); 89 Configuration configuration = new Configuration(report); 90 configuration.setInCharEncodingName("US-ASCII"); 91 in = new StreamInImpl(stream, configuration); 92 93 lexer = new Lexer(in, configuration, report); 94 lexer.configuration = configuration; 95 in.setLexer(lexer); 96 } 97 98 101 public final void testReadCharFromStreamAscii() 102 { 103 InputStream stream = new ByteArrayInputStream (new byte[]{97, 97, 97}); 104 105 Report report = new Report(); 106 Configuration configuration = new Configuration(report); 107 configuration.setInCharEncodingName("US-ASCII"); 108 in = new StreamInImpl(stream, configuration); 109 in.setLexer(lexer); 110 111 char thechar = (char) in.readCharFromStream(); 112 assertEquals('a', thechar); 113 thechar = (char) in.readCharFromStream(); 114 assertEquals('a', thechar); 115 } 116 117 120 public final void testReadCharFromStreamUTF16() 121 { 122 InputStream stream = new ByteArrayInputStream (new byte[]{00, 97, 00, 97}); 123 124 Report report = new Report(); 125 Configuration configuration = new Configuration(report); 126 configuration.setInCharEncodingName("utf16be"); 127 in = new StreamInImpl(stream, configuration); 128 in.setLexer(lexer); 129 130 char thechar = (char) in.readCharFromStream(); 131 assertEquals('a', thechar); 132 thechar = (char) in.readCharFromStream(); 133 assertEquals('a', thechar); 134 } 135 136 139 public final void testReadCharFromStreamUTF16WithBOMLE() 140 { 141 InputStream stream = new ByteArrayInputStream (new byte[]{-1, -2, 97, 00}); 142 143 Report report = new Report(); 144 Configuration configuration = new Configuration(report); 145 configuration.setInCharEncodingName("utf16"); 146 in = new StreamInImpl(stream, configuration); 147 in.setLexer(lexer); 148 149 char thechar = (char) in.readCharFromStream(); 150 assertEquals(EncodingUtils.UNICODE_BOM, thechar); 151 thechar = (char) in.readCharFromStream(); 152 assertEquals('a', thechar); 153 } 154 155 158 public final void testReadCharFromStreamUTF16WithBOMBE() 159 { 160 InputStream stream = new ByteArrayInputStream (new byte[]{-2, -1, 00, 97}); 161 162 Report report = new Report(); 163 Configuration configuration = new Configuration(report); 164 configuration.setInCharEncodingName("utf16"); 165 in = new StreamInImpl(stream, configuration); 166 in.setLexer(lexer); 167 168 char thechar = (char) in.readCharFromStream(); 169 assertEquals(EncodingUtils.UNICODE_BOM, thechar); 170 thechar = (char) in.readCharFromStream(); 171 assertEquals('a', thechar); 172 } 173 174 } | Popular Tags |