1st step in eliminating Class.forName when working with array types. Class.getComponentType on directly allocated arrays does not need that.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.vm4brwsr;
20 import static org.testng.Assert.*;
21 import org.testng.annotations.AfterClass;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.Test;
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class ArrayTest {
30 @Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
31 assertExec("0 + 0", Array.class, "sum__II",
35 @Test public void verifySimpleIntOperation() throws Exception {
36 assertExec("CheckTheSum", Array.class, "simple__IZ",
37 Double.valueOf(15), false
41 @Test public void cloneOnArray() throws Exception {
42 assertExec("CheckTheSum on clone", Array.class, "simple__IZ",
43 Double.valueOf(15), true
47 @Test public void cloneOnArrayAndComponentType() throws Exception {
48 String exp = Array.nameOfClonedComponent();
49 assertExec("getComponentType on clone", Array.class, "nameOfClonedComponent__Ljava_lang_String_2",
54 @Test public void realOperationOnArrays() throws Exception {
55 assertEquals(Array.sum(), 105.0, "Computes to 105");
58 @Test public void verifyOperationsOnArrays() throws Exception {
59 assertExec("The sum is 105", Array.class, "sum__D",
64 @Test public void twoDoubles() throws Exception {
65 assertExec("Elements are initialized", Array.class, "twoDoubles__D",
69 @Test public void twoInts() throws Exception {
70 assertExec("Elements are initialized", Array.class, "twoInts__I",
75 @Test public void doesCopyArrayWork() throws Exception {
76 assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
79 @Test public void verifyObjectArrayClass() throws Exception {
80 assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
82 @Test public void verifyInstanceOfArray() throws Exception {
83 assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
85 @Test public void verifyMultiLen() throws Exception {
86 assertExec("Multi len is one", Array.class, "multiLen__I", Double.valueOf(1));
89 private static TestVM code;
92 public void compileTheCode() throws Exception {
93 code = TestVM.compileClass("org/apidesign/vm4brwsr/Array");
96 public static void releaseTheCode() {
99 private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
100 code.assertExec(msg, clazz, method, expRes, args);