mirror of
https://github.com/nasa/trick.git
synced 2025-01-28 15:14:36 +00:00
Trick View test suite framework
This commit is contained in:
parent
6e42bc55d6
commit
4869dbe3d6
@ -28,12 +28,15 @@ public class SimulationInterface {
|
||||
public static Process startSim(String simPath, String ... args) {
|
||||
File sim_dir = new File(simPath);
|
||||
if (sim_dir.exists()) {
|
||||
String cmd = "./" + find_exe(sim_dir).getName();
|
||||
for(String arg : args) cmd += " " + arg;
|
||||
File exe = find_exe(sim_dir);
|
||||
if(exe != null && exe.exists()) {
|
||||
String cmd = "./" + find_exe(sim_dir).getName();
|
||||
for(String arg : args) cmd += " " + arg;
|
||||
|
||||
return run_cmd(sim_dir, cmd);
|
||||
} else
|
||||
return null;
|
||||
return run_cmd(sim_dir, cmd, false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Process run_cmd(File dir, String cmd, boolean block) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package trick.common;
|
||||
|
||||
import trick.common.SimulationInterface;
|
||||
|
||||
public class TestUtils {
|
||||
public static String getTrickHome() {
|
||||
String cwd = System.getProperty("user.dir");
|
||||
@ -16,4 +14,9 @@ public class TestUtils {
|
||||
SimulationInterface.cleanSim(sim_path);
|
||||
return SimulationInterface.compileSim(sim_path);
|
||||
}
|
||||
|
||||
public static Process runTestSim(String sim_name, String ... args) {
|
||||
String sim_path = getTrickHome() + "/test/" + sim_name;
|
||||
return SimulationInterface.startSim(sim_path, args);
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,61 @@ import org.jdesktop.application.Application;
|
||||
|
||||
|
||||
public class MockTVApplication extends TVApplication {
|
||||
|
||||
private boolean connected = false;
|
||||
private static String hostname;
|
||||
private static int port;
|
||||
private static Object lock = new Object();
|
||||
|
||||
boolean isEnded;
|
||||
|
||||
@Override
|
||||
protected void initialize(String[] args) {
|
||||
for(int i = 0; i < args.length; i++)
|
||||
System.out.println((i+1) + ": " + args[i]);
|
||||
super.initialize(args);
|
||||
protected void end() {
|
||||
isEnded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void ready() {
|
||||
super.ready();
|
||||
synchronized(lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isConnected() { return connected; }
|
||||
|
||||
public void connectSimulation() {
|
||||
setTargetSimulation(hostname, port);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(MockTVApplication.class, args);
|
||||
for(int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if((i+1) < args.length) {
|
||||
if(arg.equals("--host")) {
|
||||
hostname = args[++i];
|
||||
} else if(arg.equals("--port")) {
|
||||
port = Integer.parseInt(args[++i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized(lock) {
|
||||
Application.launch(MockTVApplication.class, args);
|
||||
while(true) {
|
||||
try {
|
||||
lock.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
System.err.println("launchAndWait interrupted!");
|
||||
break;
|
||||
}
|
||||
Application app = Application.getInstance(MockTVApplication.class);
|
||||
if (app instanceof MockTVApplication) {
|
||||
if (((MockTVApplication) app).isReady()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,19 @@
|
||||
package trick.tv;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
import org.junit.After;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
import static org.assertj.swing.launcher.ApplicationLauncher.application;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import trick.common.ApplicationTest;
|
||||
import trick.common.CheckApplicationProperties;
|
||||
import trick.dre.MockDreApplication;
|
||||
import trick.dre.fixtures.DreFixture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
import static org.assertj.swing.launcher.ApplicationLauncher.application;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import trick.common.TestUtils;
|
||||
import trick.tv.fixtures.TVFixture;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -29,36 +24,86 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class TVApplicationTest extends ApplicationTest {
|
||||
private static final int PORT = getOpenPort();
|
||||
private static final String SIM_NAME = "SIM_test_dr",
|
||||
GUI_TEST_INPUT = TestUtils.getTrickHome()
|
||||
+ "/trick_source/java"
|
||||
+ "/src/test/resources/RUN_gui_test/input.py";
|
||||
private static Process sim_process;
|
||||
|
||||
private TVFixture tv_fix;
|
||||
private MockTVApplication tv_app;
|
||||
|
||||
@BeforeClass
|
||||
public static void onSetUpBeforeClass() {
|
||||
System.out.println("Port: " + PORT);
|
||||
|
||||
assumeThat(TestUtils.compileTestSim(SIM_NAME))
|
||||
.withFailMessage("Simulation \"%s\" Did Not Compile\n", SIM_NAME)
|
||||
.isTrue();
|
||||
|
||||
sim_process = TestUtils.runTestSim(SIM_NAME, GUI_TEST_INPUT);
|
||||
assumeThat(sim_process)
|
||||
.withFailMessage("Simulation \"%s\" Did Not Start\n", SIM_NAME)
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
public static int getOpenPort() {
|
||||
int port = -1;
|
||||
try {
|
||||
ServerSocket temp = new ServerSocket(0);
|
||||
port = temp.getLocalPort();
|
||||
temp.close();
|
||||
} catch(IOException e) {
|
||||
System.out.println("Free Port Not Found");
|
||||
@AfterClass
|
||||
public static void onCleanUpAfterClass() {
|
||||
if(sim_process != null && sim_process.isAlive()) {
|
||||
sim_process.destroy();
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetUp() {
|
||||
application(MockTVApplication.class).start();
|
||||
protected void onSetUp() {
|
||||
application(MockTVApplication.class)
|
||||
.withArgs("--host", "localhost",
|
||||
"--port", "" + PORT)
|
||||
.start();
|
||||
|
||||
sleep(2500);
|
||||
|
||||
sleep(1500);
|
||||
tv_app = MockTVApplication.getInstance(MockTVApplication.class);
|
||||
tv_fix = new TVFixture(robot(), tv_app);
|
||||
tv_fix.getErrorPopupFixture()
|
||||
.okButton().click();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneric() {
|
||||
// tv_fix.selectVar("drx.drt.uintB.var1");
|
||||
|
||||
sleep(5000);
|
||||
assertThat(true).isTrue();
|
||||
|
||||
// tv_app.connectSimulation();
|
||||
if(tv_app.isConnected()) System.out.println("CONNECTED");
|
||||
else System.out.println("NOT CONNECTED");
|
||||
}
|
||||
|
||||
public static int getOpenPort() {
|
||||
String port = "39595";
|
||||
File port_info;
|
||||
ServerSocket temp = null;
|
||||
PrintWriter info_writer = null;
|
||||
|
||||
try {
|
||||
temp = new ServerSocket(0);
|
||||
port_info = new File("src/test/resources/RUN_gui_test/port.info");
|
||||
info_writer = new PrintWriter(port_info, "UTF-8");
|
||||
|
||||
port = "" + temp.getLocalPort();
|
||||
info_writer.write(port);
|
||||
} catch(IOException e) {
|
||||
System.err.println("Free Port Not Found");
|
||||
} finally {
|
||||
try {
|
||||
if(temp != null)
|
||||
temp.close();
|
||||
if(info_writer != null)
|
||||
info_writer.close();
|
||||
} catch(IOException e) {
|
||||
System.err.println("Issue with Cleanup.");
|
||||
}
|
||||
}
|
||||
|
||||
return Integer.parseInt(port);
|
||||
}
|
||||
}
|
@ -1,82 +1,52 @@
|
||||
package trick.tv.fixtures;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.assertj.swing.core.GenericTypeMatcher;
|
||||
import org.assertj.swing.core.Robot;
|
||||
import org.assertj.swing.fixture.ComponentContainerFixture;
|
||||
import org.assertj.swing.fixture.DialogFixture;
|
||||
import org.assertj.swing.fixture.FrameFixture;
|
||||
import org.assertj.swing.fixture.JCheckBoxFixture;
|
||||
import org.assertj.swing.fixture.JComboBoxFixture;
|
||||
import org.assertj.swing.fixture.JFileChooserFixture;
|
||||
import org.assertj.swing.fixture.JLabelFixture;
|
||||
import org.assertj.swing.fixture.JListFixture;
|
||||
import org.assertj.swing.fixture.JMenuItemFixture;
|
||||
import org.assertj.swing.fixture.JOptionPaneFixture;
|
||||
import org.assertj.swing.fixture.JPanelFixture;
|
||||
import org.assertj.swing.fixture.JScrollPaneFixture;
|
||||
import org.assertj.swing.fixture.JTextComponentFixture;
|
||||
import org.assertj.swing.fixture.JTreeFixture;
|
||||
|
||||
import static org.assertj.swing.timing.Timeout.timeout;
|
||||
import org.jdesktop.swingx.JXTitledPanel;
|
||||
|
||||
import trick.tv.TVApplication;
|
||||
import trick.common.ui.components.FontChooser;
|
||||
import trick.sie.utils.SearchPanel;
|
||||
|
||||
import static org.assertj.swing.timing.Timeout.timeout;
|
||||
|
||||
public class TVFixture extends FrameFixture {
|
||||
private JPanelFixture varTreePanel,
|
||||
varSelectedPanel,
|
||||
private JPanelFixture varSelectedPanel,
|
||||
varSearchPanel;
|
||||
|
||||
private JTextComponentFixture nameField,
|
||||
cycleField,
|
||||
fileSizeField,
|
||||
searchBar;
|
||||
private JTextComponentFixture searchBar;
|
||||
|
||||
private JCheckBoxFixture sizeLimitCheckBox,
|
||||
caseSCheckBox,
|
||||
private JCheckBoxFixture caseSCheckBox,
|
||||
regexCheckBox;
|
||||
|
||||
private JScrollPaneFixture searchResults;
|
||||
private JComboBoxFixture sizeUnitComboBox;
|
||||
private JTreeFixture varTree;
|
||||
|
||||
public TVFixture(Robot robot, TVApplication target) {
|
||||
super(robot, target.getMainFrame());
|
||||
|
||||
varTreePanel = panel(new JXTitledPanelMatcher("Variables"));
|
||||
varSelectedPanel = panel(new JXTitledPanelMatcher("Selected Variables"));
|
||||
varSearchPanel = panel(
|
||||
new GenericTypeMatcher<SearchPanel>(SearchPanel.class) {
|
||||
@Override
|
||||
protected boolean isMatching(SearchPanel panel) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// varTreePanel = panel(new JXTitledPanelMatcher("Variables"));
|
||||
// varSelectedPanel = panel(new JXTitledPanelMatcher("Selected Variables"));
|
||||
// varSearchPanel = panel(
|
||||
// new GenericTypeMatcher<SearchPanel>(SearchPanel.class) {
|
||||
// @Override
|
||||
// protected boolean isMatching(SearchPanel panel) {
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
|
||||
nameField = textBox("groupNameField");
|
||||
cycleField = textBox("cycleField");
|
||||
fileSizeField = textBox("fileSizeField");
|
||||
varTree = tree();
|
||||
|
||||
sizeLimitCheckBox = checkBox("sizeLimitToggle");
|
||||
sizeUnitComboBox = comboBox("unitsComboBox");
|
||||
|
||||
varTree = varTreePanel.tree();
|
||||
|
||||
searchBar = varSearchPanel.textBox();
|
||||
searchResults = varSearchPanel.scrollPane();
|
||||
caseSCheckBox = varSearchPanel.checkBox("caseSensitiveCheckBox");
|
||||
regexCheckBox = varSearchPanel.checkBox("regularExpressionCheckBox");
|
||||
// searchBar = varSearchPanel.textBox();
|
||||
// searchResults = varSearchPanel.scrollPane();
|
||||
// caseSCheckBox = varSearchPanel.checkBox("caseSensitiveCheckBox");
|
||||
// regexCheckBox = varSearchPanel.checkBox("regularExpressionCheckBox");
|
||||
}
|
||||
|
||||
//---------------------------
|
||||
@ -88,77 +58,12 @@ public class TVFixture extends FrameFixture {
|
||||
varTree.doubleClickPath(varPath);
|
||||
}
|
||||
|
||||
public void setOptions(int opts) {
|
||||
switch (opts & 0b11100000000) {
|
||||
case BINARY: selectOption("Binary"); break;
|
||||
case ASCII: selectOption("Ascii"); break;
|
||||
case HDF5: selectOption("HDF5"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch (opts & 0b00011100000) {
|
||||
case ALWAYS: selectOption("Always"); break;
|
||||
case CHANGES: selectOption("Changes"); break;
|
||||
case STEP: selectOption("StepChanges"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch (opts & 0b00000011100) {
|
||||
case BUFFER: selectOption("Buffer"); break;
|
||||
case NO_BUFFER: selectOption("NoBuffer"); break;
|
||||
case RING_BUFFER: selectOption("RingBuffer"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
switch (opts & 0b00000000011) {
|
||||
case SINGLE_PREC_ON: setSinglePrec(true); break;
|
||||
case SINGLE_PREC_OFF: setSinglePrec(false); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMenuItem(String path) {
|
||||
menuItem("saveDRMenuItem").click();
|
||||
|
||||
JFileChooserFixture fc = fileChooser(timeout(1500));
|
||||
JTextComponentFixture fileEntryTextBox = fc.fileNameTextBox();
|
||||
|
||||
fileEntryTextBox.deleteText()
|
||||
.enterText(path);
|
||||
fc.approve();
|
||||
|
||||
}
|
||||
|
||||
public void openMenuItem(String path) {
|
||||
menuItem("openDRMenuItem").click();
|
||||
|
||||
JFileChooserFixture fc = fileChooser(timeout(1500));
|
||||
JTextComponentFixture fileEntryTextBox = fc.fileNameTextBox();
|
||||
|
||||
fileEntryTextBox.deleteText()
|
||||
.enterText(path);
|
||||
fc.approve();
|
||||
}
|
||||
|
||||
public void setGroupName(String name) {
|
||||
nameField.deleteText()
|
||||
.enterText(name);
|
||||
}
|
||||
|
||||
public void setCycle(String cycle) {
|
||||
cycleField.deleteText()
|
||||
.enterText(cycle);
|
||||
}
|
||||
|
||||
public void setMaxFileSize(String fileSize, Size unit) {
|
||||
fileSizeField.deleteText()
|
||||
.enterText(fileSize);
|
||||
switch(unit) {
|
||||
case B: sizeUnitComboBox.selectItem("B"); break;
|
||||
case KB: sizeUnitComboBox.selectItem("KiB"); break;
|
||||
case MB: sizeUnitComboBox.selectItem("MiB"); break;
|
||||
case GB: sizeUnitComboBox.selectItem("GiB"); break;
|
||||
case UNLIMITED: sizeLimitCheckBox.check(); break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void enterQuery(String query) {
|
||||
@ -175,38 +80,6 @@ public class TVFixture extends FrameFixture {
|
||||
|
||||
}
|
||||
|
||||
public int getSelectedOptions() {
|
||||
int opts = 0b00000000000;
|
||||
|
||||
if (getOptionState("Binary"))
|
||||
opts |= BINARY;
|
||||
else if(getOptionState("Ascii"))
|
||||
opts |= ASCII;
|
||||
else if (getOptionState("HDF5"))
|
||||
opts |= HDF5;
|
||||
|
||||
if (getOptionState("Always"))
|
||||
opts |= ALWAYS;
|
||||
else if(getOptionState("Changes"))
|
||||
opts |= CHANGES;
|
||||
else if (getOptionState("StepChanges"))
|
||||
opts |= STEP;
|
||||
|
||||
if (getOptionState("Buffer"))
|
||||
opts |= BUFFER;
|
||||
else if(getOptionState("NoBuffer"))
|
||||
opts |= NO_BUFFER;
|
||||
else if (getOptionState("RingBuffer"))
|
||||
opts |= RING_BUFFER;
|
||||
|
||||
if(isSinglePrec())
|
||||
opts |= SINGLE_PREC_ON;
|
||||
else
|
||||
opts |= SINGLE_PREC_OFF;
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
public String[] getSelectedVars() {
|
||||
return varSelectedPanel.list().contents();
|
||||
}
|
||||
@ -216,30 +89,6 @@ public class TVFixture extends FrameFixture {
|
||||
return list.length > 0 ? list : null;
|
||||
}
|
||||
|
||||
private boolean getOptionState(String ID) {
|
||||
String menuItemName = "selectDR" + ID + "MenuItem";
|
||||
return menuItem(menuItemName).target().isSelected();
|
||||
}
|
||||
|
||||
private void selectOption(String ID) {
|
||||
String menuItemName = "selectDR" + ID + "MenuItem";
|
||||
menuItem(menuItemName).click();
|
||||
}
|
||||
|
||||
private boolean isSinglePrec() {
|
||||
String singlePrecName = "toggleSinglePrecisionCheckBoxMenuItem";
|
||||
return menuItem(singlePrecName).target().isSelected();
|
||||
}
|
||||
|
||||
private void setSinglePrec(boolean state) {
|
||||
String singlePrecName = "toggleSinglePrecisionCheckBoxMenuItem";
|
||||
JMenuItemFixture singlePrecCB = menuItem(singlePrecName);
|
||||
JCheckBoxMenuItem singlePrecTarget = (JCheckBoxMenuItem) singlePrecCB.target();
|
||||
if(state ^ singlePrecTarget.getState()){
|
||||
singlePrecCB.click();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------
|
||||
// Inner Classes
|
||||
//---------------------------
|
||||
@ -258,32 +107,4 @@ public class TVFixture extends FrameFixture {
|
||||
return pane.getTitle().equals(title);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// Enumerations
|
||||
//----------------------------
|
||||
|
||||
public enum Size {
|
||||
B(""), KB(" * 1024"), MB(" * 1048576"), GB(" * 1073741824"), UNLIMITED("");
|
||||
|
||||
public final String TAG;
|
||||
|
||||
Size(String val) { TAG = val; }
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// Constant Variables
|
||||
//----------------------------
|
||||
|
||||
public final static int BINARY = 0b10000000000,
|
||||
ASCII = 0b01000000000,
|
||||
HDF5 = 0b00100000000,
|
||||
ALWAYS = 0b00010000000,
|
||||
CHANGES = 0b00001000000,
|
||||
STEP = 0b00000100000,
|
||||
BUFFER = 0b00000010000,
|
||||
NO_BUFFER = 0b00000001000,
|
||||
RING_BUFFER = 0b00000000100,
|
||||
SINGLE_PREC_ON = 0b00000000010,
|
||||
SINGLE_PREC_OFF = 0b00000000001;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user