001: /***
002: * ASM tests
003: * Copyright (c) 2002-2005 France Telecom
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in the
013: * documentation and/or other materials provided with the distribution.
014: * 3. Neither the name of the copyright holders nor the names of its
015: * contributors may be used to endorse or promote products derived from
016: * this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */package org.objectweb.asm.tree;
030:
031: import org.objectweb.asm.Opcodes;
032:
033: import junit.framework.TestCase;
034:
035: /**
036: * ClassNode unit tests.
037: *
038: * @author Eric Bruneton
039: */
040: public class ClassNodeUnitTest extends TestCase implements Opcodes {
041:
042: public void testFrameNode() {
043: FrameNode fn = new FrameNode(F_SAME, 0, null, 0, null);
044: assertEquals(AbstractInsnNode.FRAME, fn.getType());
045: }
046:
047: public void testInsnNode() {
048: InsnNode in = new InsnNode(NOP);
049: assertEquals(in.getOpcode(), NOP);
050: assertEquals(AbstractInsnNode.INSN, in.getType());
051: }
052:
053: public void testIntInsnNode() {
054: IntInsnNode iin = new IntInsnNode(BIPUSH, 0);
055: iin.setOpcode(SIPUSH);
056: assertEquals(SIPUSH, iin.getOpcode());
057: assertEquals(AbstractInsnNode.INT_INSN, iin.getType());
058: }
059:
060: public void testVarInsnNode() {
061: VarInsnNode vn = new VarInsnNode(ALOAD, 0);
062: vn.setOpcode(ASTORE);
063: assertEquals(ASTORE, vn.getOpcode());
064: assertEquals(AbstractInsnNode.VAR_INSN, vn.getType());
065: }
066:
067: public void testTypeInsnNode() {
068: TypeInsnNode tin = new TypeInsnNode(NEW, "java/lang/Object");
069: tin.setOpcode(CHECKCAST);
070: assertEquals(CHECKCAST, tin.getOpcode());
071: assertEquals(AbstractInsnNode.TYPE_INSN, tin.getType());
072: }
073:
074: public void testFieldInsnNode() {
075: FieldInsnNode fn = new FieldInsnNode(GETSTATIC, "owner",
076: "name", "I");
077: fn.setOpcode(PUTSTATIC);
078: assertEquals(PUTSTATIC, fn.getOpcode());
079: assertEquals(AbstractInsnNode.FIELD_INSN, fn.getType());
080: }
081:
082: public void testMethodInsnNode() {
083: MethodInsnNode mn = new MethodInsnNode(INVOKESTATIC, "owner",
084: "name", "I");
085: mn.setOpcode(INVOKESPECIAL);
086: assertEquals(INVOKESPECIAL, mn.getOpcode());
087: assertEquals(AbstractInsnNode.METHOD_INSN, mn.getType());
088: }
089:
090: public void testJumpInsnNode() {
091: JumpInsnNode jn = new JumpInsnNode(GOTO, new LabelNode());
092: jn.setOpcode(IFEQ);
093: assertEquals(IFEQ, jn.getOpcode());
094: assertEquals(AbstractInsnNode.JUMP_INSN, jn.getType());
095: }
096:
097: public void testLabelNode() {
098: LabelNode ln = new LabelNode();
099: assertEquals(AbstractInsnNode.LABEL, ln.getType());
100: assertTrue(ln.getLabel() != null);
101: }
102:
103: public void testIincInsnNode() {
104: IincInsnNode iincn = new IincInsnNode(1, 1);
105: assertEquals(AbstractInsnNode.IINC_INSN, iincn.getType());
106: }
107:
108: public void testLdcInsnNode() {
109: LdcInsnNode ldcn = new LdcInsnNode("s");
110: assertEquals(AbstractInsnNode.LDC_INSN, ldcn.getType());
111: }
112:
113: public void testLookupSwitchInsnNode() {
114: LookupSwitchInsnNode lsn = new LookupSwitchInsnNode(null, null,
115: null);
116: assertEquals(AbstractInsnNode.LOOKUPSWITCH_INSN, lsn.getType());
117: }
118:
119: public void testTableSwitchInsnNode() {
120: TableSwitchInsnNode tsn = new TableSwitchInsnNode(0, 1, null,
121: null);
122: assertEquals(AbstractInsnNode.TABLESWITCH_INSN, tsn.getType());
123: }
124:
125: public void testMultiANewArrayInsnNode() {
126: MultiANewArrayInsnNode manan = new MultiANewArrayInsnNode(
127: "[[I", 2);
128: assertEquals(AbstractInsnNode.MULTIANEWARRAY_INSN, manan
129: .getType());
130: }
131: }
|