Home | History | Annotate | Download | only in tableswitch
      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.tableswitch;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.tableswitch.jm.T_tableswitch_1;
     22 
     23 public class Test_tableswitch extends DxTestCase {
     24 
     25     /**
     26      * @title normal test
     27      */
     28     public void testN1() {
     29         T_tableswitch_1 t = new T_tableswitch_1();
     30         assertEquals(2, t.run(-1));
     31 
     32         assertEquals(-1, t.run(4));
     33         assertEquals(20, t.run(2));
     34         assertEquals(-1, t.run(5));
     35 
     36         assertEquals(-1, t.run(6));
     37         assertEquals(20, t.run(3));
     38         assertEquals(-1, t.run(7));
     39     }
     40 
     41     /**
     42      * @title check Integer.MAX_VALUE
     43      */
     44     public void testB1() {
     45         T_tableswitch_1 t = new T_tableswitch_1();
     46         assertEquals(-1, t.run(Integer.MAX_VALUE));
     47     }
     48 
     49     /**
     50      * @title check Integer.MIN_VALUE
     51      */
     52     public void testB2() {
     53         T_tableswitch_1 t = new T_tableswitch_1();
     54         assertEquals(-1, t.run(Integer.MIN_VALUE));
     55     }
     56 
     57     /**
     58      * @constraint 4.8.2.1
     59      * @title number of arguments
     60      */
     61     public void testVFE1() {
     62         try {
     63             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_2");
     64             fail("expected a verification exception");
     65         } catch (Throwable t) {
     66             DxUtil.checkVerifyException(t);
     67         }
     68     }
     69 
     70     /**
     71      * @constraint 4.8.2.1
     72      * @title type of argument - float
     73      */
     74     public void testVFE2() {
     75         try {
     76             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_3");
     77             fail("expected a verification exception");
     78         } catch (Throwable t) {
     79             DxUtil.checkVerifyException(t);
     80         }
     81     }
     82 
     83     /**
     84      * @constraint 4.8.1.8
     85      * @title branch target shall be inside the
     86      * method
     87      */
     88     public void testVFE3() {
     89         try {
     90             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_4");
     91             fail("expected a verification exception");
     92         } catch (Throwable t) {
     93             DxUtil.checkVerifyException(t);
     94         }
     95     }
     96 
     97     /**
     98      * @constraint 4.8.1.8
     99      * @title branch target shall not be "inside" wide
    100      * instruction
    101      */
    102     public void testVFE4() {
    103         try {
    104             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_5");
    105             fail("expected a verification exception");
    106         } catch (Throwable t) {
    107             DxUtil.checkVerifyException(t);
    108         }
    109     }
    110 
    111     /**
    112      * @constraint 4.8.1.8
    113      * @title low value shall be less than high
    114      * value
    115      */
    116     public void testVFE5() {
    117         try {
    118             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_6");
    119             fail("expected a verification exception");
    120         } catch (Throwable t) {
    121             DxUtil.checkVerifyException(t);
    122         }
    123     }
    124 
    125     /**
    126      * @constraint 4.8.1.8
    127      * @title non-zero padding
    128      */
    129     public void testVFE6() {
    130         try {
    131             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_7");
    132             fail("expected a verification exception");
    133         } catch (Throwable t) {
    134             DxUtil.checkVerifyException(t);
    135         }
    136     }
    137 
    138     /**
    139      * @constraint 4.8.2.1
    140      * @title type of argument - reference
    141      */
    142     public void testVFE7() {
    143         try {
    144             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_8");
    145             fail("expected a verification exception");
    146         } catch (Throwable t) {
    147             DxUtil.checkVerifyException(t);
    148         }
    149     }
    150 
    151     /**
    152      * @constraint 4.8.1.8
    153      * @title number of entries in jump table
    154      */
    155     public void testVFE8() {
    156         try {
    157             Class.forName("dxc.junit.opcodes.tableswitch.jm.T_tableswitch_9");
    158             fail("expected a verification exception");
    159         } catch (Throwable t) {
    160             DxUtil.checkVerifyException(t);
    161         }
    162     }
    163 
    164 }
    165