Merge branch 'master' into doxygen

This commit is contained in:
Vadim Zeitlin 2018-03-19 21:54:46 +01:00
commit b7f78dd5a7
232 changed files with 5648 additions and 2419 deletions

View file

@ -47,6 +47,10 @@ CPP_TEST_CASES = \
# li_boost_intrusive_ptr
CPP11_TEST_CASES = \
cpp11_shared_ptr_const \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
cpp11_strongly_typed_enumerations_simple \
DOXYGEN_TEST_CASES := \

View file

@ -22,7 +22,7 @@ public class class_scope_namespace_runme {
F f = new F();
G g = new G();
H.HH h = new H.HH();
I.II i = new I.II();
I_.II i = new I_.II();
J j = new J();
K k = new K();
L l = new L();

View file

@ -0,0 +1,60 @@
import cpp11_shared_ptr_overload.*;
public class cpp11_shared_ptr_overload_runme {
static {
try {
System.loadLibrary("cpp11_shared_ptr_overload");
} 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[])
{
String ret = null;
// ref
ret = cpp11_shared_ptr_overload.UseA(new MyType("123"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseA fail:" + ret);
ret = cpp11_shared_ptr_overload.UseB(0, new MyType("123"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseB fail:" + ret);
ret = cpp11_shared_ptr_overload.UseC(0, new MyType("123"), new MyType("456"));
if (!ret.equals("123 ref")) throw new RuntimeException("UseC fail:" + ret);
// sharedptr
ret = cpp11_shared_ptr_overload.UseX(new MyType("123"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseX fail:" + ret);
ret = cpp11_shared_ptr_overload.UseY(0, new MyType("123"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseY fail:" + ret);
ret = cpp11_shared_ptr_overload.UseZ(0, new MyType("123"), new MyType("456"));
if (!ret.equals("123 sharedptr")) throw new RuntimeException("UseZ fail:" + ret);
// Combo1-4
ret = cpp11_shared_ptr_overload.Combo1(new MyType("XXX"));
if (!ret.equals("XXXCombo1")) throw new RuntimeException("Combo1 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo2(new MyType("XXX"));
if (!ret.equals("XXXCombo2")) throw new RuntimeException("Combo2 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo3(new MyType("XXX"));
if (!ret.equals("XXXCombo3")) throw new RuntimeException("Combo3 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo4(new MyType("XXX"));
if (!ret.equals("XXXCombo4")) throw new RuntimeException("Combo4 fail:" + ret);
// Combo5-7
ret = cpp11_shared_ptr_overload.Combo5(new MyType("XXX"));
if (!ret.equals("XXXCombo5")) throw new RuntimeException("Combo5 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo6(new MyType("XXX"));
if (!ret.equals("XXXCombo6")) throw new RuntimeException("Combo6 fail:" + ret);
ret = cpp11_shared_ptr_overload.Combo7(new MyType("XXX"));
if (!ret.equals("XXXCombo7")) throw new RuntimeException("Combo7 fail:" + ret);
}
}

View file

@ -16,6 +16,7 @@ Expected output if PrintDebug enabled:
Base - Val(444.555)
Base - Ref(444.555)
Base - Ptr(444.555)
Base - ConstPtrRef(444.555)
Base - FullyOverloaded(int 10)
Base - FullyOverloaded(bool 1)
Base - SemiOverloaded(int -678)
@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1)
Derived - Val(444.555)
Derived - Ref(444.555)
Derived - Ptr(444.555)
Derived - ConstPtrRef(444.555)
Derived - FullyOverloaded(int 10)
Derived - FullyOverloaded(bool 1)
Derived - SemiOverloaded(int -678)
@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1)
JavaDerived - Val(444.555)
JavaDerived - Ref(444.555)
JavaDerived - Ptr(444.555)
JavaDerived - ConstPtrRef(444.555)
JavaDerived - FullyOverloaded(int 10)
JavaDerived - FullyOverloaded(bool True)
JavaDerived - SemiOverloaded(-678)
@ -67,7 +70,7 @@ public class director_classes_runme {
void run()
{
if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------ ");
if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------");
Caller myCaller = new Caller();
@ -96,7 +99,7 @@ public class director_classes_runme {
myBase.delete();
}
if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------ ");
if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------");
}
void makeCalls(Caller myCaller, Base myBase)
@ -111,6 +114,7 @@ public class director_classes_runme {
if (myCaller.ValCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.RefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.PtrCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
if (myCaller.ConstPtrRefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed");
// Fully overloaded method test (all methods in base class are overloaded)
if (!myCaller.FullyOverloadedCall(10).equals(baseSimpleName + "::FullyOverloaded(int)")) {
@ -170,6 +174,11 @@ class JavaDerived extends Base
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - Ptr(" + x.getVal() + ")");
return x;
}
public DoubleHolder ConstPtrRef(DoubleHolder x)
{
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - ConstPtrRef(" + x.getVal() + ")");
return x;
}
public String FullyOverloaded(int x)
{
if (director_classes.getPrintDebug()) System.out.println("JavaDerived - FullyOverloaded(int " + x + ")");

View file

@ -0,0 +1,35 @@
import director_exception_catches.*;
public class director_exception_catches_runme {
static {
try {
System.loadLibrary("director_exception_catches");
} 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[]) {
BaseClass b = new director_exception_catches_MyClass();
try {
String s = BaseClass.call_description(b);
throw new RuntimeException("Failed to catch exception");
} catch (NullPointerException e) {
if (!e.getMessage().startsWith("Testing exception thrown in BaseClass.description"))
throw new RuntimeException("Unexpected exception message: " + e.getMessage());
}
}
}
class director_exception_catches_MyClass extends BaseClass {
@Override
public String description() {
throw new NullPointerException("Testing exception thrown in BaseClass.description");
}
}

View file

@ -0,0 +1,42 @@
import director_ownership.*;
public class director_ownership_runme {
static {
try {
System.loadLibrary("director_ownership");
} 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 set_content_and_release(Container container, ContentBase content) {
content.swigReleaseOwnership();
container.set_content(content);
}
public static void main(String argv[]) {
Container container = new Container();
// make a content in java (cMemoryOwn true)
ContentBase content_java = new ContentDerived();
// make a content in c++ (cMemoryOwn true)
ContentBase content_cpp = director_ownership.make_content();
set_content_and_release(container, content_java);
if (!container.get_content().get_name().equals("ContentDerived"))
throw new RuntimeException("did not get ContentDerived");
// when swigReleaseOwnership() is called on content_cpp, swig tries a static_cast to director and calls the method
// director->swig_java_change_ownership. The content created in c++ native library is not a director, therefore a
// segfault may occur.
// With a check done using dynamic_cast this issue could be avoided.
set_content_and_release(container, content_cpp);
if (!container.get_content().get_name().equals("ContentDerived"))
throw new RuntimeException("did not get ContentDerived");
}
}

View file

@ -126,19 +126,28 @@ public class java_director_exception_feature_nspace_runme {
try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); }
catch (MyJavaException1 e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(2); fail("No exception thrown in genericpong(2)");}
catch (java_director_exception_feature_nspace_NewCheckedException e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(3); fail("No exception thrown in genericpong(3)");}
catch (java_director_exception_feature_nspace_NewUncheckedException e) {
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_nspace_MyFooDirectorImpl.genericpong(java_director_exception_feature_nspace_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(4); fail("No exception thrown in genericpong(4)");}
catch (RuntimeException e) {
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException");
failif( ! java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RuntimeException");
failif( ! "Unspecified DirectorException message".equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
}
}
catch (Exception e) {

View file

@ -127,19 +127,28 @@ public class java_director_exception_feature_runme {
try { b.genericpong(1); fail("No exception thrown in genericpong(1)"); }
catch (MyJavaException1 e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(2); fail("No exception thrown in genericpong(2)");}
catch (NewCheckedException e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(3); fail("No exception thrown in genericpong(3)");}
catch (NewUncheckedException e) {
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP3.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
StackTraceElement[] st = e.getStackTrace();
failif( st.length != 5, "Stack length is only " + st.length);
failif( ! st[0].toString().startsWith("java_director_exception_feature_MyFooDirectorImpl.genericpong(java_director_exception_feature_runme.java:"), "Incorrect top of stack: " + st[0]);
}
try { b.genericpong(4); fail("No exception thrown in genericpong(4)");}
catch (RuntimeException e) {
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RumtimeException");
failif( ! java_director_exception_feature_Consts.GENERICPONGEXCP4.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
failif ( e.getClass() != RuntimeException.class, "Exception " + e + " is not exactly RuntimeException");
failif( ! "Unspecified DirectorException message".equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'");
}
}

View file

@ -93,6 +93,28 @@ public class java_throws_runme {
if (!pass)
throw new RuntimeException("Test 6 failed");
// Interface function
pass = false;
try {
InterfaceTestImpl iti = new InterfaceTestImpl();
iti.imethod(true);
}
catch (MyException e) { pass = true; }
if (!pass)
throw new RuntimeException("Test interface 1 failed");
pass = false;
try {
InterfaceTestImpl iti = new InterfaceTestImpl();
iti.imethod(false);
pass = true;
}
catch (MyException e) { pass = false; }
if (!pass)
throw new RuntimeException("Test interface 2 failed");
// Global function
pass = false;
try {

View file

@ -1,60 +1,129 @@
public class li_boost_shared_ptr_runme {
import li_boost_shared_ptr_director.*;
public class li_boost_shared_ptr_director_runme {
static {
try {
System.loadLibrary("li_boost_shared_ptr");
System.loadLibrary("li_boost_shared_ptr_director");
} 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);
}
}
private static void check(String got, String expected) {
if (!got.equals(expected))
private static void check(int got, int expected) {
if (got != expected)
throw new RuntimeException("Failed, got: " + got + " expected: " + expected);
}
public static void main(String argv[]) {
li_boost_shared_ptr_director_Derived a = li_boost_shared_ptr_director_Derived.new(false);
li_boost_shared_ptr_director_Derived b = li_boost_shared_ptr_director_Derived.new(true);
li_boost_shared_ptr_director_Derived a = new li_boost_shared_ptr_director_Derived(false);
li_boost_shared_ptr_director_Derived b = new li_boost_shared_ptr_director_Derived(true);
check(call_ret_c_shared_ptr(a) == 1);
check(call_ret_c_shared_ptr(b) == -1);
check(call_ret_c_by_value(a) == 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(call_take_c_by_value(a) == 5);
check(call_take_c_shared_ptr_by_value(a) == 6);
check(call_take_c_shared_ptr_by_ref(a) == 7);
check(call_take_c_shared_ptr_by_pointer(a) == 8);
check(call_take_c_shared_ptr_by_pointer_ref(a) == 9);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
check(call_take_c_shared_ptr_by_value_with_null(a) == -2);
check(call_take_c_shared_ptr_by_ref_with_null(a) == -3);
check(call_take_c_shared_ptr_by_pointer_with_null(a) == -4);
check(call_take_c_shared_ptr_by_pointer_ref_with_null(a) == -5);
check(li_boost_shared_ptr_director.call_take_c_by_value(a), 5);
check(li_boost_shared_ptr_director.call_take_c_by_ref(a), 6);
check(li_boost_shared_ptr_director.call_take_c_by_pointer(a), 7);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref(a), 8);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value(a), 9);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref(a), 10);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer(a), 11);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref(a), 12);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_with_null(a), -2);
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref_with_null(a), -3);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value_with_null(a), -4);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref_with_null(a), -5);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_with_null(a), -6);
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
}
}
class li_boost_shared_ptr_director_Derived extends li_boost_shared_ptr_director.Base {
class li_boost_shared_ptr_director_Derived extends Base {
@Override
public String ping() {
return "li_boost_shared_ptr_director_MyBarFoo.ping()";
private boolean return_none;
li_boost_shared_ptr_director_Derived(boolean flag) {
super();
this.return_none = flag;
}
@Override
public String pong() {
return "li_boost_shared_ptr_director_MyBarFoo.pong();" + ping();
public C ret_c_shared_ptr() {
if (this.return_none)
return null;
else
return new C();
}
@Override
public String upcall(li_boost_shared_ptr_director.FooBar fooBarPtr) {
return "override;" + fooBarPtr.FooBarDo();
public C ret_c_by_value() {
return new C();
}
@Override
public li_boost_shared_ptr_director.Foo makeFoo() {
return new li_boost_shared_ptr_director.Foo();
public int take_c_by_value(C c) {
return c.get_m();
}
@Override
public int take_c_by_ref(C c) {
return c.get_m();
}
@Override
public int take_c_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -2;
}
@Override
public int take_c_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -3;
}
@Override
public int take_c_shared_ptr_by_value(C c) {
if (c != null)
return c.get_m();
else
return -4;
}
@Override
public int take_c_shared_ptr_by_ref(C c) {
if (c != null)
return c.get_m();
else
return -5;
}
@Override
public int take_c_shared_ptr_by_pointer(C c) {
if (c != null)
return c.get_m();
else
return -6;
}
@Override
public int take_c_shared_ptr_by_pointer_ref(C c) {
if (c != null)
return c.get_m();
else
return -7;
}
}

View file

@ -0,0 +1,57 @@
import template_class_reuse_name.*;
public class template_class_reuse_name_runme {
static {
try {
System.loadLibrary("template_class_reuse_name");
} 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[])
{
new Bool1().tt();
new Bool1False().ff();
new Bool2().tt();
new Bool2False().ff();
new Bool3().tt();
new Bool3False().ff();
new Bool4().tt();
new Bool4False().ff();
new BoolForward1().tt();
new BoolForward1False().ff();
new BoolForward2().tt();
new BoolForward2False().ff();
new BoolForward3().tt();
new BoolForward3False().ff();
new BoolForward4().tt();
new BoolForward4False().ff();
new IntBool1().tt();
new IntBool1False().ff();
new IntBool2().tt();
new IntBool2False().ff();
new IntBool3().tt();
new IntBool3False().ff();
new IntBool4().tt();
new IntBool4False().ff();
new Duplicate2_0().n();
new Duplicate3().n();
}
}

View file

@ -23,10 +23,10 @@ public class template_partial_specialization_runme {
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new M().m();
new N().n();
new BB().b();
new BBB().b();

View file

@ -23,10 +23,10 @@ public class template_partial_specialization_typedef_runme {
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new M().m();
new N().n();
new BB().b();
new BBB().b();

View file

@ -0,0 +1,26 @@
import typedef_classforward_same_name.*;
public class typedef_classforward_same_name_runme {
static {
try {
System.loadLibrary("typedef_classforward_same_name");
} 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[]) {
Foo foo = new Foo();
foo.setX(5);
if (typedef_classforward_same_name.extractFoo(foo) != 5)
throw new RuntimeException("unexpected value");
Boo boo = new Boo();
boo.setX(5);
if (typedef_classforward_same_name.extractBoo(boo) != 5)
throw new RuntimeException("unexpected value");
}
}