1 36 package org.columba.ristretto.message.io; 37 38 import java.util.Random ; 39 40 import junit.framework.TestCase; 41 42 import org.columba.ristretto.io.MemBuffer; 43 44 50 public class MemBufferTest extends TestCase { 51 52 public void testInputSingle() { 53 MemBuffer buffer = new MemBuffer(); 54 55 byte[] input = new byte[2050]; 56 new Random ().nextBytes(input); 57 58 for( int i=0; i<input.length; i++) { 59 assertEquals( i, buffer.size()); 60 buffer.append(input[i]); 61 assertEquals( input[i], buffer.get(i)); 62 assertEquals( i+1, buffer.size()); 63 } 64 } 65 66 67 public void testInputArray() { 68 MemBuffer buffer = new MemBuffer(); 69 70 byte[] input = new byte[2050]; 71 new Random ().nextBytes(input); 72 73 buffer.append(input); 74 assertEquals( input.length, buffer.size()); 75 76 byte[] test = new byte[2050]; 77 assertEquals( 2000, buffer.get(50, test)); 78 assertEquals( input[50], test[0]); 79 80 81 assertEquals( 2050, buffer.get(0, test) ); 82 83 for( int i=0; i<input.length; i++) { 84 assertEquals( input[i], test[i]); 85 } 86 } 87 88 } 89 | Popular Tags |