No need to generate primitive final fields as their values get inlined in the classfiles anyway
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 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.
19 * To change this license header, choose License Headers in Project Properties.
20 * To change this template file, choose Tools | Templates
21 * and open the template in the editor.
24 package org.apidesign.vm4brwsr;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import static org.testng.Assert.assertEquals;
29 import static org.testng.Assert.assertTrue;
30 import org.testng.annotations.AfterClass;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
36 * @author Jaroslav Tulach <jtulach@netbeans.org>
38 public class SizeOfAMethodTest {
39 private static String code;
41 @Test public void sumXYShouldBeSmall() {
43 int beg = s.indexOf("c.sum__III");
44 int end = s.indexOf("c.sum__III.access");
46 assertTrue(beg > 0, "Found sum method in " + code);
47 assertTrue(beg < end, "Found end of sum method in " + code);
49 String method = s.substring(beg, end);
52 assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
55 @Test public void emptyConstructorRequiresNoStack() {
57 int beg = s.indexOf("CLS.cons__V");
58 int end = s.indexOf("CLS.cons__V.access");
60 assertTrue(beg > 0, "Found constructor in " + code);
61 assertTrue(beg < end, "Found end of constructor in " + code);
63 String method = s.substring(beg, end);
64 method = method.replace("constructor", "CNSTR");
66 assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
67 assertEquals(method.indexOf("for"), -1, "There should be no for blocks:\n" + method);
70 @Test public void dontGeneratePrimitiveFinalConstants() {
71 assertEquals(code.indexOf("MISSING_CONSTANT"), -1, "MISSING_CONSTANT field should not be generated");
75 public static void compileTheCode() throws Exception {
76 final String res = "org/apidesign/vm4brwsr/StaticMethod";
77 StringBuilder sb = new StringBuilder();
78 class JustStaticMethod implements Bck2Brwsr.Resources {
80 public InputStream get(String resource) throws IOException {
81 final String cn = res + ".class";
82 if (resource.equals(cn)) {
83 return getClass().getClassLoader().getResourceAsStream(cn);
88 Bck2Brwsr.generate(sb, new JustStaticMethod(), res);
92 public static void releaseTheCode() {