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