Home | History | Annotate | Download | only in invoke_interface
      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_interface;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_1;
     22 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11;
     23 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12;
     24 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13;
     25 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14;
     26 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16;
     27 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_18;
     28 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_20;
     29 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_21;
     30 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3;
     31 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_4;
     32 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_5;
     33 import dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7;
     34 
     35 public class Test_invoke_interface extends DxTestCase {
     36 
     37     /**
     38      * @title invoke interface method
     39      */
     40     public void testN1() {
     41         T_invoke_interface_1 t = new T_invoke_interface_1();
     42         assertEquals(0, t.run("aa", "aa"));
     43         assertEquals(-1, t.run("aa", "bb"));
     44         assertEquals(1, t.run("bb", "aa"));
     45     }
     46 
     47     /**
     48      * @title Check that new frame is created by invoke_interface and
     49      * arguments are passed to method
     50      */
     51     public void testN2() {
     52         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_14
     53         //@uses dot.junit.opcodes.invoke_interface.ITest
     54         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
     55         T_invoke_interface_14 t = new T_invoke_interface_14();
     56         ITestImpl impl = new ITestImpl();
     57         assertEquals(1, t.run(impl));
     58     }
     59 
     60 
     61 
     62     /**
     63      * @title objref is null
     64      */
     65     public void testE3() {
     66         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_3
     67         //@uses dot.junit.opcodes.invoke_interface.ITest
     68         try {
     69             new T_invoke_interface_3(null);
     70             fail("expected NullPointerException");
     71         } catch (NullPointerException npe) {
     72             // expected
     73         }
     74     }
     75 
     76     /**
     77      * @title object doesn't implement interface
     78      */
     79     public void testE4() {
     80         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11
     81         //@uses dot.junit.opcodes.invoke_interface.ITest
     82         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
     83         T_invoke_interface_11 t = new T_invoke_interface_11();
     84         try {
     85             t.run();
     86             fail("expected IncompatibleClassChangeError");
     87         } catch (IncompatibleClassChangeError e) {
     88             // expected
     89         }
     90     }
     91 
     92     /**
     93      * @title dvmInterpFindInterfaceMethod failures were putting NULL Method*s
     94      * in the interface cache, leading to a null pointer deference the second
     95      * time you made the same bad call, with no exception thrown.
     96      * See http://code.google.com/p/android/issues/detail?id=29358 for details.
     97      */
     98     public void testE4_2() {
     99         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11
    100         //@uses dot.junit.opcodes.invoke_interface.ITest
    101         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    102         T_invoke_interface_11 t = new T_invoke_interface_11();
    103         try {
    104             t.run();
    105             fail("expected IncompatibleClassChangeError");
    106         } catch (IncompatibleClassChangeError expected) {
    107         }
    108         try {
    109             t.run();
    110             fail("expected IncompatibleClassChangeError");
    111         } catch (IncompatibleClassChangeError expected) {
    112         }
    113     }
    114 
    115     /**
    116      * @title Native method can't be linked
    117      */
    118     public void testE5() {
    119         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_12
    120         //@uses dot.junit.opcodes.invoke_interface.ITest
    121         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    122         T_invoke_interface_12 t = new T_invoke_interface_12();
    123         ITestImpl impl = new ITestImpl();
    124         try {
    125             t.run(impl);
    126             fail("expected UnsatisfiedLinkError");
    127         } catch (UnsatisfiedLinkError e) {
    128             // expected
    129         }
    130     }
    131 
    132     /**
    133      * @title Attempt to invoke abstract method
    134      */
    135     public void testE6() {
    136         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_13
    137         //@uses dot.junit.opcodes.invoke_interface.ITest
    138         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    139         //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract
    140         T_invoke_interface_13 t = new T_invoke_interface_13();
    141         try {
    142             t.run();
    143             fail("expected AbstractMethodError");
    144         } catch (AbstractMethodError e) {
    145             // expected
    146         }
    147     }
    148 
    149     /**
    150      * @constraint A16
    151      * @title invalid constant pool index
    152      */
    153     public void testVFE1() {
    154         try {
    155             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_2");
    156             fail("expected a verification exception");
    157         } catch (Throwable t) {
    158             DxUtil.checkVerifyException(t);
    159         }
    160     }
    161 
    162     /**
    163      * @constraint A16
    164      * @title The referenced method_id must belong to an interface (not a class).
    165      */
    166     public void testVFE2() {
    167         try {
    168             new T_invoke_interface_4().run();
    169             fail("expected NoSuchMethodError");
    170         } catch (NoSuchMethodError t) {
    171         }
    172     }
    173 
    174     /**
    175      * @constraint B1
    176      * @title number of arguments
    177      */
    178     public void testVFE5() {
    179         //@uses dot.junit.opcodes.invoke_interface.ITest
    180         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    181         try {
    182             new T_invoke_interface_5(new ITestImpl());
    183             fail("expected VerifyError");
    184         } catch (VerifyError t) {
    185         }
    186     }
    187 
    188     /**
    189      * @constraint B1
    190      * @title int is passed instead of objref
    191      */
    192     public void testVFE6() {
    193         try {
    194             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_10");
    195             fail("expected a verification exception");
    196         } catch (Throwable t) {
    197             DxUtil.checkVerifyException(t);
    198         }
    199     }
    200 
    201     /**
    202      * @constraint B9
    203      * @title number of arguments passed to method
    204      */
    205     public void testVFE9() {
    206         try {
    207             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_9");
    208             fail("expected a verification exception");
    209         } catch (Throwable t) {
    210             DxUtil.checkVerifyException(t);
    211         }
    212     }
    213 
    214     /**
    215      * @constraint A15
    216      * @title invoke-interface may not be used to call <init>.
    217      */
    218     public void testVFE10() {
    219         //@uses dot.junit.opcodes.invoke_interface.ITest
    220         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    221         //@uses dot.junit.opcodes.invoke_interface.ITestImplAbstract
    222         try {
    223             new T_invoke_interface_18().run(new ITestImpl());
    224             fail("expected InstantiationError");
    225         } catch (InstantiationError t) {
    226         }
    227     }
    228 
    229     /**
    230      * @constraint A15
    231      * @title invoke-interface may not be used to call <clinit>.
    232      */
    233     public void testVFE11() {
    234         //@uses dot.junit.opcodes.invoke_interface.ITest
    235         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    236         try {
    237             new T_invoke_interface_20().run(new ITestImpl());
    238             fail("expected NoSuchMethodError");
    239         } catch (NoSuchMethodError t) {
    240         }
    241     }
    242 
    243     /**
    244      * @constraint B9
    245      * @title types of arguments passed to method
    246      */
    247     public void testVFE12() {
    248         //@uses dot.junit.opcodes.invoke_interface.ITest
    249         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    250         try {
    251             new T_invoke_interface_21().run(new ITestImpl());
    252             fail("expected VerifyError");
    253         } catch (VerifyError t) {
    254         }
    255     }
    256 
    257     /**
    258      * @constraint A23
    259      * @title number of registers
    260      */
    261     public void testVFE13() {
    262         try {
    263             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_8");
    264             fail("expected a verification exception");
    265         } catch (Throwable t) {
    266             DxUtil.checkVerifyException(t);
    267         }
    268     }
    269 
    270     /**
    271      * @constraint n/a
    272      * @title Attempt to call undefined method.
    273      */
    274     public void testVFE14() {
    275         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_7
    276         //@uses dot.junit.opcodes.invoke_interface.ITest
    277         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    278         try {
    279             new T_invoke_interface_7().run(new ITestImpl());
    280             fail("expected NoSuchMethodError");
    281         } catch (NoSuchMethodError t) {
    282         }
    283     }
    284 
    285     /**
    286      * @constraint n/a
    287      * @title Method has different signature.
    288      */
    289     public void testVFE15() {
    290         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_16
    291         //@uses dot.junit.opcodes.invoke_interface.ITest
    292         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    293         try {
    294             new T_invoke_interface_16().run(new ITestImpl());
    295             fail("expected NoSuchMethodError");
    296         } catch (NoSuchMethodError t) {
    297         }
    298     }
    299 
    300 
    301     /**
    302      * @constraint B6
    303      * @title instance methods may only be invoked on already initialized instances.
    304      */
    305     public void testVFE21() {
    306         //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22
    307         //@uses dot.junit.opcodes.invoke_interface.ITest
    308         //@uses dot.junit.opcodes.invoke_interface.ITestImpl
    309         try {
    310             Class.forName("dot.junit.opcodes.invoke_interface.d.T_invoke_interface_22");
    311             fail("expected a verification exception");
    312         } catch (Throwable t) {
    313             DxUtil.checkVerifyException(t);
    314         }
    315     }
    316 }
    317