1 36 package org.columba.ristretto.message.io; 37 38 import java.io.IOException ; 39 import java.util.Random ; 40 41 import junit.framework.TestCase; 42 43 import org.columba.ristretto.io.MemBuffer; 44 import org.columba.ristretto.io.MemBufferInputStream; 45 46 52 public class MemBufferInputStreamTest extends TestCase { 53 54 public void testInputSingle() throws IOException { 55 byte[] input = new byte[123]; 56 new Random ().nextBytes(input); 57 58 MemBuffer buffer = new MemBuffer(input.length); 59 buffer.append(input); 60 61 MemBufferInputStream in = new MemBufferInputStream( buffer ); 62 int i; 63 for( i=0; in.available() > 0; i++) { 64 assertEquals( input[i], in.read()); 65 } 66 67 assertEquals( input.length, i); 68 } 69 70 public void testInputArray() throws IOException { 71 byte[] input = new byte[123]; 72 new Random ().nextBytes(input); 73 74 MemBuffer buffer = new MemBuffer(input.length); 75 buffer.append(input); 76 77 MemBufferInputStream in = new MemBufferInputStream( buffer ); 78 79 byte[] test = new byte[50]; 80 int alreadyRead = 0; 81 int read = in.read(test); 82 83 while( read != -1) { 84 for( int i=0; i<read; i++) { 85 assertEquals( input[alreadyRead + i], test[i]); 86 } 87 alreadyRead += read; 88 read = in.read(test); 89 } 90 91 assertEquals( input.length, alreadyRead); 92 } 93 94 95 } 96 | Popular Tags |