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
jaroslav@1282
     1
/**
jaroslav@1282
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1282
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1282
     4
 *
jaroslav@1282
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1282
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1282
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1282
     8
 *
jaroslav@1282
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1282
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1282
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1282
    12
 * GNU General Public License for more details.
jaroslav@1282
    13
 *
jaroslav@1282
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1282
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1282
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1282
    17
 */
jaroslav@1282
    18
package org.apidesign.bck2brwsr.vmtest.impl;
jaroslav@1282
    19
jaroslav@1282
    20
import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
jaroslav@1282
    21
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@1282
    22
import org.testng.annotations.Factory;
jaroslav@1282
    23
jaroslav@1282
    24
/** Verify cooperation with net.java.html.js annotations.
jaroslav@1282
    25
 *
jaroslav@1282
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1282
    27
 */
jaroslav@1282
    28
public class HtmlAnnotationsTest {
jaroslav@1282
    29
    @BrwsrTest public void fourtyTwo() throws Exception {
jaroslav@1282
    30
        assertEquals(HtmlAnnotations.fourtyTwo(), 42);
jaroslav@1282
    31
    }
jaroslav@1282
    32
    
jaroslav@1282
    33
    @BrwsrTest public void externalMul() throws Exception {
jaroslav@1282
    34
        assertEquals(HtmlAnnotations.useExternalMul(7, 6), 42);
jaroslav@1282
    35
    }
jaroslav@1282
    36
jaroslav@1282
    37
    @BrwsrTest public void callRunnableFromJS() throws Exception {
jaroslav@1282
    38
        assertEquals(HtmlAnnotations.callback(), 1);
jaroslav@1282
    39
    }
jaroslav@1282
    40
jaroslav@1282
    41
    @BrwsrTest public void callStaticMethodFromJS() throws Exception {
jaroslav@1282
    42
        assertEquals(HtmlAnnotations.staticCallback(), 1);
jaroslav@1282
    43
    }
jaroslav@1282
    44
jaroslav@1282
    45
    @BrwsrTest public void callbackWithFourParamsAndReturnType() throws Exception {
jaroslav@1282
    46
        Object instance = HtmlAnnotations.create();
jaroslav@1282
    47
        assertNotNull(instance, "Instance created");
jaroslav@1282
    48
        assertEquals(HtmlAnnotations.first(instance, 42, 31), 42);
jaroslav@1282
    49
    }
jaroslav@1282
    50
jaroslav@1282
    51
    @BrwsrTest public void callbackWithObjectParamsAndReturnType() throws Exception {
jaroslav@1282
    52
        Object instance = HtmlAnnotations.create();
jaroslav@1282
    53
        assertNotNull(instance, "Instance created");
jaroslav@1282
    54
        assertEquals(HtmlAnnotations.onError(instance, 42.0), 42.0);
jaroslav@1282
    55
    }
jaroslav@1282
    56
    
jaroslav@1282
    57
    private static void assertEquals(double real, double exp) {
jaroslav@1282
    58
        if (real - exp < 0.01) {
jaroslav@1282
    59
            return;
jaroslav@1282
    60
        }
jaroslav@1282
    61
        assert false : "Expecting " + exp + " but was " + real;
jaroslav@1282
    62
    }
jaroslav@1282
    63
jaroslav@1282
    64
    private static void assertNotNull(Object obj, String msg) {
jaroslav@1282
    65
        assert obj != null : msg;
jaroslav@1282
    66
    }
jaroslav@1282
    67
    
jaroslav@1282
    68
    @Factory public static Object[] create() {
jaroslav@1282
    69
        return VMTest.create(HtmlAnnotationsTest.class);
jaroslav@1282
    70
    }
jaroslav@1282
    71
}