1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Sun Nov 18 10:00:23 2012 +0100
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Sun Nov 18 19:01:38 2012 +0100
1.3 @@ -17,6 +17,11 @@
1.4 */
1.5 package org.apidesign.vm4brwsr;
1.6
1.7 +import java.io.ByteArrayInputStream;
1.8 +import java.io.ByteArrayOutputStream;
1.9 +import java.io.DataInputStream;
1.10 +import java.io.DataOutputStream;
1.11 +import java.io.IOException;
1.12 import javax.script.Invocable;
1.13 import javax.script.ScriptException;
1.14 import static org.testng.Assert.*;
1.15 @@ -71,6 +76,23 @@
1.16 Double.valueOf(exp)
1.17 );
1.18 }
1.19 +
1.20 + @Test public void deserializeSimpleLong() throws Exception {
1.21 + assertExec("Should be 3454", "org_apidesign_vm4brwsr_Numbers_deserLongJAB",
1.22 + Double.valueOf(3454),
1.23 + new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
1.24 + );
1.25 + }
1.26 + /* XXX: JavaScript cannot represent as big longs as Java.
1.27 + @Test public void deserializeLargeLong() throws Exception {
1.28 + final byte[] arr = new byte[] {
1.29 + (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
1.30 + };
1.31 + long exp = Numbers.deserLong(arr);
1.32 + assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLongJAB",
1.33 + Double.valueOf(exp), arr);
1.34 + }
1.35 + */
1.36
1.37 @Test public void deserializeFloatInJava() throws Exception {
1.38 float f = 54324.32423f;
1.39 @@ -85,7 +107,32 @@
1.40 );
1.41 }
1.42
1.43 + @Test public void deserializeDoubleInJava() throws Exception {
1.44 + double f = 3.0;
1.45 + double r = Numbers.deserDouble();
1.46 + assertEquals(r, f, 0.001, "Doubles are the same");
1.47 + }
1.48
1.49 + @Test public void deserializeDoubleInJS() throws Exception {
1.50 + double f = 3.0;
1.51 + assertExec("Should be the same", "org_apidesign_vm4brwsr_Numbers_deserDoubleD", f);
1.52 + }
1.53 + /*
1.54 + @Test public void serDouble() throws IOException {
1.55 + double f = 3.0;
1.56 + ByteArrayOutputStream os = new ByteArrayOutputStream();
1.57 + DataOutputStream d = new DataOutputStream(os);
1.58 + d.writeLong(3454);
1.59 + d.close();
1.60 +
1.61 + StringBuilder sb = new StringBuilder();
1.62 + byte[] arr = os.toByteArray();
1.63 + for (int i = 0; i < arr.length; i++) {
1.64 + sb.append("(byte)").append(arr[i]).append(", ");
1.65 + }
1.66 + fail("" + sb);
1.67 + }
1.68 +*/
1.69 private static CharSequence codeSeq;
1.70 private static Invocable code;
1.71