Home | History | Annotate | Download | only in fill_array_data
      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.fill_array_data;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.fill_array_data.d.T_fill_array_data_1;
     22 import dot.junit.opcodes.fill_array_data.d.T_fill_array_data_2;
     23 
     24 public class Test_fill_array_data extends DxTestCase {
     25     /**
     26      * @title array of ints
     27      */
     28     public void testN1() {
     29         int arr[] = new int[5];
     30         T_fill_array_data_1 t = new T_fill_array_data_1();
     31         t.run(arr);
     32         for(int i = 0; i < 5; i++)
     33             assertEquals(i + 1, arr[i]);
     34      }
     35 
     36     /**
     37      * @title array of doubles
     38      */
     39     public void testN2() {
     40         double arr[] = new double[5];
     41         T_fill_array_data_2 t = new T_fill_array_data_2();
     42         t.run(arr);
     43         for(int i = 0; i < 5; i++)
     44             assertEquals((double)(i + 1), arr[i]);
     45      }
     46 
     47     /**
     48      * @title If there are less elements in the table than the array provides space for,
     49      * the remaining array elements stay untouched.
     50      */
     51     public void testN3() {
     52         int arr[] = new int[10];
     53         T_fill_array_data_1 t = new T_fill_array_data_1();
     54         t.run(arr);
     55         for(int i = 0; i < 5; i++)
     56             assertEquals(i + 1, arr[i]);
     57         for(int i = 5; i < 10; i++)
     58             assertEquals(0, arr[i]);
     59      }
     60 
     61     /**
     62      * @title expected NullPointerException
     63      */
     64     public void testE1() {
     65         T_fill_array_data_1 t = new T_fill_array_data_1();
     66         try {
     67             t.run(null);
     68         } catch(NullPointerException npe) {
     69             // expected
     70         }
     71      }
     72 
     73     /**
     74      * @title expected ArrayIndexOutOfBoundsException
     75      */
     76     public void testE2() {
     77         int arr[] = new int[2];
     78         T_fill_array_data_1 t = new T_fill_array_data_1();
     79        try {
     80             t.run(arr);
     81         } catch(ArrayIndexOutOfBoundsException e) {
     82             // expected
     83            }
     84      }
     85 
     86     /**
     87      * @constraint A23
     88      * @title number of registers
     89      */
     90     public void testVFE1() {
     91         try {
     92             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_3");
     93             fail("expected a verification exception");
     94         } catch (Throwable t) {
     95             DxUtil.checkVerifyException(t);
     96         }
     97     }
     98 
     99     /**
    100      * @constraint B1
    101      * @title type of argument - double
    102      */
    103     public void testVFE2() {
    104         try {
    105             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_4");
    106             fail("expected a verification exception");
    107         } catch (Throwable t) {
    108             DxUtil.checkVerifyException(t);
    109         }
    110     }
    111 
    112     /**
    113      * @constraint B1
    114      * @title type of argument - long
    115      */
    116     public void testVFE3() {
    117         try {
    118             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_5");
    119             fail("expected a verification exception");
    120         } catch (Throwable t) {
    121             DxUtil.checkVerifyException(t);
    122         }
    123     }
    124 
    125     /**
    126      * @constraint B1
    127      * @title type of argument - reference (not array)
    128      */
    129     public void testVFE4() {
    130         try {
    131             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_6");
    132             fail("expected a verification exception");
    133         } catch (Throwable t) {
    134             DxUtil.checkVerifyException(t);
    135         }
    136     }
    137 
    138     /**
    139      * @constraint B1
    140      * @title array of Objects
    141      */
    142     public void testVFE5() {
    143         try {
    144             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_7");
    145             fail("expected a verification exception");
    146         } catch (Throwable t) {
    147             DxUtil.checkVerifyException(t);
    148         }
    149     }
    150 
    151     /**
    152      * @constraint B1
    153      * @title array type and data size shall be consistent
    154      */
    155     public void testVFE6() {
    156         try {
    157             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_8");
    158             fail("expected a verification exception");
    159         } catch (Throwable t) {
    160             DxUtil.checkVerifyException(t);
    161         }
    162     }
    163 
    164     /**
    165      * @constraint n/a
    166      * @title offset to table shall be inside method
    167      */
    168     public void testVFE7() {
    169         try {
    170             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_9");
    171             fail("expected a verification exception");
    172         } catch (Throwable t) {
    173             DxUtil.checkVerifyException(t);
    174         }
    175     }
    176 
    177     /**
    178      * @constraint n/a
    179      * @title the size and the list must be consistent.
    180      */
    181     public void testVFE9() {
    182         try {
    183             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_11");
    184             fail("expected a verification exception");
    185         } catch (Throwable t) {
    186             DxUtil.checkVerifyException(t);
    187         }
    188     }
    189 
    190 
    191     /**
    192      * @constraint B22
    193      * @title packed-switch-data pseudo-instructions must not be reachable by control flow
    194      */
    195     public void testVFE10() {
    196         try {
    197             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_12");
    198             fail("expected a verification exception");
    199         } catch (Throwable t) {
    200             DxUtil.checkVerifyException(t);
    201         }
    202     }
    203 
    204     /**
    205      * @constraint n/a
    206      * @title table has wrong ident code
    207      */
    208     public void testVFE11() {
    209         try {
    210             Class.forName("dot.junit.opcodes.fill_array_data.d.T_fill_array_data_13");
    211             fail("expected a verification exception");
    212         } catch (Throwable t) {
    213             DxUtil.checkVerifyException(t);
    214         }
    215     }
    216 }
    217