/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.yura.lobby.util;
import java.util.UUID;
import net.yura.lobby.util.ByteInputStream;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
/**
*
* @author Administrator
*/
public class ByteInputStreamTest {
public ByteInputStreamTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Test
public void testUUID() {
System.out.println( UUID.randomUUID() );
}
@Test
public void testRead() {
System.out.println("testRead");
ByteInputStream in = new ByteInputStream();
in.addBytes(new byte[]{43,19});
in.addBytes(new byte[]{12,15,22});
in.addBytes(new byte[]{41,11});
assertEquals(7, in.available()); assertEquals(43, in.read());
assertEquals(6, in.available()); assertEquals(19, in.read());
assertEquals(5, in.available()); assertEquals(12, in.read());
assertEquals(4, in.available()); assertEquals(15, in.read());
assertEquals(3, in.available()); assertEquals(22, in.read());
assertEquals(2, in.available()); assertEquals(41, in.read());
assertEquals(1, in.available()); assertEquals(11, in.read());
assertEquals(0, in.available()); assertEquals(-1, in.read());
}
@Test
public void testSkip() {
System.out.println("testSkip");
ByteInputStream in = new ByteInputStream();
in.addBytes(new byte[]{43,19});
in.addBytes(new byte[]{12,15,22});
in.addBytes(new byte[]{41,11});
assertEquals(7, in.available()); assertEquals(1, in.skip(1));
assertEquals(6, in.available()); assertEquals(1, in.skip(1));
assertEquals(5, in.available()); assertEquals(1, in.skip(1));
assertEquals(4, in.available()); assertEquals(1, in.skip(1));
assertEquals(3, in.available()); assertEquals(1, in.skip(1));
assertEquals(2, in.available()); assertEquals(1, in.skip(1));
assertEquals(1, in.available()); assertEquals(1, in.skip(1));
assertEquals(0, in.available()); assertEquals(0, in.skip(1));
in.addBytes(new byte[]{43,19});
assertEquals(2, in.available()); assertEquals(43, in.read());
assertEquals(1, in.available()); assertEquals(19, in.read());
assertEquals(0, in.available()); assertEquals(-1, in.read());
in.addBytes(new byte[]{43,19});
in.addBytes(new byte[]{12,15,22});
in.addBytes(new byte[]{41,11});
assertEquals(7, in.available()); assertEquals(43, in.read());
assertEquals(6, in.available()); assertEquals(5, in.skip(5));
assertEquals(1, in.available()); assertEquals(11, in.read());
assertEquals(0, in.available()); assertEquals(-1, in.read());
}
}