Making sure resources can be loaded in brwsr testing mode with extensions closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 29 Apr 2014 10:23:55 +0200
branchclosure
changeset 14989583bcc50db3
parent 1497 daa5f903b529
child 1499 f8850d0650d6
Making sure resources can be loaded in brwsr testing mode with extensions
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java
rt/emul/brwsrtest/src/test/java/org/apidesign/bck2brwsr/brwsrtest/ResourcesInBrwsrTest.java
rt/emul/brwsrtest/src/test/resources/org/apidesign/bck2brwsr/brwsrtest/Resources.txt
     1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Mon Apr 28 20:23:44 2014 +0200
     1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Tue Apr 29 10:23:55 2014 +0200
     1.3 @@ -54,6 +54,7 @@
     1.4              
     1.5              Bck2Brwsr.newCompiler()
     1.6                  .addClasses(classes.toArray(new String[0]))
     1.7 +                .addResources(arr.toArray(new String[0]))
     1.8                  .library(true)
     1.9                  .resources(new JarRes())
    1.10                  .generate(w);
    1.11 @@ -80,6 +81,7 @@
    1.12              try {
    1.13                  Bck2Brwsr.newCompiler()
    1.14                      .addRootClasses(classes.toArray(new String[0]))
    1.15 +                    .addResources(arr.toArray(new String[0]))
    1.16                      .library(true)
    1.17                      .resources(new EmulationResources())
    1.18                      .generate(w);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/rt/emul/brwsrtest/src/test/java/org/apidesign/bck2brwsr/brwsrtest/ResourcesInBrwsrTest.java	Tue Apr 29 10:23:55 2014 +0200
     2.3 @@ -0,0 +1,46 @@
     2.4 +/**
     2.5 + * Back 2 Browser Bytecode Translator
     2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, version 2 of the License.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program. Look for COPYING file in the top folder.
    2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 + */
    2.21 +package org.apidesign.bck2brwsr.brwsrtest;
    2.22 +
    2.23 +import java.io.InputStream;
    2.24 +import org.apidesign.bck2brwsr.vmtest.Compare;
    2.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
    2.26 +import org.testng.annotations.Factory;
    2.27 +
    2.28 +/**
    2.29 + *
    2.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.31 + */
    2.32 +public class ResourcesInBrwsrTest {
    2.33 +    
    2.34 +    @Compare public String readResourceAsStream() throws Exception {
    2.35 +        InputStream is = getClass().getResourceAsStream("Resources.txt");
    2.36 +        assert is != null : "The stream for Resources.txt should be found";
    2.37 +        byte[] b = new byte[30];
    2.38 +        int len = is.read(b);
    2.39 +        StringBuilder sb = new StringBuilder();
    2.40 +        for (int i = 0; i < len; i++) {
    2.41 +            sb.append((char)b[i]);
    2.42 +        }
    2.43 +        return sb.toString();
    2.44 +    }
    2.45 +    
    2.46 +    @Factory public static Object[] create() {
    2.47 +        return VMTest.create(ResourcesInBrwsrTest.class);
    2.48 +    }
    2.49 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/rt/emul/brwsrtest/src/test/resources/org/apidesign/bck2brwsr/brwsrtest/Resources.txt	Tue Apr 29 10:23:55 2014 +0200
     3.3 @@ -0,0 +1,1 @@
     3.4 +Ahoj