1.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Sat Feb 15 14:36:43 2014 +0100
1.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java Sat Feb 15 20:18:26 2014 +0100
1.3 @@ -23,6 +23,8 @@
1.4
1.5 package org.apidesign.vm4brwsr;
1.6
1.7 +import java.io.IOException;
1.8 +import java.io.InputStream;
1.9 import static org.testng.Assert.assertEquals;
1.10 import static org.testng.Assert.assertTrue;
1.11 import org.testng.annotations.AfterClass;
1.12 @@ -34,26 +36,53 @@
1.13 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.14 */
1.15 public class SizeOfAMethodTest {
1.16 - private static TestVM code;
1.17 + private static String code;
1.18
1.19 @Test public void sumXYShouldBeSmall() {
1.20 - String s = code.codeSeq().toString();
1.21 + String s = code;
1.22 int beg = s.indexOf("c.sum__III");
1.23 int end = s.indexOf("c.sum__III.access");
1.24
1.25 - assertTrue(beg > 0, "Found sum method in " + code.toString());
1.26 - assertTrue(beg < end, "Found end of sum method in " + code.toString());
1.27 + assertTrue(beg > 0, "Found sum method in " + code);
1.28 + assertTrue(beg < end, "Found end of sum method in " + code);
1.29
1.30 String method = s.substring(beg, end);
1.31
1.32 +
1.33 + assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
1.34 + }
1.35 +
1.36 + @Test public void emptyConstructorRequiresNoStack() {
1.37 + String s = code;
1.38 + int beg = s.indexOf("CLS.cons__V");
1.39 + int end = s.indexOf("CLS.cons__V.access");
1.40 +
1.41 + assertTrue(beg > 0, "Found constructor in " + code);
1.42 + assertTrue(beg < end, "Found end of constructor in " + code);
1.43 +
1.44 + String method = s.substring(beg, end);
1.45 + method = method.replace("constructor", "CNSTR");
1.46 +
1.47 assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
1.48 }
1.49
1.50
1.51 @BeforeClass
1.52 public static void compileTheCode() throws Exception {
1.53 + final String res = "org/apidesign/vm4brwsr/StaticMethod";
1.54 StringBuilder sb = new StringBuilder();
1.55 - code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
1.56 + class JustStaticMethod implements Bck2Brwsr.Resources {
1.57 + @Override
1.58 + public InputStream get(String resource) throws IOException {
1.59 + final String cn = res + ".class";
1.60 + if (resource.equals(cn)) {
1.61 + return getClass().getClassLoader().getResourceAsStream(cn);
1.62 + }
1.63 + return null;
1.64 + }
1.65 + }
1.66 + Bck2Brwsr.generate(sb, new JustStaticMethod(), res);
1.67 + code = sb.toString();
1.68 }
1.69 @AfterClass
1.70 public static void releaseTheCode() {