jaroslav@21: /* jaroslav@21: Java 4 Browser Bytecode Translator jaroslav@21: Copyright (C) 2012-2012 Jaroslav Tulach jaroslav@21: jaroslav@21: This program is free software: you can redistribute it and/or modify jaroslav@21: it under the terms of the GNU General Public License as published by jaroslav@21: the Free Software Foundation, version 2 of the License. jaroslav@21: jaroslav@21: This program is distributed in the hope that it will be useful, jaroslav@21: but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@21: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@21: GNU General Public License for more details. jaroslav@21: jaroslav@21: You should have received a copy of the GNU General Public License jaroslav@21: along with this program. Look for COPYING file in the top folder. jaroslav@21: If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@21: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@21: jaroslav@21: import javax.script.Invocable; jaroslav@21: import javax.script.ScriptException; jaroslav@21: import org.testng.annotations.Test; jaroslav@21: import static org.testng.Assert.*; jaroslav@21: jaroslav@21: /** jaroslav@21: * jaroslav@21: * @author Jaroslav Tulach jaroslav@21: */ jaroslav@21: public class ArrayTest { jaroslav@21: @Test public void verifySimpleIntOperation() throws Exception { jaroslav@22: assertExec("CheckTheSum", "org_apidesign_vm4brwsr_Array_simpleI", jaroslav@21: Double.valueOf(15) jaroslav@21: ); jaroslav@21: } jaroslav@21: @Test public void verifyOperationsOnArrays() throws Exception { jaroslav@22: assertExec("The sum is 105", "org_apidesign_vm4brwsr_Array_sumD", jaroslav@21: Double.valueOf(105) jaroslav@21: ); jaroslav@21: } jaroslav@21: jaroslav@21: private static void assertExec(String msg, String methodName, Object expRes, Object... args) throws Exception { jaroslav@21: StringBuilder sb = new StringBuilder(); jaroslav@21: Invocable i = StaticMethodTest.compileClass(sb, jaroslav@22: "org/apidesign/vm4brwsr/Array" jaroslav@21: ); jaroslav@21: jaroslav@21: Object ret = null; jaroslav@21: try { jaroslav@21: ret = i.invokeFunction(methodName, args); jaroslav@21: } catch (ScriptException ex) { jaroslav@21: fail("Execution failed in " + sb, ex); jaroslav@21: } catch (NoSuchMethodException ex) { jaroslav@21: fail("Cannot find method in " + sb, ex); jaroslav@21: } jaroslav@21: if (ret == null && expRes == null) { jaroslav@21: return; jaroslav@21: } jaroslav@21: if (expRes.equals(ret)) { jaroslav@21: return; jaroslav@21: } jaroslav@21: assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb); jaroslav@21: } jaroslav@21: }