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 javax.script.ScriptException;
22 import org.testng.annotations.Test;
23 import static org.testng.Assert.*;
24 import org.testng.annotations.BeforeClass;
28 * @author Jaroslav Tulach <jtulach@netbeans.org>
30 public class InstanceTest {
31 @Test public void verifyDefaultDoubleValue() throws Exception {
34 Instance.class, "defaultDblValueD",
38 @Test public void verifyStaticMethodCall() throws Exception {
41 InstanceSub.class, "recallDblD",
45 @Test public void verifyAssignedByteValue() throws Exception {
47 "Will one thirty one",
48 Instance.class, "assignedByteValueB",
52 @Test public void verifyMagicOne() throws Exception {
54 "Should be three and something",
55 Instance.class, "magicOneD",
59 @Test public void verifyInstanceMethods() throws Exception {
61 "Should be eleven as we invoke overwritten method, plus 44",
62 Instance.class, "virtualBytesI",
66 @Test public void verifyInterfaceMethods() throws Exception {
68 "Retruns default value",
69 Instance.class, "interfaceBytesF",
74 @Test public void isNull() throws Exception {
76 "Yes, we are instance",
77 Instance.class, "isNullZ",
82 @Test public void isInstanceOf() throws Exception {
84 "Yes, we are instance",
85 Instance.class, "instanceOfZZ",
86 Double.valueOf(1.0), true
90 @Test public void notInstanceOf() throws Exception {
92 "No, we are not an instance",
93 Instance.class, "instanceOfZZ",
94 Double.valueOf(0.0), false
98 @Test public void verifyCastToClass() throws Exception {
100 "Five signals all is good",
101 Instance.class, "castsWorkIZ",
102 Double.valueOf(5.0), false
105 @Test public void verifyCastToInterface() throws Exception {
107 "Five signals all is good",
108 Instance.class, "castsWorkIZ",
109 Double.valueOf(5.0), true
113 protected String startCompilationWith() {
114 return "org/apidesign/vm4brwsr/Instance";
117 private static CharSequence codeSeq;
118 private static Invocable code;
121 public void compileTheCode() throws Exception {
122 if (codeSeq == null) {
123 StringBuilder sb = new StringBuilder();
124 code = StaticMethodTest.compileClass(sb, startCompilationWith());
129 private void assertExec(
130 String msg, Class clazz, String method, Object expRes, Object... args
132 StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);