mirror of
https://github.com/nasa/trick.git
synced 2025-01-28 15:14:36 +00:00
Update Dre Test Suite
This commit is contained in:
parent
d7a58f56d1
commit
e1d66dd724
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,6 +22,7 @@ bin/trick-gxplot
|
||||
bin/trick-trk2ascii
|
||||
bin/trick-trk2csv
|
||||
bin/trick-trkConvert
|
||||
build/
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
trick_test
|
||||
@ -43,3 +44,4 @@ trickops_logs/
|
||||
coverage.info
|
||||
*.dSYM
|
||||
*.log
|
||||
failed_test.dr
|
||||
|
@ -16,7 +16,10 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Toolkit;
|
||||
import java.beans.Transient;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
@ -62,6 +65,19 @@ public abstract class ApplicationTest extends AssertJSwingJUnitTestCase {
|
||||
try {Thread.sleep(ms);} catch(Exception ignored) {}
|
||||
}
|
||||
|
||||
public boolean sameFileContent(File a, File b) {
|
||||
try {
|
||||
byte[] a_bytes = Files.readAllBytes(a.toPath()),
|
||||
b_bytes = Files.readAllBytes(b.toPath());
|
||||
|
||||
return Arrays.equals(a_bytes, b_bytes);
|
||||
} catch(Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected FrameFixture getFrameByTitle(String title) {
|
||||
FrameFixture frame = findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
|
||||
protected boolean isMatching(Frame frame) {
|
||||
|
@ -19,6 +19,11 @@ import static org.assertj.swing.launcher.ApplicationLauncher.application;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static trick.dre.fixtures.DreFixture.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test DreApplication life cycle.
|
||||
@ -196,11 +201,6 @@ public class DreApplicationTest extends ApplicationTest {
|
||||
|
||||
@Test
|
||||
public void testSearchVars() {
|
||||
// System.out.println("BEFORE SEARCH:\n" + );
|
||||
// dre_fix.enterQuery("var1\n");
|
||||
// System.out.println("\nAFTER SEARCH:\n" + dre_fix.getSearchResults());
|
||||
// sleep(10000);
|
||||
|
||||
// ARRANGE
|
||||
final String[] SEARCH_VARS = { "drx.drt.uintB.var1" , "drx.drt.intB.var1",
|
||||
"drx.drt.ucharB.var1" , "drx.drt.charB.var1",
|
||||
@ -231,12 +231,166 @@ public class DreApplicationTest extends ApplicationTest {
|
||||
GRP_CYCLE = "5.2",
|
||||
GRP_SIZE = "12";
|
||||
final Size GRP_UNIT = Size.MB;
|
||||
|
||||
final String[] EXP_LINES = { "drg.append(trick.DRBinary(\"" + GRP_NAME + "\"))",
|
||||
"drg[DR_GROUP_ID].set_cycle(" + GRP_CYCLE + ")",
|
||||
"drg[DR_GROUP_ID].set_max_file_size(" + GRP_SIZE + GRP_UNIT.TAG + ")" };
|
||||
|
||||
MockDreApplication app = MockDreApplication.getInstance();
|
||||
String[] output;
|
||||
boolean setGrpName = false,
|
||||
setCycle = false,
|
||||
setSize = false;
|
||||
|
||||
// ACT
|
||||
dre_fix.setGroupName(GRP_NAME);
|
||||
dre_fix.setCycle(GRP_CYCLE);
|
||||
dre_fix.setMaxFileSize(GRP_SIZE, GRP_UNIT);
|
||||
|
||||
sleep(10000);
|
||||
output = app.getSettingsOutput();
|
||||
|
||||
// Assert
|
||||
for(String line : output) {
|
||||
if (line.contains("drg.append")) {
|
||||
setGrpName = true;
|
||||
assertThat(line).isEqualTo(EXP_LINES[0]);
|
||||
} else if (line.contains("set_cycle")) {
|
||||
setCycle = true;
|
||||
assertThat(line).isEqualTo(EXP_LINES[1]);
|
||||
} else if(line.contains("set_max_file_size")) {
|
||||
setSize = true;
|
||||
line = line.split(" # ")[0];
|
||||
assertThat(line).isEqualTo(EXP_LINES[2]);
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(setGrpName)
|
||||
.withFailMessage("Group Name was not set...\n")
|
||||
.isTrue();
|
||||
|
||||
assertThat(setCycle)
|
||||
.withFailMessage("Cycle was not set...\n")
|
||||
.isTrue();
|
||||
|
||||
assertThat(setSize)
|
||||
.withFailMessage("Max File Size was not set...\n")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveDataRecordGroup() {
|
||||
// ARRANGE
|
||||
final File TEST_DR = new File("src/test/java/trick/dre/resources/dre_test_ascii.dr");
|
||||
final String NAME = "DR_Test_ASCII",
|
||||
CYCLE = "0.2",
|
||||
SIZE = "3",
|
||||
VAR_PREFIX = "drx.drt.",
|
||||
VAR_POSTFIX = ".var";
|
||||
final Size UNIT = Size.MB;
|
||||
final String[] VAR_TYPES = {"charB", "intB", "shortB", "ucharB", "uintB", "ushortB", "mixB"};
|
||||
String var;
|
||||
File result = new File("test_result.dr");
|
||||
boolean file_as_expected = false;
|
||||
|
||||
dre_fix.setGroupName(NAME);
|
||||
dre_fix.setCycle(CYCLE);
|
||||
dre_fix.setMaxFileSize(SIZE, UNIT);
|
||||
dre_fix.setOptions(ASCII | CHANGES | SINGLE_PREC_ON | NO_BUFFER);
|
||||
|
||||
for(int i = 0; i < VAR_TYPES.length; i++) {
|
||||
for(int j = 1; j <= 4; j++) {
|
||||
var = VAR_PREFIX + VAR_TYPES[i] + VAR_POSTFIX + j;
|
||||
dre_fix.selectVar(var);
|
||||
sleep(250);
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null && result.exists()) {
|
||||
result.delete();
|
||||
}
|
||||
result.deleteOnExit();
|
||||
|
||||
assumeThat(result != null && !result.exists()).isTrue();
|
||||
assumeThat(TEST_DR != null && TEST_DR.exists())
|
||||
.withFailMessage("Benchmark File Not Found!")
|
||||
.isTrue();
|
||||
|
||||
//ACT
|
||||
dre_fix.saveMenuItem("test_result");
|
||||
file_as_expected = sameFileContent(TEST_DR, result);
|
||||
|
||||
//ASSERT
|
||||
if (!file_as_expected) {
|
||||
try{
|
||||
Files.copy( result.toPath(),
|
||||
new File("failed_test.dr").toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING );
|
||||
} catch(Exception IGNORED) {}
|
||||
|
||||
assertThat(file_as_expected)
|
||||
.withFailMessage("Generated File doesn't match Benchmark. Failed .dr file is in java directory\n")
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadDataRecordGroup() {
|
||||
// ARRANGE
|
||||
final File TEST_DR = new File("src/test/java/trick/dre/resources/dre_test_ascii.dr");
|
||||
final int EXP_OPTIONS = ASCII | CHANGES | SINGLE_PREC_ON | NO_BUFFER;
|
||||
final String EXP_NAME = "DR_Test_ASCII",
|
||||
EXP_CYCLE = "0.2",
|
||||
EXP_SIZE = "3",
|
||||
VAR_PREFIX = "drx.drt.",
|
||||
VAR_POSTFIX = ".var";
|
||||
final Size EXP_UNIT = Size.MB;
|
||||
final String[] VAR_TYPES = {"charB", "intB", "shortB", "ucharB", "uintB", "ushortB", "mixB"};
|
||||
|
||||
MockDreApplication app = MockDreApplication.getInstance();
|
||||
int sel_opts;
|
||||
String name, cycle, size;
|
||||
String[] sel_vars, settings;
|
||||
Size unit;
|
||||
boolean setGrpName = false,
|
||||
setCycle = false,
|
||||
setSize = false;
|
||||
|
||||
//ACT
|
||||
dre_fix.openMenuItem(TEST_DR.getAbsolutePath());
|
||||
|
||||
sel_opts = dre_fix.getSelectedOptions();
|
||||
sel_vars = dre_fix.getSelectedVars();
|
||||
settings = app.getSettingsOutput();
|
||||
|
||||
//ASSERT
|
||||
assumeThat(sel_vars.length).isEqualTo(VAR_TYPES.length * 4);
|
||||
|
||||
assertThat(sel_opts)
|
||||
.withFailMessage("Expected options did not load correctly.\n")
|
||||
.isEqualTo(EXP_OPTIONS);
|
||||
|
||||
for(String line : settings) {
|
||||
if (line.contains("drg.append")) {
|
||||
setGrpName = true;
|
||||
assertThat(line).contains(EXP_NAME);
|
||||
} else if (line.contains("set_cycle")) {
|
||||
setCycle = true;
|
||||
assertThat(line).contains(EXP_CYCLE);
|
||||
} else if(line.contains("set_max_file_size")) {
|
||||
setSize = true;
|
||||
assertThat(line).contains(EXP_SIZE)
|
||||
.contains(EXP_UNIT.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < VAR_TYPES.length; i++) {
|
||||
int base = (i * 4) - 1;
|
||||
for(int j = 1; j <= 4; j++) {
|
||||
String varName = VAR_PREFIX + VAR_TYPES[i] + VAR_POSTFIX + j;
|
||||
int adj_index = base + j;
|
||||
|
||||
assertThat(sel_vars[adj_index])
|
||||
.isEqualTo(varName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package trick.dre;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.assertj.swing.core.GenericTypeMatcher;
|
||||
|
||||
@ -21,6 +22,30 @@ public class MockDreApplication extends DreApplication {
|
||||
}
|
||||
|
||||
public static final MockDreApplication getInstance() { return the_dre; }
|
||||
|
||||
public String[] getSettingsOutput() {
|
||||
StringWriter strWrt = new StringWriter();
|
||||
try{ writeGroupSettings(strWrt); }
|
||||
catch(Exception IGNORED) {}
|
||||
|
||||
return strWrt.toString().split("\n");
|
||||
}
|
||||
|
||||
public String[] getFooterOutput() {
|
||||
StringWriter strWrt = new StringWriter();
|
||||
try{ writeFileFooter(strWrt); }
|
||||
catch(Exception IGNORED) {}
|
||||
|
||||
return strWrt.toString().split("\n");
|
||||
}
|
||||
|
||||
public String[] getVariableOutput() {
|
||||
StringWriter strWrt = new StringWriter();
|
||||
try{ writeVariables(strWrt); }
|
||||
catch(Exception IGNORED) {}
|
||||
|
||||
return strWrt.toString().split("\n");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
File sie;
|
||||
|
@ -2,6 +2,8 @@ package trick.dre.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;
|
||||
@ -128,6 +130,13 @@ public class DreFixture extends FrameFixture {
|
||||
|
||||
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) {
|
||||
@ -254,7 +263,13 @@ public class DreFixture extends FrameFixture {
|
||||
// Enumerations
|
||||
//----------------------------
|
||||
|
||||
public enum Size { B, KB, MB, GB, UNLIMITED }
|
||||
public enum Size {
|
||||
B(""), KB(" * 1024"), MB(" * 1048576"), GB(" * 1073741824"), UNLIMITED("");
|
||||
|
||||
public final String TAG;
|
||||
|
||||
Size(String val) { TAG = val; }
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
// Constant Variables
|
||||
|
@ -0,0 +1,44 @@
|
||||
global DR_GROUP_ID
|
||||
global drg
|
||||
try:
|
||||
if DR_GROUP_ID >= 0:
|
||||
DR_GROUP_ID += 1
|
||||
except NameError:
|
||||
DR_GROUP_ID = 0
|
||||
drg = []
|
||||
|
||||
drg.append(trick.DRAscii("DR_Test_ASCII"))
|
||||
drg[DR_GROUP_ID].set_freq(trick.DR_Changes)
|
||||
drg[DR_GROUP_ID].set_cycle(0.2)
|
||||
drg[DR_GROUP_ID].set_single_prec_only(True)
|
||||
drg[DR_GROUP_ID].set_max_file_size(3 * 1048576) # multiply converts MiB to B --Dr. Dre
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.charB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.charB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.charB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.charB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.intB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.intB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.intB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.intB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.shortB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.shortB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.shortB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.shortB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ucharB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ucharB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ucharB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ucharB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.uintB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.uintB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.uintB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.uintB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ushortB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ushortB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ushortB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.ushortB.var4")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.mixB.var1")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.mixB.var2")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.mixB.var3")
|
||||
drg[DR_GROUP_ID].add_variable("drx.drt.mixB.var4")
|
||||
trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_No_Buffer)
|
||||
drg[DR_GROUP_ID].enable()
|
Loading…
x
Reference in New Issue
Block a user