/** * add public methods * @param className * @param methodName */ public void addPublicMethod(String className, String methodName) { publicMethods.add(new CallContext(ResourceList .getClassNameFromResourcePath(className), methodName)); }
public CallContext() { addJUnitExcludes(); List<Call> context = new ArrayList<Call>(); this.context=context; hcode = this.context.hashCode(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((branchGoal == null) ? 0 : branchGoal.hashCode()); result = prime * result + ((context == null) ? 0 : context.hashCode()); return result; }
addJUnitExcludes(); List<Call> context = new ArrayList<>(); while (startPos >= 0 && shouldSkipEntry(stackTrace.get(startPos).className)) { startPos--; while (endPos < stackTrace.size() && shouldSkipEntry(stackTrace.get(endPos).className)) { endPos++;
private double getPredicateDistance(Map<Integer, Map<CallContext, Double>> distanceMap) { if (!distanceMap.containsKey(branchGoal.getBranch().getActualBranchId())) { return Double.MAX_VALUE; } Map<CallContext, Double> distances = distanceMap.get(branchGoal.getBranch().getActualBranchId()); for (Entry<CallContext, Double> value : distances.entrySet()) { if (context.matches(value.getKey())) { return value.getValue(); } } return Double.MAX_VALUE; }
public String toStringContext() { return context.toString() + ":" + branchGoal; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CBranchTestFitness other = (CBranchTestFitness) obj; if (branchGoal == null) { if (other.branchGoal != null) return false; } else if (!branchGoal.equals(other.branchGoal)) return false; if (context == null) { if (other.context != null) return false; } else if (!context.equals(other.context)) return false; return true; }
@Override public List<IBranchTestFitness> getCoverageGoals() { //TODO this creates duplicate goals. Momentary fixed using a Set. Set<IBranchTestFitness> goals = new HashSet<IBranchTestFitness>(); // retrieve set of branches BranchCoverageFactory branchFactory = new BranchCoverageFactory(); List<BranchCoverageTestFitness> branchGoals = branchFactory.getCoverageGoalsForAllKnownClasses(); CallGraph callGraph = DependencyAnalysis.getCallGraph(); // try to find all occurrences of this branch in the call tree for (BranchCoverageTestFitness branchGoal : branchGoals) { logger.info("Adding context branches for " + branchGoal.toString()); for (CallContext context : callGraph.getAllContextsFromTargetClass(branchGoal.getClassName(), branchGoal.getMethod())) { //if is not possible to reach this branch from the target class, continue. if(context.isEmpty()) continue; goals.add(new IBranchTestFitness(branchGoal.getBranchGoal(), context)); } } assert(goals.size()>=branchFactory.getCoverageGoals().size()); logger.info("Created " + goals.size() + " goals"); return new ArrayList<IBranchTestFitness>(goals); } }
private void countGoals(List<IBranchTestFitness> branchGoals) { int totalGoals = branchGoals.size(); int goalsInTarget = 0; for (IBranchTestFitness g : branchGoals) { boolean flag = true; for (Call call : g.getContext().getContext()) { if (!call.getClassName().equals(Properties.TARGET_CLASS)) { flag = false; break; } } if (flag) goalsInTarget++; } ClientServices.getInstance().getClientNode() .trackOutputVariable(RuntimeVariable.IBranchInitialGoals, totalGoals); ClientServices .getInstance() .getClientNode() .trackOutputVariable(RuntimeVariable.IBranchInitialGoalsInTargetClass, goalsInTarget); }
addJUnitExcludes(); while (startPos >= 0 && shouldSkipEntry(stackTrace[startPos].getClassName())) { startPos--; while (endPos < stackTrace.length && shouldSkipEntry(stackTrace[endPos].getClassName())) { endPos++;
private double getPredicateDistance(Map<Integer, Map<CallContext, Double>> distanceMap) { if (!distanceMap.containsKey(branchGoal.getBranch().getActualBranchId())) { return Double.MAX_VALUE; } Map<CallContext, Double> distances = distanceMap.get(branchGoal.getBranch().getActualBranchId()); for (Entry<CallContext, Double> value : distances.entrySet()) { if (context.matches(value.getKey())) { return value.getValue(); } } return Double.MAX_VALUE; }
@Override public String toString() { return "Branch " + branchGoal + " in context: " + context.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; IBranchTestFitness other = (IBranchTestFitness) obj; if (branchGoal == null) { if (other.branchGoal != null) return false; } else if (!branchGoal.equals(other.branchGoal)) return false; if (context == null) { if (other.context != null) return false; } else if (!context.equals(other.context)) return false; return true; }
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); }
private double getMethodCallDistance(ExecutionResult result) { String key = branchGoal.getClassName() + "." + branchGoal.getMethodName(); if (!result.getTrace().getMethodContextCount().containsKey(key)) { return Double.MAX_VALUE; } for (Entry<CallContext, Integer> value : result.getTrace().getMethodContextCount().get(key).entrySet()) { if (context.matches(value.getKey())) { return value.getValue() > 0 ? 0.0 : 1.0; } } return Double.MAX_VALUE; }
public int getGenericContextBranchIdentifier(){ final int prime = 31; int result = 1; result = prime * result + (branchGoal == null ? 0 : branchGoal.hashCodeWithoutValue()); result = prime * result + (context == null ? 0 : context.hashCode()); return result; }
@Override public String toString() { return "Branch " + branchGoal + " in context: " + context.toString(); }
public CallContext(Collection<Call> contextt) { addJUnitExcludes(); List<Call> context = new ArrayList<Call>(); context.addAll(contextt); this.context=context; hcode = this.context.hashCode(); }
/** * @param className * @param methodName * @param caller */ private void updateMethodContextMaps(String className, String methodName, Object caller) { String id = className + "." + methodName; if (!coveredMethodContext.containsKey(id)) { coveredMethodContext.put(id, new HashMap<>()); } // CallContext context = new CallContext(new Throwable().getStackTrace()); CallContext context = new CallContext(stack); if (!coveredMethodContext.get(id).containsKey(context)) { coveredMethodContext.get(id).put(context, 1); } else { coveredMethodContext.get(id).put(context, coveredMethodContext.get(id).get(context) + 1); } }