use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class TraitTest method addAddModifierAtRuntimeBackComp.
@Test
public void addAddModifierAtRuntimeBackComp() {
Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())), false);
AddMethodModifier opr = new AddMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.addDeltaAccess(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(2, cls.getMethods().getNumChild());
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class RecoverTest method assertContainsMethodWithName.
private void assertContainsMethodWithName(Model m, String name) {
boolean found = false;
for (MethodImpl mi : ((ClassDecl) m.getCompilationUnit(0).getModuleDecl(0).getDecl(0)).getMethods()) {
if (mi.getMethodSig().getName().equals(name)) {
found = true;
}
}
assertTrue("Did not found method with name " + name, found);
}
use of abs.frontend.ast.MethodImpl 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);
}
}
use of abs.frontend.ast.MethodImpl 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.MethodImpl in project abstools by abstools.
the class ABSUnitTestCaseTranslatorHelper method createTestClass.
ClassDecl createTestClass(InterfaceDecl inf) {
ClassDecl ct = new ClassDecl(testCaseNameBuilder.className(inf.getName()), new abs.frontend.ast.List<Annotation>(), new abs.frontend.ast.List<ParamDecl>(), new abs.frontend.ast.List<InterfaceTypeUse>(), new Opt<InitBlock>(), new abs.frontend.ast.List<CaseBranchStmt>(), new abs.frontend.ast.List<FieldDecl>(), new abs.frontend.ast.List<MethodImpl>());
ct.addAnnotation(getTestAnnotation(suiteType));
ct.addImplementedInterfaceUse(new InterfaceTypeUse(inf.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
for (MethodSig m : inf.getAllMethodSigs()) {
ct.addMethod(createMethodImpl(m));
}
FieldDecl assertImpl = new FieldDecl();
assertImpl.setName(ASSERT_HELPER);
assertImpl.setAccess(absAssertImpl.getImplementedInterfaceUse(0).treeCopyNoTransform());
ct.addField(assertImpl);
InitBlock block = new InitBlock();
block.addStmtNoTransform(getVAssign(ASSERT_HELPER, newObj(absAssertImpl, false)));
ct.setInitBlock(block);
return ct;
}
Aggregations