001: /* Copyright 2002-2004 Elliotte Rusty Harold
002:
003: This library is free software; you can redistribute it and/or modify
004: it under the terms of version 2.1 of the GNU Lesser General Public
005: License as published by the Free Software Foundation.
006:
007: This library is distributed in the hope that it will be useful,
008: but WITHOUT ANY WARRANTY; without even the implied warranty of
009: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: GNU Lesser General Public License for more details.
011:
012: You should have received a copy of the GNU Lesser General Public
013: License along with this library; if not, write to the
014: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
015: Boston, MA 02111-1307 USA
016:
017: You can contact Elliotte Rusty Harold by sending e-mail to
018: elharo@metalab.unc.edu. Please include the word "XOM" in the
019: subject line. The XOM home page is located at http://www.xom.nu/
020: */
021:
022: package nu.xom.tests;
023:
024: import java.io.ByteArrayInputStream;
025: import java.io.ByteArrayOutputStream;
026: import java.io.IOException;
027: import java.io.InputStream;
028: import java.io.UnsupportedEncodingException;
029:
030: import nu.xom.Builder;
031: import nu.xom.Document;
032: import nu.xom.Element;
033: import nu.xom.ParsingException;
034: import nu.xom.Serializer;
035:
036: /**
037: * <p>
038: * Tests support for the typical U.S. EBCDIC encoding.
039: * Unfortunately this test exposes a <a target="_top" href=
040: * "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867251">bug<a/>
041: * in the handling of NEL, character 0x85, in Sun's JDK. Specifically
042: * InputStreamReader maps 0x85 to a line feed rather than
043: * NEL. I've reported the bug to the Java Developer Connection,
044: * but until it's fixed this test fails. I don't have an easy
045: * workaround.
046: * </p>
047: *
048: * @author Elliotte Rusty Harold
049: * @version 1.0
050: *
051: */
052: public class EBCDICTest extends XOMTestCase {
053:
054: public final static char NEL = 0x85;
055:
056: public EBCDICTest(String name) {
057: super (name);
058: }
059:
060: private Document doc;
061: private String data;
062:
063: protected void setUp() {
064: Element root = new Element("r");
065: doc = new Document(root);
066: data = "\u0085";
067: root.appendChild(data);
068: }
069:
070: // This test will only pass if Java's NEL handling is fixed
071: public void testEBCDIC037() throws ParsingException,
072: UnsupportedEncodingException {
073:
074: Builder builder = new Builder();
075: ByteArrayOutputStream out = new ByteArrayOutputStream();
076: try {
077: // Write data into a byte array using encoding
078: Serializer serializer = new Serializer(out, "Cp037");
079: serializer.write(doc);
080: serializer.flush();
081: out.flush();
082: out.close();
083: byte[] result = out.toByteArray();
084:
085: // We have to look directly rather than converting to
086: // a String because Java gets the conversion of NEL to
087: // Unicode wrong
088: for (int i = 0; i < result.length; i++) {
089: if (result[i] == 0x15)
090: fail("Bad NEL output");
091: }
092:
093: InputStream in = new ByteArrayInputStream(result);
094: Document reparsed = builder.build(in);
095: assertEquals(doc, reparsed);
096: } catch (UnsupportedEncodingException ex) {
097: throw ex;
098: } catch (IOException ex) {
099: ex.printStackTrace();
100: }
101:
102: }
103:
104: }
|