KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > asm > tree > ClassNodeUnitTest


1 /***
2  * ASM tests
3  * Copyright (c) 2002-2005 France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package org.objectweb.asm.tree;
31
32 import org.objectweb.asm.Opcodes;
33
34 import junit.framework.TestCase;
35
36 /**
37  * ClassNode unit tests.
38  *
39  * @author Eric Bruneton
40  */

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