Home | History | Annotate | Download | only in aput_byte
      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_byte;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.aput_byte.d.T_aput_byte_1;
     22 import dot.junit.opcodes.aput_byte.d.T_aput_byte_8;
     23 
     24 public class Test_aput_byte extends DxTestCase {
     25     /**
     26      * @title put byte into array
     27      */
     28     public void testN1() {
     29         T_aput_byte_1 t = new T_aput_byte_1();
     30         byte[] arr = new byte[2];
     31         t.run(arr, 1, (byte) 100);
     32         assertEquals(100, arr[1]);
     33     }
     34 
     35     /**
     36      * @title put byte into array
     37      */
     38     public void testN2() {
     39         T_aput_byte_1 t = new T_aput_byte_1();
     40         byte[] arr = new byte[2];
     41         t.run(arr, 0, (byte) 100);
     42         assertEquals(100, 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         byte[] arr = new byte[2];
     52         T_aput_byte_8 t = new T_aput_byte_8();
     53         try {
     54             t.run(arr, 3.14f, (byte)1);
     55         } catch (Throwable e) {
     56         }
     57     }
     58 
     59     /**
     60      * @title expected ArrayIndexOutOfBoundsException
     61      */
     62     public void testE1() {
     63         T_aput_byte_1 t = new T_aput_byte_1();
     64         byte[] arr = new byte[2];
     65         try {
     66             t.run(arr, 2, (byte) 100);
     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_byte_1 t = new T_aput_byte_1();
     78         try {
     79             t.run(null, 2, (byte) 100);
     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_byte_1 t = new T_aput_byte_1();
     91         byte[] arr = new byte[2];
     92         try {
     93             t.run(arr, -1, (byte) 100);
     94             fail("expected ArrayIndexOutOfBoundsException");
     95         } catch (ArrayIndexOutOfBoundsException aie) {
     96             // expected
     97         }
     98     }
     99 
    100 
    101 
    102 
    103     /**
    104      * @constraint B1
    105      * @title types of arguments - array, double, short
    106      */
    107     public void testVFE1() {
    108         try {
    109             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_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_byte.d.T_aput_byte_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, short
    132      */
    133     public void testVFE3() {
    134         try {
    135             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_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, short
    145      */
    146     public void testVFE4() {
    147         try {
    148             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_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, short
    158      */
    159     public void testVFE5() {
    160         try {
    161             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_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, short
    171      */
    172     public void testVFE6() {
    173         try {
    174             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_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_byte.d.T_aput_byte_9");
    188             fail("expected a verification exception");
    189         } catch (Throwable t) {
    190             DxUtil.checkVerifyException(t);
    191         }
    192     }
    193 
    194     /**
    195      * @constraint B15
    196      * @title put value 128 into byte array
    197      */
    198     public void testVFE8() {
    199         try {
    200             Class.forName("dot.junit.opcodes.aput_byte.d.T_aput_byte_10");
    201             fail("expected a verification exception");
    202         } catch (Throwable t) {
    203             DxUtil.checkVerifyException(t);
    204         }
    205     }
    206 
    207 }
    208