提交 82351d47 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improve code coverage.

上级 6a8ec3a5
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Improved date / time arithmetics. Adding and subtracting a
<ul><li>The org.h2.tools.Console no longer calls System.exit on shutdown
(this should not have any user visible effect, but should allow to integrate the tool easier into other applications).
</li><li>Improved date / time arithmetics. Adding and subtracting a
floating point value from a date or timestamp is now supported.
</li><li>When creating a BLOB with in InputStream or a CLOB with a Reader, and the InputStream or Reader
threw an non-IOException, then the LOB storage was broken when storing LOBs in the database.
......
......@@ -50,10 +50,12 @@ ShutdownHandler {
//## AWT begin ##
private Frame frame;
private boolean trayIcon;
private boolean trayIconUsed;
private Font font;
private Button startBrowser;
private TextField urlText;
private Object tray;
private Object trayIcon;
//## AWT end ##
private Server web, tcp, pg;
private boolean isWindows;
......@@ -229,16 +231,10 @@ ShutdownHandler {
}
/**
* INTERNAL
*/
public void shutdown() {
stopAll();
}
/**
* INTERNAL.
* Stop all servers that were started using the console.
*/
void stopAll() {
public void shutdown() {
if (web != null && web.isRunning(false)) {
web.stop();
web = null;
......@@ -256,8 +252,21 @@ ShutdownHandler {
frame.dispose();
frame = null;
}
if (trayIconUsed) {
try {
// tray.remove(trayIcon);
Utils.callMethod(tray, "remove", trayIcon);
} catch (Exception e) {
// ignore
} finally {
trayIcon = null;
tray = null;
trayIconUsed = false;
}
System.gc();
}
//## AWT end ##
System.exit(0);
// System.exit(0);
}
//## AWT begin ##
......@@ -293,8 +302,8 @@ ShutdownHandler {
itemExit.addActionListener(this);
menuConsole.add(itemExit);
// SystemTray tray = SystemTray.getSystemTray();
Object tray = Utils.callStaticMethod("java.awt.SystemTray.getSystemTray");
// tray = SystemTray.getSystemTray();
tray = Utils.callStaticMethod("java.awt.SystemTray.getSystemTray");
// Dimension d = tray.getTrayIconSize();
Dimension d = (Dimension) Utils.callMethod(tray, "getTrayIconSize");
......@@ -309,16 +318,16 @@ ShutdownHandler {
}
Image icon = loadImage(iconFile);
// TrayIcon ti = new TrayIcon(image, "H2 Database Engine", menuConsole);
Object ti = Utils.newInstance("java.awt.TrayIcon", icon, "H2 Database Engine", menuConsole);
// trayIcon = new TrayIcon(image, "H2 Database Engine", menuConsole);
trayIcon = Utils.newInstance("java.awt.TrayIcon", icon, "H2 Database Engine", menuConsole);
// ti.addMouseListener(this);
Utils.callMethod(ti, "addMouseListener", this);
// trayIcon.addMouseListener(this);
Utils.callMethod(trayIcon, "addMouseListener", this);
// tray.add(ti);
Utils.callMethod(tray, "add", ti);
// tray.add(trayIcon);
Utils.callMethod(tray, "add", trayIcon);
this.trayIcon = true;
this.trayIconUsed = true;
return true;
} catch (Exception e) {
......@@ -442,7 +451,7 @@ ShutdownHandler {
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("exit".equals(command)) {
stopAll();
shutdown();
} else if ("console".equals(command)) {
startBrowser();
} else if ("status".equals(command)) {
......@@ -506,11 +515,11 @@ ShutdownHandler {
*/
//## AWT begin ##
public void windowClosing(WindowEvent e) {
if (trayIcon) {
if (trayIconUsed) {
frame.dispose();
frame = null;
} else {
stopAll();
shutdown();
}
}
//## AWT end ##
......
......@@ -26,12 +26,14 @@ import java.sql.Types;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.store.FileLister;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
import org.h2.test.trace.Player;
import org.h2.tools.Backup;
import org.h2.tools.ChangeFileEncryption;
import org.h2.tools.Console;
import org.h2.tools.ConvertTraceFile;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
......@@ -49,6 +51,7 @@ import org.h2.util.Task;
*/
public class TestTools extends TestBase {
private static String lastUrl;
private Server server;
/**
......@@ -65,6 +68,7 @@ public class TestTools extends TestBase {
return;
}
org.h2.Driver.load();
testConsole();
testJdbcDriverUtils();
testWrongServer();
deleteDb("utils");
......@@ -90,6 +94,34 @@ public class TestTools extends TestBase {
IOUtils.delete(getBaseDir() + "/b2.zip");
}
private void testConsole() throws Exception {
String old = System.getProperty(SysProperties.H2_BROWSER);
Console c = new Console();
c.setOut(new PrintStream(new ByteArrayOutputStream()));
try {
lastUrl = "-";
System.setProperty(SysProperties.H2_BROWSER, "call:" + TestTools.class.getName() + ".openBrowser");
c.runTool("-web", "-webPort", "9002", "-tool", "-browser", "-tcp", "-tcpPort", "9003", "-pg", "-pgPort", "9004", "-browser", "-quiet");
c.shutdown();
assertContains(lastUrl, ":9002");
} finally {
if (old != null) {
System.setProperty(SysProperties.H2_BROWSER, old);
} else {
System.clearProperty(SysProperties.H2_BROWSER);
}
}
}
/**
* This method is called via reflection.
*
* @param url the browser url
*/
public static void openBrowser(String url) {
lastUrl = url;
}
private void testSimpleResultSet() throws Exception {
SimpleResultSet rs;
rs = new SimpleResultSet();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论