Make sure Object is always available in each VM and each extension.
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 org.testng.annotations.AfterClass;
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__ZI",
84 Double.valueOf(1.0), 2
88 @Test public void notInstanceOf() throws Exception {
90 "No, we are not an instance",
91 Instance.class, "instanceOf__ZI",
92 Double.valueOf(0.0), 1
95 @Test public void nullInstanceOf() throws Exception {
97 "No, null is not an instance",
98 Instance.class, "instanceOf__ZI",
99 Double.valueOf(0.0), 0
103 @Test public void verifyCastToClass() throws Exception {
105 "Five signals all is good",
106 Instance.class, "castsWork__IZ",
107 Double.valueOf(5.0), false
110 @Test public void verifyCastToInterface() throws Exception {
112 "Five signals all is good",
113 Instance.class, "castsWork__IZ",
114 Double.valueOf(5.0), true
118 @Test public void sharedConstructor() throws Exception {
120 "Constructor of first and 2nd instance should be the same",
121 Instance.class, "sharedConstructor__Z",
126 @Test public void differentConstructor() throws Exception {
128 "Constructor of X and Y should be the different",
129 Instance.class, "differentConstructor__Z",
134 @Test public void jsObjectIsLikeJavaObject() throws Exception {
136 "JavaScript object is instance of Java Object",
137 Instance.class, "iofObject__Z",
142 @Test public void jsCallingConvention() throws Exception {
144 "Pointer to 'this' is passed automatically (and not as a first argument)",
145 Instance.class, "jscall__I",
150 protected String startCompilationWith() {
151 return "org/apidesign/vm4brwsr/Instance";
154 private static TestVM code;
157 public void compileTheCode() throws Exception {
158 code = TestVM.compileClass(startCompilationWith());
161 public static void releaseTheCode() {
165 private void assertExec(
166 String msg, Class clazz, String method, Object expRes, Object... args
168 code.assertExec(msg, clazz, method, expRes, args);