1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Mon Feb 25 19:00:08 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,166 +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 org.testng.annotations.Test;
1.24 -import org.testng.annotations.BeforeClass;
1.25 -
1.26 -/**
1.27 - *
1.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.29 - */
1.30 -public class InstanceTest {
1.31 - @Test public void verifyDefaultDoubleValue() throws Exception {
1.32 - assertExec(
1.33 - "Will be zero",
1.34 - Instance.class, "defaultDblValue__D",
1.35 - Double.valueOf(0)
1.36 - );
1.37 - }
1.38 - @Test public void verifyStaticMethodCall() throws Exception {
1.39 - assertExec(
1.40 - "Will be zero",
1.41 - InstanceSub.class, "recallDbl__D",
1.42 - Double.valueOf(0)
1.43 - );
1.44 - }
1.45 - @Test public void verifyAssignedByteValue() throws Exception {
1.46 - assertExec(
1.47 - "Will one thirty one",
1.48 - Instance.class, "assignedByteValue__B",
1.49 - Double.valueOf(31)
1.50 - );
1.51 - }
1.52 - @Test public void verifyMagicOne() throws Exception {
1.53 - assertExec(
1.54 - "Should be three and something",
1.55 - Instance.class, "magicOne__D",
1.56 - Double.valueOf(3.3)
1.57 - );
1.58 - }
1.59 - @Test public void verifyInstanceMethods() throws Exception {
1.60 - assertExec(
1.61 - "Should be eleven as we invoke overwritten method, plus 44",
1.62 - Instance.class, "virtualBytes__I",
1.63 - Double.valueOf(55)
1.64 - );
1.65 - }
1.66 - @Test public void verifyInterfaceMethods() throws Exception {
1.67 - assertExec(
1.68 - "Retruns default value",
1.69 - Instance.class, "interfaceBytes__F",
1.70 - Double.valueOf(31)
1.71 - );
1.72 - }
1.73 -
1.74 - @Test public void isNull() throws Exception {
1.75 - assertExec(
1.76 - "Yes, we are instance",
1.77 - Instance.class, "isNull__Z",
1.78 - Double.valueOf(0.0)
1.79 - );
1.80 - }
1.81 -
1.82 - @Test public void isInstanceOf() throws Exception {
1.83 - assertExec(
1.84 - "Yes, we are instance",
1.85 - Instance.class, "instanceOf__ZI",
1.86 - Double.valueOf(1.0), 2
1.87 - );
1.88 - }
1.89 -
1.90 - @Test public void notInstanceOf() throws Exception {
1.91 - assertExec(
1.92 - "No, we are not an instance",
1.93 - Instance.class, "instanceOf__ZI",
1.94 - Double.valueOf(0.0), 1
1.95 - );
1.96 - }
1.97 - @Test public void nullInstanceOf() throws Exception {
1.98 - assertExec(
1.99 - "No, null is not an instance",
1.100 - Instance.class, "instanceOf__ZI",
1.101 - Double.valueOf(0.0), 0
1.102 - );
1.103 - }
1.104 -
1.105 - @Test public void verifyCastToClass() throws Exception {
1.106 - assertExec(
1.107 - "Five signals all is good",
1.108 - Instance.class, "castsWork__IZ",
1.109 - Double.valueOf(5.0), false
1.110 - );
1.111 - }
1.112 - @Test public void verifyCastToInterface() throws Exception {
1.113 - assertExec(
1.114 - "Five signals all is good",
1.115 - Instance.class, "castsWork__IZ",
1.116 - Double.valueOf(5.0), true
1.117 - );
1.118 - }
1.119 -
1.120 - @Test public void sharedConstructor() throws Exception {
1.121 - assertExec(
1.122 - "Constructor of first and 2nd instance should be the same",
1.123 - Instance.class, "sharedConstructor__Z",
1.124 - Double.valueOf(1.0)
1.125 - );
1.126 - }
1.127 -
1.128 - @Test public void differentConstructor() throws Exception {
1.129 - assertExec(
1.130 - "Constructor of X and Y should be the different",
1.131 - Instance.class, "differentConstructor__Z",
1.132 - Double.valueOf(0)
1.133 - );
1.134 - }
1.135 -
1.136 - @Test public void jsObjectIsLikeJavaObject() throws Exception {
1.137 - assertExec(
1.138 - "JavaScript object is instance of Java Object",
1.139 - Instance.class, "iofObject__Z",
1.140 - Double.valueOf(1)
1.141 - );
1.142 - }
1.143 -
1.144 - @Test public void jsCallingConvention() throws Exception {
1.145 - assertExec(
1.146 - "Pointer to 'this' is passed automatically (and not as a first argument)",
1.147 - Instance.class, "jscall__I",
1.148 - Double.valueOf(31)
1.149 - );
1.150 - }
1.151 -
1.152 - protected String startCompilationWith() {
1.153 - return "org/apidesign/vm4brwsr/Instance";
1.154 - }
1.155 -
1.156 - private static TestVM code;
1.157 -
1.158 - @BeforeClass
1.159 - public void compileTheCode() throws Exception {
1.160 - code = TestVM.compileClass(startCompilationWith());
1.161 - }
1.162 -
1.163 - private void assertExec(
1.164 - String msg, Class clazz, String method, Object expRes, Object... args
1.165 - ) throws Exception {
1.166 - code.assertExec(msg, clazz, method, expRes, args);
1.167 - }
1.168 -
1.169 -}