jaroslav@1812: /** jaroslav@1812: * Back 2 Browser Bytecode Translator jaroslav@1812: * Copyright (C) 2012-2015 Jaroslav Tulach jaroslav@1812: * jaroslav@1812: * This program is free software: you can redistribute it and/or modify jaroslav@1812: * it under the terms of the GNU General Public License as published by jaroslav@1812: * the Free Software Foundation, version 2 of the License. jaroslav@1812: * jaroslav@1812: * This program is distributed in the hope that it will be useful, jaroslav@1812: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1812: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1812: * GNU General Public License for more details. jaroslav@1812: * jaroslav@1812: * You should have received a copy of the GNU General Public License jaroslav@1812: * along with this program. Look for COPYING file in the top folder. jaroslav@1812: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1812: */ jaroslav@1812: package org.apidesign.bck2brwsr.flow; jaroslav@1812: jaroslav@1812: import org.apidesign.vm4brwsr.Bck2Brwsr.Flow; jaroslav@1812: import static org.testng.Assert.*; jaroslav@1812: import org.testng.annotations.AfterClass; jaroslav@1812: import org.testng.annotations.AfterMethod; jaroslav@1812: import org.testng.annotations.BeforeClass; jaroslav@1812: import org.testng.annotations.BeforeMethod; jaroslav@1812: import org.testng.annotations.Test; jaroslav@1812: jaroslav@1812: /** jaroslav@1812: * jaroslav@1812: * @author Jaroslav Tulach jaroslav@1812: */ jaroslav@1812: public class LoopControlTest { jaroslav@1812: private static TestVM vm; jaroslav@1812: jaroslav@1812: public LoopControlTest() { jaroslav@1812: } jaroslav@1812: jaroslav@1812: @BeforeClass jaroslav@1812: public static void setUpClass() throws Exception { jaroslav@1812: class MyFlow implements Flow.Analyzer { jaroslav@1812: boolean called; jaroslav@1812: @Override jaroslav@1812: public boolean analyze(Flow request) { jaroslav@1812: called = true; jaroslav@1812: return GraalFlowAnalyzer.getDefault().analyze(request); jaroslav@1812: } jaroslav@1812: } jaroslav@1812: MyFlow flow = new MyFlow(); jaroslav@1812: vm = TestVM.compileClass(null, flow, LoopControl.class.getName().replace('.', '/')); jaroslav@1812: assertTrue(flow.called, "We have been consuted about at least one method"); jaroslav@1812: } jaroslav@1812: jaroslav@1812: @AfterClass jaroslav@1812: public static void tearDownClass() throws Exception { jaroslav@1812: vm = null; jaroslav@1812: } jaroslav@1812: jaroslav@1812: @BeforeMethod jaroslav@1812: public void setUpMethod() throws Exception { jaroslav@1812: } jaroslav@1812: jaroslav@1812: @AfterMethod jaroslav@1812: public void tearDownMethod() throws Exception { jaroslav@1812: } jaroslav@1812: jaroslav@1812: @Test jaroslav@1812: public void testExecute() throws Exception { jaroslav@1812: String code = vm.codeSeq().toString(); jaroslav@1812: int begin = code.indexOf("simpleLoopTestWithExit__II = function"); jaroslav@1812: assertNotEquals(begin, -1, "Control loop defined" + code); jaroslav@1812: int end = code.indexOf("m.access = ", begin); jaroslav@1812: assertNotEquals(end, -1, "Control loop end defined" + code); jaroslav@1812: final String body = code.substring(begin, end); jaroslav@1812: assertFalse(body.contains("gt"), "No gt control flow used: " + body); jaroslav@1812: } jaroslav@1812: jaroslav@1812: }