Search in sources :

Example 36 with DeltaDecl

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

the class ABSUnitTestCaseBuilder method createObjectsInHeap.

void createObjectsInHeap(String testMethodName, Set<String> heapNames, Map<String, InterfaceTypeUse> objectsInHeap, ClassDecl testClass, Map<ABSRef, ABSObject> initialHeap, Block testMethodBlock) {
    String setMethodForTest = testCaseNameBuilder.initialTestMethodName(testMethodName);
    Block modifyBlock = initialiseDeltaForTestClass(testClass, testCaseNameBuilder.initialTestMethodName(testMethodName));
    testMethodBlock.addStmtNoTransform(getExpStmt(getCall(getThis(), setMethodForTest, true)));
    Map<String, String> typeHierarchy = new HashMap<String, String>();
    Map<String, List<Stmt>> initialisations = new HashMap<String, List<Stmt>>();
    List<String> initialisationsOrders = new ArrayList<String>();
    for (ABSRef r : initialHeap.keySet()) {
        makeSetStatements(typeHierarchy, initialisations, initialisationsOrders, testMethodName, heapNames, initialHeap, objectsInHeap, r, initialHeap.get(r), testClass);
    }
    for (String ref : initialisationsOrders) {
        for (Stmt s : initialisations.get(ref)) {
            modifyBlock.addStmtNoTransform(s);
        }
    }
    String testClassName = testClass.getName();
    DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
    ModifyClassModifier cm = null;
    for (ModuleModifier m : delta.getModuleModifiers()) {
        if (m.getName().equals(testClassName)) {
            cm = (ModifyClassModifier) m;
            break;
        }
    }
    for (String r : objectsInHeap.keySet()) {
        FieldDecl field = new FieldDecl();
        field.setName(r);
        InterfaceTypeUse inf = objectsInHeap.get(r);
        field.setAccess(inf);
        testClass.addField(field);
        // allow access of subtype information
        cm.addModifier(new RemoveFieldModifier(field.treeCopyNoTransform()));
        FieldDecl newField = new FieldDecl();
        newField.setName(r);
        newField.setAccess(new InterfaceTypeUse(typeHierarchy.get(inf.getName()), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
        cm.addModifier(new AddFieldModifier(newField));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoveFieldModifier(abs.frontend.ast.RemoveFieldModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) AbsASTBuilderUtil.getExpStmt(abs.backend.tests.AbsASTBuilderUtil.getExpStmt) Stmt(abs.frontend.ast.Stmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) ABSRef(apet.testCases.ABSRef) ModuleModifier(abs.frontend.ast.ModuleModifier) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) Block(abs.frontend.ast.Block) List(java.util.List) ArrayList(java.util.ArrayList) AddFieldModifier(abs.frontend.ast.AddFieldModifier)

Example 37 with DeltaDecl

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

the class ABSUnitTestCaseTranslator method generateABSUnitTests.

/**
 * Generates an ABS module {@link ModuleDecl} that defines the
 * given test suite.
 *
 * @param suite
 * @param validate
 * @return
 */
@SuppressWarnings("rawtypes")
public ModuleDecl generateABSUnitTests(ApetTestSuite suite, boolean validate) {
    console("Add basic imports...");
    for (String key : suite.keySet()) {
        console("Generating test suite for " + key + "...");
        generateABSUnitTest(suite.get(key), key);
    }
    Set<DeltaDecl> deltaDecls = new HashSet<DeltaDecl>();
    for (DeltaWrapper w : deltas) {
        DeltaDecl delta = w.getDelta();
        deltaDecls.add(delta);
        abs.frontend.ast.List<DeltaAccess> access = delta.getDeltaAccesss();
        if (access.hasChildren()) {
            String use = access.getChild(0).getModuleName();
            importModules.add(use);
        }
    }
    addImports(module);
    buildProductLine(module);
    console("Pretty printing ABSUnit tests...");
    List<ASTNode<ASTNode>> nodes = new ArrayList<ASTNode<ASTNode>>();
    nodes.add(module);
    nodes.addAll(deltaDecls);
    nodes.add(productline);
    nodes.add(product);
    printToFile(nodes, outputFile);
    if (validate) {
        console("Validating ABSUnit tests...");
        validateOutput();
    }
    console("ABSUnit tests generation successful");
    return module;
}
Also used : DeltaAccess(abs.frontend.ast.DeltaAccess) DeltaWrapper(apet.absunit.DeltaForGetSetFieldsBuilder.DeltaWrapper) ASTNode(abs.frontend.ast.ASTNode) ArrayList(java.util.ArrayList) DeltaDecl(abs.frontend.ast.DeltaDecl) HashSet(java.util.HashSet)

Aggregations

DeltaDecl (abs.frontend.ast.DeltaDecl)37 Test (org.junit.Test)32 Model (abs.frontend.ast.Model)30 ClassDecl (abs.frontend.ast.ClassDecl)22 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)15 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)8 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 AddMethodModifier (abs.frontend.ast.AddMethodModifier)6 DeltaAccess (abs.frontend.ast.DeltaAccess)6 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 Block (abs.frontend.ast.Block)4 CompilationUnit (abs.frontend.ast.CompilationUnit)4 MethodImpl (abs.frontend.ast.MethodImpl)4 MethodSig (abs.frontend.ast.MethodSig)4 FrontendTest (abs.frontend.FrontendTest)3 DataTypeDecl (abs.frontend.ast.DataTypeDecl)3 Decl (abs.frontend.ast.Decl)3 FunctionDecl (abs.frontend.ast.FunctionDecl)3 List (abs.frontend.ast.List)3