1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: TestByteBufferSource.java,v 1.3 2003/01/23 01:23:40 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.io.impl; 23 24 import junit.framework.*; 25 import juju.reattore.io.impl.ByteBufferSource; 26 import juju.reattore.io.Source; 27 import java.nio.ByteBuffer; 28 29 public class TestByteBufferSource 30 extends TestCase { 31 32 private ByteBufferSource ss; 33 private ByteBuffer bb; 34 35 private void populate() { 36 bb = ByteBuffer.allocate(512); 37 38 bb.put(new byte[] { 5, 6, 7, -1, 3 } ); 39 bb.flip(); 40 41 ss = new ByteBufferSource(bb); 42 } 43 44 public void testGet() { 45 populate(); 46 47 assertEquals(5, ss.get()); 48 assertEquals(6, ss.get()); 49 assertEquals(7, ss.get()); 50 assertEquals(-1, ss.get()); 51 assertEquals(3, ss.get()); 52 assertEquals(Source.EOF, ss.get()); 53 } 54 55 public void testBulkGet() { 56 populate(); 57 58 byte[] ab = new byte[ss.remaining()]; 59 assertEquals(ab.length, ss.get(ab, 0, ab.length)); 60 61 int idx = 0; 62 assertEquals(5, ab[idx++]); 63 assertEquals(6, ab[idx++]); 64 assertEquals(7, ab[idx++]); 65 assertEquals(-1, ab[idx++]); 66 assertEquals(3, ab[idx++]); 67 } 68 69 public void testRemaining() { 70 populate(); 71 72 assertEquals(5, ss.remaining()); 73 ss.get(); 74 ss.get(); 75 assertEquals(3, ss.remaining()); 76 } 77 78 /*** @see TestSuite */ 79 public static Test suite() { 80 return new TestSuite(TestByteBufferSource.class); 81 } 82 }

This page was automatically generated by Maven