Home | History | Annotate | Download | only in aastore
      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 dxc.junit.opcodes.aastore;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.aastore.jm.T_aastore_1;
     22 import dxc.junit.opcodes.aastore.jm.T_aastore_10;
     23 import dxc.junit.opcodes.aastore.jm.T_aastore_11;
     24 import dxc.junit.opcodes.aastore.jm.T_aastore_4;
     25 
     26 public class Test_aastore extends DxTestCase {
     27 
     28     /**
     29      * @title Normal test. Trying different indexes
     30      */
     31     public void testN1() {
     32         T_aastore_1 t = new T_aastore_1();
     33         String[] arr = new String[2];
     34         t.run(arr, 0, "hello");
     35         assertEquals("hello", arr[0]);
     36     }
     37 
     38     /**
     39      * @title Normal test. Trying different indexes
     40      */
     41     public void testN2() {
     42         T_aastore_1 t = new T_aastore_1();
     43         String[] value = {"world", null, ""};
     44         String[] arr = new String[2];
     45         for (int i = 0; i < value.length; i++) {
     46             t.run(arr, 1, value[i]);
     47             assertEquals(value[i], arr[1]);
     48         }
     49     }
     50 
     51     /**
     52      * @title Normal test. Trying different indexes
     53      */
     54     public void testN3() {
     55         T_aastore_10 t = new T_aastore_10();
     56         Integer[] arr = new Integer[2];
     57         Integer value = new Integer(12345);
     58         t.run(arr, 0, value);
     59         assertEquals(value, arr[0]);
     60     }
     61 
     62     /**
     63      * @title  Check assignement compatibility rules
     64      */
     65     public void testN4() {
     66         // @uses dxc.junit.opcodes.aastore.jm.SubClass
     67         // @uses dxc.junit.opcodes.aastore.jm.SuperClass
     68         // @uses dxc.junit.opcodes.aastore.jm.SuperInterface
     69         // @uses dxc.junit.opcodes.aastore.jm.SuperInterface2
     70         T_aastore_11 t = new T_aastore_11();
     71         assertEquals(3, t.run());
     72 
     73     }
     74 
     75     /**
     76      * @title ArrayIndexOutOfBoundsException expected
     77      */
     78     public void testE1() {
     79         T_aastore_1 t = new T_aastore_1();
     80         String[] arr = new String[2];
     81         try {
     82             t.run(arr, arr.length, "abc");
     83             fail("expected ArrayIndexOutOfBoundsException");
     84         } catch (ArrayIndexOutOfBoundsException aie) {
     85             // expected
     86         }
     87     }
     88 
     89     /**
     90      * @title expected ArrayIndexOutOfBoundsException
     91      */
     92     public void testE2() {
     93         T_aastore_1 t = new T_aastore_1();
     94         String[] arr = new String[2];
     95         try {
     96             t.run(arr, -1, "abc");
     97             fail("expected ArrayIndexOutOfBoundsException");
     98         } catch (ArrayIndexOutOfBoundsException aie) {
     99             // expected
    100         }
    101     }
    102 
    103     /**
    104      * @title expected NullPointerException
    105      */
    106     public void testE3() {
    107         T_aastore_1 t = new T_aastore_1();
    108         String[] arr = null;
    109         try {
    110             t.run(arr, 0, "abc");
    111             fail("expected NullPointerException");
    112         } catch (NullPointerException aie) {
    113             // expected
    114         }
    115     }
    116 
    117     /**
    118      * @title expected ArrayStoreException
    119      */
    120     public void testE4() {
    121         T_aastore_4 t = new T_aastore_4();
    122         String[] arr = new String[2];
    123         try {
    124             t.run(arr, 0, this);
    125             fail("expected ArrayStoreException");
    126         } catch (ArrayStoreException aie) {
    127             // expected
    128         }
    129     }
    130 
    131     /**
    132      * @constraint 4.8.2.1
    133      * @title number of arguments
    134      */
    135     public void testVFE1() {
    136         try {
    137             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_2");
    138             fail("expected a verification exception");
    139         } catch (Throwable t) {
    140             DxUtil.checkVerifyException(t);
    141         }
    142     }
    143 
    144     /**
    145      * @constraint 4.8.2.1
    146      * @title number of arguments
    147      */
    148     public void testVFE2() {
    149         try {
    150             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_3");
    151             fail("expected a verification exception");
    152         } catch (Throwable t) {
    153             DxUtil.checkVerifyException(t);
    154         }
    155     }
    156 
    157     /**
    158      * @constraint 4.8.2.1
    159      * @title types of arguments - array, double, String
    160      */
    161     public void testVFE3() {
    162         try {
    163             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_5");
    164             fail("expected a verification exception");
    165         } catch (Throwable t) {
    166             DxUtil.checkVerifyException(t);
    167         }
    168     }
    169 
    170     /**
    171      * @constraint 4.8.2.1
    172      * @title types of arguments - array, int, long
    173      */
    174     public void testVFE4() {
    175         try {
    176             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_6");
    177             fail("expected a verification exception");
    178         } catch (Throwable t) {
    179             DxUtil.checkVerifyException(t);
    180         }
    181     }
    182 
    183     /**
    184      * @constraint 4.8.2.1
    185      * @title types of arguments - object, int, String
    186      */
    187     public void testVFE5() {
    188         try {
    189             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_7");
    190             fail("expected a verification exception");
    191         } catch (Throwable t) {
    192             DxUtil.checkVerifyException(t);
    193         }
    194     }
    195 
    196     /**
    197      * @constraint 4.8.2.1
    198      * @title types of arguments - float[], int, String
    199      */
    200     public void testVFE6() {
    201         try {
    202             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_8");
    203             fail("expected a verification exception");
    204         } catch (Throwable t) {
    205             DxUtil.checkVerifyException(t);
    206         }
    207     }
    208 
    209     /**
    210      * @constraint 4.8.2.1
    211      * @title types of arguments - long[], int, String
    212      */
    213     public void testVFE7() {
    214         try {
    215             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_9");
    216             fail("expected a verification exception");
    217         } catch (Throwable t) {
    218             DxUtil.checkVerifyException(t);
    219         }
    220     }
    221 
    222     /**
    223      * @constraint 4.8.2.1
    224      * @title types of arguments - array, reference, String
    225      */
    226     public void testVFE8() {
    227         try {
    228             Class.forName("dxc.junit.opcodes.aastore.jm.T_aastore_12");
    229             fail("expected a verification exception");
    230         } catch (Throwable t) {
    231             DxUtil.checkVerifyException(t);
    232         }
    233     }
    234 
    235 }
    236