rt/vm/src/test/java/org/apidesign/vm4brwsr/HtmlAnnotationsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 12 Jul 2013 16:06:38 +0200
changeset 1248 a3eb8b0dfb81
parent 1244 4b43ab1f72e8
permissions -rw-r--r--
Needs to mangle the parameters to convert / to _
jaroslav@1239
     1
/**
jaroslav@1239
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1239
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1239
     4
 *
jaroslav@1239
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1239
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1239
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1239
     8
 *
jaroslav@1239
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1239
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1239
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1239
    12
 * GNU General Public License for more details.
jaroslav@1239
    13
 *
jaroslav@1239
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1239
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1239
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1239
    17
 */
jaroslav@1239
    18
package org.apidesign.vm4brwsr;
jaroslav@1239
    19
jaroslav@1244
    20
import static org.testng.Assert.assertNotNull;
jaroslav@1239
    21
import org.testng.annotations.AfterClass;
jaroslav@1239
    22
import org.testng.annotations.BeforeClass;
jaroslav@1239
    23
import org.testng.annotations.Test;
jaroslav@1239
    24
jaroslav@1239
    25
/** Verify cooperation with net.java.html.js annotations.
jaroslav@1239
    26
 *
jaroslav@1239
    27
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1239
    28
 */
jaroslav@1239
    29
public class HtmlAnnotationsTest {
jaroslav@1239
    30
    @Test public void fourtyTwo() throws Exception {
jaroslav@1239
    31
        assertExec("Annotation used", HtmlAnnotations.class, 
jaroslav@1239
    32
            "fourtyTwo__I",
jaroslav@1239
    33
            Double.valueOf(42)
jaroslav@1239
    34
        );
jaroslav@1239
    35
    }
jaroslav@1239
    36
    
jaroslav@1239
    37
    @Test public void externalMul() throws Exception {
jaroslav@1239
    38
        assertExec("mul function is loaded", HtmlAnnotations.class, 
jaroslav@1239
    39
            "useExternalMul__III",
jaroslav@1239
    40
            Double.valueOf(42),
jaroslav@1239
    41
            7, 6
jaroslav@1239
    42
        );
jaroslav@1239
    43
    }
jaroslav@1242
    44
jaroslav@1240
    45
    @Test public void callRunnableFromJS() throws Exception {
jaroslav@1240
    46
        assertExec("runnable called", HtmlAnnotations.class, 
jaroslav@1240
    47
            "callback__I",
jaroslav@1240
    48
            Double.valueOf(1)
jaroslav@1240
    49
        );
jaroslav@1240
    50
    }
jaroslav@1243
    51
jaroslav@1243
    52
    @Test public void callStaticMethodFromJS() throws Exception {
jaroslav@1243
    53
        assertExec("runnable called", HtmlAnnotations.class, 
jaroslav@1243
    54
            "staticCallback__I",
jaroslav@1243
    55
            Double.valueOf(1)
jaroslav@1243
    56
        );
jaroslav@1243
    57
    }
jaroslav@1244
    58
jaroslav@1244
    59
    @Test public void callbackWithFourParamsAndReturnType() throws Exception {
jaroslav@1244
    60
        Object instance = code.execCode("Get an HtmlAnnotations instance", HtmlAnnotations.class, "create__Ljava_lang_Object_2", null);
jaroslav@1244
    61
        assertNotNull(instance, "Instance created");
jaroslav@1244
    62
        assertExec("runnable called", HtmlAnnotations.class, 
jaroslav@1244
    63
            "first__JLjava_lang_Object_2JJ",
jaroslav@1244
    64
            Double.valueOf(42), instance, 42, 31
jaroslav@1244
    65
        );
jaroslav@1244
    66
    }
jaroslav@1248
    67
jaroslav@1248
    68
    @Test public void callbackWithObjectParamsAndReturnType() throws Exception {
jaroslav@1248
    69
        Object instance = code.execCode("Get an HtmlAnnotations instance", HtmlAnnotations.class, "create__Ljava_lang_Object_2", null);
jaroslav@1248
    70
        assertNotNull(instance, "Instance created");
jaroslav@1248
    71
        assertExec("called back and forth", HtmlAnnotations.class, 
jaroslav@1248
    72
            "onError__Ljava_lang_Double_2Ljava_lang_Object_2Ljava_lang_Double_2",
jaroslav@1248
    73
            Double.valueOf(42), instance, 42
jaroslav@1248
    74
        );
jaroslav@1248
    75
    }
jaroslav@1239
    76
    
jaroslav@1239
    77
    private static TestVM code;
jaroslav@1239
    78
    
jaroslav@1239
    79
    @BeforeClass 
jaroslav@1239
    80
    public void compileTheCode() throws Exception {
jaroslav@1239
    81
        code = TestVM.compileClass("org/apidesign/vm4brwsr/HtmlAnnotations");
jaroslav@1239
    82
    }
jaroslav@1239
    83
    @AfterClass
jaroslav@1239
    84
    public static void releaseTheCode() {
jaroslav@1239
    85
        code = null;
jaroslav@1239
    86
    }
jaroslav@1239
    87
    private static void assertExec(String msg, Class clazz, String method, Object expRes, Object... args) throws Exception {
jaroslav@1239
    88
        code.assertExec(msg, clazz, method, expRes, args);
jaroslav@1239
    89
    }
jaroslav@1239
    90
    
jaroslav@1239
    91
}