vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
branchcanvas
changeset 808 bd8b726902a3
parent 731 e8283f10a127
parent 807 e93506e603ad
child 809 5c61f5e4898e
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Thu Feb 14 12:06:16 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,185 +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 static org.testng.Assert.*;
    1.26 -import org.testng.annotations.BeforeClass;
    1.27 -
    1.28 -/**
    1.29 - *
    1.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.31 - */
    1.32 -public class ClassTest {
    1.33 -
    1.34 -    @Test public void superClassEqualsGetSuperclass() {
    1.35 -        assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
    1.36 -    }
    1.37 -
    1.38 -    @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
    1.39 -        assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
    1.40 -    }
    1.41 -
    1.42 -    @Test public void classesAreDifferent() {
    1.43 -        assertTrue(Classes.differenceInClasses(), "Classes are not equal");
    1.44 -    }
    1.45 -
    1.46 -    @Test public void jsClassesAreDifferent() throws Exception {
    1.47 -        assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
    1.48 -    }
    1.49 -
    1.50 -    @Test public void javaInstanceName() throws Exception {
    1.51 -        assertEquals(Classes.classForInstance(), "java.io.IOException");
    1.52 -    }
    1.53 -    @Test public void jsInstanceName() throws Exception {
    1.54 -        assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
    1.55 -    }
    1.56 -    @Test public void javaName() throws Exception {
    1.57 -        assertEquals(Classes.name(), "java.io.IOException");
    1.58 -    }
    1.59 -    @Test public void jsName() throws Exception {
    1.60 -        assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
    1.61 -    }
    1.62 -    @Test public void javaSimpleName() throws Exception {
    1.63 -        assertEquals(Classes.simpleName(), "IOException");
    1.64 -    }
    1.65 -    @Test public void jsGetsSimpleName() throws Exception {
    1.66 -        assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
    1.67 -    }
    1.68 -    @Test public void javaCanonicalName() {
    1.69 -        assertEquals(Classes.canonicalName(), "java.io.IOException");
    1.70 -    }
    1.71 -    @Test public void jsCanonicalName() throws Exception {
    1.72 -        assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
    1.73 -    }
    1.74 -    @Test public void javaNewInstance() throws Exception {
    1.75 -        assertTrue(Classes.newInstance());
    1.76 -    }
    1.77 -    @Test public void jsNewInstance() throws Exception {
    1.78 -        assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
    1.79 -    }
    1.80 -    @Test public void javaNoNewInstance() throws Exception {
    1.81 -        assertEquals("java.lang.InstantiationException:java.lang.Float", 
    1.82 -            Classes.newInstanceNoPubConstructor()
    1.83 -        );
    1.84 -    }
    1.85 -    @Test public void jsNoNewInstance() throws Exception {
    1.86 -        assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2", 
    1.87 -            "java.lang.InstantiationException:java.lang.Float"
    1.88 -        );
    1.89 -    }
    1.90 -    @Test public void jsAnnotation() throws Exception {
    1.91 -        assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
    1.92 -    }
    1.93 -    @Test public void jsStringAnnotation() throws Exception {
    1.94 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
    1.95 -    }
    1.96 -    @Test public void jsStringAnnotationFromArray() throws Exception {
    1.97 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
    1.98 -    }
    1.99 -    @Test public void javaInvokeMethod() throws Exception {
   1.100 -        assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
   1.101 -    }
   1.102 -    @Test public void jsInvokeMethod() throws Exception {
   1.103 -        assertExec("Calls the name() method via reflection", Classes.class, 
   1.104 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
   1.105 -            "java.io.IOException", true, "name"
   1.106 -        );
   1.107 -    }
   1.108 -    @Test public void jsInvokeParamMethod() throws Exception {
   1.109 -        assertExec("sums two numbers via reflection", Classes.class, 
   1.110 -            "reflectiveSum__III", Double.valueOf(5), 2, 3
   1.111 -        );
   1.112 -    }
   1.113 -    @Test public void javaFindMethod() throws Exception {
   1.114 -        assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
   1.115 -    }
   1.116 -    @Test public void jsFindMethod() throws Exception {
   1.117 -        assertExec("Calls the name() method via reflection", Classes.class, 
   1.118 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
   1.119 -            "java.io.IOException", false, "name"
   1.120 -        );
   1.121 -    }
   1.122 -    @Test public void primitiveReturnType() throws Exception {
   1.123 -        assertExec("Tries to get an integer via reflection", Classes.class, 
   1.124 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
   1.125 -            Classes.primitiveType("primitive"), "primitive"
   1.126 -        );
   1.127 -    }
   1.128 -    @Test public void primitiveBoolReturnType() throws Exception {
   1.129 -        assertExec("Tries to get an integer via reflection", Classes.class, 
   1.130 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
   1.131 -            Classes.primitiveType("primitiveB"), "primitiveB"
   1.132 -        );
   1.133 -    }
   1.134 -    @Test public void javaAnnotatedMethod() throws Exception {
   1.135 -        assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
   1.136 -    }
   1.137 -    @Test public void jsAnnotatedMethod() throws Exception {
   1.138 -        assertExec("Calls the name() method via reflection", Classes.class, 
   1.139 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
   1.140 -            "java.io.IOException", false, null
   1.141 -        );
   1.142 -    }
   1.143 -    @Test public void jsClassParam() throws Exception {
   1.144 -        assertExec("Calls the nameOfIO()", Classes.class, 
   1.145 -            "nameOfIO__Ljava_lang_String_2", 
   1.146 -            "java.io.IOException"
   1.147 -        );
   1.148 -    }
   1.149 -    @Test public void noInterface() throws Exception {
   1.150 -        assertExec("Calls Class.isInterface", Classes.class, 
   1.151 -            "isInterface__ZLjava_lang_String_2", 
   1.152 -            0.0, "java.lang.String"
   1.153 -        );
   1.154 -    }
   1.155 -    /*
   1.156 -    @Test public void isInterface() throws Exception {
   1.157 -        assertExec("Calls Class.isInterface", Classes.class, 
   1.158 -            "isInterface__ZLjava_lang_String_2", 
   1.159 -            1.0, "java.lang.Runnable"
   1.160 -        );
   1.161 -    }
   1.162 -    */
   1.163 -    @Test public void integerType() throws Exception {
   1.164 -        assertExec("Computes the type", Classes.class, 
   1.165 -            "intType__Ljava_lang_String_2", 
   1.166 -            Classes.intType()
   1.167 -        );
   1.168 -    }
   1.169 -    
   1.170 -    private static CharSequence codeSeq;
   1.171 -    private static Invocable code;
   1.172 -    
   1.173 -    @BeforeClass
   1.174 -    public void compileTheCode() throws Exception {
   1.175 -        if (codeSeq == null) {
   1.176 -            StringBuilder sb = new StringBuilder();
   1.177 -            code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Classes");
   1.178 -            codeSeq = sb;
   1.179 -        }
   1.180 -    }
   1.181 -    
   1.182 -    private void assertExec(
   1.183 -        String msg, Class clazz, String method, Object expRes, Object... args
   1.184 -    ) throws Exception {
   1.185 -        StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
   1.186 -    }
   1.187 -    
   1.188 -}