Home | History | Annotate | Download | only in invoke_super_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_super_range;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_1;
     22 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_10;
     23 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_14;
     24 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_15;
     25 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_17;
     26 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_18;
     27 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_19;
     28 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_2;
     29 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_20;
     30 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_24;
     31 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_4;
     32 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_5;
     33 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_6;
     34 import dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_7;
     35 
     36 public class Test_invoke_super_range extends DxTestCase {
     37 
     38     /**
     39      * @title invoke method of superclass
     40      */
     41     public void testN1() {
     42         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_1
     43         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
     44         T_invoke_super_range_1 t = new T_invoke_super_range_1();
     45         assertEquals(5, t.run());
     46     }
     47 
     48 
     49     /**
     50      * @title Invoke protected method of superclass
     51      */
     52     public void testN3() {
     53         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_7
     54         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
     55         T_invoke_super_range_7 t = new T_invoke_super_range_7();
     56         assertEquals(5, t.run());
     57     }
     58 
     59     /**
     60      * @title Check that new frame is created by invoke_super_range and
     61      * arguments are passed to method
     62      */
     63     public void testN5() {
     64         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_14
     65         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
     66         T_invoke_super_range_14 t = new T_invoke_super_range_14();
     67         assertTrue(t.run());
     68     }
     69 
     70     /**
     71      * @title Recursion of method lookup procedure
     72      */
     73     public void testN6() {
     74         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_17
     75         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
     76         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper2
     77         T_invoke_super_range_17 t = new T_invoke_super_range_17();
     78         assertEquals(5, t.run());
     79     }
     80 
     81     /**
     82      * @title obj ref is null
     83      */
     84     public void testE1() {
     85         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_1
     86         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
     87         T_invoke_super_range_2 t = new T_invoke_super_range_2();
     88         try {
     89             t.run();
     90             fail("expected NullPointerException");
     91         } catch (NullPointerException npe) {
     92             // expected
     93         }
     94     }
     95 
     96     /**
     97      * @title Native method can't be linked
     98      */
     99     public void testE2() {
    100         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_4
    101         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    102         T_invoke_super_range_4 t = new T_invoke_super_range_4();
    103         try {
    104             t.run();
    105             fail("expected UnsatisfiedLinkError");
    106         } catch (UnsatisfiedLinkError ule) {
    107             // expected
    108         }
    109     }
    110 
    111     /**
    112      * @title Attempt to invoke abstract method
    113      */
    114     public void testE4() {
    115         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_6
    116         //@uses dot.junit.opcodes.invoke_super_range.ATest
    117         T_invoke_super_range_6 t = new T_invoke_super_range_6();
    118         try {
    119             t.run();
    120             fail("expected AbstractMethodError");
    121         } catch (AbstractMethodError iae) {
    122             // expected
    123         }
    124     }
    125 
    126     /**
    127      * @constraint A14
    128      * @title invalid constant pool index
    129      */
    130     public void testVFE1() {
    131         try {
    132             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_8");
    133             fail("expected a verification exception");
    134         } catch (Throwable t) {
    135             DxUtil.checkVerifyException(t);
    136         }
    137     }
    138 
    139     /**
    140      * @constraint A15
    141      * @title <clinit> may not be called using invoke-super
    142      */
    143     public void testVFE3() {
    144         try {
    145             new T_invoke_super_range_10().run();
    146             fail("expected a verification exception");
    147         } catch (Throwable t) {
    148             DxUtil.checkVerifyException(t);
    149         }
    150     }
    151 
    152     /**
    153      * @constraint B1
    154      * @title number of arguments passed to method
    155      */
    156     public void testVFE4() {
    157         try {
    158             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_11");
    159             fail("expected a verification exception");
    160         } catch (Throwable t) {
    161             DxUtil.checkVerifyException(t);
    162         }
    163     }
    164 
    165     /**
    166      * @constraint B9
    167      * @title types of arguments passed to method.
    168      */
    169     public void testVFE5() {
    170         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_12
    171         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    172         try {
    173             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_12");
    174             fail("expected a verification exception");
    175         } catch (Throwable t) {
    176             DxUtil.checkVerifyException(t);
    177         }
    178     }
    179 
    180     /**
    181      * @constraint A15
    182      * @title <init> may not be called using invoke_super_range
    183      */
    184     public void testVFE6() {
    185         try {
    186             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_16");
    187             fail("expected a verification exception");
    188         } catch (Throwable t) {
    189             DxUtil.checkVerifyException(t);
    190         }
    191     }
    192 
    193     /**
    194      * @constraint B10
    195      * @title assignment incompatible references when accessing
    196      *                  protected method
    197      */
    198     public void testVFE8() {
    199         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_22
    200         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    201         //@uses dot.junit.opcodes.invoke_super_range.d.TPlain
    202         try {
    203             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_22");
    204             fail("expected a verification exception");
    205         } catch (Throwable t) {
    206             DxUtil.checkVerifyException(t);
    207         }
    208     }
    209 
    210     /**
    211      * @constraint B10
    212      * @title assignment incompatible references when accessing
    213      *                  public method
    214      */
    215     public void testVFE9() {
    216         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_23
    217         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    218         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper2
    219         try {
    220             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_23");
    221             fail("expected a verification exception");
    222         } catch (Throwable t) {
    223             DxUtil.checkVerifyException(t);
    224         }
    225     }
    226 
    227     /**
    228      * @constraint n/a
    229      * @title Attempt to call static method.
    230      */
    231     public void testVFE10() {
    232         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_5
    233         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    234          try {
    235              new T_invoke_super_range_5().run();
    236              fail("expected IncompatibleClassChangeError");
    237          } catch (IncompatibleClassChangeError t) {
    238          }
    239     }
    240 
    241 
    242     /**
    243      * @constraint n/a
    244      * @title Attempt to invoke non-existing method.
    245      */
    246     public void testVFE12() {
    247          try {
    248              new T_invoke_super_range_15().run();
    249              fail("expected NoSuchMethodError");
    250          } catch (NoSuchMethodError t) {
    251          }
    252     }
    253 
    254     /**
    255      * @constraint n/a
    256      * @title Attempt to invoke private method of other class.
    257      */
    258     public void testVFE13() {
    259         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_18
    260         //@uses dot.junit.opcodes.invoke_super_range.TestStubs
    261          try {
    262              new T_invoke_super_range_18().run(new TestStubs());
    263              fail("expected IllegalAccessError");
    264          } catch (IllegalAccessError t) {
    265          }
    266     }
    267 
    268     /**
    269      * @constraint B12
    270      * @title Attempt to invoke protected method of unrelated class.
    271      */
    272     public void testVFE14() {
    273         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_20
    274         //@uses dot.junit.opcodes.invoke_super_range.TestStubs
    275          try {
    276              new T_invoke_super_range_20().run(new TestStubs());
    277              fail("expected IllegalAccessError");
    278          } catch (IllegalAccessError t) {
    279          }
    280     }
    281 
    282     /**
    283      * @constraint n/a
    284      * @title Method has different signature.
    285      */
    286     public void testVFE15() {
    287         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_19
    288         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    289          try {
    290              new T_invoke_super_range_19().run();
    291              fail("expected NoSuchMethodError");
    292          } catch (NoSuchMethodError t) {
    293          }
    294     }
    295 
    296     /**
    297      * @constraint n/a
    298      * @title invoke-super/range shall be used to invoke private methods
    299      */
    300     public void testVFE16() {
    301         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_13
    302         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    303          try {
    304              Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_13");
    305              fail("expected a verification exception");
    306          } catch (Throwable t) {
    307              DxUtil.checkVerifyException(t);
    308          }
    309     }
    310 
    311     /**
    312      * @constraint A23
    313      * @title number of registers
    314      */
    315     public void testVFE17() {
    316         try {
    317             Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_9");
    318             fail("expected a verification exception");
    319         } catch (Throwable t) {
    320             DxUtil.checkVerifyException(t);
    321         }
    322     }
    323 
    324     /**
    325      * @constraint A14
    326      * @title attempt to invoke interface method
    327      */
    328     public void testVFE18() {
    329         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_24
    330         try {
    331             new T_invoke_super_range_24().run();
    332             fail("expected a verification exception");
    333         } catch (Throwable t) {
    334             DxUtil.checkVerifyException(t);
    335         }
    336     }
    337 
    338     /**
    339      * @constraint B6
    340      * @title instance methods may only be invoked on already initialized instances.
    341      */
    342     public void testVFE19() {
    343         //@uses dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_25
    344         //@uses dot.junit.opcodes.invoke_super_range.d.TSuper
    345          try {
    346              Class.forName("dot.junit.opcodes.invoke_super_range.d.T_invoke_super_range_25");
    347              fail("expected a verification exception");
    348          } catch (Throwable t) {
    349              DxUtil.checkVerifyException(t);
    350          }
    351     }
    352 
    353 }
    354