Encapsulation. Moving shared code into TestVM instance.
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.BeforeClass;
22 import org.testng.annotations.Test;
24 /** Checks the basic behavior of the translator.
26 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 public class StaticMethodTest {
29 @Test public void threePlusFour() throws Exception {
32 StaticMethod.class, "sum__III",
38 @Test public void checkReallyInitializedValues() throws Exception {
41 StaticMethod.class, "isNull__Z",
46 @Test public void powerOfThree() throws Exception {
49 StaticMethod.class, "power__FF",
55 @Test public void minusOne() throws Exception {
57 "Should be minus one",
58 StaticMethod.class, "minusOne__I",
63 @Test public void doubleWithoutLong() throws Exception {
66 StaticMethod.class, "minus__DDJ",
72 @Test public void rintNegativeUp() throws Exception {
73 final double cnts = -453904.634;
75 "Should round up to end with 5",
76 Math.class, "rint__DD",
81 @Test public void rintNegativeDown() throws Exception {
82 final double cnts = -453904.434;
84 "Should round up to end with 4",
85 Math.class, "rint__DD",
90 @Test public void rintPositiveUp() throws Exception {
91 final double cnts = 453904.634;
93 "Should round up to end with 5",
94 Math.class, "rint__DD",
98 @Test public void rintPositiveDown() throws Exception {
99 final double cnts = 453904.434;
101 "Should round up to end with 4",
102 Math.class, "rint__DD",
106 @Test public void rintOneHalf() throws Exception {
107 final double cnts = 1.5;
109 "Should round up to end with 2",
110 Math.class, "rint__DD",
114 @Test public void rintNegativeOneHalf() throws Exception {
115 final double cnts = -1.5;
117 "Should round up to end with 2",
118 Math.class, "rint__DD",
122 @Test public void rintTwoAndHalf() throws Exception {
123 final double cnts = 2.5;
125 "Should round up to end with 2",
126 Math.class, "rint__DD",
130 @Test public void rintNegativeTwoOneHalf() throws Exception {
131 final double cnts = -2.5;
133 "Should round up to end with 2",
134 Math.class, "rint__DD",
139 @Test public void ieeeReminder1() throws Exception {
142 Math.class, "IEEEremainder__DDD",
143 Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
147 @Test public void ieeeReminder2() throws Exception {
150 Math.class, "IEEEremainder__DDD",
151 Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
155 @Test public void divAndRound() throws Exception {
157 "Should be rounded to one",
158 StaticMethod.class, "div__IBD",
163 @Test public void mixedMethodFourParams() throws Exception {
166 StaticMethod.class, "mix__IIJBD",
171 @Test public void factRec() throws Exception {
173 "Factorial of 5 is 120",
174 StaticMethod.class, "factRec__JI",
179 @Test public void factIter() throws Exception {
181 "Factorial of 5 is 120",
182 StaticMethod.class, "factIter__JI",
188 @Test public void xor() throws Exception {
191 StaticMethod.class, "xor__JIJ",
198 @Test public void or() throws Exception {
201 StaticMethod.class, "orOrAnd__JZII",
208 @Test public void nullCheck() throws Exception {
211 StaticMethod.class, "none__Ljava_lang_Object_2II",
215 @Test public void and() throws Exception {
218 StaticMethod.class, "orOrAnd__JZII",
225 @Test public void inc4() throws Exception {
228 StaticMethod.class, "inc4__I",
233 @Test public void shiftLeftInJava() throws Exception {
234 int res = StaticMethod.shiftLeft(1, 8);
235 assertEquals(res, 256);
238 @Test public void shiftLeftInJS() throws Exception {
241 StaticMethod.class, "shiftLeft__III",
247 @Test public void shiftRightInJava() throws Exception {
248 int res = StaticMethod.shiftArithmRight(-8, 3, true);
249 assertEquals(res, -1);
252 @Test public void shiftRightInJS() throws Exception {
255 StaticMethod.class, "shiftArithmRight__IIIZ",
260 @Test public void unsignedShiftRightInJava() throws Exception {
261 int res = StaticMethod.shiftArithmRight(8, 3, false);
262 assertEquals(res, 1);
265 @Test public void unsignedShiftRightInJS() throws Exception {
268 StaticMethod.class, "shiftArithmRight__IIIZ",
274 @Test public void javaScriptBody() throws Exception {
277 StaticMethod.class, "i2s__Ljava_lang_String_2II",
283 @Test public void switchJarda() throws Exception {
285 "The expected value",
286 StaticMethod.class, "swtch__Ljava_lang_String_2I",
292 @Test public void switchDarda() throws Exception {
294 "The expected value",
295 StaticMethod.class, "swtch__Ljava_lang_String_2I",
300 @Test public void switchParda() throws Exception {
302 "The expected value",
303 StaticMethod.class, "swtch2__Ljava_lang_String_2I",
308 @Test public void switchMarda() throws Exception {
310 "The expected value",
311 StaticMethod.class, "swtch__Ljava_lang_String_2I",
317 @Test public void checkNullCast() throws Exception {
318 assertExec("Null can be cast to any type",
319 StaticMethod.class, "castNull__Ljava_lang_String_2Z",
324 private static TestVM code;
327 public void compileTheCode() throws Exception {
328 StringBuilder sb = new StringBuilder();
329 code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
332 private void assertExec(
333 String msg, Class<?> clazz, String method,
334 Object ret, Object... args
336 code.assertExec(msg, clazz, method, ret, args);