Home | History | Annotate | Download | only in dom
      1 /*
      2  This Java source file was generated by test-to-java.xsl
      3  and is a derived work from the source document.
      4  The source document contained the following notice:
      5 
      6 
      7 
      8  Copyright (c) 2001-2003 World Wide Web Consortium,
      9  (Massachusetts Institute of Technology, Institut National de
     10  Recherche en Informatique et en Automatique, Keio University).  All
     11  Rights Reserved.  This program is distributed under the W3C's Software
     12  Intellectual Property License.  This program is distributed in the
     13  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     15  PURPOSE.
     16 
     17  See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     18 
     19 
     20  */
     21 
     22 package tests.org.w3c.dom;
     23 
     24 import dalvik.annotation.TestTargets;
     25 import dalvik.annotation.TestLevel;
     26 import dalvik.annotation.TestTargetNew;
     27 import dalvik.annotation.TestTargetClass;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 import org.w3c.dom.Node;
     33 import org.w3c.dom.Document;
     34 import org.w3c.dom.Element;
     35 import org.w3c.dom.Attr;
     36 import org.w3c.dom.DocumentType;
     37 import org.w3c.dom.EntityReference;
     38 import org.w3c.dom.ProcessingInstruction;
     39 
     40 import javax.xml.parsers.DocumentBuilder;
     41 
     42 /**
     43  * The method "isSupported(feature,version)" Tests whether the DOM
     44  * implementation implements a specific feature and that feature is supported by
     45  * this node.
     46  *
     47  * Call the isSupported method on the document element node with a combination
     48  * of features versions and versions as below. Valid feature names are case
     49  * insensitive and versions "2.0", "1.0" and if the version is not specified,
     50  * supporting any version of the feature should return true. Check if the value
     51  * returned value was true.
     52  *
     53  * @author IBM
     54  * @author Neil Delima
     55  * @see <a
     56  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-Node-supports">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-Node-supports</a>
     57  */
     58 @TestTargetClass(Node.class)
     59 public final class NodeIsSupported extends DOMTestCase {
     60 
     61     DOMDocumentBuilderFactory factory;
     62 
     63     DocumentBuilder builder;
     64 
     65     protected void setUp() throws Exception {
     66         super.setUp();
     67         try {
     68             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     69                     .getConfiguration1());
     70             builder = factory.getBuilder();
     71         } catch (Exception e) {
     72             fail("Unexpected exception" + e.getMessage());
     73         }
     74     }
     75 
     76     protected void tearDown() throws Exception {
     77         factory = null;
     78         builder = null;
     79         super.tearDown();
     80     }
     81 
     82     /**
     83      * Runs the test case.
     84      *
     85      * @throws Throwable
     86      *             Any uncaught exception causes test to fail
     87      */
     88     @TestTargetNew(
     89         level = TestLevel.PARTIAL,
     90         notes = "Doesn't verify that isSupported method can return false value.",
     91         method = "isSupported",
     92         args = {java.lang.String.class, java.lang.String.class}
     93     )
     94     public void testIsSupported1() throws Throwable {
     95         Document doc;
     96         Element element;
     97         String version = "";
     98         String version1 = "1.0";
     99         String version2 = "2.0";
    100         String featureCore;
    101         String featureXML;
    102         boolean success;
    103         List<String> featuresXML = new ArrayList<String>();
    104         featuresXML.add("XML");
    105         featuresXML.add("xmL");
    106 
    107         List<String> featuresCore = new ArrayList<String>();
    108         featuresCore.add("Core");
    109         featuresCore.add("CORE");
    110 
    111         doc = (Document) load("staffNS", builder);
    112         element = doc.getDocumentElement();
    113         for (int indexN10063 = 0; indexN10063 < featuresXML.size(); indexN10063++) {
    114             featureXML = (String) featuresXML.get(indexN10063);
    115             success = element.isSupported(featureXML, version);
    116             assertTrue("nodeissupported01_XML1", success);
    117             success = element.isSupported(featureXML, version1);
    118             assertTrue("nodeissupported01_XML2", success);
    119         }
    120         for (int indexN1007C = 0; indexN1007C < featuresCore.size(); indexN1007C++) {
    121             featureCore = (String) featuresCore.get(indexN1007C);
    122             success = element.isSupported(featureCore, version);
    123             assertTrue("nodeissupported01_Core1", success);
    124             success = element.isSupported(featureCore, version1);
    125             success = element.isSupported(featureCore, version2);
    126             assertTrue("nodeissupported01_Core3", success);
    127         }
    128     }
    129     @TestTargetNew(
    130         level = TestLevel.PARTIAL,
    131         notes = "Doesn't verify that isSupported method can return false value.",
    132         method = "isSupported",
    133         args = {java.lang.String.class, java.lang.String.class}
    134     )
    135     public void testIsSupported2() throws Throwable {
    136         Document doc;
    137         Attr attribute;
    138         String version = "";
    139         String version1 = "1.0";
    140         String version2 = "2.0";
    141         String featureCore;
    142         String featureXML;
    143         boolean success;
    144         List<String> featuresXML = new ArrayList<String>();
    145         featuresXML.add("XML");
    146         featuresXML.add("xmL");
    147 
    148         List<String> featuresCore = new ArrayList<String>();
    149         featuresCore.add("Core");
    150         featuresCore.add("CORE");
    151 
    152         doc = (Document) load("staffNS", builder);
    153         attribute = doc.createAttribute("TestAttr");
    154         for (int indexN10064 = 0; indexN10064 < featuresXML.size(); indexN10064++) {
    155             featureXML = (String) featuresXML.get(indexN10064);
    156             success = attribute.isSupported(featureXML, version);
    157             assertTrue("nodeissupported02_XML1", success);
    158             success = attribute.isSupported(featureXML, version1);
    159             assertTrue("nodeissupported02_XML2", success);
    160         }
    161         for (int indexN1007D = 0; indexN1007D < featuresCore.size(); indexN1007D++) {
    162             featureCore = (String) featuresCore.get(indexN1007D);
    163             success = attribute.isSupported(featureCore, version);
    164             assertTrue("nodeissupported02_Core1", success);
    165             success = attribute.isSupported(featureCore, version1);
    166             success = attribute.isSupported(featureCore, version2);
    167             assertTrue("nodeissupported02_Core3", success);
    168         }
    169     }
    170     @TestTargetNew(
    171         level = TestLevel.PARTIAL,
    172         notes = "Verifies that isSupported method returns false value if it's called with empty strings as parameters.",
    173         method = "isSupported",
    174         args = {java.lang.String.class, java.lang.String.class}
    175     )
    176     public void testIsSupported3() throws Throwable {
    177         Document doc;
    178         DocumentType docType;
    179         boolean success;
    180         doc = (Document) load("staffNS", builder);
    181         docType = doc.getDoctype();
    182         success = docType.isSupported("", "");
    183         assertFalse("nodeissupported03", success);
    184     }
    185     @TestTargetNew(
    186         level = TestLevel.PARTIAL,
    187         notes = "Verifies that isSupported method returns false value.",
    188         method = "isSupported",
    189         args = {java.lang.String.class, java.lang.String.class}
    190     )
    191     public void testIsSupported4() throws Throwable {
    192         Document doc;
    193         EntityReference entRef;
    194         boolean success;
    195         doc = (Document) load("staffNS", builder);
    196         entRef = doc.createEntityReference("ent1");
    197         assertNotNull("createdEntRefNotNull", entRef);
    198         success = entRef.isSupported("XML CORE", "");
    199         assertFalse("nodeissupported04", success);
    200     }
    201     @TestTargetNew(
    202         level = TestLevel.PARTIAL,
    203         notes = "Verifies that isSupported method returns false value.",
    204         method = "isSupported",
    205         args = {java.lang.String.class, java.lang.String.class}
    206     )
    207     public void testIsSupported5() throws Throwable {
    208         Document doc;
    209         ProcessingInstruction pi;
    210         boolean success;
    211         doc = (Document) load("staffNS", builder);
    212         pi = doc.createProcessingInstruction("PITarget", "PIData");
    213         success = pi.isSupported("-", "+");
    214         assertFalse("nodeissupported05", success);
    215     }
    216 }
    217