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 javax.script.Invocable;
|
jaroslav@704
|
21 |
import org.testng.annotations.BeforeClass;
|
jaroslav@704
|
22 |
import static org.testng.Assert.*;
|
jaroslav@704
|
23 |
import org.testng.annotations.BeforeMethod;
|
jaroslav@704
|
24 |
import org.testng.annotations.Test;
|
jaroslav@704
|
25 |
|
jaroslav@704
|
26 |
/**
|
jaroslav@704
|
27 |
*
|
jaroslav@704
|
28 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@704
|
29 |
*/
|
jaroslav@704
|
30 |
public class SystemTest {
|
jaroslav@704
|
31 |
@Test public void verifyJSTime() throws Exception {
|
jaroslav@704
|
32 |
long now = System.currentTimeMillis();
|
jaroslav@704
|
33 |
|
jaroslav@704
|
34 |
Object js = TestUtils.execCode(code, codeSeq, "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 |
private static CharSequence codeSeq;
|
jaroslav@704
|
49 |
private static Invocable code;
|
jaroslav@704
|
50 |
|
jaroslav@704
|
51 |
@BeforeClass
|
jaroslav@704
|
52 |
public void compileTheCode() throws Exception {
|
jaroslav@704
|
53 |
StringBuilder sb = new StringBuilder();
|
jaroslav@704
|
54 |
code = StaticMethodTest.compileClass(sb, "org/apidesign/bck2brwsr/emul/lang/System");
|
jaroslav@704
|
55 |
codeSeq = sb;
|
jaroslav@704
|
56 |
}
|
jaroslav@704
|
57 |
|
jaroslav@704
|
58 |
}
|
jaroslav@704
|
59 |
|