+ * TODO + * + * @author Emmanuel Bigeon + * + */ +public class HistoryTextKeyListenerTest { + + @Test + public void test() { + + } + +} diff --git a/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java b/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java index a50849c..5516c54 100644 --- a/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java +++ b/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java @@ -41,30 +41,159 @@ package fr.bigeon.gclc.swt; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.IOException; + import org.eclipse.swt.widgets.Display; import org.junit.Test; import fr.bigeon.gclc.ConsoleApplication; import fr.bigeon.gclc.command.Command; +import fr.bigeon.gclc.exception.CommandRunException; import fr.bigeon.gclc.exception.InvalidCommandName; -import fr.bigeon.gclc.manager.ConsoleManager; -/** - *
+/**
* TODO
*
- * @author Emmanuel Bigeon
- *
- */
+ * @author Emmanuel Bigeon */
public class SWTConsoleShellTest {
protected static final long TWO_SECONDS = 2000;
+ private static final Display DISPLAY = new Display();
+
+ @Test
+ public void testConsoleClose() {
+ final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY);
+ final SWTConsole swtConsole = (SWTConsole) shell.getManager();
+ swtConsole.close();
+ swtConsole.setPrompt(":");
+ try {
+ final ConsoleApplication appl = new ConsoleApplication(swtConsole,
+ "exit", "Hello", "See you");
+ appl.add(new Command("long") {
+
+ @Override
+ public String tip() {
+ return "a long running command";
+ }
+
+ @Override
+ public void execute(String... args) {
+ try {
+ Thread.sleep(TWO_SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+ appl.add(new Command("test") {
+
+ @Override
+ public String tip() {
+ return "a prompting running command";
+ }
+
+ @Override
+ public void execute(String... args) throws CommandRunException {
+ try {
+ appl.getManager().prompt("Test");
+ } catch (IOException e) {
+ throw new CommandRunException("No input", e);
+ }
+ }
+ });
+// shell.pack();
+ shell.open();
+ Thread applThread = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ appl.start();
+ }
+ });
+ Thread testThread = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(TWO_SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("test"); //$NON-NLS-1$
+ swtConsole.validateCommand();
+ }
+ });
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("ok"); //$NON-NLS-1$
+ }
+ });
+ swtConsole.validateCommand();
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("long"); //$NON-NLS-1$
+ }
+ });
+ swtConsole.validateCommand();
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("test"); //$NON-NLS-1$
+ }
+ });
+ swtConsole.validateCommand();
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("test"); //$NON-NLS-1$
+ }
+ });
+ swtConsole.validateCommand();
+ try {
+ Thread.sleep(TWO_SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ shell.dispose();
+ }
+ });
+ }
+ });
+ applThread.start();
+ testThread.start();
+ while (!shell.isDisposed()) {
+ if (!DISPLAY.readAndDispatch()) {
+ DISPLAY.sleep();
+ }
+ }
+// DISPLAY.dispose();
+ assertTrue(appl.getManager().isClosed());
+ Thread.sleep(TWO_SECONDS);
+ assertFalse(appl.isRunning());
+ } catch (InvalidCommandName e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
@Test
public void test() {
- Display display = new Display();
- final SWTConsoleShell shell = new SWTConsoleShell(display);
- ConsoleManager swtConsole = shell.getManager();
+ final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY);
+ final SWTConsole swtConsole = (SWTConsole) shell.getManager();
try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole,
"exit", "Hello", "See you");
@@ -98,6 +227,19 @@ public class SWTConsoleShellTest {
@Override
public void run() {
+ try {
+ Thread.sleep(TWO_SECONDS);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ swtConsole.setText("test"); //$NON-NLS-1$
+ swtConsole.validateCommand();
+ }
+ });
try {
Thread.sleep(TWO_SECONDS);
} catch (InterruptedException e) {
@@ -115,11 +257,11 @@ public class SWTConsoleShellTest {
applThread.start();
testThread.start();
while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
+ if (!DISPLAY.readAndDispatch()) {
+ DISPLAY.sleep();
}
}
-// display.dispose();
+// DISPLAY.dispose();
assertTrue(appl.getManager().isClosed());
Thread.sleep(TWO_SECONDS);
assertFalse(appl.isRunning());
diff --git a/gclc/pom.xml b/gclc/pom.xml
index b0fdfda..7c30006 100644
--- a/gclc/pom.xml
+++ b/gclc/pom.xml
@@ -35,7 +35,7 @@