static String hex(long v) { return Long.toHexString(v); /* String s = Long.toString(v, 16); while ((s.length() < 16)) s = "0" + s; return s;*/ }
public static void testNativeTargetCallbacks() { long rawadder = getAdder_raw(); if (rawadder != 0) System.out.println( "Returned non null raw adder, cool (" + Long.toHexString(rawadder) + ") !"); else System.out.println("Returned null raw adder !"); long longadder = getAdder_long(); if (longadder != 0) System.out.println( "Returned non null longadder, cool (" + Long.toHexString(longadder) + ") !"); else System.out.println("Returned null longadder !"); long getAdder_pvoid = getAdder_pvoid(); if (getAdder_pvoid != 0) System.out.println( "Returned non null getAdder_pvoid, cool (" + Long.toHexString(getAdder_pvoid) + ") !"); else System.out.println("Returned null getAdder_pvoid !"); Pointer<org.bridj.demos.TestCPP.MyCallback> ptr = getAdder(); if (ptr == null) throw new RuntimeException("getAdder returned null adder !!!"); MyCallback adder = ptr.getNativeObject(MyCallback.class); int res = adder.doSomething(1, 2); if (res != 3) throw new RuntimeException("Expected 3, got " + res); }
private String ptrToString(Pointer<?> ptr, NativeLibrary library) { return ptr == null ? "null" : Long.toHexString(ptr.getPeer()) + " (" + library.getSymbolName(ptr.getPeer()) + ")"; }