示例#1
0
 private void testSetDouble(Buffer buff) throws Exception {
   for (int i = 0; i < numSets; i++) {
     buff.setDouble(i * 8, (double) i);
   }
   for (int i = 0; i < numSets; i++) {
     assertEquals((double) i, buff.getDouble(i * 8));
   }
 }
示例#2
0
  @Test
  public void testGetDouble() throws Exception {
    int numDoubles = 100;
    Buffer b = new Buffer(numDoubles * 8);
    for (int i = 0; i < numDoubles; i++) {
      b.setDouble(i * 8, i);
    }

    for (int i = 0; i < numDoubles; i++) {
      assertEquals((double) i, b.getDouble(i * 8));
    }
  }
示例#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
    }
  }