private void testSetFloat(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { buff.setFloat(i * 4, (float) i); } for (int i = 0; i < numSets; i++) { assertEquals((float) i, buff.getFloat(i * 4)); } }
@Test public void testGetFloat() throws Exception { int numFloats = 100; Buffer b = new Buffer(numFloats * 4); for (int i = 0; i < numFloats; i++) { b.setFloat(i * 4, i); } for (int i = 0; i < numFloats; i++) { assertEquals((float) i, b.getFloat(i * 4)); } }
@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 } }