Home | History | Annotate | Download | only in div_int_lit16
      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.div_int_lit16;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_1;
     22 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_10;
     23 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_11;
     24 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_12;
     25 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_13;
     26 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_17;
     27 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_2;
     28 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_3;
     29 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_4;
     30 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_5;
     31 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_6;
     32 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_7;
     33 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_8;
     34 import dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_9;
     35 
     36 
     37 public class Test_div_int_lit16 extends DxTestCase {
     38     /**
     39      * @title Arguments = 8 / 4
     40      */
     41     public void testN1() {
     42         T_div_int_lit16_1 t = new T_div_int_lit16_1();
     43         assertEquals(2, t.run());
     44     }
     45 
     46     /**
     47      * @title Rounding
     48      */
     49     public void testN2() {
     50         T_div_int_lit16_2 t = new T_div_int_lit16_2();
     51         assertEquals(268435455, t.run());
     52     }
     53 
     54     /**
     55      * @title Dividend = 0
     56      */
     57     public void testN3() {
     58         T_div_int_lit16_3 t = new T_div_int_lit16_3();
     59         assertEquals(0, t.run());
     60     }
     61 
     62     /**
     63      * @title Dividend is negative
     64      */
     65     public void testN4() {
     66         T_div_int_lit16_4 t = new T_div_int_lit16_4();
     67         assertEquals(-3, t.run());
     68     }
     69 
     70     /**
     71      * @title Divisor is negative
     72      */
     73     public void testN5() {
     74         T_div_int_lit16_5 t = new T_div_int_lit16_5();
     75         assertEquals(-357913941, t.run());
     76     }
     77 
     78     /**
     79      * @title Both Dividend and divisor are negative
     80      */
     81     public void testN6() {
     82         T_div_int_lit16_6 t = new T_div_int_lit16_6();
     83         assertEquals(5965, t.run());
     84     }
     85 
     86     /**
     87      * @title Arguments = Integer.MIN_VALUE / -1
     88      */
     89     public void testB1() {
     90         T_div_int_lit16_7 t = new T_div_int_lit16_7();
     91         // result is MIN_VALUE because overflow occurs in this case
     92         assertEquals(Integer.MIN_VALUE, t.run());
     93     }
     94 
     95     /**
     96      * @title Arguments = Integer.MIN_VALUE / 1
     97      */
     98     public void testB2() {
     99         T_div_int_lit16_8 t = new T_div_int_lit16_8();
    100         assertEquals(Integer.MIN_VALUE, t.run());
    101     }
    102 
    103     /**
    104      * @title Arguments = Integer.MAX_VALUE / 1
    105      */
    106     public void testB3() {
    107         T_div_int_lit16_9 t = new T_div_int_lit16_9();
    108         assertEquals(Integer.MAX_VALUE, t.run());
    109     }
    110 
    111     /**
    112      * @title Arguments = Integer.MIN_VALUE / Short.MAX_VALUE
    113      */
    114     public void testB4() {
    115         T_div_int_lit16_10 t = new T_div_int_lit16_10();
    116         assertEquals(-65538, t.run());
    117     }
    118 
    119     /**
    120      * @title Arguments = 1 / Short.MAX_VALUE
    121      */
    122     public void testB5() {
    123         T_div_int_lit16_11 t = new T_div_int_lit16_11();
    124         assertEquals(0, t.run());
    125     }
    126 
    127     /**
    128      * @title Arguments = 1 / Short.MIN_VALUE
    129      */
    130     public void testB6() {
    131         T_div_int_lit16_12 t = new T_div_int_lit16_12();
    132         assertEquals(0, t.run());
    133     }
    134 
    135     /**
    136      * @title Divisor is 0
    137      */
    138     public void testE1() {
    139         T_div_int_lit16_13 t = new T_div_int_lit16_13();
    140         try {
    141             t.run();
    142             fail("expected ArithmeticException");
    143         } catch (ArithmeticException ae) {
    144             // expected
    145         }
    146     }
    147 
    148 
    149 
    150     /**
    151      * @constraint B1
    152      * @title types of arguments - int / double
    153      */
    154     public void testVFE1() {
    155         try {
    156             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_14");
    157             fail("expected a verification exception");
    158         } catch (Throwable t) {
    159             DxUtil.checkVerifyException(t);
    160         }
    161     }
    162 
    163     /**
    164      * @constraint B1
    165      * @title types of arguments - long / int
    166      */
    167     public void testVFE2() {
    168         try {
    169             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_15");
    170             fail("expected a verification exception");
    171         } catch (Throwable t) {
    172             DxUtil.checkVerifyException(t);
    173         }
    174     }
    175 
    176     /**
    177      * @constraint B1
    178      * @title types of arguments - reference / int
    179      */
    180     public void testVFE3() {
    181         try {
    182             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_16");
    183             fail("expected a verification exception");
    184         } catch (Throwable t) {
    185             DxUtil.checkVerifyException(t);
    186         }
    187     }
    188 
    189     /**
    190      * @constraint A23
    191      * @title  number of registers
    192      */
    193     public void testVFE4() {
    194         try {
    195             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_18");
    196             fail("expected a verification exception");
    197         } catch (Throwable t) {
    198             DxUtil.checkVerifyException(t);
    199         }
    200     }
    201 
    202     /**
    203      * @constraint B1
    204      * @title Types of arguments - int, float. The verifier checks that ints
    205      * and floats are not used interchangeably.
    206      */
    207     public void testVFE5() {
    208         try {
    209             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_17");
    210             fail("expected a verification exception");
    211         } catch (Throwable t) {
    212             DxUtil.checkVerifyException(t);
    213         }
    214     }
    215 }
    216