Home | History | Annotate | Download | only in invokestatic
      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.invokestatic;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_1;
     22 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_12;
     23 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_13;
     24 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_14;
     25 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_15;
     26 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_16;
     27 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_17;
     28 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_18;
     29 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_2;
     30 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_4;
     31 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_5;
     32 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_6;
     33 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_7;
     34 import dxc.junit.opcodes.invokestatic.jm.T_invokestatic_8;
     35 
     36 public class Test_invokestatic extends DxTestCase {
     37 
     38     /**
     39      * @title  Static method from library class Math
     40      */
     41     public void testN1() {
     42         T_invokestatic_1 t = new T_invokestatic_1();
     43         assertEquals(1234567, t.run());
     44     }
     45 
     46     /**
     47      * @title  Static method from user class
     48      */
     49     public void testN2() {
     50         // @uses dxc.junit.opcodes.invokestatic.jm.TestClass
     51         T_invokestatic_2 t = new T_invokestatic_2();
     52         assertEquals(777, t.run());
     53     }
     54 
     55     /**
     56      * @title  Check that <clinit> is called
     57      */
     58     public void testN3() {
     59         assertEquals(123456789l, T_invokestatic_4.run());
     60     }
     61 
     62     /**
     63      * @title  Check that monitor is acquired if method is synchronized
     64      */
     65     public void testN4() {
     66         assertTrue(T_invokestatic_12.execute());
     67     }
     68 
     69     /**
     70      * @title  Check that new frame is created by invokestatic and
     71      * arguments are passed to method
     72      */
     73     public void testN5() {
     74         // @uses dxc.junit.opcodes.invokestatic.jm.TestClass
     75         T_invokestatic_15 t = new T_invokestatic_15();
     76         assertTrue(t.run());
     77     }
     78 
     79     /**
     80      * @title  Static protected method from other class in the same package
     81      */
     82     public void testN6() {
     83         // @uses dxc.junit.opcodes.invokestatic.jm.TestClass
     84         T_invokestatic_18 t = new T_invokestatic_18();
     85         assertEquals(888, t.run());
     86     }
     87 
     88     /**
     89      * @title  attempt to call non-static method
     90      *
     91      */
     92     public void testE1() {
     93         try {
     94             T_invokestatic_5 t = new T_invokestatic_5();
     95             t.run();
     96             fail("expected IncompatibleClassChangeError");
     97         } catch (IncompatibleClassChangeError icce) {
     98             // expected
     99         } catch (VerifyError vfe) {
    100             // ok for dalvikvm;
    101             System.out.print("dvmvfe:");
    102         }
    103     }
    104 
    105     /**
    106      * @title  Native method can't be linked
    107      *
    108      */
    109     public void testE2() {
    110         T_invokestatic_6 t = new T_invokestatic_6();
    111         try {
    112             t.run();
    113             fail("expected UnsatisfiedLinkError");
    114         } catch (UnsatisfiedLinkError ule) {
    115             // expected
    116         }
    117     }
    118 
    119     /**
    120      * @title  NoSuchMethodError
    121      */
    122     public void testE3() {
    123         try {
    124             T_invokestatic_7 t = new T_invokestatic_7();
    125             t.run();
    126             fail("expected NoSuchMethodError");
    127         } catch (NoSuchMethodError nsme) {
    128             // expected
    129         } catch (VerifyError vfe) {
    130             // ok for dalvikvm;
    131             System.out.print("dvmvfe:");
    132         }
    133     }
    134 
    135     /**
    136      * @title  Attempt to call private method of other class
    137      *
    138      */
    139     public void testE5() {
    140         // @uses dxc.junit.opcodes.invokestatic.jm.TestClass
    141         try {
    142             T_invokestatic_8 t = new T_invokestatic_8();
    143             t.run();
    144             fail("expected IllegalAccessError");
    145         } catch (IllegalAccessError iae) {
    146             // expected
    147         } catch (VerifyError vfe) {
    148             // ok for dalvikvm;
    149             System.out.print("dvmvfe:");
    150         }
    151     }
    152 
    153     /**
    154      * @title  method has different signature
    155      */
    156     public void testE6() {
    157         // @uses dxc.junit.opcodes.invokestatic.jm.TestClass
    158         try {
    159                T_invokestatic_13 t = new T_invokestatic_13();
    160             t.run();
    161             fail("expected NoSuchMethodError");
    162         } catch (NoSuchMethodError nsme) {
    163             // expected
    164         } catch (VerifyError vfe) {
    165             // ok for dalvikvm;
    166             System.out.print("dvmvfe:");
    167         }
    168     }
    169 
    170     /**
    171      * @title  initialization of referenced class throws exception
    172      */
    173     public void testE7() {
    174         // @uses dxc.junit.opcodes.invokestatic.jm.TestClassInitError
    175         T_invokestatic_14 t = new T_invokestatic_14();
    176         try {
    177             t.run();
    178             fail("expected Error");
    179         } catch (Error e) {
    180             // expected
    181         }
    182     }
    183 
    184     /**
    185      * @title  Attempt to call abstract method of other class
    186      *
    187      */
    188     public void testE8() {
    189         // @uses dxc.junit.opcodes.invokestatic.jm.TestClassAbstract
    190         try {
    191             T_invokestatic_16 t = new T_invokestatic_16();
    192             t.run();
    193             fail("expected IncompatibleClassChangeError");
    194         } catch (IncompatibleClassChangeError iae) {
    195             // expected
    196         } catch (VerifyError vfe) {
    197             // ok for dalvikvm;
    198             System.out.print("dvmvfe:");
    199         }
    200     }
    201 
    202     /**
    203      * @title  Attempt to call protected method of unrelated class
    204      *
    205      */
    206     public void testE9() {
    207         // @uses dxc.junit.opcodes.invokestatic.TestStubs
    208         try {
    209             T_invokestatic_17 t = new T_invokestatic_17();
    210             t.run();
    211             fail("expected IllegalAccessError");
    212         } catch (IllegalAccessError iae) {
    213             // expected
    214         } catch (VerifyError vfe) {
    215             // ok for dalvikvm;
    216             System.out.print("dvmvfe:");
    217         }
    218     }
    219 
    220     /**
    221      * @constraint 4.8.1.13
    222      * @title invalid type into constant pool
    223      */
    224     public void testVFE1() {
    225         try {
    226             Class.forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_3");
    227             fail("expected a verification exception");
    228         } catch (Throwable t) {
    229             DxUtil.checkVerifyException(t);
    230         }
    231     }
    232 
    233     /**
    234      * @constraint 4.8.1.13
    235      * @title invalid index into constant pool table
    236      */
    237     public void testVFE2() {
    238         try {
    239             Class.forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_9");
    240             fail("expected a verification exception");
    241         } catch (Throwable t) {
    242             DxUtil.checkVerifyException(t);
    243         }
    244     }
    245 
    246     /**
    247      * @constraint 4.8.1.14
    248      * @title &lt;clinit&gt; may not be called using invokestatic
    249      */
    250     public void testVFE3() {
    251         try {
    252             Class
    253                     .forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_10");
    254             fail("expected a verification exception");
    255         } catch (Throwable t) {
    256             DxUtil.checkVerifyException(t);
    257         }
    258     }
    259 
    260     /**
    261      * @constraint 4.8.2.1
    262      * @title number of arguments passed to method
    263      */
    264     public void testVFE4() {
    265         try {
    266             Class
    267                     .forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_11");
    268             fail("expected a verification exception");
    269         } catch (Throwable t) {
    270             DxUtil.checkVerifyException(t);
    271         }
    272     }
    273 
    274     /**
    275      * @constraint 4.8.1.14
    276      * @title &lt;init&gt; may not be called using invokestatic
    277      */
    278     public void testVFE5() {
    279         try {
    280             Class
    281                     .forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_19");
    282             fail("expected a verification exception");
    283         } catch (Throwable t) {
    284             DxUtil.checkVerifyException(t);
    285         }
    286     }
    287 
    288     /**
    289      * @constraint 4.8.2.12
    290      * @title types of arguments passed to method
    291      */
    292     public void testVFE6() {
    293         try {
    294             Class
    295                     .forName("dxc.junit.opcodes.invokestatic.jm.T_invokestatic_20");
    296             fail("expected a verification exception");
    297         } catch (Throwable t) {
    298             DxUtil.checkVerifyException(t);
    299         }
    300     }
    301 
    302 }
    303