vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
branchmodel
changeset 878 ecbd252fd3a7
parent 877 3392f250c784
parent 871 6168fb585ab4
child 879 af170d42b5b3
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Fri Mar 22 16:59:47 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,206 +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 static org.testng.Assert.*;
    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 ClassTest {
    1.32 -
    1.33 -    @Test public void superClassEqualsGetSuperclass() {
    1.34 -        assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
    1.35 -    }
    1.36 -
    1.37 -    @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
    1.38 -        assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
    1.39 -    }
    1.40 -
    1.41 -    @Test public void classesAreDifferent() {
    1.42 -        assertTrue(Classes.differenceInClasses(), "Classes are not equal");
    1.43 -    }
    1.44 -
    1.45 -    @Test public void jsClassesAreDifferent() throws Exception {
    1.46 -        assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
    1.47 -    }
    1.48 -
    1.49 -    @Test public void javaInstanceName() throws Exception {
    1.50 -        assertEquals(Classes.classForInstance(), "java.io.IOException");
    1.51 -    }
    1.52 -    @Test public void jsInstanceName() throws Exception {
    1.53 -        assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
    1.54 -    }
    1.55 -    @Test public void javaName() throws Exception {
    1.56 -        assertEquals(Classes.name(), "java.io.IOException");
    1.57 -    }
    1.58 -    @Test public void jsName() throws Exception {
    1.59 -        assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
    1.60 -    }
    1.61 -    @Test public void javaSimpleName() throws Exception {
    1.62 -        assertEquals(Classes.simpleName(), "IOException");
    1.63 -    }
    1.64 -    @Test public void jsGetsSimpleName() throws Exception {
    1.65 -        assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
    1.66 -    }
    1.67 -    @Test public void javaCanonicalName() {
    1.68 -        assertEquals(Classes.canonicalName(), "java.io.IOException");
    1.69 -    }
    1.70 -    @Test public void jsCanonicalName() throws Exception {
    1.71 -        assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
    1.72 -    }
    1.73 -    @Test public void javaNewInstance() throws Exception {
    1.74 -        assertTrue(Classes.newInstance());
    1.75 -    }
    1.76 -    @Test public void jsNewInstance() throws Exception {
    1.77 -        assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
    1.78 -    }
    1.79 -    @Test public void javaNoNewInstance() throws Exception {
    1.80 -        assertEquals("java.lang.InstantiationException:java.lang.Float", 
    1.81 -            Classes.newInstanceNoPubConstructor()
    1.82 -        );
    1.83 -    }
    1.84 -    @Test public void jsNoNewInstance() throws Exception {
    1.85 -        assertExec("Check problems with new instance", Classes.class, "newInstanceNoPubConstructor__Ljava_lang_String_2", 
    1.86 -            "java.lang.InstantiationException:java.lang.Float"
    1.87 -        );
    1.88 -    }
    1.89 -    @Test public void jsAnnotation() throws Exception {
    1.90 -        assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
    1.91 -    }
    1.92 -    @Test public void jsArrayAnnotation() throws Exception {
    1.93 -        assertExec("Check array annotation", Classes.class, "getMarkerNicknames__Ljava_lang_String_2", Classes.getMarkerNicknames());
    1.94 -    }
    1.95 -    @Test public void jsEnumAnnotation() throws Exception {
    1.96 -        assertExec("Check enum annotation", Classes.class, "getMarkerE__Ljava_lang_String_2", Classes.getMarkerE());
    1.97 -    }
    1.98 -    @Test public void jsRetentionAnnotation() throws Exception {
    1.99 -        assertExec("Check enum annotation", Classes.class, "getRetention__Ljava_lang_String_2", Classes.getRetention());
   1.100 -    }
   1.101 -    @Test public void jsStringAnnotation() throws Exception {
   1.102 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
   1.103 -    }
   1.104 -    @Test public void jsStringAnnotationFromArray() throws Exception {
   1.105 -        assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
   1.106 -    }
   1.107 -    @Test public void jsInnerAnnotation() throws Exception {
   1.108 -        assertExec("Check inner annotation", Classes.class, "getInnerNamer__I", Double.valueOf(Classes.getInnerNamer()));
   1.109 -    }
   1.110 -    @Test public void jsInnerAnnotationFromArray() throws Exception {
   1.111 -        assertExec("Check inner annotation", Classes.class, "getInnerNamers__I", Double.valueOf(Classes.getInnerNamers()));
   1.112 -    }
   1.113 -    @Test public void javaInvokeMethod() throws Exception {
   1.114 -        assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
   1.115 -    }
   1.116 -    @Test public void jsInvokeMethod() 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", true, "name"
   1.120 -        );
   1.121 -    }
   1.122 -    
   1.123 -    @Test public void jsMethodDeclaredInObject() throws Exception {
   1.124 -        assertExec("Defined in Object", Classes.class, 
   1.125 -            "objectName__Ljava_lang_String_2", 
   1.126 -            "java.lang.Object"
   1.127 -        );
   1.128 -    }
   1.129 -    
   1.130 -    @Test public void jsInvokeParamMethod() throws Exception {
   1.131 -        assertExec("sums two numbers via reflection", Classes.class, 
   1.132 -            "reflectiveSum__III", Double.valueOf(5), 2, 3
   1.133 -        );
   1.134 -    }
   1.135 -    @Test public void javaFindMethod() throws Exception {
   1.136 -        assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
   1.137 -    }
   1.138 -    @Test public void jsFindMethod() throws Exception {
   1.139 -        assertExec("Calls the name() method via reflection", Classes.class, 
   1.140 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
   1.141 -            "java.io.IOException", false, "name"
   1.142 -        );
   1.143 -    }
   1.144 -    @Test public void primitiveReturnType() throws Exception {
   1.145 -        assertExec("Tries to get an integer via reflection", Classes.class, 
   1.146 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
   1.147 -            Classes.primitiveType("primitive"), "primitive"
   1.148 -        );
   1.149 -    }
   1.150 -    @Test public void primitiveBoolReturnType() throws Exception {
   1.151 -        assertExec("Tries to get an integer via reflection", Classes.class, 
   1.152 -            "primitiveType__Ljava_lang_String_2Ljava_lang_String_2", 
   1.153 -            Classes.primitiveType("primitiveB"), "primitiveB"
   1.154 -        );
   1.155 -    }
   1.156 -    @Test public void javaAnnotatedMethod() throws Exception {
   1.157 -        assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
   1.158 -    }
   1.159 -    @Test public void jsAnnotatedMethod() throws Exception {
   1.160 -        assertExec("Calls the name() method via reflection", Classes.class, 
   1.161 -            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
   1.162 -            "java.io.IOException", false, null
   1.163 -        );
   1.164 -    }
   1.165 -    @Test public void jsClassParam() throws Exception {
   1.166 -        assertExec("Calls the nameOfIO()", Classes.class, 
   1.167 -            "nameOfIO__Ljava_lang_String_2", 
   1.168 -            "java.io.IOException"
   1.169 -        );
   1.170 -    }
   1.171 -    @Test public void noInterface() throws Exception {
   1.172 -        assertExec("Calls Class.isInterface", Classes.class, 
   1.173 -            "isInterface__ZLjava_lang_String_2", 
   1.174 -            0.0, "java.lang.String"
   1.175 -        );
   1.176 -    }
   1.177 -    @Test public void isInterface() throws Exception {
   1.178 -        assertExec("Calls Class.isInterface", Classes.class, 
   1.179 -            "isInterface__ZLjava_lang_String_2", 
   1.180 -            1.0, "java.lang.Runnable"
   1.181 -        );
   1.182 -    }
   1.183 -    @Test public void integerType() throws Exception {
   1.184 -        assertExec("Computes the type", Classes.class, 
   1.185 -            "intType__Ljava_lang_String_2", 
   1.186 -            Classes.intType()
   1.187 -        );
   1.188 -    }
   1.189 -    
   1.190 -    private static TestVM code;
   1.191 -    
   1.192 -    @BeforeClass
   1.193 -    public void compileTheCode() throws Exception {
   1.194 -        code = TestVM.compileClass("org/apidesign/vm4brwsr/Classes");
   1.195 -    }
   1.196 -    
   1.197 -    private void assertExec(
   1.198 -        String msg, Class clazz, String method, Object expRes, Object... args
   1.199 -    ) throws Exception {
   1.200 -        code.assertExec(msg, clazz, method, expRes, args);
   1.201 -    }
   1.202 -    @Test public void isClassAssignable() throws Exception {
   1.203 -        assertExec("isAssignable works on subclasses", Classes.class, 
   1.204 -            "isClassAssignable__Z", 
   1.205 -            true
   1.206 -        );
   1.207 -    }
   1.208 -    
   1.209 -}