jaroslav@106
|
1 |
/**
|
jaroslav@106
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@106
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@106
|
4 |
*
|
jaroslav@106
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@106
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@106
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@106
|
8 |
*
|
jaroslav@106
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@106
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@106
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@106
|
12 |
* GNU General Public License for more details.
|
jaroslav@106
|
13 |
*
|
jaroslav@106
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@106
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@106
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@106
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@21
|
19 |
|
jaroslav@21
|
20 |
import static org.testng.Assert.*;
|
jaroslav@789
|
21 |
import org.testng.annotations.AfterClass;
|
jaroslav@103
|
22 |
import org.testng.annotations.BeforeClass;
|
jtulach@128
|
23 |
import org.testng.annotations.Test;
|
jaroslav@21
|
24 |
|
jaroslav@21
|
25 |
/**
|
jaroslav@21
|
26 |
*
|
jaroslav@21
|
27 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@21
|
28 |
*/
|
jaroslav@21
|
29 |
public class ArrayTest {
|
jaroslav@446
|
30 |
@Test public void intArrayShouldBeFilledWithZeroes() throws Exception {
|
jaroslav@446
|
31 |
assertExec("0 + 0", Array.class, "sum__II",
|
jaroslav@446
|
32 |
Double.valueOf(0), 2
|
jaroslav@446
|
33 |
);
|
jaroslav@446
|
34 |
}
|
jaroslav@21
|
35 |
@Test public void verifySimpleIntOperation() throws Exception {
|
jaroslav@402
|
36 |
assertExec("CheckTheSum", Array.class, "simple__IZ",
|
jaroslav@402
|
37 |
Double.valueOf(15), false
|
jaroslav@402
|
38 |
);
|
jaroslav@402
|
39 |
}
|
jaroslav@402
|
40 |
|
jaroslav@402
|
41 |
@Test public void cloneOnArray() throws Exception {
|
jaroslav@402
|
42 |
assertExec("CheckTheSum on clone", Array.class, "simple__IZ",
|
jaroslav@402
|
43 |
Double.valueOf(15), true
|
jaroslav@21
|
44 |
);
|
jaroslav@21
|
45 |
}
|
jaroslav@1532
|
46 |
|
jaroslav@1532
|
47 |
@Test public void cloneOnArrayAndComponentType() throws Exception {
|
jaroslav@1532
|
48 |
String exp = Array.nameOfClonedComponent();
|
jaroslav@1532
|
49 |
assertExec("getComponentType on clone", Array.class, "nameOfClonedComponent__Ljava_lang_String_2",
|
jaroslav@1532
|
50 |
exp
|
jaroslav@1532
|
51 |
);
|
jaroslav@1532
|
52 |
}
|
jtulach@128
|
53 |
|
jtulach@128
|
54 |
@Test public void realOperationOnArrays() throws Exception {
|
jtulach@128
|
55 |
assertEquals(Array.sum(), 105.0, "Computes to 105");
|
jtulach@128
|
56 |
}
|
jtulach@128
|
57 |
|
jaroslav@21
|
58 |
@Test public void verifyOperationsOnArrays() throws Exception {
|
jaroslav@248
|
59 |
assertExec("The sum is 105", Array.class, "sum__D",
|
jaroslav@21
|
60 |
Double.valueOf(105)
|
jaroslav@21
|
61 |
);
|
jaroslav@21
|
62 |
}
|
jaroslav@457
|
63 |
|
jaroslav@457
|
64 |
@Test public void twoDoubles() throws Exception {
|
jaroslav@457
|
65 |
assertExec("Elements are initialized", Array.class, "twoDoubles__D",
|
jaroslav@457
|
66 |
Double.valueOf(0)
|
jaroslav@457
|
67 |
);
|
jaroslav@457
|
68 |
}
|
jaroslav@457
|
69 |
@Test public void twoInts() throws Exception {
|
jaroslav@457
|
70 |
assertExec("Elements are initialized", Array.class, "twoInts__I",
|
jaroslav@457
|
71 |
Double.valueOf(0)
|
jaroslav@457
|
72 |
);
|
jaroslav@457
|
73 |
}
|
jaroslav@21
|
74 |
|
jaroslav@104
|
75 |
@Test public void doesCopyArrayWork() throws Exception {
|
jaroslav@248
|
76 |
assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
|
jaroslav@104
|
77 |
}
|
jaroslav@567
|
78 |
|
jaroslav@567
|
79 |
@Test public void verifyObjectArrayClass() throws Exception {
|
jaroslav@567
|
80 |
assertExec("Returns 'Object[]'", Array.class, "objectArrayClass__Ljava_lang_String_2", Array.objectArrayClass());
|
jaroslav@567
|
81 |
}
|
jaroslav@571
|
82 |
@Test public void verifyInstanceOfArray() throws Exception {
|
jaroslav@571
|
83 |
assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), "non-array");
|
jaroslav@571
|
84 |
}
|
jaroslav@1534
|
85 |
@Test public void verifyInstanceOfArrayOnNull() throws Exception {
|
jaroslav@1534
|
86 |
assertFalse(Array.instanceOfArray(null), "Null is not an instance of array");
|
jaroslav@1534
|
87 |
assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(0), (Object) null);
|
jaroslav@1534
|
88 |
}
|
jaroslav@1534
|
89 |
@Test public void verifyInstanceOfArrayStrings() throws Exception {
|
jaroslav@1534
|
90 |
assertExec("Returns 'false'", Array.class, "instanceOfArray__ZLjava_lang_Object_2", Double.valueOf(1), "string-array");
|
jaroslav@1534
|
91 |
}
|
jaroslav@807
|
92 |
@Test public void verifyMultiLen() throws Exception {
|
jaroslav@807
|
93 |
assertExec("Multi len is one", Array.class, "multiLen__I", Double.valueOf(1));
|
jaroslav@807
|
94 |
}
|
jaroslav@1534
|
95 |
@Test public void upCastAnArray() throws Exception {
|
jaroslav@1534
|
96 |
assertExec("Cannot cast int to string array", Array.class, "castArray__ZI", Double.valueOf(0), Double.valueOf(0));
|
jaroslav@1534
|
97 |
}
|
jaroslav@1534
|
98 |
@Test public void upCastANullArray() throws Exception {
|
jaroslav@1534
|
99 |
assertExec("Can cast null to string array", Array.class, "castArray__ZI", Double.valueOf(1), Double.valueOf(1));
|
jaroslav@1534
|
100 |
}
|
jaroslav@1534
|
101 |
@Test public void upCastOK() throws Exception {
|
jaroslav@1534
|
102 |
assertExec("Can cast string to string array", Array.class, "castArray__ZI", Double.valueOf(1), Double.valueOf(2));
|
jaroslav@1534
|
103 |
}
|
jaroslav@1534
|
104 |
@Test public void upCastOK2() throws Exception {
|
jaroslav@1534
|
105 |
assertExec("Can cast string to char sequence array", Array.class, "castArray__ZI", Double.valueOf(1), Double.valueOf(3));
|
jaroslav@1534
|
106 |
}
|
jaroslav@104
|
107 |
|
jaroslav@708
|
108 |
private static TestVM code;
|
jaroslav@103
|
109 |
|
jaroslav@103
|
110 |
@BeforeClass
|
jaroslav@103
|
111 |
public void compileTheCode() throws Exception {
|
jaroslav@708
|
112 |
code = TestVM.compileClass("org/apidesign/vm4brwsr/Array");
|
jaroslav@103
|
113 |
}
|
jaroslav@789
|
114 |
@AfterClass
|
jaroslav@789
|
115 |
public static void releaseTheCode() {
|
jaroslav@789
|
116 |
code = null;
|
jaroslav@789
|
117 |
}
|
jaroslav@203
|
118 |
private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
|
jaroslav@708
|
119 |
code.assertExec(msg, clazz, method, expRes, args);
|
jaroslav@21
|
120 |
}
|
jaroslav@21
|
121 |
}
|