mirror of
https://github.com/nasa/trick.git
synced 2025-01-31 00:24:03 +00:00
Transferring to new fork
This commit is contained in:
parent
5c9615ddad
commit
f75d26a4a8
@ -1245,7 +1245,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
|
|||||||
/**
|
/**
|
||||||
* Updates the GUI as needed if SIM states are changed.
|
* Updates the GUI as needed if SIM states are changed.
|
||||||
*/
|
*/
|
||||||
private void updateGUI() {
|
protected void updateGUI() {
|
||||||
String newStatusDesc = SimState.SIM_MODE_DESCRIPTION[simState.getMode()];
|
String newStatusDesc = SimState.SIM_MODE_DESCRIPTION[simState.getMode()];
|
||||||
|
|
||||||
recTime.setText(simState.getTwoFractionFormatted(simState.getExecOutTime()));
|
recTime.setText(simState.getTwoFractionFormatted(simState.getExecOutTime()));
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package trick.common;
|
||||||
|
|
||||||
|
public class ApplicationTest {
|
||||||
|
|
||||||
|
public static String getTrickHome() {
|
||||||
|
String path;
|
||||||
|
|
||||||
|
// Getting TRICK_HOME environment variable
|
||||||
|
path = System.getenv("TRICK_HOME");
|
||||||
|
|
||||||
|
// Getting Trick's home directory if TRICK_HOME isn't set
|
||||||
|
if(path != null) {
|
||||||
|
if(path.endsWith("/"))
|
||||||
|
path.substring(0, path.length() - 1);
|
||||||
|
} else {
|
||||||
|
path = System.getProperty("user.dir");
|
||||||
|
int cutoff = path.indexOf("/trick_source");
|
||||||
|
path = (cutoff > 0) ? path.substring(0, cutoff) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean compStringArray(String[] a, String[] b) {
|
||||||
|
boolean same = true;
|
||||||
|
for(int i = 0; i < a.length && i < b.length; i++) {
|
||||||
|
same = same && sameLetters(a[i], b[i]);
|
||||||
|
if(!same) return same;
|
||||||
|
}
|
||||||
|
return same;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sameLetters(String str1, String str2) {
|
||||||
|
String a = str1.replaceAll("\\s+", "").toLowerCase(),
|
||||||
|
b = str2.replaceAll("\\s+", "").toLowerCase();
|
||||||
|
return a.equals(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sleep(long ms) {
|
||||||
|
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
@ -29,4 +29,7 @@ public class HeadlessSimControlApplication extends SimControlApplication {
|
|||||||
public void actionPerformed(ActionEvent UNUSED) {}
|
public void actionPerformed(ActionEvent UNUSED) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateGUI() { /* UNUSED */ }
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ 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 trick.common.CheckApplicationProperties;
|
import trick.common.ApplicationTest;
|
||||||
import trick.common.SimulationInterface;
|
import trick.common.SimulationInterface;
|
||||||
import trick.common.utils.VariableServerConnection;
|
import trick.common.utils.VariableServerConnection;
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ import trick.common.utils.VariableServerConnection;
|
|||||||
* @intern mrockwell2
|
* @intern mrockwell2
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SimControlApplicationTest {
|
public class SimControlApplicationTest extends ApplicationTest {
|
||||||
private final static String SIM_DIR = "/home/cacistudent/trick/test/SIM_gui_testing";
|
private final static String SIM_DIR = "/test/SIM_gui_testing";
|
||||||
private final ByteArrayOutputStream stdContent = new ByteArrayOutputStream();
|
private final ByteArrayOutputStream stdContent = new ByteArrayOutputStream();
|
||||||
private final PrintStream originalStd = System.out;
|
private final PrintStream originalStd = System.out;
|
||||||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||||
@ -49,14 +49,16 @@ public class SimControlApplicationTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() {
|
public static void setUpBeforeClass() {
|
||||||
SimulationInterface.cleanSim(SIM_DIR);
|
String fullDir = getTrickHome() + SIM_DIR;
|
||||||
SimulationInterface.compileSim(SIM_DIR);
|
|
||||||
simProc = SimulationInterface.startSim(SIM_DIR, "RUN_test/input.py");
|
SimulationInterface.cleanSim(fullDir);
|
||||||
|
SimulationInterface.compileSim(fullDir);
|
||||||
|
simProc = SimulationInterface.startSim(fullDir, "RUN_test/input.py");
|
||||||
|
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Scanner infoReader = new Scanner(new File(SIM_DIR + "/socket_info"));
|
Scanner infoReader = new Scanner(new File(fullDir + "/socket_info"));
|
||||||
String line = infoReader.nextLine();
|
String line = infoReader.nextLine();
|
||||||
|
|
||||||
host = line.split(":")[0];
|
host = line.split(":")[0];
|
||||||
@ -72,7 +74,7 @@ public class SimControlApplicationTest {
|
|||||||
|
|
||||||
assumeTrue("Did not connect to the variable server", varserv != null);
|
assumeTrue("Did not connect to the variable server", varserv != null);
|
||||||
assumeTrue("Did not find the host name.", !host.isEmpty());
|
assumeTrue("Did not find the host name.", !host.isEmpty());
|
||||||
assumeTrue("Did not find the port numbber", port >= 0);
|
assumeTrue("Did not find the port number", port >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
@ -88,28 +90,29 @@ public class SimControlApplicationTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// System.setOut(new PrintStream(stdContent));
|
// System.setOut(new PrintStream(stdContent));
|
||||||
System.setErr(new PrintStream(errContent));
|
// System.setErr(new PrintStream(errContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
// System.setOut(originalStd);
|
// System.setOut(originalStd);
|
||||||
System.setErr(originalErr);
|
// System.setErr(originalErr);
|
||||||
|
|
||||||
// stdContent.reset();
|
// stdContent.reset();
|
||||||
errContent.reset();
|
// errContent.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartSim() throws IOException {
|
public void testStartSim() throws IOException {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
System.out.println("START TEST");
|
|
||||||
simControl = new HeadlessSimControlApplication(host, port);
|
|
||||||
sleep(1000);
|
|
||||||
System.out.println("CONNECT");
|
|
||||||
simControl.connect();
|
|
||||||
String out;
|
String out;
|
||||||
int mode = 1, count = 0;
|
int mode = 1, count = 0;
|
||||||
|
|
||||||
|
simControl = new HeadlessSimControlApplication(host, port);
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
simControl.connect();
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
||||||
@ -126,50 +129,63 @@ public class SimControlApplicationTest {
|
|||||||
System.out.println(errContent.toString());
|
System.out.println(errContent.toString());
|
||||||
assertTrue("Sim Mode is not MODE_RUN(5)\nMODE_ID=" + mode, mode == MODE_RUN);
|
assertTrue("Sim Mode is not MODE_RUN(5)\nMODE_ID=" + mode, mode == MODE_RUN);
|
||||||
|
|
||||||
|
// CLEAN UP
|
||||||
|
varserv.put("trick.exec_freeze()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFreezeSim() throws IOException {
|
||||||
|
// ARRANGE
|
||||||
|
String out;
|
||||||
|
int mode = 1, count = 0;
|
||||||
|
|
||||||
|
simControl = new HeadlessSimControlApplication(host, port);
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
simControl.connect();
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
simControl.startSim();
|
||||||
|
sleep(1000);
|
||||||
|
|
||||||
|
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
||||||
|
mode = Integer.parseInt(varserv.get().split("\t")[1]);
|
||||||
|
assumeTrue("Sim Mode was not MODE_RUN at test start", mode == MODE_RUN);
|
||||||
|
|
||||||
|
// ACT
|
||||||
|
simControl.freezeSim();
|
||||||
|
do {
|
||||||
|
count ++;
|
||||||
|
varserv.put("trick.var_send_once(\"trick_sys.sched.mode\")");
|
||||||
|
mode = Integer.parseInt(varserv.get().split("\t")[1]);
|
||||||
|
} while (mode != 1 && count < 100000);
|
||||||
|
|
||||||
|
// ASSERT
|
||||||
|
System.out.println(errContent.toString());
|
||||||
|
assertTrue("Sim Mode is not MODE_FREEZE (1)\nMODE_ID=" + mode, mode == MODE_FREEZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionFail() {
|
public void testConnectionFail() {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
String[] expOutput = { "Sim Control Error at Initialization: ",
|
String expOutput = "Invalid TCP/IP port number \"0\"", output;
|
||||||
"Error: SimControlApplication:getInitializationPacket()",
|
|
||||||
" Invalid TCP/IP port number \"0\"",
|
|
||||||
" Please check the server and enter a proper port number!",
|
|
||||||
" IOException ...java.net.ConnectException: Connection refused (Connection refused)",
|
|
||||||
" If there is no connection, please make sure SIM is up running properly!" },
|
|
||||||
output;
|
|
||||||
|
|
||||||
String badH = "localhost";
|
String badH = "localhost";
|
||||||
int badP = 0;
|
int badP = 0;
|
||||||
simControl = new HeadlessSimControlApplication();
|
simControl = new HeadlessSimControlApplication();
|
||||||
|
System.setErr(new PrintStream(errContent));
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
simControl.setHostPort(badH, badP);
|
simControl.setHostPort(badH, badP);
|
||||||
simControl.connect();
|
simControl.connect();
|
||||||
|
sleep(500);
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
output = errContent.toString().split("\n");
|
output = errContent.toString();
|
||||||
assertTrue("Did not recieve the expected error message: \n"
|
assertTrue("Did not recieve the expected error message: \n"
|
||||||
+ Arrays.toString(output),
|
+ output, output.indexOf(expOutput) >= 0);
|
||||||
compStringArray(expOutput, output));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean compStringArray(String[] a, String[] b) {
|
// CLEAN UP
|
||||||
boolean same = true;
|
System.setErr(originalErr);
|
||||||
for(int i = 0; i < a.length && i < b.length; i++) {
|
|
||||||
same = same && sameLetters(a[i], b[i]);
|
|
||||||
if(!same) return same;
|
|
||||||
}
|
|
||||||
return same;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sameLetters(String str1, String str2) {
|
|
||||||
String a = str1.replaceAll("\\s+", "").toLowerCase(),
|
|
||||||
b = str2.replaceAll("\\s+", "").toLowerCase();
|
|
||||||
return a.equals(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sleep(long ms) {
|
|
||||||
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user