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.MemBufferInputStream; 44 import org.columba.ristretto.io.MemBufferOutputStream; 45 46 52 public class MemBufferOutputStreamTest extends TestCase { 53 54 public void testIOArray() throws IOException { 55 MemBufferOutputStream out = new MemBufferOutputStream(); 56 57 byte[] input = new byte[123]; 58 new Random ().nextBytes(input); 59 60 MemBufferInputStream in = new MemBufferInputStream(out.getBuffer()); 61 62 out.write(input); 63 64 byte[] test = new byte[1024]; 65 66 int read = in.read(test); 67 assertEquals( input.length, read); 68 69 for( int i=0; i<read; i++) { 70 assertEquals( input[i], test[i]); 71 } 72 } 73 74 public void testIOSingle() throws IOException { 75 MemBufferOutputStream out = new MemBufferOutputStream(); 76 77 byte[] input = new byte[123]; 78 new Random ().nextBytes(input); 79 80 MemBufferInputStream in = new MemBufferInputStream(out.getBuffer()); 81 int test; 82 83 for( int i=0; i<input.length; i++) { 84 out.write( input[i] ); 85 assertEquals( 1, in.available()); 86 87 test = in.read(); 88 assertEquals( input[i], test); 89 assertEquals( -1, in.read()); 90 } 91 } 92 93 94 } 95 | Popular Tags |