|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| EBCDICTest.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 | /* Copyright 2002-2004 Elliotte Rusty Harold | |
| 2 | ||
| 3 | This library is free software; you can redistribute it and/or modify | |
| 4 | it under the terms of version 2.1 of the GNU Lesser General Public | |
| 5 | License as published by the Free Software Foundation. | |
| 6 | ||
| 7 | This library is distributed in the hope that it will be useful, | |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 | GNU Lesser General Public License for more details. | |
| 11 | ||
| 12 | You should have received a copy of the GNU Lesser General Public | |
| 13 | License along with this library; if not, write to the | |
| 14 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
| 15 | Boston, MA 02111-1307 USA | |
| 16 | ||
| 17 | You can contact Elliotte Rusty Harold by sending e-mail to | |
| 18 | elharo@metalab.unc.edu. Please include the word "XOM" in the | |
| 19 | subject line. The XOM home page is located at http://www.xom.nu/ | |
| 20 | */ | |
| 21 | ||
| 22 | package nu.xom.tests; | |
| 23 | ||
| 24 | import java.io.ByteArrayInputStream; | |
| 25 | import java.io.ByteArrayOutputStream; | |
| 26 | import java.io.IOException; | |
| 27 | import java.io.InputStream; | |
| 28 | import java.io.UnsupportedEncodingException; | |
| 29 | ||
| 30 | import nu.xom.Builder; | |
| 31 | import nu.xom.Document; | |
| 32 | import nu.xom.Element; | |
| 33 | import nu.xom.ParsingException; | |
| 34 | import nu.xom.Serializer; | |
| 35 | ||
| 36 | /** | |
| 37 | * <p> | |
| 38 | * Tests support for the typical U.S. EBCDIC encoding. | |
| 39 | * Unfortunately this test exposes a <a target="_top" href= | |
| 40 | * "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867251">bug<a/> | |
| 41 | * in the handling of NEL, character 0x85, in Sun's JDK. Specifically | |
| 42 | * InputStreamReader maps 0x85 to a line feed rather than | |
| 43 | * NEL. I've reported the bug to the Java Developer Connection, | |
| 44 | * but until it's fixed this test fails. I don't have an easy | |
| 45 | * workaround. | |
| 46 | * </p> | |
| 47 | * | |
| 48 | * @author Elliotte Rusty Harold | |
| 49 | * @version 1.0 | |
| 50 | * | |
| 51 | */ | |
| 52 | public class EBCDICTest extends XOMTestCase { | |
| 53 | ||
| 54 | public final static char NEL = 0x85; | |
| 55 | ||
| 56 | 0 | public EBCDICTest(String name) { |
| 57 | 0 | super(name); |
| 58 | } | |
| 59 | ||
| 60 | private Document doc; | |
| 61 | private String data; | |
| 62 | ||
| 63 | 0 | protected void setUp() { |
| 64 | 0 | Element root = new Element("r"); |
| 65 | 0 | doc = new Document(root); |
| 66 | 0 | data = "\u0085"; |
| 67 | 0 | root.appendChild(data); |
| 68 | } | |
| 69 | ||
| 70 | ||
| 71 | // This test will only pass if Java's NEL handling is fixed | |
| 72 | 0 | public void testEBCDIC037() |
| 73 | throws ParsingException, UnsupportedEncodingException { | |
| 74 | ||
| 75 | 0 | Builder builder = new Builder(); |
| 76 | 0 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 77 | 0 | try { |
| 78 | // Write data into a byte array using encoding | |
| 79 | 0 | Serializer serializer = new Serializer(out, "Cp037"); |
| 80 | 0 | serializer.write(doc); |
| 81 | 0 | serializer.flush(); |
| 82 | 0 | out.flush(); |
| 83 | 0 | out.close(); |
| 84 | 0 | byte[] result = out.toByteArray(); |
| 85 | ||
| 86 | // We have to look directly rather than converting to | |
| 87 | // a String because Java gets the conversion of NEL to | |
| 88 | // Unicode wrong | |
| 89 | 0 | for (int i = 0; i < result.length; i++) { |
| 90 | 0 | if (result[i] == 0x15) fail("Bad NEL output"); |
| 91 | } | |
| 92 | ||
| 93 | 0 | InputStream in = new ByteArrayInputStream(result); |
| 94 | 0 | Document reparsed = builder.build(in); |
| 95 | 0 | assertEquals(doc, reparsed); |
| 96 | } | |
| 97 | catch (UnsupportedEncodingException ex) { | |
| 98 | 0 | throw ex; |
| 99 | } | |
| 100 | catch (IOException ex) { | |
| 101 | 0 | ex.printStackTrace(); |
| 102 | } | |
| 103 | ||
| 104 | } | |
| 105 | ||
| 106 | ||
| 107 | } |
|
||||||||||