Esempio n. 1
0
 @Test
 public void testFloatGetPut() {
   // free up any references from other tests
   JNIMemoryManager.getMgr().flush();
   float[] in = new float[] {0x38, 0x2C, 0x18, 0x7F};
   float[] out = new float[in.length];
   Buffer buf = Buffer.make(null, 1024);
   buf.put(in, 0, 0, in.length);
   buf.get(0, out, 0, in.length);
   for (int i = 0; i < in.length; i++) assertEquals("mismatched bytes at " + i, in[i], out[i]);
   buf.delete();
   assertEquals(
       "more objects around than expected", 0, JNIMemoryManager.getMgr().getNumPinnedObjects());
 }
Esempio n. 2
0
  @Test
  public void testGetInvalidArgs() {
    Buffer buf = Buffer.make(null, 1);

    byte[] in = new byte[] {0x38, 0x2C};
    byte[] out = new byte[] {0x53, 0x7C};
    try {
      buf.put(in, 0, 0, 2);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(0, out, 0, 2);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.put(in, -1, 0, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(-1, out, 0, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.put(in, 0, -1, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(0, out, -1, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.put(in, 0, 1, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(0, out, 3, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.put(in, 3, 0, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(1, out, 0, 1);
      fail("should fail on 2 bytes");
    } catch (IndexOutOfBoundsException e) {
    }
    buf.put(in, 0, 0, 1);
    buf.get(0, out, 0, 1);
    assertEquals(in[0], out[0]);
    assertNotSame(in[1], out[1]);

    buf.delete();
  }