Home | History | Annotate | Download | only in ldc
      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.ldc;
     18 
     19 import dxc.junit.DxTestCase;
     20 import dxc.junit.DxUtil;
     21 import dxc.junit.opcodes.ldc.jm.T_ldc_1;
     22 import dxc.junit.opcodes.ldc.jm.T_ldc_2;
     23 import dxc.junit.opcodes.ldc.jm.T_ldc_3;
     24 
     25 public class Test_ldc extends DxTestCase {
     26 
     27     /**
     28      * @title push string into stack
     29      */
     30     public void testN1() {
     31         T_ldc_1 t = new T_ldc_1();
     32         // lcd is hard to test isolated
     33         String res = t.run();
     34         assertEquals(5, res.length());
     35         assertEquals('h', res.charAt(0));
     36     }
     37 
     38     /**
     39      * @title push float into stack
     40      */
     41     public void testN2() {
     42         T_ldc_2 t = new T_ldc_2();
     43         float a = 1.5f;
     44         float b = 0.04f;
     45         assertEquals(a + b, t.run(), 0f);
     46         assertEquals(1.54f, t.run(), 0f);
     47     }
     48 
     49     /**
     50      * @title push int into stack
     51      */
     52     public void testN3() {
     53         T_ldc_3 t = new T_ldc_3();
     54         int a = 1000000000;
     55         int b = 1000000000;
     56         assertEquals(a + b, t.run());
     57     }
     58 
     59     /**
     60      * @constraint 4.8.1.10
     61      * @title constant pool index
     62      */
     63     public void testVFE1() {
     64         try {
     65             Class.forName("dxc.junit.opcodes.ldc.jm.T_ldc_4");
     66             fail("expected a verification exception");
     67         } catch (Throwable t) {
     68             DxUtil.checkVerifyException(t);
     69         }
     70     }
     71 
     72     /**
     73      * @constraint 4.8.1.10
     74      * @title wrong constant pool entry type (long)
     75      */
     76     public void testVFE2() {
     77         try {
     78             Class.forName("dxc.junit.opcodes.ldc.jm.T_ldc_5");
     79             fail("expected a verification exception");
     80         } catch (Throwable t) {
     81             DxUtil.checkVerifyException(t);
     82         }
     83     }
     84 }
     85