mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 06:49:36 -04:00
added a splitter test case
This commit is contained in:
parent
46e78bf877
commit
0cb457bcd7
@ -1046,7 +1046,11 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
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) {
|
||||
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
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_HEIGHT = 800;
|
||||
private final boolean showKeys;
|
||||
|
||||
private JPanel buttons;
|
||||
|
||||
@ -50,7 +52,22 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
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);
|
||||
this.showKeys = showKeys;
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
StringWriter w = new StringWriter();
|
||||
try {
|
||||
@ -72,6 +89,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
*/
|
||||
public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) throws NodeException, PinException {
|
||||
super(parent, Lang.get("attr_help"), true);
|
||||
showKeys = false;
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
MyURLStreamHandlerFactory.setShapeFactory(shapeFactory);
|
||||
StringWriter w = new StringWriter();
|
||||
@ -143,7 +161,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @throws PinException PinException
|
||||
* @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<>();
|
||||
|
||||
String actPath = null;
|
||||
@ -187,7 +205,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @param et 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>");
|
||||
writeHTMLDescription(w, et, elementAttributes);
|
||||
w.write("</body></html>");
|
||||
@ -203,7 +221,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @throws PinException PinException
|
||||
* @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();
|
||||
if (translatedName.endsWith(".dig"))
|
||||
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");
|
||||
if (description != null && description.length() > 0 && !name.equals(description))
|
||||
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 description = key.getDescription();
|
||||
w.append("<dt><i>").append(escapeHTML(name)).append("</i></dt>\n");
|
||||
if (description != null && description.length() > 0 && !name.equals(description))
|
||||
w.append("<dd>").append(escapeHTML(description)).append(" (").append(key.getKey()).append(")</dd>\n");
|
||||
if (description != null && description.length() > 0 && !name.equals(description)) {
|
||||
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"))
|
||||
return new URLStreamHandler() {
|
||||
@Override
|
||||
protected URLConnection openConnection(URL u) throws IOException {
|
||||
protected URLConnection openConnection(URL u) {
|
||||
return new ImageConnection(u);
|
||||
}
|
||||
};
|
||||
@ -307,7 +329,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
public void connect() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -335,7 +357,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @throws PinException PinException
|
||||
* @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");
|
||||
if (!images.mkdir())
|
||||
throw new IOException("could not create image folder " + images);
|
||||
@ -343,7 +365,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
new BufferedWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(
|
||||
new File(targetPath, "index.html")), "UTF-8"))) {
|
||||
new File(targetPath, "index.html")), StandardCharsets.UTF_8))) {
|
||||
w.write("<!DOCTYPE html>\n"
|
||||
+ "<html>\n"
|
||||
+ "<head>\n"
|
||||
|
@ -43,8 +43,8 @@ public class TestExamples extends TestCase {
|
||||
*/
|
||||
public void testTestExamples() throws Exception {
|
||||
File examples = new File(Resources.getRoot(), "/dig/test");
|
||||
assertEquals(164, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(161, testCasesInFiles);
|
||||
assertEquals(166, new FileScanner(this::check).scan(examples));
|
||||
assertEquals(162, testCasesInFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
216
src/test/resources/dig/test/generics/countSplitter.dig
Normal file
216
src/test/resources/dig/test/generics/countSplitter.dig
Normal 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.'Output Splitting'=""+(args.bits*2);
|
||||
this.'Input Splitting'=args.bits+","+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>
|
164
src/test/resources/dig/test/generics/mainSplitter.dig
Normal file
164
src/test/resources/dig/test/generics/mainSplitter.dig
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user