rt/vm/src/test/java/org/apidesign/vm4brwsr/NoStringCnstntsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 18 Feb 2014 10:02:46 +0100
branchReducedStack
changeset 1474 3775fe162073
parent 1472 rt/vm/src/test/java/org/apidesign/vm4brwsr/SizeOfAMethodTest.java@0a1b4f1bf4d0
child 1787 ea12a3bb4b33
permissions -rw-r--r--
Don't generate String constants either
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
package org.apidesign.vm4brwsr;
jaroslav@1453
    20
jaroslav@1457
    21
import java.io.IOException;
jaroslav@1457
    22
import java.io.InputStream;
jaroslav@1453
    23
import static org.testng.Assert.assertEquals;
jaroslav@1453
    24
import org.testng.annotations.AfterClass;
jaroslav@1453
    25
import org.testng.annotations.BeforeClass;
jaroslav@1453
    26
import org.testng.annotations.Test;
jaroslav@1453
    27
jaroslav@1453
    28
/**
jaroslav@1453
    29
 *
jaroslav@1453
    30
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1453
    31
 */
jaroslav@1474
    32
public class NoStringCnstntsTest {
jaroslav@1457
    33
    private static String code;
jaroslav@1453
    34
jaroslav@1453
    35
    
jaroslav@1472
    36
    @Test public void dontGeneratePrimitiveFinalConstants() {
jaroslav@1474
    37
        assertEquals(code.indexOf("HELLO"), -1, "MISSING_CONSTANT field should not be generated");
jaroslav@1472
    38
    }
jaroslav@1453
    39
    
jaroslav@1453
    40
    @BeforeClass 
jaroslav@1453
    41
    public static void compileTheCode() throws Exception {
jaroslav@1474
    42
        final String res = "org/apidesign/vm4brwsr/StringSample";
jaroslav@1453
    43
        StringBuilder sb = new StringBuilder();
jaroslav@1457
    44
        class JustStaticMethod implements Bck2Brwsr.Resources {
jaroslav@1457
    45
            @Override
jaroslav@1457
    46
            public InputStream get(String resource) throws IOException {
jaroslav@1457
    47
                final String cn = res + ".class";
jaroslav@1457
    48
                if (resource.equals(cn)) {
jaroslav@1457
    49
                    return getClass().getClassLoader().getResourceAsStream(cn);
jaroslav@1457
    50
                }
jaroslav@1457
    51
                return null;
jaroslav@1457
    52
            }
jaroslav@1457
    53
        }
jaroslav@1457
    54
        Bck2Brwsr.generate(sb, new JustStaticMethod(), res);
jaroslav@1457
    55
        code = sb.toString();
jaroslav@1453
    56
    }
jaroslav@1453
    57
    @AfterClass
jaroslav@1453
    58
    public static void releaseTheCode() {
jaroslav@1453
    59
        code = null;
jaroslav@1453
    60
    }
jaroslav@1453
    61
    
jaroslav@1453
    62
}