# HG changeset patch # User Shinji KONO # Date 1312330179 -32400 # Node ID 9b3b1e3e7db50783c960eb8d8287bcdcfee1cb5a # Parent a8c33757ac99eb52b21065a080045ff16a2cc898 add test routine diff -r a8c33757ac99 -r 9b3b1e3e7db5 .classpath --- a/.classpath Wed Aug 03 08:33:55 2011 +0900 +++ b/.classpath Wed Aug 03 09:09:39 2011 +0900 @@ -2,5 +2,6 @@ + diff -r a8c33757ac99 -r 9b3b1e3e7db5 src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 08:33:55 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 09:09:39 2011 +0900 @@ -1,5 +1,7 @@ package myVncProxy; +import static org.junit.Assert.*; + import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; @@ -17,6 +19,8 @@ import javax.imageio.ImageIO; +import org.junit.Test; + import myVncProxy.MulticastQueue.Client; import java.util.concurrent.ExecutorService; @@ -26,6 +30,7 @@ import java.util.zip.Inflater; import java.io.OutputStream; +public class MyRfbProto extends RfbProto { final static String versionMsg_3_998 = "RFB 003.998\n"; /** @@ -61,6 +66,10 @@ private int clients = 0; private Inflater inflater = new Inflater(); + public + MyRfbProto() throws IOException { + } + MyRfbProto(String h, int p, VncViewer v) throws IOException { super(h, p, v); cliList = new LinkedList(); @@ -565,16 +574,19 @@ * byte data[] * @throws IOException */ - public void unzip(Inflater inflater, byte[] input, LinkedList outputs) - throws DataFormatException { + public void unzip(Inflater inflater, LinkedList inputs, LinkedList outputs) + throws DataFormatException { int len=0,len0; - inflater.setInput(input); - do { - byte buf[] = new byte[INFLATE_BUFSIZE]; - len0 = inflater.inflate(buf); - len += len0; - outputs.addLast(buf); - } while (len0 ==INFLATE_BUFSIZE); + inputs.poll(); + for(byte [] input:inputs) { + inflater.setInput(input); + do { + byte buf[] = new byte[INFLATE_BUFSIZE]; + len0 = inflater.inflate(buf); + len += len0; + outputs.addLast(buf); + } while (len0 ==INFLATE_BUFSIZE); + } byte [] blen = castIntByte(len); outputs.addFirst(blen); } @@ -590,7 +602,10 @@ readFully(len,0,4); byte inputData[] = new byte[dataLen-20]; readFully(inputData); - unzip(inflater, inputData, bufs); + LinkedListinputs = new LinkedList(); + inputs.add(len); + inputs.add(inputData); + unzip(inflater, inputs, bufs); bufs.addFirst(header); multicastqueue.put(bufs); is.reset(); @@ -678,6 +693,36 @@ return ret; } + + @Test + public void test1() { + try { + LinkedList in = new LinkedList(); + LinkedList out = new LinkedList(); + LinkedList out2 = new LinkedList(); + for(int i=0;i<10;i++) { + in.add("test1".getBytes()); + in.add("test1".getBytes()); + in.add("test1".getBytes()); + in.add("test1".getBytes()); + } + int len = 0; + for(byte[] b: in) len += b.length; + in.addFirst(castIntByte(len)); + + Deflater deflater = new Deflater(); + zip(deflater, in,out); + unzip(inflater, out, out2); + for(byte[] b:out) { + byte []c = out2.poll(); + assertEquals(b,c); + } + System.out.println("Test Ok."); + } catch (Exception e) { + assertEquals(0,1); + } + } + } diff -r a8c33757ac99 -r 9b3b1e3e7db5 src/myVncProxy/RfbProto.java --- a/src/myVncProxy/RfbProto.java Wed Aug 03 08:33:55 2011 +0900 +++ b/src/myVncProxy/RfbProto.java Wed Aug 03 09:09:39 2011 +0900 @@ -223,6 +223,10 @@ timeWaitedIn100us = 5; timedKbits = 0; } + + public RfbProto() { + + }