1 package tests.org.w3c.dom; 2 3 import dalvik.annotation.TestTargets; 4 import dalvik.annotation.TestLevel; 5 import dalvik.annotation.TestTargetNew; 6 import dalvik.annotation.TestTargetClass; 7 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import org.w3c.dom.DOMImplementation; 12 import org.w3c.dom.Document; 13 14 import javax.xml.parsers.DocumentBuilder; 15 16 /** 17 * The "feature" parameter in the "hasFeature(feature,version)" method is the 18 * package name of the feature. Legal values are XML and HTML and CORE. (Test 19 * for feature core, lower case) 20 * 21 * Retrieve the entire DOM document and invoke its "getImplementation()" method. 22 * This should create a DOMImplementation object whose "hasFeature(feature, 23 * version)" method is invoked with feature equal to "core". The method should 24 * return a boolean "true". 25 * 26 * @author NIST 27 * @author Mary Brady 28 * @see <a 29 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-5CED94D7">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-5CED94D7</a> 30 */ 31 @TestTargetClass(DOMImplementation.class) 32 public final class DOMImplementationHasFeature extends DOMTestCase { 33 34 DOMDocumentBuilderFactory factory; 35 36 DocumentBuilder builder; 37 38 protected void setUp() throws Exception { 39 super.setUp(); 40 try { 41 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 42 .getConfiguration1()); 43 builder = factory.getBuilder(); 44 } catch (Exception e) { 45 fail("Unexpected exception" + e.getMessage()); 46 } 47 } 48 49 protected void tearDown() throws Exception { 50 factory = null; 51 builder = null; 52 super.tearDown(); 53 } 54 55 /** 56 * Runs the test case. 57 * 58 * @throws Throwable 59 * Any uncaught exception causes test to fail 60 */ 61 @TestTargetNew( 62 level = TestLevel.PARTIAL, 63 notes = "Verifies that hasFeature returns true value.", 64 method = "hasFeature", 65 args = {java.lang.String.class, java.lang.String.class} 66 ) 67 public void testHasFeatureCore() throws Throwable { 68 Document doc; 69 DOMImplementation domImpl; 70 boolean state; 71 doc = (Document) load("staff", builder); 72 domImpl = doc.getImplementation(); 73 state = domImpl.hasFeature("core", "2.0"); 74 assertTrue("domimplementationFeaturecoreAssert", state); 75 } 76 @TestTargetNew( 77 level = TestLevel.PARTIAL, 78 notes = "Verifies that hasFeature returns true value.", 79 method = "hasFeature", 80 args = {java.lang.String.class, java.lang.String.class} 81 ) 82 public void testHasFeatureXml() throws Throwable { 83 Document doc; 84 DOMImplementation domImpl; 85 boolean state; 86 doc = (Document) load("staff", builder); 87 domImpl = doc.getImplementation(); 88 state = domImpl.hasFeature("xml", "2.0"); 89 assertTrue("domimplementationFeaturexmlVersion2Assert", state); 90 } 91 @TestTargetNew( 92 level = TestLevel.PARTIAL, 93 notes = "Doesn't verify that hasFeature method returns false.", 94 method = "hasFeature", 95 args = {java.lang.String.class, java.lang.String.class} 96 ) 97 public void testHasFeature1() throws Throwable { 98 Document doc; 99 DOMImplementation domImpl; 100 String version = ""; 101 String version1 = "1.0"; 102 String version2 = "2.0"; 103 String featureCore; 104 String featureXML; 105 boolean success; 106 List<String> featuresXML = new ArrayList<String>(); 107 featuresXML.add("XML"); 108 featuresXML.add("xmL"); 109 110 List<String> featuresCore = new ArrayList<String>(); 111 featuresCore.add("Core"); 112 featuresCore.add("CORE"); 113 114 doc = (Document) load("staffNS", builder); 115 domImpl = doc.getImplementation(); 116 for (int indexN10063 = 0; indexN10063 < featuresXML.size(); indexN10063++) { 117 featureXML = (String) featuresXML.get(indexN10063); 118 success = domImpl.hasFeature(featureXML, version); 119 assertTrue("domimplementationhasfeature01_XML_1", success); 120 success = domImpl.hasFeature(featureXML, version1); 121 assertTrue("domimplementationhasfeature01_XML_2", success); 122 } 123 for (int indexN1007C = 0; indexN1007C < featuresCore.size(); indexN1007C++) { 124 featureCore = (String) featuresCore.get(indexN1007C); 125 success = domImpl.hasFeature(featureCore, version); 126 assertTrue("domimplementationhasfeature01_Core_1", success); 127 success = domImpl.hasFeature(featureCore, version1); 128 success = domImpl.hasFeature(featureCore, version2); 129 assertTrue("domimplementationhasfeature01_Core_3", success); 130 } 131 } 132 @TestTargetNew( 133 level = TestLevel.PARTIAL, 134 notes = "Verifies that hasFeature method returns false.", 135 method = "hasFeature", 136 args = {java.lang.String.class, java.lang.String.class} 137 ) 138 public void testHasFeature2() throws Throwable { 139 Document doc; 140 DOMImplementation domImpl; 141 boolean success; 142 doc = (Document) load("staffNS", builder); 143 domImpl = doc.getImplementation(); 144 success = domImpl.hasFeature("Blah Blah", ""); 145 assertFalse("domimplementationhasfeature02", success); 146 } 147 } 148