Exemplo n.º 1
0
 private void testSetLong(Buffer buff) throws Exception {
   for (int i = 0; i < numSets; i++) {
     buff.setLong(i * 8, i);
   }
   for (int i = 0; i < numSets; i++) {
     assertEquals(i, buff.getLong(i * 8));
   }
 }
Exemplo n.º 2
0
  @Test
  public void testGetLong() throws Exception {
    int numLongs = 100;
    Buffer b = new Buffer(numLongs * 8);
    for (int i = 0; i < numLongs; i++) {
      b.setLong(i * 8, i);
    }

    for (int i = 0; i < numLongs; i++) {
      assertEquals(i, b.getLong(i * 8));
    }
  }
Exemplo n.º 3
0
  @Test
  public void testGetOutOfBounds() throws Exception {
    int bytesLen = 100;
    byte[] bytes = TestUtils.generateRandomByteArray(bytesLen);

    Buffer b = new Buffer(bytes);
    try {
      b.getByte(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getByte(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getByte(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getByte(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getByte(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getInt(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getInt(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getInt(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getInt(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getInt(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getLong(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getLong(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getLong(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getLong(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getLong(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getFloat(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getFloat(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getFloat(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getFloat(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getFloat(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getDouble(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getDouble(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getDouble(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getDouble(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getDouble(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getShort(bytesLen);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getShort(bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getShort(bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getShort(-1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getShort(-100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }

    try {
      b.getBytes(bytesLen + 1, bytesLen + 1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getBytes(bytesLen + 100, bytesLen + 100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getBytes(-1, -1);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      b.getBytes(-100, -100);
      fail();
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }