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