rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 15 Feb 2014 14:36:43 +0100
branchReducedStack
changeset 1453 e046cfcb8f00
child 1457 b9386cc3ff7b
permissions -rw-r--r--
Centralizing the stack pushes into single assign method
jaroslav@1453
     1
/**
jaroslav@1453
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1453
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1453
     4
 *
jaroslav@1453
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1453
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1453
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1453
     8
 *
jaroslav@1453
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1453
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1453
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1453
    12
 * GNU General Public License for more details.
jaroslav@1453
    13
 *
jaroslav@1453
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1453
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1453
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1453
    17
 */
jaroslav@1453
    18
/*
jaroslav@1453
    19
 * To change this license header, choose License Headers in Project Properties.
jaroslav@1453
    20
 * To change this template file, choose Tools | Templates
jaroslav@1453
    21
 * and open the template in the editor.
jaroslav@1453
    22
 */
jaroslav@1453
    23
jaroslav@1453
    24
package org.apidesign.vm4brwsr;
jaroslav@1453
    25
jaroslav@1453
    26
import static org.testng.Assert.assertEquals;
jaroslav@1453
    27
import static org.testng.Assert.assertTrue;
jaroslav@1453
    28
import org.testng.annotations.AfterClass;
jaroslav@1453
    29
import org.testng.annotations.BeforeClass;
jaroslav@1453
    30
import org.testng.annotations.Test;
jaroslav@1453
    31
jaroslav@1453
    32
/**
jaroslav@1453
    33
 *
jaroslav@1453
    34
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1453
    35
 */
jaroslav@1453
    36
public class SizeOfAMethodTest {
jaroslav@1453
    37
    private static TestVM code;
jaroslav@1453
    38
jaroslav@1453
    39
    @Test public void sumXYShouldBeSmall() {
jaroslav@1453
    40
        String s = code.codeSeq().toString();
jaroslav@1453
    41
        int beg = s.indexOf("c.sum__III");
jaroslav@1453
    42
        int end = s.indexOf("c.sum__III.access");
jaroslav@1453
    43
        
jaroslav@1453
    44
        assertTrue(beg > 0, "Found sum method in " + code.toString());
jaroslav@1453
    45
        assertTrue(beg < end, "Found end of sum method in " + code.toString());
jaroslav@1453
    46
        
jaroslav@1453
    47
        String method = s.substring(beg, end);
jaroslav@1453
    48
        
jaroslav@1453
    49
        assertEquals(method.indexOf("st"), -1, "There should be no stack operations:\n" + method);
jaroslav@1453
    50
    }
jaroslav@1453
    51
    
jaroslav@1453
    52
    
jaroslav@1453
    53
    @BeforeClass 
jaroslav@1453
    54
    public static void compileTheCode() throws Exception {
jaroslav@1453
    55
        StringBuilder sb = new StringBuilder();
jaroslav@1453
    56
        code = TestVM.compileClass(sb, "org/apidesign/vm4brwsr/StaticMethod");
jaroslav@1453
    57
    }
jaroslav@1453
    58
    @AfterClass
jaroslav@1453
    59
    public static void releaseTheCode() {
jaroslav@1453
    60
        code = null;
jaroslav@1453
    61
    }
jaroslav@1453
    62
    
jaroslav@1453
    63
}