vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 15 Feb 2013 21:14:49 +0100
branchemul
changeset 747 ae352b763959
parent 704 4fe8b3dfc55f
child 755 5652acd48509
permissions -rw-r--r--
Merge from default branch to resolve conflicts
jaroslav@704
     1
/**
jaroslav@704
     2
 * Back 2 Browser Bytecode Translator
jaroslav@704
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@704
     4
 *
jaroslav@704
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@704
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@704
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@704
     8
 *
jaroslav@704
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@704
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@704
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@704
    12
 * GNU General Public License for more details.
jaroslav@704
    13
 *
jaroslav@704
    14
 * You should have received a copy of the GNU General Public License
jaroslav@704
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@704
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@704
    17
 */
jaroslav@704
    18
package org.apidesign.vm4brwsr;
jaroslav@704
    19
jaroslav@704
    20
import org.testng.annotations.BeforeClass;
jaroslav@704
    21
import static org.testng.Assert.*;
jaroslav@704
    22
import org.testng.annotations.Test;
jaroslav@704
    23
jaroslav@704
    24
/**
jaroslav@704
    25
 *
jaroslav@704
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@704
    27
 */
jaroslav@704
    28
public class SystemTest {
jaroslav@747
    29
    private static TestVM code;
jaroslav@747
    30
    
jaroslav@704
    31
    @Test public void verifyJSTime() throws Exception {
jaroslav@704
    32
        long now = System.currentTimeMillis();
jaroslav@704
    33
        
jaroslav@747
    34
        Object js = code.execCode("Get js time", 
jaroslav@704
    35
            org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J",
jaroslav@704
    36
            null
jaroslav@704
    37
        );
jaroslav@704
    38
        
jaroslav@704
    39
        assertTrue(js instanceof Double, "Double " + js);
jaroslav@704
    40
        long time = ((Double)js).longValue();
jaroslav@704
    41
        
jaroslav@704
    42
        long later = System.currentTimeMillis();
jaroslav@704
    43
        
jaroslav@704
    44
        assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
jaroslav@704
    45
        assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
jaroslav@704
    46
    }
jaroslav@704
    47
    
jaroslav@704
    48
    
jaroslav@704
    49
    @BeforeClass 
jaroslav@747
    50
    public static void compileTheCode() throws Exception {
jaroslav@747
    51
        code = TestVM.compileClass(
jaroslav@747
    52
            "org/apidesign/bck2brwsr/emul/lang/System");
jaroslav@704
    53
    }
jaroslav@704
    54
    
jaroslav@704
    55
}
jaroslav@704
    56