mirror of
https://github.com/nasa/trick.git
synced 2025-01-31 00:24:03 +00:00
Allow for both gui and headless testing
This commit is contained in:
parent
b6ff7ec3f1
commit
6a8edf6771
2256
test/SIM_gui_testing/RUN_test/TESTING_CHECKPOINT_LOAD
Normal file
2256
test/SIM_gui_testing/RUN_test/TESTING_CHECKPOINT_LOAD
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,9 +8,13 @@ all:
|
|||||||
@echo "[32mBuilding java application...[0m"
|
@echo "[32mBuilding java application...[0m"
|
||||||
@${MVN} package -q -Dmaven.test.skip -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15
|
@${MVN} package -q -Dmaven.test.skip -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15
|
||||||
|
|
||||||
|
test-headless:
|
||||||
|
@echo "[32mBuilding gui-less java tests...[0m"
|
||||||
|
@${MVN} test -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 -Djava.awt.headless=true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@echo "[32mBuilding java tests...[0m"
|
@echo "[32mBuilding java tests...[0m"
|
||||||
@${MVN} test --quiet -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 -Djava.awt.headless=true
|
@${MVN} test -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 -Djava.awt.headless=false
|
||||||
|
|
||||||
javadoc:
|
javadoc:
|
||||||
${MVN} javadoc:javadoc
|
${MVN} javadoc:javadoc
|
||||||
|
@ -541,10 +541,23 @@ public class SimControlApplication extends TrickApplication implements PropertyC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHostPort(String hostname, int portNum) {
|
public static void setHostPort(String hostname, int portNum) {
|
||||||
host = hostname;
|
host = hostname;
|
||||||
port = portNum;
|
port = portNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getting specific values from GUI
|
||||||
|
public double getExecTime() { return simState.getExecOutTime(); }
|
||||||
|
|
||||||
|
// Passing components as read-only to inheriting classes
|
||||||
|
protected final JComboBox getRunningSimList() { return runningSimList; }
|
||||||
|
protected final JXEditorPane getEditorPane() { return statusMsgPane; }
|
||||||
|
protected final JToggleButton getDataRecButton() { return dataRecButton; }
|
||||||
|
protected final JToggleButton getRealTimeButton() { return realtimeButton; }
|
||||||
|
protected final JTextField getSimRunDirField() { return getSimRunDirField(0); }
|
||||||
|
protected final JTextField getSimRunDirField(int index) {
|
||||||
|
return (index < simRunDirField.length) ? simRunDirField[index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================
|
//========================================
|
||||||
|
13
trick_source/java/src/test/java/trick/common/ActionInfo.java
Normal file
13
trick_source/java/src/test/java/trick/common/ActionInfo.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package trick.common;
|
||||||
|
|
||||||
|
public class ActionInfo {
|
||||||
|
String name;
|
||||||
|
String text;
|
||||||
|
String description;
|
||||||
|
|
||||||
|
public ActionInfo(String name, String text, String description) {
|
||||||
|
this.name = name;
|
||||||
|
this.text = text;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,17 @@
|
|||||||
package trick.common;
|
package trick.common;
|
||||||
|
|
||||||
public class ApplicationTest {
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.Action;
|
||||||
|
import javax.swing.ActionMap;
|
||||||
|
import org.jdesktop.application.ResourceMap;
|
||||||
|
|
||||||
|
import trick.common.ActionInfo;
|
||||||
|
|
||||||
|
public abstract class ApplicationTest {
|
||||||
|
protected ArrayList<ActionInfo> coreActionInfo, supportActionInfo, miscActionInfo;
|
||||||
|
protected ActionMap actionContext;
|
||||||
|
protected ResourceMap resourceContext;
|
||||||
|
|
||||||
public static String getTrickHome() {
|
public static String getTrickHome() {
|
||||||
String path;
|
String path;
|
||||||
@ -39,4 +50,51 @@ public class ApplicationTest {
|
|||||||
public static void sleep(long ms) {
|
public static void sleep(long ms) {
|
||||||
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getActionText(Action action) {
|
||||||
|
return (String)action.getValue(Action.NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getActionShortDescription(Action action) {
|
||||||
|
return (String)action.getValue(Action.SHORT_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Action getActionFromKey(String actionKey) {
|
||||||
|
String errMsg = String.format("No ActionMap set. Action '%s' cannot be searched for.\n", actionKey);
|
||||||
|
// assumeNotNull(errMsg, actionContext);
|
||||||
|
return actionContext.get(actionKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupExpectedActionInfo() {
|
||||||
|
coreActionInfo = new ArrayList<ActionInfo>();
|
||||||
|
supportActionInfo = new ArrayList<ActionInfo>();
|
||||||
|
miscActionInfo = new ArrayList<ActionInfo>();
|
||||||
|
|
||||||
|
getCoreActionInfo();
|
||||||
|
getSupportActionInfo();
|
||||||
|
getMiscActionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// protected void verifyActionInfo(ActionInfo aInfo) {
|
||||||
|
// Action action = getActionFromKey(aInfo.name);
|
||||||
|
// assumeNotNull(String.format("ActionMap.get(\"%s\") = null", aInfo.name), action);
|
||||||
|
|
||||||
|
// String actualText = getActionText(action);
|
||||||
|
// String actualDesc = getActionShortDescription(action);
|
||||||
|
|
||||||
|
// assertEquals(aInfo.text, actualText);
|
||||||
|
// assertEquals(aInfo.description, actualDesc);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// protected void verifyResourceInfo(String key, String expectedStr) {
|
||||||
|
// String resourceText, errMsg = String.format("No ResourceMap set. Resource '%s' cannot be searched for.\n", key);
|
||||||
|
// assumeNotNull(errMsg, resourceContext);
|
||||||
|
|
||||||
|
// resourceText = resourceContext.getString(key);
|
||||||
|
// assertEquals(expectedStr, resourceText);
|
||||||
|
// }
|
||||||
|
|
||||||
|
protected abstract void getCoreActionInfo();
|
||||||
|
protected abstract void getSupportActionInfo();
|
||||||
|
protected abstract void getMiscActionInfo();
|
||||||
}
|
}
|
||||||
|
102
trick_source/java/src/test/java/trick/common/GUIController.java
Normal file
102
trick_source/java/src/test/java/trick/common/GUIController.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package trick.common;
|
||||||
|
|
||||||
|
import java.awt.AWTException;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class GUIController extends Robot {
|
||||||
|
private long depressTime;
|
||||||
|
|
||||||
|
public GUIController() throws AWTException {
|
||||||
|
super();
|
||||||
|
depressTime = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUIController(long ms) throws AWTException {
|
||||||
|
super();
|
||||||
|
depressTime = ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void typeString(String entry) {
|
||||||
|
int keycode;
|
||||||
|
String upperCaseSpecial = "~!@#$%^&*()_+{}|:\"<>?";
|
||||||
|
for (char c : entry.toCharArray()) {
|
||||||
|
if (Character.isUpperCase(c) || upperCaseSpecial.indexOf(c) >= 0)
|
||||||
|
keyPress(KeyEvent.VK_SHIFT);
|
||||||
|
else
|
||||||
|
keyRelease(KeyEvent.VK_SHIFT);
|
||||||
|
|
||||||
|
switch(c) {
|
||||||
|
case '\n' : keycode = KeyEvent.VK_ENTER; break;
|
||||||
|
|
||||||
|
default: keycode = KeyEvent.getExtendedKeyCodeForChar(c); break;
|
||||||
|
}
|
||||||
|
keyTap(keycode);
|
||||||
|
sleep(25);
|
||||||
|
}
|
||||||
|
|
||||||
|
keyRelease(KeyEvent.VK_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearTextField() {
|
||||||
|
keyPress(KeyEvent.VK_CONTROL);
|
||||||
|
sleep(depressTime);
|
||||||
|
|
||||||
|
keyTap('A');
|
||||||
|
sleep(depressTime);
|
||||||
|
|
||||||
|
keyRelease(KeyEvent.VK_CONTROL);
|
||||||
|
sleep(depressTime);
|
||||||
|
|
||||||
|
keyTap(KeyEvent.VK_BACK_SPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTap(int keycode) {
|
||||||
|
keyPress(keycode);
|
||||||
|
sleep(depressTime);
|
||||||
|
keyRelease(keycode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delayedKeyTap(int keycode, long delay) {
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() { keyTap(keycode); }
|
||||||
|
}, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delayedTypeString(String entry, long delay) {
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() { typeString(entry); }
|
||||||
|
}, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClick(int buttons) {
|
||||||
|
mousePress(buttons);
|
||||||
|
sleep(depressTime);
|
||||||
|
mouseRelease(buttons);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClickAt(int buttons, Point pos) {
|
||||||
|
mouseMove(pos.x, pos.y);
|
||||||
|
mouseClick(buttons);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClickAt(int buttons, Component comp) {
|
||||||
|
Point pos = comp.getLocationOnScreen();
|
||||||
|
pos.translate(comp.getWidth()/2, comp.getHeight()/2);
|
||||||
|
mouseClickAt(buttons, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sleep(long ms) {
|
||||||
|
try { Thread.sleep(ms); } catch (Exception ignored) { }
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package trick.simcontrol;
|
package trick.simcontrol;
|
||||||
|
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.beans.Transient;
|
import java.beans.Transient;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -9,6 +10,8 @@ import java.io.IOException;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jdesktop.application.Application;
|
import org.jdesktop.application.Application;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -18,10 +21,12 @@ import org.junit.BeforeClass;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
import static org.junit.Assume.assumeNotNull;
|
||||||
|
|
||||||
import trick.common.ApplicationTest;
|
import trick.common.ApplicationTest;
|
||||||
import trick.common.SimulationInterface;
|
import trick.common.SimulationInterface;
|
||||||
import trick.common.utils.VariableServerConnection;
|
import trick.common.utils.VariableServerConnection;
|
||||||
|
import trick.common.ActionInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -39,7 +44,7 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
private final int MODE_FREEZE = 1,
|
private final int MODE_FREEZE = 1,
|
||||||
MODE_RUN = 5;
|
MODE_RUN = 5;
|
||||||
|
|
||||||
private static HeadlessSimControlApplication simControl;
|
private static SimControlApplication simControl;
|
||||||
private static VariableServerConnection varserv;
|
private static VariableServerConnection varserv;
|
||||||
private static Process simProc;
|
private static Process simProc;
|
||||||
private static String host;
|
private static String host;
|
||||||
@ -48,6 +53,7 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() {
|
public static void setUpBeforeClass() {
|
||||||
String fullDir = getTrickHome() + SIM_DIR;
|
String fullDir = getTrickHome() + SIM_DIR;
|
||||||
|
simControl = null;
|
||||||
|
|
||||||
SimulationInterface.cleanSim(fullDir);
|
SimulationInterface.cleanSim(fullDir);
|
||||||
SimulationInterface.compileSim(fullDir);
|
SimulationInterface.compileSim(fullDir);
|
||||||
@ -77,16 +83,373 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownAfterClass() {
|
public static void tearDownAfterClass() {
|
||||||
// if(simControl != null) {
|
|
||||||
// simControl.freezeSim();
|
|
||||||
// simControl.shutdown();
|
|
||||||
// }
|
|
||||||
if(simProc != null && simProc.isAlive())
|
if(simProc != null && simProc.isAlive())
|
||||||
simProc.destroy();
|
simProc.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanup() {
|
||||||
|
simControl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getCoreActionInfo() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getSupportActionInfo() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void getMiscActionInfo() { }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartSim() throws IOException {
|
public void testStartSim() throws IOException {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
headlessStartSim();
|
||||||
|
} else {
|
||||||
|
guiStartSim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFreezeSim() throws IOException {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
headlessFreezeSim();
|
||||||
|
} else {
|
||||||
|
guiFreezeSim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConnectionFail() {
|
||||||
|
// ARRANGE
|
||||||
|
String expOutput = "Invalid TCP/IP port number \"0\"", output;
|
||||||
|
|
||||||
|
String badH = "localhost";
|
||||||
|
int badP = 0;
|
||||||
|
simControl = new HeadlessSimControlApplication();
|
||||||
|
System.setErr(new PrintStream(errContent));
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
HeadlessSimControlApplication.setHostPort(badH, badP);
|
||||||
|
simControl.connect();
|
||||||
|
sleep(500);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
output = errContent.toString();
|
||||||
|
assertTrue("Did not recieve the expected error message: \n"
|
||||||
|
+ output, output.indexOf(expOutput) >= 0);
|
||||||
|
|
||||||
|
// CLEAN UP
|
||||||
|
System.setErr(originalErr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------//
|
||||||
|
// GUI Only Tests //
|
||||||
|
//--------------------//
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that the freezeAtSim() action functions properly.
|
||||||
|
*/
|
||||||
|
public void testFreezeAtTimeSimulation() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testFreezeAtTimeSimulation";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
double targetTime = simcontrol.getExecTime() + 3.0;
|
||||||
|
String statusMsg[], expStatus = "Freeze ON",
|
||||||
|
expTimeStamp = String.format("%.6f", targetTime);
|
||||||
|
Matcher line1, line2;
|
||||||
|
Pattern freezeOffPatt = Pattern.compile("\\|.*\\| Freeze OFF\\.\\n?"),
|
||||||
|
freezeOnPatt = Pattern.compile("\\|.*\\| Freeze ON\\. Simulation time holding at "
|
||||||
|
+ expTimeStamp + " seconds\\.\\n?");
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simcontrol.controller.delayedTypeString((targetTime + "\n"), 500);
|
||||||
|
simcontrol.freezeAt();
|
||||||
|
|
||||||
|
simcontrol.startSim();
|
||||||
|
simcontrol.sleep(4000);
|
||||||
|
|
||||||
|
statusMsg = simcontrol.getStatusMessages().split("\n");
|
||||||
|
line1 = freezeOffPatt.matcher(statusMsg[0]);
|
||||||
|
line2 = freezeOnPatt.matcher(statusMsg[1]);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assumeTrue("Unexpected number of messages", statusMsg.length == 2);
|
||||||
|
assumeTrue("Simulation did not start!", line1.find());
|
||||||
|
assertTrue("Simulation didn't freeze at " + expTimeStamp + "\n" + statusMsg[1],
|
||||||
|
line2.find());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that the freezeInSim() action functions properly.
|
||||||
|
*/
|
||||||
|
public void testFreezeInTimeSimulation() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testFreezeInTimeSimulation";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
double targetTime = simcontrol.getExecTime() + 3.0;
|
||||||
|
String statusMsg[], expStatus = "Freeze ON",
|
||||||
|
expTimeStamp = String.format("%.6f", targetTime);
|
||||||
|
Matcher line1, line2;
|
||||||
|
Pattern freezeOffPatt = Pattern.compile("\\|.*\\| Freeze OFF\\.\\n?"),
|
||||||
|
freezeOnPatt = Pattern.compile("\\|.*\\| Freeze ON\\. Simulation time holding at "
|
||||||
|
+ expTimeStamp + " seconds\\.\\n?");
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simcontrol.controller.delayedTypeString("3.0\n", 500);
|
||||||
|
simcontrol.freezeIn();
|
||||||
|
|
||||||
|
simcontrol.startSim();
|
||||||
|
simcontrol.sleep(4000);
|
||||||
|
|
||||||
|
statusMsg = simcontrol.getStatusMessages().split("\n");
|
||||||
|
line1 = freezeOffPatt.matcher(statusMsg[0]);
|
||||||
|
line2 = freezeOnPatt.matcher(statusMsg[1]);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assumeTrue("Unexpected number of messages", statusMsg.length == 2);
|
||||||
|
assumeTrue("Simulation did not start!", line1.find());
|
||||||
|
assertTrue("Simulation didn't freeze at " + expTimeStamp + "\n" + statusMsg[1],
|
||||||
|
line2.find());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that the startSim() action functions properly after the
|
||||||
|
* freezeSim() action.
|
||||||
|
*/
|
||||||
|
public void testRestartSimulation() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testRestartSimulation";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
String statusMsg;
|
||||||
|
String[] statusLines;
|
||||||
|
Matcher line1, line2, line3;
|
||||||
|
Pattern freezeOffPatt = Pattern.compile("\\|.*\\| Freeze OFF\\.\\n?"),
|
||||||
|
freezeOnPatt = Pattern.compile("\\|.*\\| Freeze ON\\. Simulation time holding at \\d+\\.\\d+ seconds\\.\\n?");
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simcontrol.startSim();
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
simcontrol.freezeSim();
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
simcontrol.startSim();
|
||||||
|
|
||||||
|
do {
|
||||||
|
counter++;
|
||||||
|
sleep(500);
|
||||||
|
statusMsg = simcontrol.getStatusMessages();
|
||||||
|
statusLines = statusMsg.split("\n");
|
||||||
|
} while(statusLines.length < 3 && counter < 6);
|
||||||
|
|
||||||
|
assumeTrue("Status Message Pane does not have the expected number of entries!", statusLines.length >= 3);
|
||||||
|
line1 = freezeOffPatt.matcher(statusLines[0]);
|
||||||
|
line2 = freezeOnPatt.matcher(statusLines[1]);
|
||||||
|
line3 = freezeOffPatt.matcher(statusLines[2]);
|
||||||
|
|
||||||
|
simcontrol.freezeSim();
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assertTrue( "Simulation didn't start correctly:\n" + statusLines[0], line1.find());
|
||||||
|
assertTrue("Simulation didn't freeze correctly:\n" + statusLines[1], line2.find());
|
||||||
|
assertTrue("Simulation didn't resume correctly:\n" + statusLines[2], line3.find());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that the dumpChkpntASCII() action functions properly.
|
||||||
|
*/
|
||||||
|
public void testDumpCheckpointSimulation() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testDumpCheckpointSimulation";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
String expMsg = "Dumped ASCII Checkpoint ", actualMsg, errMsg,
|
||||||
|
fileName, filePath = getTrickHome() + SIM_DIR + "/RUN_test/";
|
||||||
|
File checkpointFile;
|
||||||
|
int nameIndex;
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simcontrol.controller.delayedKeyTap(KeyEvent.VK_ENTER, 500);
|
||||||
|
simcontrol.controller.delayedKeyTap(KeyEvent.VK_ENTER, 750);
|
||||||
|
simcontrol.dumpChkpntASCII();
|
||||||
|
sleep(500);
|
||||||
|
|
||||||
|
actualMsg = simcontrol.getStatusMessages();
|
||||||
|
nameIndex = actualMsg.indexOf(expMsg);
|
||||||
|
assumeTrue("Dumped Checkpoint Message Not Found", nameIndex >= 0);
|
||||||
|
|
||||||
|
nameIndex += expMsg.length();
|
||||||
|
fileName = actualMsg.substring(nameIndex, actualMsg.length() - 2);
|
||||||
|
checkpointFile = new File(filePath + fileName );
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
errMsg = String.format("'%s' Checkpoint File Not Found At '%s'\n", fileName, filePath);
|
||||||
|
assumeNotNull(errMsg, checkpointFile);
|
||||||
|
assertTrue(errMsg, checkpointFile.exists());
|
||||||
|
|
||||||
|
// CLEANUP
|
||||||
|
checkpointFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that the loadChkpnt() action functions properly.
|
||||||
|
*/
|
||||||
|
public void testLoadCheckpointSimulation() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testLoadCheckpointSimulation";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
String actualMsgs[], fileName = "TESTING_CHECKPOINT_LOAD",
|
||||||
|
expMsgs[] = {"Load checkpoint file " + getTrickHome() + SIM_DIR + "/RUN_test/TESTING_CHECKPOINT_LOAD.",
|
||||||
|
"Finished loading checkpoint file. Calling restart jobs.",
|
||||||
|
"|8.700000| restart variable server message port = " + port};
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simcontrol.controller.delayedTypeString(fileName + "\n", 500);
|
||||||
|
simcontrol.loadChkpnt();
|
||||||
|
sleep(5000);
|
||||||
|
actualMsgs = simcontrol.getStatusMessages().split("\n");
|
||||||
|
|
||||||
|
assumeTrue("Unexpected Status Messages:\n" + Arrays.toString(actualMsgs), actualMsgs.length >= 3);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assertTrue("Unexpected Status Message:\n" + actualMsgs[0], actualMsgs[0].endsWith(expMsgs[0]));
|
||||||
|
assertTrue("Unexpected Status Message:\n" + actualMsgs[1], actualMsgs[1].endsWith(expMsgs[1]));
|
||||||
|
assertTrue("Unexpected Status Message:\n" + actualMsgs[2], actualMsgs[2].endsWith(expMsgs[2]));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that data recording toggles off and on correctly.
|
||||||
|
*/
|
||||||
|
public void testDataRecordingToggle() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testDataRecordingToggle";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
final boolean expectedOrder[] = {true, false, true};
|
||||||
|
boolean actualOrder[] = new boolean[3];
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
for(int i = 0; i < actualOrder.length; i++) {
|
||||||
|
actualOrder[i] = simcontrol.isDataRecOn();
|
||||||
|
simcontrol.toggleDataRecButton();
|
||||||
|
sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assertTrue("Data Recording was not ON at the start of the Sim",
|
||||||
|
expectedOrder[0] == actualOrder[0]);
|
||||||
|
assertTrue("Data Recording didn't toggle OFF correctly",
|
||||||
|
expectedOrder[1] == actualOrder[1]);
|
||||||
|
assertTrue("Data Recording didn't toggle back ON correctly",
|
||||||
|
expectedOrder[2] == actualOrder[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing that data recording toggles off and on correctly.
|
||||||
|
*/
|
||||||
|
public void testRealTimeToggle() {
|
||||||
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
|
String testName = "testRealTimeToggle";
|
||||||
|
System.out.println("Testing Headlessly. Skipping '" + testName + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ARRANGE
|
||||||
|
final boolean expectedOrder[] = {true, false, true};
|
||||||
|
boolean actualOrder[] = new boolean[3];
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication simcontrol = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
for(int i = 0; i < actualOrder.length; i++) {
|
||||||
|
actualOrder[i] = simcontrol.isRealTimeOn();
|
||||||
|
simcontrol.toggleRealTimeButton();
|
||||||
|
sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assertTrue("Real Time was not ON at the start of the Sim",
|
||||||
|
expectedOrder[0] == actualOrder[0]);
|
||||||
|
assertTrue("Real Time didn't toggle OFF correctly",
|
||||||
|
expectedOrder[1] == actualOrder[1]);
|
||||||
|
assertTrue("Real Time didn't toggle back ON correctly",
|
||||||
|
expectedOrder[2] == actualOrder[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hybrid Test helper methods
|
||||||
|
|
||||||
|
private void headlessStartSim() throws IOException {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
String out;
|
String out;
|
||||||
int mode = 1, count = 0;
|
int mode = 1, count = 0;
|
||||||
@ -101,6 +464,7 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
||||||
mode = Integer.parseInt(varserv.get().split("\t")[1]);
|
mode = Integer.parseInt(varserv.get().split("\t")[1]);
|
||||||
assumeTrue("Sim Mode was not MODE_FREEZE at test start", mode == MODE_FREEZE);
|
assumeTrue("Sim Mode was not MODE_FREEZE at test start", mode == MODE_FREEZE);
|
||||||
|
|
||||||
simControl.startSim();
|
simControl.startSim();
|
||||||
do {
|
do {
|
||||||
count ++;
|
count ++;
|
||||||
@ -115,12 +479,41 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
varserv.put("trick.exec_freeze()\n");
|
varserv.put("trick.exec_freeze()\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void guiStartSim() throws IOException {
|
||||||
public void testFreezeSim() throws IOException {
|
// ARRANGE
|
||||||
|
String statusMsg, expStatus = "Freeze OFF";
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication guiControl = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
||||||
|
int mode = Integer.parseInt(varserv.get().split("\t")[1]);
|
||||||
|
assumeTrue("Sim Mode was not MODE_FREEZE at test start", mode == MODE_FREEZE);
|
||||||
|
|
||||||
|
guiControl.clearStatusMsgs();
|
||||||
|
guiControl.startSim();
|
||||||
|
|
||||||
|
do {
|
||||||
|
counter++;
|
||||||
|
sleep(500);
|
||||||
|
statusMsg = guiControl.getStatusMessages();
|
||||||
|
} while(statusMsg.isEmpty() && counter < 5);
|
||||||
|
|
||||||
|
guiControl.freezeSim();
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
assertTrue("Simulation did not start!\n" + statusMsg, statusMsg.indexOf(expStatus) != -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void headlessFreezeSim() throws IOException {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
String out;
|
String out;
|
||||||
int mode = 1, count = 0;
|
int mode = 1, count = 0;
|
||||||
|
|
||||||
simControl = new HeadlessSimControlApplication(host, port);
|
simControl = new HeadlessSimControlApplication(host, port);
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
|
|
||||||
@ -145,28 +538,49 @@ public class SimControlApplicationTest extends ApplicationTest {
|
|||||||
// ASSERT
|
// ASSERT
|
||||||
assertTrue("Sim Mode is not MODE_FREEZE (1)\nMODE_ID=" + mode, mode == MODE_FREEZE);
|
assertTrue("Sim Mode is not MODE_FREEZE (1)\nMODE_ID=" + mode, mode == MODE_FREEZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testConnectionFail() {
|
|
||||||
// ARRANGE
|
|
||||||
String expOutput = "Invalid TCP/IP port number \"0\"", output;
|
|
||||||
|
|
||||||
String badH = "localhost";
|
private void guiFreezeSim() throws IOException {
|
||||||
int badP = 0;
|
// ARRANGE
|
||||||
simControl = new HeadlessSimControlApplication();
|
String statusMsg, expStatus = "Freeze ON";
|
||||||
System.setErr(new PrintStream(errContent));
|
int counter = 0;
|
||||||
|
|
||||||
|
startApplication(true);
|
||||||
|
assumeTrue("Sim Control Panel didn't start...", simControl != null);
|
||||||
|
|
||||||
|
WaitForSimControlApplication guiControl = (WaitForSimControlApplication) simControl;
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
simControl.setHostPort(badH, badP);
|
guiControl.startSim();
|
||||||
simControl.connect();
|
guiControl.freezeSim();
|
||||||
sleep(500);
|
|
||||||
|
do {
|
||||||
|
counter++;
|
||||||
|
sleep(500);
|
||||||
|
statusMsg = guiControl.getStatusMessages();
|
||||||
|
} while(statusMsg.indexOf(expStatus) < 0 && counter < 5);
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
output = errContent.toString();
|
assertTrue("Simulation did not freeze!\n" + statusMsg, statusMsg.indexOf(expStatus) != -1);
|
||||||
assertTrue("Did not recieve the expected error message: \n"
|
}
|
||||||
+ output, output.indexOf(expOutput) >= 0);
|
|
||||||
|
|
||||||
// CLEAN UP
|
private static void startApplication(boolean startConnected) {
|
||||||
System.setErr(originalErr);
|
if(simControl == null) {
|
||||||
|
if(startConnected) // Launch Testing SimControlPanel with the provided connection info
|
||||||
|
WaitForSimControlApplication.launchAndWait(WaitForSimControlApplication.class, host, port);
|
||||||
|
else // Launch Testing SimControlPanel
|
||||||
|
WaitForSimControlApplication.launchAndWait(WaitForSimControlApplication.class);
|
||||||
|
|
||||||
|
handleAppSetup();
|
||||||
|
} else {
|
||||||
|
System.err.println("SimControlApplication is already Running...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleAppSetup() {
|
||||||
|
// Set up the required variables for testing
|
||||||
|
simControl = Application.getInstance(WaitForSimControlApplication.class);
|
||||||
|
|
||||||
|
// Ensure that everything got set up correctly.
|
||||||
|
assumeTrue("SimControlApplicationTest is not ready yet!", simControl.isReady());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,138 @@
|
|||||||
|
package trick.simcontrol;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JEditorPane;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JToggleButton;
|
||||||
|
import javax.swing.text.Document;
|
||||||
|
|
||||||
|
import java.awt.AWTException;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
import org.jdesktop.application.Application;
|
||||||
|
import org.jdesktop.swingx.JXEditorPane;
|
||||||
|
|
||||||
|
import trick.common.GUIController;
|
||||||
|
import trick.simcontrol.SimControlApplication;
|
||||||
|
|
||||||
|
|
||||||
|
public class WaitForSimControlApplication extends SimControlApplication {
|
||||||
|
static Object lock = new Object();
|
||||||
|
|
||||||
|
boolean isEnded;
|
||||||
|
public GUIController controller;
|
||||||
|
|
||||||
|
public WaitForSimControlApplication() throws AWTException{
|
||||||
|
super();
|
||||||
|
controller = new GUIController();
|
||||||
|
// controller.setAutoDelay(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sleep(long ms) {
|
||||||
|
try { Thread.sleep(ms); } catch (Exception ignored) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void end() {
|
||||||
|
isEnded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void ready() {
|
||||||
|
super.ready();
|
||||||
|
synchronized(lock) {
|
||||||
|
lock.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void launchAndWait(Class<? extends WaitForSimControlApplication> applicationClass, String host, int port) {
|
||||||
|
setHostPort(host, port);
|
||||||
|
launchAndWait(applicationClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//========================================
|
||||||
|
// Robot Methods
|
||||||
|
//========================================
|
||||||
|
public void editRunningSimList(String socketInfo) {
|
||||||
|
getRunningSimList().setSelectedItem(socketInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleDataRecButton() {
|
||||||
|
JToggleButton button = getDataRecButton();
|
||||||
|
selectComponent(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleRealTimeButton() {
|
||||||
|
JToggleButton button = getRealTimeButton();
|
||||||
|
selectComponent(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectAndClearField(Component field) {
|
||||||
|
selectComponent(field);
|
||||||
|
controller.clearTextField();
|
||||||
|
controller.waitForIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectComponent(Component comp) {
|
||||||
|
controller.mouseClickAt(InputEvent.BUTTON1_DOWN_MASK, comp);
|
||||||
|
controller.waitForIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
//========================================
|
||||||
|
// Getter Methods
|
||||||
|
//========================================
|
||||||
|
public String getRunningSimInfo() {
|
||||||
|
JTextField runDir = getSimRunDirField();
|
||||||
|
if (runDir == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return runDir.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusMessages() {
|
||||||
|
JXEditorPane status = getEditorPane();
|
||||||
|
String msg = "";
|
||||||
|
try {
|
||||||
|
Document doc = status.getDocument();
|
||||||
|
msg = doc.getText(0, doc.getLength());
|
||||||
|
} catch (Exception e) {
|
||||||
|
msg = e.getMessage();
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDataRecOn() { return getDataRecButton().isSelected(); }
|
||||||
|
public boolean isRealTimeOn() { return getRealTimeButton().isSelected(); }
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user