Commit 9ddb295e authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated tests

parent 16698687
......@@ -9,6 +9,7 @@ import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.Generator;
import de.monticore.lang.monticar.generator.Helper;
import de.monticore.lang.monticar.generator.optimization.ThreadingOptimizer;
import de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.io.FileUtils;
......@@ -60,7 +61,7 @@ public class GenerationTest extends AbstractSymtabTest {
"#ifndef M_PI\n" +
"#define M_PI 3.14159265358979323846\n" +
"#endif\n" +
"#include \"octave/oct.h\"\n"+
"#include \"octave/oct.h\"\n" +
"class test_basicPorts{\n" +
"public:\n" +
"double in1;\n" +
......@@ -95,7 +96,7 @@ public class GenerationTest extends AbstractSymtabTest {
"#ifndef M_PI\n" +
"#define M_PI 3.14159265358979323846\n" +
"#endif\n" +
"#include \"octave/oct.h\"\n"+
"#include \"octave/oct.h\"\n" +
"class test_basicPortsConstantConnector{\n" +
"public:\n" +
"double out1;\n" +
......@@ -134,7 +135,7 @@ public class GenerationTest extends AbstractSymtabTest {
"#ifndef M_PI\n" +
"#define M_PI 3.14159265358979323846\n" +
"#endif\n" +
"#include \"octave/oct.h\"\n"+
"#include \"octave/oct.h\"\n" +
"class test_basicPortsMath{\n" +
"public:\n" +
"double counter;\n" +
......@@ -175,7 +176,7 @@ public class GenerationTest extends AbstractSymtabTest {
"#ifndef M_PI\n" +
"#define M_PI 3.14159265358979323846\n" +
"#endif\n" +
"#include \"octave/oct.h\"\n"+
"#include \"octave/oct.h\"\n" +
"class test_basicPortsLoop{\n" +
"public:\n" +
"double counter;\n" +
......@@ -311,18 +312,20 @@ public class GenerationTest extends AbstractSymtabTest {
}
@Test
public void testBasicGenericInstance() {
public void testBasicGenericInstance() throws Exception{
Scope symtab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.basicGenericInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
/*System.out.println(componentSymbol.getSubComponents().iterator().next().toString());
for(ResolutionDeclarationSymbol sym:componentSymbol.getSubComponents().iterator().next().getResolutionDeclarationSymbols())
{
System.out.println(sym.getNameToResolve());
}*/
MathStatementsSymbol mathSymbol = Helper.getMathStatementsSymbolFor(componentSymbol, symtab);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testBasicGenericInstance");
System.out.println(generatorCPP.generateStrings(componentSymbol, symtab));
System.out.println(generatorCPP.generateString(componentSymbol.getSubComponents().iterator().next(), mathSymbol));
generatorCPP.generateFiles(componentSymbol, symtab);
}
@Test
......@@ -333,9 +336,9 @@ public class GenerationTest extends AbstractSymtabTest {
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testBasicGenericArrayInstance");
generatorCPP.generateFiles(componentSymbol, symtab);
//System.out.println(generatorCPP.generateString(componentSymbol.getSubComponents().iterator().next(), mathSymbol));
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String restPath = "testBasicGenericArrayInstance/";
testFilesAreEqual(files, restPath);
}
@Test
......@@ -440,5 +443,4 @@ public class GenerationTest extends AbstractSymtabTest {
}
}
#ifndef HELPER_H
#define HELPER_H
#define _GLIBCXX_USE_CXX11_ABI 0
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#include <stdarg.h>
#include <initializer_list>
class Helper
{
public:
static void init()
{
string_vector argv(2);
argv(0) = "embedded";
argv(1) = "-q";
octave_main(2, argv.c_str_vec(), 1);
//octave_debug=1;
//feval ("pkg", ovl ("load", "all"), 0);
}
static octave_value_list convertToOctaveValueList(double a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(double a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(std::initializer_list<double> args)
{
octave_value_list in;
int counter = 0;
for(double element : args) {
in(counter) = octave_value(element);
++counter;
}
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list callOctaveFunction(octave_value_list in, std::string functionName,int argsOut)
{
/*octave_idx_type n = 2;
octave_value_list in;
for(octave_idx_type i = 0; i < n; i++)
in(i) = octave_value(5 * (i + 2));
octave_value_list out = feval("gcd", in, 1);
if(!error_state && out.length() > 0)
std::cout << "GCD of [" << in(0).int_value() << ", " << in(1).int_value() << "] is " << out(0).int_value()
<< std::endl;
else
std::cout << "invalid\n";
clean_up_and_exit(0);*/
/* if(functionName=="eigs")
return feval(functionName, in, 2);
else if(functionName=="kmeans")
return feval(functionName, in, 2);
*/
return feval(functionName, in, argsOut);
}
static int callOctaveFunctionIntFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionIntFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).int_value();
}
static double callOctaveFunctionDoubleFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionDoubleFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).double_value();
}
static Matrix callOctaveFunctionMatrixFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
printf("pre Call %s\n", functionName.c_str());
try {
in=octave_value_list();
octave_value_list list = callOctaveFunction(in, functionName,argsOut);
printf("post Call %s\n", functionName.c_str());
return list(0).array_value().as_column();
} catch(const std::exception& e) {
printf("%s\n", e.what());
}
return ColumnVector();
}
static RowVector callOctaveFunctionRowVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).array_value().as_row();
}
static int callOctaveFunctionIntSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).int_value();
}
static double callOctaveFunctionDoubleSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).double_value();
}
static Matrix callOctaveFunctionMatrixSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_column();
}
static RowVector callOctaveFunctionRowVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_row();
}
static Matrix getMatrixFromOctaveListFirstResult(octave_value_list list){
return list(0).matrix_value();
}
static RowVector getRowVectorFromOctaveListFirstResult(octave_value_list list){
return list(0).array_value().as_row();
}
static ColumnVector getColumnVectorFromOctaveListFirstResult(octave_value_list list){
return list(0).array_value().as_column();
}
static double getDoubleFromOctaveListFirstResult(octave_value_list list){
return list(0).double_value();
}
static int getIntFromOctaveListFirstResult(octave_value_list list){
return list(0).int_value();
}
};
#endif // HELPER_H
\ No newline at end of file
#ifndef TEST_BASICGENERICARRAYINSTANCE
#define TEST_BASICGENERICARRAYINSTANCE
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
#include "test_basicGenericArrayInstance_basicGenericArraySize1.h"
#include "test_basicGenericArrayInstance_basicGenericArraySize2.h"
class test_basicGenericArrayInstance{
public:
double val1[6];
double valOut[6];
test_basicGenericArrayInstance_basicGenericArraySize1 basicGenericArraySize1;
test_basicGenericArrayInstance_basicGenericArraySize2 basicGenericArraySize2;
void init()
{
basicGenericArraySize1.init();
basicGenericArraySize2.init();
}
void execute()
{
basicGenericArraySize1.val1[0] = val1[0];
basicGenericArraySize1.val1[1] = val1[1];
basicGenericArraySize1.val1[2] = val1[2];
basicGenericArraySize1.execute();
basicGenericArraySize2.val1[0] = val1[3];
basicGenericArraySize2.val1[1] = val1[4];
basicGenericArraySize2.val1[2] = val1[5];
basicGenericArraySize2.execute();
valOut[0] = basicGenericArraySize1.valOut[0];
valOut[1] = basicGenericArraySize1.valOut[1];
valOut[2] = basicGenericArraySize1.valOut[2];
valOut[3] = basicGenericArraySize2.valOut[0];
valOut[4] = basicGenericArraySize2.valOut[1];
valOut[5] = basicGenericArraySize2.valOut[2];
}
};
#endif
#ifndef TEST_BASICGENERICARRAYINSTANCE_BASICGENERICARRAYSIZE1
#define TEST_BASICGENERICARRAYINSTANCE_BASICGENERICARRAYSIZE1
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class test_basicGenericArrayInstance_basicGenericArraySize1{
const int n = 3;
public:
double val1[3];
double valOut[3];
void init()
{
}
void execute()
{
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1]*2/1 ;
}
}
};
#endif
#ifndef TEST_BASICGENERICARRAYINSTANCE_BASICGENERICARRAYSIZE2
#define TEST_BASICGENERICARRAYINSTANCE_BASICGENERICARRAYSIZE2
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class test_basicGenericArrayInstance_basicGenericArraySize2{
const int n = 3;
public:
double val1[3];
double valOut[3];
void init()
{
}
void execute()
{
for( auto i=1/1 ;i<=n;++i){
valOut(i) = val1[i-1-1]*2/1 ;
}
}
};
#endif
#ifndef HELPER_H
#define HELPER_H
#define _GLIBCXX_USE_CXX11_ABI 0
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
#include <stdarg.h>
#include <initializer_list>
class Helper
{
public:
static void init()
{
string_vector argv(2);
argv(0) = "embedded";
argv(1) = "-q";
octave_main(2, argv.c_str_vec(), 1);
//octave_debug=1;
//feval ("pkg", ovl ("load", "all"), 0);
}
static octave_value_list convertToOctaveValueList(double a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a)
{
octave_value_list in;
in(0) = a;
return in;
}
static octave_value_list convertToOctaveValueList(double a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(std::initializer_list<double> args)
{
octave_value_list in;
int counter = 0;
for(double element : args) {
in(counter) = octave_value(element);
++counter;
}
return in;
}
static octave_value_list convertToOctaveValueList(Matrix a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(RowVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list convertToOctaveValueList(ColumnVector a, double b)
{
octave_value_list in;
in(0) = a;
in(1) = b;
return in;
}
static octave_value_list callOctaveFunction(octave_value_list in, std::string functionName,int argsOut)
{
/*octave_idx_type n = 2;
octave_value_list in;
for(octave_idx_type i = 0; i < n; i++)
in(i) = octave_value(5 * (i + 2));
octave_value_list out = feval("gcd", in, 1);
if(!error_state && out.length() > 0)
std::cout << "GCD of [" << in(0).int_value() << ", " << in(1).int_value() << "] is " << out(0).int_value()
<< std::endl;
else
std::cout << "invalid\n";
clean_up_and_exit(0);*/
/* if(functionName=="eigs")
return feval(functionName, in, 2);
else if(functionName=="kmeans")
return feval(functionName, in, 2);
*/
return feval(functionName, in, argsOut);
}
static int callOctaveFunctionIntFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionIntFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).int_value();
}
static double callOctaveFunctionDoubleFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
// printf("callOctaveFunctionDoubleFirstResult pre return functionName: %s\n",functionName.c_str());
return callOctaveFunction(in, functionName,argsOut)(0).double_value();
}
static Matrix callOctaveFunctionMatrixFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
printf("pre Call %s\n", functionName.c_str());
try {
in=octave_value_list();
octave_value_list list = callOctaveFunction(in, functionName,argsOut);
printf("post Call %s\n", functionName.c_str());
return list(0).array_value().as_column();
} catch(const std::exception& e) {
printf("%s\n", e.what());
}
return ColumnVector();
}
static RowVector callOctaveFunctionRowVectorFirstResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(0).array_value().as_row();
}
static int callOctaveFunctionIntSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).int_value();
}
static double callOctaveFunctionDoubleSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).double_value();
}
static Matrix callOctaveFunctionMatrixSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).matrix_value();
}
static ColumnVector callOctaveFunctionColumnVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_column();
}
static RowVector callOctaveFunctionRowVectorSecondResult(octave_value_list in, std::string functionName, int argsOut)
{
return callOctaveFunction(in, functionName,argsOut)(1).array_value().as_row();
}
static Matrix getMatrixFromOctaveListFirstResult(octave_value_list list){
return list(0).matrix_value();
}