mirror of
https://github.com/nasa/trick.git
synced 2025-03-12 15:33:58 +00:00
Finished Trick View Test Suite
This commit is contained in:
parent
3fc5f5fc80
commit
d35d750a74
@ -78,6 +78,23 @@ public abstract class ApplicationTest extends AssertJSwingJUnitTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> void assertThat2DArraysAreEqual(T[][] array_a, T[][] array_b) {
|
||||
assertThat(array_a.length)
|
||||
.withFailMessage("Unexpected number of rows.")
|
||||
.isEqualTo(array_b.length);
|
||||
|
||||
for (int i = 0; i < array_a.length; i++) {
|
||||
assertThat(array_a[i].length)
|
||||
.withFailMessage("Unexpected number of columns.")
|
||||
.isEqualTo(array_b[i].length);
|
||||
|
||||
for (int j = 0; j < array_a[i].length; j++) {
|
||||
assertThat(array_a[i][j])
|
||||
.isEqualTo(array_b[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected FrameFixture getFrameByTitle(String title) {
|
||||
FrameFixture frame = findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
|
||||
protected boolean isMatching(Frame frame) {
|
||||
|
@ -6,6 +6,7 @@ import java.io.PrintWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
@ -163,12 +164,53 @@ public class TVApplicationTest extends ApplicationTest {
|
||||
assertThat(found_vars[i]).isEqualTo(SEARCH_VARS[i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditTable() {
|
||||
// ARRANGE
|
||||
final String[][] SEL_VARS = { { "drx.drt.a", "88", "1", "Decimal" },
|
||||
{ "drx.drt.b", "88", "1", "Decimal" },
|
||||
{ "drx.drt.c", "88", "1", "Decimal" },
|
||||
{ "drx.drt.uintB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.intB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.ucharB.var1", "3", "1", "Decimal" },
|
||||
{ "drx.drt.charB.var1", "-1", "1", "Decimal" },
|
||||
{ "drx.drt.ushortB.var1", "14", "1", "Decimal" },
|
||||
{ "drx.drt.shortB.var1", "78", "1", "Decimal" },
|
||||
{ "drx.drt.mixB.var1", "1", "1", "Decimal" } };
|
||||
|
||||
String[][] res_vars;
|
||||
String[] inital_values = new String[SEL_VARS.length];
|
||||
|
||||
// ACT
|
||||
for(int i = 0; i < SEL_VARS.length; i++){
|
||||
tv_fix.selectVar(SEL_VARS[i][0]);
|
||||
sleep(250);
|
||||
}
|
||||
|
||||
for(int i = 0; i < SEL_VARS.length; i++){
|
||||
inital_values[i] = tv_fix.getCellValue(i, 1);
|
||||
tv_fix.editVariableTable(i, 1, SEL_VARS[i][1] + "\n");
|
||||
sleep(500);
|
||||
}
|
||||
|
||||
res_vars = tv_fix.getSelectedVars();
|
||||
|
||||
// ASSERT
|
||||
assertThat2DArraysAreEqual(res_vars, SEL_VARS);
|
||||
|
||||
// CLEANUP
|
||||
for(int i = 0; i < inital_values.length; i++) {
|
||||
tv_fix.editVariableTable(i, 1, inital_values[i]);
|
||||
sleep(250);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave() {
|
||||
// ARRANGE
|
||||
final File EXPECTED_OUTPUT = new File("src/test/java/trick/tv/resources/tv_save_test.tv"),
|
||||
SAVED_OUTPUT = new File("test_results.tv"),
|
||||
FAILED_TEST = new File("failed_test.tv");
|
||||
SAVED_OUTPUT = new File("test_results.tv"),
|
||||
FAILED_TEST = new File("failed_test.tv");
|
||||
final String[] SEL_VARS = { "drx.drt.a", "drx.drt.b", "drx.drt.c",
|
||||
"drx.drt.uintB.var1", "drx.drt.intB.var1",
|
||||
"drx.drt.ucharB.var1", "drx.drt.charB.var1",
|
||||
@ -212,52 +254,135 @@ public class TVApplicationTest extends ApplicationTest {
|
||||
@Test
|
||||
public void testLoadVariables() {
|
||||
// ARRANGE
|
||||
final File SAVED_FILE = new File("src/test/java/trick/tv/resources/tv_save_test.tv");
|
||||
final String[][] SEL_VARS = { { "drx.drt.a", "8", "1", "Decimal" },
|
||||
{ "drx.drt.b", "8", "1", "Decimal" },
|
||||
{ "drx.drt.c", "8", "1", "Decimal" },
|
||||
final File SAVED_FILE = new File("src/test/java/trick/tv/resources/tv_load_test.tv");
|
||||
final String[][] SEL_VARS = { { "drx.drt.a", "97", "1", "Decimal" },
|
||||
{ "drx.drt.b", "98", "1", "Decimal" },
|
||||
{ "drx.drt.c", "-1234","1", "Decimal" },
|
||||
{ "drx.drt.uintB.var1", "128", "1", "Decimal" },
|
||||
{ "drx.drt.intB.var1", "63", "1", "Decimal" },
|
||||
{ "drx.drt.ucharB.var1", "2", "1", "Decimal" },
|
||||
{ "drx.drt.charB.var1", "1", "1", "Decimal" },
|
||||
{ "drx.drt.ushortB.var1", "4", "1", "Decimal" },
|
||||
{ "drx.drt.shortB.var1", "127", "1", "Decimal" },
|
||||
{ "drx.drt.mixB.var1", "3", "1", "Decimal" } };
|
||||
|
||||
String[][] res_vars;
|
||||
|
||||
// ACT
|
||||
tv_fix.openMenuItem(SAVED_FILE);
|
||||
|
||||
sleep(500);
|
||||
|
||||
res_vars = tv_fix.getSelectedVars();
|
||||
|
||||
// ASSERT
|
||||
assertThat2DArraysAreEqual(res_vars, SEL_VARS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadVariables_SetValues() {
|
||||
// ARRANGE
|
||||
final File SAVED_FILE = new File("src/test/java/trick/tv/resources/tv_load_test.tv"),
|
||||
ORIGINAL_VALS_FILE = new File("src/test/java/trick/tv/resources/tv_save_test.tv");
|
||||
final String[][] SEL_VARS = { { "drx.drt.a", "88", "1", "Decimal" },
|
||||
{ "drx.drt.b", "88", "1", "Decimal" },
|
||||
{ "drx.drt.c", "88", "1", "Decimal" },
|
||||
{ "drx.drt.uintB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.intB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.ucharB.var1", "3", "1", "Decimal" },
|
||||
{ "drx.drt.charB.var1", "-1", "1", "Decimal" },
|
||||
{ "drx.drt.ushortB.var1", "14", "1", "Decimal" },
|
||||
{ "drx.drt.shortB.var1", "78", "1", "Decimal" },
|
||||
{ "drx.drt.mixB.var1", "3", "1", "Decimal" } };
|
||||
{ "drx.drt.mixB.var1", "1", "1", "Decimal" } };
|
||||
|
||||
String[][] res_vars;
|
||||
|
||||
// ACT
|
||||
tv_fix.openSetMenuItem(SAVED_FILE);
|
||||
|
||||
sleep(500);
|
||||
|
||||
res_vars = tv_fix.getSelectedVars();
|
||||
|
||||
// ASSERT
|
||||
assertThat2DArraysAreEqual(res_vars, SEL_VARS);
|
||||
|
||||
// CLEANUP
|
||||
tv_fix.openSetMenuItem(ORIGINAL_VALS_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetValues() {
|
||||
// ARRANGE
|
||||
final File SAVED_FILE = new File("src/test/java/trick/tv/resources/tv_load_test.tv"),
|
||||
ORIGINAL_VALS_FILE = new File("src/test/java/trick/tv/resources/tv_save_test.tv");
|
||||
final String[][] SEL_VARS = { { "drx.drt.a", "88", "1", "Decimal" },
|
||||
{ "drx.drt.b", "88", "1", "Decimal" },
|
||||
{ "drx.drt.c", "88", "1", "Decimal" },
|
||||
{ "drx.drt.uintB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.intB.var1", "28", "1", "Decimal" },
|
||||
{ "drx.drt.ucharB.var1", "3", "1", "Decimal" },
|
||||
{ "drx.drt.charB.var1", "-1", "1", "Decimal" },
|
||||
{ "drx.drt.ushortB.var1", "14", "1", "Decimal" },
|
||||
{ "drx.drt.shortB.var1", "78", "1", "Decimal" },
|
||||
{ "drx.drt.mixB.var1", "1", "1", "Decimal" } };
|
||||
|
||||
String[][] res_vars1, res_vars2;
|
||||
|
||||
// ACT
|
||||
tv_fix.setValMenuItem(SAVED_FILE);
|
||||
|
||||
sleep(500);
|
||||
|
||||
res_vars1 = tv_fix.getSelectedVars();
|
||||
|
||||
for(int i = 0; i < SEL_VARS.length; i++){
|
||||
tv_fix.selectVar(SEL_VARS[i][0]);
|
||||
sleep(250);
|
||||
}
|
||||
|
||||
for(int i = 0; i < SEL_VARS.length; i++){
|
||||
tv_fix.editVariableTable(i, 1, SEL_VARS[i][1] + "\n");
|
||||
sleep(500);
|
||||
}
|
||||
|
||||
tv_fix.openMenuItem(SAVED_FILE);
|
||||
|
||||
res_vars = tv_fix.getSelectedVars();
|
||||
res_vars2 = tv_fix.getSelectedVars();
|
||||
|
||||
// ASSERT
|
||||
assumeThat(res_vars.length)
|
||||
.withFailMessage("Unexpected number of rows.")
|
||||
.isEqualTo(SEL_VARS.length);
|
||||
assertThat(res_vars1.length)
|
||||
.withFailMessage("Variable Table has unexpected Entries: %s\n", Arrays.deepToString(res_vars1))
|
||||
.isEqualTo(0);
|
||||
|
||||
assertThat2DArraysAreEqual(res_vars2, SEL_VARS);
|
||||
|
||||
for (int i = 0; i < res_vars.length; i++) {
|
||||
assumeThat(res_vars[i].length)
|
||||
.withFailMessage("Unexpected number of columns.")
|
||||
.isEqualTo(SEL_VARS[i].length);
|
||||
|
||||
for (int j = 0; j < res_vars[0].length; j++) {
|
||||
assertThat(res_vars[i][j])
|
||||
.isEqualTo(SEL_VARS[i][j]);
|
||||
}
|
||||
}
|
||||
// CLEANUP
|
||||
tv_fix.openSetMenuItem(ORIGINAL_VALS_FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMonitorToggle() {
|
||||
// ARRANGE
|
||||
final String[] EXP_VAR_MONITOR = { "drx.drt.a", "97", "1", "Decimal" },
|
||||
EXP_VAR_NO_MONITOR = { "drx.drt.a", "<Unknown>", "1", "Decimal" };
|
||||
String[] var_no_monitor, var_monitor;
|
||||
|
||||
// ACT
|
||||
tv_fix.clickMonitorToggleMenuItem();
|
||||
tv_fix.selectVar(EXP_VAR_MONITOR[0]);
|
||||
sleep(250);
|
||||
|
||||
var_no_monitor = tv_fix.getSelectedVars()[0];
|
||||
tv_fix.clickMonitorToggleMenuItem();
|
||||
sleep(500);
|
||||
|
||||
var_monitor = tv_fix.getSelectedVars()[0];
|
||||
|
||||
// ASSERT
|
||||
assertThat(var_monitor.length).isEqualTo(EXP_VAR_MONITOR.length);
|
||||
assertThat(var_no_monitor.length).isEqualTo(EXP_VAR_NO_MONITOR.length);
|
||||
|
||||
for(int i = 0; i < EXP_VAR_MONITOR.length; i++) {
|
||||
assertThat(var_no_monitor[i]).isEqualTo(EXP_VAR_NO_MONITOR[i]);
|
||||
assertThat(var_monitor[i]).isEqualTo(EXP_VAR_MONITOR[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int getOpenPort() {
|
||||
String port = "39595";
|
||||
File port_info;
|
||||
|
@ -11,6 +11,7 @@ import org.assertj.swing.data.TableCell;
|
||||
import org.assertj.swing.fixture.FrameFixture;
|
||||
import org.assertj.swing.fixture.JCheckBoxFixture;
|
||||
import org.assertj.swing.fixture.JFileChooserFixture;
|
||||
import org.assertj.swing.fixture.JMenuItemFixture;
|
||||
import org.assertj.swing.fixture.JOptionPaneFixture;
|
||||
import org.assertj.swing.fixture.JPanelFixture;
|
||||
import org.assertj.swing.fixture.JScrollPaneFixture;
|
||||
@ -79,7 +80,25 @@ public class TVFixture extends FrameFixture {
|
||||
return triggerFileChooserMenuItem(file, "Open");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean openSetMenuItem(File file) {
|
||||
if (file != null && file.exists())
|
||||
return triggerFileChooserMenuItem(file, "Open & Set");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setValMenuItem(File file) {
|
||||
if (file != null && file.exists())
|
||||
return triggerFileChooserMenuItem(file, "Set");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clickMonitorToggleMenuItem() {
|
||||
menuItemByText("Toggle Monitor").click();
|
||||
}
|
||||
|
||||
public void enterQuery(String query) {
|
||||
varSearchPanel.textBox()
|
||||
@ -111,8 +130,12 @@ public class TVFixture extends FrameFixture {
|
||||
|
||||
public void editVariableTable(int row, int col, String entry) {
|
||||
TableCell cell = TableCell.row(row).column(col);
|
||||
varSelectedPanel
|
||||
.enterValue(cell, entry);
|
||||
varSelectedPanel.enterValue(cell, entry);
|
||||
}
|
||||
|
||||
public String getCellValue(int row, int col) {
|
||||
TableCell cell = TableCell.row(row).column(col);
|
||||
return varSelectedPanel.valueAt(cell);
|
||||
}
|
||||
|
||||
public String[] getSearchResults() {
|
||||
@ -120,18 +143,22 @@ public class TVFixture extends FrameFixture {
|
||||
return list.length > 0 ? list : null;
|
||||
}
|
||||
|
||||
private JMenuItemFixture menuItemByText(String text) {
|
||||
return menuItem(new GenericTypeMatcher<JMenuItem>(JMenuItem.class) {
|
||||
@Override
|
||||
protected boolean isMatching(JMenuItem item) {
|
||||
return item.getText().equals(text);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private boolean triggerFileChooserMenuItem(File file, String menuItemText) {
|
||||
if(file == null) return false;
|
||||
|
||||
String path = file.getAbsolutePath();
|
||||
|
||||
try {
|
||||
menuItem(new GenericTypeMatcher<JMenuItem>(JMenuItem.class) {
|
||||
@Override
|
||||
protected boolean isMatching(JMenuItem item) {
|
||||
return item.getText().equals(menuItemText);
|
||||
};
|
||||
}).click();
|
||||
menuItemByText(menuItemText).click();
|
||||
|
||||
JFileChooserFixture fc = fileChooser(timeout(1500));
|
||||
JTextComponentFixture fileEntryTextBox = fc.fileNameTextBox();
|
||||
|
@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<trickView>
|
||||
<cyclePeriod>0.5</cyclePeriod>
|
||||
<variable>
|
||||
<name>drx.drt.a</name>
|
||||
<tvByte>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:byte">88</value>
|
||||
<unsigned>false</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvByte>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.b</name>
|
||||
<tvByte>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:byte">88</value>
|
||||
<unsigned>true</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvByte>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.c</name>
|
||||
<tvShort>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:short">88</value>
|
||||
<unsigned>false</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvShort>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.uintB.var1</name>
|
||||
<tvInteger>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">28</value>
|
||||
<unsigned>true</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvInteger>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.intB.var1</name>
|
||||
<tvInteger>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">28</value>
|
||||
<unsigned>false</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvInteger>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.ucharB.var1</name>
|
||||
<tvByte>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:byte">3</value>
|
||||
<unsigned>true</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvByte>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.charB.var1</name>
|
||||
<tvByte>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:byte">-1</value>
|
||||
<unsigned>false</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvByte>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.ushortB.var1</name>
|
||||
<tvShort>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:short">14</value>
|
||||
<unsigned>true</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvShort>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.shortB.var1</name>
|
||||
<tvShort>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:short">78</value>
|
||||
<unsigned>false</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvShort>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
<variable>
|
||||
<name>drx.drt.mixB.var1</name>
|
||||
<tvByte>
|
||||
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:byte">1</value>
|
||||
<unsigned>true</unsigned>
|
||||
<format>Decimal</format>
|
||||
</tvByte>
|
||||
<state>Valid</state>
|
||||
<units>1</units>
|
||||
</variable>
|
||||
</trickView>
|
Loading…
x
Reference in New Issue
Block a user