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.iget_short; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.iget_short.d.T_iget_short_1; 22 import dot.junit.opcodes.iget_short.d.T_iget_short_11; 23 import dot.junit.opcodes.iget_short.d.T_iget_short_12; 24 import dot.junit.opcodes.iget_short.d.T_iget_short_13; 25 import dot.junit.opcodes.iget_short.d.T_iget_short_21; 26 import dot.junit.opcodes.iget_short.d.T_iget_short_5; 27 import dot.junit.opcodes.iget_short.d.T_iget_short_6; 28 import dot.junit.opcodes.iget_short.d.T_iget_short_7; 29 import dot.junit.opcodes.iget_short.d.T_iget_short_8; 30 import dot.junit.opcodes.iget_short.d.T_iget_short_9; 31 32 public class Test_iget_short extends DxTestCase { 33 34 /** 35 * @title get short from field 36 */ testN1()37 public void testN1() { 38 T_iget_short_1 t = new T_iget_short_1(); 39 assertEquals(32000, t.run()); 40 } 41 42 43 /** 44 * @title access protected field from subclass 45 */ testN3()46 public void testN3() { 47 //@uses dot.junit.opcodes.iget_short.d.T_iget_short_1 48 //@uses dot.junit.opcodes.iget_short.d.T_iget_short_11 49 T_iget_short_11 t = new T_iget_short_11(); 50 assertEquals(32000, t.run()); 51 } 52 53 /** 54 * @title expected NullPointerException 55 */ testE2()56 public void testE2() { 57 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_9", NullPointerException.class); 58 } 59 60 /** 61 * @constraint A11 62 * @title constant pool index 63 */ testVFE1()64 public void testVFE1() { 65 load("dot.junit.opcodes.iget_short.d.T_iget_short_4", VerifyError.class); 66 } 67 68 /** 69 * 70 * @constraint A23 71 * @title number of registers 72 */ testVFE2()73 public void testVFE2() { 74 load("dot.junit.opcodes.iget_short.d.T_iget_short_3", VerifyError.class); 75 } 76 77 /** 78 * 79 * @constraint B13 80 * @title read short from long field - only field with same name but 81 * different type exists 82 */ testVFE3()83 public void testVFE3() { 84 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_13", NoSuchFieldError.class); 85 } 86 87 /** 88 * @constraint n/a 89 * @title Attempt to read inaccessible field. 90 */ testVFE4()91 public void testVFE4() { 92 //@uses dot.junit.opcodes.iget_short.TestStubs 93 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_6", IllegalAccessError.class); 94 } 95 96 /** 97 * @constraint n/a 98 * @title Attempt to read field of undefined class. 99 */ testVFE5()100 public void testVFE5() { 101 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_7", NoClassDefFoundError.class); 102 } 103 104 /** 105 * @constraint n/a 106 * @title Attempt to read undefined field. 107 */ testVFE6()108 public void testVFE6() { 109 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_8", NoSuchFieldError.class); 110 } 111 112 /** 113 * @constraint n/a 114 * @title Attempt to read superclass' private field from subclass. 115 */ testVFE7()116 public void testVFE7() { 117 //@uses dot.junit.opcodes.iget_short.d.T_iget_short_1 118 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_12", IllegalAccessError.class); 119 } 120 121 /** 122 * @constraint B1 123 * @title iget_short shall not work for reference fields 124 */ testVFE8()125 public void testVFE8() { 126 load("dot.junit.opcodes.iget_short.d.T_iget_short_14", VerifyError.class); 127 } 128 129 /** 130 * 131 * @constraint B1 132 * @title iget_short shall not work for char fields 133 */ testVFE9()134 public void testVFE9() { 135 load("dot.junit.opcodes.iget_short.d.T_iget_short_15", VerifyError.class); 136 } 137 138 /** 139 * 140 * @constraint B1 141 * @title iget_short shall not work for int fields 142 */ testVFE10()143 public void testVFE10() { 144 load("dot.junit.opcodes.iget_short.d.T_iget_short_16", VerifyError.class); 145 } 146 147 /** 148 * 149 * @constraint B1 150 * @title iget_short shall not work for byte fields 151 */ testVFE11()152 public void testVFE11() { 153 load("dot.junit.opcodes.iget_short.d.T_iget_short_17", VerifyError.class); 154 } 155 156 /** 157 * 158 * @constraint B1 159 * @title iget_short shall not work for boolean fields 160 */ testVFE12()161 public void testVFE12() { 162 load("dot.junit.opcodes.iget_short.d.T_iget_short_18", VerifyError.class); 163 } 164 165 /** 166 * 167 * @constraint B1 168 * @title iget_short shall not work for double fields 169 */ testVFE13()170 public void testVFE13() { 171 load("dot.junit.opcodes.iget_short.d.T_iget_short_19", VerifyError.class); 172 } 173 174 /** 175 * 176 * @constraint B1 177 * @title iget_short shall not work for long fields 178 */ testVFE14()179 public void testVFE14() { 180 load("dot.junit.opcodes.iget_short.d.T_iget_short_20", VerifyError.class); 181 } 182 183 /** 184 * @constraint B12 185 * @title Attempt to read inaccessible protected field. 186 */ testVFE15()187 public void testVFE15() { 188 //@uses dot.junit.opcodes.iget_short.TestStubs 189 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_21", IllegalAccessError.class); 190 } 191 192 /** 193 * @constraint A11 194 * @title Attempt to read static field. 195 */ testVFE16()196 public void testVFE16() { 197 //@uses dot.junit.opcodes.iget_short.TestStubs 198 loadAndRun("dot.junit.opcodes.iget_short.d.T_iget_short_5", 199 IncompatibleClassChangeError.class); 200 } 201 202 /** 203 * @constraint B6 204 * @title instance fields may only be accessed on already initialized instances. 205 */ testVFE30()206 public void testVFE30() { 207 load("dot.junit.opcodes.iget_short.d.T_iget_short_30", VerifyError.class); 208 } 209 210 /** 211 * @constraint N/A 212 * @title instance fields may only be accessed on already initialized instances. 213 */ testVFE31()214 public void testVFE31() { 215 load("dot.junit.opcodes.iget_short.d.T_iget_short_31", VerifyError.class); 216 } 217 } 218