swig/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java
William S Fulton 54e2317b24 Fix shared_ptr of classes with private constructors and destructors.
Usually these use a custom deleter passed to the shared_ptr.
This also fixes the "unref" feature when used on classes with private destructors.
2015-05-14 19:03:06 +01:00

34 lines
1.1 KiB
Java

import li_boost_shared_ptr_bits.*;
public class li_boost_shared_ptr_bits_runme {
static {
try {
System.loadLibrary("li_boost_shared_ptr_bits");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
VectorIntHolder v = new VectorIntHolder();
v.add(new IntHolder(11));
v.add(new IntHolder(22));
v.add(new IntHolder(33));
int sum = li_boost_shared_ptr_bits.sum(v);
if (sum != 66)
throw new RuntimeException("sum is wrong");
HiddenDestructor hidden = HiddenDestructor.create();
hidden.delete();
HiddenPrivateDestructor hiddenPrivate = HiddenPrivateDestructor.create();
if (HiddenPrivateDestructor.getDeleteCount() != 0)
throw new RuntimeException("Count should be zero");
hiddenPrivate.delete();
if (HiddenPrivateDestructor.getDeleteCount() != 1)
throw new RuntimeException("Count should be one");
}
}