1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Tue Jan 22 11:14:00 2013 +0100
1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Tue Jan 22 11:59:25 2013 +0100
1.3 @@ -243,7 +243,8 @@
1.4 LOG.log(Level.INFO, "Desktop.browse successfully finished");
1.5 return null;
1.6 } catch (UnsupportedOperationException ex) {
1.7 - LOG.log(Level.INFO, "Desktop.browse not supported", ex);
1.8 + LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
1.9 + LOG.log(Level.FINE, null, ex);
1.10 }
1.11 }
1.12 {
2.1 --- a/vmtest/pom.xml Tue Jan 22 11:14:00 2013 +0100
2.2 +++ b/vmtest/pom.xml Tue Jan 22 11:59:25 2013 +0100
2.3 @@ -44,13 +44,14 @@
2.4 <dependency>
2.5 <groupId>${project.groupId}</groupId>
2.6 <artifactId>vm4brwsr</artifactId>
2.7 - <version>0.3-SNAPSHOT</version>
2.8 + <version>${project.version}</version>
2.9 <type>jar</type>
2.10 </dependency>
2.11 <dependency>
2.12 <groupId>${project.groupId}</groupId>
2.13 <artifactId>emul</artifactId>
2.14 - <version>0.3-SNAPSHOT</version>
2.15 + <version>${project.version}</version>
2.16 + <scope>test</scope>
2.17 </dependency>
2.18 <dependency>
2.19 <groupId>${project.groupId}</groupId>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/BrwsrTest.java Tue Jan 22 11:59:25 2013 +0100
3.3 @@ -0,0 +1,38 @@
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;
3.22 +
3.23 +import java.lang.annotation.ElementType;
3.24 +import java.lang.annotation.Retention;
3.25 +import java.lang.annotation.RetentionPolicy;
3.26 +import java.lang.annotation.Target;
3.27 +
3.28 +/** Annotation to indicate that given method should be executed
3.29 + * in a browser environment. Has to be used in conjunction with {@link VMTest#create(java.lang.Class)}
3.30 + * factory method.
3.31 + * <p>
3.32 + * The browser to is by default executed via {@link java.awt.Desktop#browse(java.net.URI)},
3.33 + * but one can change that by specifying <code>-Dvmtest.brwsrs=firefox,google-chrome</code>
3.34 + * property.
3.35 + *
3.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
3.37 + */
3.38 +@Retention(RetentionPolicy.RUNTIME)
3.39 +@Target(ElementType.METHOD)
3.40 +public @interface BrwsrTest {
3.41 +}
4.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java Tue Jan 22 11:14:00 2013 +0100
4.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Compare.java Tue Jan 22 11:59:25 2013 +0100
4.3 @@ -32,5 +32,4 @@
4.4 @Retention(RetentionPolicy.RUNTIME)
4.5 @Target(ElementType.METHOD)
4.6 public @interface Compare {
4.7 -
4.8 }
5.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 11:14:00 2013 +0100
5.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Bck2BrwsrCase.java Tue Jan 22 11:59:25 2013 +0100
5.3 @@ -20,6 +20,7 @@
5.4 import java.io.File;
5.5 import java.io.FileWriter;
5.6 import java.io.IOException;
5.7 +import java.lang.reflect.Constructor;
5.8 import java.lang.reflect.InvocationTargetException;
5.9 import java.lang.reflect.Method;
5.10 import java.util.Map;
5.11 @@ -37,21 +38,56 @@
5.12 private final Method m;
5.13 private final Launcher l;
5.14 private final String type;
5.15 + private final boolean fail;
5.16 Object value;
5.17 private static final Map<Class, Object[]> compiled = new WeakHashMap<>();
5.18 private Object inst;
5.19
5.20 - Bck2BrwsrCase(Method m, String type, Launcher l) {
5.21 + Bck2BrwsrCase(Method m, String type, Launcher l, boolean fail) {
5.22 this.l = l;
5.23 this.m = m;
5.24 this.type = type;
5.25 + this.fail = fail;
5.26 }
5.27
5.28 @Test(groups = "run")
5.29 public void executeCode() throws Throwable {
5.30 if (l != null) {
5.31 MethodInvocation c = l.invokeMethod(m.getDeclaringClass(), m.getName());
5.32 - value = c.toString();
5.33 + String res = c.toString();
5.34 + value = res;
5.35 + if (fail) {
5.36 + int idx = res.indexOf(':');
5.37 + if (idx >= 0) {
5.38 + Class<? extends Throwable> thrwbl = null;
5.39 + try {
5.40 + Class<?> exCls = Class.forName(res.substring(0, idx));
5.41 + if (Throwable.class.isAssignableFrom(exCls)) {
5.42 + thrwbl = exCls.asSubclass(Throwable.class);
5.43 + }
5.44 + } catch (Exception ex) {
5.45 + // ignore
5.46 + }
5.47 + if (thrwbl != null) {
5.48 + Throwable t = null;
5.49 + try {
5.50 + for (Constructor<?> cnstr : thrwbl.getConstructors()) {
5.51 + if (cnstr.getParameterTypes().length == 1 && cnstr.getParameterTypes()[0].isAssignableFrom(String.class)) {
5.52 + t = (Throwable) cnstr.newInstance(res.substring(idx + 1));
5.53 + break;
5.54 + }
5.55 + }
5.56 + } catch (Throwable ex) {
5.57 + t = thrwbl.newInstance().initCause(ex);
5.58 + }
5.59 + if (t == null) {
5.60 + t = thrwbl.newInstance().initCause(new Exception(res.substring(idx)));
5.61 + }
5.62 + throw t;
5.63 + }
5.64 + throw new AssertionError(res);
5.65 + }
5.66 + }
5.67 } else {
5.68 try {
5.69 value = m.invoke(m.getDeclaringClass().newInstance());
6.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Jan 22 11:14:00 2013 +0100
6.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/CompareCase.java Tue Jan 22 11:59:25 2013 +0100
6.3 @@ -74,23 +74,8 @@
6.4 }
6.5
6.6 for (Method m : arr) {
6.7 - Compare c = m.getAnnotation(Compare.class);
6.8 - if (c == null) {
6.9 - continue;
6.10 - }
6.11 - final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null);
6.12 - final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript());
6.13 - ret.add(real);
6.14 - ret.add(js);
6.15 - ret.add(new CompareCase(m, real, js));
6.16 -
6.17 - for (String b : brwsr) {
6.18 - final Launcher s = l.brwsr(b);
6.19 - ret.add(s);
6.20 - final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s);
6.21 - ret.add(cse);
6.22 - ret.add(new CompareCase(m, real, cse));
6.23 - }
6.24 + registerCompareCases(m, l, ret, brwsr);
6.25 + registerBrwsrCases(m, l, ret, brwsr);
6.26 }
6.27 return ret.toArray();
6.28 }
6.29 @@ -123,4 +108,40 @@
6.30 public String getTestName() {
6.31 return m.getName() + "[Compare " + second.typeName() + "]";
6.32 }
6.33 +
6.34 + private static void registerCompareCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
6.35 + Compare c = m.getAnnotation(Compare.class);
6.36 + if (c == null) {
6.37 + return;
6.38 + }
6.39 + final Bck2BrwsrCase real = new Bck2BrwsrCase(m, "Java", null, false);
6.40 + final Bck2BrwsrCase js = new Bck2BrwsrCase(m, "JavaScript", l.javaScript(), false);
6.41 + ret.add(real);
6.42 + ret.add(js);
6.43 + ret.add(new CompareCase(m, real, js));
6.44 + for (String b : brwsr) {
6.45 + final Launcher s = l.brwsr(b);
6.46 + ret.add(s);
6.47 + final Bck2BrwsrCase cse = new Bck2BrwsrCase(m, b, s, false);
6.48 + ret.add(cse);
6.49 + ret.add(new CompareCase(m, real, cse));
6.50 + }
6.51 + }
6.52 + private static void registerBrwsrCases(Method m, final LaunchSetup l, List<Object> ret, String[] brwsr) {
6.53 + BrwsrTest c = m.getAnnotation(BrwsrTest.class);
6.54 + if (c == null) {
6.55 + return;
6.56 + }
6.57 + if (brwsr.length == 0) {
6.58 + final Launcher s = l.brwsr(null);
6.59 + ret.add(s);
6.60 + ret.add(new Bck2BrwsrCase(m, "Brwsr", s, true));
6.61 + } else {
6.62 + for (String b : brwsr) {
6.63 + final Launcher s = l.brwsr(b);
6.64 + ret.add(s);
6.65 + ret.add(new Bck2BrwsrCase(m, b, s, true));
6.66 + }
6.67 + }
6.68 + }
6.69 }
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/BrwsrCheckTest.java Tue Jan 22 11:59:25 2013 +0100
7.3 @@ -0,0 +1,43 @@
7.4 +/**
7.5 + * Back 2 Browser Bytecode Translator
7.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 + *
7.8 + * This program is free software: you can redistribute it and/or modify
7.9 + * it under the terms of the GNU General Public License as published by
7.10 + * the Free Software Foundation, version 2 of the License.
7.11 + *
7.12 + * This program is distributed in the hope that it will be useful,
7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 + * GNU General Public License for more details.
7.16 + *
7.17 + * You should have received a copy of the GNU General Public License
7.18 + * along with this program. Look for COPYING file in the top folder.
7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 + */
7.21 +package org.apidesign.bck2brwsr.tck;
7.22 +
7.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
7.24 +import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
7.25 +import org.apidesign.bck2brwsr.vmtest.VMTest;
7.26 +import org.testng.annotations.Factory;
7.27 +
7.28 +/**
7.29 + *
7.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
7.31 + */
7.32 +public class BrwsrCheckTest {
7.33 +
7.34 + @BrwsrTest public void assertWindowObjectIsDefined() {
7.35 + assert window() != null : "No window object found!";
7.36 + }
7.37 +
7.38 + @Factory
7.39 + public static Object[] create() {
7.40 + return VMTest.create(BrwsrCheckTest.class);
7.41 + }
7.42 +
7.43 + @JavaScriptBody(args = {}, body = "return window;")
7.44 + private static native Object window();
7.45 +
7.46 +}