forked from JavaTX/JavaCompilerCore
77 lines
2.0 KiB
Java
77 lines
2.0 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
package bytecode.simplifyalgo;
|
||
|
|
||
|
import static org.junit.Assert.*;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.HashSet;
|
||
|
|
||
|
import org.junit.BeforeClass;
|
||
|
import org.junit.Test;
|
||
|
import org.objectweb.asm.Type;
|
||
|
|
||
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||
|
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||
|
|
||
|
/**
|
||
|
* @author Fayez Abu Alia
|
||
|
*
|
||
|
*/
|
||
|
public class CycleTest {
|
||
|
|
||
|
private static TPHExtractor tphExtractor;
|
||
|
private static String methName;
|
||
|
|
||
|
/**
|
||
|
* @throws java.lang.Exception
|
||
|
*/
|
||
|
@BeforeClass
|
||
|
public static void setUpBeforeClass() throws Exception {
|
||
|
tphExtractor = new TPHExtractor();
|
||
|
// A < B
|
||
|
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
||
|
// B < C
|
||
|
TPHConstraint c2 = new ExtendsConstraint("B", "C", Relation.EXTENDS);
|
||
|
// C < D
|
||
|
TPHConstraint c3 = new ExtendsConstraint("C", "D", Relation.EXTENDS);
|
||
|
// D < A
|
||
|
TPHConstraint c4 = new ExtendsConstraint("D", "A", Relation.EXTENDS);
|
||
|
// name
|
||
|
methName = "m";
|
||
|
MethodAndTPH mtph = new MethodAndTPH("m");
|
||
|
mtph.getTphs().add("A");
|
||
|
mtph.getTphs().add("B");
|
||
|
mtph.getTphs().add("C");
|
||
|
mtph.getTphs().add("D");
|
||
|
tphExtractor.ListOfMethodsAndTph.add(mtph);
|
||
|
tphExtractor.allCons.add(c1);
|
||
|
tphExtractor.allCons.add(c2);
|
||
|
tphExtractor.allCons.add(c3);
|
||
|
tphExtractor.allCons.add(c4);
|
||
|
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void test() {
|
||
|
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||
|
HashSet<String> equals = new HashSet<>();
|
||
|
equals.add("A");
|
||
|
equals.add("B");
|
||
|
equals.add("C");
|
||
|
equals.add("D");
|
||
|
TPHConstraint k = new ExtendsConstraint("A", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||
|
result.put(k, equals);
|
||
|
|
||
|
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor);
|
||
|
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||
|
assertTrue(areEquals);
|
||
|
}
|
||
|
|
||
|
}
|