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 Types of arguments - int, float. Dalvik doens't distinguish 32-bits types internally,
     88      * so this division of float and int makes no sense but shall not crash the VM.
     89      */
     90 
     91     public void testN7() {
     92         T_div_int_lit16_17 t = new T_div_int_lit16_17();
     93         try {
     94             t.run(3.14f);
     95         } catch (Throwable e) {
     96         }
     97     }
     98 
     99     /**
    100      * @title Arguments = Integer.MIN_VALUE / -1
    101      */
    102     public void testB1() {
    103         T_div_int_lit16_7 t = new T_div_int_lit16_7();
    104         // result is MIN_VALUE because overflow occurs in this case
    105         assertEquals(Integer.MIN_VALUE, t.run());
    106     }
    107 
    108     /**
    109      * @title Arguments = Integer.MIN_VALUE / 1
    110      */
    111     public void testB2() {
    112         T_div_int_lit16_8 t = new T_div_int_lit16_8();
    113         assertEquals(Integer.MIN_VALUE, t.run());
    114     }
    115 
    116     /**
    117      * @title Arguments = Integer.MAX_VALUE / 1
    118      */
    119     public void testB3() {
    120         T_div_int_lit16_9 t = new T_div_int_lit16_9();
    121         assertEquals(Integer.MAX_VALUE, t.run());
    122     }
    123 
    124     /**
    125      * @title Arguments = Integer.MIN_VALUE / Short.MAX_VALUE
    126      */
    127     public void testB4() {
    128         T_div_int_lit16_10 t = new T_div_int_lit16_10();
    129         assertEquals(-65538, t.run());
    130     }
    131 
    132     /**
    133      * @title Arguments = 1 / Short.MAX_VALUE
    134      */
    135     public void testB5() {
    136         T_div_int_lit16_11 t = new T_div_int_lit16_11();
    137         assertEquals(0, t.run());
    138     }
    139 
    140     /**
    141      * @title Arguments = 1 / Short.MIN_VALUE
    142      */
    143     public void testB6() {
    144         T_div_int_lit16_12 t = new T_div_int_lit16_12();
    145         assertEquals(0, t.run());
    146     }
    147 
    148     /**
    149      * @title Divisor is 0
    150      */
    151     public void testE1() {
    152         T_div_int_lit16_13 t = new T_div_int_lit16_13();
    153         try {
    154             t.run();
    155             fail("expected ArithmeticException");
    156         } catch (ArithmeticException ae) {
    157             // expected
    158         }
    159     }
    160 
    161 
    162 
    163     /**
    164      * @constraint B1
    165      * @title types of arguments - int / double
    166      */
    167     public void testVFE1() {
    168         try {
    169             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_14");
    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 - long / int
    179      */
    180     public void testVFE2() {
    181         try {
    182             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_15");
    183             fail("expected a verification exception");
    184         } catch (Throwable t) {
    185             DxUtil.checkVerifyException(t);
    186         }
    187     }
    188 
    189     /**
    190      * @constraint B1
    191      * @title types of arguments - reference / int
    192      */
    193     public void testVFE3() {
    194         try {
    195             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_16");
    196             fail("expected a verification exception");
    197         } catch (Throwable t) {
    198             DxUtil.checkVerifyException(t);
    199         }
    200     }
    201 
    202     /**
    203      * @constraint A23
    204      * @title  number of registers
    205      */
    206     public void testVFE4() {
    207         try {
    208             Class.forName("dot.junit.opcodes.div_int_lit16.d.T_div_int_lit16_18");
    209             fail("expected a verification exception");
    210         } catch (Throwable t) {
    211             DxUtil.checkVerifyException(t);
    212         }
    213     }
    214 }
    215