1 23 24 package org.enhydra.xml.xmlc.html; 25 import java.io.File ; 26 import java.lang.reflect.Method ; 27 28 import junit.framework.Test; 29 30 import org.enhydra.xml.xmlc.XMLObject; 31 import org.enhydra.xml.xmlc.driver.ExecXmlc; 32 33 36 public class ExtendsTests extends HtmlTestCaseBase { 37 38 private final String [] INTERFACE_INSTANCEOF = { 39 "org.enhydra.xml.xmlc.XMLObject", 40 "org.enhydra.xml.xmlc.html.HTMLObject", 41 "org.w3c.dom.html.HTMLDocument" 42 }; 43 44 45 private final String [] INTERFACE_NOT_INSTANCEOF = { 46 "org.enhydra.xml.xmlc.XMLObjectImpl", 47 "org.enhydra.xml.xmlc.html.HTMLObjectImpl" 48 }; 49 50 51 private final String [] IMPLEMENTATION_INSTANCEOF = { 52 "org.enhydra.xml.xmlc.XMLObject", 53 "org.enhydra.xml.xmlc.XMLObjectImpl", 54 "org.enhydra.xml.xmlc.html.HTMLObject", 55 "org.enhydra.xml.xmlc.html.HTMLObjectImpl", 56 "org.w3c.dom.html.HTMLDocument" 57 }; 58 59 60 public static Test suite() { 61 return createSuite(ExtendsTests.class, null); 62 } 63 64 65 public ExtendsTests(Method method) { 66 super(method); 67 } 68 69 72 private void verifyClass(XMLObject doc, 73 Class xtraImpl) { 74 verifyIsClass(doc.getClass()); 75 verifyInstanceOf(doc.getClass(), 76 IMPLEMENTATION_INSTANCEOF); 77 if (xtraImpl != null) { 78 verifyInstanceOf(doc.getClass(), xtraImpl); 79 } 80 } 81 82 85 private void verifyInterface(Class docClass, 86 Class xtraImpl) { 87 verifyIsInterface(docClass); 88 verifyInstanceOf(docClass, 89 INTERFACE_INSTANCEOF); 90 verifyNotInstanceOf(docClass, 91 INTERFACE_NOT_INSTANCEOF); 92 if (xtraImpl != null) { 93 verifyInstanceOf(docClass, xtraImpl); 94 } 95 } 96 97 100 public void test1() { 101 HtmlBasicTest test = createTest("testPage1.html"); 102 test.addFirst(ExecXmlc.OPT_IMPLEMENTS, 103 TestPage1Interface.class.getName()); 104 test.basicTest(); 105 verifyClass(loadTestDocument(), TestPage1Interface.class); 106 } 107 108 111 public void test2() { 112 HtmlBasicTest test = createTest("testPage2.html"); 113 test.addFirst(ExecXmlc.OPT_EXTENDS, 114 HTMLObjectBase.class.getName()); 115 test.basicTest(); 116 if (fParams.getReloading()) { 117 verifyInterface(loadDocClassInterface(), null); 118 } 119 verifyClass(loadTestDocument(), HTMLObjectBase.class); 120 } 121 122 126 public void test3() { 127 HtmlBasicTest test = createTest("testPage1.html"); 128 setUsingImplInterface(); 129 test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH); 130 test.addFirst(ExecXmlc.OPT_IMPLEMENTS, 131 TestPage1Interface.class.getName()); 132 test.addOptionFile(getInputFile("testPage1.xmlc")); 133 test.basicTest(); 134 135 verifyInterface(loadDocClassInterface(), 136 TestPage1Interface.class); 137 verifyClass(loadTestDocument(), TestPage1Interface.class); 138 } 139 140 144 public void test4() { 145 HtmlBasicTest test = createTest("testPage2.html"); 146 setUsingImplInterface(); 147 test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH); 148 test.addFirst(ExecXmlc.OPT_EXTENDS, 149 HTMLObjectBase.class.getName()); 150 test.basicTest(); 151 152 verifyInterface(loadDocClassInterface(), null); 153 verifyClass(loadTestDocument(), HTMLObjectBase.class); 154 } 155 156 159 public void test5() { 160 HtmlBasicTest test = createTest("testPage3.html"); 161 setUsingImplInterface(); 162 test.addFirst(ExecXmlc.OPT_EXTENDS, 163 HTMLObjectBase.class.getName()); 164 test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_BOTH); 165 test.basicTest(); 166 verifyInterface(loadDocClassInterface(), null); 167 verifyClass(loadTestDocument(), HTMLObjectBase.class); 168 } 169 170 173 public void test6() { 174 HtmlBasicTest test = createTest("testPage3.html"); 175 setUsingImplInterface(); 176 177 test.addFirst(ExecXmlc.OPT_GENERATE, ExecXmlc.GENERATE_INTERFACE); 179 test.compileOriginalStep(); 180 181 ExecXmlc execXmlc = new ExecXmlc(this); 183 execXmlc.addOpt(ExecXmlc.OPT_GENERATE, 184 ExecXmlc.GENERATE_IMPLEMENTATION); 185 execXmlc.addOpt(ExecXmlc.OPT_CLASS, getTestClass()); 186 execXmlc.addOpt(ExecXmlc.OPT_DEST_DIR, getClassRoot()); 187 execXmlc.addClassPath(getClassRoot()); 188 execXmlc.setSrcFile(getInputFile("testPage3.html")); 189 190 File outFile2 = getResultFile("compile2.out"); 191 File expectFile2 = getExpectedFile("compile2.out"); 192 execXmlc.compile(outFile2); 193 getDiffer().diff(expectFile2, outFile2); 194 195 Class faceClass = loadDocClassInterface(); 199 verifyInterface(faceClass, null); 200 verifyClass(loadTestDocument(faceClass), faceClass); 201 202 test.reparseStep(); 204 } 205 } 206 | Popular Tags |