1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 15:08:39 2012 +0100
1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 15:31:58 2012 +0100
1.3 @@ -31,15 +31,15 @@
1.4 */
1.5 public final class Bck2BrwsrCase implements ITest {
1.6 private final Method m;
1.7 - private final Launchers l;
1.8 - private final int type;
1.9 + private final LaunchSetup l;
1.10 + private final String type;
1.11 Object value;
1.12 private Invocable code;
1.13 private CharSequence codeSeq;
1.14 private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
1.15 private Object inst;
1.16
1.17 - Bck2BrwsrCase(Method m, int type, Launchers l) {
1.18 + Bck2BrwsrCase(Method m, String type, LaunchSetup l) {
1.19 this.l = l;
1.20 this.m = m;
1.21 this.type = type;
1.22 @@ -47,11 +47,8 @@
1.23
1.24 @Test(groups = "run")
1.25 public void executeCode() throws Throwable {
1.26 - if (type == 1) {
1.27 - MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), false);
1.28 - value = c.toString();
1.29 - } else if (type == 2) {
1.30 - MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), true);
1.31 + if (l != null) {
1.32 + MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName());
1.33 value = c.toString();
1.34 } else {
1.35 value = m.invoke(m.getDeclaringClass().newInstance());
1.36 @@ -64,67 +61,6 @@
1.37 }
1.38
1.39 final String typeName() {
1.40 - switch (type) {
1.41 - case 0:
1.42 - return "Java";
1.43 - case 1:
1.44 - return "JavaScript";
1.45 - case 2:
1.46 - return "Browser";
1.47 - default:
1.48 - return "Unknown type " + type;
1.49 - }
1.50 + return type;
1.51 }
1.52 -
1.53 - private static String computeSignature(Method m) {
1.54 - StringBuilder sb = new StringBuilder();
1.55 - appendType(sb, m.getReturnType());
1.56 - for (Class<?> c : m.getParameterTypes()) {
1.57 - appendType(sb, c);
1.58 - }
1.59 - return sb.toString();
1.60 - }
1.61 -
1.62 - private static void appendType(StringBuilder sb, Class<?> t) {
1.63 - if (t == null) {
1.64 - sb.append('V');
1.65 - return;
1.66 - }
1.67 - if (t.isPrimitive()) {
1.68 - int ch = -1;
1.69 - if (t == int.class) {
1.70 - ch = 'I';
1.71 - }
1.72 - if (t == short.class) {
1.73 - ch = 'S';
1.74 - }
1.75 - if (t == byte.class) {
1.76 - ch = 'B';
1.77 - }
1.78 - if (t == boolean.class) {
1.79 - ch = 'Z';
1.80 - }
1.81 - if (t == long.class) {
1.82 - ch = 'J';
1.83 - }
1.84 - if (t == float.class) {
1.85 - ch = 'F';
1.86 - }
1.87 - if (t == double.class) {
1.88 - ch = 'D';
1.89 - }
1.90 - assert ch != -1 : "Unknown primitive type " + t;
1.91 - sb.append((char) ch);
1.92 - return;
1.93 - }
1.94 - if (t.isArray()) {
1.95 - sb.append("_3");
1.96 - appendType(sb, t.getComponentType());
1.97 - return;
1.98 - }
1.99 - sb.append('L');
1.100 - sb.append(t.getName().replace('.', '_'));
1.101 - sb.append("_2");
1.102 - }
1.103 -
1.104 }
2.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 15:08:39 2012 +0100
2.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 15:31:58 2012 +0100
2.3 @@ -59,25 +59,37 @@
2.4 Method[] arr = clazz.getMethods();
2.5 List<Object> ret = new ArrayList<>();
2.6
2.7 - final Launchers l = Launchers.INSTANCE;
2.8 -
2.9 + final LaunchSetup l = LaunchSetup.javaScript();
2.10 ret.add(l);
2.11
2.12 + String[] brwsr;
2.13 + {
2.14 + String p = System.getProperty("vmtest.brwsrs");
2.15 + if (p != null) {
2.16 + brwsr = p.split(",");
2.17 + } else {
2.18 + brwsr = new String[0];
2.19 + }
2.20 + }
2.21 +
2.22 for (Method m : arr) {
2.23 Compare c = m.getAnnotation(Compare.class);
2.24 if (c == null) {
2.25 continue;
2.26 }
2.27 - final Bck2BrwsrCase real = new Bck2BrwsrCase(m, 0, null);
2.28 - final Bck2BrwsrCase js = new Bck2BrwsrCase(m, 1, l);
2.29 - final Bck2BrwsrCase brwsr = new Bck2BrwsrCase(m, 2, l);
2.30 -
2.31 + final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null);
2.32 + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l);
2.33 ret.add(real);
2.34 ret.add(js);
2.35 - ret.add(brwsr);
2.36 -
2.37 ret.add(new CompareCase(m, real, js));
2.38 - ret.add(new CompareCase(m, real, brwsr));
2.39 +
2.40 + for (String b : brwsr) {
2.41 + final LaunchSetup s = LaunchSetup.brwsr(b);
2.42 + ret.add(s);
2.43 + final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s);
2.44 + ret.add(cse);
2.45 + ret.add(new CompareCase(m, real, cse));
2.46 + }
2.47 }
2.48 return ret.toArray();
2.49 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Tue Dec 25 15:31:58 2012 +0100
3.3 @@ -0,0 +1,68 @@
3.4 +/**
3.5 + * Back 2 Browser Bytecode Translator
3.6 + * Copyright (C) 2012 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.vmtest.impl;
3.22 +
3.23 +import java.io.IOException;
3.24 +import java.util.LinkedHashMap;
3.25 +import java.util.Map;
3.26 +import org.apidesign.bck2brwsr.launcher.Launcher;
3.27 +import org.apidesign.bck2brwsr.launcher.MethodInvocation;
3.28 +import org.testng.annotations.AfterGroups;
3.29 +import org.testng.annotations.BeforeGroups;
3.30 +
3.31 +/**
3.32 + *
3.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.34 + */
3.35 +public final class LaunchSetup {
3.36 + private static final LaunchSetup JS = new LaunchSetup(Launcher.createJavaScript());
3.37 + private static final Map<String,LaunchSetup> BRWSRS = new LinkedHashMap<>();
3.38 +
3.39 + private final Launcher launcher;
3.40 +
3.41 + private LaunchSetup(Launcher l) {
3.42 + launcher = l;
3.43 + }
3.44 +
3.45 + public static LaunchSetup javaScript() {
3.46 + return JS;
3.47 + }
3.48 +
3.49 + public static synchronized LaunchSetup brwsr(String cmd) {
3.50 + LaunchSetup s = BRWSRS.get(cmd);
3.51 + if (s == null) {
3.52 + s = new LaunchSetup(Launcher.createBrowser(cmd));
3.53 + BRWSRS.put(cmd, s);
3.54 + }
3.55 + return s;
3.56 + }
3.57 +
3.58 + @BeforeGroups("run")
3.59 + public void initializeLauncher() throws IOException {
3.60 + launcher.initialize();
3.61 + }
3.62 +
3.63 + @AfterGroups("run")
3.64 + public void shutDownLauncher() throws IOException, InterruptedException {
3.65 + launcher.shutdown();
3.66 + }
3.67 +
3.68 + public MethodInvocation invokeMethod(Class<?> clazz, String name) throws IOException {
3.69 + return launcher.invokeMethod(clazz, name);
3.70 + }
3.71 +}
4.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java Tue Dec 25 15:08:39 2012 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,61 +0,0 @@
4.4 -/**
4.5 - * Back 2 Browser Bytecode Translator
4.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 - *
4.8 - * This program is free software: you can redistribute it and/or modify
4.9 - * it under the terms of the GNU General Public License as published by
4.10 - * the Free Software Foundation, version 2 of the License.
4.11 - *
4.12 - * This program is distributed in the hope that it will be useful,
4.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 - * GNU General Public License for more details.
4.16 - *
4.17 - * You should have received a copy of the GNU General Public License
4.18 - * along with this program. Look for COPYING file in the top folder.
4.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
4.20 - */
4.21 -package org.apidesign.bck2brwsr.vmtest.impl;
4.22 -
4.23 -import java.io.IOException;
4.24 -import org.apidesign.bck2brwsr.launcher.Launcher;
4.25 -import org.apidesign.bck2brwsr.launcher.MethodInvocation;
4.26 -import org.testng.annotations.AfterGroups;
4.27 -import org.testng.annotations.BeforeGroups;
4.28 -
4.29 -/**
4.30 - *
4.31 - * @author Jaroslav Tulach <jtulach@netbeans.org>
4.32 - */
4.33 -public final class Launchers {
4.34 - public static final Launchers INSTANCE = new Launchers();
4.35 -
4.36 - private Launcher jsl;
4.37 - private Launcher brwsr;
4.38 -
4.39 - private Launchers() {
4.40 - }
4.41 -
4.42 - @BeforeGroups("run")
4.43 - public void initializeLauncher() throws IOException {
4.44 - jsl = Launcher.createJavaScript();
4.45 - jsl.initialize();
4.46 - Launcher l = Launcher.createBrowser("xdg-open");
4.47 - l.initialize();
4.48 - brwsr = l;
4.49 - }
4.50 -
4.51 - @AfterGroups("run")
4.52 - public void shutDownLauncher() throws IOException, InterruptedException {
4.53 - jsl.shutdown();
4.54 - brwsr.shutdown();
4.55 - }
4.56 -
4.57 - public MethodInvocation invokeMethod(Class<?> clazz, String name, boolean inBrwsr) throws IOException {
4.58 - if (!inBrwsr) {
4.59 - return jsl.invokeMethod(clazz, name);
4.60 - } else {
4.61 - return brwsr.invokeMethod(clazz, name);
4.62 - }
4.63 - }
4.64 -}