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 Type of index argument - float. Dalvik doens't distinguish 32-bits types internally,
     48      * so this array[float]=value makes no sense but shall not crash the VM.
     49      */
     50 
     51     public void testN3() {
     52         int[] arr = new int[2];
     53         T_aput_8 t = new T_aput_8();
     54         try {
     55             t.run(arr, 3.14f, 111f);
     56         } catch (Throwable e) {
     57         }
     58     }
     59 
     60     /**
     61      * @title expected ArrayIndexOutOfBoundsException
     62      */
     63     public void testE1() {
     64         T_aput_1 t = new T_aput_1();
     65         int[] arr = new int[2];
     66         try {
     67             t.run(arr, 2, 100000000);
     68             fail("expected ArrayIndexOutOfBoundsException");
     69         } catch (ArrayIndexOutOfBoundsException aie) {
     70             // expected
     71         }
     72     }
     73 
     74     /**
     75      * @title expected NullPointerException
     76      */
     77     public void testE2() {
     78         T_aput_1 t = new T_aput_1();
     79         try {
     80             t.run(null, 2, 100000000);
     81             fail("expected NullPointerException");
     82         } catch (NullPointerException aie) {
     83             // expected
     84         }
     85     }
     86 
     87     /**
     88      * @title expected ArrayIndexOutOfBoundsException (negative index)
     89      */
     90     public void testE3() {
     91         T_aput_1 t = new T_aput_1();
     92         int[] arr = new int[2];
     93         try {
     94             t.run(arr, -1, 100000000);
     95             fail("expected ArrayIndexOutOfBoundsException");
     96         } catch (ArrayIndexOutOfBoundsException aie) {
     97             // expected
     98         }
     99     }
    100 
    101 
    102 
    103     /**
    104      * @constraint B1
    105      * @title types of arguments - array, double, int
    106      */
    107     public void testVFE1() {
    108         try {
    109             Class.forName("dot.junit.opcodes.aput.d.T_aput_2");
    110             fail("expected a verification exception");
    111         } catch (Throwable t) {
    112             DxUtil.checkVerifyException(t);
    113         }
    114     }
    115 
    116     /**
    117      * @constraint B1
    118      * @title types of arguments - array, int, long
    119      */
    120     public void testVFE2() {
    121         try {
    122             Class.forName("dot.junit.opcodes.aput.d.T_aput_3");
    123             fail("expected a verification exception");
    124         } catch (Throwable t) {
    125             DxUtil.checkVerifyException(t);
    126         }
    127     }
    128 
    129     /**
    130      * @constraint B1
    131      * @title types of arguments - object, int, int
    132      */
    133     public void testVFE3() {
    134         try {
    135             Class.forName("dot.junit.opcodes.aput.d.T_aput_4");
    136             fail("expected a verification exception");
    137         } catch (Throwable t) {
    138             DxUtil.checkVerifyException(t);
    139         }
    140     }
    141 
    142     /**
    143      * @constraint B1
    144      * @title types of arguments - double[], int, int
    145      */
    146     public void testVFE4() {
    147         try {
    148             Class.forName("dot.junit.opcodes.aput.d.T_aput_5");
    149             fail("expected a verification exception");
    150         } catch (Throwable t) {
    151             DxUtil.checkVerifyException(t);
    152         }
    153     }
    154 
    155     /**
    156      * @constraint B1
    157      * @title types of arguments - long[], int, int
    158      */
    159     public void testVFE5() {
    160         try {
    161             Class.forName("dot.junit.opcodes.aput.d.T_aput_6");
    162             fail("expected a verification exception");
    163         } catch (Throwable t) {
    164             DxUtil.checkVerifyException(t);
    165         }
    166     }
    167 
    168     /**
    169      * @constraint B1
    170      * @title types of arguments - array, reference, int
    171      */
    172     public void testVFE6() {
    173         try {
    174             Class.forName("dot.junit.opcodes.aput.d.T_aput_7");
    175             fail("expected a verification exception");
    176         } catch (Throwable t) {
    177             DxUtil.checkVerifyException(t);
    178         }
    179     }
    180 
    181     /**
    182      * @constraint A23
    183      * @title number of registers
    184      */
    185     public void testVFE7() {
    186         try {
    187             Class.forName("dot.junit.opcodes.aput.d.T_aput_9");
    188             fail("expected a verification exception");
    189         } catch (Throwable t) {
    190             DxUtil.checkVerifyException(t);
    191         }
    192     }
    193 }
    194