Search in sources :

Example 1 with InheritanceTree

use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.

the class TestFinalPrimitiveFieldIsNotAddedToCluster method test.

/**
 * As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
 * of static fields in the target class, the purpose of this test case is to
 * check that the TestClusterGenerator indeed does not include these fields.
 *
 * @throws ClassNotFoundException
 * @throws RuntimeException
 */
@Test
public void test() throws ClassNotFoundException, RuntimeException {
    Properties.TARGET_CLASS = FinalPrimitiveField.class.getCanonicalName();
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
    InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
    TestClusterGenerator gen = new TestClusterGenerator(tree);
    assertNotNull(gen);
    TestCluster cluster = TestCluster.getInstance();
    List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
    assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) FinalPrimitiveField(com.examples.with.different.packagename.clinit.FinalPrimitiveField) Test(org.junit.Test)

Example 2 with InheritanceTree

use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.

the class TestFinalReferenceFieldIsNotAddedToCluster method test.

/**
 * As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
 * of static fields in the target class, the purpose of this test case is to
 * check that the TestClusterGenerator indeed does not include these fields.
 *
 * @throws ClassNotFoundException
 * @throws RuntimeException
 */
@Test
public void test() throws ClassNotFoundException, RuntimeException {
    Properties.TARGET_CLASS = FinalReferenceField.class.getCanonicalName();
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
    InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
    TestClusterGenerator gen = new TestClusterGenerator(tree);
    assertNotNull(gen);
    TestCluster cluster = TestCluster.getInstance();
    List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
    assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) FinalReferenceField(com.examples.with.different.packagename.clinit.FinalReferenceField) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) Test(org.junit.Test)

Example 3 with InheritanceTree

use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.

the class CheapPurityAnalyzer method isPureSuperclass.

private boolean isPureSuperclass(MethodEntry entry, Stack<MethodEntry> callStack) {
    InheritanceTree inheritanceTree = TestCluster.getInheritanceTree();
    for (String superClassName : inheritanceTree.getOrderedSuperclasses(entry.className)) {
        if (superClassName.equals(entry.className))
            continue;
        MethodEntry superEntry = new MethodEntry(superClassName, entry.methodName, entry.descriptor);
        if (!callStack.contains(superEntry) && methodsWithBodies.contains(superEntry)) {
            // We can conclude the purity of this method because
            // we found an implementation in a super class for it
            Stack<MethodEntry> newStack = new Stack<MethodEntry>();
            newStack.addAll(callStack);
            newStack.add(superEntry);
            boolean purityValueForSuperClass = isPure(superEntry, newStack);
            return purityValueForSuperClass;
        }
    }
    // to default purity value
    return DEFAULT_PURITY_VALUE;
}
Also used : InheritanceTree(org.evosuite.setup.InheritanceTree)

Example 4 with InheritanceTree

use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.

the class CheapPurityAnalyzer method checkAnyOverridingMethodImpure.

private boolean checkAnyOverridingMethodImpure(MethodEntry entry, Stack<MethodEntry> callStack) {
    InheritanceTree inheritanceTree = DependencyAnalysis.getInheritanceTree();
    String className = "" + entry.className;
    if (!inheritanceTree.hasClass(className)) {
        logger.warn(className + " was not found in the inheritance tree. Using DEFAULT value for cheap-purity analysis");
        return DEFAULT_PURITY_VALUE;
    }
    Set<String> subclasses = inheritanceTree.getSubclasses(className);
    for (String subclassName : subclasses) {
        if (!entry.className.equals(subclassName)) {
            MethodEntry subclassEntry = new MethodEntry(subclassName, entry.methodName, entry.descriptor);
            if (!callStack.contains(subclassEntry) && methodEntries.contains(subclassEntry)) {
                Stack<MethodEntry> newStack = new Stack<MethodEntry>();
                newStack.addAll(callStack);
                newStack.add(subclassEntry);
                if (!isPure(subclassEntry, newStack)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : InheritanceTree(org.evosuite.setup.InheritanceTree)

Example 5 with InheritanceTree

use of org.evosuite.setup.InheritanceTree in project evosuite by EvoSuite.

the class EvoSuite method generateInheritanceTree.

public static String generateInheritanceTree(String cp) throws IOException {
    LoggingUtils.getEvoLogger().info("* Analyzing classpath (generating inheritance tree)");
    List<String> cpList = Arrays.asList(cp.split(File.pathSeparator));
    // Clear current inheritance file to make sure a new one is generated
    Properties.INHERITANCE_FILE = "";
    InheritanceTree tree = InheritanceTreeGenerator.createFromClassPath(cpList);
    File outputFile = File.createTempFile("ES_inheritancetree", ".xml.gz");
    outputFile.deleteOnExit();
    InheritanceTreeGenerator.writeInheritanceTree(tree, outputFile);
    return outputFile.getAbsolutePath();
}
Also used : InheritanceTree(org.evosuite.setup.InheritanceTree) File(java.io.File)

Aggregations

InheritanceTree (org.evosuite.setup.InheritanceTree)5 TestCluster (org.evosuite.setup.TestCluster)2 TestClusterGenerator (org.evosuite.setup.TestClusterGenerator)2 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)2 Test (org.junit.Test)2 FinalPrimitiveField (com.examples.with.different.packagename.clinit.FinalPrimitiveField)1 FinalReferenceField (com.examples.with.different.packagename.clinit.FinalReferenceField)1 File (java.io.File)1