Commit f090c336 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Updated for Breaking Symbol Update

parent 504837ed
......@@ -5,7 +5,17 @@
*/
package de.monticore.lang.monticar.generator.rosmsg;
import de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab;
import de.monticore.ModelingLanguageFamily;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.embeddedmontiarc.LogConfig;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathLanguage;
import de.monticore.lang.monticar.Utils;
import de.monticore.lang.monticar.enumlang._symboltable.EnumLangLanguage;
import de.monticore.lang.monticar.streamunits._symboltable.StreamUnitsLanguage;
import de.monticore.lang.monticar.struct._symboltable.StructLanguage;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import org.junit.Assert;
......@@ -13,6 +23,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -21,7 +33,35 @@ import static org.junit.Assert.assertTrue;
/**
* Common methods for symboltable tests
*/
public class AbstractSymtabTest extends AbstractSymtab {
public class AbstractSymtabTest {
public static TaggingResolver createSymTabAndTaggingResolver(String... modelPath) {
Scope scope = createSymTab(modelPath);
return new TaggingResolver(scope, Arrays.asList(modelPath));
}
public static Scope createSymTab(String... modelPath) {
ModelingLanguageFamily fam = new ModelingLanguageFamily();
EmbeddedMontiArcMathLanguage montiArcLanguage = new EmbeddedMontiArcMathLanguage();
fam.addModelingLanguage(montiArcLanguage);
fam.addModelingLanguage(new StreamUnitsLanguage());
fam.addModelingLanguage(new StructLanguage());
fam.addModelingLanguage(new EnumLangLanguage());
ModelPath mp = new ModelPath(new Path[0]);
String[] var4 = modelPath;
int var5 = modelPath.length;
for(int var6 = 0; var6 < var5; ++var6) {
String m = var4[var6];
mp.addEntry(Paths.get(m));
}
LogConfig.init();
GlobalScope scope = new GlobalScope(mp, fam);
Utils.addBuiltInTypes(scope);
return scope;
}
public static void testFilesAreEqual(List<File> files, String restPath) {
for (File f : files) {
File fileTarget = new File("./src/test/resources/results/" + restPath + f.getName());
......
package de.monticore.lang.monticar.generator.rosmsg;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.symboltable.CommonSymbol;
import de.monticore.symboltable.Scope;
import org.junit.Test;
......@@ -20,12 +20,12 @@ public class BasicTypesTest extends AbstractSymtabTest {
@Test
public void testBasicTypes() throws IOException {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.basicTypesComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.basicTypesComp", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
PortSymbol inQ = component.getPort("inQ").orElse(null);
PortSymbol inZ = component.getPort("inZ").orElse(null);
PortSymbol inB = component.getPort("inB").orElse(null);
EMAPortSymbol inQ = component.getPortInstance("inQ").orElse(null);
EMAPortSymbol inZ = component.getPortInstance("inZ").orElse(null);
EMAPortSymbol inB = component.getPortInstance("inB").orElse(null);
assertNotNull(inQ);
assertNotNull(inZ);
......@@ -56,10 +56,10 @@ public class BasicTypesTest extends AbstractSymtabTest {
@Test
public void testMatrixTypes() {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.matrixTypesComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.matrixTypesComp", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
Map<String, RosMsg> portToMsg = component.getPortsList().stream()
Map<String, RosMsg> portToMsg = component.getPortInstanceList().stream()
.collect(Collectors.toMap(CommonSymbol::getName, p -> GeneratorRosMsg.getRosType("std_msgs", p.getTypeReference())));
assertTrue(portToMsg.get("in1").getName().equals("std_msgs/Float64MultiArray"));
......@@ -72,15 +72,15 @@ public class BasicTypesTest extends AbstractSymtabTest {
public void testBasicStructComp() throws IOException {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.basicStructComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.basicStructComp", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
String packageName = "basic";
generatorRosMsg.setTarget("target/generated-sources-rosmsg/basic", packageName);
PortSymbol in1 = component.getPort("in1").orElse(null);
PortSymbol out1 = component.getPort("out1").orElse(null);
EMAPortSymbol in1 = component.getPortInstance("in1").orElse(null);
EMAPortSymbol out1 = component.getPortInstance("out1").orElse(null);
assertNotNull(in1);
assertNotNull(out1);
......@@ -102,14 +102,14 @@ public class BasicTypesTest extends AbstractSymtabTest {
public void testNestedStructComp() throws IOException {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.nestedStructComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.nestedStructComp", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
String packageName = "nested";
generatorRosMsg.setTarget("target/generated-sources-rosmsg/nested", packageName);
PortSymbol inNested = component.getPort("inNested").orElse(null);
EMAPortSymbol inNested = component.getPortInstance("inNested").orElse(null);
assertNotNull(inNested);
......@@ -127,14 +127,14 @@ public class BasicTypesTest extends AbstractSymtabTest {
public void testMultiNestedStructComp() throws IOException {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.multiNestedStructComp", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.multiNestedStructComp", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
GeneratorRosMsg generatorRosMsg = new GeneratorRosMsg();
String packageName = "multinested";
generatorRosMsg.setTarget("target/generated-sources-rosmsg/multinested", packageName);
PortSymbol inMultiNested = component.getPort("inMultiNested").orElse(null);
EMAPortSymbol inMultiNested = component.getPortInstance("inMultiNested").orElse(null);
assertNotNull(inMultiNested);
......@@ -147,12 +147,12 @@ public class BasicTypesTest extends AbstractSymtabTest {
@Test
public void testGenericCompInstance() {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.genericCompInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol component = symtab.<EMAComponentInstanceSymbol>resolve("tests.genericCompInstance", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
RosMsg typeB = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instB").get().getPort("in1").get().getTypeReference());
RosMsg typeQ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instQ").get().getPort("in1").get().getTypeReference());
RosMsg typeZ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instZ").get().getPort("in1").get().getTypeReference());
RosMsg typeB = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instB").get().getPortInstance("in1").get().getTypeReference());
RosMsg typeQ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instQ").get().getPortInstance("in1").get().getTypeReference());
RosMsg typeZ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instZ").get().getPortInstance("in1").get().getTypeReference());
assertTrue(typeB.getName().equals("std_msgs/Bool"));
assertTrue(typeQ.getName().equals("std_msgs/Float64"));
......
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