コード例 #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);
   }
 }
コード例 #2
0
 @Test
 public void testPassBytes() {
   Pointer<Byte> out = allocateBytes(8);
   for (int value : intValues) {
     passVarArgs(out, true, (byte) value);
     assertEquals(value, out.getSizeT());
   }
 }
コード例 #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);
   }
 }
コード例 #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());
 }
コード例 #5
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());
    }
  }
コード例 #6
0
 /** Issue 295 : wchar_t broken on MacOS X https://github.com/ochafik/nativelibs4java/issues/295 */
 @Test
 public void testWideCharReadout() {
   assertEquals("1234567890", getSomeWString().getWideCString());
 }