1- import de .upb .soot .diff .DiffSootMethod ;
1+ import de .upb .soot .diff .SootMethodDiffBuilder ;
2+ import java .util .Collections ;
23import org .apache .commons .lang3 .builder .DiffResult ;
4+ import org .apache .commons .lang3 .builder .ToStringStyle ;
35import org .junit .Assert ;
46import org .junit .Test ;
57import soot .G ;
68import soot .Local ;
7- import soot .NullType ;
89import soot .Scene ;
910import soot .SootClass ;
1011import soot .SootMethod ;
1314import soot .jimple .Jimple ;
1415import soot .jimple .JimpleBody ;
1516import soot .jimple .NullConstant ;
16- import soot .jimple .ReturnStmt ;
1717import soot .jimple .ReturnVoidStmt ;
1818
19- import java .util .Collections ;
20- import java .util .Locale ;
21-
2219/** @author Andreas Dann created on 06.12.18 */
2320public class SootMethodDiffTest {
2421
@@ -33,7 +30,8 @@ public void simpleMethod() {
3330
3431 SootMethod lhsMethod = new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
3532
36- DiffResult res = new DiffSootMethod (lhsMethod ).diff (new DiffSootMethod (lhsMethod ));
33+ DiffResult res =
34+ new SootMethodDiffBuilder (lhsMethod , lhsMethod , ToStringStyle .JSON_STYLE ).build ();
3735 Assert .assertNotNull (res );
3836 Assert .assertEquals (0 , res .getNumberOfDiffs ());
3937 }
@@ -52,7 +50,8 @@ public void simpleMethod2() {
5250 SootMethod rhsMethod =
5351 new SootMethod ("foo" , Collections .singletonList (objectClass .getType ()), VoidType .v ());
5452
55- DiffResult res = new DiffSootMethod (lhsMethod ).diff (new DiffSootMethod (rhsMethod ));
53+ DiffResult res =
54+ new SootMethodDiffBuilder (lhsMethod , rhsMethod , ToStringStyle .JSON_STYLE ).build ();
5655 Assert .assertNotNull (res );
5756 Assert .assertEquals (1 , res .getNumberOfDiffs ());
5857 System .out .println (res .toString ());
@@ -77,12 +76,12 @@ public void simpleMethodBody() {
7776 jimpleBody .setMethod (lhsMethod );
7877 lhsMethod .setActiveBody (jimpleBody );
7978
80- SootMethod rhsMethod =
81- new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
79+ SootMethod rhsMethod = new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
8280
83- DiffResult res = new DiffSootMethod (lhsMethod ).diff (new DiffSootMethod (rhsMethod ));
81+ DiffResult res =
82+ new SootMethodDiffBuilder (lhsMethod , lhsMethod , ToStringStyle .JSON_STYLE ).build ();
8483 Assert .assertNotNull (res );
85- Assert .assertEquals (1 , res .getNumberOfDiffs ());
84+ Assert .assertEquals (0 , res .getNumberOfDiffs ());
8685 System .out .println (res .toString ());
8786 }
8887
@@ -105,9 +104,7 @@ public void simpleMethodBody2() {
105104 jimpleBody .setMethod (lhsMethod );
106105 lhsMethod .setActiveBody (jimpleBody );
107106
108- SootMethod rhsMethod =
109- new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
110-
107+ SootMethod rhsMethod = new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
111108
112109 JimpleBody jimpleBody2 = new JimpleBody ();
113110
@@ -117,55 +114,53 @@ public void simpleMethodBody2() {
117114 jimpleBody2 .setMethod (rhsMethod );
118115 rhsMethod .setActiveBody (jimpleBody2 );
119116
120- DiffResult res = new DiffSootMethod (lhsMethod ).diff (new DiffSootMethod (rhsMethod ));
117+ DiffResult res =
118+ new SootMethodDiffBuilder (lhsMethod , rhsMethod , ToStringStyle .JSON_STYLE ).build ();
121119 Assert .assertNotNull (res );
122120 Assert .assertEquals (0 , res .getNumberOfDiffs ());
123121 System .out .println (res .toString ());
124122 }
125123
124+ @ Test
125+ public void simpleMethodBody3 () {
126126
127- @ Test
128- public void simpleMethodBody3 () {
129-
130- G .reset ();
131-
132- Scene .v ().loadNecessaryClasses ();
133-
134- SootClass objectClass = Scene .v ().getObjectType ().getSootClass ();
127+ G .reset ();
135128
136- SootMethod lhsMethod = new SootMethod ( "foo" , Collections . emptyList (), VoidType . v () );
129+ Scene . v (). loadNecessaryClasses ( );
137130
138- JimpleBody jimpleBody = new JimpleBody ();
131+ SootClass objectClass = Scene . v (). getObjectType (). getSootClass ();
139132
140- ReturnVoidStmt returnVoidStmt = Jimple .v ().newReturnVoidStmt ();
141- jimpleBody .getUnits ().add (returnVoidStmt );
133+ SootMethod lhsMethod = new SootMethod ("foo" , Collections .emptyList (), VoidType .v ());
142134
143- jimpleBody .setMethod (lhsMethod );
144- lhsMethod .setActiveBody (jimpleBody );
135+ JimpleBody jimpleBody = new JimpleBody ();
145136
146- SootMethod rhsMethod =
147- new SootMethod ( "foo" , Collections . emptyList (), VoidType . v () );
137+ ReturnVoidStmt returnVoidStmt = Jimple . v (). newReturnVoidStmt ();
138+ jimpleBody . getUnits (). add ( returnVoidStmt );
148139
140+ jimpleBody .setMethod (lhsMethod );
141+ lhsMethod .setActiveBody (jimpleBody );
149142
150- JimpleBody jimpleBody2 = new JimpleBody ( );
143+ SootMethod rhsMethod = new SootMethod ( "foo" , Collections . emptyList (), VoidType . v () );
151144
145+ JimpleBody jimpleBody2 = new JimpleBody ();
152146
153- Local var1 = Jimple .v ().newLocal ("var1" , objectClass .getType ());
154- jimpleBody2 .getLocals ().add (var1 );
147+ Local var1 = Jimple .v ().newLocal ("var1" , objectClass .getType ());
148+ jimpleBody2 .getLocals ().add (var1 );
155149
156- AssignStmt assignStmt = Jimple .v ().newAssignStmt (var1 , NullConstant .v ());
150+ AssignStmt assignStmt = Jimple .v ().newAssignStmt (var1 , NullConstant .v ());
157151
158- jimpleBody2 .getUnits ().add (assignStmt );
152+ jimpleBody2 .getUnits ().add (assignStmt );
159153
160- ReturnVoidStmt returnVoidStmt2 = Jimple .v ().newReturnVoidStmt ();
161- jimpleBody2 .getUnits ().add (returnVoidStmt2 );
154+ ReturnVoidStmt returnVoidStmt2 = Jimple .v ().newReturnVoidStmt ();
155+ jimpleBody2 .getUnits ().add (returnVoidStmt2 );
162156
163- jimpleBody2 .setMethod (rhsMethod );
164- rhsMethod .setActiveBody (jimpleBody2 );
157+ jimpleBody2 .setMethod (rhsMethod );
158+ rhsMethod .setActiveBody (jimpleBody2 );
165159
166- DiffResult res = new DiffSootMethod (lhsMethod ).diff (new DiffSootMethod (rhsMethod ));
167- Assert .assertNotNull (res );
168- Assert .assertEquals (1 , res .getNumberOfDiffs ());
169- System .out .println (res .toString ());
170- }
160+ DiffResult res =
161+ new SootMethodDiffBuilder (lhsMethod , rhsMethod , ToStringStyle .JSON_STYLE ).build ();
162+ Assert .assertNotNull (res );
163+ Assert .assertEquals (1 , res .getNumberOfDiffs ());
164+ System .out .println (res .toString ());
165+ }
171166}
0 commit comments