Home | History | Annotate | Download | only in getstatic
      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.getstatic;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.getstatic.jm.T_getstatic_1;
     22 import dxc.junit.opcodes.getstatic.jm.T_getstatic_10;
     23 import dxc.junit.opcodes.getstatic.jm.T_getstatic_11;
     24 import dxc.junit.opcodes.getstatic.jm.T_getstatic_12;
     25 import dxc.junit.opcodes.getstatic.jm.T_getstatic_2;
     26 import dxc.junit.opcodes.getstatic.jm.T_getstatic_5;
     27 import dxc.junit.opcodes.getstatic.jm.T_getstatic_6;
     28 import dxc.junit.opcodes.getstatic.jm.T_getstatic_7;
     29 import dxc.junit.opcodes.getstatic.jm.T_getstatic_8;
     30 import dxc.junit.opcodes.getstatic.jm.T_getstatic_9;
     31 
     32 public class Test_getstatic extends DxTestCase {
     33 
     34     /**
     35      * @title  type - int
     36      */
     37     public void testN1() {
     38         T_getstatic_1 t = new T_getstatic_1();
     39         assertEquals(5, t.run());
     40     }
     41 
     42     /**
     43      * @title  type - double
     44      */
     45     public void testN2() {
     46         T_getstatic_2 t = new T_getstatic_2();
     47         assertEquals(123d, t.run());
     48     }
     49 
     50     /**
     51      * @title  access protected field from subclass
     52      */
     53     public void testN3() {
     54         // @uses dxc.junit.opcodes.getstatic.jm.T_getstatic_1
     55         T_getstatic_11 t = new T_getstatic_11();
     56         assertEquals(10, t.run());
     57     }
     58 
     59     /**
     60      * @title  attempt to access non-static field
     61      */
     62     public void testE1() {
     63         T_getstatic_5 t = new T_getstatic_5();
     64         try {
     65             t.run();
     66             fail("expected IncompatibleClassChangeError");
     67         } catch (IncompatibleClassChangeError e) {
     68             // expected
     69         }
     70     }
     71 
     72     /**
     73      * @title  attempt to access of non-accessible field
     74      */
     75     public void testE2() {
     76         // @uses dxc.junit.opcodes.getstatic.TestStubs
     77         try {
     78             T_getstatic_6 t = new T_getstatic_6();
     79             t.run();
     80             fail("expected IllegalAccessError");
     81         } catch (IllegalAccessError iae) {
     82             // expected
     83         } catch (VerifyError vfe) {
     84             // ok for dalvikvm;
     85             System.out.print("dvmvfe:");
     86         }
     87     }
     88 
     89     /**
     90      * @title expected NoClassDefFoundError
     91      */
     92     public void testE3() {
     93         try {
     94             T_getstatic_7 t = new T_getstatic_7();
     95             t.run();
     96             fail("expected NoClassDefFoundError");
     97         } catch (NoClassDefFoundError e) {
     98             // expected
     99         } catch (VerifyError vfe) {
    100             // ok for dalvikvm;
    101             System.out.print("dvmvfe:");
    102         }
    103     }
    104 
    105     /**
    106      * @title expected NoSuchFieldError
    107      */
    108     public void testE4() {
    109         try {
    110                T_getstatic_8 t = new T_getstatic_8();
    111             t.run();
    112             fail("expected NoSuchFieldError");
    113         } catch (NoSuchFieldError e) {
    114             // expected
    115         } catch (VerifyError vfe) {
    116             // ok for dalvikvm;
    117             System.out.print("dvmvfe:");
    118         }
    119     }
    120 
    121     /**
    122      * @title  attempt to get int from float field
    123      */
    124     public void testE5() {
    125         try {
    126             T_getstatic_10 t = new T_getstatic_10();
    127             t.run();
    128             fail("expected NoSuchFieldError");
    129         } catch (NoSuchFieldError e) {
    130             // expected
    131         } catch (VerifyError vfe) {
    132             // ok for dalvikvm;
    133             System.out.print("dvmvfe:");
    134         }
    135     }
    136 
    137     /**
    138      * @title  initialization of referenced class throws exception
    139      */
    140     public void testE6() {
    141         // @uses dxc.junit.opcodes.getstatic.jm.StubInitError
    142         T_getstatic_9 t = new T_getstatic_9();
    143         try {
    144             t.run();
    145             fail("expected Error");
    146         } catch (Error e) {
    147             // expected
    148         }
    149     }
    150 
    151     //  FIXME: "fail" commented out temporarily - check
    152     /**
    153      * @title  attempt to read superclass' private field from subclass
    154      *
    155      * FIXME: is this a JVM bug?
    156      */
    157     public void testE7() {
    158         // @uses dxc.junit.opcodes.getstatic.jm.T_getstatic_1
    159         try {
    160             T_getstatic_12 t = new T_getstatic_12();
    161             t.run();
    162             //fail("expected IllegalAccessError");
    163         } catch (IllegalAccessError e) {
    164             // expected
    165         } catch (VerifyError vfe) {
    166             // ok for dalvikvm;
    167             System.out.print("dvmvfe:");
    168         }
    169     }
    170 
    171     /**
    172      * @constraint 4.8.1.12
    173      * @title constant pool index
    174      */
    175     public void testVFE1() {
    176         try {
    177             Class.forName("dxc.junit.opcodes.getstatic.jm.T_getstatic_4");
    178             fail("expected a verification exception");
    179         } catch (Throwable t) {
    180             DxUtil.checkVerifyException(t);
    181         }
    182     }
    183 
    184     /**
    185      * @constraint 4.8.2.5
    186      * @title stack size
    187      */
    188     public void testVFE2() {
    189         try {
    190             Class.forName("dxc.junit.opcodes.getstatic.jm.T_getstatic_3");
    191             fail("expected a verification exception");
    192         } catch (Throwable t) {
    193             DxUtil.checkVerifyException(t);
    194         }
    195     }
    196 
    197     /**
    198      * @constraint 4.8.1.12
    199      * @title constant pool type
    200      */
    201     public void testVFE3() {
    202         try {
    203             Class.forName("dxc.junit.opcodes.getstatic.jm.T_getstatic_13");
    204             fail("expected a verification exception");
    205         } catch (Throwable t) {
    206             DxUtil.checkVerifyException(t);
    207         }
    208     }
    209 }
    210