Commit 763d759d authored by Christoph Richter's avatar Christoph Richter
Browse files

Added tests

parent ae646fa3
Pipeline #56857 passed with stage
in 21 minutes and 2 seconds
......@@ -313,6 +313,21 @@
</execution>
</executions>
</plugin>
<!-- export tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
......@@ -336,6 +351,7 @@
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
<check/>
</configuration>
</plugin>
</plugins>
......
package de.monticore.lang.embeddedmontiarcmathopt._symboltable;
import de.monticore.EmbeddingModelingLanguage;
import de.monticore.antlr4.MCConcreteParser;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcLanguage;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathLanguage;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathModelLoader;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathSymbolTableCreator;
import de.monticore.lang.embeddedmontiarcmathopt._parser.EmbeddedMontiArcMathOptParser;
import de.monticore.lang.mathopt._symboltable.MathOptLanguage;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.resolving.ResolvingFilter;
import java.util.Collection;
import java.util.Optional;
public class EmbeddedMontiArcMathOptLanguage extends EmbeddedMontiArcMathLanguage {
public class EmbeddedMontiArcMathOptLanguage extends EmbeddingModelingLanguage {
private EmbeddedMontiArcMathLanguage parentLanguage;
public EmbeddedMontiArcMathOptLanguage() {
super();
this.embeddedLanguages.clear();
this.embeddedLanguages.add(new MathOptLanguage());
super("Embedded MontiArc Math Opt Language", "emam", new EmbeddedMontiArcLanguage(), new MathOptLanguage());
parentLanguage = new EmbeddedMontiArcMathLanguage();
}
@Override
public Collection<ResolvingFilter<? extends Symbol>> getResolvingFilters() {
return parentLanguage.getResolvingFilters();
}
@Override
protected EmbeddedMontiArcMathModelLoader provideModelLoader() {
protected EmbeddedMontiArcMathOptModelLoader provideModelLoader() {
return new EmbeddedMontiArcMathOptModelLoader(this);
}
......@@ -30,7 +39,7 @@ public class EmbeddedMontiArcMathOptLanguage extends EmbeddedMontiArcMathLanguag
}
@Override
public Optional<EmbeddedMontiArcMathSymbolTableCreator> getSymbolTableCreator(ResolvingConfiguration resolvingConfiguration, MutableScope enclosingScope) {
public Optional<EmbeddedMontiArcMathOptSymbolTableCreator> getSymbolTableCreator(ResolvingConfiguration resolvingConfiguration, MutableScope enclosingScope) {
return Optional.of(new EmbeddedMontiArcMathOptSymbolTableCreator(resolvingConfiguration, enclosingScope));
}
}
/**
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
* <p>
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
/* generated by template symboltable.ModelingLanguage*/
package de.monticore.lang.embeddedmontiarcmathopt._symboltable;
import de.monticore.ModelingLanguageFamily;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConstantPortSymbol;
import de.monticore.lang.embeddedmontiarcmathopt._ast.ASTEMAMOptCompilationUnit;
import de.monticore.lang.monticar.stream._symboltable.StreamLanguage;
import de.monticore.lang.monticar.struct._symboltable.StructLanguage;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
import java.nio.file.Paths;
/**
* @author Christoph Richter
*/
public class EmbeddedMontiArcMathOptLanguageFamiliy extends ModelingLanguageFamily {
public EmbeddedMontiArcMathOptLanguageFamiliy() {
addModelingLanguage(new EmbeddedMontiArcMathOptLanguage());
addModelingLanguage(new StreamLanguage());
addModelingLanguage(new StructLanguage());
}
}
package de.monticore.lang.embeddedmontiarcmathopt._symboltable;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathLanguage;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathModelLoader;
import de.monticore.lang.embeddedmontiarcmathopt._ast.ASTEMAMOptCompilationUnit;
import de.monticore.modelloader.ModelingLanguageModelLoader;
import de.monticore.symboltable.ArtifactScope;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
public class EmbeddedMontiArcMathOptModelLoader extends EmbeddedMontiArcMathModelLoader {
public class EmbeddedMontiArcMathOptModelLoader extends ModelingLanguageModelLoader<ASTEMAMOptCompilationUnit> {
public EmbeddedMontiArcMathOptModelLoader(EmbeddedMontiArcMathOptLanguage language) {
super(language);
}
@Override
protected void createSymbolTableFromAST(ASTEMAMOptCompilationUnit ast, String modelName, MutableScope enclosingScope, ResolvingConfiguration resolvingConfiguration) {
final EmbeddedMontiArcMathOptSymbolTableCreator stc = getModelingLanguage().getSymbolTableCreator(resolvingConfiguration, enclosingScope).orElse(null);
if (stc != null) {
Log.debug("Start creation of symbol table for model \"" + modelName + "\".",
EmbeddedMontiArcMathModelLoader.class.getSimpleName());
final Scope scope = stc.createFromAST(ast);
if (!(scope instanceof ArtifactScope)) {
Log.warn("0xA7001_184 Top scope of model " + modelName + " is expected to be an artifact scope, but"
+ " is scope \"" + scope.getName() + "\"");
}
Log.debug("Created symbol table for model \"" + modelName + "\".", EmbeddedMontiArcMathOptModelLoader.class.getSimpleName());
} else {
Log.warn("0xA7002_184 No symbol created, because '" + getModelingLanguage().getName()
+ "' does not define a symbol table creator.");
}
}
@Override
public EmbeddedMontiArcMathOptLanguage getModelingLanguage() {
return (EmbeddedMontiArcMathOptLanguage) super.getModelingLanguage();
}
}
......@@ -20,11 +20,14 @@
package de.monticore.lang.embeddedmontiarcmathopt._symboltable;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathSymbolTableCreator;
import de.monticore.lang.embeddedmontiarcmathopt._ast.ASTEMAMOptCompilationUnit;
import de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptDelegatorVisitor;
import de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptVisitor;
import de.monticore.lang.mathopt._symboltable.MathOptSymbolTableCreator;
import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.ResolvingConfiguration;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import java.util.Deque;
......@@ -36,7 +39,7 @@ import java.util.Deque;
public class EmbeddedMontiArcMathOptSymbolTableCreator extends EmbeddedMontiArcMathSymbolTableCreator implements EmbeddedMontiArcMathOptVisitor {
// fields
private EmbeddedMontiArcMathOptDelegatorVisitor visitorOpt = new EmbeddedMontiArcMathOptDelegatorVisitor();
private EmbeddedMontiArcMathOptDelegatorVisitor visitorOpt;
private MathOptSymbolTableCreator mathOptSTC;
// constructors from inherited
......@@ -51,6 +54,8 @@ public class EmbeddedMontiArcMathOptSymbolTableCreator extends EmbeddedMontiArcM
@Override
protected void initSuperSTC(ResolvingConfiguration resolvingConfig) {
super.initSuperSTC(resolvingConfig);
// init visitorOpt
visitorOpt = new EmbeddedMontiArcMathOptDelegatorVisitor();
// init math opt symbol table creator
mathOptSTC = new MathOptSymbolTableCreator(resolvingConfig, scopeStack);
// init visitor delegator for test.emam.optimization languages
......@@ -84,5 +89,12 @@ public class EmbeddedMontiArcMathOptSymbolTableCreator extends EmbeddedMontiArcM
protected MathOptSymbolTableCreator getMathOptSTC() {
return mathOptSTC;
}
public Scope createFromAST(ASTEMAMOptCompilationUnit rootNode) {
Log.errorIfNull(rootNode, "0xA7004_184 Error by creating of the EmbeddedMontiArcMathOptSymbolTableCreator symbol table: top ast node is null");
rootNode.getEMAMCompilationUnit().accept(visitorOpt);
return getFirstCreatedScope();
}
}
package de.monticore.lang.embeddedmontiarcmathopt._ast;
import static org.junit.Assert.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcbehavior._ast.ASTBehaviorImplementation;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._ast.ASTBehaviorEmbedding;
import de.monticore.lang.embeddedmontiarcmathopt._parser.EmbeddedMontiArcMathOptParser;
import de.monticore.lang.math._ast.ASTStatement;
import de.monticore.lang.mathopt._ast.ASTOptimizationStatement;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Christoph Richter
*/
public class ASTEmbeddedMontiArcMathOptNodesTest {
@Test
public void testEMAMOptCompilationUnit() throws IOException {
EmbeddedMontiArcMathOptParser parser = new EmbeddedMontiArcMathOptParser();
ASTEMAMOptCompilationUnit astNode = parser.parse("src/test/resources/test/emam/optimization/MinimizePortsTest.emam").orElse(null);
assertNotNull(astNode);
assertEquals(ASTBehaviorImplementation.class, astNode.getEMAMCompilationUnit().getEMACompilationUnit().getComponent().getBody().getElement(1).getClass());
ASTBehaviorImplementation behaviour = (ASTBehaviorImplementation) astNode.getEMAMCompilationUnit().getEMACompilationUnit().getComponent().getBody().getElement(1);
ASTStatement astOptStatement = ((ASTBehaviorEmbedding) behaviour.getBehavior()).getStatement(0);
assertEquals(ASTOptimizationStatement.class, astOptStatement.getClass());
}
}
\ No newline at end of file
......@@ -4,28 +4,36 @@ import de.monticore.ModelingLanguageFamily;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.embeddedmontiarc.LogConfig;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath.AbstractSymtabTest;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathLanguage;
import de.monticore.lang.mathopt._symboltable.MathOptLanguage;
import de.monticore.lang.monticar.Utils;
import de.monticore.lang.monticar.stream._symboltable.StreamLanguage;
import de.monticore.lang.monticar.struct._symboltable.StructLanguage;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
/**
* Base test class for EMAMOpt symbol tables
* Provides initialized symbol table at default resource path
*/
public abstract class EMAMOptAbstractSymtabTest extends AbstractSymtabTest {
protected static Scope createSymTab(String... modelPath) {
ModelingLanguageFamily fam = getModelingLanguageFamily();
final ModelPath mp = getModelPath(modelPath);
ModelPath mp = getModelPath(modelPath);
GlobalScope scope = new GlobalScope(mp, fam);
de.monticore.lang.monticar.Utils.addBuiltInTypes(scope);
Utils.addBuiltInTypes(scope);
LogConfig.init();
return scope;
}
protected static ModelingLanguageFamily getModelingLanguageFamily() {
ModelingLanguageFamily fam = super.getModelingLanguageFamily();
ModelingLanguageFamily fam = new ModelingLanguageFamily();
fam.addModelingLanguage(new EmbeddedMontiArcMathOptLanguage());
fam.addModelingLanguage(new MathOptLanguage());
fam.addModelingLanguage(new StreamLanguage());
fam.addModelingLanguage(new StructLanguage());
return fam;
}
}
package de.monticore.lang.embeddedmontiarcmathopt._symboltable;
import static org.junit.Assert.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ComponentSymbol;
import de.monticore.symboltable.Scope;
import org.junit.Test;
public class EmbeddedMontiArcMathOptSymbolTableCreatorTest {
import static org.junit.Assert.assertNotNull;
public class EmbeddedMontiArcMathOptSymbolTableCreatorTest extends EMAMOptAbstractSymtabTest {
@Test
public void testScalarMinimizationModel() {
Scope symTab = createSymTab("src/test/resources");
ComponentSymbol symbol = symTab.<ComponentSymbol>resolve("test.math.optimization.ScalarMinimizationTest", ComponentSymbol.KIND).orElse(null);
assertNotNull(symbol);
}
@Test
public void testScalarMaximizationModel() {
Scope symTab = createSymTab("src/test/resources");
ComponentSymbol symbol = symTab.<ComponentSymbol>resolve("test.math.optimization.ScalarMaximizationTest", ComponentSymbol.KIND).orElse(null);
assertNotNull(symbol);
}
}
\ No newline at end of file
package test;
component Add{
ports
in (0 m : 10 m) a,
in (0 m : 10 m) b,
out (0 m : 20 m) c;
implementation Math{
c = a + b;
}
}
Markdown is supported
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