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