Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 923   Methods: 50
NCLOC: 636   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DocTypeTest.java 100% 92% 100% 93.3%
coverage coverage
 1    /* Copyright 2002-2005 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.ByteArrayOutputStream;
 25    import java.io.IOException;
 26    import java.io.PrintStream;
 27   
 28    import org.xml.sax.SAXException;
 29    import org.xml.sax.XMLFilter;
 30    import org.xml.sax.XMLReader;
 31    import org.xml.sax.helpers.XMLFilterImpl;
 32    import org.xml.sax.helpers.XMLReaderFactory;
 33   
 34    import nu.xom.Builder;
 35    import nu.xom.DocType;
 36    import nu.xom.Document;
 37    import nu.xom.IllegalDataException;
 38    import nu.xom.IllegalNameException;
 39    import nu.xom.ParsingException;
 40    import nu.xom.ValidityException;
 41    import nu.xom.WellformednessException;
 42   
 43    /**
 44    * <p>
 45    * Various tests for the <code>DocType</code> class.
 46    * </p>
 47    *
 48    * @author Elliotte Rusty Harold
 49    * @version 1.1b4
 50    *
 51    */
 52    public class DocTypeTest extends XOMTestCase {
 53   
 54   
 55  46 public DocTypeTest(String name) {
 56  46 super(name);
 57    }
 58   
 59   
 60    String name = "MyName";
 61    String systemID = "http://www.w3.org/TR/some.dtd";
 62    String publicID = "-//Me//some public ID";
 63   
 64   
 65    // This class tests error conditions, which Xerces
 66    // annoyingly logs to System.err. This hides System.err
 67    // before each test and restores it after each test.
 68    private PrintStream systemErr = System.err;
 69    private DocType doctypePublicID;
 70    private DocType doctypeSystemID;
 71    private DocType doctypeRootOnly;
 72   
 73   
 74  46 protected void setUp() {
 75  46 doctypePublicID = new DocType(name, publicID, systemID);
 76  46 doctypeSystemID = new DocType(name, systemID);
 77  46 doctypeRootOnly = new DocType(name);
 78  46 System.setErr(new PrintStream(new ByteArrayOutputStream()));
 79    }
 80   
 81   
 82  46 protected void tearDown() {
 83  46 System.setErr(systemErr);
 84    }
 85   
 86   
 87  1 public void testToXML() {
 88   
 89  1 String expected
 90    = "<!DOCTYPE " + name + " PUBLIC \""
 91    + publicID + "\" \"" + systemID + "\">";
 92  1 assertEquals(expected, doctypePublicID.toXML());
 93  1 assertEquals(
 94    "<!DOCTYPE " + name + " SYSTEM \"" + systemID + "\">",
 95    doctypeSystemID.toXML()
 96    );
 97  1 assertEquals(
 98    "<!DOCTYPE " + name + ">",
 99    doctypeRootOnly.toXML()
 100    );
 101   
 102    }
 103   
 104   
 105  1 public void testToXMLWithInternalDTDSubset()
 106    throws ValidityException, ParsingException, IOException {
 107   
 108  1 String data = "<?xml version=\"1.0\"?>\n"
 109    + "<!DOCTYPE root [\n <!ELEMENT test (#PCDATA)>\n]>"
 110    + "\n<test />\n";
 111  1 Document doc = (new Builder()).build(data, null);
 112  1 String result = doc.toXML();
 113  1 assertEquals(data, result);
 114   
 115    }
 116   
 117   
 118  1 public void testToXMLWithCommentsInInternalDTDSubset()
 119    throws ValidityException, ParsingException, IOException {
 120   
 121  1 String data = "<?xml version=\"1.0\"?>\n"
 122    + "<!DOCTYPE root [\n" +
 123    " <!--comment-->\n <!ELEMENT test (#PCDATA)>" +
 124    "\n <!--comment-->\n]>"
 125    + "\n<test />\n";
 126  1 Document doc = (new Builder()).build(data, null);
 127  1 String result = doc.toXML();
 128  1 assertEquals(data, result);
 129   
 130    }
 131   
 132   
 133  1 public void testToXMLWithCommentsInInternalDTDSubsetAndVerifyingBuilder()
 134    throws ValidityException, ParsingException, IOException, SAXException {
 135   
 136  1 String data = "<?xml version=\"1.0\"?>\n"
 137    + "<!DOCTYPE root [\n" +
 138    " <!--comment-->\n <!ELEMENT test (#PCDATA)>" +
 139    "\n <!--comment-->\n]>"
 140    + "\n<test />\n";
 141  1 XMLFilter filter = new XMLFilterImpl();
 142  1 filter.setParent(XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"));
 143  1 Document doc = (new Builder(filter)).build(data, null);
 144  1 String result = doc.toXML();
 145  1 assertEquals(data, result);
 146   
 147    }
 148   
 149   
 150  1 public void testToXMLWithProcessingInstructionsInInternalDTDSubset()
 151    throws ValidityException, ParsingException, IOException {
 152   
 153  1 String data = "<?xml version=\"1.0\"?>\n"
 154    + "<!DOCTYPE root [\n" +
 155    " <?target data?>\n <!ELEMENT test (#PCDATA)>" +
 156    "\n <?target?>\n]>"
 157    + "\n<test />\n";
 158  1 Document doc = (new Builder()).build(data, null);
 159  1 String result = doc.toXML();
 160  1 assertEquals(data, result);
 161   
 162    }
 163   
 164   
 165  1 public void testToXMLWithProcessingInstructionsInInternalDTDSubsetAndNonverifyingBuilder()
 166    throws ValidityException, ParsingException, IOException, SAXException {
 167   
 168  1 String data = "<?xml version=\"1.0\"?>\n"
 169    + "<!DOCTYPE root [\n" +
 170    " <?target data?>\n <!ELEMENT test (#PCDATA)>" +
 171    "\n <?target?>\n]>"
 172    + "\n<test />\n";
 173  1 XMLFilter filter = new XMLFilterImpl();
 174  1 filter.setParent(XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"));
 175  1 Document doc = (new Builder(filter)).build(data, null);
 176  1 String result = doc.toXML();
 177  1 assertEquals(data, result);
 178   
 179    }
 180   
 181   
 182  1 public void testInternalDTDSubset()
 183    throws ParsingException, IOException {
 184   
 185  1 String data = "<!DOCTYPE root [ <!ELEMENT root EMPTY> ]><test/>";
 186  1 Builder builder = new Builder();
 187  1 Document doc = builder.build(data, "http://www.example.com");
 188  1 DocType doctype = doc.getDocType();
 189  1 assertEquals("root", doctype.getRootElementName());
 190  1 String internalSubset = doctype.getInternalDTDSubset();
 191  1 assertEquals(" <!ELEMENT root EMPTY>\n", internalSubset);
 192  1 assertTrue(doctype.toXML().indexOf("[") > 0);
 193  1 assertTrue(doctype.toXML().indexOf("]") > 0);
 194  1 assertTrue(doctype.toXML().indexOf("<!ELEMENT root EMPTY>") > 0);
 195   
 196    }
 197   
 198   
 199  1 public void testToString() {
 200   
 201  1 String expected
 202    = "[nu.xom.DocType: " + name + "]";
 203  1 assertEquals(expected, doctypePublicID.toString());
 204   
 205    }
 206   
 207   
 208  1 public void testConstructor1Arg() {
 209   
 210  1 String name = "MyName";
 211  1 DocType doctype = new DocType(name);
 212  1 assertEquals(name, doctype.getRootElementName());
 213  1 assertEquals("", doctype.getInternalDTDSubset());
 214  1 assertNull(doctype.getSystemID());
 215  1 assertNull(doctype.getPublicID());
 216   
 217    // legal to have a colon here
 218  1 name = "try:MyName";
 219  1 doctype = new DocType(name);
 220  1 assertEquals("", doctype.getInternalDTDSubset());
 221  1 assertEquals(name, doctype.getRootElementName());
 222  1 assertNull(doctype.getSystemID());
 223  1 assertNull(doctype.getPublicID());
 224   
 225    // illegal name
 226  1 try {
 227  1 name = "try MyName";
 228  1 doctype = new DocType(name);
 229  0 fail("allowed root element name to contain spaces");
 230    }
 231    catch (IllegalNameException success) {
 232  1 assertNotNull(success.getMessage());
 233    }
 234   
 235    }
 236   
 237   
 238  1 public void testNullRootElementName() {
 239   
 240  1 try {
 241  1 new DocType((String) null);
 242  0 fail("Allowed null root element name");
 243    }
 244    catch (IllegalNameException success) {
 245  1 assertNotNull(success.getMessage());
 246    }
 247   
 248    }
 249   
 250   
 251  1 public void testRootElementNameBeginsWithDigit() {
 252   
 253  1 try {
 254  1 new DocType("1Data");
 255  0 fail("Allowed non-namestart character in root element name");
 256    }
 257    catch (IllegalNameException success) {
 258  1 assertNotNull(success.getMessage());
 259    }
 260   
 261    }
 262   
 263   
 264  1 public void testRootElementNameBeginsWithColon() {
 265   
 266  1 try {
 267  1 new DocType(":Data");
 268  0 fail("Allowed colon to begin root element name");
 269    }
 270    catch (IllegalNameException success) {
 271  1 assertNotNull(success.getMessage());
 272    }
 273   
 274    }
 275   
 276   
 277  1 public void testSetRootElementName() {
 278   
 279  1 DocType doctype = new DocType("root");
 280  1 doctype.setRootElementName("newname");
 281  1 assertEquals("newname", doctype.getRootElementName());
 282  1 doctype.setRootElementName("new:name");
 283  1 assertEquals("new:name", doctype.getRootElementName());
 284  1 try {
 285  1 doctype.setRootElementName(":Data");
 286  0 fail("Allowed colon to begin root element name");
 287    }
 288    catch (IllegalNameException success) {
 289  1 assertNotNull(success.getMessage());
 290    }
 291   
 292    }
 293   
 294   
 295  1 public void testAllowEmptyInternalDTDSubset() {
 296   
 297  1 DocType doctype = new DocType("root");
 298  1 doctype.setInternalDTDSubset("");
 299  1 assertEquals("", doctype.getInternalDTDSubset());
 300   
 301    }
 302   
 303   
 304  1 public void testAllowNullInternalDTDSubset() {
 305   
 306  1 DocType doctype = new DocType("root");
 307  1 doctype.setInternalDTDSubset(null);
 308  1 assertEquals("", doctype.getInternalDTDSubset());
 309   
 310    }
 311   
 312   
 313  1 public void testSetInternalDTDSubset() {
 314   
 315  1 DocType doctype = new DocType("root");
 316  1 doctype.setInternalDTDSubset("<!ELEMENT test (PCDATA)>");
 317  1 assertEquals("<!ELEMENT test (PCDATA)>", doctype.getInternalDTDSubset());
 318   
 319    }
 320   
 321   
 322  1 public void testSetInternalDTDSubsetWithEntityThatPointsToNonExistentURL() {
 323   
 324  1 String subset =
 325    "<!ENTITY % test SYSTEM 'http://www.example.com/notexists.dtd'>\n"
 326    + "%test;\n";
 327  1 DocType doctype = new DocType("root");
 328  1 doctype.setInternalDTDSubset(subset);
 329  1 assertEquals(subset, doctype.getInternalDTDSubset());
 330   
 331    }
 332   
 333   
 334  1 public void testSetInternalDTDSubsetWithRelativeURL()
 335    throws ParsingException, IOException {
 336   
 337  1 Builder builder = new Builder();
 338  1 Document doc = builder.build("data/outer21.xml");
 339  1 String subset = doc.getDocType().getInternalDTDSubset();
 340  1 assertEquals(subset, subset.indexOf("file:/"), -1);
 341   
 342    }
 343   
 344   
 345  1 public void testSetInternalDTDSubsetWithRelativeURLAndCrimson()
 346    throws ParsingException, IOException {
 347   
 348  1 XMLReader crimson;
 349  1 try {
 350  1 crimson = XMLReaderFactory.createXMLReader(
 351    "org.apache.crimson.parser.XMLReaderImpl");
 352    }
 353    catch (SAXException ex) {
 354    // can't test Crimson if you can't load it
 355  0 return;
 356    }
 357  1 Builder builder = new Builder(crimson);
 358  1 Document doc = builder.build("data/outer21.xml");
 359  1 String subset = doc.getDocType().getInternalDTDSubset();
 360  1 assertEquals(subset, subset.indexOf("file:/"), -1);
 361   
 362    }
 363   
 364   
 365  1 public void testSetMalformedInternalDTDSubset() {
 366   
 367  1 DocType doctype = new DocType("root");
 368  1 try {
 369  1 doctype.setInternalDTDSubset("<!ELEMENT test (PCDATA>");
 370  0 fail("Allowed malformed internal DTD subset");
 371    }
 372    catch (WellformednessException success) {
 373  1 assertNotNull(success.getMessage());
 374    }
 375   
 376    }
 377   
 378   
 379  1 public void testEmptyRootElementName() {
 380   
 381  1 try {
 382  1 new DocType("");
 383  0 fail("Allowed empty string to be root element name");
 384    }
 385    catch (IllegalNameException success) {
 386  1 assertNotNull(success.getMessage());
 387    }
 388   
 389    }
 390   
 391   
 392  1 public void testNoChildren() {
 393   
 394  1 assertEquals(0, doctypePublicID.getChildCount());
 395  1 assertEquals(0, doctypeSystemID.getChildCount());
 396  1 assertEquals(0, doctypeRootOnly.getChildCount());
 397   
 398  1 try {
 399  1 doctypePublicID.getChild(0);
 400  0 fail("Got zeroth child");
 401    }
 402    catch (IndexOutOfBoundsException success) {
 403  1 assertNotNull(success.getMessage());
 404    }
 405   
 406    }
 407   
 408   
 409  1 public void testConstructor2Arg() {
 410   
 411  1 String name = "MyName";
 412  1 String systemID = "http://www.w3.org/TR/some.dtd";
 413  1 DocType doctype = new DocType(name, systemID);
 414  1 assertEquals(name, doctype.getRootElementName());
 415  1 assertEquals("", doctype.getInternalDTDSubset());
 416  1 assertEquals(systemID, doctype.getSystemID());
 417  1 assertNull(doctype.getPublicID());
 418   
 419    // empty system ID
 420  1 name = "try:MyName";
 421  1 systemID = "";
 422  1 doctype = new DocType(name, systemID);
 423  1 assertEquals(name, doctype.getRootElementName());
 424  1 assertEquals("", doctype.getInternalDTDSubset());
 425  1 assertEquals(systemID, doctype.getSystemID());
 426  1 assertNull(doctype.getPublicID());
 427   
 428    }
 429   
 430   
 431  1 public void testConstructor3Arg() {
 432   
 433  1 String name = "MyName";
 434  1 String systemID = "http://www.w3.org/TR/some.dtd";
 435  1 String publicID = "-//Me//some public ID";
 436  1 DocType doctype = new DocType(name, publicID, systemID);
 437  1 assertEquals(name, doctype.getRootElementName());
 438  1 assertEquals("", doctype.getInternalDTDSubset());
 439  1 assertEquals(systemID, doctype.getSystemID());
 440  1 assertEquals(publicID, doctype.getPublicID());
 441   
 442    }
 443   
 444   
 445  1 public void testEmptyStringForPublicID() {
 446   
 447  1 String name = "MyName";
 448  1 String systemID = "http://www.w3.org/TR/some.dtd";
 449  1 String publicID = "";
 450  1 DocType doctype = new DocType(name, publicID, systemID);
 451  1 assertEquals(name, doctype.getRootElementName());
 452  1 assertEquals("", doctype.getInternalDTDSubset());
 453  1 assertEquals(systemID, doctype.getSystemID());
 454  1 assertEquals(publicID, doctype.getPublicID());
 455   
 456    }
 457   
 458   
 459  1 public void testEmptyStringForSystemID() {
 460   
 461  1 String name = "MyName";
 462  1 String systemID = "";
 463  1 String publicID = "-//Me//some public ID";
 464  1 DocType doctype = new DocType(name, publicID, systemID);
 465  1 assertEquals(name, doctype.getRootElementName());
 466  1 assertEquals("", doctype.getInternalDTDSubset());
 467  1 assertEquals(systemID, doctype.getSystemID());
 468  1 assertEquals(publicID, doctype.getPublicID());
 469   
 470    }
 471   
 472   
 473  1 public void testIllegalPublicIDs() {
 474   
 475    // PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
 476  1 for (char c = 0; c <= 0x9; c++) {
 477  10 try {
 478  10 checkPublicIDCharacter(c + "");
 479  0 fail("Allowed bad public ID character "
 480    + Integer.toHexString(c));
 481    }
 482    catch (WellformednessException success) {
 483    // successfully detected bad public ID
 484  10 assertNotNull(success.getMessage());
 485    }
 486    }
 487  1 for (char c = 0xB; c < 0xD; c++) {
 488  2 try {
 489  2 checkPublicIDCharacter(c + "");
 490  0 fail("Allowed bad public ID character "
 491    + Integer.toHexString(c));
 492    }
 493    catch (WellformednessException success) {
 494    // successfully detected bad public ID
 495  2 assertNotNull(success.getMessage());
 496    }
 497    }
 498  1 for (char c = 0xE; c < 0x20; c++) {
 499  18 try {
 500  18 checkPublicIDCharacter(c + "");
 501  0 fail("Allowed bad public ID character "
 502    + Integer.toHexString(c));
 503    }
 504    catch (WellformednessException success) {
 505    // successfully detected bad public ID
 506  18 assertNotNull(success.getMessage());
 507    }
 508    }
 509  1 for (char c = '~'; c < 1000; c++) {
 510  874 try {
 511  874 checkPublicIDCharacter(c + "");
 512  0 fail("Allowed bad public ID character "
 513    + Integer.toHexString(c));
 514    }
 515    catch (WellformednessException success) {
 516    // successfully detected bad public ID
 517  874 assertNotNull(success.getMessage());
 518    }
 519    }
 520   
 521  1 char[] illegalPunctuationMarks = "<>`^&\"[]{}|\\~".toCharArray();
 522  1 for (int i = 0; i < illegalPunctuationMarks.length; i++) {
 523  13 char c = illegalPunctuationMarks[i];
 524  13 try {
 525  13 checkPublicIDCharacter(c + "");
 526  0 fail("Allowed bad public ID character "
 527    + Integer.toHexString(c));
 528    }
 529    catch (WellformednessException success) {
 530    // successfully detected bad public ID
 531  13 assertNotNull(success.getMessage());
 532    }
 533    }
 534   
 535    }
 536   
 537   
 538  1 public void testLegalPublicIDs() {
 539   
 540    // PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
 541    // should public IDs allow initial and trailing space? No.
 542    // These are normalized like attribute values according to
 543    // section 4.2.2 of the XML spec.
 544    // This also means charriage returns and linefeeds are
 545    // not roundtrippable. They can appear in the document but not
 546    // the infoset so XOM forbids them.
 547  1 checkPublicIDCharacter("-'()+,./:=?;!*#@$_%");
 548  26 for (char c = 'a'; c <= 'z'; c++) checkPublicIDCharacter(c + "");
 549  26 for (char c = 'A'; c <= 'Z'; c++) checkPublicIDCharacter(c + "");
 550  10 for (char c = '0'; c <= '9'; c++) checkPublicIDCharacter(c + "");
 551   
 552    }
 553   
 554   
 555  1 public void testSpaceContainingPublicIDs() {
 556   
 557    // According to section 4.2.2 of the XML spec, public IDs are
 558    // normalized like attribute values of non-CDATA type
 559  1 try {
 560  1 new DocType("root", " test", "http://www.example.org");
 561  0 fail("allowed initial space in public ID");
 562    }
 563    catch (WellformednessException success) {
 564  1 assertNotNull(success.getMessage());
 565    }
 566   
 567  1 try {
 568  1 new DocType("root", "test ", "http://www.example.org");
 569  0 fail("allowed trailing space in public ID");
 570    }
 571    catch (WellformednessException success) {
 572  1 assertNotNull(success.getMessage());
 573    }
 574   
 575  1 try {
 576  1 new DocType("root", "test\ntest", "http://www.example.org");
 577  0 fail("allowed linefeed public ID");
 578    }
 579    catch (WellformednessException success) {
 580  1 assertNotNull(success.getMessage());
 581    }
 582   
 583  1 try {
 584  1 new DocType("root", "test\rtest", "http://www.example.org");
 585  0 fail("allowed carriage return in public ID");
 586    }
 587    catch (WellformednessException success) {
 588  1 assertNotNull(success.getMessage());
 589    }
 590   
 591  1 try {
 592  1 new DocType("root", "test\r\ntest", "http://www.example.org");
 593  0 fail("allowed carriage return linefeed pair public ID");
 594    }
 595    catch (WellformednessException success) {
 596  1 assertNotNull(success.getMessage());
 597    }
 598   
 599  1 try {
 600  1 new DocType("root", "test test", "http://www.example.org");
 601  0 fail("allowed multiple consecutive spaces in public ID");
 602    }
 603    catch (WellformednessException success) {
 604  1 assertNotNull(success.getMessage());
 605    }
 606   
 607    // one space is legal
 608  1 DocType test = new DocType("root", "test test", "http://www.example.org");
 609  1 assertEquals(test.getPublicID(), "test test");
 610   
 611    }
 612   
 613   
 614  1 public void testSystemIDWithDollarSignAndComma() {
 615   
 616  1 String systemID = "http://www.example.com/test$red/limit,data.xml";
 617  1 DocType doctype = new DocType("root", systemID);
 618  1 assertEquals(systemID, doctype.getSystemID());
 619   
 620    }
 621   
 622   
 623  1 public void testSystemIDWithSemicolon() {
 624   
 625  1 String systemID = "smb://domain;user:pass@server/share/path/to/file";
 626  1 DocType doctype = new DocType("root", systemID);
 627  1 assertEquals(systemID, doctype.getSystemID());
 628   
 629    }
 630   
 631   
 632  1 public void testIllegalSystemIDs() {
 633   
 634    // "It is an error for a fragment identifier
 635    // (beginning with a # character)
 636    // to be part of a system identifier."
 637  1 try {
 638  1 new DocType("test", "http://www.example.com/index.html#test");
 639  0 fail("Allowed system ID with fragment identifier");
 640    }
 641    catch (IllegalDataException success) {
 642    // successfully detected bad system ID
 643  1 assertNotNull(success.getMessage());
 644    }
 645   
 646  1 try {
 647  1 new DocType("test", "http://www.example.com/index.html#");
 648  0 fail("Allowed # in system ID");
 649    }
 650    catch (IllegalDataException success) {
 651    // successfully detected bad system ID
 652  1 assertNotNull(success.getMessage());
 653    }
 654   
 655  1 try {
 656  1 new DocType("test", "http://www.example.com/\u00A9.html#");
 657  0 fail("Allowed non-ASCII character in system ID");
 658    }
 659    catch (IllegalDataException success) {
 660    // successfully detected bad system ID
 661  1 assertNotNull(success.getMessage());
 662    }
 663   
 664  1 try {
 665  1 new DocType("test", "http://www.example.com/\u0007.html#");
 666  0 fail("Allowed C0 control character in system ID");
 667    }
 668    catch (IllegalDataException success) {
 669    // successfully detected bad system ID
 670  1 assertNotNull(success.getMessage());
 671    }
 672   
 673  1 try {
 674  1 new DocType("test", "test\" and ' in the same ID");
 675  0 fail("Allowed both \" and ' in system ID");
 676    }
 677    catch (IllegalDataException success) {
 678    // successfully detected bad system ID
 679  1 assertNotNull(success.getMessage());
 680    }
 681   
 682    }
 683   
 684   
 685  980 void checkPublicIDCharacter(String publicID) {
 686  980 String name = "MyName";
 687  980 String systemID = "http://www.w3.org/TR/some.dtd";
 688  980 DocType doctype = new DocType(name, publicID, systemID);
 689  63 assertEquals(publicID, doctype.getPublicID());
 690    }
 691   
 692   
 693  1 public void testClone() {
 694   
 695  1 String name = "MyName";
 696  1 String systemID = "http://www.w3.org/TR/some.dtd";
 697  1 String publicID = "-//Me//some public ID";
 698  1 DocType doctype = new DocType(name, publicID, systemID);
 699   
 700  1 DocType other = (DocType) doctype.copy();
 701   
 702  1 assertEquals(
 703    doctype.getRootElementName(),
 704    other.getRootElementName());
 705  1 assertEquals(
 706    doctype.getInternalDTDSubset(),
 707    other.getInternalDTDSubset()
 708    );
 709  1 assertEquals(doctype.getSystemID(), other.getSystemID());
 710  1 assertEquals(doctype.getPublicID(), other.getPublicID());
 711  1 assertTrue(!other.equals(doctype));
 712   
 713    }
 714   
 715   
 716  1 public void testGetters() {
 717   
 718  1 String name = "MyName";
 719  1 String systemID = "http://www.w3.org/TR/some.dtd";
 720  1 String publicID = "-//Me//some public ID";
 721  1 DocType doctype = new DocType(name, publicID, systemID);
 722   
 723  1 assertEquals("", doctype.getValue());
 724   
 725    }
 726   
 727   
 728  1 public void testSystemIDRequiredForPublicID() {
 729   
 730  1 String name = "MyName";
 731  1 DocType doctype = new DocType(name);
 732   
 733  1 try {
 734  1 doctype.setPublicID("-//Me//some public ID");
 735  0 fail("created a doctype with a public ID and no system ID");
 736    }
 737    catch (WellformednessException ex) {
 738    // success
 739  1 assertNotNull(ex.getMessage());
 740    }
 741   
 742    }
 743   
 744   
 745  1 public void testRemove() {
 746   
 747  1 String name = "MyName";
 748  1 String publicID = "-//Me//some public ID";
 749  1 DocType doctype =
 750    new DocType(name, publicID, "http://www.example.com");
 751   
 752  1 doctype.setPublicID(null);
 753  1 assertNull(doctype.getPublicID());
 754  1 doctype.setPublicID(publicID);
 755  1 assertEquals(publicID, doctype.getPublicID());
 756   
 757  1 try {
 758  1 doctype.setSystemID(null);
 759  0 fail("removed system ID before removing public ID");
 760    }
 761    catch (WellformednessException success) {
 762  1 assertNotNull(success.getMessage());
 763    }
 764   
 765  1 doctype.setPublicID(null);
 766  1 assertNull(doctype.getPublicID());
 767  1 doctype.setSystemID(null);
 768  1 assertNull(doctype.getSystemID());
 769   
 770    }
 771   
 772   
 773  1 public void testCarriageReturnInEntityReplacementTextInInternalDTDSubset()
 774    throws ParsingException, IOException {
 775   
 776  1 Builder builder = new Builder();
 777  1 String data = "<!DOCTYPE root ["
 778    + "<!ENTITY CR '&#13;'>"
 779    + "]><root/>";
 780  1 Document doc = builder.build(data, null);
 781  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 782  1 assertTrue(internalDTDSubset.indexOf("<!ENTITY CR \"&#x0D;\">") > 1);
 783   
 784    }
 785   
 786   
 787  1 public void testCarriageReturnInAttributeDefaultValueInInternalDTDSubset()
 788    throws ParsingException, IOException {
 789   
 790  1 Builder builder = new Builder();
 791  1 String data = "<!DOCTYPE root ["
 792    + "<!ATTLIST root attribute CDATA '&#13;'>"
 793    + "]><root/>";
 794  1 Document doc = builder.build(data, null);
 795  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 796  1 assertTrue(internalDTDSubset.indexOf("<!ATTLIST root attribute CDATA \"&#x0D;\">") > 1);
 797   
 798    }
 799   
 800   
 801  1 public void testQuotationMarksInNotationDeclarationInInternalDTDSubset()
 802    throws ParsingException, IOException {
 803   
 804  1 Builder builder = new Builder();
 805  1 String data = "<!DOCTYPE root [\n"
 806    + "<!NOTATION not2 SYSTEM 'a b\"\"\"'>\n"
 807    + "]><root />";
 808  1 Document doc = builder.build(data, null);
 809  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 810  1 assertEquals(" <!NOTATION not2 SYSTEM \"a b&#x22;&#x22;&#x22;\">\n", internalDTDSubset);
 811   
 812    }
 813   
 814   
 815  1 public void testAmpersandInEntityReplacementTextInInternalDTDSubset()
 816    throws ParsingException, IOException {
 817   
 818  1 Builder builder = new Builder();
 819  1 String data = "<!DOCTYPE root ["
 820    + "<!ENTITY amp2 '&amp;'>"
 821    + "]><root/>";
 822  1 Document doc = builder.build(data, null);
 823  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 824  1 assertTrue(internalDTDSubset.indexOf("<!ENTITY amp2 \"&#x26;amp;\">") > 1);
 825   
 826    }
 827   
 828   
 829  1 public void testAmpersandInAttributeDefaultValueInInternalDTDSubset()
 830    throws ParsingException, IOException {
 831   
 832  1 Builder builder = new Builder();
 833  1 String data = "<!DOCTYPE root ["
 834    + "<!ATTLIST root attribute CDATA '&amp;'>"
 835    + "]><root/>";
 836  1 Document doc = builder.build(data, null);
 837  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 838  1 assertTrue(internalDTDSubset.indexOf(
 839    "<!ATTLIST root attribute CDATA \"&amp;\">") > 1
 840    );
 841   
 842    }
 843   
 844   
 845  1 public void testDoubleQuoteInAttributeDefaultValueInInternalDTDSubset()
 846    throws ParsingException, IOException {
 847   
 848  1 Builder builder = new Builder();
 849  1 String data = "<!DOCTYPE root ["
 850    + "<!ATTLIST root attribute CDATA '&quot;'>"
 851    + "]><root/>";
 852  1 Document doc = builder.build(data, null);
 853  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 854  1 assertTrue(internalDTDSubset.indexOf(
 855    "<!ATTLIST root attribute CDATA \"&quot;\">") > 1
 856    );
 857   
 858    }
 859   
 860   
 861  1 public void testSingleQuoteInAttributeDefaultValueInInternalDTDSubset()
 862    throws ParsingException, IOException {
 863   
 864  1 Builder builder = new Builder();
 865  1 String data = "<!DOCTYPE root ["
 866    + "<!ATTLIST root attribute CDATA '&apos;'>"
 867    + "]><root/>";
 868  1 Document doc = builder.build(data, null);
 869  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 870  1 assertTrue(internalDTDSubset.indexOf(
 871    "<!ATTLIST root attribute CDATA \"'\">") > 1
 872    );
 873   
 874    }
 875   
 876   
 877  1 public void testLessThanSignInAttributeDefaultValueInInternalDTDSubset()
 878    throws ParsingException, IOException {
 879   
 880  1 Builder builder = new Builder();
 881  1 String data = "<!DOCTYPE root ["
 882    + "<!ATTLIST root attribute CDATA '&lt;'>"
 883    + "]><root/>";
 884  1 Document doc = builder.build(data, null);
 885  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 886  1 assertTrue(internalDTDSubset.indexOf(
 887    "<!ATTLIST root attribute CDATA \"&lt;\">") > 1
 888    );
 889   
 890    }
 891   
 892   
 893  1 public void testGreaterThanSignInAttributeDefaultValueInInternalDTDSubset()
 894    throws ParsingException, IOException {
 895   
 896  1 Builder builder = new Builder();
 897  1 String data = "<!DOCTYPE root ["
 898    + "<!ATTLIST root attribute CDATA '>'>"
 899    + "]><root/>";
 900  1 Document doc = builder.build(data, null);
 901  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 902  1 assertTrue(internalDTDSubset.indexOf(
 903    "<!ATTLIST root attribute CDATA \">\">") > 1
 904    );
 905   
 906    }
 907   
 908   
 909  1 public void testDoubleQuoteInEntityReplacementTextInInternalDTDSubset()
 910    throws ParsingException, IOException {
 911   
 912  1 Builder builder = new Builder();
 913  1 String data = "<!DOCTYPE root ["
 914    + "<!ENTITY q2 '&quot;'>"
 915    + "]><root/>";
 916  1 Document doc = builder.build(data, null);
 917  1 String internalDTDSubset = doc.getDocType().getInternalDTDSubset();
 918  1 assertTrue(internalDTDSubset.indexOf("<!ENTITY q2 \"&#x26;quot;\">") > 1);
 919   
 920    }
 921   
 922   
 923    }