changeset 88:9b3b1e3e7db5

add test routine
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 03 Aug 2011 09:09:39 +0900
parents a8c33757ac99
children 43822a70978c
files .classpath src/myVncProxy/MyRfbProto.java src/myVncProxy/RfbProto.java
diffstat 3 files changed, 60 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Wed Aug 03 08:33:55 2011 +0900
+++ b/.classpath	Wed Aug 03 09:09:39 2011 +0900
@@ -2,5 +2,6 @@
 <classpath>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
--- 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<Socket>();
@@ -565,16 +574,19 @@
 	 *            byte data[]
 	 * @throws IOException
 	 */
-	public void unzip(Inflater inflater, byte[] input, LinkedList<byte[]> outputs)
-			throws DataFormatException {
+	public void unzip(Inflater inflater, LinkedList<byte[]> inputs, LinkedList<byte[]> 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);
+				LinkedList<byte[]>inputs = new LinkedList<byte[]>();
+				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<byte[]> in = new LinkedList<byte[]>();
+			LinkedList<byte[]> out = new LinkedList<byte[]>();
+			LinkedList<byte[]> out2 = new LinkedList<byte[]>();
+			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);
+		}
+	}
+
 }
 
 
--- 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() {
+		
+	}