1 30 package org.objectweb.asm; 31 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 35 import junit.framework.TestCase; 36 37 43 public class ClassReaderUnitTest extends TestCase implements Opcodes { 44 45 public void testIllegalConstructorArgument() { 46 try { 47 new ClassReader((InputStream ) null); 48 fail(); 49 } catch (IOException e) { 50 } 51 } 52 53 public void testGetItem() throws IOException { 54 ClassReader cr = new ClassReader(getClass().getName()); 55 int item = cr.getItem(1); 56 assertTrue(item >= 10); 57 assertTrue(item < cr.header); 58 } 59 60 public void testReadByte() throws IOException { 61 ClassReader cr = new ClassReader(getClass().getName()); 62 assertEquals(cr.b[0] & 0xFF, cr.readByte(0)); 63 } 64 65 public void testGetAccess() throws Exception { 66 String name = getClass().getName(); 67 assertEquals(Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, new ClassReader(name).getAccess()); 68 } 69 70 public void testGetClassName() throws Exception { 71 String name = getClass().getName(); 72 assertEquals(name.replace('.', '/'), new ClassReader(name).getClassName()); 73 } 74 75 public void testGetSuperName() throws Exception { 76 assertEquals(TestCase.class.getName().replace('.', '/'), new ClassReader(getClass().getName()).getSuperName()); 77 assertEquals(null, new ClassReader(Object .class.getName()).getSuperName()); 78 } 79 80 public void testGetInterfaces() throws Exception { 81 String [] interfaces = new ClassReader(getClass().getName()).getInterfaces(); 82 assertNotNull(interfaces); 83 assertEquals(1, interfaces.length); 84 assertEquals(Opcodes.class.getName().replace('.', '/'), interfaces[0]); 85 86 interfaces = new ClassReader(Opcodes.class.getName()).getInterfaces(); 87 assertNotNull(interfaces); 88 } 89 } 90 | Popular Tags |