use of abs.frontend.ast.Access in project abstools by abstools.
the class ABSUnitTestCaseTranslator method createTestSuiteForFunction.
/**
* Create a test suite for testing a function.
*
* @param testCases
* @param testInterface
* @param className
* @param functionName
*/
private void createTestSuiteForFunction(List<TestCase> testCases, InterfaceDecl testInterface, String functionName) {
// create test class ([Suite])
final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
module.addDecl(testClass);
// find function under test
FunctionDecl functionUnderTest = getDecl(model, FunctionDecl.class, new DeclNamePredicate<FunctionDecl>(functionName));
final Access access = functionUnderTest.getTypeUse();
importModules.add(functionUnderTest.getModuleDecl().getName());
/*
* Test methods and Test cases are ordered that is,
* test case 1 is implemented by test method 1 and so on...
*/
for (int i = 0; i < testCases.size(); i++) {
console("Generating test case " + i + "...");
TestCase testCase = testCases.get(i);
MethodImpl method = testClass.getMethod(i);
functionBuilder.buildTestCase(testCase, testClass, method, access, functionName);
}
}
use of abs.frontend.ast.Access in project abstools by abstools.
the class ABSUnitTestCaseTranslator method createTestSuiteForClassMethod.
/**
* Create a test suite for testing a method.
*
* @param testCases
* @param testInterface
* @param className
* @param methodName
*/
private void createTestSuiteForClassMethod(List<TestCase> testCases, InterfaceDecl testInterface, String className, String methodName) {
// create test class ([Suite])
final ClassDecl testClass = translatorHelper.createTestClass(testInterface);
module.addDecl(testClass);
// find class under test.
ClassDecl classUnderTest = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(className));
assert classUnderTest != null : "It should not be possible to not " + "find class under test";
// find method under test.
MethodImpl methodUnderTest = findMethodImpl(classUnderTest, new MethodNamePredicate(methodName));
assert methodUnderTest != null : "It should not be possible to not " + "find method under test";
// find interface of class under test.
InterfaceDecl interfaceOfClassUnderTest = findInterfaceUnderTest(methodName, classUnderTest);
if (interfaceOfClassUnderTest == null) {
// this method is not exposed by any interface!
}
// return type
MethodSig signature = methodUnderTest.getMethodSig();
final Access access = signature.getReturnType();
// add imports of class/interface under test
importModules.add(classUnderTest.getModuleDecl().getName());
importModules.add(interfaceOfClassUnderTest.getModuleDecl().getName());
/*
* Test methods and Test cases are ordered that is,
* test case 1 is implemented by test method 1 and so on...
*/
for (int i = 0; i < testCases.size(); i++) {
console("Generating test case " + i + "...");
TestCase testCase = testCases.get(i);
MethodImpl method = testClass.getMethod(i);
methodBuilder.buildTestCase(testCase, testClass, method, access, methodName);
}
}
use of abs.frontend.ast.Access in project abstools by abstools.
the class ASTBasedABSTestRunnerGenerator method generateDataPointsAST.
private TypeUse generateDataPointsAST(InterfaceDecl key, ClassDecl clazz, Set<TypeUse> use, MainBlock block) {
MethodSig dataPoint = findDataPoints(key);
if (dataPoint == null) {
return null;
}
Access rt = dataPoint.getReturnType();
if (!(rt instanceof ParametricDataTypeUse)) {
return null;
}
ParametricDataTypeUse prt = (ParametricDataTypeUse) rt;
if (!prt.getName().equals("Set")) {
return null;
}
// Set has only one type parameter
TypeUse u = (TypeUse) prt.getParam(0).copy();
use.add(u);
String objName = uncap(clazz.getName()) + "dataPoint";
String dataSet = dataPointSetName(clazz);
block.addStmtNoTransform(newObj(key, clazz, objName, true));
block.addStmtNoTransform(getVarDecl(dataSet, prt.copy(), new SyncCall(new VarUse(objName), dataPoint.getName(), new List<>())));
return u;
}
Aggregations