1 30 package org.objectweb.asm; 31 32 import java.lang.reflect.Constructor ; 33 import java.lang.reflect.Method ; 34 import java.util.Arrays ; 35 36 import junit.framework.TestCase; 37 38 43 public class TypeUnitTest extends TestCase implements Opcodes { 44 45 public void testConstants() { 46 assertEquals(Type.INT_TYPE, Type.getType(Integer.TYPE)); 47 assertEquals(Type.VOID_TYPE, Type.getType(Void.TYPE)); 48 assertEquals(Type.BOOLEAN_TYPE, Type.getType(Boolean.TYPE)); 49 assertEquals(Type.BYTE_TYPE, Type.getType(Byte.TYPE)); 50 assertEquals(Type.CHAR_TYPE, Type.getType(Character.TYPE)); 51 assertEquals(Type.SHORT_TYPE, Type.getType(Short.TYPE)); 52 assertEquals(Type.DOUBLE_TYPE, Type.getType(Double.TYPE)); 53 assertEquals(Type.FLOAT_TYPE, Type.getType(Float.TYPE)); 54 assertEquals(Type.LONG_TYPE, Type.getType(Long.TYPE)); 55 } 56 57 public void testInternalName() { 58 String s1 = Type.getType(TypeUnitTest.class).getInternalName(); 59 String s2 = Type.getInternalName(TypeUnitTest.class); 60 assertEquals(s1, s2); 61 } 62 63 public void testConstructorDescriptor() { 64 for (int i = 0; i < String .class.getConstructors().length; ++i) { 65 Constructor c = String .class.getConstructors()[i]; 66 Type.getConstructorDescriptor(c); 67 } 68 } 69 70 public void testMethodDescriptor() { 71 for (int i = 0; i < Arrays .class.getMethods().length; ++i) { 72 Method m = Arrays .class.getMethods()[i]; 73 Type[] args = Type.getArgumentTypes(m); 74 Type r = Type.getReturnType(m); 75 String d1 = Type.getMethodDescriptor(r, args); 76 String d2 = Type.getMethodDescriptor(m); 77 assertEquals(d1, d2); 78 } 79 } 80 81 public void testGetOpcode() { 82 Type object = Type.getType("Ljava/lang/Object;"); 83 assertEquals(BALOAD, Type.BOOLEAN_TYPE.getOpcode(IALOAD)); 84 assertEquals(BALOAD, Type.BYTE_TYPE.getOpcode(IALOAD)); 85 assertEquals(CALOAD, Type.CHAR_TYPE.getOpcode(IALOAD)); 86 assertEquals(SALOAD, Type.SHORT_TYPE.getOpcode(IALOAD)); 87 assertEquals(IALOAD, Type.INT_TYPE.getOpcode(IALOAD)); 88 assertEquals(FALOAD, Type.FLOAT_TYPE.getOpcode(IALOAD)); 89 assertEquals(LALOAD, Type.LONG_TYPE.getOpcode(IALOAD)); 90 assertEquals(DALOAD, Type.DOUBLE_TYPE.getOpcode(IALOAD)); 91 assertEquals(AALOAD, object.getOpcode(IALOAD)); 92 assertEquals(IADD, Type.BOOLEAN_TYPE.getOpcode(IADD)); 93 assertEquals(IADD, Type.BYTE_TYPE.getOpcode(IADD)); 94 assertEquals(IADD, Type.CHAR_TYPE.getOpcode(IADD)); 95 assertEquals(IADD, Type.SHORT_TYPE.getOpcode(IADD)); 96 assertEquals(IADD, Type.INT_TYPE.getOpcode(IADD)); 97 assertEquals(FADD, Type.FLOAT_TYPE.getOpcode(IADD)); 98 assertEquals(LADD, Type.LONG_TYPE.getOpcode(IADD)); 99 assertEquals(DADD, Type.DOUBLE_TYPE.getOpcode(IADD)); 100 } 101 102 public void testHashcode() { 103 Type.getType("Ljava/lang/Object;").hashCode(); 104 } 105 106 public void testObjectType() throws Exception { 107 Type t1 = Type.getObjectType("java/lang/Object"); 108 Type t2 = Type.getType("Ljava/lang/Object;"); 109 assertEquals(t2.getSort(), t1.getSort()); 110 assertEquals(t2.getClassName(), t1.getClassName()); 111 assertEquals(t2.getDescriptor(), t1.getDescriptor()); 112 } 113 } 114
| Popular Tags
|