Commit 5e71bf05 authored by Carlos Galindo's avatar Carlos Galindo
Browse files

Testing: extract testing code and resources from library.

parent e17fc82d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
            <groupId>es.upv.mist.slicing</groupId>
            <artifactId>sdg-cli</artifactId>
            <version>1.3.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

+4 −24
Original line number Diff line number Diff line
@@ -8,11 +8,8 @@ import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.ConstructorDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.github.javaparser.utils.CodeGenerationUtils;
import es.upv.mist.slicing.arcs.Arc;
import es.upv.mist.slicing.arcs.cfg.ControlFlowArc;
import es.upv.mist.slicing.cli.DOTAttributes;
import es.upv.mist.slicing.cli.GraphLog;
import es.upv.mist.slicing.graphs.CallGraph;
import es.upv.mist.slicing.graphs.ClassGraph;
import es.upv.mist.slicing.graphs.Graph;
@@ -30,7 +27,6 @@ import es.upv.mist.slicing.utils.StaticTypeSolver;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

import static es.upv.mist.slicing.util.SingletonCollector.toSingleton;
@@ -39,18 +35,11 @@ public class I_ACFG extends Graph {

    protected static final Map<CallableDeclaration<?>, CFG> acfgMap = ASTUtils.newIdentityHashMap();
    protected CallGraph callGraph;
    protected boolean built = false;

    public static void main(String[] args) throws IOException {
        String ruta = "/src/main/java/es/upv/mist/slicing/tests/";
        String fichero = "Test.java";

        I_ACFG iAcfg = new I_ACFG();
        iAcfg.generarACFG(ruta, fichero);
    }

    public void generarACFG(String ruta, String fichero) throws IOException {
    public void build(File file) {
        if (built) return;
        NodeList<CompilationUnit> units = new NodeList<>();
        File file = new File(CodeGenerationUtils.mavenModuleRoot(I_ACFG.class)+ruta+fichero);

        StaticJavaParser.getConfiguration().setAttributeComments(false);
        StaticTypeSolver.addTypeSolverJRE();
@@ -68,16 +57,7 @@ public class I_ACFG extends Graph {
        copyACFGs();
        expandCalls();
        joinACFGs();
        new GraphLog<>(this) {
            @Override
            protected DOTAttributes edgeAttributes(Arc arc) {
                DOTAttributes att = super.edgeAttributes(arc);
                if (arc.isNonExecutableControlFlowArc())
                    att.add("style", "dashed");
                return att;
            }
        }.generateImages("migrafo");
        System.out.println("Grafo generado...");
        built = true;
    }

    protected void buildACFGs(NodeList<CompilationUnit> nodeList) {
+28 −0
Original line number Diff line number Diff line
package es.upv.mist.slicing.graphs.icfg;

import es.upv.mist.slicing.I_ACFG;
import es.upv.mist.slicing.arcs.Arc;
import es.upv.mist.slicing.cli.DOTAttributes;
import es.upv.mist.slicing.cli.GraphLog;

import java.io.File;
import java.io.IOException;

public class IACFGTest {
    public static void main(String[] args) throws IOException {
        File file = new File(Thread.currentThread().getContextClassLoader().getResource("Test.java").getPath());

        I_ACFG icfg = new I_ACFG();
        icfg.build(file);
        new GraphLog<>(icfg) {
            @Override
            protected DOTAttributes edgeAttributes(Arc arc) {
                DOTAttributes att = super.edgeAttributes(arc);
                if (arc.isNonExecutableControlFlowArc())
                    att.add("style", "dashed");
                return att;
            }
        }.generateImages("migrafo");
        System.out.println("Grafo generado...");
    }
}
+0 −2
Original line number Diff line number Diff line
package es.upv.mist.slicing.tests;

public class Test {

	public static int z = 0;