# HG changeset patch # User Jaroslav Tulach # Date 1356445918 -3600 # Node ID 88ed1f51eb220bdcbb16e9b1fe3a3bd1bd0c490a # Parent 57fc3a0563c99b31005b87de94889457aa156f2a One can specify list of browsers to test in via 'vmtest.brwsrs' property diff -r 57fc3a0563c9 -r 88ed1f51eb22 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 15:08:39 2012 +0100 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Dec 25 15:31:58 2012 +0100 @@ -31,15 +31,15 @@ */ public final class Bck2BrwsrCase implements ITest { private final Method m; - private final Launchers l; - private final int type; + private final LaunchSetup l; + private final String type; Object value; private Invocable code; private CharSequence codeSeq; private static final Map compiled = new WeakHashMap<>(); private Object inst; - Bck2BrwsrCase(Method m, int type, Launchers l) { + Bck2BrwsrCase(Method m, String type, LaunchSetup l) { this.l = l; this.m = m; this.type = type; @@ -47,11 +47,8 @@ @Test(groups = "run") public void executeCode() throws Throwable { - if (type == 1) { - MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), false); - value = c.toString(); - } else if (type == 2) { - MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName(), true); + if (l != null) { + MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName()); value = c.toString(); } else { value = m.invoke(m.getDeclaringClass().newInstance()); @@ -64,67 +61,6 @@ } final String typeName() { - switch (type) { - case 0: - return "Java"; - case 1: - return "JavaScript"; - case 2: - return "Browser"; - default: - return "Unknown type " + type; - } + return type; } - - private static String computeSignature(Method m) { - StringBuilder sb = new StringBuilder(); - appendType(sb, m.getReturnType()); - for (Class c : m.getParameterTypes()) { - appendType(sb, c); - } - return sb.toString(); - } - - private static void appendType(StringBuilder sb, Class t) { - if (t == null) { - sb.append('V'); - return; - } - if (t.isPrimitive()) { - int ch = -1; - if (t == int.class) { - ch = 'I'; - } - if (t == short.class) { - ch = 'S'; - } - if (t == byte.class) { - ch = 'B'; - } - if (t == boolean.class) { - ch = 'Z'; - } - if (t == long.class) { - ch = 'J'; - } - if (t == float.class) { - ch = 'F'; - } - if (t == double.class) { - ch = 'D'; - } - assert ch != -1 : "Unknown primitive type " + t; - sb.append((char) ch); - return; - } - if (t.isArray()) { - sb.append("_3"); - appendType(sb, t.getComponentType()); - return; - } - sb.append('L'); - sb.append(t.getName().replace('.', '_')); - sb.append("_2"); - } - } diff -r 57fc3a0563c9 -r 88ed1f51eb22 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 15:08:39 2012 +0100 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Dec 25 15:31:58 2012 +0100 @@ -59,25 +59,37 @@ Method[] arr = clazz.getMethods(); List ret = new ArrayList<>(); - final Launchers l = Launchers.INSTANCE; - + final LaunchSetup l = LaunchSetup.javaScript(); ret.add(l); + String[] brwsr; + { + String p = System.getProperty("vmtest.brwsrs"); + if (p != null) { + brwsr = p.split(","); + } else { + brwsr = new String[0]; + } + } + for (Method m : arr) { Compare c = m.getAnnotation(Compare.class); if (c == null) { continue; } - final Bck2BrwsrCase real = new Bck2BrwsrCase(m, 0, null); - final Bck2BrwsrCase js = new Bck2BrwsrCase(m, 1, l); - final Bck2BrwsrCase brwsr = new Bck2BrwsrCase(m, 2, l); - + final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null); + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l); ret.add(real); ret.add(js); - ret.add(brwsr); - ret.add(new CompareCase(m, real, js)); - ret.add(new CompareCase(m, real, brwsr)); + + for (String b : brwsr) { + final LaunchSetup s = LaunchSetup.brwsr(b); + ret.add(s); + final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s); + ret.add(cse); + ret.add(new CompareCase(m, real, cse)); + } } return ret.toArray(); } diff -r 57fc3a0563c9 -r 88ed1f51eb22 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java Tue Dec 25 15:31:58 2012 +0100 @@ -0,0 +1,68 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.vmtest.impl; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import org.apidesign.bck2brwsr.launcher.Launcher; +import org.apidesign.bck2brwsr.launcher.MethodInvocation; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; + +/** + * + * @author Jaroslav Tulach + */ +public final class LaunchSetup { + private static final LaunchSetup JS = new LaunchSetup(Launcher.createJavaScript()); + private static final Map BRWSRS = new LinkedHashMap<>(); + + private final Launcher launcher; + + private LaunchSetup(Launcher l) { + launcher = l; + } + + public static LaunchSetup javaScript() { + return JS; + } + + public static synchronized LaunchSetup brwsr(String cmd) { + LaunchSetup s = BRWSRS.get(cmd); + if (s == null) { + s = new LaunchSetup(Launcher.createBrowser(cmd)); + BRWSRS.put(cmd, s); + } + return s; + } + + @BeforeGroups("run") + public void initializeLauncher() throws IOException { + launcher.initialize(); + } + + @AfterGroups("run") + public void shutDownLauncher() throws IOException, InterruptedException { + launcher.shutdown(); + } + + public MethodInvocation invokeMethod(Class clazz, String name) throws IOException { + return launcher.invokeMethod(clazz, name); + } +} diff -r 57fc3a0563c9 -r 88ed1f51eb22 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java Tue Dec 25 15:08:39 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.vmtest.impl; - -import java.io.IOException; -import org.apidesign.bck2brwsr.launcher.Launcher; -import org.apidesign.bck2brwsr.launcher.MethodInvocation; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; - -/** - * - * @author Jaroslav Tulach - */ -public final class Launchers { - public static final Launchers INSTANCE = new Launchers(); - - private Launcher jsl; - private Launcher brwsr; - - private Launchers() { - } - - @BeforeGroups("run") - public void initializeLauncher() throws IOException { - jsl = Launcher.createJavaScript(); - jsl.initialize(); - Launcher l = Launcher.createBrowser("xdg-open"); - l.initialize(); - brwsr = l; - } - - @AfterGroups("run") - public void shutDownLauncher() throws IOException, InterruptedException { - jsl.shutdown(); - brwsr.shutdown(); - } - - public MethodInvocation invokeMethod(Class clazz, String name, boolean inBrwsr) throws IOException { - if (!inBrwsr) { - return jsl.invokeMethod(clazz, name); - } else { - return brwsr.invokeMethod(clazz, name); - } - } -}