Exemplo n.º 1
0
  /*
   * Short Tests
   */
  @Test
  public void testGetAndSetShort() throws Exception {
    DynamicByteBuffer buf = new DynamicByteBuffer();
    buf.putShort((short) 0);
    buf.putShort((short) 1);
    buf.putShort((short) 32767);
    buf.putShort((short) -32768);
    buf.flip();

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

    assertEquals((short) 0, buf.getShort());
    assertEquals((short) 1, buf.getShort());
    assertEquals((short) 32767, buf.getShort());
    assertEquals((short) -32768, buf.getShort());

    assertEquals(buf.position(), 8);

    buf.putShortAt(0, (short) 121);
    buf.putShortAt(2, (short) 1000);
    assertEquals((short) 121, buf.getShortAt(0));
    assertEquals((short) 1000, buf.getShortAt(2));

    assertEquals(buf.position(), 8);
  }
Exemplo n.º 2
0
 @Test
 public void testGetAndSetShorts() throws Exception {
   // tests reallocation of buffer automatically.
   DynamicByteBuffer buf = DynamicByteBuffer.allocate(2);
   buf.putShort((short) 1);
   buf.putShort((short) 2);
   buf.putShort((short) 3);
   buf.putShort((short) 4);
   buf.putShort((short) 5);
   buf.flip();
   assertEquals((short) 1, buf.getShort());
   assertEquals((short) 1, buf.getShortAt(0));
   assertEquals((short) 2, buf.getShortAt(2));
   assertEquals((short) 3, buf.getShortAt(4));
   assertEquals((short) 2, buf.getShort());
   assertEquals((short) 3, buf.getShort());
   assertEquals((short) 4, buf.getShort());
   assertEquals((short) 5, buf.getShort());
 }
Exemplo n.º 3
0
 @Test(expected = IndexOutOfBoundsException.class)
 public void testGetAndSetGetShortAtException4() {
   DynamicByteBuffer buf = new DynamicByteBuffer();
   buf.getShortAt(128);
 }