Home | History | Annotate | Download | only in neg_int
      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.neg_int;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.neg_int.d.T_neg_int_1;
     22 import dot.junit.opcodes.neg_int.d.T_neg_int_2;
     23 import dot.junit.opcodes.neg_int.d.T_neg_int_7;
     24 
     25 public class Test_neg_int extends DxTestCase {
     26 
     27     /**
     28      * @title Argument = 1
     29      */
     30     public void testN1() {
     31         T_neg_int_1 t = new T_neg_int_1();
     32         assertEquals(-1, t.run(1));
     33     }
     34 
     35     /**
     36      * @title Argument = -1
     37      */
     38     public void testN2() {
     39         T_neg_int_1 t = new T_neg_int_1();
     40         assertEquals(1, t.run(-1));
     41     }
     42 
     43     /**
     44      * @title Argument = 32768
     45      */
     46     public void testN3() {
     47         T_neg_int_1 t = new T_neg_int_1();
     48         assertEquals(-32768, t.run(32768));
     49     }
     50 
     51     /**
     52      * @title Argument = 0
     53      */
     54     public void testN4() {
     55         T_neg_int_1 t = new T_neg_int_1();
     56         assertEquals(0, t.run(0));
     57     }
     58 
     59     /**
     60      * @title Check that -x == (~x + 1)
     61      */
     62     public void testN5() {
     63         T_neg_int_2 t = new T_neg_int_2();
     64         assertTrue(t.run(5));
     65     }
     66 
     67     /**
     68      * @title Argument = Integer.MAX_VALUE
     69      */
     70     public void testB1() {
     71         T_neg_int_1 t = new T_neg_int_1();
     72         assertEquals(0x80000001, t.run(Integer.MAX_VALUE));
     73     }
     74 
     75     /**
     76      * @title Argument = Integer.MIN_VALUE
     77      */
     78     public void testB2() {
     79         T_neg_int_1 t = new T_neg_int_1();
     80         assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE));
     81     }
     82 
     83     /**
     84      * @constraint A23
     85      * @title  number of registers
     86      */
     87     public void testVFE1() {
     88         try {
     89             Class.forName("dot.junit.opcodes.neg_int.d.T_neg_int_3");
     90             fail("expected a verification exception");
     91         } catch (Throwable t) {
     92             DxUtil.checkVerifyException(t);
     93         }
     94     }
     95 
     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.neg_int.d.T_neg_int_4");
    106             fail("expected a verification exception");
    107         } catch (Throwable t) {
    108             DxUtil.checkVerifyException(t);
    109         }
    110     }
    111 
    112     /**
    113      *
    114      * @constraint B1
    115      * @title  type of argument - long
    116      */
    117     public void testVFE3() {
    118         try {
    119             Class.forName("dot.junit.opcodes.neg_int.d.T_neg_int_5");
    120             fail("expected a verification exception");
    121         } catch (Throwable t) {
    122             DxUtil.checkVerifyException(t);
    123         }
    124     }
    125 
    126     /**
    127      *
    128      * @constraint B1
    129      * @title  type of argument - reference
    130      */
    131     public void testVFE4() {
    132         try {
    133             Class.forName("dot.junit.opcodes.neg_int.d.T_neg_int_6");
    134             fail("expected a verification exception");
    135         } catch (Throwable t) {
    136             DxUtil.checkVerifyException(t);
    137         }
    138     }
    139 
    140     /**
    141      * @constraint B1
    142      * @title Types of arguments - float, int. The verifier checks that ints
    143      * and floats are not used interchangeably.
    144      */
    145     public void testVFE5() {
    146         try {
    147             Class.forName("dot.junit.opcodes.neg_int.d.T_neg_int_7");
    148             fail("expected a verification exception");
    149         } catch (Throwable t) {
    150             DxUtil.checkVerifyException(t);
    151         }
    152     }
    153 }
    154