Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 146   Methods: 7
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RoundTripTest.java - 100% 100% 100%
coverage
 1    /* Copyright 2002, 2003 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   
 28    import nu.xom.Attribute;
 29    import nu.xom.Builder;
 30    import nu.xom.Document;
 31    import nu.xom.Element;
 32    import nu.xom.ParsingException;
 33    import nu.xom.Serializer;
 34   
 35    /**
 36    * <p>
 37    * This mostly verifies that white space
 38    * is properly escaped on output.
 39    * </p>
 40    *
 41    * @author Elliotte Rusty Harold
 42    * @version 1.0
 43    *
 44    */
 45    public class RoundTripTest extends XOMTestCase {
 46   
 47    private Builder builder;
 48    private Serializer serializer;
 49    private ByteArrayOutputStream out;
 50   
 51  5 public RoundTripTest(String name) {
 52  5 super(name);
 53    }
 54   
 55  5 protected void setUp() {
 56  5 builder = new Builder();
 57  5 out = new ByteArrayOutputStream();
 58  5 serializer = new Serializer(out);
 59    }
 60   
 61  1 public void testTabInAttributeValue()
 62    throws IOException, ParsingException {
 63  1 Element test = new Element("test");
 64  1 test.addAttribute(new Attribute("tab", "\t"));
 65  1 Document doc = new Document(test);
 66  1 serializer.write(doc);
 67  1 byte[] input = out.toByteArray();
 68  1 Document reparsed = builder.build(new ByteArrayInputStream(input));
 69  1 Element root = reparsed.getRootElement();
 70  1 Attribute tab = root.getAttribute("tab");
 71  1 assertEquals(
 72    "Round trip did not preserve tab in attribute value",
 73    "\t", tab.getValue()
 74    );
 75  1 assertEquals("Unexpected error on round trip", doc, reparsed);
 76    }
 77   
 78  1 public void testCarriageReturnInAttributeValue()
 79    throws IOException, ParsingException {
 80  1 Element test = new Element("test");
 81  1 test.addAttribute(new Attribute("cr", "\r"));
 82  1 Document doc = new Document(test);
 83  1 serializer.write(doc);
 84  1 byte[] input = out.toByteArray();
 85  1 Document reparsed = builder.build(new ByteArrayInputStream(input));
 86  1 Element root = reparsed.getRootElement();
 87  1 Attribute cr = root.getAttribute("cr");
 88  1 assertEquals(
 89    "Round trip did not preserve carriage return in attribute value",
 90    "\r", cr.getValue()
 91    );
 92  1 assertEquals("Unexpected error on round trip", doc, reparsed);
 93    }
 94   
 95  1 public void testCarriageReturnInText()
 96    throws IOException, ParsingException {
 97  1 Element test = new Element("test");
 98  1 test.appendChild("\r");
 99  1 Document doc = new Document(test);
 100  1 serializer.write(doc);
 101  1 byte[] input = out.toByteArray();
 102  1 Document reparsed = builder.build(new ByteArrayInputStream(input));
 103  1 Element root = reparsed.getRootElement();
 104  1 String value = root.getValue();
 105  1 assertEquals(
 106    "Round trip did not preserve carriage return in text",
 107    "\r", value
 108    );
 109  1 assertEquals("Unexpected error on round trip", doc, reparsed);
 110    }
 111   
 112  1 public void testLineFeedInAttributeValue()
 113    throws IOException, ParsingException {
 114  1 Element test = new Element("test");
 115  1 test.addAttribute(new Attribute("lf", "\n"));
 116  1 Document doc = new Document(test);
 117  1 serializer.write(doc);
 118  1 byte[] input = out.toByteArray();
 119  1 Document reparsed = builder.build(new ByteArrayInputStream(input));
 120  1 Element root = reparsed.getRootElement();
 121  1 Attribute lf = root.getAttribute("lf");
 122  1 assertEquals(
 123    "Round trip did not preserve carriage return in attribute value",
 124    "\n", lf.getValue()
 125    );
 126  1 assertEquals("Unexpected error on round trip", doc, reparsed);
 127    }
 128   
 129  1 public void testSpacesInAttributeValue()
 130    throws IOException, ParsingException {
 131  1 Element test = new Element("test");
 132  1 test.addAttribute(new Attribute("spaces", " "));
 133  1 Document doc = new Document(test);
 134  1 serializer.write(doc);
 135  1 byte[] input = out.toByteArray();
 136  1 Document reparsed = builder.build(new ByteArrayInputStream(input));
 137  1 Element root = reparsed.getRootElement();
 138  1 Attribute spaces = root.getAttribute("spaces");
 139  1 assertEquals(
 140    "Round trip did not preserve spaces in attribute value",
 141    " ", spaces.getValue()
 142    );
 143  1 assertEquals("Unexpected error on round trip", doc, reparsed);
 144    }
 145   
 146    }