Exemplo n.º 1
0
  @Test
  public void testGetAndSetUnsignedInt() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    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, buf.getUnsignedIntAt(0));
    assertEquals(4000000000L, buf.getUnsignedIntAt(4));

    assertEquals(buf.position(), 20);
  }
Exemplo n.º 2
0
 @Test(expected = IndexOutOfBoundsException.class)
 public void testGetAndSetGetUnsignedIntAtException4() {
   DynamicByteBuffer buf = new DynamicByteBuffer();
   buf.getUnsignedIntAt(128);
 }