jaroslav@106
|
1 |
/**
|
jaroslav@106
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@106
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@106
|
4 |
*
|
jaroslav@106
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@106
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@106
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@106
|
8 |
*
|
jaroslav@106
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@106
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@106
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@106
|
12 |
* GNU General Public License for more details.
|
jaroslav@106
|
13 |
*
|
jaroslav@106
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@106
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@106
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@106
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@0
|
19 |
|
jaroslav@1495
|
20 |
import java.io.UnsupportedEncodingException;
|
jaroslav@789
|
21 |
import org.testng.annotations.AfterClass;
|
jaroslav@103
|
22 |
import org.testng.annotations.BeforeClass;
|
jaroslav@0
|
23 |
import org.testng.annotations.Test;
|
jaroslav@0
|
24 |
|
jaroslav@1493
|
25 |
/** Tests related to loading resources from the VM.
|
jaroslav@0
|
26 |
*
|
jaroslav@0
|
27 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
28 |
*/
|
jaroslav@1493
|
29 |
public class ResourcesTest {
|
jaroslav@1494
|
30 |
@Test public void loadPrecompiledResource() throws Exception {
|
jaroslav@1493
|
31 |
String exp = Resources.loadKO();
|
jaroslav@1493
|
32 |
|
jaroslav@1493
|
33 |
assertExec("Loading a precompiled resource:",
|
jaroslav@1493
|
34 |
Resources.class, "loadKO__Ljava_lang_String_2",
|
jaroslav@1493
|
35 |
exp
|
jaroslav@291
|
36 |
);
|
jaroslav@291
|
37 |
}
|
jaroslav@1496
|
38 |
|
jaroslav@1496
|
39 |
@Test public void loadBinaryPrecompiledResource() throws Exception {
|
jaroslav@1496
|
40 |
String exp = Resources.loadClazz();
|
jaroslav@1496
|
41 |
|
jaroslav@1496
|
42 |
assertExec("Loading a precompiled resource:",
|
jaroslav@1496
|
43 |
Resources.class, "loadClazz__Ljava_lang_String_2",
|
jaroslav@1496
|
44 |
exp
|
jaroslav@1496
|
45 |
);
|
jaroslav@1496
|
46 |
}
|
jaroslav@291
|
47 |
|
jaroslav@708
|
48 |
private static TestVM code;
|
jaroslav@103
|
49 |
|
jaroslav@103
|
50 |
@BeforeClass
|
jaroslav@789
|
51 |
public static void compileTheCode() throws Exception {
|
jaroslav@103
|
52 |
StringBuilder sb = new StringBuilder();
|
jaroslav@1496
|
53 |
code = TestVM.compileClassAndResources(sb, null,
|
jaroslav@1496
|
54 |
"org/apidesign/vm4brwsr/Resources",
|
jaroslav@1496
|
55 |
"org/apidesign/vm4brwsr/ko.js",
|
jaroslav@1496
|
56 |
"org/apidesign/vm4brwsr/Bck2BrwsrToolkit.class"
|
jaroslav@1496
|
57 |
);
|
jaroslav@2
|
58 |
}
|
jaroslav@789
|
59 |
@AfterClass
|
jaroslav@789
|
60 |
public static void releaseTheCode() {
|
jaroslav@789
|
61 |
code = null;
|
jaroslav@789
|
62 |
}
|
jaroslav@2
|
63 |
|
jaroslav@708
|
64 |
private void assertExec(
|
jaroslav@708
|
65 |
String msg, Class<?> clazz, String method,
|
jaroslav@708
|
66 |
Object ret, Object... args
|
jaroslav@708
|
67 |
) throws Exception {
|
jaroslav@708
|
68 |
code.assertExec(msg, clazz, method, ret, args);
|
jaroslav@298
|
69 |
}
|
jaroslav@1495
|
70 |
|
jaroslav@1495
|
71 |
public static String parseBase64Binary(String s) throws UnsupportedEncodingException {
|
jaroslav@1496
|
72 |
final byte[] arr = javax.xml.bind.DatatypeConverter.parseBase64Binary(s);
|
jaroslav@1496
|
73 |
StringBuilder sb = new StringBuilder();
|
jaroslav@1496
|
74 |
for (int i = 0; i < arr.length; i++) {
|
jaroslav@1496
|
75 |
int ch = arr[i];
|
jaroslav@1496
|
76 |
sb.append((char)ch);
|
jaroslav@1496
|
77 |
}
|
jaroslav@1496
|
78 |
return sb.toString();
|
jaroslav@1495
|
79 |
}
|
jaroslav@0
|
80 |
}
|