01: package net.sourceforge.squirrel_sql.fw.sql;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.squirrel_sql.client.ApplicationManager;
05:
06: public class QueryTokenizerTest extends TestCase implements GenericSQL {
07:
08: static String nullSQL = null;
09: static String tmpFilename = null;
10: static boolean removeMultilineComment = true;
11: static {
12: ApplicationManager.initApplication();
13: }
14: QueryTokenizer qt = null;
15:
16: public void testHasQueryOne() {
17: qt = new QueryTokenizer(";", "--", removeMultilineComment);
18: qt.setScriptToTokenize(CREATE_STUDENT);
19: SQLUtil.checkQueryTokenizer(qt, 1);
20:
21: qt = new QueryTokenizer(";", "--", removeMultilineComment);
22: qt.setScriptToTokenize(CREATE_COURSES);
23: SQLUtil.checkQueryTokenizer(qt, 1);
24:
25: qt = new QueryTokenizer(";", "--", removeMultilineComment);
26: qt.setScriptToTokenize(STUDENTS_NOT_TAKING_CS112);
27: SQLUtil.checkQueryTokenizer(qt, 1);
28: }
29:
30: public void testEmbeddedComments() {
31: qt = new QueryTokenizer(";", "--", false);
32: qt.setScriptToTokenize(ANSI_SQL_92_PROCEDURE);
33: StringBuffer sql = new StringBuffer();
34: while (qt.hasQuery()) {
35: sql.append(qt.nextQuery());
36: sql.append(";");
37: }
38: /* System.out.println("length="+sql.length());
39: System.out.println("sql="+sql);
40: System.out.println("comment at "+sql.indexOf("/* remove"));
41: System.out.println("comment at "+sql.indexOf("/* add"));
42: */
43:
44: int firstCommentIndex = sql.indexOf("/* remove");
45: assertTrue("first comment not found", firstCommentIndex != -1);
46: int secondCommentIndex = sql.indexOf("/* add");
47: assertTrue("second comment not found", secondCommentIndex != -1);
48:
49: }
50:
51: public void testHasQueryAll() {
52: qt = new QueryTokenizer(";", "--", removeMultilineComment);
53: qt.setScriptToTokenize(SQLUtil.getGenericSQLScript());
54: SQLUtil.checkQueryTokenizer(qt, SQLUtil.getGenericSQLCount());
55: }
56:
57: }
|