Commit 599d306a authored by Manuel Schrick's avatar Manuel Schrick
Browse files

implemented bus tests

parent 5fa769b4
......@@ -7,8 +7,10 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
*/
public class MainCalculator {
public RoutesLayoutCalculator routesLayoutCalculator = new RoutesLayoutCalculator();
public void calculateLayout(ExpandedComponentInstanceSymbol inst) {
new RoutesLayoutCalculator().calculateLayout(inst);
routesLayoutCalculator.calculateLayout(inst);
}
}
......@@ -23,7 +23,7 @@ public class RoutesLayoutCalculator implements DrawingConstants {
private final static String NAME_ROOT_IN = "root_in";
private final static String NAME_ROOT_OUT = "root_out";
private RoutesLayoutState layoutState;
public RoutesLayoutState layoutState;
public void calculateLayout(ExpandedComponentInstanceSymbol inst) {
layoutState = new RoutesLayoutState();
......
package de.monticore.lang.montiarc.svggenerator.routesTests;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.svggenerator.SVGGenerator;
import de.monticore.lang.montiarc.svggenerator.TestingUtilities;
import de.monticore.lang.montiarc.svggenerator.calculators.MainCalculator;
import de.monticore.lang.montiarc.svggenerator.calculators.RoutesLayoutState;
import de.monticore.lang.montiarc.svggenerator.calculators.routes.Node;
import de.monticore.symboltable.Scope;
import org.junit.Test;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Created by Peters Notebook on 10.11.2017.
*/
public class BusHandlerTest {
private MainCalculator calculator = new MainCalculator();
private SVGGenerator svgGenerator = new SVGGenerator();
@Test
public void testNormalBus() {
Scope symTab = TestingUtilities.createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol instance = symTab.<ExpandedComponentInstanceSymbol>resolve("testManuelSchrick.bus.normalBus", ExpandedComponentInstanceSymbol.KIND).orElse(null);
TestingUtilities.drawComponentsAndSubComponents(instance, 5, calculator, svgGenerator);
RoutesLayoutState layoutState = calculator.routesLayoutCalculator.layoutState;
// Check if a bus has been created
assertEquals(layoutState.busses.size(), 1);
// Check if all routes have been inserted
assertEquals(layoutState.routes.size(), 6);
// Check if there are exactly two temporary bus nodes
List<Node> temporaryNodes = layoutState.nodeOrder.stream().filter(node -> node.isTemporary).collect(Collectors.toList());
assertEquals(temporaryNodes.size(), 2);
}
@Test
public void testDecomposedBus() {
Scope symTab = TestingUtilities.createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol instance = symTab.<ExpandedComponentInstanceSymbol>resolve("testManuelSchrick.bus.decomposedBus", ExpandedComponentInstanceSymbol.KIND).orElse(null);
TestingUtilities.drawComponentsAndSubComponents(instance, 5, calculator, svgGenerator);
RoutesLayoutState layoutState = calculator.routesLayoutCalculator.layoutState;
// Check if all routes have been inserted
assertEquals(layoutState.routes.size(), 5);
// Check that there are no temporary bus nodes
layoutState.nodeOrder.forEach(node -> {
assertFalse(node.isTemporary);
});
}
@Test
public void testBackConnectorBus() {
Scope symTab = TestingUtilities.createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol instance = symTab.<ExpandedComponentInstanceSymbol>resolve("testManuelSchrick.bus.backConnectorBus", ExpandedComponentInstanceSymbol.KIND).orElse(null);
TestingUtilities.drawComponentsAndSubComponents(instance, 5, calculator, svgGenerator);
RoutesLayoutState layoutState = calculator.routesLayoutCalculator.layoutState;
// Check if all routes have been inserted
layoutState.busses.values().forEach(bus -> {
assertEquals(bus.portConnections.size(), 5);
});
// Check if there are exactly two temporary bus nodes
List<Node> temporaryNodes = layoutState.nodeOrder.stream().filter(node -> node.isTemporary).collect(Collectors.toList());
assertEquals(temporaryNodes.size(), 2);
}
}
package testManuelSchrick.bus;
component BackConnectorBus {
ports
in Integer in0,
out Integer out0;
component EmptyA {
ports
in Integer in1,
in Integer in2,
in Integer in3,
in Integer in4,
in Integer in5,
out Integer out1,
out Integer out2,
out Integer out3,
out Integer out4,
out Integer out5;
}
component EmptyB {
ports
in Integer in1,
in Integer in2,
in Integer in3,
in Integer in4,
in Integer in5,
out Integer out1,
out Integer out2,
out Integer out3,
out Integer out4,
out Integer out5;
}
instance EmptyA emptyA;
instance EmptyB emptyB;
connect emptyA.out1 -> emptyB.in1;
connect emptyA.out2 -> emptyB.in2;
connect emptyA.out3 -> emptyB.in3;
connect emptyA.out4 -> emptyB.in4;
connect emptyA.out5 -> emptyB.in5;
connect emptyB.out1 -> emptyA.in1;
connect emptyB.out2 -> emptyA.in2;
connect emptyB.out3 -> emptyA.in3;
connect emptyB.out4 -> emptyA.in4;
connect emptyB.out5 -> emptyA.in5;
connect in0 -> emptyA.in1;
connect emptyB.out1 -> out0;
}
package testManuelSchrick.bus;
component DecomposedBus {
ports
in Integer in0,
out Integer out0;
component EmptyA {
ports
in Integer in1,
out Integer out1,
out Integer out2,
out Integer out3,
out Integer out4,
out Integer out5;
}
component EmptyB {
ports
in Integer in1,
in Integer in2,
in Integer in3,
in Integer in4,
in Integer in5,
out Integer out1;
}
instance EmptyA emptyA;
instance EmptyB emptyB;
connect emptyA.out1 -> emptyB.in1;
connect emptyA.out2 -> emptyB.in2;
connect emptyA.out3 -> emptyB.in3;
connect emptyA.out4 -> emptyB.in4;
connect emptyA.out5 -> emptyB.in5;
connect in0 -> emptyA.in1;
connect emptyB.out1 -> out0;
}
package testManuelSchrick.bus;
component NormalBus {
ports
in Integer in0,
out Integer out0;
component EmptyA {
ports
in Integer in1,
out Integer out1,
out Integer out2,
out Integer out3,
out Integer out4,
out Integer out6,
out Integer out5;
}
component EmptyB {
ports
in Integer in1,
out Integer out1;
}
component EmptyC {
ports
in Integer in1,
in Integer in2,
in Integer in3,
in Integer in4,
in Integer in5,
in Integer in6,
out Integer out1;
}
instance EmptyA emptyA;
instance EmptyB emptyB;
instance EmptyC emptyC;
connect emptyA.out1 -> emptyC.in1;
connect emptyA.out2 -> emptyC.in2;
connect emptyA.out3 -> emptyC.in3;
connect emptyA.out4 -> emptyC.in4;
connect emptyA.out5 -> emptyC.in5;
connect emptyA.out6 -> emptyB.in1;
connect emptyB.out1 -> emptyC.in6;
connect in0 -> emptyA.in1;
connect emptyC.out1 -> out0;
}
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