1.1 --- a/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrJavaScriptBodyTest.java Fri Feb 27 18:11:54 2015 +0100
1.2 +++ b/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrJavaScriptBodyTest.java Fri Feb 27 18:55:06 2015 +0100
1.3 @@ -27,14 +27,22 @@
1.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.5 */
1.6 public class Bck2BrwsrJavaScriptBodyTest extends JavaScriptTCK {
1.7 - @Factory public static Object[] tests() {
1.8 + @Factory public static Object[] create() {
1.9 + return VMTest.newTests().
1.10 + withClasses(tests()).
1.11 + withClasses(Bck2BrwsrKnockoutImpl.createClasses()).
1.12 + withLaunchers("bck2brwsr").
1.13 + withTestAnnotation(KOTest.class).
1.14 + build();
1.15 + }
1.16 +
1.17 + static Class[] tests() {
1.18 final Class<?>[] arr = testClasses();
1.19 for (int i = 0; i < arr.length; i++) {
1.20 if (arr[i].getSimpleName().startsWith("GC")) {
1.21 arr[i] = Object.class;
1.22 }
1.23 }
1.24 - return VMTest.newTests().withClasses(arr)
1.25 - .withTestAnnotation(KOTest.class).build();
1.26 + return arr;
1.27 }
1.28 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutImpl.java Fri Feb 27 18:55:06 2015 +0100
2.3 @@ -0,0 +1,121 @@
2.4 +/**
2.5 + * Back 2 Browser Bytecode Translator
2.6 + * Copyright (C) 2012-2015 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.ko2brwsr;
2.22 +
2.23 +import java.io.IOException;
2.24 +import java.net.URI;
2.25 +import java.net.URISyntaxException;
2.26 +import java.net.URL;
2.27 +import java.util.Map;
2.28 +import net.java.html.BrwsrCtx;
2.29 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
2.30 +import org.netbeans.html.context.spi.Contexts;
2.31 +import org.netbeans.html.json.spi.Technology;
2.32 +import org.netbeans.html.json.spi.Transfer;
2.33 +import org.netbeans.html.json.spi.WSTransfer;
2.34 +import org.netbeans.html.json.tck.KnockoutTCK;
2.35 +import org.netbeans.html.ko4j.KO4J;
2.36 +import org.openide.util.lookup.ServiceProvider;
2.37 +
2.38 +/**
2.39 + *
2.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.41 + */
2.42 +@ServiceProvider(service = KnockoutTCK.class)
2.43 +public final class Bck2BrwsrKnockoutImpl extends KnockoutTCK {
2.44 + static Class[] createClasses() {
2.45 + final Class<?>[] arr = testClasses();
2.46 + for (int i = 0; i < arr.length; i++) {
2.47 + if (arr[i].getSimpleName().startsWith("GC")) {
2.48 + arr[i] = Object.class;
2.49 + }
2.50 + }
2.51 + return arr;
2.52 + }
2.53 +
2.54 + @Override
2.55 + public BrwsrCtx createContext() {
2.56 + KO4J ko = new KO4J(null);
2.57 + return Contexts.newBuilder().
2.58 + register(Transfer.class, ko.transfer(), 9).
2.59 + register(WSTransfer.class, ko.websockets(), 9).
2.60 + register(Technology.class, ko.knockout(), 9).build();
2.61 + }
2.62 +
2.63 +
2.64 +
2.65 + @Override
2.66 + public Object createJSON(Map<String, Object> values) {
2.67 + Object json = createJSON();
2.68 +
2.69 + for (Map.Entry<String, Object> entry : values.entrySet()) {
2.70 + putValue(json, entry.getKey(), entry.getValue());
2.71 + }
2.72 + return json;
2.73 + }
2.74 +
2.75 + @JavaScriptBody(args = {}, body = "return new Object();")
2.76 + private static native Object createJSON();
2.77 +
2.78 + @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
2.79 + private static native void putValue(Object json, String key, Object value);
2.80 +
2.81 + @Override
2.82 + public Object executeScript(String script, Object[] arguments) {
2.83 + return execScript(script, arguments);
2.84 + }
2.85 +
2.86 + @JavaScriptBody(args = { "s", "args" }, body =
2.87 + "var f = new Function(s); return f.apply(null, args);"
2.88 + )
2.89 + private static native Object execScript(String s, Object[] arguments);
2.90 +
2.91 + @JavaScriptBody(args = { }, body =
2.92 + "var h;"
2.93 + + "if (!!window && !!window.location && !!window.location.href)\n"
2.94 + + " h = window.location.href;\n"
2.95 + + "else "
2.96 + + " h = null;"
2.97 + + "return h;\n"
2.98 + )
2.99 + private static native String findBaseURL();
2.100 +
2.101 + @Override
2.102 + public URI prepareURL(String content, String mimeType, String[] parameters) {
2.103 + try {
2.104 + final URL baseURL = new URL(findBaseURL());
2.105 + StringBuilder sb = new StringBuilder();
2.106 + sb.append("/dynamic?mimeType=").append(mimeType);
2.107 + for (int i = 0; i < parameters.length; i++) {
2.108 + sb.append("¶m" + i).append("=").append(parameters[i]);
2.109 + }
2.110 + String mangle = content.replace("\n", "%0a")
2.111 + .replace("\"", "\\\"").replace(" ", "%20");
2.112 + sb.append("&content=").append(mangle);
2.113 +
2.114 + URL query = new URL(baseURL, sb.toString());
2.115 + String uri = (String) query.getContent(new Class[] { String.class });
2.116 + URI connectTo = new URI(uri.trim());
2.117 + return connectTo;
2.118 + } catch (IOException ex) {
2.119 + throw new IllegalStateException(ex);
2.120 + } catch (URISyntaxException ex) {
2.121 + throw new IllegalStateException(ex);
2.122 + }
2.123 + }
2.124 +}
3.1 --- a/ko/bck2brwsr/src/test/java/org/apidesign/bck2brwsr/ko2brwsr/Bck2BrwsrKnockoutTest.java Fri Feb 27 18:11:54 2015 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,128 +0,0 @@
3.4 -/**
3.5 - * Back 2 Browser Bytecode Translator
3.6 - * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.7 - *
3.8 - * This program is free software: you can redistribute it and/or modify
3.9 - * it under the terms of the GNU General Public License as published by
3.10 - * the Free Software Foundation, version 2 of the License.
3.11 - *
3.12 - * This program is distributed in the hope that it will be useful,
3.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.15 - * GNU General Public License for more details.
3.16 - *
3.17 - * You should have received a copy of the GNU General Public License
3.18 - * along with this program. Look for COPYING file in the top folder.
3.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
3.20 - */
3.21 -package org.apidesign.bck2brwsr.ko2brwsr;
3.22 -
3.23 -import java.io.IOException;
3.24 -import java.net.URI;
3.25 -import java.net.URISyntaxException;
3.26 -import java.net.URL;
3.27 -import java.util.Map;
3.28 -import net.java.html.BrwsrCtx;
3.29 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
3.30 -import org.apidesign.bck2brwsr.vmtest.VMTest;
3.31 -import org.netbeans.html.context.spi.Contexts;
3.32 -import org.netbeans.html.json.spi.Technology;
3.33 -import org.netbeans.html.json.spi.Transfer;
3.34 -import org.netbeans.html.json.spi.WSTransfer;
3.35 -import org.netbeans.html.json.tck.KOTest;
3.36 -import org.netbeans.html.json.tck.KnockoutTCK;
3.37 -import org.netbeans.html.ko4j.KO4J;
3.38 -import org.openide.util.lookup.ServiceProvider;
3.39 -import org.testng.annotations.Factory;
3.40 -
3.41 -/**
3.42 - *
3.43 - * @author Jaroslav Tulach <jtulach@netbeans.org>
3.44 - */
3.45 -@ServiceProvider(service = KnockoutTCK.class)
3.46 -public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
3.47 - @Factory public static Object[] create() {
3.48 - final Class<?>[] arr = testClasses();
3.49 - for (int i = 0; i < arr.length; i++) {
3.50 - if (arr[i].getSimpleName().startsWith("GC")) {
3.51 - arr[i] = Object.class;
3.52 - }
3.53 - }
3.54 - return VMTest.newTests().
3.55 - withClasses(arr).
3.56 - withLaunchers("bck2brwsr").
3.57 - withTestAnnotation(KOTest.class).
3.58 - build();
3.59 - }
3.60 -
3.61 - @Override
3.62 - public BrwsrCtx createContext() {
3.63 - KO4J ko = new KO4J(null);
3.64 - return Contexts.newBuilder().
3.65 - register(Transfer.class, ko.transfer(), 9).
3.66 - register(WSTransfer.class, ko.websockets(), 9).
3.67 - register(Technology.class, ko.knockout(), 9).build();
3.68 - }
3.69 -
3.70 -
3.71 -
3.72 - @Override
3.73 - public Object createJSON(Map<String, Object> values) {
3.74 - Object json = createJSON();
3.75 -
3.76 - for (Map.Entry<String, Object> entry : values.entrySet()) {
3.77 - putValue(json, entry.getKey(), entry.getValue());
3.78 - }
3.79 - return json;
3.80 - }
3.81 -
3.82 - @JavaScriptBody(args = {}, body = "return new Object();")
3.83 - private static native Object createJSON();
3.84 -
3.85 - @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
3.86 - private static native void putValue(Object json, String key, Object value);
3.87 -
3.88 - @Override
3.89 - public Object executeScript(String script, Object[] arguments) {
3.90 - return execScript(script, arguments);
3.91 - }
3.92 -
3.93 - @JavaScriptBody(args = { "s", "args" }, body =
3.94 - "var f = new Function(s); return f.apply(null, args);"
3.95 - )
3.96 - private static native Object execScript(String s, Object[] arguments);
3.97 -
3.98 - @JavaScriptBody(args = { }, body =
3.99 - "var h;"
3.100 - + "if (!!window && !!window.location && !!window.location.href)\n"
3.101 - + " h = window.location.href;\n"
3.102 - + "else "
3.103 - + " h = null;"
3.104 - + "return h;\n"
3.105 - )
3.106 - private static native String findBaseURL();
3.107 -
3.108 - @Override
3.109 - public URI prepareURL(String content, String mimeType, String[] parameters) {
3.110 - try {
3.111 - final URL baseURL = new URL(findBaseURL());
3.112 - StringBuilder sb = new StringBuilder();
3.113 - sb.append("/dynamic?mimeType=").append(mimeType);
3.114 - for (int i = 0; i < parameters.length; i++) {
3.115 - sb.append("¶m" + i).append("=").append(parameters[i]);
3.116 - }
3.117 - String mangle = content.replace("\n", "%0a")
3.118 - .replace("\"", "\\\"").replace(" ", "%20");
3.119 - sb.append("&content=").append(mangle);
3.120 -
3.121 - URL query = new URL(baseURL, sb.toString());
3.122 - String uri = (String) query.getContent(new Class[] { String.class });
3.123 - URI connectTo = new URI(uri.trim());
3.124 - return connectTo;
3.125 - } catch (IOException ex) {
3.126 - throw new IllegalStateException(ex);
3.127 - } catch (URISyntaxException ex) {
3.128 - throw new IllegalStateException(ex);
3.129 - }
3.130 - }
3.131 -}