diff --git a/README-Grupo4.txt b/README-Grupo4.txt new file mode 100644 index 0000000..34f0408 --- /dev/null +++ b/README-Grupo4.txt @@ -0,0 +1,25 @@ +Readme + +Localização dos arquivos: +Seguimos os paths originais, ou seja, + os testes estão em src-tests(rwsets.database, rwsets.cqueue, rwsets.forest e rwsets.pgproj), + os jars estão em example-apps(database.jar, cqueue.jar, forest.jar e pgproj.jar) e + as fontes estão em example-apps/src, em pastas com os mesmos nomes dos jars. + +---------------------------------------------------- +Testes: + Nossos testes se encontram no AllTestsGrupo4 + +#### known-bug #####################################################33 +-Ao rodar os testes no pgproj encontramos uma possível falha no rwsets. + +No primeiro teste(test0), o JUnit retorna um NullPointerException + -Para analisar este erro adicionamos um System.out + na linha 318 do arquivo src/depend/MethodDependencyAnalysis.java + ->System.out.println(fr.getDeclaringClass()); + -Esse System.out visa retornar o nome da classe que será passado para a chamada onde está ocorrendo a exceção. + -Com vários testes diferentes percebemos que a execução sempre para quando o rwsets tenta encontrar a classe Ponto dentro de projpg. + +Fizemos então um segundo teste (test1) que, ao ser rodado, evidencia o erro com um RuntimeException decorrente de não conseguir encontrar a classe. + -O erro não deveria ocorrer pois a classe Lprojpg/Ponto existe. + (apesar de termos usado pgproj no nome das pastas, o nome da package do projeto é projpg) diff --git a/example-apps/cqueue.jar b/example-apps/cqueue.jar new file mode 100644 index 0000000..f4a9cd5 Binary files /dev/null and b/example-apps/cqueue.jar differ diff --git a/example-apps/database.jar b/example-apps/database.jar new file mode 100644 index 0000000..9c64b74 Binary files /dev/null and b/example-apps/database.jar differ diff --git a/example-apps/forest.jar b/example-apps/forest.jar new file mode 100644 index 0000000..d870d82 Binary files /dev/null and b/example-apps/forest.jar differ diff --git a/example-apps/pgproj.jar b/example-apps/pgproj.jar new file mode 100644 index 0000000..ee10d2b Binary files /dev/null and b/example-apps/pgproj.jar differ diff --git a/src-tests/rwsets/AllTestsGrupo4.java b/src-tests/rwsets/AllTestsGrupo4.java new file mode 100644 index 0000000..5b3186b --- /dev/null +++ b/src-tests/rwsets/AllTestsGrupo4.java @@ -0,0 +1,17 @@ +package rwsets; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + + rwsets.database.TestDatabase.class, + rwsets.cqueue.TestCqueue.class, + rwsets.forest.TestForest.class, + rwsets.pgproj.TestPgproj.class + +}) + + +public class AllTestsGrupo4 {} diff --git a/src-tests/rwsets/cqueue/TestCqueue.java b/src-tests/rwsets/cqueue/TestCqueue.java new file mode 100644 index 0000000..9c8a914 --- /dev/null +++ b/src-tests/rwsets/cqueue/TestCqueue.java @@ -0,0 +1,76 @@ +package rwsets.cqueue; + + +import japa.parser.ParseException; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import org.junit.Assert; +import org.junit.Test; + +import rwsets.Helper; + +import com.ibm.wala.classLoader.IClass; +import com.ibm.wala.classLoader.IMethod; +import com.ibm.wala.shrikeCT.InvalidClassFileException; +import com.ibm.wala.util.CancelException; +import com.ibm.wala.util.WalaException; +import com.ibm.wala.util.io.CommandLine; +import com.ibm.wala.util.warnings.Warnings; + +import depend.MethodDependencyAnalysis; +import depend.util.Util; +import depend.util.graph.SimpleGraph; + +public class TestCqueue { + + String USER_DIR = System.getProperty("user.dir"); + String SEP = System.getProperty("file.separator"); + String EXAMPLES = USER_DIR + SEP + "example-apps"; + String TEST_DIR = USER_DIR + SEP + "src-tests"; + String EXAMPLES_SRC = EXAMPLES + SEP + "src"; + String EXAMPLES_JAR = EXAMPLES; + String RESOURCES_DIR = USER_DIR + SEP + "dat"; + String cqueuejar = EXAMPLES_JAR + SEP + "cqueue.jar"; + + @Test + public void testPopDependency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "cqueue/Pile.java"; + //filter vê se tem este nome na package + String filter = "comp2"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(cqueuejar)).exists()); + + //line e de onde a análise e iniciada + String line = "if(this.next == null) return new Pile();"; + SimpleGraph sg = depend.Main.analyze(cqueuejar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/cqueue/TestCqueue.testpop.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + + @Test + public void testPushbackDependency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + + String strCompUnit = EXAMPLES_SRC + SEP + "cqueue/Queue.java"; + //filter vê se tem este nome na package + String filter = "comp2"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(cqueuejar)).exists()); + + //line e de onde a análise e iniciada + String line = "if (this.n == -1) {"; + SimpleGraph sg = depend.Main.analyze(cqueuejar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/cqueue/TestCqueue.testqueue.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + + } + +} diff --git a/src-tests/rwsets/cqueue/TestCqueue.testpop.data b/src-tests/rwsets/cqueue/TestCqueue.testpop.data new file mode 100644 index 0000000..55cc7de --- /dev/null +++ b/src-tests/rwsets/cqueue/TestCqueue.testpop.data @@ -0,0 +1,10 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"comp2/Pile comp2/Pile.pop()"[color="red", fontsize="6", fontname="Arial"]; +"comp2/Pile comp2/Pile.push(int)" -> "comp2/Pile comp2/Pile.pop()" [label="comp2/Pile comp2/Pile.next : 20" ] +"void comp2/Pile.()" -> "comp2/Pile comp2/Pile.pop()" [label="comp2/Pile comp2/Pile.next : 10" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/cqueue/TestCqueue.testqueue.data b/src-tests/rwsets/cqueue/TestCqueue.testqueue.data new file mode 100644 index 0000000..5e1087b --- /dev/null +++ b/src-tests/rwsets/cqueue/TestCqueue.testqueue.data @@ -0,0 +1,15 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"comp2/Queue comp2/Queue.pushback(int)"[color="red", fontsize="6", fontname="Arial"]; +"comp2/Queue comp2/Queue.pop()" -> "comp2/Queue comp2/Queue.pushback(int)" [label="comp2/Queue comp2/Queue.last : 35" ] +"comp2/Queue comp2/Queue.pushback(int)" -> "comp2/Queue comp2/Queue.pushback(int)" [label="comp2/Queue comp2/Queue.last : 18" ] +"comp2/Queue comp2/Queue.pushback(int)" -> "comp2/Queue comp2/Queue.pushback(int)" [label="comp2/Queue comp2/Queue.last : 24" ] +"comp2/Queue comp2/Queue.pushback(int)" -> "comp2/Queue comp2/Queue.pushback(int)" [label="int comp2/Queue.n : 17" ] +"comp2/Queue comp2/Queue.pushback(int)" -> "comp2/Queue comp2/Queue.pushback(int)" [label="int comp2/Queue.n : 22" ] +"void comp2/Queue.()" -> "comp2/Queue comp2/Queue.pushback(int)" [label="comp2/Queue comp2/Queue.last : 12" ] +"void comp2/Queue.()" -> "comp2/Queue comp2/Queue.pushback(int)" [label="int comp2/Queue.n : 10" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/database/TestDatabase.java b/src-tests/rwsets/database/TestDatabase.java new file mode 100644 index 0000000..f59ecba --- /dev/null +++ b/src-tests/rwsets/database/TestDatabase.java @@ -0,0 +1,130 @@ +package rwsets.database; + + + +import japa.parser.ParseException; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import org.junit.Assert; +import org.junit.Test; + +import rwsets.Helper; + +import com.ibm.wala.classLoader.IClass; +import com.ibm.wala.classLoader.IMethod; +import com.ibm.wala.shrikeCT.InvalidClassFileException; +import com.ibm.wala.util.CancelException; +import com.ibm.wala.util.WalaException; +import com.ibm.wala.util.io.CommandLine; +import com.ibm.wala.util.warnings.Warnings; + +import depend.MethodDependencyAnalysis; +import depend.util.Util; +import depend.util.graph.SimpleGraph; + +public class TestDatabase { + + String USER_DIR = System.getProperty("user.dir"); + String SEP = System.getProperty("file.separator"); + String EXAMPLES = USER_DIR + SEP + "example-apps"; + String TEST_DIR = USER_DIR + SEP + "src-tests"; + String EXAMPLES_SRC = EXAMPLES + SEP + "src"; + String EXAMPLES_JAR = EXAMPLES; + String RESOURCES_DIR = USER_DIR + SEP + "dat"; + String databasejar = EXAMPLES_JAR + SEP + "database.jar"; + + @Test + public void testAddDependency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "database/RepFunc.java"; + + //filter vê se tem este nome na package + String filter = "comp"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(databasejar)).exists()); + + //line e de onde a análise e iniciada + String line = " if (repList.insertCheck(repList, f)) {"; + SimpleGraph sg = depend.Main.analyze(databasejar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/database/TestDatabase.testAdd.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + + @Test + public void testAnalysisWithLineContents() throws Exception { + String strCompUnit = EXAMPLES_SRC + SEP + "database/RepFunc.java"; + String exclusionFile = RESOURCES_DIR + SEP + "ExclusionAllJava.txt"; + String exclusionFileForCallGraph = RESOURCES_DIR + SEP + "ExclusionForCallGraph.txt"; + String databasejar = EXAMPLES_JAR + SEP + "database.jar"; + String targetClass = "Lcomp/RepFunc"; + String targetMethod = "addFuncRepLista(Lcomp/Funcionario;)Z"; + + // checks + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(exclusionFile)).exists()); + Assert.assertTrue((new File(exclusionFileForCallGraph)).exists()); + Assert.assertTrue((new File(databasejar)).exists()); + + + String[] args = new String[] { + "-appJar=" + databasejar, + "-printWalaWarnings=" + false, + "-exclusionFile=" + exclusionFile, + "-exclusionFileForCallGraph=" + exclusionFileForCallGraph, + "-dotPath=" + "/usr/bin/dot", + "-appPrefix=" + "comp", + "-listAppClasses=" + false, + "-listAllClasses=" + false, + "-listAppMethods=" + false, + "-genCallGraph=" + false, + "-measureTime=" + false, + "-reportType=" + "list", + "-targetClass=" + targetClass, + "-targetMethod=" + targetMethod, + "-targetLine=33"}; + + // reading and saving command-line properties + Properties p = CommandLine.parse(args); + Util.setProperties(p); + + // clearing warnings from WALA + Warnings.clear(); + + MethodDependencyAnalysis mda = new MethodDependencyAnalysis(p); + + // find informed class + IClass clazz = depend.Main.findClass(mda); + // find informed method + IMethod method = depend.Main.findMethod(clazz); + SimpleGraph sg = depend.Main.run(mda, method); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/database/TestDatabase.testAnalysisWithLineContents.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toString()); + } + + @Test + public void testFSearchDepedency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "database/List.java"; + + //filter vê se tem este nome na package + String filter = "comp"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(databasejar)).exists()); + + //line e de onde a análise e iniciada + String line = " if (lista == null || lista.func == null) {"; + SimpleGraph sg = depend.Main.analyze(databasejar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/database/TestDatabase.testFSearch.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + + +} diff --git a/src-tests/rwsets/database/TestDatabase.testAdd.data b/src-tests/rwsets/database/TestDatabase.testAdd.data new file mode 100644 index 0000000..afb32d5 --- /dev/null +++ b/src-tests/rwsets/database/TestDatabase.testAdd.data @@ -0,0 +1,27 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)"[color="red", fontsize="6", fontname="Arial"]; +"boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 34" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 23" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 26" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 29" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/Funcionario comp/List.func : 23" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/Funcionario comp/List.func : 26" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/List comp/List.next : 29" ] +"comp/List comp/List.remove(comp/List,java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 42" ] +"comp/List comp/List.remove(comp/List,java/lang/String)" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/List comp/List.next : 42" ] +"void comp/Funcionario.(java/lang/String,java/lang/String,java/lang/String,int)" -> "boolean comp/List.insertCheck(comp/List,comp/Funcionario)" [label="java/lang/String comp/Funcionario.cpf : 11" ] +"void comp/Funcionario.(java/lang/String,java/lang/String,java/lang/String,int)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 11" ] +"void comp/Funcionario.setCpf(java/lang/String)" -> "boolean comp/List.insertCheck(comp/List,comp/Funcionario)" [label="java/lang/String comp/Funcionario.cpf : 41" ] +"void comp/Funcionario.setCpf(java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 41" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 9" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 10" ] +"void comp/List.()" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/Funcionario comp/List.func : 9" ] +"void comp/List.()" -> "comp/List comp/List.insert(comp/List,comp/Funcionario)" [label="comp/List comp/List.next : 10" ] +"void comp/RepFunc.()" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 10" ] +"void comp/RepFunc.removeFuncRepLista(java/lang/String)" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 51" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/database/TestDatabase.testAnalysisWithLineContents.data b/src-tests/rwsets/database/TestDatabase.testAnalysisWithLineContents.data new file mode 100644 index 0000000..800d80d --- /dev/null +++ b/src-tests/rwsets/database/TestDatabase.testAnalysisWithLineContents.data @@ -0,0 +1,13 @@ +"boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 34" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 23" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 26" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 29" ] +"comp/List comp/List.remove(comp/List,java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 42" ] +"void comp/Funcionario.(java/lang/String,java/lang/String,java/lang/String,int)" -> "boolean comp/List.insertCheck(comp/List,comp/Funcionario)" [label="java/lang/String comp/Funcionario.cpf : 11" ] +"void comp/Funcionario.(java/lang/String,java/lang/String,java/lang/String,int)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 11" ] +"void comp/Funcionario.setCpf(java/lang/String)" -> "boolean comp/List.insertCheck(comp/List,comp/Funcionario)" [label="java/lang/String comp/Funcionario.cpf : 41" ] +"void comp/Funcionario.setCpf(java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 41" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 9" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 10" ] +"void comp/RepFunc.()" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 10" ] +"void comp/RepFunc.removeFuncRepLista(java/lang/String)" -> "boolean comp/RepFunc.addFuncRepLista(comp/Funcionario)" [label="comp/List comp/RepFunc.repList : 51" ] \ No newline at end of file diff --git a/src-tests/rwsets/database/TestDatabase.testFSearch.data b/src-tests/rwsets/database/TestDatabase.testFSearch.data new file mode 100644 index 0000000..16e50c1 --- /dev/null +++ b/src-tests/rwsets/database/TestDatabase.testFSearch.data @@ -0,0 +1,16 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"comp/Funcionario comp/List.search(comp/List,java/lang/String)"[color="red", fontsize="6", fontname="Arial"]; +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 23" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 26" ] +"comp/List comp/List.insert(comp/List,comp/Funcionario)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 29" ] +"comp/List comp/List.remove(comp/List,java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 42" ] +"void comp/Funcionario.(java/lang/String,java/lang/String,java/lang/String,int)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 11" ] +"void comp/Funcionario.setCpf(java/lang/String)" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="java/lang/String comp/Funcionario.cpf : 41" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/Funcionario comp/List.func : 9" ] +"void comp/List.()" -> "comp/Funcionario comp/List.search(comp/List,java/lang/String)" [label="comp/List comp/List.next : 10" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/forest/TestForest.java b/src-tests/rwsets/forest/TestForest.java new file mode 100644 index 0000000..c02ed9c --- /dev/null +++ b/src-tests/rwsets/forest/TestForest.java @@ -0,0 +1,129 @@ +package rwsets.forest; + +import japa.parser.ParseException; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import org.junit.Assert; +import org.junit.Test; + +import rwsets.Helper; + +import com.ibm.wala.classLoader.IClass; +import com.ibm.wala.classLoader.IMethod; +import com.ibm.wala.shrikeCT.InvalidClassFileException; +import com.ibm.wala.util.CancelException; +import com.ibm.wala.util.WalaException; +import com.ibm.wala.util.io.CommandLine; +import com.ibm.wala.util.warnings.Warnings; + +import depend.MethodDependencyAnalysis; +import depend.util.Util; +import depend.util.graph.SimpleGraph; + + +public class TestForest { + + String USER_DIR = System.getProperty("user.dir"); + String SEP = System.getProperty("file.separator"); + String EXAMPLES = USER_DIR + SEP + "example-apps"; + String TEST_DIR = USER_DIR + SEP + "src-tests"; + String EXAMPLES_SRC = EXAMPLES + SEP + "src"; + String EXAMPLES_JAR = EXAMPLES; + String RESOURCES_DIR = USER_DIR + SEP + "dat"; + String forestjar = EXAMPLES_JAR + SEP + "forest.jar"; + + @Test + public void testPrintDepedency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "forest/Bst.java"; + + //filter vê se tem este nome na package + String filter = "comp3"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(forestjar)).exists()); + + //line e de onde a análise e iniciada + String line = "if (node.left != null) printInOrder(node.left);"; + SimpleGraph sg = depend.Main.analyze(forestjar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/forest/TestForest.testPrint.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + + + @Test + public void testPrintWithLineContents() throws Exception { + String strCompUnit = EXAMPLES_SRC + SEP + "forest/Bst.java"; + String exclusionFile = RESOURCES_DIR + SEP + "ExclusionAllJava.txt"; + String exclusionFileForCallGraph = RESOURCES_DIR + SEP + "ExclusionForCallGraph.txt"; + String targetClass = "Lcomp3/Bst"; + String targetMethod = "printInOrder(Lcomp3/Bst;)V"; + + // checks + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(exclusionFile)).exists()); + Assert.assertTrue((new File(exclusionFileForCallGraph)).exists()); + Assert.assertTrue((new File(forestjar)).exists()); + + + String[] args = new String[] { + "-appJar=" + forestjar, + "-printWalaWarnings=" + false, + "-exclusionFile=" + exclusionFile, + "-exclusionFileForCallGraph=" + exclusionFileForCallGraph, + "-dotPath=" + "/usr/bin/dot", + "-appPrefix=" + "comp3", + "-listAppClasses=" + false, + "-listAllClasses=" + false, + "-listAppMethods=" + false, + "-genCallGraph=" + false, + "-measureTime=" + false, + "-reportType=" + "list", + "-targetClass=" + targetClass, + "-targetMethod=" + targetMethod, + "-targetLine=75"}; + + // reading and saving command-line properties + Properties p = CommandLine.parse(args); + Util.setProperties(p); + + // clearing warnings from WALA + Warnings.clear(); + + MethodDependencyAnalysis mda = new MethodDependencyAnalysis(p); + + // find informed class + IClass clazz = depend.Main.findClass(mda); + // find informed method + IMethod method = depend.Main.findMethod(clazz); + SimpleGraph sg = depend.Main.run(mda, method); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/forest/TestForest.testPrintWithLineContents.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toString()); + } + + @Test + public void testSearchDepedency() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "forest/Bst.java"; + + //filter vê se tem este nome na package + String filter = "comp3"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(forestjar)).exists()); + + //line e de onde a análise e iniciada + //String line = " if (node == null) {"; + String line = "return search(node.left, n);"; + SimpleGraph sg = depend.Main.analyze(forestjar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/forest/TestForest.testSearch.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + +} diff --git a/src-tests/rwsets/forest/TestForest.testPrint.data b/src-tests/rwsets/forest/TestForest.testPrint.data new file mode 100644 index 0000000..2f69891 --- /dev/null +++ b/src-tests/rwsets/forest/TestForest.testPrint.data @@ -0,0 +1,23 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"void comp3/Bst.printInOrder(comp3/Bst)"[color="red", fontsize="6", fontname="Arial"]; +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 23" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 26" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 17" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 20" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 36" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 50" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 56" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 39" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 51" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 55" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 49" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 54" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 10" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 11" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 9" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/forest/TestForest.testPrintWithLineContents.data b/src-tests/rwsets/forest/TestForest.testPrintWithLineContents.data new file mode 100644 index 0000000..540963a --- /dev/null +++ b/src-tests/rwsets/forest/TestForest.testPrintWithLineContents.data @@ -0,0 +1,15 @@ +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 23" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 26" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 17" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 20" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 36" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 50" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 56" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 39" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 51" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 55" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 49" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 54" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.left : 10" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="comp3/Bst comp3/Bst.right : 11" ] +"void comp3/Bst.()" -> "void comp3/Bst.printInOrder(comp3/Bst)" [label="int comp3/Bst.n : 9" ] \ No newline at end of file diff --git a/src-tests/rwsets/forest/TestForest.testSearch.data b/src-tests/rwsets/forest/TestForest.testSearch.data new file mode 100644 index 0000000..4d2d1e9 --- /dev/null +++ b/src-tests/rwsets/forest/TestForest.testSearch.data @@ -0,0 +1,23 @@ +digraph "DirectedGraph" { + graph [concentrate = true]; + center=true; + fontsize=6; + node [ color=blue,shape="box"fontsize=6,fontcolor=black,fontname=Arial]; + edge [ color=black,fontsize=6,fontcolor=black,fontname=Arial]; +"boolean comp3/Bst.search(comp3/Bst,int)"[color="red", fontsize="6", fontname="Arial"]; +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.left : 23" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.right : 26" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="int comp3/Bst.n : 17" ] +"comp3/Bst comp3/Bst.insert(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="int comp3/Bst.n : 20" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.left : 36" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.left : 50" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.left : 56" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.right : 39" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.right : 51" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.right : 55" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="int comp3/Bst.n : 49" ] +"comp3/Bst comp3/Bst.remove(comp3/Bst,int)" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="int comp3/Bst.n : 54" ] +"void comp3/Bst.()" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.left : 10" ] +"void comp3/Bst.()" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="comp3/Bst comp3/Bst.right : 11" ] +"void comp3/Bst.()" -> "boolean comp3/Bst.search(comp3/Bst,int)" [label="int comp3/Bst.n : 9" ] +} \ No newline at end of file diff --git a/src-tests/rwsets/pgproj/TestPgProj.test0.data b/src-tests/rwsets/pgproj/TestPgProj.test0.data new file mode 100644 index 0000000..e69de29 diff --git a/src-tests/rwsets/pgproj/TestPgProj.test1.data b/src-tests/rwsets/pgproj/TestPgProj.test1.data new file mode 100644 index 0000000..e69de29 diff --git a/src-tests/rwsets/pgproj/TestPgproj.java b/src-tests/rwsets/pgproj/TestPgproj.java new file mode 100644 index 0000000..1d4cae5 --- /dev/null +++ b/src-tests/rwsets/pgproj/TestPgproj.java @@ -0,0 +1,87 @@ +package rwsets.pgproj; + + + + + + +import japa.parser.ParseException; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import java.util.Vector; + +import org.junit.Assert; +import org.junit.Test; + +import rwsets.Helper; + +import com.ibm.wala.classLoader.IClass; +import com.ibm.wala.classLoader.IMethod; +import com.ibm.wala.shrikeCT.InvalidClassFileException; +import com.ibm.wala.util.CancelException; +import com.ibm.wala.util.WalaException; +import com.ibm.wala.util.io.CommandLine; +import com.ibm.wala.util.warnings.Warnings; + +import depend.MethodDependencyAnalysis; +import depend.util.Util; +import depend.util.graph.SimpleGraph; + + +public class TestPgproj { + String USER_DIR = System.getProperty("user.dir"); + String SEP = System.getProperty("file.separator"); + String EXAMPLES = USER_DIR + SEP + "example-apps"; + String TEST_DIR = USER_DIR + SEP + "src-tests"; + String EXAMPLES_SRC = EXAMPLES + SEP + "src"; + String EXAMPLES_JAR = EXAMPLES; + String RESOURCES_DIR = USER_DIR + SEP + "dat"; + + //@Test(expected=NullPointerException.class) + @Test + public void test0() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "pgproj/AlgoritmoDeCasteljau.java"; + String pgprojjar = EXAMPLES_JAR + SEP + "pgproj.jar"; + //filter vê se tem este nome na package + String filter = "projpg"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(pgprojjar)).exists()); + + //line e de onde a análise e iniciada + String line = "this.pontosCasteljau.add((Ponto)pontos.get(0));"; + SimpleGraph sg = depend.Main.analyze(pgprojjar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/pgproj/TestPgProj.test0.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + //teste acima da erro por motivo desconhecido + + @Test + public void test1() throws IOException, WalaException, CancelException, ParseException, InvalidClassFileException { + + String strCompUnit = EXAMPLES_SRC + SEP + "pgproj/Ponto.java"; + String pgprojjar = EXAMPLES_JAR + SEP + "pgproj.jar"; + //filter vê se tem este nome na package + String filter = "projpg"; + + Assert.assertTrue((new File(strCompUnit)).exists()); + Assert.assertTrue((new File(pgprojjar)).exists()); + + //line e de onde a análise e iniciada + String line = "boolean colidiu = false;"; + SimpleGraph sg = depend.Main.analyze(pgprojjar, filter, strCompUnit, line); + + String expectedResultFile = TEST_DIR + SEP + "rwsets/pgproj/TestPgProj.test1.data"; + Assert.assertEquals(Helper.readFile(expectedResultFile), sg.toDotString()); + } + + + + + + +}