rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 12 Sep 2013 14:15:47 +0200
changeset 1282 8d29792a09c6
child 1722 fd3a354d6e8f
permissions -rw-r--r--
Updating to recent changes in html.java.net APIs
     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.bck2brwsr.vmtest.impl;
    19 
    20 import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
    21 import org.apidesign.bck2brwsr.vmtest.VMTest;
    22 import org.testng.annotations.Factory;
    23 
    24 /** Verify cooperation with net.java.html.js annotations.
    25  *
    26  * @author Jaroslav Tulach <jtulach@netbeans.org>
    27  */
    28 public class HtmlAnnotationsTest {
    29     @BrwsrTest public void fourtyTwo() throws Exception {
    30         assertEquals(HtmlAnnotations.fourtyTwo(), 42);
    31     }
    32     
    33     @BrwsrTest public void externalMul() throws Exception {
    34         assertEquals(HtmlAnnotations.useExternalMul(7, 6), 42);
    35     }
    36 
    37     @BrwsrTest public void callRunnableFromJS() throws Exception {
    38         assertEquals(HtmlAnnotations.callback(), 1);
    39     }
    40 
    41     @BrwsrTest public void callStaticMethodFromJS() throws Exception {
    42         assertEquals(HtmlAnnotations.staticCallback(), 1);
    43     }
    44 
    45     @BrwsrTest public void callbackWithFourParamsAndReturnType() throws Exception {
    46         Object instance = HtmlAnnotations.create();
    47         assertNotNull(instance, "Instance created");
    48         assertEquals(HtmlAnnotations.first(instance, 42, 31), 42);
    49     }
    50 
    51     @BrwsrTest public void callbackWithObjectParamsAndReturnType() throws Exception {
    52         Object instance = HtmlAnnotations.create();
    53         assertNotNull(instance, "Instance created");
    54         assertEquals(HtmlAnnotations.onError(instance, 42.0), 42.0);
    55     }
    56     
    57     private static void assertEquals(double real, double exp) {
    58         if (real - exp < 0.01) {
    59             return;
    60         }
    61         assert false : "Expecting " + exp + " but was " + real;
    62     }
    63 
    64     private static void assertNotNull(Object obj, String msg) {
    65         assert obj != null : msg;
    66     }
    67     
    68     @Factory public static Object[] create() {
    69         return VMTest.create(HtmlAnnotationsTest.class);
    70     }
    71 }