1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package org.objectweb.asm;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Arrays;
import junit.framework.TestCase;
public class UnitTest extends TestCase {
public void testReader() throws IOException {
try {
new ClassReader((InputStream) null);
fail();
} catch (IOException e) {
}
ClassReader cr = new ClassReader(getClass().getName());
int item = cr.getItem(1);
assertTrue(item >= 10);
assertTrue(item < cr.header);
}
public void testWriter() {
ClassWriter cw = new ClassWriter(false);
cw.newConst(new Byte((byte) 0));
cw.newConst(new Character('0'));
cw.newConst(new Short((short) 0));
cw.newConst(new Boolean(false));
try {
cw.newConst(new Object());
fail();
} catch (RuntimeException e) {
}
cw.newMethod("A", "m", "()V", false);
}
public void testLabel() {
new Label().toString();
try {
new Label().getOffset();
fail();
} catch (RuntimeException e) {
}
}
public void testType() {
assertEquals(Type.getType(Integer.TYPE), Type.INT_TYPE);
assertEquals(Type.getType(Void.TYPE), Type.VOID_TYPE);
assertEquals(Type.getType(Boolean.TYPE), Type.BOOLEAN_TYPE);
assertEquals(Type.getType(Byte.TYPE), Type.BYTE_TYPE);
assertEquals(Type.getType(Character.TYPE), Type.CHAR_TYPE);
assertEquals(Type.getType(Short.TYPE), Type.SHORT_TYPE);
assertEquals(Type.getType(Double.TYPE), Type.DOUBLE_TYPE);
assertEquals(Type.getType(Float.TYPE), Type.FLOAT_TYPE);
assertEquals(Type.getType(Long.TYPE), Type.LONG_TYPE);
String s1 = Type.getType(UnitTest.class).getInternalName();
String s2 = Type.getInternalName(UnitTest.class);
assertEquals(s1, s2);
for (int i = 0; i < Arrays.class.getMethods().length; ++i) {
Method m = Arrays.class.getMethods()[i];
Type[] args = Type.getArgumentTypes(m);
Type r = Type.getReturnType(m);
String d1 = Type.getMethodDescriptor(r, args);
String d2 = Type.getMethodDescriptor(m);
assertEquals(d1, d2);
}
Type.INT_TYPE.hashCode();
}
}
|