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 org.testng.annotations.BeforeClass; jaroslav@789: import org.testng.annotations.AfterClass; jaroslav@704: import org.testng.annotations.Test; jaroslav@704: jaroslav@704: /** jaroslav@704: * jaroslav@704: * @author Jaroslav Tulach jaroslav@704: */ jaroslav@1373: public class ReloadingTest { jaroslav@747: private static TestVM code; jaroslav@747: jaroslav@1367: @Test public void verifyUsageOf() throws Exception { jaroslav@1373: code.execCode("First hello", jaroslav@1373: Hello.class, "hello__Ljava_lang_String_2", jaroslav@1373: "Hello World!" jaroslav@1373: ); jaroslav@1373: jaroslav@1373: byte[] arr = BytesLoader.readClass("org/apidesign/vm4brwsr/Hello.class"); jaroslav@1373: for (int i = 0; i < arr.length; i++) { jaroslav@1373: if (arr[i] == 'H' && arr[i + 1] == 'e' && arr[i + 2] == 'l') { jaroslav@1373: arr[i] = 'A'; jaroslav@1373: arr[i + 1] = 'h'; jaroslav@1373: arr[i + 2] = 'o'; jaroslav@1373: arr[i + 3] = 'y'; jaroslav@1373: arr[i + 4] = ' '; jaroslav@1373: break; jaroslav@1373: } jaroslav@1373: } jaroslav@704: jaroslav@1373: code.execCode("Redefine class", jaroslav@1373: Hello.class, "reloadYourSelf__Ljava_lang_Object_2_3B", jaroslav@1373: null, arr jaroslav@1373: ); jaroslav@1373: jaroslav@1373: code.execCode("Second hello", jaroslav@1373: Hello.class, "hello__Ljava_lang_String_2", jaroslav@1373: "Ahoy World!" jaroslav@704: ); jaroslav@704: } jaroslav@704: jaroslav@704: jaroslav@704: @BeforeClass jaroslav@747: public static void compileTheCode() throws Exception { jaroslav@747: code = TestVM.compileClass( jaroslav@1373: "org/apidesign/vm4brwsr/Hello"); jaroslav@704: } jaroslav@789: @AfterClass jaroslav@789: public static void releaseTheCode() { jaroslav@789: code = null; jaroslav@789: } jaroslav@704: jaroslav@704: } jaroslav@704: