Home | History | Annotate | Download | only in aget_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.aget_byte;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.aget_byte.d.T_aget_byte_1;
     22 import dot.junit.opcodes.aget_byte.d.T_aget_byte_8;
     23 
     24 
     25 public class Test_aget_byte extends DxTestCase {
     26     /**
     27      * @title get byte from array
     28      */
     29     public void testN1() {
     30         T_aget_byte_1 t = new T_aget_byte_1();
     31         byte[] arr = new byte[2];
     32         arr[1] = 100;
     33         assertEquals(100, t.run(arr, 1));
     34     }
     35 
     36     /**
     37      * @title get byte from array
     38      */
     39     public void testN2() {
     40         T_aget_byte_1 t = new T_aget_byte_1();
     41         byte[] arr = new byte[2];
     42         arr[0] = 100;
     43         assertEquals(100, t.run(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] makes no sense but shall not crash the VM.
     49      */
     50     public void testN3() {
     51          byte[] arr = new byte[2];
     52          T_aget_byte_8 t = new T_aget_byte_8();
     53         try {
     54             t.run(arr, 3.14f);
     55         } catch (Throwable e) {
     56         }
     57     }
     58 
     59     /**
     60      * @title expected ArrayIndexOutOfBoundsException
     61      */
     62     public void testE1() {
     63         T_aget_byte_1 t = new T_aget_byte_1();
     64         byte[] arr = new byte[2];
     65         try {
     66             t.run(arr, 2);
     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_aget_byte_1 t = new T_aget_byte_1();
     78         try {
     79             t.run(null, 2);
     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_aget_byte_1 t = new T_aget_byte_1();
     91         byte[] arr = new byte[2];
     92         try {
     93             t.run(arr, -1);
     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
    105      */
    106     public void testVFE1() {
    107         try {
    108             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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, long
    118      */
    119     public void testVFE2() {
    120         try {
    121             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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, short
    131      */
    132     public void testVFE3() {
    133         try {
    134             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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
    144      */
    145     public void testVFE4() {
    146         try {
    147             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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 - int[], int
    157      */
    158     public void testVFE5() {
    159         try {
    160             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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
    170      */
    171     public void testVFE6() {
    172         try {
    173             Class.forName("dot.junit.opcodes.aget_byte.d.T_aget_byte_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.aget_byte.d.T_aget_byte_9");
    187             fail("expected a verification exception");
    188         } catch (Throwable t) {
    189             DxUtil.checkVerifyException(t);
    190         }
    191     }
    192 }
    193