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.baload; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.baload.jm.T_baload_1; 22 23 public class Test_baload extends DxTestCase { 24 25 /** 26 * @title normal test. Trying different indexes 27 */ 28 public void testN1() { 29 T_baload_1 t = new T_baload_1(); 30 byte[] arr = new byte[2]; 31 arr[1] = 100; 32 assertEquals(100, t.run(arr, 1)); 33 } 34 35 /** 36 * @title normal test. Trying different indexes 37 */ 38 public void testN2() { 39 T_baload_1 t = new T_baload_1(); 40 byte[] arr = new byte[2]; 41 arr[0] = 100; 42 assertEquals(100, t.run(arr, 0)); 43 } 44 45 /** 46 * @title expected ArrayIndexOutOfBoundsException 47 */ 48 public void testE1() { 49 T_baload_1 t = new T_baload_1(); 50 byte[] arr = new byte[2]; 51 try { 52 t.run(arr, 2); 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_baload_1 t = new T_baload_1(); 64 try { 65 t.run(null, 2); 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_baload_1 t = new T_baload_1(); 77 byte[] arr = new byte[2]; 78 try { 79 t.run(arr, -1); 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.baload.jm.T_baload_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.baload.jm.T_baload_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 */ 116 public void testVFE3() { 117 try { 118 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_4"); 119 fail("expected a verification exception"); 120 } catch (Throwable t) { 121 DxUtil.checkVerifyException(t); 122 } 123 } 124 125 /** 126 * @constraint 4.8.2.1 127 * @title types of arguments - array, long 128 */ 129 public void testVFE4() { 130 try { 131 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_5"); 132 fail("expected a verification exception"); 133 } catch (Throwable t) { 134 DxUtil.checkVerifyException(t); 135 } 136 } 137 138 /** 139 * @constraint 4.8.2.1 140 * @title types of arguments - Object, short 141 */ 142 public void testVFE5() { 143 try { 144 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_6"); 145 fail("expected a verification exception"); 146 } catch (Throwable t) { 147 DxUtil.checkVerifyException(t); 148 } 149 } 150 151 /** 152 * @constraint 4.8.2.1 153 * @title types of arguments - double[], short 154 */ 155 public void testVFE6() { 156 try { 157 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_7"); 158 fail("expected a verification exception"); 159 } catch (Throwable t) { 160 DxUtil.checkVerifyException(t); 161 } 162 } 163 164 /** 165 * @constraint 4.8.2.1 166 * @title types of arguments - int[], int 167 */ 168 public void testVFE7() { 169 try { 170 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_8"); 171 fail("expected a verification exception"); 172 } catch (Throwable t) { 173 DxUtil.checkVerifyException(t); 174 } 175 } 176 177 /** 178 * @constraint 4.8.2.1 179 * @title types of arguments - array, reference 180 */ 181 public void testVFE8() { 182 try { 183 Class.forName("dxc.junit.opcodes.baload.jm.T_baload_9"); 184 fail("expected a verification exception"); 185 } catch (Throwable t) { 186 DxUtil.checkVerifyException(t); 187 } 188 } 189 190 } 191