org.evosuite.coverage.statement.StatementCoverageFactory Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
* contributors
*
* This file is part of EvoSuite.
*
* EvoSuite is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* EvoSuite is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with EvoSuite. If not, see .
*/
package org.evosuite.coverage.statement;
import java.util.ArrayList;
import java.util.List;
import org.evosuite.Properties;
import org.evosuite.TestGenerationContext;
import org.evosuite.coverage.MethodNameMatcher;
import org.evosuite.graphs.cfg.BytecodeInstruction;
import org.evosuite.graphs.cfg.BytecodeInstructionPool;
import org.evosuite.testsuite.AbstractFitnessFactory;
public class StatementCoverageFactory extends
AbstractFitnessFactory {
private static boolean called = false;
private static List goals = new ArrayList();
/** {@inheritDoc} */
@Override
public List getCoverageGoals() {
if (!called)
computeGoals();
return goals;
}
private static void computeGoals() {
if (called)
return;
long start = System.currentTimeMillis();
String targetClass = Properties.TARGET_CLASS;
final MethodNameMatcher matcher = new MethodNameMatcher();
for (String className : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
if (!(targetClass.equals("") || className.endsWith(targetClass)))
continue;
for (String methodName : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownMethods(className)) {
if (!matcher.methodMatches(methodName))
continue;
for (BytecodeInstruction ins : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getInstructionsIn(className,
methodName))
if (isUsable(ins))
goals.add(new StatementCoverageTestFitness(ins));
}
}
long end = System.currentTimeMillis();
goalComputationTime = end - start;
called = true;
}
private static boolean isUsable(BytecodeInstruction ins) {
return !ins.isLabel() && !ins.isLineNumber();
}
/**
*
* retrieveCoverageGoals
*
*
* @return a {@link java.util.List} object.
*/
public static List retrieveCoverageGoals() {
if (!called)
computeGoals();
return goals;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy