1   package serp.bytecode;
2   
3   import junit.framework.*;
4   import junit.textui.*;
5   
6   /**
7    * Tests the {@link ArrayStoreInstruction} type.
8    *
9    * @author Abe White
10   */
11  public class TestArrayStoreInstruction extends TestCase {
12      private Code _code = new Code();
13  
14      public TestArrayStoreInstruction(String test) {
15          super(test);
16      }
17  
18      /**
19       * Test that the instruction initializes correctly when generated.
20       */
21      public void testIniitalize() {
22          assertEquals(Constants.NOP, _code.xastore().getOpcode());
23          assertEquals(Constants.IASTORE, _code.iastore().getOpcode());
24          assertEquals(Constants.LASTORE, _code.lastore().getOpcode());
25          assertEquals(Constants.FASTORE, _code.fastore().getOpcode());
26          assertEquals(Constants.DASTORE, _code.dastore().getOpcode());
27          assertEquals(Constants.AASTORE, _code.aastore().getOpcode());
28          assertEquals(Constants.BASTORE, _code.bastore().getOpcode());
29          assertEquals(Constants.CASTORE, _code.castore().getOpcode());
30          assertEquals(Constants.SASTORE, _code.sastore().getOpcode());
31      }
32  
33      /**
34       * Test the the instruction returns its type correctly.
35       */
36      public void testGetType() {
37          assertNull(_code.xastore().getType());
38          assertEquals(int.class, _code.iastore().getType());
39          assertEquals(long.class, _code.lastore().getType());
40          assertEquals(float.class, _code.fastore().getType());
41          assertEquals(double.class, _code.dastore().getType());
42          assertEquals(Object.class, _code.aastore().getType());
43          assertEquals(byte.class, _code.bastore().getType());
44          assertEquals(char.class, _code.castore().getType());
45          assertEquals(short.class, _code.sastore().getType());
46      }
47  
48      /**
49       * Test that the opcode morphs correctly with type changes.
50       */
51      public void testOpcodeMorph() {
52          ArrayStoreInstruction ins = _code.xastore();
53          assertEquals(Constants.NOP, ins.getOpcode());
54          assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
55          assertEquals(Constants.NOP, ins.setType((BCClass) null).getOpcode());
56          assertEquals(Constants.NOP, ins.setType((Class) null).getOpcode());
57  
58          assertEquals(Constants.IASTORE, ins.setType(int.class).getOpcode());
59          assertEquals(Constants.NOP, ins.setType((String) null).getOpcode());
60          assertEquals(Constants.LASTORE, ins.setType(long.class).getOpcode());
61          assertEquals(Constants.FASTORE, ins.setType(float.class).getOpcode());
62          assertEquals(Constants.DASTORE, ins.setType(double.class).getOpcode());
63          assertEquals(Constants.AASTORE, ins.setType(Object.class).getOpcode());
64          assertEquals(Constants.BASTORE, ins.setType(byte.class).getOpcode());
65          assertEquals(Constants.CASTORE, ins.setType(char.class).getOpcode());
66          assertEquals(Constants.SASTORE, ins.setType(short.class).getOpcode());
67          assertEquals(Constants.IASTORE, ins.setType(void.class).getOpcode());
68          assertEquals(Constants.AASTORE, ins.setType(String.class).getOpcode());
69          assertEquals(Constants.IASTORE, ins.setType(boolean.class).getOpcode());
70      }
71  
72      public static Test suite() {
73          return new TestSuite(TestArrayStoreInstruction.class);
74      }
75  
76      public static void main(String[] args) {
77          TestRunner.run(suite());
78      }
79  }