KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanseltest > TestBugStackUnderflow


1 package org.hanseltest;
2
3
4 import junit.framework.TestCase;
5
6
7 /**
8  * Test cases for testing expressions on the stack.
9  *
10  * @author Niklas Mehner
11  */

12 public class TestBugStackUnderflow extends TestCase {
13     /** Methods of class org.hanseltest.TestBugStackUnderflow. */
14     //private Method[] methods;
15

16     /** Constant Pool of class org.hanseltest.TestBugStackUnderflow. */
17    // private ConstantPoolGen cpg;
18

19     /**
20      * Create a new Test.
21      * @param name Name of the test.
22      */

23     /*public TestBugStackUnderflow(String name) {
24         super(name);
25     } */

26
27     /**
28      * Setup the test.
29      * @throws Exception if loading the example class fails.
30      */

31    /* public void setUp() throws Exception {
32         ClassLoaderRepository repository =
33                 new ClassLoaderRepository(getClass().getClassLoader());
34         JavaClass javaClass =
35                 repository.loadClass("org.hanseltest.TestBugStackUnderflow");
36         methods = javaClass.getMethods();
37         cpg = new ConstantPoolGen(javaClass.getConstantPool());
38     }
39
40     /**
41      * Returns the method with the given name.
42      * @param name Name of the method.
43      * @return Method with name 'name'.
44      */

45    /* private MethodGen getMethod(String name) {
46         for (int i = 0; i < methods.length; i++) {
47             if (methods[i].getName().equals(name)) {
48                 return new MethodGen(methods[i],
49                                      "org.hanselexample.stack.StackExample",
50                                      cpg);
51             }
52         }
53
54         throw new IllegalStateException("Method not found.");
55     }
56
57     /**
58      * Tests for a stack underflow.
59      */

60     public void testUnderFlow() {
61         throw new UnsupportedOperationException JavaDoc("Not yet converted");
62       /* // this threw an StackUnderflowException
63         StackFactory sf = new StackFactory(getMethod("getIntArray"));
64         sf.calculateMethodStacks();
65        
66         // Stupid fix for eclipase warning:
67         inBuf = new byte[3];
68         getIntArray();*/

69     }
70
71     /** The byte array to convert.*/
72    // private byte[] inBuf;
73

74     /** The int array destination.*/
75    // private int[] outBuf;
76

77
78     /**
79      * Converts a byte array to an int array
80      *
81      * @return int[] containing converted byte[]
82      */

83   /* private int[] getIntArray() {
84         // Create the array.
85         outBuf = new int[inBuf.length];
86
87         int length = outBuf.length;
88         for (int i = 0; i < length; i++) {
89             outBuf[i] = (int) inBuf[i];
90             if (outBuf[i] < 0) {
91                 outBuf[i] += 256;
92             }
93         }
94
95         return (int[]) outBuf.clone();
96     }*/

97 }
98
Popular Tags