Search in sources :

Example 6 with DataTypeUse

use of abs.frontend.ast.DataTypeUse in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestClassImplAST.

private Set<TypeUse> generateTestClassImplAST(InterfaceDecl inf, ClassDecl clazz, MainBlock block) {
    Set<TypeUse> accesses = new HashSet<>();
    TypeUse dataType = generateDataPointsAST(inf, clazz, accesses, block);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        Block thisBlock = block;
        WhileStmt ws = null;
        if (method.getNumParam() > 0) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            ws = new WhileStmt();
            ws.setCondition(getFnApp("hasNext", new VarUse(dataPointSet)));
            Block body = new Block();
            thisBlock = body;
            DataTypeUse u = getType("Pair", getType("Set", (TypeUse) dataType.copy()), (TypeUse) dataType.copy());
            thisBlock.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(dataPointSet))));
            thisBlock.addStmtNoTransform(getVarDecl(dataValue, (TypeUse) dataType.copy(), getFnApp("snd", new VarUse("nt"))));
            thisBlock.addStmtNoTransform(getVAssign(dataPointSet, getFnApp("fst", new VarUse("nt"))));
            ws.setBody(body);
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            String objectRef = uncap(namePrefix) + instance;
            thisBlock.addStmtNoTransform(newObj(inf, clazz, objectRef, false));
            generateAsyncTestCallAST(thisBlock, objectRef, method);
        }
        if (ws != null) {
            block.addStmtNoTransform(ws);
        }
        instance++;
    }
    return accesses;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) TypeUse(abs.frontend.ast.TypeUse) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) VarUse(abs.frontend.ast.VarUse) HashSet(java.util.HashSet)

Aggregations

DataTypeUse (abs.frontend.ast.DataTypeUse)6 VarUse (abs.frontend.ast.VarUse)4 Block (abs.frontend.ast.Block)3 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)3 EqExp (abs.frontend.ast.EqExp)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 MainBlock (abs.frontend.ast.MainBlock)2 NullExp (abs.frontend.ast.NullExp)2 PureExp (abs.frontend.ast.PureExp)2 TypeUse (abs.frontend.ast.TypeUse)2 WhileStmt (abs.frontend.ast.WhileStmt)2 ABSRef (apet.testCases.ABSRef)2 HashSet (java.util.HashSet)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 Exp (abs.frontend.ast.Exp)1 GetExp (abs.frontend.ast.GetExp)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 MethodSig (abs.frontend.ast.MethodSig)1 ABSData (apet.testCases.ABSData)1 ABSObject (apet.testCases.ABSObject)1