mirror of
https://github.com/nasa/trick.git
synced 2025-04-19 00:27:00 +00:00
Reimplemented the Sniffer Test Suite
This commit is contained in:
parent
935bf287d4
commit
69dc3d4110
@ -0,0 +1,76 @@
|
||||
package trick.sniffer;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import trick.common.CheckApplicationProperties;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test SnifferApplication life cycle.
|
||||
*
|
||||
* @author hchen
|
||||
*
|
||||
*/
|
||||
public class SnifferApplicationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
WaitForSnifferApplication.launchAndWait(WaitForSnifferApplication.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReady() {
|
||||
assertTrue("SnifferApplicationTest is not ready yet!", application().isReady());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that all implemented actions exist as well as their text, shortDescription properties.
|
||||
*/
|
||||
/* @Test
|
||||
public void testDefinedActions() {
|
||||
String[] actionNames = {"launchSimControlPanel", "launchTrickView"};
|
||||
String[] actionTexts = {"Launch Sim Control Panel", "Launch Trick View"};
|
||||
String[] actionShortDescriptions = {"Launch the Sim Control Panel and connect it to the selected simulation.",
|
||||
"Launch Trick View and connect it to the selected simulation."};
|
||||
for (int i = 0; i < actionNames.length; i++) {
|
||||
CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]);
|
||||
CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]);
|
||||
CheckApplicationProperties.checkActionShortDescription(application().actionMap, actionNames[i], actionShortDescriptions[i]);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void testDefinedKeyText() {
|
||||
CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExit() {
|
||||
application().removeExitListener(application().exitListener);
|
||||
application().exit();
|
||||
assertTrue(application().isEnded);
|
||||
}
|
||||
|
||||
private static WaitForSnifferApplication application() {
|
||||
return Application.getInstance(WaitForSnifferApplication.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package trick.sniffer;
|
||||
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
|
||||
|
||||
public class WaitForSnifferApplication extends SimSnifferApplication {
|
||||
static Object lock = new Object();
|
||||
|
||||
boolean isEnded;
|
||||
|
||||
@Override
|
||||
protected void end() {
|
||||
isEnded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void ready() {
|
||||
super.ready();
|
||||
synchronized(lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launch the specified subclsas of SnifferApplication and block
|
||||
* (wait) until it's startup() method has run.
|
||||
*/
|
||||
public static void launchAndWait(Class<? extends WaitForSnifferApplication> applicationClass) {
|
||||
synchronized(lock) {
|
||||
Application.launch(applicationClass, new String[]{});
|
||||
while(true) {
|
||||
try {
|
||||
lock.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
System.err.println("launchAndWait interrupted!");
|
||||
break;
|
||||
}
|
||||
Application app = Application.getInstance(WaitForSnifferApplication.class);
|
||||
if (app instanceof WaitForSnifferApplication) {
|
||||
if (((WaitForSnifferApplication)app).isReady()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user