1 package tests.org.w3c.dom;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Node;
8 
9 import javax.xml.parsers.DocumentBuilder;
10 
11 /**
12  * The "feature" parameter in the isSupported(feature,version)" method is the
13  * name of the feature and the version is the version number of the feature to
14  * test. XXX is NOT a legal value for the feature parameter. The method should
15  * return "false" since XXX is not a valid feature.
16  *
17  * Retrieve the root node of the DOM document by invoking the
18  * "getDocumentElement()" method. This should create a node object on which the
19  * "isSupported(feature,version)" method is invoked with "feature" equal to
20  * "XXX" and version to "1.0". The method should return a boolean "false" since
21  * XXX is not a valid feature.
22  *
23  * @author NIST
24  * @author Mary Brady
25  * @see <a
26  *      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>
27  */
28 public final class IsSupported extends DOMTestCase {
29 
30     DOMDocumentBuilderFactory factory;
31 
32     DocumentBuilder builder;
33 
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         try {
37             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
38                     .getConfiguration1());
39             builder = factory.getBuilder();
40         } catch (Exception e) {
41             fail("Unexpected exception" + e.getMessage());
42         }
43     }
44 
tearDown()45     protected void tearDown() throws Exception {
46         factory = null;
47         builder = null;
48         super.tearDown();
49     }
50 
51     /**
52      * Runs the test case.
53      *
54      * @throws Throwable
55      *             Any uncaught exception causes test to fail
56      */
testIsSupported1()57     public void testIsSupported1() throws Throwable {
58         Document doc;
59         Node rootNode;
60         boolean state;
61         doc = (Document) load("staff", builder);
62         rootNode = doc.getDocumentElement();
63         state = rootNode.isSupported("XXX", "1.0");
64         assertFalse("throw_False", state);
65     }
testIsSupported2()66     public void testIsSupported2() throws Throwable {
67         Document doc;
68         Node rootNode;
69         boolean state;
70         doc = (Document) load("staff", builder);
71         rootNode = doc.getDocumentElement();
72         state = rootNode.isSupported("XML", "9.0");
73         assertFalse("throw_False", state);
74     }
testIsSupported4()75     public void testIsSupported4() throws Throwable {
76         Document doc;
77         Node rootNode;
78         boolean state;
79         doc = (Document) load("staff", builder);
80         rootNode = doc.getDocumentElement();
81         state = rootNode.isSupported("xml", "1.0");
82         assertTrue("throw_True", state);
83     }
testIsSupported5()84     public void testIsSupported5() throws Throwable {
85         Document doc;
86         Node rootNode;
87         boolean state;
88         doc = (Document) load("staff", builder);
89         rootNode = doc.getDocumentElement();
90         state = rootNode.isSupported("core", "2.0");
91         assertTrue("throw_True", state);
92     }
testIsSupported6()93     public void testIsSupported6() throws Throwable {
94         Document doc;
95         Node rootNode;
96         boolean state;
97         doc = (Document) load("staff", builder);
98         rootNode = doc.getDocumentElement();
99         state = rootNode.isSupported("xml", "2.0");
100         assertTrue("throw_True", state);
101     }
testIsSupported7()102     public void testIsSupported7() throws Throwable {
103         Document doc;
104         Node rootNode;
105         boolean state;
106         doc = (Document) load("staff", builder);
107         rootNode = doc.getDocumentElement();
108         state = rootNode.isSupported("XML", "");
109         assertTrue("throw_True", state);
110     }
testIsSupported9()111     public void testIsSupported9() throws Throwable {
112         Document doc;
113         Node rootNode;
114         boolean state;
115         doc = (Document) load("staff", builder);
116         rootNode = doc.getDocumentElement();
117         state = rootNode.isSupported("XML", "1.0");
118         assertTrue("throw_True", state);
119     }
testIsSupported10()120     public void testIsSupported10() throws Throwable {
121         Document doc;
122         Node rootNode;
123         boolean state;
124         doc = (Document) load("staff", builder);
125         rootNode = doc.getDocumentElement();
126         state = rootNode.isSupported("CORE", "2.0");
127         assertTrue("throw_True", state);
128     }
testIsSupported11()129     public void testIsSupported11() throws Throwable {
130         Document doc;
131         Node rootNode;
132         boolean state;
133         doc = (Document) load("staff", builder);
134         rootNode = doc.getDocumentElement();
135         state = rootNode.isSupported("XML", "2.0");
136         assertTrue("throw_True", state);
137     }
138 
testIsSupported12()139     public void testIsSupported12() throws Throwable {
140         List<String> features = new ArrayList<String>();
141         features.add("Core");
142         features.add("XML");
143         features.add("HTML");
144         features.add("Views");
145         features.add("StyleSheets");
146         features.add("CSS");
147         features.add("CSS2");
148         features.add("Events");
149         features.add("UIEvents");
150         features.add("MouseEvents");
151         features.add("MutationEvents");
152         features.add("HTMLEvents");
153         features.add("Range");
154         features.add("Traversal");
155         features.add("bogus.bogus.bogus");
156 
157         Document doc;
158         Node rootNode;
159         String featureElement;
160         boolean state;
161         doc = (Document) load("staff", builder);
162         rootNode = doc.getDocumentElement();
163         state = rootNode.isSupported("Core", "2.0");
164         assertTrue("Core2", state);
165         for (int indexN10078 = 0; indexN10078 < features.size(); indexN10078++) {
166             featureElement = (String) features.get(indexN10078);
167             state = rootNode.isSupported(featureElement, "1.0");
168         }
169         for (int indexN10083 = 0; indexN10083 < features.size(); indexN10083++) {
170             featureElement = (String) features.get(indexN10083);
171             state = rootNode.isSupported(featureElement, "2.0");
172         }
173     }
testIsSupported13()174     public void testIsSupported13() throws Throwable {
175         Document doc;
176         Node rootNode;
177         boolean state;
178         doc = (Document) load("staff", builder);
179         rootNode = doc.getDocumentElement();
180         state = rootNode.isSupported("Core", "");
181         assertTrue("Core", state);
182     }
testIsSupported14()183     public void testIsSupported14() throws Throwable {
184         Document doc;
185         Node rootNode;
186         boolean state;
187         String nullString = null;
188 
189         doc = (Document) load("staff", builder);
190         rootNode = doc.getDocumentElement();
191         state = rootNode.isSupported("Core", nullString);
192         assertTrue("Core", state);
193     }
194 }
195