Commit 892a351c authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated test generation

parent b5162357
......@@ -10,6 +10,7 @@ import de.se_rwth.commons.logging.Log;
* @author Sascha Schneiders
*/
public class OctaveBackend implements MathBackend {
public static final String NAME="OctaveBackend";
@Override
public String getMatrixTypeName() {
return "Matrix";
......@@ -42,7 +43,7 @@ public class OctaveBackend implements MathBackend {
@Override
public String getBackendName() {
return "OctaveBackend";
return NAME;
}
@Override
......
......@@ -6,6 +6,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Componen
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ComponentStreamTestViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.StreamViewModel;
......@@ -82,7 +83,10 @@ public final class TestsGeneratorCPP {
}
}
if (generator.isGenerateTests()) {
files.add(new FileContent(AllTemplates.generateMainEntry(viewModelForMain), TESTS_DIRECTORY_NAME + "/tests_main.cpp"));
boolean isOctaveBackend = true;
if (!MathConverter.curBackend.getBackendName().equals(OctaveBackend.NAME))
isOctaveBackend = false;
files.add(new FileContent(AllTemplates.generateMainEntry(viewModelForMain, isOctaveBackend), TESTS_DIRECTORY_NAME + "/tests_main.cpp"));
files.add(getCatchLib());
}
//files.add(new FileContent(getTestedComponentsString(), TESTS_DIRECTORY_NAME + "/testedComponents.txt"));
......
package de.monticore.lang.monticar.generator.cpp.template;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ComponentStreamTestViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.EnumViewModel;
......@@ -19,6 +20,7 @@ public final class AllTemplates {
private static final Template COMPONENT_STREAM_TEST;
private static final Template TESTS_MAIN_ENTRY;
private static final Template TESTS_MAIN_ENTRY_ARMADILLO;
private static final Template STRUCT;
private static final Template ENUM;
private static final Template AUTOPILOT_ADAPTER;
......@@ -32,6 +34,7 @@ public final class AllTemplates {
try {
COMPONENT_STREAM_TEST = conf.getTemplate("/test/ComponentStreamTest.ftl");
TESTS_MAIN_ENTRY = conf.getTemplate("/test/TestsMainEntry.ftl");
TESTS_MAIN_ENTRY_ARMADILLO = conf.getTemplate("/test/TestsMainEntryArmadillo.ftl");
STRUCT = conf.getTemplate("/type/Struct.ftl");
ENUM = conf.getTemplate("/type/Enum.ftl");
AUTOPILOT_ADAPTER = conf.getTemplate("/autopilotadapter/AutopilotAdapter.ftl");
......@@ -49,8 +52,11 @@ public final class AllTemplates {
return generate(COMPONENT_STREAM_TEST, viewModel);
}
public static String generateMainEntry(TestsMainEntryViewModel viewModel) {
return generate(TESTS_MAIN_ENTRY, viewModel);
public static String generateMainEntry(TestsMainEntryViewModel viewModel, boolean backendOctave) {
if (backendOctave)
return generate(TESTS_MAIN_ENTRY, viewModel);
else
return generate(TESTS_MAIN_ENTRY_ARMADILLO, viewModel);
}
public static String generateStruct(StructViewModel viewModel) {
......
<#include "/Common.ftl">
#ifndef TESTS_MAIN
#define TESTS_MAIN
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
int main(int argc, char* argv[]) {
Catch::Session session;
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) {
return returnCode;
}
int numFailed = session.run();
return numFailed;
}
<#list viewModel.includes as i>
#include "${i}"
</#list>
#endif
......@@ -25,7 +25,7 @@ public class AllTemplatesTest {
vm.setIncludes(
Arrays.asList("cmp1.h", "cmp2.h", "cmp3.h")
);
String result = AllTemplates.generateMainEntry(vm);
String result = AllTemplates.generateMainEntry(vm,true);
Assert.assertNotNull(result);
Assert.assertTrue(result.contains("#include \"cmp1.h\""));
Assert.assertTrue(result.contains("#include \"cmp2.h\""));
......
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