Home | History | Annotate | Download | only in aget_object
      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.aget_object;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.aget_object.d.T_aget_object_1;
     22 import dot.junit.opcodes.aget_object.d.T_aget_object_8;
     23 
     24 
     25 public class Test_aget_object extends DxTestCase {
     26      /**
     27      * @title get reference from array
     28      */
     29     public void testN1() {
     30         T_aget_object_1 t = new T_aget_object_1();
     31         String[] arr = new String[] {"a", "b"};
     32         assertEquals("a", t.run(arr, 0));
     33     }
     34 
     35     /**
     36      * @title  get reference from array
     37      */
     38     public void testN2() {
     39         T_aget_object_1 t = new T_aget_object_1();
     40         String[] arr = new String[] {"a", "b"};
     41         assertEquals("b", t.run(arr, 1));
     42     }
     43 
     44     /**
     45      * @title expected ArrayIndexOutOfBoundsException
     46      */
     47     public void testE1() {
     48         T_aget_object_1 t = new T_aget_object_1();
     49         String[] arr = new String[] {"a", "b"};
     50         try {
     51             t.run(arr, 2);
     52             fail("expected ArrayIndexOutOfBoundsException");
     53         } catch (ArrayIndexOutOfBoundsException aioobe) {
     54             // expected
     55         }
     56     }
     57 
     58     /**
     59      * @title expected ArrayIndexOutOfBoundsException (negative index)
     60      */
     61     public void testE2() {
     62         T_aget_object_1 t = new T_aget_object_1();
     63         String[] arr = new String[] {"a", "b"};
     64         try {
     65             t.run(arr, -1);
     66             fail("expected ArrayIndexOutOfBoundsException");
     67         } catch (ArrayIndexOutOfBoundsException aioobe) {
     68             // expected
     69         }
     70     }
     71 
     72     /**
     73      * @title expected NullPointerException
     74      */
     75     public void testE3() {
     76         T_aget_object_1 t = new T_aget_object_1();
     77         String[] arr = null;
     78         try {
     79             t.run(arr, 0);
     80             fail("expected NullPointerException");
     81         } catch (NullPointerException npe) {
     82             // expected
     83         }
     84     }
     85 
     86     /**
     87      * @constraint B1
     88      * @title types of arguments - array, double
     89      */
     90     public void testVFE1() {
     91         try {
     92             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_2");
     93             fail("expected a verification exception");
     94         } catch (Throwable t) {
     95             DxUtil.checkVerifyException(t);
     96         }
     97     }
     98 
     99     /**
    100      * @constraint B1
    101      * @title types of arguments - array, long
    102      */
    103     public void testVFE2() {
    104         try {
    105             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_3");
    106             fail("expected a verification exception");
    107         } catch (Throwable t) {
    108             DxUtil.checkVerifyException(t);
    109         }
    110     }
    111 
    112     /**
    113      * @constraint B1
    114      * @title types of arguments - Object, int
    115      */
    116     public void testVFE3() {
    117         try {
    118             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_4");
    119             fail("expected a verification exception");
    120         } catch (Throwable t) {
    121             DxUtil.checkVerifyException(t);
    122         }
    123     }
    124 
    125     /**
    126      * @constraint B1
    127      * @title types of arguments - float[], int
    128      */
    129     public void testVFE4() {
    130         try {
    131             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_5");
    132             fail("expected a verification exception");
    133         } catch (Throwable t) {
    134             DxUtil.checkVerifyException(t);
    135         }
    136     }
    137 
    138     /**
    139      * @constraint B1
    140      * @title types of arguments - long[], int
    141      */
    142     public void testVFE5() {
    143         try {
    144             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_6");
    145             fail("expected a verification exception");
    146         } catch (Throwable t) {
    147             DxUtil.checkVerifyException(t);
    148         }
    149     }
    150 
    151     /**
    152      * @constraint B1
    153      * @title types of arguments - array, reference
    154      */
    155     public void testVFE6() {
    156         try {
    157             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_7");
    158             fail("expected a verification exception");
    159         } catch (Throwable t) {
    160             DxUtil.checkVerifyException(t);
    161         }
    162     }
    163 
    164     /**
    165      * @constraint A23
    166      * @title number of registers
    167      */
    168     public void testVFE7() {
    169         try {
    170             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_9");
    171             fail("expected a verification exception");
    172         } catch (Throwable t) {
    173             DxUtil.checkVerifyException(t);
    174         }
    175     }
    176 
    177     /**
    178      * @constraint B1
    179      * @title Type of index argument - float. The verifier checks that ints
    180      * and floats are not used interchangeably.
    181      */
    182     public void testVFE8() {
    183         try {
    184             Class.forName("dot.junit.opcodes.aget_object.d.T_aget_object_8");
    185             fail("expected a verification exception");
    186         } catch (Throwable t) {
    187             DxUtil.checkVerifyException(t);
    188         }
    189     }
    190 
    191 }
    192