Home | History | Annotate | Download | only in invokeinterface
      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.invokeinterface;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.invokeinterface.jm.ITestImpl;
     22 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_1;
     23 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_11;
     24 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_12;
     25 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_13;
     26 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_14;
     27 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_15;
     28 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_16;
     29 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_17;
     30 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_19;
     31 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_3;
     32 import dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_7;
     33 
     34 public class Test_invokeinterface extends DxTestCase {
     35 
     36     /**
     37      * @title normal test
     38      */
     39     public void testN1() {
     40         T_invokeinterface_1 t = new T_invokeinterface_1();
     41         assertEquals(0, t.run("aa", "aa"));
     42         assertEquals(-1, t.run("aa", "bb"));
     43         assertEquals(1, t.run("bb", "aa"));
     44     }
     45 
     46     /**
     47      * @title  Check that new frame is created by invokeinterface and
     48      * arguments are passed to method
     49      */
     50     public void testN2() {
     51         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
     52         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
     53         T_invokeinterface_14 t = new T_invokeinterface_14();
     54         ITestImpl impl = new ITestImpl();
     55         assertEquals(1, t.run(impl));
     56     }
     57 
     58     /**
     59      * @title  Check that monitor is acquired if method is synchronized
     60      */
     61     public void testN3() {
     62         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
     63         assertTrue(T_invokeinterface_19.execute());
     64     }
     65 
     66 
     67     /**
     68      * @title  method doesn't exist
     69      */
     70     public void testE1() {
     71         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
     72         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
     73         try {
     74             T_invokeinterface_7 t = new T_invokeinterface_7();
     75             ITestImpl impl = new ITestImpl();
     76             t.run(impl);
     77             fail("expected NoSuchMethodError");
     78         } catch (NoSuchMethodError e) {
     79             // expected
     80         } catch (VerifyError vfe) {
     81             // ok for dalvikvm;
     82             System.out.print("dvmvfe:");
     83         }
     84     }
     85 
     86     /**
     87      * @title  method has different signature
     88      */
     89     public void testE2() {
     90         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
     91         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
     92         try {
     93             T_invokeinterface_16 t = new T_invokeinterface_16();
     94             ITestImpl impl = new ITestImpl();
     95             t.run(impl);
     96             fail("expected NoSuchMethodError");
     97         } catch (NoSuchMethodError e) {
     98             // expected
     99         } catch (VerifyError vfe) {
    100             // ok for dalvikvm;
    101             System.out.print("dvmvfe:");
    102         }
    103     }
    104 
    105     /**
    106      * @title expected NullPointerException
    107      */
    108     public void testE3() {
    109         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    110         try {
    111             new T_invokeinterface_3(null);
    112             fail("expected NullPointerException");
    113         } catch (NullPointerException npe) {
    114             // expected
    115         }
    116     }
    117 
    118     /**
    119      * @title  object doesn't implement interface
    120      */
    121     public void testE4() {
    122         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    123         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
    124         T_invokeinterface_11 t = new T_invokeinterface_11();
    125         ITestImpl impl = new ITestImpl();
    126         try {
    127             t.run(impl);
    128             fail("expected IncompatibleClassChangeError");
    129         } catch (IncompatibleClassChangeError e) {
    130             // expected
    131         }
    132     }
    133 
    134     /**
    135      * @title  Native method can't be linked
    136      */
    137     public void testE5() {
    138         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    139         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
    140         T_invokeinterface_12 t = new T_invokeinterface_12();
    141         ITestImpl impl = new ITestImpl();
    142         try {
    143             t.run(impl);
    144             fail("expected UnsatisfiedLinkError");
    145         } catch (UnsatisfiedLinkError e) {
    146             // expected
    147         }
    148     }
    149 
    150     /**
    151      * @title  Attempt to invoke abstract method
    152      */
    153     public void testE6() {
    154         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    155         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImplAbstract
    156         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
    157         try {
    158             T_invokeinterface_13 t = new T_invokeinterface_13();
    159             ITestImpl impl = new ITestImpl();
    160             t.run(impl);
    161             fail("expected AbstractMethodError");
    162         } catch (AbstractMethodError e) {
    163             // expected
    164         } catch (VerifyError vfe) {
    165             // ok for dalvikvm;
    166             System.out.print("dvmvfe:");
    167         }
    168     }
    169 
    170     /**
    171      * @title  Attempt to invoke static method
    172      */
    173     public void testE7() {
    174         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    175         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImplAbstract
    176         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
    177         try {
    178             T_invokeinterface_15 t = new T_invokeinterface_15();
    179             ITestImpl impl = new ITestImpl();
    180             t.run(impl);
    181             fail("expected AbstractMethodError");
    182         } catch (AbstractMethodError e) {
    183             // expected
    184         } catch (VerifyError vfe) {
    185             // ok for dalvikvm;
    186             System.out.print("dvmvfe:");
    187         }
    188     }
    189 
    190     /**
    191      * @title  Attempt to invoke non-public interface method
    192      */
    193     public void testE8() {
    194         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    195         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImplAbstract
    196         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImpl
    197         try {
    198             T_invokeinterface_17 t = new T_invokeinterface_17();
    199             ITestImpl impl = new ITestImpl();
    200             t.run(impl);
    201             fail("expected IllegalAccessError");
    202         } catch (IllegalAccessError e) {
    203             // expected
    204         } catch (VerifyError vfe) {
    205             // ok for dalvikvm;
    206             System.out.print("dvmvfe:");
    207         }
    208     }
    209 
    210     /**
    211      * @constraint 4.8.1.15
    212      * @title valid index into constant pool table
    213      */
    214     public void testVFE1() {
    215         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    216         try {
    217             Class
    218                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_2");
    219             fail("expected a verification exception");
    220         } catch (Throwable t) {
    221             DxUtil.checkVerifyException(t);
    222         }
    223     }
    224 
    225     /**
    226      * @constraint 4.8.1.15
    227      * @title invalid index into constant pool table
    228      */
    229     public void testVFE2() {
    230         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    231         try {
    232             Class
    233                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_23");
    234             fail("expected a verification exception");
    235         } catch (Throwable t) {
    236             DxUtil.checkVerifyException(t);
    237         }
    238     }
    239 
    240     /**
    241      * @constraint 4.8.2.1
    242      * @title number of arguments
    243      */
    244     public void testVFE5() {
    245         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    246         try {
    247             Class
    248                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_5");
    249             fail("expected a verification exception");
    250         } catch (Throwable t) {
    251             DxUtil.checkVerifyException(t);
    252         }
    253     }
    254 
    255     /**
    256      * @constraint 4.8.2.1
    257      * @title type of argument - int
    258      */
    259     public void testVFE6() {
    260         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    261         try {
    262             Class
    263                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_10");
    264             fail("expected a verification exception");
    265         } catch (Throwable t) {
    266             DxUtil.checkVerifyException(t);
    267         }
    268     }
    269 
    270     /**
    271      * @constraint 4.8.2.15
    272      * @title args_size value must match number of arguments
    273      */
    274     public void testVFE7() {
    275         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    276         try {
    277             Class
    278                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_8");
    279             fail("expected a verification exception");
    280         } catch (Throwable t) {
    281             DxUtil.checkVerifyException(t);
    282         }
    283     }
    284 
    285     /**
    286      * @constraint 4.8.2.15
    287      * @title 4th operand must be zero
    288      */
    289     public void testVFE8() {
    290         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    291         try {
    292             Class
    293                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_6");
    294             fail("expected a verification exception");
    295         } catch (Throwable t) {
    296             DxUtil.checkVerifyException(t);
    297         }
    298     }
    299 
    300     /**
    301      * @constraint 4.8.2.1
    302      * @title number of arguments passed to method
    303      */
    304     public void testVFE9() {
    305         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    306         try {
    307             Class
    308                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_9");
    309             fail("expected a verification exception");
    310         } catch (Throwable t) {
    311             DxUtil.checkVerifyException(t);
    312         }
    313     }
    314 
    315     /**
    316      * @constraint 4.8.2.14
    317      * @title only invokespecial may be used to call <init>
    318      */
    319     public void testVFE10() {
    320         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    321         //@uses dxc.junit.opcodes.invokeinterface.jm.ITestImplAbstract
    322         try {
    323             Class
    324                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_18");
    325             fail("expected a verification exception");
    326         } catch (Throwable t) {
    327             DxUtil.checkVerifyException(t);
    328         }
    329     }
    330 
    331     /**
    332      * @constraint 4.8.2.14
    333      * @title only invokespecial may be used to call <clinit>
    334      */
    335     public void testVFE11() {
    336         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    337         try {
    338             Class
    339                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_20");
    340             fail("expected a verification exception");
    341         } catch (Throwable t) {
    342             DxUtil.checkVerifyException(t);
    343         }
    344     }
    345 
    346     /**
    347      * @constraint 4.8.2.12
    348      * @title types of arguments passed to method
    349      */
    350     public void testVFE12() {
    351         //@uses dxc.junit.opcodes.invokeinterface.jm.ITest
    352         try {
    353             Class
    354                     .forName("dxc.junit.opcodes.invokeinterface.jm.T_invokeinterface_21");
    355             fail("expected a verification exception");
    356         } catch (Throwable t) {
    357             DxUtil.checkVerifyException(t);
    358         }
    359     }
    360 
    361 }
    362