1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Fri Dec 07 10:09:50 2012 +0100
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Tue Dec 11 10:24:00 2012 +0100
1.3 @@ -35,8 +35,33 @@
1.4 private static CharSequence codeSeq;
1.5 private static Invocable code;
1.6
1.7 - @Test public void compareTheGeneratedCode() throws Exception {
1.8 - byte[] arr = readClass("/org/apidesign/vm4brwsr/Array.class");
1.9 + @Test public void compareGeneratedCodeForArrayClass() throws Exception {
1.10 + compareCode("/org/apidesign/vm4brwsr/Array.class");
1.11 + }
1.12 +
1.13 + @BeforeClass
1.14 + public void compileTheCode() throws Exception {
1.15 + StringBuilder sb = new StringBuilder();
1.16 + code = StaticMethodTest.compileClass(sb,
1.17 + "org/apidesign/vm4brwsr/VMinVM"
1.18 + );
1.19 + codeSeq = sb;
1.20 + }
1.21 +
1.22 + private static byte[] readClass(String res) throws IOException {
1.23 + InputStream is1 = VMinVMTest.class.getResourceAsStream(res);
1.24 + assertNotNull(is1, "Stream found");
1.25 + byte[] arr = new byte[is1.available()];
1.26 + int len = is1.read(arr);
1.27 + is1.close();
1.28 + if (len != arr.length) {
1.29 + throw new IOException("Wrong len " + len + " for arr: " + arr.length);
1.30 + }
1.31 + return arr;
1.32 + }
1.33 +
1.34 + private void compareCode(final String nm) throws Exception, IOException {
1.35 + byte[] arr = readClass(nm);
1.36 String ret1 = VMinVM.toJavaScript(arr);
1.37
1.38 Object ret;
1.39 @@ -65,27 +90,11 @@
1.40
1.41 assertTrue(ret instanceof String, "It is string: " + ret);
1.42
1.43 - assertEquals((String)ret, ret1.toString(), "The code is the same");
1.44 - }
1.45 -
1.46 - @BeforeClass
1.47 - public void compileTheCode() throws Exception {
1.48 - StringBuilder sb = new StringBuilder();
1.49 - code = StaticMethodTest.compileClass(sb,
1.50 - "org/apidesign/vm4brwsr/VMinVM"
1.51 - );
1.52 - codeSeq = sb;
1.53 - }
1.54 -
1.55 - private static byte[] readClass(String res) throws IOException {
1.56 - InputStream is1 = VMinVMTest.class.getResourceAsStream(res);
1.57 - assertNotNull(is1, "Stream found");
1.58 - byte[] arr = new byte[is1.available()];
1.59 - int len = is1.read(arr);
1.60 - is1.close();
1.61 - if (len != arr.length) {
1.62 - throw new IOException("Wrong len " + len + " for arr: " + arr.length);
1.63 + if (!ret1.toString().equals(ret)) {
1.64 + StringBuilder msg = StaticMethodTest.dumpJS(ret1);
1.65 + msg.append(" is not the same as ");
1.66 + msg.append(StaticMethodTest.dumpJS((CharSequence) ret));
1.67 + fail(msg.toString());
1.68 }
1.69 - return arr;
1.70 }
1.71 }