001: package org.hanseltest.stack;
002:
003: import junit.framework.TestCase;
004:
005: public class ComplexExpressionTest extends TestCase {
006: /*private ClassLoaderRepository repository;
007: private JavaClass javaClass;
008: private Method[] methods;
009: private ConstantPoolGen cpg;
010:
011: public void setUp() throws Exception {
012: repository = new ClassLoaderRepository(getClass().getClassLoader());
013: javaClass = repository.loadClass(Example.class.getName());
014: methods = javaClass.getMethods();
015: cpg = new ConstantPoolGen(javaClass.getConstantPool());
016: }
017:
018: private ComplexOr getResultComplexOr(String methodName,
019: int relIndex) {
020: for (int i=0; i<methods.length; i++) {
021: if (methods[i].getName().equals(methodName)) {
022: MethodGen methodGen = new MethodGen(methods[i], Example.class.getName(),
023: cpg);
024: InstructionList il = methodGen.getInstructionList();
025: InstructionHandle ih = il.getEnd();
026: for (int j=0; j<relIndex; j++) {
027: ih = ih.getPrev();
028: }
029:
030: StackFactory sf = new StackFactory(methodGen);
031: sf.calculateMethodStacks();
032: Hashtable stacks = sf.getResult();
033:
034: return new ComplexOr(ih,
035: stacks,
036: il);
037: }
038: }
039:
040: throw new IllegalArgumentException("Unknown method: " + methodName);
041: }*/
042:
043: public void testSimple() {
044: throw new UnsupportedOperationException("Not yet converted");
045:
046: // assertEquals("!a", getResultComplexOr("not", 4).getStackEntry().toString());
047: }
048: /*
049: public void testAnd() {
050: assertEquals("a && b", getResultComplexOr("and", 4).getStackEntry().toString());
051: }
052:
053: public void testOr() {
054: assertEquals("a || b", getResultComplexOr("or", 4).getStackEntry().toString());
055: }
056:
057: public void testComplexA() {
058: assertEquals("(a || b) && (c || d)", getResultComplexOr("complexA", 4).getStackEntry().toString());
059: }
060:
061: public void testComplexB() {
062: assertEquals("a && b || c && d", getResultComplexOr("complexB", 4).getStackEntry().toString());
063: }
064:
065: public void testlessThan() {
066: assertEquals("a < b && c", getResultComplexOr("lessThan", 4).getStackEntry().toString());
067: }
068:
069: public static class Example {
070: boolean boolVar;
071:
072: public void not(boolean a) {
073: boolVar = !a;
074: }
075:
076: public void and(boolean a, boolean b) {
077: boolVar = a && b;
078: }
079:
080: public void or(boolean a, boolean b) {
081: boolVar = a || b;
082: }
083:
084: public void complexA(boolean a,
085: boolean b,
086: boolean c,
087: boolean d) {
088: boolVar = (a || b) && (c || d);
089: }
090:
091: public void complexB(boolean a,
092: boolean b,
093: boolean c,
094: boolean d) {
095: boolVar = (a && b) || (c && d);
096: }
097:
098: public void lessThan(int a, int b, boolean c) {
099: boolVar = (a < b) && c;
100: }
101:
102: }
103: */
104: }
|