Пример #1
0
  @Test
  public void testGetAndSetUnsignedInt() throws Exception {
    WrappedByteBuffer buf = new WrappedByteBuffer();
    long MAX_UNSIGNED_INT = 4294967295L;

    buf.putUnsignedInt(MAX_UNSIGNED_INT);
    buf.putUnsignedInt(1);
    buf.putUnsignedInt(0);
    buf.putUnsignedInt(-1);
    buf.putUnsignedInt(MAX_UNSIGNED_INT + 1);

    assertEquals(buf.position(), 20);

    buf.flip();

    assertEquals(buf.position(), 0);
    assertEquals(buf.limit(), 20);

    assertEquals("test 1", MAX_UNSIGNED_INT, buf.getUnsignedInt());
    assertEquals("test 2", 1L, buf.getUnsignedInt());
    assertEquals("test 3", 0L, buf.getUnsignedInt());
    assertEquals("test 4", MAX_UNSIGNED_INT, buf.getUnsignedInt());
    assertEquals("test 5", 0L, buf.getUnsignedInt());

    assertEquals(buf.position(), 20);

    buf.putUnsignedIntAt(0, 121);
    buf.putUnsignedIntAt(4, 4000000000L);
    assertEquals(121L, (long) buf.getUnsignedIntAt(0));
    assertEquals(4000000000L, (long) buf.getUnsignedIntAt(4));

    assertEquals(buf.position(), 20);
  }
Пример #2
0
 @Test(expected = BufferOverflowException.class)
 public void testGetAndSetPutUnsignedIntException() throws Exception {
   WrappedByteBuffer buf = WrappedByteBuffer.allocate(0);
   buf.setAutoExpand(false);
   buf.putUnsignedInt(121);
 }