rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java
branchReducedStack
changeset 1453 e046cfcb8f00
child 1457 b9386cc3ff7b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java	Sat Feb 15 14:36:43 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +/*
    1.22 + * To change this license header, choose License Headers in Project Properties.
    1.23 + * To change this template file, choose Tools | Templates
    1.24 + * and open the template in the editor.
    1.25 + */
    1.26 +
    1.27 +package org.apidesign.vm4brwsr;
    1.28 +
    1.29 +import static org.testng.Assert.assertEquals;
    1.30 +import static org.testng.Assert.assertTrue;
    1.31 +import org.testng.annotations.AfterClass;
    1.32 +import org.testng.annotations.BeforeClass;
    1.33 +import org.testng.annotations.Test;
    1.34 +
    1.35 +/**
    1.36 + *
    1.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.38 + */
    1.39 +public class SizeOfAMethodTest {
    1.40 +    private static TestVM code;
    1.41 +
    1.42 +    @Test public void sumXYShouldBeSmall() {
    1.43 +        String s = code.codeSeq().toString();
    1.44 +        int beg = s.indexOf("c.sum__III");
    1.45 +        int end = s.indexOf("c.sum__III.access");
    1.46 +        
    1.47 +        assertTrue(beg > 0, "Found sum method in " + code.toString());
    1.48 +        assertTrue(beg < end, "Found end of sum method in " + code.toString());
    1.49 +        
    1.50 +        String method = s.substring(beg, end);
    1.51 +        
    1.52 +        assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
    1.53 +    }
    1.54 +    
    1.55 +    
    1.56 +    @BeforeClass 
    1.57 +    public static void compileTheCode() throws Exception {
    1.58 +        StringBuilder sb = new StringBuilder();
    1.59 +        code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
    1.60 +    }
    1.61 +    @AfterClass
    1.62 +    public static void releaseTheCode() {
    1.63 +        code = null;
    1.64 +    }
    1.65 +    
    1.66 +}