rt/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 28 Feb 2013 07:48:54 +0100
changeset 789 bb7506513353
parent 772 d382dacfd73f
child 1787 ea12a3bb4b33
permissions -rw-r--r--
releasing the compiled code as soon as it is no longer needed to prevent OutOfMemoryError when adding more and more tests
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@789
    22
import org.testng.annotations.AfterClass;
jaroslav@704
    23
import org.testng.annotations.Test;
jaroslav@704
    24
jaroslav@704
    25
/**
jaroslav@704
    26
 *
jaroslav@704
    27
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@704
    28
 */
jaroslav@704
    29
public class SystemTest {
jaroslav@747
    30
    private static TestVM code;
jaroslav@747
    31
    
jaroslav@704
    32
    @Test public void verifyJSTime() throws Exception {
jaroslav@704
    33
        long now = System.currentTimeMillis();
jaroslav@704
    34
        
jaroslav@747
    35
        Object js = code.execCode("Get js time", 
lubomir@755
    36
            org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillisDouble__D",
jaroslav@704
    37
            null
jaroslav@704
    38
        );
jaroslav@704
    39
        
jaroslav@704
    40
        assertTrue(js instanceof Double, "Double " + js);
jaroslav@704
    41
        long time = ((Double)js).longValue();
jaroslav@704
    42
        
jaroslav@704
    43
        long later = System.currentTimeMillis();
jaroslav@704
    44
        
jaroslav@704
    45
        assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
jaroslav@704
    46
        assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
jaroslav@704
    47
    }
jaroslav@704
    48
    
jaroslav@704
    49
    
jaroslav@704
    50
    @BeforeClass 
jaroslav@747
    51
    public static void compileTheCode() throws Exception {
jaroslav@747
    52
        code = TestVM.compileClass(
jaroslav@747
    53
            "org/apidesign/bck2brwsr/emul/lang/System");
jaroslav@704
    54
    }
jaroslav@789
    55
    @AfterClass
jaroslav@789
    56
    public static void releaseTheCode() {
jaroslav@789
    57
        code = null;
jaroslav@789
    58
    }
jaroslav@704
    59
    
jaroslav@704
    60
}
jaroslav@704
    61