use of abs.frontend.ast.InterfaceDecl in project abstools by abstools.
the class StringBasedABSTestRunnerGenerator method generateMainBlock.
private TestRunnerScriptBuilder generateMainBlock(TestRunnerScriptBuilder imports) {
TestRunnerScriptBuilder builder = new TestRunnerScriptBuilder();
builder.increaseIndent();
Set<Type> paramNames = new HashSet<>();
builder.append("Set<Fut<Unit>> ").append(futs).append(" = EmptySet;").newLine();
builder.append("Fut<Unit> ").append(fut).append(";").newLine();
for (InterfaceDecl key : tests.keySet()) {
builder.append("//Test cases for ").append(key.getType().getQualifiedName()).newLine();
for (ClassDecl clazz : tests.get(key)) {
builder.append("//Test cases for implementation ").append(clazz.getName()).newLine();
paramNames.addAll(generateTestClassImpl(key, clazz, builder));
}
}
generateWaitSync(builder);
generateImports(imports, paramNames);
return builder;
}
use of abs.frontend.ast.InterfaceDecl 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);
}
}
use of abs.frontend.ast.InterfaceDecl in project abstools by abstools.
the class ABSUnitTestCaseTranslator method createTestFixture.
/**
* Create Test Fixture for a given Class method or a function.
*
* @param testCaseSize
* @param className
* @param methodName
* @return
*/
private InterfaceDecl createTestFixture(int testCaseSize, String className, String methodName) {
String capMethodName = StringUtils.capitalize(methodName);
if (className == null) {
className = testCaseNameBuilder.functionClassName(capMethodName);
}
final String testInterfaceName = testCaseNameBuilder.testInterfaceName(className, capMethodName);
// create fixture
InterfaceDecl testInterface = getDecl(module, InterfaceDecl.class, AbsASTBuilderUtil.<InterfaceDecl>namePred(testInterfaceName));
if (testInterface == null) {
testInterface = translatorHelper.createTestInterface(testInterfaceName);
module.addDecl(testInterface);
}
for (int i = 1; i <= testCaseSize; i++) {
testInterface.addBody(translatorHelper.createTestMethodSig(testCaseNameBuilder.testMethodName(capMethodName, Integer.valueOf(i).toString())));
}
return testInterface;
}
use of abs.frontend.ast.InterfaceDecl in project abstools by abstools.
the class ABSUnitTestCaseTranslatorHelper method createTestInterface.
InterfaceDecl createTestInterface(String interfaceName) {
InterfaceDecl ti = createInterface(interfaceName);
ti.addAnnotation(getTestAnnotation(fixtureType));
return ti;
}
use of abs.frontend.ast.InterfaceDecl in project abstools by abstools.
the class DeltaForGetSetFieldsBuilder method updateDelta.
/**
* Add a delta that adds Getters and Setters for clazz.
*
* @param extensions
* @param interf
* @param clazz
*/
void updateDelta(Map<String, String> typeHierarchy, InterfaceTypeUse interf, ClassDecl clazz) {
String className = clazz.getName();
String deltaOnClassName = testCaseNameBuilder.deltaOnClass(className);
String interfaceForModifyingClassFieldName = testCaseNameBuilder.interfaceForModifyingFieldOfClass(className);
DeltaDecl dd = getDelta(deltaOnClassName);
if (dd != null) {
typeHierarchy.put(interf.getName(), interfaceForModifyingClassFieldName);
return;
}
dd = new DeltaDecl();
dd.setName(deltaOnClassName);
dd.addDeltaAccess(new DeltaAccess(clazz.getModuleDecl().getName()));
// add Setters and Getters
ModifyClassModifier mcm = new ModifyClassModifier();
mcm.setName(className);
InterfaceDecl ai = new InterfaceDecl();
ai.setName(interfaceForModifyingClassFieldName);
// extends the existing interface
InterfaceTypeUse inf = interf.treeCopyNoTransform();
ai.addExtendedInterfaceUse(inf.treeCopyNoTransform());
mcm.addAddedInterface(new InterfaceTypeUse(ai.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
typeHierarchy.put(inf.getName(), interfaceForModifyingClassFieldName);
for (MethodImpl m : clazz.getMethodList()) {
if (RUN_METHOD.equals(m.getMethodSig().getName())) {
mcm.addModifier(removeRun());
break;
}
}
for (FieldDecl fd : clazz.getFieldList()) {
AddMethodModifier smm = addSetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
AddMethodModifier gmm = addGetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
mcm.addModifier(smm);
mcm.addModifier(gmm);
ai.addBody(smm.getMethodImpl().getMethodSig());
ai.addBody(gmm.getMethodImpl().getMethodSig());
}
dd.addModuleModifier(new AddInterfaceModifier(ai));
dd.addModuleModifier(mcm);
deltas.add(new DeltaWrapper(dd, false));
}
Aggregations