Static methods needs to be in the prototype, as the bytecode can refer to them as being in a subclass
2 * Java 4 Browser Bytecode Translator
3 * Copyright (C) 2012-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 javax.script.ScriptException;
22 import org.testng.annotations.Test;
23 import static org.testng.Assert.*;
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class InstanceTest {
30 @Test public void verifyDefaultDoubleValue() throws Exception {
33 "org_apidesign_vm4brwsr_Instance_defaultDblValueD",
37 @Test public void verifyStaticMethodCall() throws Exception {
40 "org_apidesign_vm4brwsr_InstanceSub_recallDblD",
44 @Test public void verifyAssignedByteValue() throws Exception {
46 "Will one thirty one",
47 "org_apidesign_vm4brwsr_Instance_assignedByteValueB",
51 @Test public void verifyMagicOne() throws Exception {
53 "Should be three and something",
54 "org_apidesign_vm4brwsr_Instance_magicOneD",
58 @Test public void verifyInstanceMethods() throws Exception {
60 "Should be eleven as we invoke overwritten method, plus 44",
61 "org_apidesign_vm4brwsr_Instance_virtualBytesI",
65 @Test public void verifyInterfaceMethods() throws Exception {
67 "Retruns default value",
68 "org_apidesign_vm4brwsr_Instance_interfaceBytesF",
73 @Test public void isNull() throws Exception {
75 "Yes, we are instance",
76 "org_apidesign_vm4brwsr_Instance_isNullZ",
81 @Test public void isInstanceOf() throws Exception {
83 "Yes, we are instance",
84 "org_apidesign_vm4brwsr_Instance_instanceOfZZ",
85 Double.valueOf(1.0), true
89 @Test public void notInstanceOf() throws Exception {
91 "No, we are not an instance",
92 "org_apidesign_vm4brwsr_Instance_instanceOfZZ",
93 Double.valueOf(0.0), false
97 @Test public void verifyCastToClass() throws Exception {
99 "Five signals all is good",
100 "org_apidesign_vm4brwsr_Instance_castsWorkIZ",
101 Double.valueOf(5.0), false
104 @Test public void verifyCastToInterface() throws Exception {
106 "Five signals all is good",
107 "org_apidesign_vm4brwsr_Instance_castsWorkIZ",
108 Double.valueOf(5.0), true
112 protected String startCompilationWith() {
113 return "org/apidesign/vm4brwsr/Instance";
116 private void assertExec(
117 String msg, String methodName, Object expRes, Object... args
119 StringBuilder sb = new StringBuilder();
120 Invocable i = StaticMethodTest.compileClass(sb, startCompilationWith());
124 ret = i.invokeFunction(methodName, args);
125 } catch (ScriptException ex) {
126 fail("Execution failed in " + sb, ex);
127 } catch (NoSuchMethodException ex) {
128 fail("Cannot find method in " + sb, ex);
130 if (ret == null && expRes == null) {
133 if (expRes.equals(ret)) {
136 assertEquals(ret, expRes, msg + "was: " + ret + "\n" + sb);