Mercurial > hg > Members > nobuyasu > tightVNCProxy
diff src/myVncProxy/MyRfbProto.java @ 92:aa7df396e04d
Test on going
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 11:40:18 +0900 |
parents | 4116c19cd76e |
children | 40c22e507655 |
line wrap: on
line diff
--- 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<ByteBuffer> inputs, LinkedList<ByteBuffer> 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<ByteBuffer> in1 = clone(in); Deflater deflater = new Deflater(); zip(deflater, in,out); + // LinkedList<ByteBuffer> 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<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); + zip(deflater,out2,out4); + LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); + unzip(inflater,out4,out5); + equalByteBuffers(in1,out5); + System.out.println("Test Ok."); } catch (Exception e) { assertEquals(0,1); } } + private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) { + LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>(); + for(ByteBuffer b: in) { + ByteBuffer c = b.duplicate(); + copy.add(c); + } + return copy; + } + + public void equalByteBuffers(LinkedList<ByteBuffer> in, + LinkedList<ByteBuffer> 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(); + } + } + }