vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 03 Jan 2013 09:14:57 +0100
changeset 402 1fb46c65f030
parent 248 0bfcb6585290
child 446 5b3d5ed03014
permissions -rw-r--r--
clone works on arrays
     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 javax.script.Invocable;
    21 import static org.testng.Assert.*;
    22 import org.testng.annotations.BeforeClass;
    23 import org.testng.annotations.Test;
    24 
    25 /**
    26  *
    27  * @author Jaroslav Tulach <jtulach@netbeans.org>
    28  */
    29 public class ArrayTest {
    30     @Test public void verifySimpleIntOperation() throws Exception {
    31             assertExec("CheckTheSum", Array.class, "simple__IZ", 
    32             Double.valueOf(15), false
    33         );
    34     }
    35     
    36     @Test public void cloneOnArray() throws Exception {
    37             assertExec("CheckTheSum on clone", Array.class, "simple__IZ", 
    38             Double.valueOf(15), true
    39         );
    40     }
    41     
    42     @Test public void realOperationOnArrays() throws Exception {
    43         assertEquals(Array.sum(), 105.0, "Computes to 105");
    44     }
    45     
    46     @Test public void verifyOperationsOnArrays() throws Exception {
    47         assertExec("The sum is 105", Array.class, "sum__D", 
    48             Double.valueOf(105)
    49         );
    50     }
    51     
    52     @Test public void doesCopyArrayWork() throws Exception {
    53         assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
    54     }
    55     
    56     private static CharSequence codeSeq;
    57     private static Invocable code;
    58     
    59     @BeforeClass 
    60     public void compileTheCode() throws Exception {
    61         StringBuilder sb = new StringBuilder();
    62         code = StaticMethodTest.compileClass(sb, 
    63             "org/apidesign/vm4brwsr/Array"
    64         );
    65         codeSeq = sb;
    66     }
    67     private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
    68         StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
    69     }
    70 }