Search in sources :

Example 1 with InterfaceDecl

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;
}
Also used : Type(abs.frontend.typechecker.Type) ClassDecl(abs.frontend.ast.ClassDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Example 2 with InterfaceDecl

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);
    }
}
Also used : MethodSig(abs.frontend.ast.MethodSig) AbsASTBuilderUtil.findMethodSig(abs.backend.tests.AbsASTBuilderUtil.findMethodSig) ClassDecl(abs.frontend.ast.ClassDecl) AbsASTBuilderUtil.findMethodImpl(abs.backend.tests.AbsASTBuilderUtil.findMethodImpl) MethodImpl(abs.frontend.ast.MethodImpl) TestCase(apet.testCases.TestCase) MethodNamePredicate(abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate) Access(abs.frontend.ast.Access) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 3 with InterfaceDecl

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;
}
Also used : InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 4 with InterfaceDecl

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;
}
Also used : InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Example 5 with InterfaceDecl

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));
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) AddInterfaceModifier(abs.frontend.ast.AddInterfaceModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) MethodImpl(abs.frontend.ast.MethodImpl) DeltaAccess(abs.frontend.ast.DeltaAccess) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) InterfaceDecl(abs.frontend.ast.InterfaceDecl)

Aggregations

InterfaceDecl (abs.frontend.ast.InterfaceDecl)15 ClassDecl (abs.frontend.ast.ClassDecl)7 Decl (abs.frontend.ast.Decl)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 FrontendTest (abs.frontend.FrontendTest)2 DataTypeUse (abs.frontend.ast.DataTypeUse)2 DeltaAccess (abs.frontend.ast.DeltaAccess)2 FieldDecl (abs.frontend.ast.FieldDecl)2 InterfaceTypeUse (abs.frontend.ast.InterfaceTypeUse)2 List (abs.frontend.ast.List)2 MethodImpl (abs.frontend.ast.MethodImpl)2 Model (abs.frontend.ast.Model)2 ModuleDecl (abs.frontend.ast.ModuleDecl)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 MethodNamePredicate (abs.backend.tests.AbsASTBuilderUtil.MethodNamePredicate)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 AbsASTBuilderUtil.findMethodSig (abs.backend.tests.AbsASTBuilderUtil.findMethodSig)1 Access (abs.frontend.ast.Access)1 AddInterfaceModifier (abs.frontend.ast.AddInterfaceModifier)1