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.sget; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.sget.d.T_sget_1; 22 import dot.junit.opcodes.sget.d.T_sget_11; 23 import dot.junit.opcodes.sget.d.T_sget_12; 24 import dot.junit.opcodes.sget.d.T_sget_13; 25 import dot.junit.opcodes.sget.d.T_sget_2; 26 import dot.junit.opcodes.sget.d.T_sget_5; 27 import dot.junit.opcodes.sget.d.T_sget_6; 28 import dot.junit.opcodes.sget.d.T_sget_7; 29 import dot.junit.opcodes.sget.d.T_sget_8; 30 import dot.junit.opcodes.sget.d.T_sget_9; 31 32 public class Test_sget extends DxTestCase { 33 34 /** 35 * @title type - int 36 */ 37 public void testN1() { 38 T_sget_1 t = new T_sget_1(); 39 assertEquals(5, t.run()); 40 } 41 42 /** 43 * @title type - float 44 */ 45 public void testN2() { 46 T_sget_2 t = new T_sget_2(); 47 assertEquals(123f, t.run()); 48 } 49 50 /** 51 * @title access protected field from subclass 52 */ 53 public void testN3() { 54 //@uses dot.junit.opcodes.sget.d.T_sget_1 55 //@uses dot.junit.opcodes.sget.d.T_sget_11 56 T_sget_11 t = new T_sget_11(); 57 assertEquals(10, t.run()); 58 } 59 60 /** 61 * @constraint A12 62 * @title attempt to access non-static field 63 */ 64 public void testE1() { 65 loadAndRun("dot.junit.opcodes.sget.d.T_sget_5", IncompatibleClassChangeError.class); 66 } 67 68 /** 69 * @title initialization of referenced class throws exception 70 */ 71 public void testE6() { 72 loadAndRun("dot.junit.opcodes.sget.d.T_sget_9", ExceptionInInitializerError.class); 73 } 74 75 /** 76 * @constraint A12 77 * @title constant pool index 78 */ 79 public void testVFE1() { 80 load("dot.junit.opcodes.sget.d.T_sget_4", VerifyError.class); 81 } 82 83 /** 84 * 85 * @constraint A23 86 * @title number of registers 87 */ 88 public void testVFE2() { 89 load("dot.junit.opcodes.sget.d.T_sget_3", VerifyError.class); 90 } 91 92 /** 93 * 94 * @constraint B13 95 * @title read integer from long field - only field with same name but 96 * different type exists 97 */ 98 public void testVFE3() { 99 loadAndRun("dot.junit.opcodes.sget.d.T_sget_13", NoSuchFieldError.class); 100 } 101 102 /** 103 * @constraint n/a 104 * @title Attempt to read inaccessible field. 105 */ 106 public void testVFE4() { 107 //@uses dot.junit.opcodes.sget.TestStubs 108 loadAndRun("dot.junit.opcodes.sget.d.T_sget_6", IllegalAccessError.class); 109 } 110 111 /** 112 * @constraint n/a 113 * @title Attempt to read field of undefined class. 114 */ 115 public void testVFE5() { 116 loadAndRun("dot.junit.opcodes.sget.d.T_sget_7", NoClassDefFoundError.class); 117 } 118 119 /** 120 * @constraint n/a 121 * @title Attempt to read undefined field. 122 */ 123 public void testVFE6() { 124 loadAndRun("dot.junit.opcodes.sget.d.T_sget_8", NoSuchFieldError.class); 125 } 126 127 /** 128 * @constraint n/a 129 * @title Attempt to read superclass' private field from subclass. 130 */ 131 public void testVFE7() { 132 //@uses dot.junit.opcodes.sget.d.T_sget_1 133 loadAndRun("dot.junit.opcodes.sget.d.T_sget_12", IllegalAccessError.class); 134 } 135 136 /** 137 * @constraint B1 138 * @title sget shall not work for reference fields 139 */ 140 public void testVFE8() { 141 load("dot.junit.opcodes.sget.d.T_sget_14", VerifyError.class); 142 } 143 144 /** 145 * 146 * @constraint B1 147 * @title sget shall not work for short fields 148 */ 149 public void testVFE9() { 150 load("dot.junit.opcodes.sget.d.T_sget_15", VerifyError.class); 151 } 152 153 /** 154 * 155 * @constraint B1 156 * @title sget shall not work for boolean fields 157 */ 158 public void testVFE10() { 159 load("dot.junit.opcodes.sget.d.T_sget_16", VerifyError.class); 160 } 161 162 /** 163 * 164 * @constraint B1 165 * @title sget shall not work for char fields 166 */ 167 public void testVFE11() { 168 load("dot.junit.opcodes.sget.d.T_sget_17", VerifyError.class); 169 } 170 171 /** 172 * 173 * @constraint B1 174 * @title sget shall not work for byte fields 175 */ 176 public void testVFE12() { 177 load("dot.junit.opcodes.sget.d.T_sget_18", VerifyError.class); 178 } 179 180 /** 181 * 182 * @constraint B1 183 * @title sget shall not work for double fields 184 */ 185 public void testVFE13() { 186 load("dot.junit.opcodes.sget.d.T_sget_19", VerifyError.class); 187 } 188 189 /** 190 * 191 * @constraint B1 192 * @title sget shall not work for long fields 193 */ 194 public void testVFE14() { 195 load("dot.junit.opcodes.sget.d.T_sget_20", VerifyError.class); 196 } 197 } 198