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.checkcast; 18 19 import dxc.junit.DxTestCase; 20 import dxc.junit.DxUtil; 21 import dxc.junit.opcodes.checkcast.jm.T_checkcast_1; 22 import dxc.junit.opcodes.checkcast.jm.T_checkcast_2; 23 import dxc.junit.opcodes.checkcast.jm.T_checkcast_3; 24 import dxc.junit.opcodes.checkcast.jm.T_checkcast_7; 25 26 public class Test_checkcast extends DxTestCase { 27 28 /** 29 * @title normal test 30 */ testN1()31 public void testN1() { 32 T_checkcast_1 t = new T_checkcast_1(); 33 String s = ""; 34 assertEquals(s, t.run(s)); 35 } 36 37 /** 38 * @title check null value 39 */ testN2()40 public void testN2() { 41 T_checkcast_1 t = new T_checkcast_1(); 42 assertNull(t.run(null)); 43 } 44 45 /** 46 * @title normal class 47 */ testN4()48 public void testN4() { 49 // @uses dxc.junit.opcodes.checkcast.jm.SubClass 50 // @uses dxc.junit.opcodes.checkcast.jm.SuperClass 51 // @uses dxc.junit.opcodes.checkcast.jm.SuperInterface 52 // @uses dxc.junit.opcodes.checkcast.jm.SuperInterface2 53 54 T_checkcast_2 t = new T_checkcast_2(); 55 assertEquals(5, t.run()); 56 } 57 58 /** 59 * @title expected ClassCastException 60 */ testE1()61 public void testE1() { 62 T_checkcast_1 t = new T_checkcast_1(); 63 try { 64 t.run(this); 65 fail("expected ClassCastException"); 66 } catch (ClassCastException iae) { 67 // expected 68 } 69 } 70 71 /** 72 * @title expected ClassCastException. checkcast [[[Ldxc/junit/opcodes/checkcast/jm/TestStubs$TestStub; 73 * dalvikvm throws ClassCastException as demanded by checkcast, but 74 * does not claim a IllegalAccessError to a private class - ok, 75 * since checkcast does what the spec says it should do. 76 */ testE2()77 public void testE2() { 78 // @uses dxc.junit.opcodes.checkcast.jm.TestStubs$TestStub 79 try { 80 T_checkcast_3 t = new T_checkcast_3(); 81 t.run(); 82 fail("expected ClassCastException"); 83 } catch (ClassCastException cce) { 84 // expected 85 } 86 } 87 88 /** 89 * @title expected NoClassDefFoundError 90 */ testE3()91 public void testE3() { 92 try { 93 T_checkcast_7 t = new T_checkcast_7(); 94 t.run(); 95 fail("expected NoClassDefFoundError"); 96 } catch (NoClassDefFoundError iae) { 97 // expected 98 } catch (VerifyError vfe) { 99 // ok for dalvikvm; early resolution 100 System.out.print("dvmvfe:"); 101 } 102 } 103 104 /** 105 * @constraint 4.8.1.16 106 * @title constant pool index 107 */ testVFE1()108 public void testVFE1() { 109 try { 110 Class.forName("dxc.junit.opcodes.checkcast.jm.T_checkcast_4"); 111 fail("expected a verification exception"); 112 } catch (Throwable t) { 113 DxUtil.checkVerifyException(t); 114 } 115 } 116 117 /** 118 * @constraint 4.8.2.1 119 * @title type of argument - float 120 */ testVFE2()121 public void testVFE2() { 122 try { 123 Class.forName("dxc.junit.opcodes.checkcast.jm.T_checkcast_5"); 124 fail("expected a verification exception"); 125 } catch (Throwable t) { 126 DxUtil.checkVerifyException(t); 127 } 128 } 129 130 /** 131 * @constraint 4.8.2.1 132 * @title number of arguments 133 */ testVFE3()134 public void testVFE3() { 135 try { 136 Class.forName("dxc.junit.opcodes.checkcast.jm.T_checkcast_6"); 137 fail("expected a verification exception"); 138 } catch (Throwable t) { 139 DxUtil.checkVerifyException(t); 140 } 141 } 142 143 /** 144 * @constraint 4.8.1.16 145 * @title constant pool type 146 */ testVFE4()147 public void testVFE4() { 148 try { 149 Class.forName("dxc.junit.opcodes.checkcast.jm.T_checkcast_8"); 150 fail("expected a verification exception"); 151 } catch (Throwable t) { 152 DxUtil.checkVerifyException(t); 153 } 154 } 155 156 } 157