Search in sources :

Example 6 with CallContext

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

the class CallGraph method getMethodEntryPoint.

/**
 * computes and returns the call contexts of the specific method
 *
 * @param className
 * @param methodName
 * @return
 */
public Set<CallContext> getMethodEntryPoint(String className, String methodName) {
    Set<CallContext> contexts = new HashSet<>();
    List<Call> cont = new ArrayList<>();
    cont.add(new Call(className, methodName));
    CallContext context = new CallContext(cont);
    if (publicMethods.contains(context)) {
        contexts.add(context);
    } else {
        contexts.add(new CallContext());
    }
    return contexts;
}
Also used : Call(org.evosuite.setup.Call) ArrayList(java.util.ArrayList) CallContext(org.evosuite.setup.CallContext) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with CallContext

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

the class CallGraph method addPublicClassMethod.

private void addPublicClassMethod(String className, String methodName, Set<CallContext> contexts) {
    List<Call> calls = new ArrayList<>();
    Call call = new Call(className, methodName);
    calls.add(call);
    CallContext context = new CallContext(calls);
    if (publicMethods.contains(context) && className.equals(this.className))
        contexts.add(context);
}
Also used : Call(org.evosuite.setup.Call) ArrayList(java.util.ArrayList) CallContext(org.evosuite.setup.CallContext)

Example 8 with CallContext

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

the class CallGraph method convertIntoCallContext.

private Set<CallContext> convertIntoCallContext(Set<List<CallGraphEntry>> paths) {
    Set<CallContext> contexts = new HashSet<>();
    // return only context that starts from the class under test
    for (List<CallGraphEntry> list : paths) {
        boolean insert = false;
        List<Call> cont = new ArrayList<>();
        for (int i = list.size() - 1; i >= 0; i--) {
            if (!insert && list.get(i).getClassName().equals(className)) {
                insert = true;
            }
            if (insert)
                cont.add(new Call(list.get(i).getClassName(), list.get(i).getMethodName()));
        }
        contexts.add(new CallContext(cont));
    }
    return contexts;
}
Also used : Call(org.evosuite.setup.Call) ArrayList(java.util.ArrayList) CallContext(org.evosuite.setup.CallContext) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with CallContext

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

the class ExecutionTraceImpl method updateBranchContextMaps.

/**
 * @param branch
 * @param true_distance
 * @param false_distance
 */
private void updateBranchContextMaps(int branch, double true_distance, double false_distance) {
    if (!coveredPredicateContext.containsKey(branch)) {
        coveredPredicateContext.put(branch, new HashMap<>());
        coveredTrueContext.put(branch, new HashMap<>());
        coveredFalseContext.put(branch, new HashMap<>());
    }
    CallContext context = new CallContext(Thread.currentThread().getStackTrace());
    if (!coveredPredicateContext.get(branch).containsKey(context)) {
        coveredPredicateContext.get(branch).put(context, 1);
        coveredTrueContext.get(branch).put(context, true_distance);
        coveredFalseContext.get(branch).put(context, false_distance);
    } else {
        coveredPredicateContext.get(branch).put(context, coveredPredicateContext.get(branch).get(context) + 1);
        coveredTrueContext.get(branch).put(context, Math.min(coveredTrueContext.get(branch).get(context), true_distance));
        coveredFalseContext.get(branch).put(context, Math.min(coveredFalseContext.get(branch).get(context), false_distance));
    }
}
Also used : CallContext(org.evosuite.setup.CallContext)

Aggregations

CallContext (org.evosuite.setup.CallContext)9 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 Call (org.evosuite.setup.Call)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 BranchCoverageFactory (org.evosuite.coverage.branch.BranchCoverageFactory)2 BranchCoverageTestFitness (org.evosuite.coverage.branch.BranchCoverageTestFitness)2 CallGraph (org.evosuite.setup.callgraph.CallGraph)2 TestChromosome (org.evosuite.testcase.TestChromosome)2 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)2