import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; public class VariableLengthQuantityTest { @Rule public ExpectedException expectedException = ExpectedException.none(); private VariableLengthQuantity variableLengthQuantity; @Before public void setup() { variableLengthQuantity = new VariableLengthQuantity(); } @Test public void testZero() { List expected = Arrays.asList("0x0"); List numbers = Arrays.asList(0x0L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testArbitrarySingleByte() { List expected = Arrays.asList("0x40"); List numbers = Arrays.asList(0x40L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testLargestSingleByte() { List expected = Arrays.asList("0x7f"); List numbers = Arrays.asList(0x7fL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testSmallestDoubleByte() { List expected = Arrays.asList("0x81", "0x0"); List numbers = Arrays.asList(0x80L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testArbitraryDoubleByte() { List expected = Arrays.asList("0xc0", "0x0"); List numbers = Arrays.asList(0x2000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testLargestDoubleByte() { List expected = Arrays.asList("0xff", "0x7f"); List numbers = Arrays.asList(0x3fffL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testSmallestTripleByte() { List expected = Arrays.asList("0x81", "0x80", "0x0"); List numbers = Arrays.asList(0x4000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testArbitraryTripleByte() { List expected = Arrays.asList("0xc0", "0x80", "0x0"); List numbers = Arrays.asList(0x100000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testLargestTripleByte() { List expected = Arrays.asList("0xff", "0xff", "0x7f"); List numbers = Arrays.asList(0x1fffffL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testSmallestQuadrupleByte() { List expected = Arrays.asList("0x81", "0x80", "0x80", "0x0"); List numbers = Arrays.asList(0x200000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testArbitraryQuadrupleByte() { List expected = Arrays.asList("0xc0", "0x80", "0x80", "0x0"); List numbers = Arrays.asList(0x8000000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testLargestQuadrupleByte() { List expected = Arrays.asList("0xff", "0xff", "0xff", "0x7f"); List numbers = Arrays.asList(0xfffffffL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testSmallestQuintupleByte() { List expected = Arrays.asList("0x81", "0x80", "0x80", "0x80", "0x0"); List numbers = Arrays.asList(0x10000000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testArbitraryQuintupleByte() { List expected = Arrays.asList("0x8f", "0xf8", "0x80", "0x80", "0x0"); List numbers = Arrays.asList(0xff000000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testMaximum32BitIntegerInput() { List expected = Arrays.asList("0x8f", "0xff", "0xff", "0xff", "0x7f"); List numbers = Arrays.asList(0xffffffffL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testTwoSingleByteValues() { List expected = Arrays.asList("0x40", "0x7f"); List numbers = Arrays.asList(0x40L, 0x7fL); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testTwoMultiByteValues() { List expected = Arrays.asList("0x81", "0x80", "0x0", "0xc8", "0xe8", "0x56"); List numbers = Arrays.asList(0x4000L, 0x123456L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testManyMultiByteValues() { List expected = Arrays.asList("0xc0", "0x0", "0xc8", "0xe8", "0x56", "0xff", "0xff", "0xff", "0x7f", "0x0", "0xff", "0x7f", "0x81", "0x80", "0x0"); List numbers = Arrays.asList(0x2000L, 0x123456L, 0xfffffffL, 0x0L, 0x3fffL, 0x4000L); assertEquals(expected, variableLengthQuantity.encode(numbers)); } @Ignore("Remove to run test") @Test public void testDecodeOneByte() { List expected = Arrays.asList("0x7f"); List bytes = Arrays.asList(0x7fL); assertEquals(expected, variableLengthQuantity.decode(bytes)); } @Ignore("Remove to run test") @Test public void testDecodeTwoBytes() { List expected = Arrays.asList("0x2000"); List bytes = Arrays.asList(0xc0L, 0x0L); assertEquals(expected, variableLengthQuantity.decode(bytes)); } @Ignore("Remove to run test") @Test public void testDecodeThreeBytes() { List expected = Arrays.asList("0x1fffff"); List bytes = Arrays.asList(0xffL, 0xffL, 0x7fL); assertEquals(expected, variableLengthQuantity.decode(bytes)); } @Ignore("Remove to run test") @Test public void testDecodeFourBytes() { List expected = Arrays.asList("0x200000"); List bytes = Arrays.asList(0x81L, 0x80L, 0x80L, 0x0L); assertEquals(expected, variableLengthQuantity.decode(bytes)); } @Ignore("Remove to run test") @Test public void testDecodeMaximum32BitInteger() { List expected = Arrays.asList("0xffffffff"); List bytes = Arrays.asList(0x8fL, 0xffL, 0xffL, 0xffL, 0x7fL); assertEquals(expected, variableLengthQuantity.decode(bytes)); } @Ignore("Remove to run test") @Test public void testCannotDecodeIncompleteSequence() { List bytes = Arrays.asList(0xffL); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Invalid variable-length quantity encoding"); variableLengthQuantity.decode(bytes); } @Ignore("Remove to run test") @Test public void testCannotDecodeIncompleteSequenceEvenIfValueIsZero() { List bytes = Arrays.asList(0x80L); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Invalid variable-length quantity encoding"); variableLengthQuantity.decode(bytes); } @Ignore("Remove to run test") @Test public void testDecodeMultipleBytes() { List expected = Arrays.asList("0x2000", "0x123456", "0xfffffff", "0x0", "0x3fff", "0x4000"); List bytes = Arrays.asList(0xc0L, 0x0L, 0xc8L, 0xe8L, 0x56L, 0xffL, 0xffL, 0xffL, 0x7fL, 0x0L, 0xffL, 0x7fL, 0x81L, 0x80L, 0x0L); assertEquals(expected, variableLengthQuantity.decode(bytes)); } }