2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.vm4brwsr;
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;
25 /** Verify cooperation with net.java.html.js annotations.
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class HtmlAnnotationsTest {
30 @Test public void fourtyTwo() throws Exception {
31 assertExec("Annotation used", HtmlAnnotations.class,
37 @Test public void externalMul() throws Exception {
38 assertExec("mul function is loaded", HtmlAnnotations.class,
39 "useExternalMul__III",
45 @Test public void callRunnableFromJS() throws Exception {
46 assertExec("runnable called", HtmlAnnotations.class,
52 @Test public void callStaticMethodFromJS() throws Exception {
53 assertExec("runnable called", HtmlAnnotations.class,
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
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
77 private static TestVM code;
80 public void compileTheCode() throws Exception {
81 code = TestVM.compileClass("org/apidesign/vm4brwsr/HtmlAnnotations");
84 public static void releaseTheCode() {
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);