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