/* Reattore HTTP Server
Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: TestByteBufferSource.java,v 1.3 2003/01/23 01:23:40 michaelh Exp $
*/
package test.juju.reattore.io.impl;
import junit.framework.*;
import juju.reattore.io.impl.ByteBufferSource;
import juju.reattore.io.Source;
import java.nio.ByteBuffer;
public class TestByteBufferSource
extends TestCase {
private ByteBufferSource ss;
private ByteBuffer bb;
private void populate() {
bb = ByteBuffer.allocate(512);
bb.put(new byte[] { 5, 6, 7, -1, 3 } );
bb.flip();
ss = new ByteBufferSource(bb);
}
public void testGet() {
populate();
assertEquals(5, ss.get());
assertEquals(6, ss.get());
assertEquals(7, ss.get());
assertEquals(-1, ss.get());
assertEquals(3, ss.get());
assertEquals(Source.EOF, ss.get());
}
public void testBulkGet() {
populate();
byte[] ab = new byte[ss.remaining()];
assertEquals(ab.length, ss.get(ab, 0, ab.length));
int idx = 0;
assertEquals(5, ab[idx++]);
assertEquals(6, ab[idx++]);
assertEquals(7, ab[idx++]);
assertEquals(-1, ab[idx++]);
assertEquals(3, ab[idx++]);
}
public void testRemaining() {
populate();
assertEquals(5, ss.remaining());
ss.get();
ss.get();
assertEquals(3, ss.remaining());
}
/** @see TestSuite */
public static Test suite() {
return new TestSuite(TestByteBufferSource.class);
}
}