Home | History | Annotate | Download | only in aput_short
      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_short;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.aput_short.d.T_aput_short_1;
     22 import dot.junit.opcodes.aput_short.d.T_aput_short_8;
     23 
     24 public class Test_aput_short extends DxTestCase {
     25     /**
     26      * @title put short into array
     27      */
     28     public void testN1() {
     29         T_aput_short_1 t = new T_aput_short_1();
     30         short[] arr = new short[2];
     31         t.run(arr, 1, (short) 10000);
     32         assertEquals(10000, arr[1]);
     33     }
     34 
     35     /**
     36      * @title put short into array
     37      */
     38     public void testN2() {
     39         T_aput_short_1 t = new T_aput_short_1();
     40         short[] arr = new short[2];
     41         t.run(arr, 0, (short) 10000);
     42         assertEquals(10000, arr[0]);
     43     }
     44 
     45     /**
     46      * @title Type of index argument - float. Dalvik doens't distinguish 32-bits types internally,
     47      * so this array[float]=value makes no sense but shall not crash the VM.
     48      */
     49 
     50     public void testN3() {
     51         short[] arr = new short[2];
     52         T_aput_short_8 t = new T_aput_short_8();
     53         try {
     54             t.run(arr, 3.14f, (short)111);
     55         } catch (Throwable e) {
     56         }
     57     }
     58 
     59     /**
     60      * @title expected ArrayIndexOutOfBoundsException
     61      */
     62     public void testE1() {
     63         T_aput_short_1 t = new T_aput_short_1();
     64         short[] arr = new short[2];
     65         try {
     66             t.run(arr, 2, (short) 10000);
     67             fail("expected ArrayIndexOutOfBoundsException");
     68         } catch (ArrayIndexOutOfBoundsException aie) {
     69             // expected
     70         }
     71     }
     72 
     73     /**
     74      * @title expected NullPointerException
     75      */
     76     public void testE2() {
     77         T_aput_short_1 t = new T_aput_short_1();
     78         try {
     79             t.run(null, 2, (short) 10000);
     80             fail("expected NullPointerException");
     81         } catch (NullPointerException aie) {
     82             // expected
     83         }
     84     }
     85 
     86     /**
     87      * @title expected ArrayIndexOutOfBoundsException (negative index)
     88      */
     89     public void testE3() {
     90         T_aput_short_1 t = new T_aput_short_1();
     91         short[] arr = new short[2];
     92         try {
     93             t.run(arr, -1, (short) 10000);
     94             fail("expected ArrayIndexOutOfBoundsException");
     95         } catch (ArrayIndexOutOfBoundsException aie) {
     96             // expected
     97         }
     98     }
     99 
    100 
    101 
    102     /**
    103      * @constraint B1
    104      * @title types of arguments - array, double, int
    105      */
    106     public void testVFE1() {
    107         try {
    108             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_2");
    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 - array, int, long
    118      */
    119     public void testVFE2() {
    120         try {
    121             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_3");
    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 - object, int, int
    131      */
    132     public void testVFE3() {
    133         try {
    134             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_4");
    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 - double[], int, int
    144      */
    145     public void testVFE4() {
    146         try {
    147             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_5");
    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 - long[], int, int
    157      */
    158     public void testVFE5() {
    159         try {
    160             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_6");
    161             fail("expected a verification exception");
    162         } catch (Throwable t) {
    163             DxUtil.checkVerifyException(t);
    164         }
    165     }
    166 
    167     /**
    168      * @constraint B1
    169      * @title types of arguments - array, reference, int
    170      */
    171     public void testVFE6() {
    172         try {
    173             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_7");
    174             fail("expected a verification exception");
    175         } catch (Throwable t) {
    176             DxUtil.checkVerifyException(t);
    177         }
    178     }
    179 
    180     /**
    181      * @constraint A23
    182      * @title number of registers
    183      */
    184     public void testVFE7() {
    185         try {
    186             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_9");
    187             fail("expected a verification exception");
    188         } catch (Throwable t) {
    189             DxUtil.checkVerifyException(t);
    190         }
    191     }
    192 
    193     /**
    194      * @constraint B15
    195      * @title put value 32768 into array of shorts
    196      */
    197     public void testVFE8() {
    198         try {
    199             Class.forName("dot.junit.opcodes.aput_short.d.T_aput_short_10");
    200             fail("expected a verification exception");
    201         } catch (Throwable t) {
    202             DxUtil.checkVerifyException(t);
    203         }
    204     }
    205 }
    206