jaroslav@106: /** jaroslav@106: * Back 2 Browser Bytecode Translator jaroslav@106: * Copyright (C) 2012 Jaroslav Tulach jaroslav@106: * jaroslav@106: * This program is free software: you can redistribute it and/or modify jaroslav@106: * it under the terms of the GNU General Public License as published by jaroslav@106: * the Free Software Foundation, version 2 of the License. jaroslav@106: * jaroslav@106: * This program is distributed in the hope that it will be useful, jaroslav@106: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@106: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@106: * GNU General Public License for more details. jaroslav@106: * jaroslav@106: * You should have received a copy of the GNU General Public License jaroslav@106: * along with this program. Look for COPYING file in the top folder. jaroslav@106: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@106: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@21: jaroslav@21: import static org.testng.Assert.*; jaroslav@103: import org.testng.annotations.BeforeClass; jtulach@128: import org.testng.annotations.Test; jaroslav@21: jaroslav@21: /** jaroslav@21: * jaroslav@21: * @author Jaroslav Tulach jaroslav@21: */ jaroslav@21: public class ArrayTest { jaroslav@446: @Test public void intArrayShouldBeFilledWithZeroes() throws Exception { jaroslav@446: assertExec("0 + 0", Array.class, "sum__II", jaroslav@446: Double.valueOf(0), 2 jaroslav@446: ); jaroslav@446: } jaroslav@21: @Test public void verifySimpleIntOperation() throws Exception { jaroslav@402: assertExec("CheckTheSum", Array.class, "simple__IZ", jaroslav@402: Double.valueOf(15), false jaroslav@402: ); jaroslav@402: } jaroslav@402: jaroslav@402: @Test public void cloneOnArray() throws Exception { jaroslav@402: assertExec("CheckTheSum on clone", Array.class, "simple__IZ", jaroslav@402: Double.valueOf(15), true jaroslav@21: ); jaroslav@21: } jtulach@128: jtulach@128: @Test public void realOperationOnArrays() throws Exception { jtulach@128: assertEquals(Array.sum(), 105.0, "Computes to 105"); jtulach@128: } jtulach@128: jaroslav@21: @Test public void verifyOperationsOnArrays() throws Exception { jaroslav@248: assertExec("The sum is 105", Array.class, "sum__D", jaroslav@21: Double.valueOf(105) jaroslav@21: ); jaroslav@21: } jaroslav@457: jaroslav@457: @Test public void twoDoubles() throws Exception { jaroslav@457: assertExec("Elements are initialized", Array.class, "twoDoubles__D", jaroslav@457: Double.valueOf(0) jaroslav@457: ); jaroslav@457: } jaroslav@457: @Test public void twoInts() throws Exception { jaroslav@457: assertExec("Elements are initialized", Array.class, "twoInts__I", jaroslav@457: Double.valueOf(0) jaroslav@457: ); jaroslav@457: } jaroslav@21: jaroslav@104: @Test public void doesCopyArrayWork() throws Exception { jaroslav@248: assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a')); jaroslav@104: } jaroslav@567: jaroslav@567: @Test public void verifyObjectArrayClass() throws Exception { jaroslav@567: assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass()); jaroslav@567: } jaroslav@571: @Test public void verifyInstanceOfArray() throws Exception { jaroslav@571: assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array"); jaroslav@571: } jaroslav@104: jaroslav@708: private static TestVM code; jaroslav@103: jaroslav@103: @BeforeClass jaroslav@103: public void compileTheCode() throws Exception { jaroslav@708: code = TestVM.compileClass("org/apidesign/vm4brwsr/Array"); jaroslav@103: } jaroslav@203: private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception { jaroslav@708: code.assertExec(msg, clazz, method, expRes, args); jaroslav@21: } jaroslav@21: }