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 javax.script.Invocable;
21 import org.testng.annotations.Test;
22 import org.testng.annotations.BeforeClass;
26 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 public class InstanceTest {
29 @Test public void verifyDefaultDoubleValue() throws Exception {
32 Instance.class, "defaultDblValue__D",
36 @Test public void verifyStaticMethodCall() throws Exception {
39 InstanceSub.class, "recallDbl__D",
43 @Test public void verifyAssignedByteValue() throws Exception {
45 "Will one thirty one",
46 Instance.class, "assignedByteValue__B",
50 @Test public void verifyMagicOne() throws Exception {
52 "Should be three and something",
53 Instance.class, "magicOne__D",
57 @Test public void verifyInstanceMethods() throws Exception {
59 "Should be eleven as we invoke overwritten method, plus 44",
60 Instance.class, "virtualBytes__I",
64 @Test public void verifyInterfaceMethods() throws Exception {
66 "Retruns default value",
67 Instance.class, "interfaceBytes__F",
72 @Test public void isNull() throws Exception {
74 "Yes, we are instance",
75 Instance.class, "isNull__Z",
80 @Test public void isInstanceOf() throws Exception {
82 "Yes, we are instance",
83 Instance.class, "instanceOf__ZZ",
84 Double.valueOf(1.0), true
88 @Test public void notInstanceOf() throws Exception {
90 "No, we are not an instance",
91 Instance.class, "instanceOf__ZZ",
92 Double.valueOf(0.0), false
96 @Test public void verifyCastToClass() throws Exception {
98 "Five signals all is good",
99 Instance.class, "castsWork__IZ",
100 Double.valueOf(5.0), false
103 @Test public void verifyCastToInterface() throws Exception {
105 "Five signals all is good",
106 Instance.class, "castsWork__IZ",
107 Double.valueOf(5.0), true
111 @Test public void sharedConstructor() throws Exception {
113 "Constructor of first and 2nd instance should be the same",
114 Instance.class, "sharedConstructor__Z",
119 @Test public void differentConstructor() throws Exception {
121 "Constructor of X and Y should be the different",
122 Instance.class, "differentConstructor__Z",
127 @Test public void jsObjectIsLikeJavaObject() throws Exception {
129 "JavaScript object is instance of Java Object",
130 Instance.class, "iofObject__Z",
135 protected String startCompilationWith() {
136 return "org/apidesign/vm4brwsr/Instance";
139 private static CharSequence codeSeq;
140 private static Invocable code;
143 public void compileTheCode() throws Exception {
144 if (codeSeq == null) {
145 StringBuilder sb = new StringBuilder();
146 code = StaticMethodTest.compileClass(sb, startCompilationWith());
151 private void assertExec(
152 String msg, Class clazz, String method, Object expRes, Object... args
154 StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);