Home | History | Annotate | Download | only in rsub_int_lit8
      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.rsub_int_lit8;
     18 
     19 import dot.junit.DxTestCase;
     20 import dot.junit.DxUtil;
     21 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_1;
     22 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_2;
     23 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_3;
     24 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_4;
     25 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_5;
     26 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_6;
     27 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_7;
     28 import dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_12;
     29 
     30 public class Test_rsub_int_lit8 extends DxTestCase {
     31 
     32     /**
     33      * @title normal test - check different values
     34      */
     35     public void testN1() {
     36         T_rsub_int_lit8_1 t = new T_rsub_int_lit8_1();
     37         assertEquals("Subtest_1 is failed", -4, t.run(8));
     38         assertEquals("Subtest_2 is failed",45, t.run1(15));
     39         assertEquals("Subtest_3 is failed",0, t.run2(20));
     40         assertEquals("Subtest_4 is failed",-35, t.run3(10));
     41         assertEquals("Subtest_5 is failed",-20, t.run4(-50));
     42         assertEquals("Subtest_6 is failed",20, t.run5(-70));
     43     }
     44 
     45     /**
     46      * @title normal test - check different values
     47      */
     48     public void testN2() {
     49         T_rsub_int_lit8_2 t = new T_rsub_int_lit8_2();
     50         assertEquals("Subtest_1 is failed",123, t.run(0));
     51         assertEquals("Subtest_2 is failed",-123, t.run1(0));
     52         assertEquals("Subtest_3 is failed",-15, t.run2(15));
     53         assertEquals("Subtest_4 is failed",85, t.run2(-85));
     54     }
     55 
     56     /**
     57      * @title Types of arguments - float, int. Dalvik doens't distinguish 32-bits types internally,
     58      * so this operation of float and int makes no sense but shall not crash the VM.
     59      */
     60     public void testN3() {
     61         T_rsub_int_lit8_12 t = new T_rsub_int_lit8_12();
     62         try {
     63             t.run(3.14f);
     64         } catch (Throwable e) {
     65         }
     66     }
     67 
     68     /**
     69      * @title
     70      * 1: a = Integer.MAX_VALUE, b = 0, b-a = -Integer.MAX_VALUE
     71      * 2: a = Byte.MAX_VALUE, b = 0, b-a = -Byte.MAX_VALUE
     72      */
     73     public void testB1() {
     74         T_rsub_int_lit8_3 t = new T_rsub_int_lit8_3();
     75         assertEquals(-Integer.MAX_VALUE, t.run(Integer.MAX_VALUE));
     76         assertEquals(-Byte.MAX_VALUE, t.run(Byte.MAX_VALUE));
     77     }
     78 
     79     /**
     80      * @title
     81      * 1: a = Integer.MIN_VALUE, b = 0, b-a = Integer.MIN_VALUE
     82      * 2: a = Byte.MIN_VALUE, b = 0, b-a = 128
     83      */
     84     public void testB2() {
     85         T_rsub_int_lit8_3 t = new T_rsub_int_lit8_3();
     86         assertEquals(Integer.MIN_VALUE, t.run(Integer.MIN_VALUE));
     87         assertEquals(128, t.run(Byte.MIN_VALUE));
     88     }
     89 
     90     /**
     91      * @title (a = 0, b = 0, b-a = 0)
     92      */
     93     public void testB3() {
     94         T_rsub_int_lit8_3 t = new T_rsub_int_lit8_3();
     95         assertEquals(0, t.run(0));
     96     }
     97 
     98     /**
     99      * @title
    100      * 1: a = 0, b = Byte.MAX_VALUE, b-a = Byte.MAX_VALUE
    101      * 2: a = 1, b = Byte.MAX_VALUE, b-a = 126
    102      * 3: a = -1, b = Byte.MAX_VALUE, b-a = 128
    103      */
    104     public void testB4() {
    105         T_rsub_int_lit8_4 t = new T_rsub_int_lit8_4();
    106         assertEquals(Byte.MAX_VALUE, t.run(0));
    107         assertEquals(126, t.run(1));
    108         assertEquals(128, t.run(-1));
    109     }
    110 
    111     /**
    112      * @title
    113      * 1: a = Integer.MIN_VALUE, b = Byte.MAX_VALUE, b-a = -2147483521
    114      * 2: a = Integer.MAX_VALUE, b = Byte.MAX_VALUE, b-a = -2147483520
    115      * 3: a = Byte.MIN_VALUE, b = Byte.MAX_VALUE, b-a = 255
    116      */
    117     public void testB5() {
    118         T_rsub_int_lit8_4 t = new T_rsub_int_lit8_4();
    119         assertEquals(-2147483521, t.run(Integer.MIN_VALUE));
    120         assertEquals(-2147483520, t.run(Integer.MAX_VALUE));
    121         assertEquals(255, t.run(Byte.MIN_VALUE));
    122     }
    123 
    124     /**
    125      * @title
    126      * 1: a = 0, b = Byte.MIN_VALUE, b-a = Byte.MIN_VALUE
    127      * 2: a = 1, b = Byte.MIN_VALUE, b-a = -129
    128      * 3: a = -1, b = Byte.MIN_VALUE, b-a = -127
    129      */
    130     public void testB6() {
    131         T_rsub_int_lit8_5 t = new T_rsub_int_lit8_5();
    132         assertEquals(Byte.MIN_VALUE, t.run(0));
    133         assertEquals(-129, t.run(1));
    134         assertEquals(-127, t.run(-1));
    135     }
    136 
    137     /**
    138      * @title
    139      * 1: a = Integer.MAX_VALUE, b = Byte.MIN_VALUE, b-a = 2147483521
    140      * 2: a = Integer.MIN_VALUE, b = Byte.MIN_VALUE, b-a = 2147483520
    141      * 3: a = Byte.MAX_VALUE, b = Byte.MIN_VALUE, b-a = -255
    142      */
    143     public void testB7() {
    144         T_rsub_int_lit8_5 t = new T_rsub_int_lit8_5();
    145         assertEquals(2147483521, t.run(Integer.MAX_VALUE));
    146         assertEquals(2147483520, t.run(Integer.MIN_VALUE));
    147         assertEquals(-255, t.run(Byte.MAX_VALUE));
    148     }
    149 
    150     /**
    151      * @title
    152      * 1: a = Integer.MIN_VALUE, b = -1, b-a = Integer.MAX_VALUE
    153      * 2: a = Byte.MIN_VALUE, b = -1, b-a = Byte.MAX_VALUE
    154      */
    155     public void testB8() {
    156         T_rsub_int_lit8_6 t = new T_rsub_int_lit8_6();
    157         assertEquals(Integer.MAX_VALUE, t.run(Integer.MIN_VALUE));
    158         assertEquals(Byte.MAX_VALUE, t.run(Byte.MIN_VALUE));
    159     }
    160 
    161     /**
    162      * @title
    163      * 1: a = Integer.MAX_VALUE, b = -1, b-a = Integer.MIN_VALUE
    164      * 2: a = Byte.MAX_VALUE, b = -1, b-a = Byte.MIN_VALUE
    165      */
    166     public void testB9() {
    167         T_rsub_int_lit8_6 t = new T_rsub_int_lit8_6();
    168         assertEquals(Integer.MIN_VALUE, t.run(Integer.MAX_VALUE));
    169         assertEquals(Byte.MIN_VALUE, t.run(Byte.MAX_VALUE));
    170     }
    171 
    172     /**
    173      * @title
    174      * 1: a = Integer.MIN_VALUE, b = 1, b-a = -Integer.MAX_VALUE
    175      * 2: a = Integer.MAX_VALUE, b = 1, b-a = -2147483646
    176      */
    177     public void testB10() {
    178         T_rsub_int_lit8_7 t = new T_rsub_int_lit8_7();
    179         assertEquals(-Integer.MAX_VALUE, t.run(Integer.MIN_VALUE));
    180         assertEquals(-2147483646, t.run(Integer.MAX_VALUE));
    181     }
    182 
    183     /**
    184      * @title
    185      * 1: a = Byte.MIN_VALUE, b = 1, b-a = 129
    186      * 2: a = Byte.MAX_VALUE, b = 1, b-a = -126
    187      */
    188     public void testB11() {
    189         T_rsub_int_lit8_7 t = new T_rsub_int_lit8_7();
    190         assertEquals(129, t.run(Byte.MIN_VALUE));
    191         assertEquals(-126, t.run(Byte.MAX_VALUE));
    192     }
    193 
    194     /**
    195      * @title (a = 1, b = 1, b-a = 0)
    196      */
    197     public void testB12() {
    198         T_rsub_int_lit8_7 t = new T_rsub_int_lit8_7();
    199         assertEquals(0, t.run(1));
    200     }
    201 
    202     /**
    203      * @constraint A23
    204      * @title number of registers
    205      */
    206     public void testVFE1() {
    207         try {
    208             Class.forName("dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_8");
    209             fail("expected a verification exception");
    210         } catch (Throwable t) {
    211             DxUtil.checkVerifyException(t);
    212         }
    213     }
    214 
    215 
    216 
    217     /**
    218      * @constraint B1
    219      * @title types of arguments - double, int
    220      */
    221     public void testVFE2() {
    222         try {
    223             Class.forName("dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_9");
    224             fail("expected a verification exception");
    225         } catch (Throwable t) {
    226             DxUtil.checkVerifyException(t);
    227         }
    228     }
    229 
    230     /**
    231      * @constraint B1
    232      * @title types of arguments - long, int
    233      */
    234     public void testVFE3() {
    235         try {
    236             Class.forName("dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_10");
    237             fail("expected a verification exception");
    238         } catch (Throwable t) {
    239             DxUtil.checkVerifyException(t);
    240         }
    241     }
    242 
    243     /**
    244      * @constraint B1
    245      * @title types of arguments - reference, int
    246      */
    247     public void testVFE4() {
    248         try {
    249             Class.forName("dot.junit.opcodes.rsub_int_lit8.d.T_rsub_int_lit8_11");
    250             fail("expected a verification exception");
    251         } catch (Throwable t) {
    252             DxUtil.checkVerifyException(t);
    253         }
    254     }
    255 }
    256