1 30 package org.objectweb.asm.commons; 31 32 import junit.framework.TestSuite; 33 34 import org.objectweb.asm.AbstractTest; 35 import org.objectweb.asm.ClassAdapter; 36 import org.objectweb.asm.ClassReader; 37 import org.objectweb.asm.ClassWriter; 38 import org.objectweb.asm.Label; 39 import org.objectweb.asm.MethodVisitor; 40 41 public class CodeSizeEvaluatorTest extends AbstractTest { 42 43 public static TestSuite suite() throws Exception { 44 return new CodeSizeEvaluatorTest().getSuite(); 45 } 46 47 public void test() throws Exception { 48 ClassReader cr = new ClassReader(is); 49 cr.accept(new ClassAdapter(new ClassWriter(0)) { 50 public MethodVisitor visitMethod( 51 final int access, 52 final String name, 53 final String desc, 54 final String signature, 55 final String [] exceptions) 56 { 57 MethodVisitor mv = cv.visitMethod(access, 58 name, 59 desc, 60 signature, 61 exceptions); 62 return new CodeSizeEvaluator(mv) { 63 public void visitMaxs( 64 final int maxStack, 65 final int maxLocals) 66 { 67 Label end = new Label(); 68 mv.visitLabel(end); 69 mv.visitMaxs(maxStack, maxLocals); 70 int size = end.getOffset(); 71 assertTrue(getMinSize() + " <= " + size + " <= " 72 + getMaxSize(), getMinSize() <= size 73 && size <= getMaxSize()); 74 } 75 }; 76 } 77 }, 0); 78 } 79 } 80 | Popular Tags |