KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > html > MiscOptionsTests


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: MiscOptionsTests.java,v 1.2 2005/01/26 08:29:25 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.html;
25 import java.io.File JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.enhydra.xml.driver.TestError;
31 import org.enhydra.xml.driver.TestFileOps;
32 import org.enhydra.xml.xmlc.XMLObject;
33 import org.enhydra.xml.xmlc.driver.ExecXmlc;
34
35 /**
36  * Tests of various compilation options not tested elsewhere.
37  */

38 public class MiscOptionsTests extends HtmlTestCaseBase {
39     /** Factory method to create suite of these tests */
40     public static Test suite() {
41         return createSuite(MiscOptionsTests.class, null);
42     }
43     
44     /** Constructor */
45     public MiscOptionsTests(Method JavaDoc method) {
46         super(method);
47     }
48
49     /**
50      * Class used to implement tests that run the compiler with different
51      * options. Extended to implement the test.
52      */

53     private abstract class OptTest {
54         protected ExecXmlc fExecXmlc;
55
56         /** Constructor, set up ExecXmlc object for test */
57         protected OptTest() {
58             fExecXmlc = new ExecXmlc(MiscOptionsTests.this);
59             fExecXmlc.addOpt(ExecXmlc.OPT_DEST_DIR,
60                              getClassRoot().getPath());
61         }
62
63         /** Add the standard -class option */
64         protected void addClass() {
65             fExecXmlc.addOpt(ExecXmlc.OPT_CLASS, getTestClass());
66         }
67
68         /** Use input/testPage1.html as the imput file. */
69         protected void setTestPage1() {
70             fExecXmlc.setSrcFile(getInputFile("testPage1.html"));
71         }
72
73         /** Compile the file and verify the output */
74         protected void compile() {
75             fExecXmlc.compile(getResultFile(COMPILE_OUTPUT_EXT));
76             getDiffer().diff(getExpectedFile(COMPILE_OUTPUT_EXT),
77                              getResultFile(COMPILE_OUTPUT_EXT));
78         }
79         
80         /**
81          * Setup and run the basic test; should add specific options before
82          * calling.
83          */

84         public void basicTest() {
85             addClass();
86             setTestPage1();
87             compile();
88         }
89
90         /** This method is implemented to run the test */
91         public abstract void run();
92     }
93
94     /*
95      * Test 1: proprietary tags
96      */

97     public void test1() {
98         HtmlBasicTest test = createTest("proptags1.html");
99         test.addOptionFile(getInputFile("proptags1.xmlc"));
100         test.basicTest();
101     }
102
103     /*
104      * Test 2: Keep, outdir, etc.
105      */

106     public void test2() {
107         new OptTest() {
108             public void run() {
109                 // Assemble output file paths, and remove existing files
110
File JavaDoc genSrcFile = getGenSrcFile();
111                 removeFile(genSrcFile);
112                 File JavaDoc genClassFile = getGenClassFile();
113                 removeFile(genClassFile);
114
115                 fExecXmlc.addOpt(ExecXmlc.OPT_SOURCE_OUT,
116                                  getGenSourceDir().getPath());
117                 fExecXmlc.addOpt(ExecXmlc.OPT_KEEP);
118                 basicTest();
119                 verifyExists(genSrcFile);
120                 verifyExists(genClassFile);
121             }
122         }.run();
123     }
124
125     /*
126      * Test 3: Default package, class name from source file
127      */

128     public void test3() {
129         new OptTest() {
130             public void run() {
131                 // Assemble class and remove existing files
132
File JavaDoc genClassFile = new File JavaDoc(getClassRoot(),
133                                              "testPage1.class");
134                 removeFile(genClassFile);
135                 setTestPage1();
136                 compile();
137                 verifyExists(genClassFile);
138             }
139         }.run();
140     }
141
142     /*
143      * Test 4: Two .xmlc files
144      */

145     public void test4() {
146         HtmlBasicTest test = createTest("testPage1.html");
147         test.addCyberStudioTags();
148         test.addOptionFile(getInputFile("test-11.1a.xmlc"));
149         test.addOptionFile(getInputFile("test-11.1b.xmlc"));
150         test.basicTest();
151     }
152
153     /*
154      * Test 5: HTML Compatibility options for older versions of XMLC.
155      */

156     public void test5() {
157         HtmlBasicTest test = createLutrisIndexTest();
158         test.addCyberStudioTags();
159         test.addBoth("-html:old-class-constants");
160         test.addBoth("-html:old-name-constants");
161         test.addOptionFile(getInputFile("lutris-index1.xmlc"));
162         test.basicTest();
163     }
164
165     /*
166      * Test 6: -javacflag
167      */

168     public void test6() {
169         new OptTest() {
170             public void run() {
171                 fExecXmlc.addOpt(ExecXmlc.OPT_JAVAC_FLAG, "-nowarn");
172                 basicTest();
173             }
174         }.run();
175     }
176
177     /*
178      * Test 7: -javacopt
179      */

180     public void test7() {
181         // -encoding doesn't work for jikes, so skip
182
if (!fParams.getUsingJikes()) {
183             new OptTest() {
184                 public void run() {
185                     fExecXmlc.addOpt(ExecXmlc.OPT_JAVAC_OPT);
186                     fExecXmlc.addOpt("-encoding", "US-ASCII");
187                     basicTest();
188                 }
189             }.run();
190         }
191     }
192
193     /*
194      * Test 8: -dom
195      */

196     public void test8() {
197         new OptTest() {
198             public void run() {
199                 fExecXmlc.setDomOpt(ExecXmlc.OPT_DOM, getParams().getDom());
200                 basicTest();
201                 XMLObject doc = loadTestDocument(getTestClass());
202                 dumpVerifyDom(doc, DOC_DOM_DUMP_EXT);
203             }
204         }.run();
205     }
206
207     /*
208      * Test 9: -domfactory
209      */

210     public void test9() {
211         new OptTest() {
212             public void run() {
213                 if (getParams().getDom().equals(ExecXmlc.XERCES_DOM)) {
214                     fExecXmlc.setDomOpt(ExecXmlc.OPT_DOM_FACTORY,
215                                         ExecXmlc.XERCES_HTML_DOM_FACTORY);
216                 } else if (getParams().getDom().equals(ExecXmlc.LAZY_DOM)) {
217                     fExecXmlc.setDomOpt(ExecXmlc.OPT_DOM_FACTORY,
218                                         ExecXmlc.LAZY_HTML_DOM_FACTORY);
219                 } else {
220                     throw new TestError("bug in test: unknown DOM: \""
221                                         + getParams().getDom() + "\"");
222                 }
223                 basicTest();
224                 XMLObject doc = loadTestDocument(getTestClass());
225                 dumpVerifyDom(doc, DOC_DOM_DUMP_EXT);
226             }
227         }.run();
228     }
229
230     /*
231      * Test 10: -nocompile (-verbose will indicate if the compiler is
232      * started).
233      */

234     public void test10() {
235         new OptTest() {
236             public void run() {
237                 fExecXmlc.addOpt(ExecXmlc.OPT_NO_COMPILE);
238                 fExecXmlc.addOpt(ExecXmlc.OPT_VERBOSE);
239                 basicTest();
240             }
241         }.run();
242     }
243
244     /*
245      * Test 11: -create-get-tag-methods
246      */

247     public void test11() {
248         HtmlBasicTest test = createLutrisIndexTest();
249         test.addBoth(ExecXmlc.OPT_CREATE_GET_TAG_METHODS);
250         test.basicTest();
251     }
252
253     /*
254      * Test 12: -create-get-tag-methods along with setTextXXX() methods
255      */

256     public void test12() {
257         HtmlBasicTest test = createTest("testPage1.html");
258         test.addBoth(ExecXmlc.OPT_CREATE_GET_TAG_METHODS);
259         test.addBoth(ExecXmlc.OPT_METHODS);
260         test.basicTest();
261     }
262
263     /*
264      * Test 13: -warnings
265      */

266     public void test13() {
267         HtmlBasicTest test = createLutrisIndexTest();
268         test.addBoth(ExecXmlc.OPT_WARNINGS, "false");
269         test.basicTest();
270     }
271
272     /*
273      * Test 14: -docout
274      */

275     public void test14() {
276         new OptTest() {
277             public void run() {
278                 File JavaDoc docOut = getResultFile("docout.html");
279                 TestFileOps.ensureFileDir(docOut);
280                 fExecXmlc.addOpt(ExecXmlc.OPT_DOC_OUT, docOut.getPath());
281                 fExecXmlc.addOpt(ExecXmlc.OPT_NO_COMPILE);
282                 setTestPage1();
283                 compile();
284                 parseVerifyDom(docOut);
285             }
286         }.run();
287     }
288
289     /*
290      * Test 16: Depreciated -html:frameset option.
291      */

292     public void test16() {
293         HtmlBasicTest test = createTest("FrameSet.html");
294         test.addBoth("-html:frameset");
295         test.basicTest();
296     }
297
298 }
299
Popular Tags