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.check_cast; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.check_cast.d.T_check_cast_1; 22 import dot.junit.opcodes.check_cast.d.T_check_cast_2; 23 import dot.junit.opcodes.check_cast.d.T_check_cast_3; 24 import dot.junit.opcodes.check_cast.d.T_check_cast_7; 25 26 27 public class Test_check_cast extends DxTestCase { 28 29 30 /** 31 * @title (String)(Object)String 32 */ testN1()33 public void testN1() { 34 T_check_cast_1 t = new T_check_cast_1(); 35 String s = ""; 36 assertEquals(s, t.run(s)); 37 } 38 39 /** 40 * @title (String)(Object)null 41 */ testN2()42 public void testN2() { 43 T_check_cast_1 t = new T_check_cast_1(); 44 assertNull(t.run(null)); 45 } 46 47 /** 48 * @title check assignment compatibility rules 49 */ testN4()50 public void testN4() { 51 T_check_cast_2 t = new T_check_cast_2(); 52 assertEquals(5, t.run()); 53 } 54 55 /** 56 * @title expected ClassCastException 57 */ testE1()58 public void testE1() { 59 loadAndRun("dot.junit.opcodes.check_cast.d.T_check_cast_1", ClassCastException.class, 60 new Integer(1)); 61 } 62 63 /** 64 * @constraint A18 65 * @title constant pool index 66 */ testVFE1()67 public void testVFE1() { 68 load("dot.junit.opcodes.check_cast.d.T_check_cast_4", VerifyError.class); 69 } 70 71 /** 72 * 73 * @constraint B1 74 * @title type of argument - int 75 */ testVFE2()76 public void testVFE2() { 77 load("dot.junit.opcodes.check_cast.d.T_check_cast_5", VerifyError.class); 78 } 79 80 /** 81 * 82 * @constraint B1 83 * @title type of argument - long 84 */ testVFE3()85 public void testVFE3() { 86 load("dot.junit.opcodes.check_cast.d.T_check_cast_8", VerifyError.class); 87 } 88 89 /** 90 * 91 * @constraint B1 92 * @title number of registers 93 */ testVFE4()94 public void testVFE4() { 95 load("dot.junit.opcodes.check_cast.d.T_check_cast_6", VerifyError.class); 96 } 97 98 /** 99 * @constraint n/a 100 * @title Attempt to access inaccessible class, expect throws IllegalAccessError 101 */ testVFE5()102 public void testVFE5() { 103 //@uses dot.junit.opcodes.check_cast.TestStubs 104 loadAndRun("dot.junit.opcodes.check_cast.d.T_check_cast_3", IllegalAccessError.class); 105 } 106 107 /** 108 * @constraint n/a 109 * @title Attempt to access undefined class, expect throws NoClassDefFoundError on 110 * first access 111 */ testVFE6()112 public void testVFE6() { 113 loadAndRun("dot.junit.opcodes.check_cast.d.T_check_cast_7", NoClassDefFoundError.class); 114 } 115 116 /** 117 * @constraint A18 118 * @title constant pool type 119 */ testVFE7()120 public void testVFE7() { 121 load("dot.junit.opcodes.check_cast.d.T_check_cast_9", VerifyError.class); 122 } 123 124 } 125