vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 11 Feb 2013 12:46:43 +0100
branchemul
changeset 708 59d5596a9c6c
parent 571 62c327a1e23f
permissions -rw-r--r--
Encapsulation. Moving shared code into TestVM instance.
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package org.apidesign.vm4brwsr;
    19 
    20 import static org.testng.Assert.*;
    21 import org.testng.annotations.BeforeClass;
    22 import org.testng.annotations.Test;
    23 
    24 /**
    25  *
    26  * @author Jaroslav Tulach <jtulach@netbeans.org>
    27  */
    28 public class ArrayTest {
    29     @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
    30             assertExec("0 + 0", Array.class, "sum__II", 
    31             Double.valueOf(0), 2
    32         );
    33     }
    34     @Test public void verifySimpleIntOperation() throws Exception {
    35             assertExec("CheckTheSum", Array.class, "simple__IZ", 
    36             Double.valueOf(15), false
    37         );
    38     }
    39     
    40     @Test public void cloneOnArray() throws Exception {
    41             assertExec("CheckTheSum on clone", Array.class, "simple__IZ", 
    42             Double.valueOf(15), true
    43         );
    44     }
    45     
    46     @Test public void realOperationOnArrays() throws Exception {
    47         assertEquals(Array.sum(), 105.0, "Computes to 105");
    48     }
    49     
    50     @Test public void verifyOperationsOnArrays() throws Exception {
    51         assertExec("The sum is 105", Array.class, "sum__D", 
    52             Double.valueOf(105)
    53         );
    54     }
    55 
    56     @Test public void twoDoubles() throws Exception {
    57         assertExec("Elements are initialized", Array.class, "twoDoubles__D", 
    58             Double.valueOf(0)
    59         );
    60     }
    61     @Test public void twoInts() throws Exception {
    62         assertExec("Elements are initialized", Array.class, "twoInts__I", 
    63             Double.valueOf(0)
    64         );
    65     }
    66     
    67     @Test public void doesCopyArrayWork() throws Exception {
    68         assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
    69     }
    70 
    71     @Test public void verifyObjectArrayClass() throws Exception {
    72         assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
    73     }
    74     @Test public void verifyInstanceOfArray() throws Exception {
    75         assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
    76     }
    77     
    78     private static TestVM code;
    79     
    80     @BeforeClass 
    81     public void compileTheCode() throws Exception {
    82         code = TestVM.compileClass("org/apidesign/vm4brwsr/Array");
    83     }
    84     private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
    85         code.assertExec(msg, clazz, method, expRes, args);
    86     }
    87 }