Пример #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
 public boolean isValid() {
   Pointer<Integer> pCount = allocateInt();
   int err;
   try {
     err = clIcdGetPlatformIDsKHR(0, null, pCount);
   } catch (Throwable th) {
     try {
       err = clGetPlatformIDs(0, null, pCount);
     } catch (Throwable th2) {
       return false;
     }
   }
   return err == OpenCLLibrary.CL_SUCCESS && pCount.get() > 0;
 }
Пример #6
0
  /** Lists all available OpenCL implementations. */
  public static CLPlatform[] listPlatforms() {
    Pointer<Integer> pCount = allocateInt();
    error(getPlatformIDs(0, null, pCount));

    int nPlats = pCount.get();
    if (nPlats == 0) return new CLPlatform[0];

    Pointer<cl_platform_id> ids = allocateTypedPointers(cl_platform_id.class, nPlats);

    error(getPlatformIDs(nPlats, ids, null));
    CLPlatform[] platforms = new CLPlatform[nPlats];

    for (int i = 0; i < nPlats; i++) {
      platforms[i] = new CLPlatform(ids.get(i));
    }
    return platforms;
  }
Пример #7
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);
  }
Пример #8
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());
    }
  }