Changed exit mechanism on gclc

This commit is contained in:
2016-06-09 17:04:53 -04:00
parent 9660d675b6
commit 48c51b3a16
29 changed files with 1059 additions and 442 deletions

View File

@@ -1,114 +0,0 @@
/*
* Copyright E. Bigeon (2015)
*
* emmanuel@bigeon.fr
*
* This software is a computer program whose purpose is to
* provide a swt window for console applications.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package fr.bigeon.gclc.swt;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/** Unit test for simple App. */
public class AppTest extends TestCase {
protected static final long TWO_SECONDS = 2000;
/** Create the test case
*
* @param testName name of the test case */
public AppTest(String testName) {
super(testName);
}
/** @return the suite of tests being tested */
public static Test suite() {
return new TestSuite(AppTest.class);
}
/** Rigourous Test :-) */
@SuppressWarnings("static-method")
public void testApp() {
// Display display = new Display();
// final Shell shell = new Shell(display);
// shell.setLayout(new GridLayout(1, false));
// SWTConsole swtConsole = new SWTConsole(shell, SWT.NONE);
// swtConsole.setLayoutData(
// new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// final ConsoleApplication appl = new ConsoleApplication(swtConsole,
// "exit", "Hello", "See you");
// try {
// 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();
// }
// }
// });
// } catch (InvalidCommandName e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// shell.pack();
// shell.open();
// Thread applThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
// appl.start();
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// shell.dispose();
// }
// });
// }
// });
// applThread.start();
// while (!shell.isDisposed()) {
// if (!display.readAndDispatch()) {
// display.sleep();
// }
// }
// display.dispose();
assertTrue(true);
}
}

View File

@@ -0,0 +1,100 @@
/**
* gclc-swt:fr.bigeon.gclc.swt.SWTConsoleShellTest.java
* Created on: Jun 8, 2016
*/
package fr.bigeon.gclc.swt;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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.InvalidCommandName;
import fr.bigeon.gclc.manager.ConsoleManager;
/**
* <p>
* TODO
*
* @author Emmanuel Bigeon
*
*/
public class SWTConsoleShellTest {
protected static final long TWO_SECONDS = 2000;
@Test
public void test() {
Display display = new Display();
final SWTConsoleShell shell = new SWTConsoleShell(display);
ConsoleManager swtConsole = shell.getManager();
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();
}
}
});
// 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() {
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();
}
}
}