|
16 | 16 | */ |
17 | 17 | package org.apache.commons.io.input; |
18 | 18 |
|
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertFalse; |
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertNull; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | +import static org.junit.Assert.fail; |
| 25 | + |
19 | 26 | import java.io.ByteArrayInputStream; |
20 | 27 | import java.io.IOException; |
21 | 28 | import java.io.InputStream; |
22 | 29 | import java.nio.charset.Charset; |
23 | 30 |
|
24 | | -import junit.framework.TestCase; |
| 31 | +import javax.xml.parsers.DocumentBuilderFactory; |
25 | 32 |
|
26 | 33 | import org.apache.commons.io.ByteOrderMark; |
27 | 34 | import org.apache.commons.io.Charsets; |
28 | 35 | import org.junit.Assert; |
29 | 36 | import org.junit.Assume; |
| 37 | +import org.junit.Ignore; |
30 | 38 | import org.junit.Test; |
| 39 | +import org.w3c.dom.Document; |
| 40 | +import org.xml.sax.InputSource; |
31 | 41 |
|
32 | 42 | /** |
33 | 43 | * Test case for {@link BOMInputStream}. |
34 | 44 | * |
35 | 45 | * @version $Id$ |
36 | 46 | */ |
37 | | -public class BOMInputStreamTest extends TestCase { |
| 47 | +public class BOMInputStreamTest { |
38 | 48 | //---------------------------------------------------------------------------- |
39 | 49 | // Support code |
40 | 50 | //---------------------------------------------------------------------------- |
@@ -219,6 +229,55 @@ public void testReadWithBOMUtf8() throws Exception { |
219 | 229 | } |
220 | 230 | } |
221 | 231 |
|
| 232 | + @Test |
| 233 | + public void testReadXmlWithBOMUtf8() throws Exception { |
| 234 | + byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><X/>".getBytes(Charsets.UTF_8); |
| 235 | + BOMInputStream in = new BOMInputStream(createUtf8DataStream(data, true)); |
| 236 | + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in)); |
| 237 | + assertNotNull(doc); |
| 238 | + assertEquals("X", doc.getFirstChild().getNodeName()); |
| 239 | + } |
| 240 | + |
| 241 | + @Test |
| 242 | + public void testReadXmlWithBOMUtf16Be() throws Exception { |
| 243 | + byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16BE\"?><X/>".getBytes(Charsets.UTF_16BE); |
| 244 | + BOMInputStream in = new BOMInputStream(createUtf16BeDataStream(data, true)); |
| 245 | + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in)); |
| 246 | + assertNotNull(doc); |
| 247 | + assertEquals("X", doc.getFirstChild().getNodeName()); |
| 248 | + } |
| 249 | + |
| 250 | + @Test |
| 251 | + public void testReadXmlWithBOMUtf16Le() throws Exception { |
| 252 | + byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16LE\"?><X/>".getBytes(Charsets.UTF_16LE); |
| 253 | + BOMInputStream in = new BOMInputStream(createUtf16LeDataStream(data, true)); |
| 254 | + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in)); |
| 255 | + assertNotNull(doc); |
| 256 | + assertEquals("X", doc.getFirstChild().getNodeName()); |
| 257 | + } |
| 258 | + |
| 259 | + @Ignore |
| 260 | + @Test |
| 261 | + public void testReadXmlWithBOMUtf32Be() throws Exception { |
| 262 | + Assume.assumeTrue(Charset.isSupported("UTF_32BE")); |
| 263 | + byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-32BE\"?><X/>".getBytes("UTF_32BE"); |
| 264 | + BOMInputStream in = new BOMInputStream(createUtf32BeDataStream(data, true)); |
| 265 | + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in)); |
| 266 | + assertNotNull(doc); |
| 267 | + assertEquals("X", doc.getFirstChild().getNodeName()); |
| 268 | + } |
| 269 | + |
| 270 | + @Ignore |
| 271 | + @Test |
| 272 | + public void testReadXmlWithBOMUtf32Le() throws Exception { |
| 273 | + Assume.assumeTrue(Charset.isSupported("UTF_32LE")); |
| 274 | + byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-32LE\"?><X/>".getBytes("UTF_32LE"); |
| 275 | + BOMInputStream in = new BOMInputStream(createUtf32LeDataStream(data, true)); |
| 276 | + final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in)); |
| 277 | + assertNotNull(doc); |
| 278 | + assertEquals("X", doc.getFirstChild().getNodeName()); |
| 279 | + } |
| 280 | + |
222 | 281 | @Test |
223 | 282 | public void testReadWithBOMUtf16Be() throws Exception { |
224 | 283 | byte[] data = "ABC".getBytes(Charsets.UTF_16BE); |
|
0 commit comments