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
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 
    19 package org.apidesign.vm4brwsr;
    20 
    21 import java.io.IOException;
    22 import java.io.InputStream;
    23 import static org.testng.Assert.assertEquals;
    24 import org.testng.annotations.AfterClass;
    25 import org.testng.annotations.BeforeClass;
    26 import org.testng.annotations.Test;
    27 
    28 /**
    29  *
    30  * @author Jaroslav Tulach <jtulach@netbeans.org>
    31  */
    32 public class NoStringCnstntsTest {
    33     private static String code;
    34 
    35     
    36     @Test public void dontGeneratePrimitiveFinalConstants() {
    37         assertEquals(code.indexOf("HELLO"), -1, "MISSING_CONSTANT field should not be generated");
    38     }
    39     
    40     @BeforeClass 
    41     public static void compileTheCode() throws Exception {
    42         final String res = "org/apidesign/vm4brwsr/StringSample";
    43         StringBuilder sb = new StringBuilder();
    44         class JustStaticMethod implements Bck2Brwsr.Resources {
    45             @Override
    46             public InputStream get(String resource) throws IOException {
    47                 final String cn = res + ".class";
    48                 if (resource.equals(cn)) {
    49                     return getClass().getClassLoader().getResourceAsStream(cn);
    50                 }
    51                 return null;
    52             }
    53         }
    54         Bck2Brwsr.generate(sb, new JustStaticMethod(), res);
    55         code = sb.toString();
    56     }
    57     @AfterClass
    58     public static void releaseTheCode() {
    59         code = null;
    60     }
    61     
    62 }