# HG changeset patch # User Shinji KONO # Date 1312339218 -32400 # Node ID aa7df396e04defac083d7d59edca40918de56a98 # Parent 4116c19cd76ea50c5533e0b36bf887d69a2c2862 Test on going diff -r 4116c19cd76e -r aa7df396e04d src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 10:52:19 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 11:40:18 2011 +0900 @@ -534,7 +534,7 @@ public int zip(Deflater deflater,LinkedList inputs, LinkedList outputs) throws IOException { int len1=0,len = 0; deflater.reset(); - do { + while(inputs.size()>0) { ByteBuffer b1 = inputs.poll(); deflater.setInput(b1.array(),b1.position(),b1.limit()); if (inputs.size()==0) { @@ -549,7 +549,7 @@ len += len1; } } while (len1==INFLATE_BUFSIZE); - } while(inputs.size()>0); + } return len; } @@ -688,20 +688,59 @@ in.add(ByteBuffer.wrap("test3".getBytes())); in.add(ByteBuffer.wrap("test4".getBytes())); } + LinkedList in1 = clone(in); Deflater deflater = new Deflater(); zip(deflater, in,out); + // LinkedList out3 = clone(out); zipped result is depend on deflator's state unzip(inflater, out, out2); - for(ByteBuffer b:in) { - ByteBuffer c = out2.poll(); - assertEquals(b,c); - } + equalByteBuffers(in1, out2); + LinkedList out4 = new LinkedList(); + zip(deflater,out2,out4); + LinkedList out5 = new LinkedList(); + unzip(inflater,out4,out5); + equalByteBuffers(in1,out5); + System.out.println("Test Ok."); } catch (Exception e) { assertEquals(0,1); } } + private LinkedList clone(LinkedList in) { + LinkedList copy = new LinkedList(); + for(ByteBuffer b: in) { + ByteBuffer c = b.duplicate(); + copy.add(c); + } + return copy; + } + + public void equalByteBuffers(LinkedList in, + LinkedList out2) { + int k = 0; + ByteBuffer c = out2.get(k++); + c.mark(); + for(ByteBuffer b:in) { + b.mark(); + while(b.remaining()>0) { + if (c.remaining()==0) { + c.reset(); + if (k>=out2.size()) { + assertEquals(0,1); + return; + } + c = out2.get(k++); + c.mark(); + } + byte i = b.get(); + byte j = c.get(); + assertEquals(i,j); + } + b.reset(); + } + } + }