Example #1
0
  @Test
  public void testGetAndSetUnsigned() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    buf.putUnsigned(0);
    buf.putUnsigned(255);
    buf.putUnsigned(256);
    buf.putUnsigned(-1);
    buf.flip();

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

    assertEquals(0, buf.getUnsigned());
    assertEquals(255, buf.getUnsigned());
    assertEquals(0, buf.getUnsigned());
    assertEquals(255, buf.getUnsigned());

    assertEquals(buf.position(), 4);

    buf.putUnsignedAt(0, 121);
    buf.putUnsignedAt(1, 122);
    assertEquals(121, buf.getUnsignedAt(0));
    assertEquals(122, buf.getUnsignedAt(1));

    assertEquals(buf.position(), 4);
  }
Example #2
0
  /*
   * Unsigned Medium Int tests
   */
  @Test
  public void testGetAndSetMediumInt() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    buf.putUnsigned(0x12);
    buf.putUnsigned(0x34);
    buf.putUnsigned(0x56);

    buf.flip();

    assertEquals(0x123456, buf.getUnsignedMediumInt());
  }
Example #3
0
  @SuppressWarnings("deprecation")
  @Test
  public void testGetAndSetMediumInt2() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    buf.order(java.nio.ByteOrder.LITTLE_ENDIAN);

    buf.putUnsigned(0x12);
    buf.putUnsigned(0x34);
    buf.putUnsigned(0x56);

    buf.flip();

    assertEquals(0x563412, buf.getUnsignedMediumInt());
  }
Example #4
0
 @Test(expected = BufferOverflowException.class)
 public void testGetAndSetPutUnsignedException() {
   DynamicByteBuffer buf = DynamicByteBuffer.allocate(0);
   buf.setAutoExpand(false);
   buf.putUnsigned(121);
 }