1 30 package org.objectweb.asm.tree; 31 32 import org.objectweb.asm.Opcodes; 33 34 import junit.framework.TestCase; 35 36 41 public class ClassNodeUnitTest extends TestCase implements Opcodes { 42 43 public void testFrameNode() { 44 FrameNode fn = new FrameNode(F_SAME, 0, null, 0, null); 45 assertEquals(AbstractInsnNode.FRAME, fn.getType()); 46 } 47 48 public void testInsnNode() { 49 InsnNode in = new InsnNode(NOP); 50 assertEquals(in.getOpcode(), NOP); 51 assertEquals(AbstractInsnNode.INSN, in.getType()); 52 } 53 54 public void testIntInsnNode() { 55 IntInsnNode iin = new IntInsnNode(BIPUSH, 0); 56 iin.setOpcode(SIPUSH); 57 assertEquals(SIPUSH, iin.getOpcode()); 58 assertEquals(AbstractInsnNode.INT_INSN, iin.getType()); 59 } 60 61 public void testVarInsnNode() { 62 VarInsnNode vn = new VarInsnNode(ALOAD, 0); 63 vn.setOpcode(ASTORE); 64 assertEquals(ASTORE, vn.getOpcode()); 65 assertEquals(AbstractInsnNode.VAR_INSN, vn.getType()); 66 } 67 68 public void testTypeInsnNode() { 69 TypeInsnNode tin = new TypeInsnNode(NEW, "java/lang/Object"); 70 tin.setOpcode(CHECKCAST); 71 assertEquals(CHECKCAST, tin.getOpcode()); 72 assertEquals(AbstractInsnNode.TYPE_INSN, tin.getType()); 73 } 74 75 public void testFieldInsnNode() { 76 FieldInsnNode fn = new FieldInsnNode(GETSTATIC, "owner", "name", "I"); 77 fn.setOpcode(PUTSTATIC); 78 assertEquals(PUTSTATIC, fn.getOpcode()); 79 assertEquals(AbstractInsnNode.FIELD_INSN, fn.getType()); 80 } 81 82 public void testMethodInsnNode() { 83 MethodInsnNode mn = new MethodInsnNode(INVOKESTATIC, 84 "owner", 85 "name", 86 "I"); 87 mn.setOpcode(INVOKESPECIAL); 88 assertEquals(INVOKESPECIAL, mn.getOpcode()); 89 assertEquals(AbstractInsnNode.METHOD_INSN, mn.getType()); 90 } 91 92 public void testJumpInsnNode() { 93 JumpInsnNode jn = new JumpInsnNode(GOTO, new LabelNode()); 94 jn.setOpcode(IFEQ); 95 assertEquals(IFEQ, jn.getOpcode()); 96 assertEquals(AbstractInsnNode.JUMP_INSN, jn.getType()); 97 } 98 99 public void testLabelNode() { 100 LabelNode ln = new LabelNode(); 101 assertEquals(AbstractInsnNode.LABEL, ln.getType()); 102 assertTrue(ln.getLabel() != null); 103 } 104 105 public void testIincInsnNode() { 106 IincInsnNode iincn = new IincInsnNode(1, 1); 107 assertEquals(AbstractInsnNode.IINC_INSN, iincn.getType()); 108 } 109 110 public void testLdcInsnNode() { 111 LdcInsnNode ldcn = new LdcInsnNode("s"); 112 assertEquals(AbstractInsnNode.LDC_INSN, ldcn.getType()); 113 } 114 115 public void testLookupSwitchInsnNode() { 116 LookupSwitchInsnNode lsn = new LookupSwitchInsnNode(null, null, null); 117 assertEquals(AbstractInsnNode.LOOKUPSWITCH_INSN, lsn.getType()); 118 } 119 120 public void testTableSwitchInsnNode() { 121 TableSwitchInsnNode tsn = new TableSwitchInsnNode(0, 1, null, null); 122 assertEquals(AbstractInsnNode.TABLESWITCH_INSN, tsn.getType()); 123 } 124 125 public void testMultiANewArrayInsnNode() { 126 MultiANewArrayInsnNode manan = new MultiANewArrayInsnNode("[[I", 2); 127 assertEquals(AbstractInsnNode.MULTIANEWARRAY_INSN, manan.getType()); 128 } 129 } 130 | Popular Tags |