Fix blocks, add tests, fix bounding box calc of some components

This commit is contained in:
Bane Stojkovic
2022-03-18 09:23:03 +01:00
parent d513cb2667
commit bf89b07cea
81 changed files with 41887 additions and 6426 deletions
@@ -9,6 +9,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.RegressionTestRunner"/>
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="diylc-swing"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="&quot;C:\Users\bancika\Documents\GitHub\diy-layout-creator\diylc-regression-data&quot; TEST user-files"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="&quot;C:\Users\bancika\Documents\GitHub\diy-layout-creator\diylc-regression-data&quot; TEST travelcaster3"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="diylc-swing"/>
</launchConfiguration>
+1 -1
View File
@@ -10,7 +10,7 @@
<property name="jar.dir" value="${build.dir}/jar" />
<property name="report.dir" value="${build.dir}/junitreport" />
<property name="main.class" value="org.diylc.DIYLCStarter" />
<property name="diylc.version" value="4.22.1" />
<property name="diylc.version" value="4.22.2" />
<property name="osx.jre8.path" value="jre\osx\jre8u321\Contents\Home\" />
-2
View File
@@ -26,8 +26,6 @@ A-O-I REGULATOR
AWG
And
C-B-E BJT
C1
C2
Check Trace Proximity
D-G-S JFET
D-G-S MOSFET
@@ -37,6 +37,15 @@
<update_contact>nbenitezl_AT_gmail.com</update_contact>
<content_rating type="oars-1.1"/>
<releases>
<release version="4.22.2" date="2022-03-18">
<description>
<ul>
<li>[Bug Fix] Fixed the issue with application hanging when loading certain files</li>
<li>[Bug Fix] Fixed importing building blocks and variants from a file</li>
</ul>
</description>
<url>https://github.com/bancika/diy-layout-creator/releases/tag/v4.22.2</url>
</release>
<release version="4.22.1" date="2022-03-07">
<description>
<ul>
Binary file not shown.
Binary file not shown.
@@ -97,9 +97,6 @@ import org.diylc.swingframework.TextDialog;
import org.diylc.swingframework.export.DrawingExporter;
import org.diylc.utils.BomEntry;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class ActionFactory {
private static final Logger LOG = Logger.getLogger(ActionFactory.class);
@@ -967,10 +964,8 @@ public class ActionFactory {
LOG.debug("Exporting variants to " + file.getAbsolutePath());
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
XStream xStream = new XStream(new DomDriver());
ProjectFileManager.configure(xStream);
xStream.toXML(variantPkg, out);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
ProjectFileManager.xStreamSerializer.toXML(variantPkg, out);
out.close();
LOG.info("Exported variants succesfully");
} catch (IOException e) {
@@ -1124,10 +1119,8 @@ public class ActionFactory {
LOG.debug("Exporting variants to " + file.getAbsolutePath());
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
XStream xStream = new XStream(new DomDriver());
ProjectFileManager.configure(xStream);
xStream.toXML(variantPkg, out);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
ProjectFileManager.xStreamSerializer.toXML(variantPkg, out);
out.close();
LOG.info("Exported building blocks succesfully");
} catch (IOException e) {
@@ -122,7 +122,7 @@ public class MainFrame extends JFrame implements ISwingUI {
IConfigurationManager configManager = ConfigurationManager.getInstance();
this.presenter = new Presenter(this, configManager);
this.presenter = new Presenter(this, configManager, true);
presenter.installPlugin(() -> new ToolBox(this));
presenter.installPlugin(() -> new FileMenuPlugin(this));
@@ -21,33 +21,29 @@
*/
package org.diylc.swing.plugins.file;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.util.EnumSet;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
import java.util.EnumSet;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.common.DrawOption;
import org.diylc.common.IPlugInPort;
import org.diylc.core.Project;
import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.DummyView;
import org.diylc.common.DrawOption;
import org.diylc.common.IPlugInPort;
import org.diylc.core.Project;
import org.diylc.presenter.Presenter;
import org.diylc.serialization.ProjectFileManager;
import org.diylc.swing.gui.DummyView;
import org.diylc.swingframework.IFileChooserAccessory;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* {@link JComponent} that shows preview of the selected project in {@link JFileChooser}. It's
* hooked onto {@link JFileChooser} as {@link PropertyChangeListener} and refreshes when file is
@@ -60,7 +56,6 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
private static final long serialVersionUID = 1L;
private IPlugInPort presenter;
private XStream xStream;
private Project emptyProject;
private RenderComponent renderComponent;
private JLabel nameLabel;
@@ -70,7 +65,6 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
setPreferredSize(new Dimension(140, 128));
presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
xStream = new XStream(new DomDriver());
emptyProject = new Project();
emptyProject.setTitle("");
@@ -97,7 +91,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
File selectedFile = (File) evt.getNewValue();
try {
FileInputStream in = new FileInputStream(selectedFile);
selectedProject = (Project) xStream.fromXML(in);
selectedProject = (Project) ProjectFileManager.xStreamSerializer.fromXML(in);
in.close();
} catch (Exception e) {
}
+11 -2
View File
@@ -1,18 +1,27 @@
package org.diylc;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IView;
public class MockView implements IView {
private Map<Integer, List<String>> messages = new HashMap<Integer, List<String>>();
@Override
public void showMessage(String message, String title, int messageType) {
// TODO Auto-generated method stub
messages.putIfAbsent(messageType, new ArrayList<String>());
messages.get(messageType).add(message);
}
public Map<Integer, List<String>> getMessages() {
return messages;
}
@Override
@@ -1,9 +1,11 @@
package org.diylc;
import java.awt.Point;
import java.io.IOException;
import java.util.List;
import org.diylc.common.ComponentType;
import org.diylc.core.Template;
import org.junit.Test;
import junit.framework.Assert;
public class PresenterTests extends TestBase {
@@ -24,4 +26,28 @@ public class PresenterTests extends TestBase {
instantiateOneClick("Connectivity", "Solder Pad", new Point(1000, 1000));
Assert.assertEquals(1, presenter.getCurrentProject().getComponents().size());
}
@Test
public void testLoadVariants() {
try {
ComponentType resistorType = presenter.getComponentTypes().get("Passive").stream().filter(x -> x.getName().equals("Resistor")).findAny().get();
List<Template> variantsFor = presenter.getVariantsFor(resistorType);
Assert.assertEquals(0, variantsFor.size());
presenter.importVariants("./test/resources/variants_test.xml");
variantsFor = presenter.getVariantsFor(resistorType);
Assert.assertTrue(!variantsFor.isEmpty());
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testLoadBlocks() {
try {
int blocks = presenter.importBlocks("./test/resources/blocks_test.xml");
Assert.assertTrue(blocks > 0);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
}
@@ -3,9 +3,16 @@ package org.diylc;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -16,7 +23,12 @@ import java.util.stream.Stream;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.appframework.update.VersionNumber;
import org.diylc.common.INetlistAnalyzer;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IView;
import org.diylc.netlist.Netlist;
import org.diylc.netlist.Summary;
import org.diylc.netlist.TreeException;
import org.diylc.presenter.Presenter;
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
import org.diylc.swingframework.export.DrawingExporter;
@@ -32,6 +44,15 @@ public class RegressionTestRunner {
System.out.println("No path and command provided");
return;
}
//
// URL url = DIYLCStarter.class.getResource("log4j.properties");
// Properties properties = new Properties();
// try {
// properties.load(url.openStream());
// PropertyConfigurator.configure(properties);
// } catch (Exception e) {
// System.err.println("Could not initialize log4j configuration: " + e.getMessage());
// }
ConfigurationManager.getInstance().initialize("diylc-test");
@@ -66,17 +87,17 @@ public class RegressionTestRunner {
Presenter presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
VersionNumber currentVersionNumber = presenter.getCurrentVersionNumber();
String fileName = basePath + File.separator + "reports" + File.separator
+ LocalDateTime.now().toString().replace(":", "_") + "-"
+ "V" + currentVersionNumber.toString().replace('.', '_') + ".csv";
String fileName = basePath + File.separator + "reports" + File.separator
+ LocalDateTime.now().toString().replace(":", "_") + "-" + "V"
+ currentVersionNumber.toString().replace('.', '_') + ".csv";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
long okCount = results.stream().filter(x -> x.ok).count();
long failCount = results.size() - okCount;
long totalTime = results.stream().map(x -> x.duration).reduce(0l, (a, b) -> a + b);
long avgTime = totalTime / results.size();
writer.write("OK,Failed,Total Time,Avg Time");
writer.newLine();
writer.write(Long.toString(okCount));
@@ -85,11 +106,11 @@ public class RegressionTestRunner {
writer.write(",");
writer.write(Long.toString(totalTime));
writer.write(",");
writer.write(Long.toString(avgTime));
writer.write(Long.toString(avgTime));
writer.newLine();
writer.newLine();
writer.newLine();
writer.write("File,Status,Message,Time");
writer.newLine();
results.stream().sorted(Comparator.comparing(x -> x.fileName)).forEach(item -> {
@@ -108,9 +129,9 @@ public class RegressionTestRunner {
});
writer.close();
System.out.println("OK files: " + okCount + "; Failed files: " + failCount
+ "; totalTime: " + (totalTime / 1000) + "s" + "; avgTime: " + avgTime + "ms");
System.out.println("OK files: " + okCount + "; Failed files: " + failCount + "; totalTime: "
+ (totalTime / 1000) + "s" + "; avgTime: " + avgTime + "ms");
System.out.println("Saved test report to: " + fileName);
}
@@ -134,8 +155,8 @@ public class RegressionTestRunner {
}
}
RegressionTestResult testResult = processFile(file, command);
System.out
.println(testResult.fileName + ": " + (testResult.ok ? "OK" : testResult.message));
System.out.println(
testResult.fileName + ": " + (testResult.message == null ? "OK" : testResult.message));
return Stream.of(testResult);
}
});
@@ -144,16 +165,16 @@ public class RegressionTestRunner {
private static RegressionTestResult processFile(File file, String command) {
String prefix = "File: " + file.getName() + " status: ";
try {
IView view = new MockView();
MockView view = new MockView();
Presenter presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
ProjectDrawingProvider drawingProvider =
new ProjectDrawingProvider(presenter, false, true, false);
presenter.loadProjectFromFile(file.getAbsolutePath());
if ("PREPARE".equalsIgnoreCase(command)) {
// generate PNG input image for comparison
return prepareInputs(file, drawingProvider);
return prepareInputs(file, drawingProvider, presenter);
} else if ("TEST".equalsIgnoreCase(command)) {
return testOutputs(file, prefix, presenter, drawingProvider);
return testOutputs(file, prefix, presenter, drawingProvider, view);
}
return new RegressionTestResult(file.getName()).failed("Command not recognized");
} catch (Exception e) {
@@ -163,7 +184,7 @@ public class RegressionTestRunner {
}
private static RegressionTestResult testOutputs(File file, String prefix, Presenter presenter,
ProjectDrawingProvider drawingProvider) {
ProjectDrawingProvider drawingProvider, MockView view) {
RegressionTestResult res = new RegressionTestResult(file.getName());
File baseDir = file.getParentFile().getParentFile().getParentFile().getParentFile();
File outputDir = new File(baseDir.getAbsolutePath() + File.separator + "output" + File.separator
@@ -210,11 +231,74 @@ public class RegressionTestRunner {
if (ImageComparisonState.MATCH != imageComparisonResult.getImageComparisonState()) {
return res.failed("Images do not match!");
}
return res.succedded();
List<INetlistAnalyzer> summarizers = presenter.getNetlistAnalyzers();
if (summarizers != null) {
List<Netlist> netlists = presenter.extractNetlists(true);
for (INetlistAnalyzer summarizer : summarizers) {
File summaryOutputDir =
new File(outputDir.getAbsolutePath() + File.separator + summarizer.getShortName());
File summaryOutputFile = new File(summaryOutputDir.getAbsolutePath() + File.separator
+ file.getName().replace(".diy", ".txt"));
summaryOutputDir.mkdirs();
if (summaryOutputFile.exists()) {
summaryOutputFile.delete();
}
File summaryInputDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
+ File.separator + summarizer.getShortName());
File summaryInputFile = new File(summaryInputDir.getAbsolutePath() + File.separator
+ file.getName().replace(".diy", ".txt"));
if (!summaryInputFile.exists()) {
return res.failed("Summary input file not found for: " + summarizer.getShortName());
}
try {
List<String> outputLines = new ArrayList<String>();
try {
writeSummariesToFile(netlists, summarizer, summaryOutputFile);
outputLines = Files.readAllLines(Paths.get(summaryOutputFile.getAbsolutePath()));
} catch (Exception e) {
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(summaryOutputFile, true), "UTF-8"))) {
String line = e.getClass().getCanonicalName() + ": " + e.getMessage();
writer.write(line);
outputLines.add(line);
}
}
List<String> inputLines =
Files.readAllLines(Paths.get(summaryInputFile.getAbsolutePath()));
if (inputLines.size() != outputLines.size()) {
return res.failed(
"Summary input and output files do not match for: " + summarizer.getShortName());
}
for (int i = 0; i < inputLines.size(); i++) {
if (!inputLines.get(i).equals(outputLines.get(i))) {
return res.failed(
"Summary input and output files do not match for: " + summarizer.getShortName());
}
}
} catch (Exception e) {
return res.failed(e.getMessage());
}
}
}
String message = null;
if (!view.getMessages().isEmpty()) {
message = view.getMessages().entrySet().stream().flatMap(x -> x.getValue().stream())
.reduce("", String::concat);
}
return res.succedded(message);
}
private static RegressionTestResult prepareInputs(File file,
ProjectDrawingProvider drawingProvider) {
ProjectDrawingProvider drawingProvider, IPlugInPort plugInPort) {
RegressionTestResult res = new RegressionTestResult(file.getName());
try {
File pngDir =
@@ -222,8 +306,32 @@ public class RegressionTestRunner {
File pngFile = new File(
pngDir.getAbsolutePath() + File.separator + file.getName().replace(".diy", ".png"));
pngFile.getParentFile().mkdirs();
if (!pngFile.exists()) {
DrawingExporter.getInstance().exportPNG(drawingProvider, pngFile);
// always export image to ensure that rendering is done and continuity areas are populated
DrawingExporter.getInstance().exportPNG(drawingProvider, pngFile);
List<INetlistAnalyzer> summarizers = plugInPort.getNetlistAnalyzers();
if (summarizers != null) {
List<Netlist> netlists = plugInPort.extractNetlists(true);
for (INetlistAnalyzer summarizer : summarizers) {
File summaryDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
+ File.separator + summarizer.getShortName());
File summaryFile = new File(summaryDir.getAbsolutePath() + File.separator
+ file.getName().replace(".diy", ".txt"));
summaryDir.mkdirs();
if (!summaryFile.exists()) {
try {
writeSummariesToFile(netlists, summarizer, summaryFile);
} catch (Exception e) {
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
}
}
}
}
}
} catch (Exception e) {
return res.failed(e.getMessage());
@@ -231,6 +339,23 @@ public class RegressionTestRunner {
return res.succedded();
}
private static void writeSummariesToFile(List<Netlist> netlists, INetlistAnalyzer summarizer,
File summaryFile)
throws TreeException, IOException, UnsupportedEncodingException, FileNotFoundException {
List<Summary> summaries = summarizer.summarize(netlists, null);
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
for (Summary summary : summaries) {
writer.write("<b>Switch configuration: ");
writer.write(summary.getNetlist().getSwitchSetup().toString());
writer.write("</b><br><br>");
writer.write(summary.getSummary());
writer.newLine();
}
}
}
static class RegressionTestResult {
boolean ok;
String message;
@@ -244,13 +369,18 @@ public class RegressionTestRunner {
}
public RegressionTestResult succedded() {
return succedded(null);
}
public RegressionTestResult succedded(String message) {
this.ok = true;
this.message = message;
this.duration = System.currentTimeMillis() - this.startTime;
return this;
}
public RegressionTestResult failed(String message) {
this.ok = true;
this.ok = false;
this.message = message;
this.duration = System.currentTimeMillis() - this.startTime;
return this;
+12 -1
View File
@@ -2,9 +2,11 @@ package org.diylc;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.common.ComponentType;
@@ -17,6 +19,15 @@ public class TestBase {
protected IView view;
public TestBase() {
URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
} catch (Exception e) {
System.err.println("Could not initialize log4j configuration: " + e.getMessage());
}
ConfigurationManager.getInstance().initialize("diylc-test");
view = new MockView();
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff