Search in sources :

Example 1 with Access

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);
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) FunctionDecl(abs.frontend.ast.FunctionDecl)

Example 2 with Access

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);
    }
}
Also used : MethodSig(abs.frontend.ast.MethodSig) AbsASTBuilderUtil.findMethodSig(abs.backend.tests.AbsASTBuilderUtil.findMethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) MethodNamePredicate(abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 3 with Access

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;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) SyncCall(abs.frontend.ast.SyncCall) Access(abs.frontend.ast.Access) VarUse(abs.frontend.ast.VarUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse)

Aggregations

Access (abs.frontend.ast.Access)3 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)2 ClassDecl (abs.frontend.ast.ClassDecl)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 MethodImpl (abs.frontend.ast.MethodImpl)2 MethodSig (abs.frontend.ast.MethodSig)2 TestCase (apet.testCases.TestCase)2 MethodNamePredicate (abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate)1 AbsASTBuilderUtil.findMethodSig (abs.backend.tests.AbsASTBuilderUtil.findMethodSig)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1 FunctionDecl (abs.frontend.ast.FunctionDecl)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)1 SyncCall (abs.frontend.ast.SyncCall)1 TypeUse (abs.frontend.ast.TypeUse)1 VarUse (abs.frontend.ast.VarUse)1