Home | History | Annotate | Download | only in invoke_direct_range
      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.invoke_direct_range;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12;
     22 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13;
     23 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_16;
     24 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_2;
     25 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_21;
     26 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_26;
     27 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6;
     28 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_7;
     29 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_8;
     30 import dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_9;
     31 
     32 public class Test_invoke_direct_range extends DxTestCase {
     33 
     34     /**
     35      * @title private method call
     36      */
     37     public void testN2() {
     38         T_invoke_direct_range_2 t = new T_invoke_direct_range_2();
     39         assertEquals(345, t.run());
     40     }
     41 
     42 
     43     /**
     44      * @title Check that new frame is created by invoke_direct_range
     45      */
     46     public void testN7() {
     47         T_invoke_direct_range_21 t = new T_invoke_direct_range_21();
     48         assertEquals(1, t.run());
     49     }
     50 
     51 
     52 
     53     /**
     54      * @title objref is null
     55      */
     56     public void testE3() {
     57         T_invoke_direct_range_8 t = new T_invoke_direct_range_8();
     58         try {
     59             assertEquals(5, t.run());
     60             fail("expected NullPointerException");
     61         } catch (NullPointerException e) {
     62             // expected
     63         }
     64     }
     65 
     66     /**
     67      * @title Native method can't be linked
     68      */
     69     public void testE5() {
     70         T_invoke_direct_range_9 t = new T_invoke_direct_range_9();
     71         try {
     72             assertEquals(5, t.run());
     73             fail("expected UnsatisfiedLinkError");
     74         } catch (UnsatisfiedLinkError e) {
     75             // expected
     76         }
     77     }
     78 
     79     /**
     80      * @constraint A14
     81      * @title invalid constant pool index
     82      */
     83     public void testVFE1() {
     84         try {
     85             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_3");
     86             fail("expected a verification exception");
     87         } catch (Throwable t) {
     88             DxUtil.checkVerifyException(t);
     89         }
     90     }
     91 
     92     /**
     93      * @constraint A15
     94      * @title invoke-direct may not be used to invoke <clinit>
     95      */
     96     public void testVFE3() {
     97         try {
     98             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_4");
     99             fail("expected a verification exception");
    100         } catch (Throwable t) {
    101             DxUtil.checkVerifyException(t);
    102         }
    103     }
    104 
    105     /**
    106      * @constraint B4
    107      * @title invoke-direct target must be in self or superclass
    108      */
    109     public void testVFE4() {
    110         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_6
    111         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
    112         try {
    113             new T_invoke_direct_range_6();
    114             fail("expected NoSuchMethodError");
    115         } catch (NoSuchMethodError t) {
    116         }
    117     }
    118 
    119     /**
    120      * @constraint B1
    121      * @title number of arguments
    122      */
    123     public void testVFE5() {
    124         try {
    125             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_5");
    126             fail("expected a verification exception");
    127         } catch (Throwable t) {
    128             DxUtil.checkVerifyException(t);
    129         }
    130     }
    131 
    132     /**
    133      * @constraint B1
    134      * @title int is passed instead of obj ref
    135      */
    136     public void testVFE6() {
    137         try {
    138             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_10");
    139             fail("expected a verification exception");
    140         } catch (Throwable t) {
    141             DxUtil.checkVerifyException(t);
    142         }
    143     }
    144 
    145 
    146     /**
    147      * @constraint B9
    148      * @title number of arguments passed to method
    149      */
    150     public void testVFE8() {
    151         try {
    152             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_14");
    153             fail("expected a verification exception");
    154         } catch (Throwable t) {
    155             DxUtil.checkVerifyException(t);
    156         }
    157     }
    158 
    159     /**
    160      * @constraint B9
    161      * @title types of arguments passed to method
    162      */
    163     public void testVFE9() {
    164         try {
    165             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_24");
    166             fail("expected a verification exception");
    167         } catch (Throwable t) {
    168             DxUtil.checkVerifyException(t);
    169         }
    170     }
    171 
    172     /**
    173      * @constraint B10
    174      * @title assignment incompatible references when accessing protected method
    175      */
    176     public void testVFE10() {
    177         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25
    178         //@uses dot.junit.opcodes.invoke_direct_range.TPlain
    179         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
    180         try {
    181             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25");
    182             fail("expected a verification exception");
    183         } catch (Throwable t) {
    184             DxUtil.checkVerifyException(t);
    185         }
    186     }
    187 
    188     /**
    189      * @constraint B5
    190      * @title  Superclass' method call
    191      */
    192     public void testVFE11() {
    193         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_25
    194         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
    195         try {
    196             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_1");
    197             fail("expected a verification exception");
    198         } catch (Throwable t) {
    199             DxUtil.checkVerifyException(t);
    200         }
    201     }
    202 
    203     /**
    204      * @constraint A23
    205      * @title number of registers
    206      */
    207     public void testVFE12() {
    208         try {
    209             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_15");
    210             fail("expected a verification exception");
    211         } catch (Throwable t) {
    212             DxUtil.checkVerifyException(t);
    213         }
    214     }
    215 
    216 
    217     /**
    218      * @constraint n/a
    219      * @title Attempt to call undefined method.
    220      */
    221     public void testVFE13() {
    222         try {
    223             new T_invoke_direct_range_7().run();
    224             fail("expected NoSuchMethodError");
    225         } catch (NoSuchMethodError t) {
    226         }
    227     }
    228 
    229     /**
    230      * @constraint n/a
    231      * @title Method has different signature.
    232      */
    233     public void testVFE14() {
    234         try {
    235             new T_invoke_direct_range_16().run();
    236             fail("expected NoSuchMethodError");
    237         } catch (NoSuchMethodError t) {
    238         }
    239     }
    240 
    241     /**
    242      * @constraint n/a
    243      * @title Attempt to invoke static method. Java throws IncompatibleClassChangeError
    244      * on first access but Dalvik throws VerifyError on class loading.
    245      */
    246     public void testVFE15() {
    247         try {
    248             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_11");
    249             fail("expected a verification exception");
    250         } catch (Throwable t) {
    251             DxUtil.checkVerifyException(t);
    252         }
    253     }
    254 
    255 
    256     /**
    257      * @constraint n/a
    258      * @title Attempt to invoke private method of superclass. Java throws IllegalAccessError
    259      * on first access but Dalvik throws VerifyError on class loading.
    260      */
    261     public void testVFE16() {
    262         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_12
    263         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
    264         try {
    265             new T_invoke_direct_range_12().run();
    266             fail("expected IllegalAccessError");
    267         } catch (IllegalAccessError t) {
    268         }
    269     }
    270 
    271 
    272     /**
    273      * @constraint n/a
    274      * @title Attempt to invoke abstract method
    275      */
    276     public void testVFE17() {
    277         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_13
    278         //@uses dot.junit.opcodes.invoke_direct_range.TAbstract
    279         try {
    280             new T_invoke_direct_range_13().run();
    281             fail("expected NoSuchMethodError or verification exception");
    282         } catch (NoSuchMethodError t) {
    283         } catch (Throwable t) {
    284             DxUtil.checkVerifyException(t);
    285         }
    286     }
    287 
    288     /**
    289      * @constraint B5
    290      * @title An instance initializer must only be invoked on an uninitialized instance.
    291      */
    292     public void testVFE18() {
    293         try {
    294             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_17");
    295             fail("expected a verification exception");
    296         } catch (Throwable t) {
    297             DxUtil.checkVerifyException(t);
    298         }
    299     }
    300 
    301     /**
    302      * @constraint B8
    303      * @title attempt to access inherited instance field before <init> is called
    304      */
    305     public void testVFE19() {
    306         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18
    307         //@uses dot.junit.opcodes.invoke_direct_range.TSuper
    308         try {
    309             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_18");
    310             fail("expected a verification exception");
    311         } catch (Throwable t) {
    312             DxUtil.checkVerifyException(t);
    313         }
    314     }
    315 
    316     /**
    317      * @constraint A14
    318      * @title attempt to invoke interface method
    319      */
    320     public void testVFE20() {
    321         //@uses dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_26
    322         try {
    323             new T_invoke_direct_range_26().run();
    324             fail("expected a verification exception");
    325         } catch (Throwable t) {
    326             DxUtil.checkVerifyException(t);
    327         }
    328     }
    329 
    330     /**
    331      * @constraint B6
    332      * @title instance methods may only be invoked on already initialized instances.
    333      */
    334     public void testVFE21() {
    335         try {
    336             Class.forName("dot.junit.opcodes.invoke_direct_range.d.T_invoke_direct_range_27");
    337             fail("expected a verification exception");
    338         } catch (Throwable t) {
    339             DxUtil.checkVerifyException(t);
    340         }
    341     }
    342 }
    343