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.const_class; 18 19 import dot.junit.DxTestCase; 20 import dot.junit.DxUtil; 21 import dot.junit.opcodes.const_class.d.T_const_class_1; 22 import dot.junit.opcodes.const_class.d.T_const_class_2; 23 import dot.junit.opcodes.const_class.d.T_const_class_6; 24 import dot.junit.opcodes.const_class.d.T_const_class_7; 25 26 public class Test_const_class extends DxTestCase { 27 /** 28 * @title const-class v254, java/lang/String 29 */ testN1()30 public void testN1() { 31 T_const_class_1 t = new T_const_class_1(); 32 Class c = t.run(); 33 assertEquals(0, c.getCanonicalName().compareTo("java.lang.String")); 34 } 35 36 /** 37 * @title const-class v254, I 38 */ testN2()39 public void testN2() { 40 T_const_class_2 t = new T_const_class_2(); 41 Class c = t.run(); 42 assertEquals(c.getCanonicalName(), "int"); 43 } 44 45 /** 46 * @title Class definition not found 47 */ testE1()48 public void testE1() { 49 try { 50 T_const_class_6 t = new T_const_class_6(); 51 t.run(); 52 fail("expected a verification exception"); 53 } catch (NoClassDefFoundError e) { 54 // expected 55 } catch(VerifyError e) { 56 // expected 57 } 58 } 59 60 /** 61 * @title Class is not accessible 62 */ testE2()63 public void testE2() { 64 //@uses dot.junit.opcodes.const_class.TestStubs$TestStub 65 //@uses dot.junit.opcodes.const_class.d.T_const_class_7 66 try { 67 T_const_class_7 t = new T_const_class_7(); 68 t.run(); 69 fail("expected a verification exception"); 70 } catch (IllegalAccessError e) { 71 // expected 72 } catch(VerifyError e) { 73 // expected 74 } 75 } 76 77 /** 78 * @constraint A23 79 * @title number of registers 80 */ testVFE1()81 public void testVFE1() { 82 try { 83 Class.forName("dot.junit.opcodes.const_class.d.T_const_class_3"); 84 fail("expected a verification exception"); 85 } catch (Throwable t) { 86 DxUtil.checkVerifyException(t); 87 } 88 } 89 90 /** 91 * @constraint B11 92 * @title When writing to a register that is one half of a register 93 * pair, but not touching the other half, the old register pair gets broken up, and the 94 * other register involved in it becomes undefined 95 */ testVFE2()96 public void testVFE2() { 97 try { 98 Class.forName("dot.junit.opcodes.const_class.d.T_const_class_4"); 99 fail("expected a verification exception"); 100 } catch (Throwable t) { 101 DxUtil.checkVerifyException(t); 102 } 103 } 104 105 /** 106 * @constraint A18 107 * @title constant pool index 108 */ testVFE3()109 public void testVFE3() { 110 try { 111 Class.forName("dot.junit.opcodes.const_class.d.T_const_class_5"); 112 fail("expected a verification exception"); 113 } catch (Throwable t) { 114 DxUtil.checkVerifyException(t); 115 } 116 } 117 118 } 119