提交 3f000aa1 authored 作者: Thomas Mueller's avatar Thomas Mueller

shell test

上级 713b55c8
......@@ -105,6 +105,7 @@ import org.h2.test.unit.TestRecovery;
import org.h2.test.unit.TestSampleApps;
import org.h2.test.unit.TestScriptReader;
import org.h2.test.unit.TestSecurity;
import org.h2.test.unit.TestShell;
import org.h2.test.unit.TestStreams;
import org.h2.test.unit.TestStringCache;
import org.h2.test.unit.TestStringUtils;
......@@ -162,25 +163,20 @@ java org.h2.test.TestAll timer
long time = System.currentTimeMillis();
TestAll test = new TestAll();
test.printSystem();
System.setProperty("h2.maxMemoryRowsDistinct", "128");
/*
not tested:
ResultTempTable
HashIndex
HashCursor
Shell
ExecuteProcedure
PreparedProcedure
Procedure
DeallocateProcedure
PreparedProcedure PREPARE <name>(column,...) AS ...
Procedure
DeallocateProcedure DEALLOCATE [PLAN] <name>
ExecuteProcedure EXECUTE <name>[([p[,...])]
create an mbean for each database? server? (jconsole)
jazoon
upload and test javadoc/index.html
in help.csv, use complete examples for functions; add a test case
improve javadocs
......@@ -539,6 +535,7 @@ Roadmap:
new TestScriptReader().runTest(this);
runTest("org.h2.test.unit.TestServlet");
new TestSecurity().runTest(this);
new TestShell().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
new TestStringUtils().runTest(this);
......
......@@ -351,7 +351,13 @@ public abstract class TestBase {
error(result + " does not contain: " + contains);
}
}
protected void checkStartsWith(String text, String expectedStart) throws Exception {
if (!text.startsWith(expectedStart)) {
error(text + " does not start with: " + expectedStart);
}
}
protected void check(double a, double b) throws Exception {
if (a != b) {
error("double a: " + a + " b: " + b);
......
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.sql.SQLException;
import org.h2.test.TestBase;
import org.h2.tools.Shell;
/**
* Test the shell tool.
*/
public class TestShell extends TestBase {
PrintStream toolOut;
InputStream toolIn;
PrintStream testOut;
PipedInputStream testIn;
LineNumberReader lineReader;
public void test() throws Exception {
testIn = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(testIn);
toolOut = new PrintStream(out, true);
out = new PipedOutputStream();
testOut = new PrintStream(out, true);
toolIn = new PipedInputStream(out);
new Thread(new Runnable() {
public void run() {
try {
Shell shell = new Shell();
shell.setStreams(toolIn, toolOut, toolOut);
shell.run(new String[0]);
} catch (SQLException e) {
e.printStackTrace();
} finally {
toolOut.close();
}
}
}).start();
InputStreamReader reader = new InputStreamReader(testIn);
lineReader = new LineNumberReader(reader);
read("");
read("Welcome to H2 Shell");
read("Exit with");
read("[Enter]");
testOut.println("jdbc:h2:mem:");
read("URL");
testOut.println("org.h2.Driver");
read("Driver");
testOut.println("sa");
read("User");
testOut.println("sa");
read("Password");
read("Commands are case insensitive");
read("help or ?");
read("list");
read("maxwidth");
read("show");
read("describe");
read("quit or exit");
read("");
testOut.println("create table test(id int primary key, name varchar)\n;");
read("sql> ...>");
testOut.println("show public");
read("sql>");
while (read("").startsWith("INFORMATION_SCHEMA")) {
// ignore
}
testOut.println("insert into test values(1, 'Hello');");
read("sql>");
testOut.println("select * from test;");
read("sql> ID");
read("1 ");
read("(1 row,");
testOut.println("describe test");
read("sql> Column Name");
read("ID");
read("NAME");
testOut.println("exit");
read("sql>");
}
private String read(String expectedStart) throws Exception {
String line = lineReader.readLine();
// System.out.println(": " + line);
checkStartsWith(line, expectedStart);
return line;
}
}
......@@ -19,7 +19,7 @@ public class Build extends BuildBase {
/**
* Run the build.
*
* @params args the command line arguments
* @param args the command line arguments
*/
public static void main(String[] args) {
new Build().run(args);
......
......@@ -226,10 +226,10 @@ public class BuildBase {
}
/**
* Read a final static field in a class using reflection.
* Reads the value from a static method of a class using reflection.
*
* @param className the name of the class
* @param fieldName the field name
* @param methodName the field name
* @return the value as a string
*/
protected String getStaticValue(String className, String methodName) {
......@@ -371,9 +371,10 @@ public class BuildBase {
if (file.getName().startsWith(".svn")) {
// ignore
} else if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
addFiles(list, files[i]);
String[] fileNames = file.list();
String path = file.getPath();
for (int i = 0; i < fileNames.length; i++) {
addFiles(list, new File(path, fileNames[i]));
}
} else {
list.add(file);
......@@ -628,16 +629,17 @@ public class BuildBase {
delete(new File(dir));
}
private void delete(File f) {
if (f.exists()) {
if (f.isDirectory()) {
File[] list = f.listFiles();
for (int i = 0; i < list.length; i++) {
delete(list[i]);
private void delete(File file) {
if (file.exists()) {
if (file.isDirectory()) {
String[] fileNames = file.list();
String path = file.getPath();
for (int i = 0; i < fileNames.length; i++) {
delete(new File(path, fileNames[i]));
}
}
if (!f.delete()) {
throw new Error("Can not delete " + f.getPath());
if (!file.delete()) {
throw new Error("Can not delete " + file.getPath());
}
}
}
......
......@@ -514,5 +514,5 @@ derbynet ado happy derbyclient unspecified federated sysadmin lengths doing
gives clunky cooperative paged conflicts ontology freely regards standards
placing refer informational unlocks memo unlimited unmounted keeping hints
hides heterogeneous construction rutema prepending rowscn overrides jconsole
mbean explicit directs leaves printing holds covariant redirector
mbean explicit directs leaves printing holds covariant redirector piped
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论