| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- 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<String> expected = Arrays.asList("0x0");
- List<Long> numbers = Arrays.asList(0x0L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testArbitrarySingleByte() {
- List<String> expected = Arrays.asList("0x40");
- List<Long> numbers = Arrays.asList(0x40L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testLargestSingleByte() {
- List<String> expected = Arrays.asList("0x7f");
- List<Long> numbers = Arrays.asList(0x7fL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testSmallestDoubleByte() {
- List<String> expected = Arrays.asList("0x81", "0x0");
- List<Long> numbers = Arrays.asList(0x80L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testArbitraryDoubleByte() {
- List<String> expected = Arrays.asList("0xc0", "0x0");
- List<Long> numbers = Arrays.asList(0x2000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testLargestDoubleByte() {
- List<String> expected = Arrays.asList("0xff", "0x7f");
- List<Long> numbers = Arrays.asList(0x3fffL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testSmallestTripleByte() {
- List<String> expected = Arrays.asList("0x81", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x4000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testArbitraryTripleByte() {
- List<String> expected = Arrays.asList("0xc0", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x100000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testLargestTripleByte() {
- List<String> expected = Arrays.asList("0xff", "0xff", "0x7f");
- List<Long> numbers = Arrays.asList(0x1fffffL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testSmallestQuadrupleByte() {
- List<String> expected = Arrays.asList("0x81", "0x80", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x200000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testArbitraryQuadrupleByte() {
- List<String> expected = Arrays.asList("0xc0", "0x80", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x8000000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testLargestQuadrupleByte() {
- List<String> expected = Arrays.asList("0xff", "0xff", "0xff", "0x7f");
- List<Long> numbers = Arrays.asList(0xfffffffL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testSmallestQuintupleByte() {
- List<String> expected = Arrays.asList("0x81", "0x80", "0x80", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x10000000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testArbitraryQuintupleByte() {
- List<String> expected = Arrays.asList("0x8f", "0xf8", "0x80", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0xff000000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testMaximum32BitIntegerInput() {
- List<String> expected = Arrays.asList("0x8f", "0xff", "0xff", "0xff", "0x7f");
- List<Long> numbers = Arrays.asList(0xffffffffL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testTwoSingleByteValues() {
- List<String> expected = Arrays.asList("0x40", "0x7f");
- List<Long> numbers = Arrays.asList(0x40L, 0x7fL);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testTwoMultiByteValues() {
- List<String> expected = Arrays.asList("0x81", "0x80", "0x0", "0xc8", "0xe8", "0x56");
- List<Long> numbers = Arrays.asList(0x4000L, 0x123456L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testManyMultiByteValues() {
- List<String> expected = Arrays.asList("0xc0", "0x0", "0xc8", "0xe8",
- "0x56", "0xff", "0xff", "0xff",
- "0x7f", "0x0", "0xff", "0x7f",
- "0x81", "0x80", "0x0");
- List<Long> numbers = Arrays.asList(0x2000L, 0x123456L, 0xfffffffL,
- 0x0L, 0x3fffL, 0x4000L);
-
- assertEquals(expected, variableLengthQuantity.encode(numbers));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testDecodeOneByte() {
- List<String> expected = Arrays.asList("0x7f");
- List<Long> bytes = Arrays.asList(0x7fL);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testDecodeTwoBytes() {
- List<String> expected = Arrays.asList("0x2000");
- List<Long> bytes = Arrays.asList(0xc0L, 0x0L);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testDecodeThreeBytes() {
- List<String> expected = Arrays.asList("0x1fffff");
- List<Long> bytes = Arrays.asList(0xffL, 0xffL, 0x7fL);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testDecodeFourBytes() {
- List<String> expected = Arrays.asList("0x200000");
- List<Long> bytes = Arrays.asList(0x81L, 0x80L, 0x80L, 0x0L);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testDecodeMaximum32BitInteger() {
- List<String> expected = Arrays.asList("0xffffffff");
- List<Long> bytes = Arrays.asList(0x8fL, 0xffL, 0xffL, 0xffL, 0x7fL);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
-
- @Ignore("Remove to run test")
- @Test
- public void testCannotDecodeIncompleteSequence() {
- List<Long> 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<Long> 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<String> expected = Arrays.asList("0x2000", "0x123456",
- "0xfffffff", "0x0", "0x3fff",
- "0x4000");
- List<Long> bytes = Arrays.asList(0xc0L, 0x0L, 0xc8L, 0xe8L, 0x56L,
- 0xffL, 0xffL, 0xffL, 0x7fL, 0x0L,
- 0xffL, 0x7fL, 0x81L, 0x80L, 0x0L);
-
- assertEquals(expected, variableLengthQuantity.decode(bytes));
- }
- }
|