added a splitter test case

This commit is contained in:
hneemann 2019-06-30 17:10:15 +02:00
parent 46e78bf877
commit 0cb457bcd7
5 changed files with 420 additions and 14 deletions

View File

@ -1046,7 +1046,11 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
@Override @Override
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
try { try {
new ElementHelpDialog(attributeDialog, elementType, element.getElementAttributes()).setVisible(true); new ElementHelpDialog(
attributeDialog,
elementType,
element.getElementAttributes(),
getCircuit().getAttributes().get(Keys.IS_GENERIC)).setVisible(true);
} catch (PinException | NodeException e1) { } catch (PinException | NodeException e1) {
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this); new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this);
} }

View File

@ -24,6 +24,7 @@ import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -37,6 +38,7 @@ public class ElementHelpDialog extends JDialog {
private static final int MAX_WIDTH = 600; private static final int MAX_WIDTH = 600;
private static final int MAX_HEIGHT = 800; private static final int MAX_HEIGHT = 800;
private final boolean showKeys;
private JPanel buttons; private JPanel buttons;
@ -50,7 +52,22 @@ public class ElementHelpDialog extends JDialog {
* @throws NodeException NodeException * @throws NodeException NodeException
*/ */
public ElementHelpDialog(Window parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) throws NodeException, PinException { public ElementHelpDialog(Window parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) throws NodeException, PinException {
this(parent, elementType, elementAttributes, false);
}
/**
* Creates a new instance
*
* @param parent the parents frame
* @param elementType the type of the element
* @param elementAttributes the attributes of this element
* @param showKeys shows the key strings
* @throws PinException PinException
* @throws NodeException NodeException
*/
public ElementHelpDialog(Window parent, ElementTypeDescription elementType, ElementAttributes elementAttributes, boolean showKeys) throws NodeException, PinException {
super(parent, Lang.get("attr_help"), ModalityType.APPLICATION_MODAL); super(parent, Lang.get("attr_help"), ModalityType.APPLICATION_MODAL);
this.showKeys = showKeys;
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
try { try {
@ -72,6 +89,7 @@ public class ElementHelpDialog extends JDialog {
*/ */
public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) throws NodeException, PinException { public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) throws NodeException, PinException {
super(parent, Lang.get("attr_help"), true); super(parent, Lang.get("attr_help"), true);
showKeys = false;
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
MyURLStreamHandlerFactory.setShapeFactory(shapeFactory); MyURLStreamHandlerFactory.setShapeFactory(shapeFactory);
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
@ -143,7 +161,7 @@ public class ElementHelpDialog extends JDialog {
* @throws PinException PinException * @throws PinException PinException
* @throws NodeException NodeException * @throws NodeException NodeException
*/ */
private static void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException { private void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException {
ArrayList<String> chapter = new ArrayList<>(); ArrayList<String> chapter = new ArrayList<>();
String actPath = null; String actPath = null;
@ -187,7 +205,7 @@ public class ElementHelpDialog extends JDialog {
* @param et the element to describe * @param et the element to describe
* @param elementAttributes the actual attributes of the element to describe * @param elementAttributes the actual attributes of the element to describe
*/ */
private static void writeDetailedDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { private void writeDetailedDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException {
w.write("<html><body>"); w.write("<html><body>");
writeHTMLDescription(w, et, elementAttributes); writeHTMLDescription(w, et, elementAttributes);
w.write("</body></html>"); w.write("</body></html>");
@ -203,7 +221,7 @@ public class ElementHelpDialog extends JDialog {
* @throws PinException PinException * @throws PinException PinException
* @throws NodeException NodeException * @throws NodeException NodeException
*/ */
private static void writeHTMLDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { private void writeHTMLDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException {
String translatedName = et.getTranslatedName(); String translatedName = et.getTranslatedName();
if (translatedName.endsWith(".dig")) if (translatedName.endsWith(".dig"))
translatedName = new File(translatedName).getName(); translatedName = new File(translatedName).getName();
@ -242,18 +260,22 @@ public class ElementHelpDialog extends JDialog {
} }
} }
private static void writeEntry(Writer w, String name, String description) throws IOException { private void writeEntry(Writer w, String name, String description) throws IOException {
w.append("<dt><i>").append(escapeHTML(name)).append("</i></dt>\n"); w.append("<dt><i>").append(escapeHTML(name)).append("</i></dt>\n");
if (description != null && description.length() > 0 && !name.equals(description)) if (description != null && description.length() > 0 && !name.equals(description))
w.append("<dd>").append(escapeHTML(description)).append("</dd>\n"); w.append("<dd>").append(escapeHTML(description)).append("</dd>\n");
} }
private static void writeEntry(Writer w, Key key) throws IOException { private void writeEntry(Writer w, Key key) throws IOException {
final String name = key.getName(); final String name = key.getName();
final String description = key.getDescription(); final String description = key.getDescription();
w.append("<dt><i>").append(escapeHTML(name)).append("</i></dt>\n"); w.append("<dt><i>").append(escapeHTML(name)).append("</i></dt>\n");
if (description != null && description.length() > 0 && !name.equals(description)) if (description != null && description.length() > 0 && !name.equals(description)) {
w.append("<dd>").append(escapeHTML(description)).append(" (").append(key.getKey()).append(")</dd>\n"); w.append("<dd>").append(escapeHTML(description));
if (showKeys)
w.append(" (").append(key.getKey()).append(')');
w.append("</dd>\n");
}
} }
/** /**
@ -279,7 +301,7 @@ public class ElementHelpDialog extends JDialog {
if (protocol.equals("image")) if (protocol.equals("image"))
return new URLStreamHandler() { return new URLStreamHandler() {
@Override @Override
protected URLConnection openConnection(URL u) throws IOException { protected URLConnection openConnection(URL u) {
return new ImageConnection(u); return new ImageConnection(u);
} }
}; };
@ -307,7 +329,7 @@ public class ElementHelpDialog extends JDialog {
} }
@Override @Override
public void connect() throws IOException { public void connect() {
} }
@Override @Override
@ -335,7 +357,7 @@ public class ElementHelpDialog extends JDialog {
* @throws PinException PinException * @throws PinException PinException
* @throws NodeException NodeException * @throws NodeException NodeException
*/ */
private static void exportHTMLDocumentation(File targetPath, ElementLibrary library) throws IOException, NodeException, PinException { private void exportHTMLDocumentation(File targetPath, ElementLibrary library) throws IOException, NodeException, PinException {
File images = new File(targetPath, "img"); File images = new File(targetPath, "img");
if (!images.mkdir()) if (!images.mkdir())
throw new IOException("could not create image folder " + images); throw new IOException("could not create image folder " + images);
@ -343,7 +365,7 @@ public class ElementHelpDialog extends JDialog {
new BufferedWriter( new BufferedWriter(
new OutputStreamWriter( new OutputStreamWriter(
new FileOutputStream( new FileOutputStream(
new File(targetPath, "index.html")), "UTF-8"))) { new File(targetPath, "index.html")), StandardCharsets.UTF_8))) {
w.write("<!DOCTYPE html>\n" w.write("<!DOCTYPE html>\n"
+ "<html>\n" + "<html>\n"
+ "<head>\n" + "<head>\n"

View File

@ -43,8 +43,8 @@ public class TestExamples extends TestCase {
*/ */
public void testTestExamples() throws Exception { public void testTestExamples() throws Exception {
File examples = new File(Resources.getRoot(), "/dig/test"); File examples = new File(Resources.getRoot(), "/dig/test");
assertEquals(164, new FileScanner(this::check).scan(examples)); assertEquals(166, new FileScanner(this::check).scan(examples));
assertEquals(161, testCasesInFiles); assertEquals(162, testCasesInFiles);
} }
/** /**

View File

@ -0,0 +1,216 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes>
<entry>
<string>isGeneric</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>
<elementName>Counter</elementName>
<elementAttributes>
<entry>
<string>Bits</string>
<int>2</int>
</entry>
<entry>
<string>generic</string>
<string>this.Bits=int(args.bits);</string>
</entry>
</elementAttributes>
<pos x="440" y="120"/>
</visualElement>
<visualElement>
<elementName>Counter</elementName>
<elementAttributes>
<entry>
<string>Bits</string>
<int>2</int>
</entry>
<entry>
<string>generic</string>
<string>this.Bits=int(args.bits);</string>
</entry>
</elementAttributes>
<pos x="440" y="220"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="420" y="180"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="420" y="280"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>en</string>
</entry>
</elementAttributes>
<pos x="380" y="100"/>
</visualElement>
<visualElement>
<elementName>Splitter</elementName>
<elementAttributes>
<entry>
<string>Input Splitting</string>
<string>2,2</string>
</entry>
<entry>
<string>Output Splitting</string>
<string>4</string>
</entry>
<entry>
<string>generic</string>
<string>this.&apos;Output Splitting&apos;=&quot;&quot;+(args.bits*2);
this.&apos;Input Splitting&apos;=args.bits+&quot;,&quot;+args.bits;</string>
</entry>
</elementAttributes>
<pos x="560" y="120"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>d</string>
</entry>
<entry>
<string>Bits</string>
<int>4</int>
</entry>
<entry>
<string>generic</string>
<string>this.Bits=int(args.bits);</string>
</entry>
</elementAttributes>
<pos x="620" y="120"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>ov</string>
</entry>
</elementAttributes>
<pos x="620" y="240"/>
</visualElement>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes>
<entry>
<string>runRealTime</string>
<boolean>true</boolean>
</entry>
<entry>
<string>Label</string>
<string>C</string>
</entry>
<entry>
<string>Frequency</string>
<int>2</int>
</entry>
</elementAttributes>
<pos x="380" y="140"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="420" y="160"/>
<p2 x="440" y="160"/>
</wire>
<wire>
<p1 x="400" y="240"/>
<p2 x="440" y="240"/>
</wire>
<wire>
<p1 x="500" y="240"/>
<p2 x="620" y="240"/>
</wire>
<wire>
<p1 x="420" y="260"/>
<p2 x="440" y="260"/>
</wire>
<wire>
<p1 x="380" y="100"/>
<p2 x="420" y="100"/>
</wire>
<wire>
<p1 x="420" y="200"/>
<p2 x="520" y="200"/>
</wire>
<wire>
<p1 x="500" y="120"/>
<p2 x="560" y="120"/>
</wire>
<wire>
<p1 x="580" y="120"/>
<p2 x="620" y="120"/>
</wire>
<wire>
<p1 x="420" y="120"/>
<p2 x="440" y="120"/>
</wire>
<wire>
<p1 x="380" y="140"/>
<p2 x="400" y="140"/>
</wire>
<wire>
<p1 x="500" y="140"/>
<p2 x="520" y="140"/>
</wire>
<wire>
<p1 x="540" y="140"/>
<p2 x="560" y="140"/>
</wire>
<wire>
<p1 x="400" y="140"/>
<p2 x="440" y="140"/>
</wire>
<wire>
<p1 x="420" y="220"/>
<p2 x="440" y="220"/>
</wire>
<wire>
<p1 x="500" y="220"/>
<p2 x="540" y="220"/>
</wire>
<wire>
<p1 x="400" y="140"/>
<p2 x="400" y="240"/>
</wire>
<wire>
<p1 x="420" y="160"/>
<p2 x="420" y="180"/>
</wire>
<wire>
<p1 x="420" y="260"/>
<p2 x="420" y="280"/>
</wire>
<wire>
<p1 x="420" y="200"/>
<p2 x="420" y="220"/>
</wire>
<wire>
<p1 x="420" y="100"/>
<p2 x="420" y="120"/>
</wire>
<wire>
<p1 x="520" y="140"/>
<p2 x="520" y="200"/>
</wire>
<wire>
<p1 x="540" y="140"/>
<p2 x="540" y="220"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>Clock</elementName>
<elementAttributes>
<entry>
<string>runRealTime</string>
<boolean>true</boolean>
</entry>
<entry>
<string>Label</string>
<string>C</string>
</entry>
<entry>
<string>Frequency</string>
<int>5</int>
</entry>
</elementAttributes>
<pos x="300" y="280"/>
</visualElement>
<visualElement>
<elementName>VDD</elementName>
<elementAttributes/>
<pos x="360" y="140"/>
</visualElement>
<visualElement>
<elementName>Splitter</elementName>
<elementAttributes>
<entry>
<string>Input Splitting</string>
<string>4,6</string>
</entry>
<entry>
<string>Output Splitting</string>
<string>10</string>
</entry>
</elementAttributes>
<pos x="520" y="240"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>O</string>
</entry>
<entry>
<string>Bits</string>
<int>10</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>hex</intFormat>
</entry>
</elementAttributes>
<pos x="580" y="240"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Testdata</string>
<testData>
<dataString>C O
loop(n,1024)
C (n+1)
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="520" y="140"/>
</visualElement>
<visualElement>
<elementName>countSplitter.dig</elementName>
<elementAttributes>
<entry>
<string>generic</string>
<string>bits:=2;</string>
</entry>
</elementAttributes>
<pos x="380" y="160"/>
</visualElement>
<visualElement>
<elementName>countSplitter.dig</elementName>
<elementAttributes>
<entry>
<string>generic</string>
<string>bits:=3;</string>
</entry>
</elementAttributes>
<pos x="380" y="260"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="480" y="240"/>
<p2 x="520" y="240"/>
</wire>
<wire>
<p1 x="540" y="240"/>
<p2 x="580" y="240"/>
</wire>
<wire>
<p1 x="360" y="240"/>
<p2 x="460" y="240"/>
</wire>
<wire>
<p1 x="440" y="160"/>
<p2 x="480" y="160"/>
</wire>
<wire>
<p1 x="360" y="160"/>
<p2 x="380" y="160"/>
</wire>
<wire>
<p1 x="440" y="260"/>
<p2 x="520" y="260"/>
</wire>
<wire>
<p1 x="360" y="260"/>
<p2 x="380" y="260"/>
</wire>
<wire>
<p1 x="320" y="180"/>
<p2 x="380" y="180"/>
</wire>
<wire>
<p1 x="440" y="180"/>
<p2 x="460" y="180"/>
</wire>
<wire>
<p1 x="300" y="280"/>
<p2 x="320" y="280"/>
</wire>
<wire>
<p1 x="320" y="280"/>
<p2 x="380" y="280"/>
</wire>
<wire>
<p1 x="480" y="160"/>
<p2 x="480" y="240"/>
</wire>
<wire>
<p1 x="320" y="180"/>
<p2 x="320" y="280"/>
</wire>
<wire>
<p1 x="360" y="140"/>
<p2 x="360" y="160"/>
</wire>
<wire>
<p1 x="360" y="240"/>
<p2 x="360" y="260"/>
</wire>
<wire>
<p1 x="460" y="180"/>
<p2 x="460" y="240"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>