mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
VarIntTest: add test for reading and writing
This commit is contained in:
parent
21fae58bc8
commit
140912b080
1 changed files with 17 additions and 0 deletions
|
@ -21,7 +21,11 @@ import junitparams.Parameters;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
@RunWith(JUnitParamsRunner.class)
|
@RunWith(JUnitParamsRunner.class)
|
||||||
public class VarIntTest {
|
public class VarIntTest {
|
||||||
|
@ -62,6 +66,19 @@ public class VarIntTest {
|
||||||
assertEquals(value, VarInt.ofBytes(a.encode(), 0).longValue());
|
assertEquals(value, VarInt.ofBytes(a.encode(), 0).longValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Parameters(method = "longTestVectors")
|
||||||
|
public void writeThenRead(long value, int size) {
|
||||||
|
VarInt varInt = VarInt.of(value);
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(varInt.getSizeInBytes());
|
||||||
|
varInt.write(buf);
|
||||||
|
assertFalse(buf.hasRemaining());
|
||||||
|
((Buffer) buf).rewind();
|
||||||
|
VarInt varIntCopy = VarInt.read(buf);
|
||||||
|
assertFalse(buf.hasRemaining());
|
||||||
|
assertEquals(varInt, varIntCopy);
|
||||||
|
}
|
||||||
|
|
||||||
private Object[] integerTestVectors() {
|
private Object[] integerTestVectors() {
|
||||||
return new Object[]{
|
return new Object[]{
|
||||||
new Object[]{ 0, 1},
|
new Object[]{ 0, 1},
|
||||||
|
|
Loading…
Add table
Reference in a new issue