use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class AnnotationTests method testMethodParam.
@Test
public void testMethodParam() {
Model m = assertParseOkAnn("class C { Unit m([Far] I i) { } }");
ClassDecl decl = getFirstClassDecl(m);
assertHasLocAnnotation(decl.getMethod(0).getMethodSig().getParam(0).getType(), "Far");
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class AnnotationTests method testClassParam.
@Test
public void testClassParam() {
Model m = assertParseOkAnn("class C([Far] I i) { }");
ClassDecl decl = getFirstClassDecl(m);
assertHasLocAnnotation(decl.getParam(0).getType(), "Far");
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class ABSUnitTestCaseBuilder method makeSetStatements.
void makeSetStatements(Map<String, String> typeHierarchy, Map<String, List<Stmt>> initialisations, List<String> initialisationsOrders, String testName, Set<String> heapNames, Map<ABSRef, ABSObject> initialHeap, Map<String, InterfaceTypeUse> objectsInHeap, ABSRef ref, ABSObject state, ClassDecl testClass) {
String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
String concreteTypeName = getABSObjectType(state);
ClassDecl concreteType = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName));
if (concreteType == null) {
throw new IllegalStateException("Cannot find class: " + concreteTypeName);
}
List<Stmt> statements = new ArrayList<Stmt>();
initialisations.put(rn, statements);
if (!initialisationsOrders.contains(rn)) {
initialisationsOrders.add(rn);
}
Map<String, ABSData> fields = getABSObjectFields(state);
abs.frontend.ast.List<ParamDecl> params = concreteType.getParamList();
PureExp[] constructorArgs = new PureExp[params.getNumChild()];
for (int i = 0; i < params.getNumChild(); i++) {
ParamDecl param = params.getChild(i);
String name = param.getName();
assert fields.containsKey(name);
ABSData d = fields.remove(name);
objectsInHeap.putAll(getTypesFromABSData(testName, d));
PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
constructorArgs[i] = exp;
}
statements.add(getVAssign(rn, newObj(concreteType, false, constructorArgs)));
for (String fn : fields.keySet()) {
ABSData d = fields.get(fn);
objectsInHeap.putAll(getTypesFromABSData(testName, d));
PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
Call call = getCall(new VarUse(rn), testCaseNameBuilder.setterMethodName(fn), true, exp);
statements.add(getExpStmt(call));
}
// ADD getter and setter
deltaBuilder.updateDelta(typeHierarchy, objectsInHeap.get(rn), getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName)));
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class ABSUnitTestCaseBuilder method makeGetAndAssertStatementsForHeapRef.
void makeGetAndAssertStatementsForHeapRef(String testName, Set<String> heapNames, Map<ABSRef, ABSObject> finalHeap, ABSRef ref, ABSObject state, Set<String> visited, Block block) {
String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
if (!visited.add(rn)) {
return;
}
Map<String, ABSData> fields = getABSObjectFields(state);
ClassDecl clazz = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(getABSObjectType(state)));
abs.frontend.ast.List<FieldDecl> fieldDecls = clazz.getFieldList();
for (int i = 0; i < fieldDecls.getNumChild(); i++) {
FieldDecl field = fieldDecls.getChild(i);
String fn = field.getName();
if (fields.containsKey(fn)) {
ABSData d = fields.get(fn);
block.addStmtNoTransform(getVarDecl(testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), getCall(new VarUse(rn), testCaseNameBuilder.getterMethodName(fn), true)));
makeOracle(testName, heapNames, finalHeap, testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), d, visited, block);
}
}
}
use of abs.frontend.ast.ClassDecl 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);
}
}
Aggregations