Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 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 dot.junit.opcodes.aput_boolean; |
| 18 | |
| 19 | import dot.junit.DxTestCase; |
| 20 | import dot.junit.DxUtil; |
| 21 | import dot.junit.opcodes.aput_boolean.d.T_aput_boolean_1; |
| 22 | import dot.junit.opcodes.aput_boolean.d.T_aput_boolean_8; |
| 23 | |
| 24 | public class Test_aput_boolean extends DxTestCase { |
| 25 | /** |
| 26 | * @title put boolean into array |
| 27 | */ |
| 28 | public void testN1() { |
| 29 | T_aput_boolean_1 t = new T_aput_boolean_1(); |
| 30 | boolean[] arr = new boolean[2]; |
| 31 | t.run(arr, 1, true); |
| 32 | assertEquals(true, arr[1]); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @title put boolean into array |
| 37 | */ |
| 38 | public void testN2() { |
| 39 | T_aput_boolean_1 t = new T_aput_boolean_1(); |
| 40 | boolean[] arr = new boolean[2]; |
| 41 | t.run(arr, 0, true); |
| 42 | assertEquals(true, arr[0]); |
| 43 | } |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * @title expected ArrayIndexOutOfBoundsException |
| 47 | */ |
| 48 | public void testE1() { |
| 49 | T_aput_boolean_1 t = new T_aput_boolean_1(); |
| 50 | boolean[] arr = new boolean[2]; |
| 51 | try { |
| 52 | t.run(arr, 2, true); |
| 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_aput_boolean_1 t = new T_aput_boolean_1(); |
| 64 | try { |
| 65 | t.run(null, 2, true); |
| 66 | fail("expected NullPointerException"); |
| 67 | } catch (NullPointerException aie) { |
| 68 | // expected |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @title expected ArrayIndexOutOfBoundsException (negative index) |
| 74 | */ |
| 75 | public void testE3() { |
| 76 | T_aput_boolean_1 t = new T_aput_boolean_1(); |
| 77 | boolean[] arr = new boolean[2]; |
| 78 | try { |
| 79 | t.run(arr, -1, true); |
| 80 | fail("expected ArrayIndexOutOfBoundsException"); |
| 81 | } catch (ArrayIndexOutOfBoundsException aie) { |
| 82 | // expected |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | /** |
| 89 | * @constraint B1 |
| 90 | * @title types of arguments - array, double, int |
| 91 | */ |
| 92 | public void testVFE1() { |
| 93 | try { |
| 94 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_2"); |
| 95 | fail("expected a verification exception"); |
| 96 | } catch (Throwable t) { |
| 97 | DxUtil.checkVerifyException(t); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @constraint B1 |
| 103 | * @title types of arguments - array, int, long |
| 104 | */ |
| 105 | public void testVFE2() { |
| 106 | try { |
| 107 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_3"); |
| 108 | fail("expected a verification exception"); |
| 109 | } catch (Throwable t) { |
| 110 | DxUtil.checkVerifyException(t); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @constraint B1 |
| 116 | * @title types of arguments - object, int, int |
| 117 | */ |
| 118 | public void testVFE3() { |
| 119 | try { |
| 120 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_4"); |
| 121 | fail("expected a verification exception"); |
| 122 | } catch (Throwable t) { |
| 123 | DxUtil.checkVerifyException(t); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @constraint B1 |
| 129 | * @title types of arguments - double[], int, int |
| 130 | */ |
| 131 | public void testVFE4() { |
| 132 | try { |
| 133 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_5"); |
| 134 | fail("expected a verification exception"); |
| 135 | } catch (Throwable t) { |
| 136 | DxUtil.checkVerifyException(t); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @constraint B1 |
| 142 | * @title types of arguments - long[], int, int |
| 143 | */ |
| 144 | public void testVFE5() { |
| 145 | try { |
| 146 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_6"); |
| 147 | fail("expected a verification exception"); |
| 148 | } catch (Throwable t) { |
| 149 | DxUtil.checkVerifyException(t); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @constraint B1 |
| 155 | * @title types of arguments - array, reference, int |
| 156 | */ |
| 157 | public void testVFE6() { |
| 158 | try { |
| 159 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_7"); |
| 160 | fail("expected a verification exception"); |
| 161 | } catch (Throwable t) { |
| 162 | DxUtil.checkVerifyException(t); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @constraint A23 |
| 168 | * @title number of registers |
| 169 | */ |
| 170 | public void testVFE7() { |
| 171 | try { |
| 172 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_9"); |
| 173 | fail("expected a verification exception"); |
| 174 | } catch (Throwable t) { |
| 175 | DxUtil.checkVerifyException(t); |
| 176 | } |
| 177 | } |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 178 | |
jeffhao | 4fda9ca | 2011-10-04 19:20:23 -0700 | [diff] [blame] | 179 | /** |
| 180 | * @constraint B1 |
| 181 | * @title Type of index argument - float. The verifier checks that ints |
| 182 | * and floats are not used interchangeably. |
| 183 | */ |
| 184 | public void testVFE10() { |
| 185 | try { |
| 186 | Class.forName("dot.junit.opcodes.aput_boolean.d.T_aput_boolean_8"); |
| 187 | fail("expected a verification exception"); |
| 188 | } catch (Throwable t) { |
| 189 | DxUtil.checkVerifyException(t); |
| 190 | } |
| 191 | } |
| 192 | |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 193 | } |