use of apet.testCases.ABSObject in project abstools by abstools.
the class ABSUnitTestCaseBuilder method buildTestCase.
/**
* @param testCase
* @param testClass
* @param method
* @param access
* @param unitUnderTest
*/
void buildTestCase(TestCase testCase, ClassDecl testClass, MethodImpl method, Access access, String unitUnderTest) {
// initial arg
List<ABSData> inputArguments = getInputArgs(testCase);
String testName = method.getMethodSig().getName();
Block block = method.getBlock();
Map<String, InterfaceTypeUse> typesOfObjectInHeap = new HashMap<String, InterfaceTypeUse>();
for (ABSData d : inputArguments) {
typesOfObjectInHeap.putAll(getTypesFromABSData(testName, d));
}
Map<ABSRef, ABSObject> initial = getInitialState(testCase);
for (ABSObject obj : initial.values()) {
typesOfObjectInHeap.putAll(getTypesFromABSObject(testName, obj));
}
Set<String> initialHeapNames = referenceNames(initial.keySet());
createObjectsInHeap(testName, initialHeapNames, typesOfObjectInHeap, testClass, initial, block);
List<PreviousCall> calls = getPreviousCalls(testCase);
List<Exp> previous = makePreviousCalls(testName, initialHeapNames, calls);
for (Exp pc : previous) {
// does not care about return value
block.addStmtNoTransform(getExpStmt(pc));
}
// test execution
Exp test = makeTestExecution(testName, initialHeapNames, unitUnderTest, inputArguments);
final boolean hasReturnValue;
if (access instanceof DataTypeUse && ((DataTypeUse) access).getName().equals("Unit")) {
// no return value
block.addStmtNoTransform(getExpStmt(test));
hasReturnValue = false;
} else {
block.addStmtNoTransform(getVarDecl("returnValue", access.treeCopyNoTransform(), test));
hasReturnValue = true;
}
Map<ABSRef, ABSObject> finalHeap = getAfterState(testCase);
if (finalHeap.isEmpty()) {
// the method under test is side-effect free?
// use the initial heap as oracle
finalHeap = initial;
}
Set<String> finalHeapNames = referenceNames(finalHeap.keySet());
// need to remember which objects in the heap we have already handled.
Set<String> visited = new HashSet<String>();
// assertions of object states can be done in the heap assertions
if (hasReturnValue) {
ABSData rd = getReturnData(testCase);
PureExp exp = pureExpBuilder.createPureExpression(testName, finalHeapNames, rd);
block.addStmtNoTransform(getExpStmt(getCall(new VarUse(ASSERT_HELPER), "assertTrue", true, new EqExp(new VarUse("returnValue"), exp))));
}
// check return value (using deltas)
makeGetAndAssertStatements(testName, finalHeapNames, testClass, finalHeap, visited, block);
}
Aggregations