releasing the compiled code as soon as it is no longer needed to prevent OutOfMemoryError when adding more and more tests
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;
25 /** Checks the basic behavior of the translator.
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class StaticMethodTest {
30 @Test public void threePlusFour() throws Exception {
33 StaticMethod.class, "sum__III",
39 @Test public void checkReallyInitializedValues() throws Exception {
42 StaticMethod.class, "isNull__Z",
47 @Test public void powerOfThree() throws Exception {
50 StaticMethod.class, "power__FF",
56 @Test public void minusOne() throws Exception {
58 "Should be minus one",
59 StaticMethod.class, "minusOne__I",
64 @Test public void doubleWithoutLong() throws Exception {
67 StaticMethod.class, "minus__DDJ",
73 @Test public void rintNegativeUp() throws Exception {
74 final double cnts = -453904.634;
76 "Should round up to end with 5",
77 Math.class, "rint__DD",
82 @Test public void rintNegativeDown() throws Exception {
83 final double cnts = -453904.434;
85 "Should round up to end with 4",
86 Math.class, "rint__DD",
91 @Test public void rintPositiveUp() throws Exception {
92 final double cnts = 453904.634;
94 "Should round up to end with 5",
95 Math.class, "rint__DD",
99 @Test public void rintPositiveDown() throws Exception {
100 final double cnts = 453904.434;
102 "Should round up to end with 4",
103 Math.class, "rint__DD",
107 @Test public void rintOneHalf() throws Exception {
108 final double cnts = 1.5;
110 "Should round up to end with 2",
111 Math.class, "rint__DD",
115 @Test public void rintNegativeOneHalf() throws Exception {
116 final double cnts = -1.5;
118 "Should round up to end with 2",
119 Math.class, "rint__DD",
123 @Test public void rintTwoAndHalf() throws Exception {
124 final double cnts = 2.5;
126 "Should round up to end with 2",
127 Math.class, "rint__DD",
131 @Test public void rintNegativeTwoOneHalf() throws Exception {
132 final double cnts = -2.5;
134 "Should round up to end with 2",
135 Math.class, "rint__DD",
140 @Test public void ieeeReminder1() throws Exception {
143 Math.class, "IEEEremainder__DDD",
144 Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
148 @Test public void ieeeReminder2() throws Exception {
151 Math.class, "IEEEremainder__DDD",
152 Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
156 @Test public void divAndRound() throws Exception {
158 "Should be rounded to one",
159 StaticMethod.class, "div__IBD",
164 @Test public void mixedMethodFourParams() throws Exception {
167 StaticMethod.class, "mix__IIJBD",
172 @Test public void factRec() throws Exception {
174 "Factorial of 5 is 120",
175 StaticMethod.class, "factRec__JI",
180 @Test public void factIter() throws Exception {
182 "Factorial of 5 is 120",
183 StaticMethod.class, "factIter__JI",
189 @Test public void xor() throws Exception {
192 StaticMethod.class, "xor__JIJ",
199 @Test public void or() throws Exception {
202 StaticMethod.class, "orOrAnd__JZII",
209 @Test public void nullCheck() throws Exception {
212 StaticMethod.class, "none__Ljava_lang_Object_2II",
216 @Test public void and() throws Exception {
219 StaticMethod.class, "orOrAnd__JZII",
226 @Test public void inc4() throws Exception {
229 StaticMethod.class, "inc4__I",
234 @Test public void shiftLeftInJava() throws Exception {
235 int res = StaticMethod.shiftLeft(1, 8);
236 assertEquals(res, 256);
239 @Test public void shiftLeftInJS() throws Exception {
242 StaticMethod.class, "shiftLeft__III",
248 @Test public void shiftRightInJava() throws Exception {
249 int res = StaticMethod.shiftArithmRight(-8, 3, true);
250 assertEquals(res, -1);
253 @Test public void shiftRightInJS() throws Exception {
256 StaticMethod.class, "shiftArithmRight__IIIZ",
261 @Test public void unsignedShiftRightInJava() throws Exception {
262 int res = StaticMethod.shiftArithmRight(8, 3, false);
263 assertEquals(res, 1);
266 @Test public void unsignedShiftRightInJS() throws Exception {
269 StaticMethod.class, "shiftArithmRight__IIIZ",
275 @Test public void javaScriptBody() throws Exception {
278 StaticMethod.class, "i2s__Ljava_lang_String_2II",
284 @Test public void switchJarda() throws Exception {
286 "The expected value",
287 StaticMethod.class, "swtch__Ljava_lang_String_2I",
293 @Test public void switchDarda() throws Exception {
295 "The expected value",
296 StaticMethod.class, "swtch__Ljava_lang_String_2I",
301 @Test public void switchParda() throws Exception {
303 "The expected value",
304 StaticMethod.class, "swtch2__Ljava_lang_String_2I",
309 @Test public void switchMarda() throws Exception {
311 "The expected value",
312 StaticMethod.class, "swtch__Ljava_lang_String_2I",
318 @Test public void checkNullCast() throws Exception {
319 assertExec("Null can be cast to any type",
320 StaticMethod.class, "castNull__Ljava_lang_String_2Z",
325 private static TestVM code;
328 public static void compileTheCode() throws Exception {
329 StringBuilder sb = new StringBuilder();
330 code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
333 public static void releaseTheCode() {
337 private void assertExec(
338 String msg, Class<?> clazz, String method,
339 Object ret, Object... args
341 code.assertExec(msg, clazz, method, ret, args);