Defining API for registration of a Flow.Analyzer and getting ready for use the one from Graal
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.flow;
20 import org.apidesign.vm4brwsr.Bck2Brwsr.Flow;
21 import static org.testng.Assert.*;
22 import org.testng.annotations.AfterClass;
23 import org.testng.annotations.AfterMethod;
24 import org.testng.annotations.BeforeClass;
25 import org.testng.annotations.BeforeMethod;
26 import org.testng.annotations.Test;
30 * @author Jaroslav Tulach
32 public class LoopControlTest {
33 private static TestVM vm;
35 public LoopControlTest() {
39 public static void setUpClass() throws Exception {
40 class MyFlow implements Flow.Analyzer {
43 public boolean analyze(Flow request) {
45 return GraalFlowAnalyzer.getDefault().analyze(request);
48 MyFlow flow = new MyFlow();
49 vm = TestVM.compileClass(null, flow, LoopControl.class.getName().replace('.', '/'));
50 assertTrue(flow.called, "We have been consuted about at least one method");
54 public static void tearDownClass() throws Exception {
59 public void setUpMethod() throws Exception {
63 public void tearDownMethod() throws Exception {
67 public void testExecute() throws Exception {
68 String code = vm.codeSeq().toString();
69 int begin = code.indexOf("simpleLoopTestWithExit__II = function");
70 assertNotEquals(begin, -1, "Control loop defined" + code);
71 int end = code.indexOf("m.access = ", begin);
72 assertNotEquals(end, -1, "Control loop end defined" + code);
73 final String body = code.substring(begin, end);
74 assertFalse(body.contains("gt"), "No gt control flow used: " + body);