1 30 31 32 package org.hsqldb.test; 33 34 import java.io.BufferedReader ; 35 import java.io.File ; 36 import java.io.FileReader ; 37 import java.io.IOException ; 38 import java.util.ArrayList ; 39 import java.util.StringTokenizer ; 40 41 public class TestSqlTool extends junit.framework.TestCase { 42 43 48 private class TestSqlFile { 49 50 public File file; 51 public String description; 52 53 public TestSqlFile(String filename, 54 String inDescript) throws IOException { 55 56 file = new File (filename); 57 58 if (!file.isFile()) { 59 throw new IOException ("'" + file + "' is not a file"); 60 } 61 62 description = inDescript; 63 } 64 } 65 66 69 private class SqlFileList extends ArrayList { 70 71 75 public SqlFileList(String filename) throws IOException { 76 77 BufferedReader br = new BufferedReader (new FileReader (filename)); 78 String s, trimmed; 79 StringTokenizer st; 80 int ctr = 0; 81 82 while ((s = br.readLine()) != null) { 83 ctr++; 84 85 trimmed = s.replaceFirst("#.*", "").trim(); 87 if (trimmed.length() < 1) { 88 continue; } 90 91 st = new StringTokenizer (trimmed); 92 93 if (st.countTokens() < 2) { 94 throw new IOException ("Bad line no. " + ctr 95 + " in list file '" + filename 96 + "'"); 97 } 98 99 add(new TestSqlFile(st.nextToken(), st.nextToken(""))); 100 } 101 102 br.close(); 103 } 104 105 public TestSqlFile getSqlFile(int i) { 106 return (TestSqlFile) get(i); 107 } 108 } 109 110 SqlToolHarness harness = new SqlToolHarness(); 111 112 private void runTestsInList(String testList) throws Exception { 113 114 SqlFileList fileList = new SqlFileList(testList); 115 TestSqlFile sqlFile; 116 117 for (int i = 0; i < fileList.size(); i++) { 118 sqlFile = fileList.getSqlFile(i); 119 120 assertTrue(sqlFile.description + " (" + sqlFile.file + ')', 121 harness.execute(sqlFile.file)); 122 } 123 } 124 125 public void testHistory() throws Exception { 126 runTestsInList("testHistory.list"); 127 } 128 129 public void testEditing() throws Exception { 130 runTestsInList("testEditing.list"); 131 } 132 133 public void testArgs() throws Exception { 134 runTestsInList("testArgs.list"); 135 } 136 137 public void testComments() throws Exception { 138 runTestsInList("testComments.list"); 139 } 140 141 public void testPL() throws Exception { 142 runTestsInList("testPL.list"); 143 } 144 145 public void testSpecials() throws Exception { 146 runTestsInList("testSpecials.list"); 147 } 148 149 public void testSQL() throws Exception { 150 runTestsInList("testSQL.list"); 151 } 152 153 public TestSqlTool(String s) { 155 super(s); 156 } 157 158 public static void main(String [] sa) { 159 160 if (sa.length > 0 && sa[0].startsWith("--gui")) { 161 junit.swingui.TestRunner.run(TestSqlTool.class); 162 } else { 163 junit.textui.TestRunner runner = new junit.textui.TestRunner(); 164 165 System.exit( 166 runner.run( 167 runner.getTest( 168 TestSqlTool.class.getName())).wasSuccessful() ? 0 169 : 1); 170 } 171 } 172 173 public static junit.framework.Test suite() { 174 175 junit.framework.TestSuite newSuite = new junit.framework.TestSuite(); 176 177 newSuite.addTest(new TestSqlTool("testHistory")); 178 newSuite.addTest(new TestSqlTool("testEditing")); 179 newSuite.addTest(new TestSqlTool("testArgs")); 180 newSuite.addTest(new TestSqlTool("testComments")); 181 newSuite.addTest(new TestSqlTool("testPL")); 182 newSuite.addTest(new TestSqlTool("testSpecials")); 183 newSuite.addTest(new TestSqlTool("testSQL")); 184 185 return newSuite; 186 } 187 ; 188 } 189 | Popular Tags |