Esempio n. 1
0
 @Test
 public void testPassFloats() {
   Pointer<Byte> out = allocateBytes(8);
   for (int value : intValues) {
     passVarArgs(out, false, (float) value);
     assertEquals(value, out.getDouble(), 0);
   }
 }
Esempio n. 2
0
 @Test
 public void testPassBytes() {
   Pointer<Byte> out = allocateBytes(8);
   for (int value : intValues) {
     passVarArgs(out, true, (byte) value);
     assertEquals(value, out.getSizeT());
   }
 }
Esempio n. 3
0
 @Test
 public void testPassBools() {
   Pointer<Byte> out = allocateBytes(8);
   for (boolean value : new boolean[] {true, false}) {
     passVarArgs(out, true, value);
     assertEquals(value, out.getSizeT() != 0);
   }
 }
Esempio n. 4
0
 @Test
 public void testSPrintf() {
   Pointer<Byte> dest = allocateBytes(100);
   String fmtString = "Hello %d !";
   int value = 10;
   sprintf(dest, pointerToCString(fmtString), value);
   assertEquals(String.format(fmtString, value), dest.getCString());
 }
Esempio n. 5
0
  /**
   * Issue 37 : BridJ: org.bridj.Pointer#iterator for native-allocated pointers is empty
   * http://code.google.com/p/nativelibs4java/issues/detail?id=37
   */
  @Test
  public void emptyIteratorFromUnmanagedPointer() {
    Pointer<Byte> ptr = allocateBytes(10);
    assertTrue(!ptr.asList().isEmpty());
    assertTrue(ptr.iterator().next() != null);

    Pointer<Byte> unmanaged = pointerToAddress(ptr.getPeer()).as(Byte.class);
    assertTrue(!unmanaged.asList().isEmpty());
    assertTrue(unmanaged.iterator().next() != null);
  }
Esempio n. 6
0
  /**
   * Issue 47: Pointer#pointerToAddress(long, Class, Releaser) does not use releaser argument
   * http://code.google.com/p/nativelibs4java/issues/detail?id=37
   */
  @Test
  public void usePointerReleaser() {
    final boolean[] released = new boolean[1];
    Pointer<Integer> p = allocateInt();
    long address = p.getPeer();

    {
      Pointer pp = pointerToAddress(address);
      assertEquals(address, pp.getPeer());
    }

    {
      Pointer pp = pointerToAddress(address, 123);
      assertEquals(address, pp.getPeer());
      assertEquals(123, pp.getValidBytes());
    }

    Releaser releaser =
        new Releaser() {
          // @Override
          public void release(Pointer<?> p) {
            released[0] = true;
          }
        };

    {
      released[0] = false;
      Pointer pp = pointerToAddress(address, Integer.class, releaser);
      assertEquals(address, pp.getPeer());
      assertEquals(Integer.class, pp.getTargetType());
      pp.release();
      assertEquals(true, released[0]);
    }

    {
      Pointer pp = pointerToAddress(address, PointerIO.getIntInstance());
      assertEquals(address, pp.getPeer());
      assertEquals(Integer.class, pp.getTargetType());
    }

    {
      released[0] = false;
      Pointer pp = pointerToAddress(address, PointerIO.getIntInstance(), releaser);
      assertEquals(address, pp.getPeer());
      assertEquals(Integer.class, pp.getTargetType());
      pp.release();
      assertEquals(true, released[0]);
    }

    {
      released[0] = false;
      Pointer pp = pointerToAddress(address, releaser);
      assertEquals(address, pp.getPeer());
      pp.release();
      assertEquals(true, released[0]);
    }

    {
      released[0] = false;
      Pointer pp = pointerToAddress(address, 123, releaser);
      assertEquals(address, pp.getPeer());
      assertEquals(123, pp.getValidBytes());
      pp.release();
      assertEquals(true, released[0]);
    }

    {
      Pointer pp = pointerToAddress(address, Integer.class);
      assertEquals(address, pp.getPeer());
      assertEquals(Integer.class, pp.getTargetType());
    }

    {
      Pointer pp = pointerToAddress(address, 123, PointerIO.getIntInstance());
      assertEquals(address, pp.getPeer());
      assertEquals(123, pp.getValidBytes());
      assertEquals(Integer.class, pp.getTargetType());
    }
  }