1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Thu Feb 14 12:06:16 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,172 +0,0 @@
1.4 -/**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, version 2 of the License.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program. Look for COPYING file in the top folder.
1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 - */
1.21 -package org.apidesign.vm4brwsr;
1.22 -
1.23 -import javax.script.Invocable;
1.24 -import org.testng.annotations.Test;
1.25 -import org.testng.annotations.BeforeClass;
1.26 -
1.27 -/**
1.28 - *
1.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.30 - */
1.31 -public class InstanceTest {
1.32 - @Test public void verifyDefaultDoubleValue() throws Exception {
1.33 - assertExec(
1.34 - "Will be zero",
1.35 - Instance.class, "defaultDblValue__D",
1.36 - Double.valueOf(0)
1.37 - );
1.38 - }
1.39 - @Test public void verifyStaticMethodCall() throws Exception {
1.40 - assertExec(
1.41 - "Will be zero",
1.42 - InstanceSub.class, "recallDbl__D",
1.43 - Double.valueOf(0)
1.44 - );
1.45 - }
1.46 - @Test public void verifyAssignedByteValue() throws Exception {
1.47 - assertExec(
1.48 - "Will one thirty one",
1.49 - Instance.class, "assignedByteValue__B",
1.50 - Double.valueOf(31)
1.51 - );
1.52 - }
1.53 - @Test public void verifyMagicOne() throws Exception {
1.54 - assertExec(
1.55 - "Should be three and something",
1.56 - Instance.class, "magicOne__D",
1.57 - Double.valueOf(3.3)
1.58 - );
1.59 - }
1.60 - @Test public void verifyInstanceMethods() throws Exception {
1.61 - assertExec(
1.62 - "Should be eleven as we invoke overwritten method, plus 44",
1.63 - Instance.class, "virtualBytes__I",
1.64 - Double.valueOf(55)
1.65 - );
1.66 - }
1.67 - @Test public void verifyInterfaceMethods() throws Exception {
1.68 - assertExec(
1.69 - "Retruns default value",
1.70 - Instance.class, "interfaceBytes__F",
1.71 - Double.valueOf(31)
1.72 - );
1.73 - }
1.74 -
1.75 - @Test public void isNull() throws Exception {
1.76 - assertExec(
1.77 - "Yes, we are instance",
1.78 - Instance.class, "isNull__Z",
1.79 - Double.valueOf(0.0)
1.80 - );
1.81 - }
1.82 -
1.83 - @Test public void isInstanceOf() throws Exception {
1.84 - assertExec(
1.85 - "Yes, we are instance",
1.86 - Instance.class, "instanceOf__ZI",
1.87 - Double.valueOf(1.0), 2
1.88 - );
1.89 - }
1.90 -
1.91 - @Test public void notInstanceOf() throws Exception {
1.92 - assertExec(
1.93 - "No, we are not an instance",
1.94 - Instance.class, "instanceOf__ZI",
1.95 - Double.valueOf(0.0), 1
1.96 - );
1.97 - }
1.98 - @Test public void nullInstanceOf() throws Exception {
1.99 - assertExec(
1.100 - "No, null is not an instance",
1.101 - Instance.class, "instanceOf__ZI",
1.102 - Double.valueOf(0.0), 0
1.103 - );
1.104 - }
1.105 -
1.106 - @Test public void verifyCastToClass() throws Exception {
1.107 - assertExec(
1.108 - "Five signals all is good",
1.109 - Instance.class, "castsWork__IZ",
1.110 - Double.valueOf(5.0), false
1.111 - );
1.112 - }
1.113 - @Test public void verifyCastToInterface() throws Exception {
1.114 - assertExec(
1.115 - "Five signals all is good",
1.116 - Instance.class, "castsWork__IZ",
1.117 - Double.valueOf(5.0), true
1.118 - );
1.119 - }
1.120 -
1.121 - @Test public void sharedConstructor() throws Exception {
1.122 - assertExec(
1.123 - "Constructor of first and 2nd instance should be the same",
1.124 - Instance.class, "sharedConstructor__Z",
1.125 - Double.valueOf(1.0)
1.126 - );
1.127 - }
1.128 -
1.129 - @Test public void differentConstructor() throws Exception {
1.130 - assertExec(
1.131 - "Constructor of X and Y should be the different",
1.132 - Instance.class, "differentConstructor__Z",
1.133 - Double.valueOf(0)
1.134 - );
1.135 - }
1.136 -
1.137 - @Test public void jsObjectIsLikeJavaObject() throws Exception {
1.138 - assertExec(
1.139 - "JavaScript object is instance of Java Object",
1.140 - Instance.class, "iofObject__Z",
1.141 - Double.valueOf(1)
1.142 - );
1.143 - }
1.144 -
1.145 - @Test public void jsCallingConvention() throws Exception {
1.146 - assertExec(
1.147 - "Pointer to 'this' is passed automatically (and not as a first argument)",
1.148 - Instance.class, "jscall__I",
1.149 - Double.valueOf(31)
1.150 - );
1.151 - }
1.152 -
1.153 - protected String startCompilationWith() {
1.154 - return "org/apidesign/vm4brwsr/Instance";
1.155 - }
1.156 -
1.157 - private static CharSequence codeSeq;
1.158 - private static Invocable code;
1.159 -
1.160 - @BeforeClass
1.161 - public void compileTheCode() throws Exception {
1.162 - if (codeSeq == null) {
1.163 - StringBuilder sb = new StringBuilder();
1.164 - code = StaticMethodTest.compileClass(sb, startCompilationWith());
1.165 - codeSeq = sb;
1.166 - }
1.167 - }
1.168 -
1.169 - private void assertExec(
1.170 - String msg, Class clazz, String method, Object expRes, Object... args
1.171 - ) throws Exception {
1.172 - StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
1.173 - }
1.174 -
1.175 -}