use of org.jdom2.Document in project JMRI by JMRI.
the class QualifierAdderTest method setUp.
// The minimal setup for log4J
@Override
protected void setUp() {
apps.tests.Log4JFixture.setUp();
p = new ProgDebugger();
cvtable = new CvTableModel(new JLabel(""), p);
model = new VariableTableModel(new JLabel(""), new String[] { "Name", "Value" }, cvtable, new IndexedCvTableModel(new JLabel(""), p));
// create a JDOM tree with just some elements
Element root = new Element("decoder-config");
Document doc = new Document(root);
doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
// add some elements
Element el1, el2, el3;
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(el1 = new Element("variable").setAttribute("CV", "1").setAttribute("item", "one").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el2 = new Element("variable").setAttribute("CV", "2").setAttribute("item", "two").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1"))).addContent(el3 = new Element("variable").setAttribute("CV", "3").setAttribute("item", "three").addContent(new Element("decVal").setAttribute("max", "31").setAttribute("min", "1")))));
// end of adding contents
// and test reading this
model.setRow(0, el1);
model.setRow(1, el2);
model.setRow(1, el3);
v1 = model.findVar("one");
v2 = model.findVar("two");
v3 = model.findVar("three");
}
use of org.jdom2.Document in project JMRI by JMRI.
the class QualifierAdderTest method testExistsOk1.
public void testExistsOk1() {
Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("one")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("1")));
// create a JDOM tree with just some elements
Element root = new Element("decoder-config");
Document doc = new Document(root);
doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
root.addContent(// the sites information here lists all relevant
new Element("decoder").addContent(new Element("variables").addContent(e)));
// print JDOM tree, to check
//org.jdom2.output.XMLOutputter fmt
// = new org.jdom2.output.XMLOutputter(org.jdom2.output.Format.getPrettyFormat());
//try {
// fmt.output(doc, System.out);
//} catch (Exception ex) { log.error("error writing XML", ex);}
// test Exists
processModifierElements(e, v2);
Assert.assertTrue(v2.getAvailable());
}
use of org.jdom2.Document in project JMRI by JMRI.
the class PaneProgPaneTest method testPaneRead.
// test storage of programming info in list
@Test
public void testPaneRead() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
log.debug("testPaneRead starts");
// initialize the system
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
log.debug("VariableTableModel ctor complete");
// have to add a couple of defined variables
Element el0 = new Element("variable").setAttribute("CV", "2").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
Element el1 = new Element("variable").setAttribute("CV", "3").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
varModel.setRow(0, el0);
varModel.setRow(1, el1);
PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
p.resetCv(2, 20);
p.resetCv(3, 30);
// test by invoking
progPane.readAllButton.setSelected(true);
// wait for reply (normally, done by callback; will check that later)
JUnitUtil.waitFor(() -> {
return !progPane.isBusy();
}, "progPane.isBusy");
Assert.assertEquals("CV 2 value ", "20", varModel.getValString(0));
Assert.assertEquals("CV 3 value ", "30", varModel.getValString(1));
log.debug("testPaneRead ends ok");
}
use of org.jdom2.Document in project JMRI by JMRI.
the class PaneProgPaneTest method testPaneWrite.
@Test
public void testPaneWrite() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
log.debug("testPaneWrite starts");
// initialize the system
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
log.debug("VariableTableModel ctor complete");
// have to add a couple of defined variables
Element el0 = new Element("variable").setAttribute("CV", "2").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "20").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
Element el1 = new Element("variable").setAttribute("CV", "3").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "30").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
varModel.setRow(0, el0);
varModel.setRow(1, el1);
log.debug("Two elements loaded");
// PaneProgPane progPane = new PaneProgPane("name", pane1, cvModel, varModel, null);
PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
p.resetCv(2, -1);
p.resetCv(3, -1);
// test by invoking
progPane.writeAllButton.setSelected(true);
// wait for reply (normally, done by callback; will check that later)
JUnitUtil.waitFor(() -> {
return !progPane.isBusy();
}, "progPane.isBusy");
Assert.assertEquals("CV 2 value ", 20, p.getCvVal(2));
Assert.assertEquals("CV 3 value ", 30, p.getCvVal(3));
log.debug("testPaneWrite ends ok");
}
use of org.jdom2.Document in project JMRI by JMRI.
the class PaneProgPaneTest method testPaneReadOpCount.
// test counting of read operations needed
@Test
public void testPaneReadOpCount() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
log.debug("testPaneReadOpCount starts");
// initialize the system
// make sure XML document is ready
setupDoc();
PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {
// dummy implementations
@Override
protected JPanel getModePane() {
return null;
}
};
CvTableModel cvModel = new CvTableModel(new JLabel(), p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
String[] args = { "CV", "Name" };
VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
// have to add a couple of defined variables
int row = 0;
// note these +have+ to be on this pane, e.g. named in setupDoc
Element el0 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
varModel.setRow(row++, el0);
Element el1 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
varModel.setRow(row++, el1);
Element el2 = new Element("variable").setAttribute("CV", "67").setAttribute("label", "Normal direction of motion").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").addContent(new Element("speedTableVal"));
varModel.setRow(row++, el2);
Element el3 = new Element("variable").setAttribute("CV", "68").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Address").addContent(new Element("decVal"));
varModel.setRow(row++, el3);
PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
// start actual testing
Assert.assertEquals("number of all CVs to read ", 29, progPane.countOpsNeeded(true, false));
Assert.assertEquals("number of all CVs to write ", 29, progPane.countOpsNeeded(false, false));
Assert.assertEquals("number of changed CVs to read ", 0, progPane.countOpsNeeded(true, true));
Assert.assertEquals("number of changed CVs to write ", 0, progPane.countOpsNeeded(false, true));
// mark some as needing to be written
(cvModel.allCvMap().get("1")).setValue(12);
Assert.assertEquals("modified all CVs to read ", 29, progPane.countOpsNeeded(true, false));
Assert.assertEquals("modified all CVs to write ", 29, progPane.countOpsNeeded(false, false));
Assert.assertEquals("modified changed CVs to read ", 1, progPane.countOpsNeeded(true, true));
Assert.assertEquals("modified changed CVs to write ", 1, progPane.countOpsNeeded(false, true));
(cvModel.allCvMap().get("69")).setValue(12);
// careful - might change more than one CV!
Assert.assertEquals("spdtbl all CVs to read ", 29, progPane.countOpsNeeded(true, false));
Assert.assertEquals("spdtbl all CVs to write ", 29, progPane.countOpsNeeded(false, false));
Assert.assertEquals("spdtbl changed CVs to read ", 2, progPane.countOpsNeeded(true, true));
Assert.assertEquals("spdtbl changed CVs to write ", 2, progPane.countOpsNeeded(false, true));
log.debug("testPaneReadOpCount ends ok");
}
Aggregations