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@789
|
21 |
import org.testng.annotations.AfterClass;
|
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@1373
|
28 |
public class ReloadingTest {
|
jaroslav@747
|
29 |
private static TestVM code;
|
jaroslav@747
|
30 |
|
jaroslav@1367
|
31 |
@Test public void verifyUsageOf() throws Exception {
|
jaroslav@1373
|
32 |
code.execCode("First hello",
|
jaroslav@1373
|
33 |
Hello.class, "hello__Ljava_lang_String_2",
|
jaroslav@1373
|
34 |
"Hello World!"
|
jaroslav@1373
|
35 |
);
|
jaroslav@1373
|
36 |
|
jaroslav@1373
|
37 |
byte[] arr = BytesLoader.readClass("org/apidesign/vm4brwsr/Hello.class");
|
jaroslav@1373
|
38 |
for (int i = 0; i < arr.length; i++) {
|
jaroslav@1373
|
39 |
if (arr[i] == 'H' && arr[i + 1] == 'e' && arr[i + 2] == 'l') {
|
jaroslav@1373
|
40 |
arr[i] = 'A';
|
jaroslav@1373
|
41 |
arr[i + 1] = 'h';
|
jaroslav@1373
|
42 |
arr[i + 2] = 'o';
|
jaroslav@1373
|
43 |
arr[i + 3] = 'y';
|
jaroslav@1373
|
44 |
arr[i + 4] = ' ';
|
jaroslav@1373
|
45 |
break;
|
jaroslav@1373
|
46 |
}
|
jaroslav@1373
|
47 |
}
|
jaroslav@704
|
48 |
|
jaroslav@1373
|
49 |
code.execCode("Redefine class",
|
jaroslav@1373
|
50 |
Hello.class, "reloadYourSelf__Ljava_lang_Object_2_3B",
|
jaroslav@1373
|
51 |
null, arr
|
jaroslav@1373
|
52 |
);
|
jaroslav@1373
|
53 |
|
jaroslav@1373
|
54 |
code.execCode("Second hello",
|
jaroslav@1373
|
55 |
Hello.class, "hello__Ljava_lang_String_2",
|
jaroslav@1373
|
56 |
"Ahoy World!"
|
jaroslav@704
|
57 |
);
|
jaroslav@704
|
58 |
}
|
jaroslav@704
|
59 |
|
jaroslav@704
|
60 |
|
jaroslav@704
|
61 |
@BeforeClass
|
jaroslav@747
|
62 |
public static void compileTheCode() throws Exception {
|
jaroslav@747
|
63 |
code = TestVM.compileClass(
|
jaroslav@1373
|
64 |
"org/apidesign/vm4brwsr/Hello");
|
jaroslav@704
|
65 |
}
|
jaroslav@789
|
66 |
@AfterClass
|
jaroslav@789
|
67 |
public static void releaseTheCode() {
|
jaroslav@789
|
68 |
code = null;
|
jaroslav@789
|
69 |
}
|
jaroslav@704
|
70 |
|
jaroslav@704
|
71 |
}
|
jaroslav@704
|
72 |
|