Home | History | Annotate | Download | only in core
      1 
      2 /*
      3 This Java source file was generated by test-to-java.xsl
      4 and is a derived work from the source document.
      5 The source document contained the following notice:
      6 
      7 
      8 
      9 Copyright (c) 2001-2004 World Wide Web Consortium,
     10 (Massachusetts Institute of Technology, Institut National de
     11 Recherche en Informatique et en Automatique, Keio University).  All
     12 Rights Reserved.  This program is distributed under the W3C's Software
     13 Intellectual Property License.  This program is distributed in the
     14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     16 PURPOSE.
     17 
     18 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     19 
     20 
     21 */
     22 
     23 package org.w3c.domts.level2.core;
     24 
     25 import org.w3c.dom.*;
     26 
     27 
     28 import org.w3c.domts.DOMTestCase;
     29 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     30 
     31 
     32 
     33 /**
     34  *  The method "normalize" puts all Text nodes in the full depth of the sub-tree underneath
     35  *  this Node, including attribute nodes, into a "normal" form where only structure
     36  *  (e.g., elements, comments, processing instructions, CDATA sections, and entity references)
     37  *  separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
     38  *
     39  *  Create a dom tree consisting of elements, comments, processing instructions, CDATA sections,
     40  *  and entity references nodes seperated by text nodes.  Check the length of the node list of each
     41  *  before and after normalize has been called.
     42 * @author IBM
     43 * @author Neil Delima
     44 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-normalize">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-normalize</a>
     45 */
     46 public final class nodenormalize01 extends DOMTestCase {
     47 
     48    /**
     49     * Constructor.
     50     * @param factory document factory, may not be null
     51     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     52     */
     53    public nodenormalize01(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     54       super(factory);
     55 
     56     //
     57     //   check if loaded documents are supported for content type
     58     //
     59     String contentType = getContentType();
     60     preload(contentType, "staffNS", true);
     61     }
     62 
     63    /**
     64     * Runs the test case.
     65     * @throws Throwable Any uncaught exception causes test to fail
     66     */
     67    public void runTest() throws Throwable {
     68       Document doc;
     69       Document newDoc;
     70       DOMImplementation domImpl;
     71       DocumentType docType;
     72       DocumentType docTypeNull = null;
     73 
     74       Element documentElement;
     75       Element element1;
     76       Element element2;
     77       Element element3;
     78       Element element4;
     79       Element element5;
     80       Element element6;
     81       Element element7;
     82       Text text1;
     83       Text text2;
     84       Text text3;
     85       ProcessingInstruction pi;
     86       CDATASection cData;
     87       Comment comment;
     88       EntityReference entRef;
     89       NodeList elementList;
     90       Node appendedChild;
     91       doc = (Document) load("staffNS", true);
     92       domImpl = doc.getImplementation();
     93       newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "dom:root", docTypeNull);
     94       element1 = newDoc.createElement("element1");
     95       element2 = newDoc.createElement("element2");
     96       element3 = newDoc.createElement("element3");
     97       element4 = newDoc.createElement("element4");
     98       element5 = newDoc.createElement("element5");
     99       element6 = newDoc.createElement("element6");
    100       element7 = newDoc.createElement("element7");
    101       text1 = newDoc.createTextNode("text1");
    102       text2 = newDoc.createTextNode("text2");
    103       text3 = newDoc.createTextNode("text3");
    104       cData = newDoc.createCDATASection("Cdata");
    105       comment = newDoc.createComment("comment");
    106       pi = newDoc.createProcessingInstruction("PITarget", "PIData");
    107       entRef = newDoc.createEntityReference("EntRef");
    108       assertNotNull("createdEntRefNotNull", entRef);
    109       documentElement = newDoc.getDocumentElement();
    110       appendedChild = documentElement.appendChild(element1);
    111       appendedChild = element2.appendChild(text1);
    112       appendedChild = element2.appendChild(text2);
    113       appendedChild = element2.appendChild(text3);
    114       appendedChild = element1.appendChild(element2);
    115       text1 = (Text) text1.cloneNode(false);
    116       text2 = (Text) text2.cloneNode(false);
    117       appendedChild = element3.appendChild(entRef);
    118       appendedChild = element3.appendChild(text1);
    119       appendedChild = element3.appendChild(text2);
    120       appendedChild = element1.appendChild(element3);
    121       text1 = (Text) text1.cloneNode(false);
    122       text2 = (Text) text2.cloneNode(false);
    123       appendedChild = element4.appendChild(cData);
    124       appendedChild = element4.appendChild(text1);
    125       appendedChild = element4.appendChild(text2);
    126       appendedChild = element1.appendChild(element4);
    127       text2 = (Text) text2.cloneNode(false);
    128       text3 = (Text) text3.cloneNode(false);
    129       appendedChild = element5.appendChild(comment);
    130       appendedChild = element5.appendChild(text2);
    131       appendedChild = element5.appendChild(text3);
    132       appendedChild = element1.appendChild(element5);
    133       text2 = (Text) text2.cloneNode(false);
    134       text3 = (Text) text3.cloneNode(false);
    135       appendedChild = element6.appendChild(pi);
    136       appendedChild = element6.appendChild(text2);
    137       appendedChild = element6.appendChild(text3);
    138       appendedChild = element1.appendChild(element6);
    139       entRef = (EntityReference) entRef.cloneNode(false);
    140       text1 = (Text) text1.cloneNode(false);
    141       text2 = (Text) text2.cloneNode(false);
    142       text3 = (Text) text3.cloneNode(false);
    143       appendedChild = element7.appendChild(entRef);
    144       appendedChild = element7.appendChild(text1);
    145       appendedChild = element7.appendChild(text2);
    146       appendedChild = element7.appendChild(text3);
    147       appendedChild = element1.appendChild(element7);
    148       elementList = element1.getChildNodes();
    149       assertSize("nodeNormalize01_1Bef", 6, elementList);
    150       elementList = element2.getChildNodes();
    151       assertSize("nodeNormalize01_2Bef", 3, elementList);
    152       elementList = element3.getChildNodes();
    153       assertSize("nodeNormalize01_3Bef", 3, elementList);
    154       elementList = element4.getChildNodes();
    155       assertSize("nodeNormalize01_4Bef", 3, elementList);
    156       elementList = element5.getChildNodes();
    157       assertSize("nodeNormalize01_5Bef", 3, elementList);
    158       elementList = element6.getChildNodes();
    159       assertSize("nodeNormalize01_6Bef", 3, elementList);
    160       elementList = element7.getChildNodes();
    161       assertSize("nodeNormalize01_7Bef", 4, elementList);
    162       newDoc.normalize();
    163       elementList = element1.getChildNodes();
    164       assertSize("nodeNormalize01_1Aft", 6, elementList);
    165       elementList = element2.getChildNodes();
    166       assertSize("nodeNormalize01_2Aft", 1, elementList);
    167       elementList = element3.getChildNodes();
    168       assertSize("nodeNormalize01_3Aft", 2, elementList);
    169       elementList = element4.getChildNodes();
    170       assertSize("nodeNormalize01_4Aft", 2, elementList);
    171       elementList = element5.getChildNodes();
    172       assertSize("nodeNormalize01_5Aft", 2, elementList);
    173       elementList = element6.getChildNodes();
    174       assertSize("nodeNormalize01_6Aft", 2, elementList);
    175       elementList = element7.getChildNodes();
    176       assertSize("nodeNormalize01_7Aft", 2, elementList);
    177       }
    178    /**
    179     *  Gets URI that identifies the test.
    180     *  @return uri identifier of test
    181     */
    182    public String getTargetURI() {
    183       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodenormalize01";
    184    }
    185    /**
    186     * Runs this test from the command line.
    187     * @param args command line arguments
    188     */
    189    public static void main(final String[] args) {
    190         DOMTestCase.doMain(nodenormalize01.class, args);
    191    }
    192 }
    193 
    194