KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > stack > ComplexExpressionTest


1 package org.hanseltest.stack;
2
3
4 import junit.framework.TestCase;
5
6
7 public class ComplexExpressionTest extends TestCase {
8     /*private ClassLoaderRepository repository;
9     private JavaClass javaClass;
10     private Method[] methods;
11     private ConstantPoolGen cpg;
12
13     public void setUp() throws Exception {
14         repository = new ClassLoaderRepository(getClass().getClassLoader());
15         javaClass = repository.loadClass(Example.class.getName());
16         methods = javaClass.getMethods();
17         cpg = new ConstantPoolGen(javaClass.getConstantPool());
18     }
19
20     private ComplexOr getResultComplexOr(String methodName,
21                                          int relIndex) {
22         for (int i=0; i<methods.length; i++) {
23             if (methods[i].getName().equals(methodName)) {
24                 MethodGen methodGen = new MethodGen(methods[i], Example.class.getName(),
25                                                     cpg);
26                 InstructionList il = methodGen.getInstructionList();
27                 InstructionHandle ih = il.getEnd();
28                 for (int j=0; j<relIndex; j++) {
29                     ih = ih.getPrev();
30                 }
31
32                 StackFactory sf = new StackFactory(methodGen);
33                 sf.calculateMethodStacks();
34                 Hashtable stacks = sf.getResult();
35             
36                 return new ComplexOr(ih,
37                                      stacks,
38                                      il);
39             }
40         }
41
42         throw new IllegalArgumentException("Unknown method: " + methodName);
43     }*/

44
45     public void testSimple() {
46          throw new UnsupportedOperationException JavaDoc("Not yet converted");
47
48 // assertEquals("!a", getResultComplexOr("not", 4).getStackEntry().toString());
49
}
50 /*
51     public void testAnd() {
52         assertEquals("a && b", getResultComplexOr("and", 4).getStackEntry().toString());
53     }
54
55     public void testOr() {
56         assertEquals("a || b", getResultComplexOr("or", 4).getStackEntry().toString());
57     }
58
59     public void testComplexA() {
60         assertEquals("(a || b) && (c || d)", getResultComplexOr("complexA", 4).getStackEntry().toString());
61     }
62
63     public void testComplexB() {
64         assertEquals("a && b || c && d", getResultComplexOr("complexB", 4).getStackEntry().toString());
65     }
66
67     public void testlessThan() {
68         assertEquals("a < b && c", getResultComplexOr("lessThan", 4).getStackEntry().toString());
69     }
70
71     public static class Example {
72         boolean boolVar;
73
74         public void not(boolean a) {
75             boolVar = !a;
76         }
77
78         public void and(boolean a, boolean b) {
79             boolVar = a && b;
80         }
81
82         public void or(boolean a, boolean b) {
83             boolVar = a || b;
84         }
85
86         public void complexA(boolean a,
87                              boolean b,
88                              boolean c,
89                              boolean d) {
90             boolVar = (a || b) && (c || d);
91         }
92
93         public void complexB(boolean a,
94                              boolean b,
95                              boolean c,
96                              boolean d) {
97             boolVar = (a && b) || (c && d);
98         }
99
100         public void lessThan(int a, int b, boolean c) {
101             boolVar = (a < b) && c;
102         }
103  
104     }
105  */

106 }
107
Popular Tags