1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package dxc.junit.opcodes.sastore; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.sastore.jm.T_sastore_1; 22 23 public class Test_sastore extends DxTestCase { 24 25 /** 26 * @title normal test. trying different indexes 27 */ 28 public void testN1() { 29 T_sastore_1 t = new T_sastore_1(); 30 short[] arr = new short[2]; 31 t.run(arr, 1, (short) 10000); 32 assertEquals(10000, arr[1]); 33 } 34 35 /** 36 * @title normal test. trying different indexes 37 */ 38 public void testN2() { 39 T_sastore_1 t = new T_sastore_1(); 40 short[] arr = new short[2]; 41 t.run(arr, 0, (short) 10000); 42 assertEquals(10000, arr[0]); 43 } 44 45 /** 46 * @title expected ArrayIndexOutOfBoundsException 47 */ 48 public void testE1() { 49 T_sastore_1 t = new T_sastore_1(); 50 short[] arr = new short[2]; 51 try { 52 t.run(arr, 2, (short) 10000); 53 fail("expected ArrayIndexOutOfBoundsException"); 54 } catch (ArrayIndexOutOfBoundsException aie) { 55 // expected 56 } 57 } 58 59 /** 60 * @title expected NullPointerException 61 */ 62 public void testE2() { 63 T_sastore_1 t = new T_sastore_1(); 64 try { 65 t.run(null, 2, (short) 10000); 66 fail("expected NullPointerException"); 67 } catch (NullPointerException aie) { 68 // expected 69 } 70 } 71 72 /** 73 * @title expected ArrayIndexOutOfBoundsException 74 */ 75 public void testE3() { 76 T_sastore_1 t = new T_sastore_1(); 77 short[] arr = new short[2]; 78 try { 79 t.run(arr, -1, (short) 10000); 80 fail("expected ArrayIndexOutOfBoundsException"); 81 } catch (ArrayIndexOutOfBoundsException aie) { 82 // expected 83 } 84 } 85 86 /** 87 * @constraint 4.8.2.1 88 * @title number of arguments 89 */ 90 public void testVFE1() { 91 try { 92 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_2"); 93 fail("expected a verification exception"); 94 } catch (Throwable t) { 95 DxUtil.checkVerifyException(t); 96 } 97 } 98 99 /** 100 * @constraint 4.8.2.1 101 * @title number of arguments 102 */ 103 public void testVFE2() { 104 try { 105 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_3"); 106 fail("expected a verification exception"); 107 } catch (Throwable t) { 108 DxUtil.checkVerifyException(t); 109 } 110 } 111 112 /** 113 * @constraint 4.8.2.1 114 * @title types of arguments - array, double, 115 * int 116 */ 117 public void testVFE3() { 118 try { 119 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_4"); 120 fail("expected a verification exception"); 121 } catch (Throwable t) { 122 DxUtil.checkVerifyException(t); 123 } 124 } 125 126 /** 127 * @constraint 4.8.2.1 128 * @title types of arguments - array, int, long 129 */ 130 public void testVFE4() { 131 try { 132 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_5"); 133 fail("expected a verification exception"); 134 } catch (Throwable t) { 135 DxUtil.checkVerifyException(t); 136 } 137 } 138 139 /** 140 * @constraint 4.8.2.1 141 * @title types of arguments - object, int, int 142 */ 143 public void testVFE5() { 144 try { 145 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_6"); 146 fail("expected a verification exception"); 147 } catch (Throwable t) { 148 DxUtil.checkVerifyException(t); 149 } 150 } 151 152 /** 153 * @constraint 4.8.2.1 154 * @title types of arguments - double[], int, 155 * int 156 */ 157 public void testVFE6() { 158 try { 159 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_7"); 160 fail("expected a verification exception"); 161 } catch (Throwable t) { 162 DxUtil.checkVerifyException(t); 163 } 164 } 165 166 /** 167 * @constraint 4.8.2.1 168 * @title types of arguments - long[], int, int 169 */ 170 public void testVFE7() { 171 try { 172 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_8"); 173 fail("expected a verification exception"); 174 } catch (Throwable t) { 175 DxUtil.checkVerifyException(t); 176 } 177 } 178 179 /** 180 * @constraint 4.8.2.1 181 * @title types of arguments - array, reference, 182 * int 183 */ 184 public void testVFE8() { 185 try { 186 Class.forName("dxc.junit.opcodes.sastore.jm.T_sastore_9"); 187 fail("expected a verification exception"); 188 } catch (Throwable t) { 189 DxUtil.checkVerifyException(t); 190 } 191 } 192 } 193