Commit 5fa769b4 authored by Manuel Schrick's avatar Manuel Schrick
Browse files

implemented test to check whether everything was drawn

parent dbecae73
......@@ -123,7 +123,7 @@ public class SVGMain {
}
// Calculate Layout information for the given input
calculator.calculateLayout(inst, MainCalculator.Mode.ROUTES);
calculator.calculateLayout(inst);
// Draw the layout (create output SVG file)
svgGenerator.drawLayouts(inst);
......@@ -142,12 +142,10 @@ public class SVGMain {
try {
// Calculate Layout information for the given input
calculator.calculateLayout(symbol, MainCalculator.Mode.ROUTES);
calculator.calculateLayout(symbol);
// Draw the layout (create output SVG file)
svgGenerator.drawLayouts(symbol);
} catch (NoHorizontalLayoutInformationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -7,19 +7,8 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
*/
public class MainCalculator {
public void calculateLayout(ExpandedComponentInstanceSymbol inst, Mode mode) throws NoHorizontalLayoutInformationException {
switch (mode) {
case ROUTES:
calculateLayoutRoutes(inst);
break;
}
}
private void calculateLayoutRoutes(ExpandedComponentInstanceSymbol inst) {
public void calculateLayout(ExpandedComponentInstanceSymbol inst) {
new RoutesLayoutCalculator().calculateLayout(inst);
}
public enum Mode {
NORMAL, ROUTES
}
}
package de.monticore.lang.montiarc.svggenerator;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.MainCalculator;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.CanvasLayoutSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.ComponentLayoutSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.ConnectorLayoutSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.PortLayoutSymbol;
import de.monticore.symboltable.Scope;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
* @author Manuel Schrick
*/
public class BaseLayoutTest {
private ExpandedComponentInstanceSymbol instance;
private MainCalculator calculator = new MainCalculator();
private SVGGenerator svgGenerator = new SVGGenerator();
@Before
public void init() {
Scope symTab = TestingUtilities.createSymTab("src/test/resources/");
instance = symTab.<ExpandedComponentInstanceSymbol>resolve("testManuelSchrick.bumperBotEmergency", ExpandedComponentInstanceSymbol.KIND).orElse(null);
}
@Test
public void testBaseLayoutFeatures() {
assertNotNull(instance);
TestingUtilities.drawComponentsAndSubComponents(instance, 5, calculator, svgGenerator);
checkIfEverythingWasDrawn();
checkComponentBounds();
checkConnectorBounds();
}
private void checkIfEverythingWasDrawn() {
List<ExpandedComponentInstanceSymbol> instancesToCheck = new ArrayList<>();
instancesToCheck.add(instance);
while (!instancesToCheck.isEmpty()) {
ExpandedComponentInstanceSymbol inst = instancesToCheck.remove(0);
// Check if component was is drawn
assertFalse(inst.getTags(ComponentLayoutSymbol.KIND).isEmpty());
// Check if all ports were drawn
inst.getPorts().forEach(port -> {
assertFalse(port.getTags(PortLayoutSymbol.KIND).isEmpty());
});
// Check if all connectors were drawn
inst.getConnectors().forEach(connector -> {
assertFalse(connector.getTags(ConnectorLayoutSymbol.KIND).isEmpty());
});
Collection<ExpandedComponentInstanceSymbol> subComponents = inst.getSubComponents();
if (!subComponents.isEmpty()) {
instancesToCheck.addAll(inst.getSubComponents());
// If the component has subcomponents, there has to be a CanvasLayoutSymbolPresent
assertFalse(inst.getTags(CanvasLayoutSymbol.KIND).isEmpty());
}
}
}
private void checkComponentBounds() {
}
private void checkConnectorBounds() {
}
}
package de.monticore.lang.montiarc.svggenerator;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.MainCalculator;
import de.monticore.lang.montiarc.svggenerator.calculators.NoHorizontalLayoutInformationException;
import de.monticore.symboltable.Scope;
......@@ -10,6 +11,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Collection;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
/**
......@@ -48,7 +50,7 @@ public class DemonstratorTest {
assertNotNull(instance);
// Calculate Layout information for the given input
cal.calculateLayout(instance, MainCalculator.Mode.ROUTES);
cal.calculateLayout(instance);
// Draw the layout (create output SVG file)
svgGenerator.drawLayouts(instance);
......@@ -77,12 +79,10 @@ public class DemonstratorTest {
assertNotNull(symbol);
// Calculate Layout information for the given input
cal.calculateLayout(symbol, MainCalculator.Mode.ROUTES);
cal.calculateLayout(symbol);
// Draw the layout (create output SVG file)
svgGenerator.drawLayouts(symbol);
} catch (NoHorizontalLayoutInformationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -4,7 +4,9 @@ import de.monticore.ModelingLanguageFamily;
import de.monticore.io.paths.ModelPath;
import de.monticore.java.lang.JavaDSLLanguage;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcLanguage;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.stream._symboltable.StreamLanguage;
import de.monticore.lang.montiarc.svggenerator.calculators.MainCalculator;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.*;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
......@@ -14,6 +16,7 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Random;
/**
......@@ -45,7 +48,7 @@ public class TestingUtilities {
}
public static int getCountOf(String outerString, String subString) {
return (outerString.length() - outerString.replace(subString, "").length())/subString.length();
return (outerString.length() - outerString.replace(subString, "").length()) / subString.length();
}
public static Scope createSymTabAlternative(String... modelPath) {
......@@ -91,13 +94,12 @@ public class TestingUtilities {
}
public static String readFile(String path, Charset encoding)
throws IOException
{
throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
}
public static String readFile(String path){
public static String readFile(String path) {
try {
return readFile(path, Charset.forName("UTF-8"));
} catch (IOException e) {
......@@ -105,4 +107,25 @@ public class TestingUtilities {
}
return "";
}
public static void drawComponentsAndSubComponents(ExpandedComponentInstanceSymbol instance, int maxDepth, MainCalculator cal, SVGGenerator svgGenerator) {
if (maxDepth <= 0 || instance.getSubComponents().isEmpty()) {
return;
}
try {
// Calculate Layout information for the given input
cal.calculateLayout(instance);
// Draw the layout (create output SVG file)
svgGenerator.drawLayouts(instance);
} catch (IOException e) {
e.printStackTrace();
}
Collection<ExpandedComponentInstanceSymbol> subComponents = instance.getSubComponents();
for (ExpandedComponentInstanceSymbol symbol : subComponents) {
drawComponentsAndSubComponents(symbol, maxDepth - 1, cal, svgGenerator);
}
}
}
......@@ -39,8 +39,7 @@ public abstract class AbstractUserNoMethodsTest {
assertNotNull(inst1);
// Calculate Layout information for the given input
cal.calculateLayout(inst1, MainCalculator.Mode.NORMAL);
cal.calculateLayout(inst1);
return inst1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment