jaroslav@704: /** jaroslav@704: * Back 2 Browser Bytecode Translator jaroslav@704: * Copyright (C) 2012 Jaroslav Tulach jaroslav@704: * jaroslav@704: * This program is free software: you can redistribute it and/or modify jaroslav@704: * it under the terms of the GNU General Public License as published by jaroslav@704: * the Free Software Foundation, version 2 of the License. jaroslav@704: * jaroslav@704: * This program is distributed in the hope that it will be useful, jaroslav@704: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@704: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@704: * GNU General Public License for more details. jaroslav@704: * jaroslav@704: * You should have received a copy of the GNU General Public License jaroslav@704: * along with this program. Look for COPYING file in the top folder. jaroslav@704: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@704: */ jaroslav@704: package org.apidesign.vm4brwsr; jaroslav@704: jaroslav@704: import javax.script.Invocable; jaroslav@704: import org.testng.annotations.BeforeClass; jaroslav@704: import static org.testng.Assert.*; jaroslav@704: import org.testng.annotations.BeforeMethod; jaroslav@704: import org.testng.annotations.Test; jaroslav@704: jaroslav@704: /** jaroslav@704: * jaroslav@704: * @author Jaroslav Tulach jaroslav@704: */ jaroslav@704: public class SystemTest { jaroslav@704: @Test public void verifyJSTime() throws Exception { jaroslav@704: long now = System.currentTimeMillis(); jaroslav@704: jaroslav@704: Object js = TestUtils.execCode(code, codeSeq, "Get js time", jaroslav@704: org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J", jaroslav@704: null jaroslav@704: ); jaroslav@704: jaroslav@704: assertTrue(js instanceof Double, "Double " + js); jaroslav@704: long time = ((Double)js).longValue(); jaroslav@704: jaroslav@704: long later = System.currentTimeMillis(); jaroslav@704: jaroslav@704: assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time); jaroslav@704: assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later); jaroslav@704: } jaroslav@704: jaroslav@704: private static CharSequence codeSeq; jaroslav@704: private static Invocable code; jaroslav@704: jaroslav@704: @BeforeClass jaroslav@704: public void compileTheCode() throws Exception { jaroslav@704: StringBuilder sb = new StringBuilder(); jaroslav@704: code = StaticMethodTest.compileClass(sb, "org/apidesign/bck2brwsr/emul/lang/System"); jaroslav@704: codeSeq = sb; jaroslav@704: } jaroslav@704: jaroslav@704: } jaroslav@704: