//
// $Id$
//
// Nexus GWTIO - I/O and network services for Nexus built on GWT and WebSockets
// http://github.com/samskivert/nexus/blob/master/LICENSE

package com.samskivert.nexus.io;

import com.google.gwt.junit.client.GWTTestCase;

import org.junit.*;
import static org.junit.Assert.*;

/**
 * Tests the client input and server output pair (in conjunction with ServerOutputTest in
 * nexus-server).
 */
public class ClientInputTest extends GWTTestCase
{
    public String getModuleName ()
    {
        return "com.samskivert.nexus.GWTIO";
    }

    @Test
    public void testBasicTypes ()
    {
        Streamable.Input in = GWTIO.newInput(new TestSerializer(), BASIC_TYPES_PAYLOAD);
        assertEquals(true, in.readBoolean());
        assertEquals(false, in.readBoolean());
        assertEquals(Byte.MIN_VALUE, in.readByte());
        assertEquals((byte)0, in.readByte());
        assertEquals(Byte.MAX_VALUE, in.readByte());
        assertEquals(Short.MIN_VALUE, in.readShort());
        assertEquals((short)0, in.readShort());
        assertEquals(Short.MAX_VALUE, in.readShort());
        assertEquals(Character.MIN_VALUE, in.readChar());
        assertEquals('0', in.readChar());
        assertEquals(Character.MAX_VALUE, in.readChar());
        assertEquals(Integer.MIN_VALUE, in.readInt());
        assertEquals(0, in.readInt());
        assertEquals(Integer.MAX_VALUE, in.readInt());
        assertEquals(Long.MIN_VALUE, in.readLong());
        assertEquals(0L, in.readLong());
        assertEquals(Long.MAX_VALUE, in.readLong());
        assertEquals(Float.MIN_VALUE, in.readFloat(), 0f);
        assertEquals(0.0f, in.readFloat(), 0f);
        assertEquals(Float.MAX_VALUE, in.readFloat(), 0f);
        assertEquals(Double.MIN_VALUE, in.readDouble(), 0.0);
        assertEquals(0.0, in.readDouble(), 0.0);
        assertEquals(Double.MAX_VALUE, in.readDouble(), 0.0);
        assertEquals(null, in.readString());
        assertEquals("The quick brown fox jumped over the lazy dog.", in.readString());
    }

    protected static final String BASIC_TYPES_PAYLOAD =
        "1|0|-128|0|127|-32768|0|32767|0|48|65535|-2147483648|0|2147483647|IAAAAAAAAAA|" +
        "A|H__________|1.401298464324817E-45|0.0|3.4028234663852886E38|4.9E-324|0.0|" +
        "1.7976931348623157E308|0|1|The quick brown fox jumped over the lazy dog.|";
}

@@ -2088,49 +2088,50 @@
    %22
-1%7C0%7C
+%5B1,0,
 -128
-%7C0%7C127%7C
+,0,127,
 -32768
-%7C0%7C
+,0,
 32767
-%7C0%7C48%7C
+,0,48,
 65535
-%7C
+,
 -214
@@ -2137,19 +2137,19 @@
 47483648
-%7C0%7C
+,0,
 21474836
@@ -2150,17 +2150,18 @@
 47483647
-%7C
+,'
 IAAAAAAA
@@ -2163,17 +2163,18 @@
 AAAAAAAA
-%7C
+',
 %22 +%0A    
@@ -2182,10 +2182,13 @@
    %22
-A%7C
+'A','
 H___
@@ -2194,17 +2194,18 @@
 ________
-%7C
+',
 1.401298
@@ -2217,21 +2217,21 @@
 4817E-45
-%7C0.0%7C
+,0.0,
 3.402823
@@ -2247,17 +2247,17 @@
 6E38
-%7C
+,
 4.9E-324
 %7C0.0
@@ -2256,13 +2256,13 @@
 -324
-%7C0.0%7C
+,0.0,
 %22 +%0A
@@ -2296,13 +2296,16 @@
 E308
-%7C0%7C1%7C
+,null,%5C%22
 The 
@@ -2349,9 +2349,11 @@
 dog.
-%7C
+%5C%22%5D
 %22;%0A%7D

Use the proper payload string, not that the damned test will run anyway, due to massive GWT machinations.