KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ANTLRTest


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.taskdefs.optional;
19
20 import java.io.*;
21 import org.apache.tools.ant.BuildFileTest;
22
23 /**
24  * If you want to run tests, it is highly recommended
25  * to download ANTLR (www.antlr.org), build the 'antlrall.jar' jar
26  * with <code>make antlr-all.jar</code> and drop the jar (about 300KB) into
27  * Ant lib.
28  * - Running w/ the default antlr.jar (70KB) does not work (missing class)
29  *
30  * Unless of course you specify the ANTLR classpath in your
31  * system classpath. (see ANTLR install.html)
32  *
33  */

34 public class ANTLRTest extends BuildFileTest {
35
36     private final static String JavaDoc TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/";
37
38     public ANTLRTest(String JavaDoc name) {
39         super(name);
40     }
41
42     public void setUp() {
43         configureProject(TASKDEFS_DIR + "antlr.xml");
44     }
45
46     public void tearDown() {
47         executeTarget("cleanup");
48     }
49
50     public void test1() {
51         expectBuildException("test1", "required argument, target, missing");
52     }
53
54     public void test2() {
55         expectBuildException("test2", "Invalid output directory");
56     }
57
58     public void test3() {
59         executeTarget("test3");
60         File outputDirectory = new File(TASKDEFS_DIR + "antlr.tmp");
61         String JavaDoc[] calcFiles = outputDirectory.list(new CalcFileFilter());
62         assertEquals(5, calcFiles.length);
63     }
64
65     public void test4() {
66         executeTarget("test4");
67     }
68
69     public void test5() {
70         // should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
71
// since it needs to run java.g first before java.tree.g
72
expectBuildException("test5", "ANTLR returned: 1");
73     }
74
75     public void test6() {
76         executeTarget("test6");
77     }
78
79     public void test7() {
80         expectBuildException("test7", "Unable to determine generated class");
81     }
82
83     /**
84      * This is a negative test for the super grammar (glib) option.
85      */

86     public void test8() {
87         expectBuildException("test8", "Invalid super grammar file");
88     }
89
90     /**
91      * This is a positive test for the super grammar (glib) option. ANTLR
92      * will throw an error if everything is not correct.
93      */

94     public void test9() {
95         executeTarget("test9");
96     }
97
98     /**
99      * This test creates an html-ized version of the calculator grammar.
100      * The sanity check is simply whether or not an html file was generated.
101      */

102     public void test10() {
103         executeTarget("test10");
104         File outputDirectory = new File(TASKDEFS_DIR + "antlr.tmp");
105         String JavaDoc[] calcFiles = outputDirectory.list(new HTMLFilter());
106         assertTrue(calcFiles.length > 0);
107     }
108
109     /**
110      * This is just a quick sanity check to run the diagnostic option and
111      * make sure that it doesn't throw any funny exceptions.
112      */

113     public void test11() {
114         executeTarget("test11");
115     }
116
117     /**
118      * This is just a quick sanity check to run the trace option and
119      * make sure that it doesn't throw any funny exceptions.
120      */

121     public void test12() {
122         executeTarget("test12");
123     }
124
125     /**
126      * This is just a quick sanity check to run all the rest of the
127      * trace options (traceLexer, traceParser, and traceTreeWalker) to
128      * make sure that they don't throw any funny exceptions.
129      */

130     public void test13() {
131         executeTarget("test13");
132     }
133
134     public void testNoRecompile() {
135         executeTarget("test9");
136         assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
137         executeTarget("noRecompile");
138         assertTrue(-1 != getFullLog().indexOf("Skipped grammar file."));
139     }
140
141     public void testNormalRecompile() {
142         executeTarget("test9");
143         assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
144         executeTarget("normalRecompile");
145         assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
146     }
147
148     // Bugzilla Report 12961
149
public void testSupergrammarChangeRecompile() {
150         executeTarget("test9");
151         assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
152         executeTarget("supergrammarChangeRecompile");
153         assertEquals(-1, getFullLog().indexOf("Skipped grammar file."));
154     }
155 }
156
157 class CalcFileFilter implements FilenameFilter {
158     public boolean accept(File dir, String JavaDoc name) {
159         return name.startsWith("Calc");
160     }
161 }
162
163 class HTMLFilter implements FilenameFilter {
164     public boolean accept(File dir, String JavaDoc name) {
165         return name.endsWith("html");
166     }
167 }
168
Popular Tags