1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Mon Dec 17 17:51:05 2012 +0100
1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java Tue Dec 18 13:10:56 2012 +0100
1.3 @@ -29,6 +29,7 @@
1.4 import javax.script.Invocable;
1.5 import javax.script.ScriptEngine;
1.6 import javax.script.ScriptEngineManager;
1.7 +import org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher;
1.8 import org.apidesign.vm4brwsr.Bck2Brwsr;
1.9 import org.testng.Assert;
1.10 import org.testng.ITest;
1.11 @@ -63,18 +64,21 @@
1.12 */
1.13 public static Object[] create(Class<?> clazz) {
1.14 Method[] arr = clazz.getMethods();
1.15 - Object[] ret = new Object[3 * arr.length];
1.16 + Object[] ret = new Object[5 * arr.length];
1.17 int cnt = 0;
1.18 for (Method m : arr) {
1.19 Compare c = m.getAnnotation(Compare.class);
1.20 if (c == null) {
1.21 continue;
1.22 }
1.23 - final Run real = new Run(m, false);
1.24 - final Run js = new Run(m, true);
1.25 + final Run real = new Run(m, 0);
1.26 + final Run js = new Run(m, 1);
1.27 + final Run brwsr = new Run(m, 2);
1.28 ret[cnt++] = real;
1.29 ret[cnt++] = js;
1.30 + ret[cnt++] = brwsr;
1.31 ret[cnt++] = new VMTest(m, real, js);
1.32 + ret[cnt++] = new VMTest(m, real, brwsr);
1.33 }
1.34 Object[] r = new Object[cnt];
1.35 for (int i = 0; i < cnt; i++) {
1.36 @@ -100,7 +104,7 @@
1.37 */
1.38 @Override
1.39 public String getTestName() {
1.40 - return m.getName() + "[Compare]";
1.41 + return m.getName() + "[Compare " + second.typeName() + "]";
1.42 }
1.43
1.44 /** Helper method that inspects the classpath and loads given resource
1.45 @@ -136,15 +140,15 @@
1.46
1.47 public static final class Run implements ITest {
1.48 private final Method m;
1.49 - private final boolean js;
1.50 + private final int type;
1.51 Object value;
1.52 private Invocable code;
1.53 private CharSequence codeSeq;
1.54 private static final Map<Class,Object[]> compiled = new WeakHashMap<>();
1.55
1.56 - private Run(Method m, boolean js) {
1.57 + private Run(Method m, int type) {
1.58 this.m = m;
1.59 - this.js = js;
1.60 + this.type = type;
1.61 }
1.62
1.63 private void compileTheCode(Class<?> clazz) throws Exception {
1.64 @@ -173,7 +177,7 @@
1.65 }
1.66
1.67 @Test(groups = "run") public void executeCode() throws Throwable {
1.68 - if (js) {
1.69 + if (type == 1) {
1.70 try {
1.71 compileTheCode(m.getDeclaringClass());
1.72 Object vm = code.invokeFunction("initVM");
1.73 @@ -182,13 +186,28 @@
1.74 } catch (Exception ex) {
1.75 throw new AssertionError(dumpJS(codeSeq)).initCause(ex);
1.76 }
1.77 + } else if (type == 2) {
1.78 + Bck2BrwsrLauncher l = new Bck2BrwsrLauncher();
1.79 + l.setTimeout(5000);
1.80 + Bck2BrwsrLauncher.MethodInvocation c = l.addMethod(m.getDeclaringClass(), m.getName());
1.81 + l.execute();
1.82 + value = c.toString();
1.83 } else {
1.84 value = m.invoke(m.getDeclaringClass().newInstance());
1.85 }
1.86 }
1.87 @Override
1.88 public String getTestName() {
1.89 - return m.getName() + (js ? "[JavaScript]" : "[Java]");
1.90 + return m.getName() + "[" + typeName() + "]";
1.91 + }
1.92 +
1.93 + final String typeName() {
1.94 + switch (type) {
1.95 + case 0: return "Java";
1.96 + case 1: return "JavaScript";
1.97 + case 2: return "Browser";
1.98 + default: return "Unknown type " + type;
1.99 + }
1.100 }
1.101
1.102 private static String computeSignature(Method m) {