mirror of
https://github.com/nasa/trick.git
synced 2025-02-06 02:49:20 +00:00
Reimplemented the SimControl Test Suite
This commit is contained in:
parent
04615cb434
commit
935bf287d4
@ -0,0 +1,87 @@
|
||||
package trick.simcontrol;
|
||||
|
||||
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 SimControlApplication life cycle.
|
||||
*
|
||||
* @author hchen
|
||||
* @intern mrockwell2
|
||||
*
|
||||
*/
|
||||
public class SimControlApplicationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
WaitForSimControlApplication.launchAndWait(WaitForSimControlApplication.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("SimControlApplicationTest 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 = {"saveStatusMsgs", "clearStatusMsgs", "startTV", "startMTV", "freezeAt", "freezeIn",
|
||||
"checkpointObjects", "throttle", "connect", "stepSim", "recordingSim", "startSim",
|
||||
"realtime", "freezeSim", "dumpChkpntASCII", "shutdownSim", "loadChkpnt", "lite"};
|
||||
String[] actionTexts = {"Save Status Msgs...", "Clear Status Msgs...", "Start Trick View",
|
||||
"Start Event/Malfunction Trick View", "Freeze At...", "Freeze In...",
|
||||
"Checkpoint Objects...", "Throttle...", "Connect", "Step", "Data Rec On",
|
||||
"Start", "RealTime On", "Freeze", "Dump Chkpnt", "Shutdown", "Load Chkpnt", "Lite"};
|
||||
String[] actionShortDescriptions = {"Save Status Messages", "Clear Status Messages", "Start Trick View (TV)",
|
||||
"Start Event/Malfunction Trick View (MTV)", "Freeze At", "Freeze In",
|
||||
"Checkpoint the specified objects", "Throttle", "Connect to the specified server at specified port",
|
||||
"Step through sim initialization", "Data Recording On/Off", "Start the simulation",
|
||||
"Realtime on/off", "Freeze/Stop the simulation", "Dump ASCII Checkpoint",
|
||||
"Shutdown Simulation", "Load ASCII Checkpoint", "Lite/Full"};
|
||||
|
||||
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 WaitForSimControlApplication application() {
|
||||
return Application.getInstance(WaitForSimControlApplication.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package trick.simcontrol;
|
||||
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
|
||||
|
||||
public class WaitForSimControlApplication extends SimControlApplication {
|
||||
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 SimControlApplication and block
|
||||
* (wait) until it's startup() method has run.
|
||||
*/
|
||||
public static void launchAndWait(Class<? extends WaitForSimControlApplication> 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(WaitForSimControlApplication.class);
|
||||
if (app instanceof WaitForSimControlApplication) {
|
||||
if (((WaitForSimControlApplication)app).isReady()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user