Merge branch 'master' into doxygen

Merge with ~3.0.1 sources from master.
This commit is contained in:
Vadim Zeitlin 2014-04-30 18:37:57 +02:00
commit 1ebd2334b8
45 changed files with 53108 additions and 29452 deletions

View file

@ -3,8 +3,8 @@
#######################################################################
LANGUAGE = java
JAVA = java
JAVAC = javac
JAVA = @JAVA@
JAVAC = @JAVAC@
JAVAFLAGS = -Xcheck:jni
SCRIPTSUFFIX = _runme.java
srcdir = @srcdir@
@ -27,10 +27,14 @@ CPP_TEST_CASES = \
intermediary_classname \
java_constants \
java_director \
java_director_assumeoverride \
java_director_exception_feature \
java_director_exception_feature_nspace \
java_enums \
java_jnitypes \
java_lib_arrays_dimensionless \
java_lib_various \
java_jnitypes \
java_nspacewithoutpackage \
java_pgcpp \
java_pragmas \
java_prepost \
@ -43,12 +47,16 @@ include $(srcdir)/../common.mk
# Overridden variables here
JAVA_PACKAGE = $*
SWIGOPT += -package $(JAVA_PACKAGE)
JAVA_PACKAGEOPT = -package $(JAVA_PACKAGE)
SWIGOPT += $(JAVA_PACKAGEOPT)
# Custom tests - tests with additional commandline options
java_nspacewithoutpackage.%: JAVA_PACKAGEOPT =
java_director_exception_feature_nspace.%: JAVA_PACKAGE = $*Package
nspace.%: JAVA_PACKAGE = $*Package
nspace_extend.%: JAVA_PACKAGE = $*Package
director_nspace.%: JAVA_PACKAGE = $*Package
director_nspace_director_name_collision.%: JAVA_PACKAGE = $*Package
# Rules for the different types of tests
%.cpptest:
@ -69,9 +77,9 @@ director_nspace.%: JAVA_PACKAGE = $*Package
# Makes a directory for the testcase if it does not exist
setup = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \
else \
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \
fi; \
if [ ! -d $(JAVA_PACKAGE) ]; then \
mkdir $(JAVA_PACKAGE); \

View file

@ -1,6 +1,6 @@
See ../README for common README file.
The Java implementation of the test-suite is a little different to the other languages in that all of SWIGs output goes into a subdirectory named after the individual test case. This is so that all the shadow classes can be compiled as Java classes have to go into separate files. Otherwise the Makefile wouldn't know which .java files would be relevant to the testcase. For this to work the testcase must go into a Java package.
The Java implementation of the test-suite is a little different to the other languages in that all of SWIG's output goes into a subdirectory named after the individual test case. This is so that all the shadow classes can be compiled as Java classes which have to go into separate files. Otherwise the Makefile wouldn't know which .java files would be relevant to the testcase. For this to work the testcase must go into a Java package.
Any testcases which have _runme.java appended after the testcase name will be detected and run.

View file

@ -0,0 +1,33 @@
import cpp11_constexpr.*;
public class cpp11_constexpr_runme {
static {
try {
System.loadLibrary("cpp11_constexpr");
} 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(int received, int expected) {
if (expected != received)
throw new RuntimeException("check failed, expected: " + expected + " received: " + received);
}
public static void main(String argv[])
{
check(cpp11_constexpr.getAAA(), 10);
check(cpp11_constexpr.getBBB(), 20);
check(cpp11_constexpr.CCC(), 30);
check(cpp11_constexpr.DDD(), 40);
ConstExpressions ce = new ConstExpressions();
check(ce.JJJ, 100);
check(ce.KKK, 200);
check(ce.LLL, 300);
check(ce.MMM(), 400);
check(ce.NNN(), 500);
}
}

View file

@ -0,0 +1,28 @@
import cpp11_lambda_functions.*;
public class cpp11_lambda_functions_runme {
static {
try {
System.loadLibrary("cpp11_lambda_functions");
} 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(int received, int expected) {
if (expected != received)
throw new RuntimeException("check failed, expected: " + expected + " received: " + received);
}
public static void main(String argv[])
{
check(cpp11_lambda_functions.runLambda1(), 11);
check(cpp11_lambda_functions.runLambda2(), 11);
check(cpp11_lambda_functions.runLambda3(), 11);
check(cpp11_lambda_functions.runLambda4(), 11);
check(cpp11_lambda_functions.runLambda5(), 1);
check(cpp11_lambda_functions.runLambda5(), 2);
}
}

View file

@ -0,0 +1,24 @@
import cpp11_result_of.*;
public class cpp11_result_of_runme {
static {
try {
System.loadLibrary("cpp11_result_of");
} 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[])
{
double result = cpp11_result_of.test_result(cpp11_result_ofConstants.SQUARE, 3.0);
if (result != 9.0)
throw new RuntimeException("test_result(square, 3.0) is not 9.0. Got: " + Double.toString(result));
result = cpp11_result_of.test_result_alternative1(cpp11_result_ofConstants.SQUARE, 3.0);
if (result != 9.0)
throw new RuntimeException("test_result_alternative1(square, 3.0) is not 9.0. Got: " + Double.toString(result));
}
}

View file

@ -0,0 +1,51 @@
import cpp11_thread_local.*;
public class cpp11_thread_local_runme {
static {
try {
System.loadLibrary("cpp11_thread_local");
} 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[])
{
if (ThreadLocals.getStval() != 11)
throw new RuntimeException();
if (ThreadLocals.getTsval() != 22)
throw new RuntimeException();
if (ThreadLocals.tscval99 != 99)
throw new RuntimeException();
cpp11_thread_local.setEtval(-11);
if (cpp11_thread_local.getEtval() != -11)
throw new RuntimeException();
cpp11_thread_local.setStval(-22);
if (cpp11_thread_local.getStval() != -22)
throw new RuntimeException();
cpp11_thread_local.setTsval(-33);
if (cpp11_thread_local.getTsval() != -33)
throw new RuntimeException();
cpp11_thread_local.setEtval(-44);
if (cpp11_thread_local.getEtval() != -44)
throw new RuntimeException();
cpp11_thread_local.setTeval(-55);
if (cpp11_thread_local.getTeval() != -55)
throw new RuntimeException();
cpp11_thread_local.setEctval(-55);
if (cpp11_thread_local.getEctval() != -55)
throw new RuntimeException();
cpp11_thread_local.setEcpptval(-66);
if (cpp11_thread_local.getEcpptval() != -66)
throw new RuntimeException();
}
}

View file

@ -0,0 +1,29 @@
import curiously_recurring_template_pattern.*;
public class curiously_recurring_template_pattern_runme {
static {
try {
System.loadLibrary("curiously_recurring_template_pattern");
} 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[]) {
Derived d = new Derived();
d.setBase1Param(1).setDerived1Param(10).setDerived2Param(20).setBase2Param(2);
if (d.getBase1Param() != 1)
throw new RuntimeException("fail");
if (d.getDerived1Param() != 10)
throw new RuntimeException("fail");
if (d.getBase2Param() != 2)
throw new RuntimeException("fail");
if (d.getDerived2Param() != 20)
throw new RuntimeException("fail");
}
}

View file

@ -0,0 +1,22 @@
import derived_nested.*;
public class derived_nested_runme {
static {
try {
System.loadLibrary("derived_nested");
} 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[]) {
BB outer = new BB();
BB.DD d = new BB.DD();
BB.EE e = new BB.EE();
outer.getFf_instance().setZ(outer.getFf_instance().getX());
outer.useEE(e);
}
}

View file

@ -21,6 +21,11 @@ public class director_binary_string_runme {
if (sum != 9*2*8 + 13*3*5)
throw new RuntimeException("Unexpected sum: " + sum);
new Callback().run(null, null);
callback = new DirectorBinaryStringCallback();
caller.setCallback(callback);
caller.call_null();
}
}
@ -32,11 +37,13 @@ class DirectorBinaryStringCallback extends Callback {
@Override
public void run(byte[] dataBufferAA, byte[] dataBufferBB)
{
for (int i = 0; i < dataBufferAA.length; i++)
dataBufferAA[i] = (byte)(dataBufferAA[i] * 2);
if (dataBufferAA != null)
for (int i = 0; i < dataBufferAA.length; i++)
dataBufferAA[i] = (byte)(dataBufferAA[i] * 2);
for (int i = 0; i < dataBufferBB.length; i++)
dataBufferBB[i] = (byte)(dataBufferBB[i] * 3);
if (dataBufferBB != null)
for (int i = 0; i < dataBufferBB.length; i++)
dataBufferBB[i] = (byte)(dataBufferBB[i] * 3);
}
}

View file

@ -19,7 +19,7 @@ public class director_nspace_runme {
}
class director_nspace_MyBarFoo extends director_nspacePackage.Bar.Foo {
class director_nspace_MyBarFoo extends director_nspacePackage.TopLevel.Bar.Foo {
@Override
public String ping() {
@ -32,17 +32,17 @@ class director_nspace_MyBarFoo extends director_nspacePackage.Bar.Foo {
}
@Override
public String fooBar(director_nspacePackage.Bar.FooBar fooBar) {
public String fooBar(director_nspacePackage.TopLevel.Bar.FooBar fooBar) {
return fooBar.FooBarDo();
}
@Override
public director_nspacePackage.Bar.Foo makeFoo() {
return new director_nspacePackage.Bar.Foo();
public director_nspacePackage.TopLevel.Bar.Foo makeFoo() {
return new director_nspacePackage.TopLevel.Bar.Foo();
}
@Override
public director_nspacePackage.Bar.FooBar makeFooBar() {
return new director_nspacePackage.Bar.FooBar();
public director_nspacePackage.TopLevel.Bar.FooBar makeFooBar() {
return new director_nspacePackage.TopLevel.Bar.FooBar();
}
}

View file

@ -0,0 +1,48 @@
// Make sure that directors are connected and disconnected when used inconjunction with
// being a smart pointer
public class director_smartptr_runme {
static {
try {
System.loadLibrary("director_smartptr");
} 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[]) {
director_smartptr_MyBarFoo myBarFoo =
new director_smartptr_MyBarFoo();
}
}
class director_smartptr_MyBarFoo extends director_smartptr.Foo {
@Override
public String ping() {
return "director_smartptr_MyBarFoo.ping();";
}
@Override
public String pong() {
return "director_smartptr_MyBarFoo.pong();" + ping();
}
@Override
public String fooBar(director_smartptr.FooBar fooBar) {
return fooBar.FooBarDo();
}
@Override
public director_smartptr.Foo makeFoo() {
return new director_smartptr.Foo();
}
@Override
public director_smartptr.FooBar makeFooBar() {
return new director_smartptr.FooBar();
}
}

View file

@ -22,8 +22,7 @@ public class dynamic_cast_runme {
// Note it is possible to downcast y with a Java cast.
String a = dynamic_cast.do_test((Bar)y);
if (!a.equals("Bar::test")) {
System.err.println("Failed!");
System.exit(1);
throw new RuntimeException("Failed!");
}
}
}

View file

@ -0,0 +1,33 @@
import enum_forward.*;
public class enum_forward_runme {
static {
try {
System.loadLibrary("enum_forward");
} 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[])
{
try {
ForwardEnum1 f1 = enum_forward.get_enum1();
f1 = enum_forward.test_function1(f1);
} catch (IllegalArgumentException e) {
}
try {
ForwardEnum2 f2 = enum_forward.get_enum2();
f2 = enum_forward.test_function2(f2);
} catch (IllegalArgumentException e) {
}
ForwardEnum3 f3 = enum_forward.get_enum3();
f3 = enum_forward.test_function3(f3);
}
}

View file

@ -0,0 +1,93 @@
import enum_macro.*;
public class enum_macro_runme {
static {
try {
System.loadLibrary("enum_macro");
} 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[])
{
{
Greeks1 a = Greeks1.alpha1;
a = Greeks1.beta1;
a = Greeks1.theta1;
if (a.swigValue() != 3)
throw new RuntimeException("Greeks1");
}
{
Greeks2 a = Greeks2.alpha2;
a = Greeks2.beta2;
a = Greeks2.theta2;
if (a.swigValue() != 4)
throw new RuntimeException("Greeks2");
}
{
Greeks3 a = Greeks3.alpha3;
a = Greeks3.beta3;
a = Greeks3.theta3;
if (a.swigValue() != 2)
throw new RuntimeException("Greeks3");
}
{
Greeks4 a = Greeks4.alpha4;
a = Greeks4.beta4;
a = Greeks4.theta4;
if (a.swigValue() != 6)
throw new RuntimeException("Greeks4");
}
{
Greeks5 a = Greeks5.alpha5;
a = Greeks5.beta5;
if (a.swigValue() != 1)
throw new RuntimeException("Greeks5");
}
{
Greeks6 a = Greeks6.alpha6;
a = Greeks6.beta6;
if (a.swigValue() != 1)
throw new RuntimeException("Greeks6");
}
{
Greeks7 a = Greeks7.alpha7;
a = Greeks7.beta7;
if (a.swigValue() != 1)
throw new RuntimeException("Greeks7");
}
{
Greeks8 a = Greeks8.theta8;
if (a.swigValue() != 0)
throw new RuntimeException("Greeks8");
}
{
Greeks9 a = Greeks9.theta9;
if (a.swigValue() != 0)
throw new RuntimeException("Greeks9");
}
{
Greeks10 a = Greeks10.theta10;
if (a.swigValue() != 0)
throw new RuntimeException("Greeks10");
}
{
Greeks11 a = Greeks11.theta11;
if (a.swigValue() != 0)
throw new RuntimeException("Greeks11");
}
{
Greeks12 a = Greeks12.theta12;
if (a.swigValue() != 0)
throw new RuntimeException("Greeks12");
}
{
Greeks13 a = null;
}
}
}

View file

@ -0,0 +1,25 @@
import extend_special_variables.*;
public class extend_special_variables_runme {
static {
try {
System.loadLibrary("extend_special_variables");
} 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[])
{
ForExtensionNewName f = new ForExtensionNewName();
verify(f.extended_renamed(), "name:extended symname:extended_renamed wrapname: overname:__SWIG_0 decl:ForExtension::extended() fulldecl:char const * ForExtension::extended() parentclasssymname:ForExtensionNewName parentclassname:ForExtension");
verify(f.extended_renamed(10), "name:extended symname:extended_renamed wrapname: overname:__SWIG_1 decl:ForExtension::extended(int) fulldecl:char const * ForExtension::extended(int) parentclasssymname:ForExtensionNewName parentclassname:ForExtension");
}
static void verify(String received, String expected) {
if (!received.equals(expected))
throw new RuntimeException("Incorrect, received: " + received);
}
}

View file

@ -16,16 +16,16 @@ public class ignore_parameter_runme {
{
// Compilation will ensure the number of arguments and type are correct.
// Then check the return value is the same as the value given to the ignored parameter.
if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { System.err.println("Runtime Error in jaguar()");}
if (ignore_parameter.lotus("fast", 0.0) != 101) { System.err.println("Runtime Error in lotus()");}
if (ignore_parameter.tvr("fast", 200) != 8.8) { System.err.println("Runtime Error in tvr()");}
if (ignore_parameter.ferrari() != 101) { System.err.println("Runtime Error in ferrari()");}
if (!ignore_parameter.jaguar(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in jaguar()");}
if (ignore_parameter.lotus("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in lotus()");}
if (ignore_parameter.tvr("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in tvr()");}
if (ignore_parameter.ferrari() != 101) { throw new RuntimeException("Runtime Error in ferrari()");}
SportsCars sc = new SportsCars();
if (!sc.daimler(200, 0.0).equals("hello")) { System.err.println("Runtime Error in daimler()");}
if (sc.astonmartin("fast", 0.0) != 101) { System.err.println("Runtime Error in astonmartin()");}
if (sc.bugatti("fast", 200) != 8.8) { System.err.println("Runtime Error in bugatti()");}
if (sc.lamborghini() != 101) { System.err.println("Runtime Error in lamborghini()");}
if (!sc.daimler(200, 0.0).equals("hello")) { throw new RuntimeException("Runtime Error in daimler()");}
if (sc.astonmartin("fast", 0.0) != 101) { throw new RuntimeException("Runtime Error in astonmartin()");}
if (sc.bugatti("fast", 200) != 8.8) { throw new RuntimeException("Runtime Error in bugatti()");}
if (sc.lamborghini() != 101) { throw new RuntimeException("Runtime Error in lamborghini()");}
// Check constructors are also generated correctly
MiniCooper mc = new MiniCooper(200, 0.0);

View file

@ -0,0 +1,27 @@
import java_director_assumeoverride.*;
public class java_director_assumeoverride_runme {
static {
try {
System.loadLibrary("java_director_assumeoverride");
} 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);
}
}
static class MyOverrideMe extends OverrideMe {
}
public static void main(String argv[]) {
OverrideMe overrideMe = new MyOverrideMe();
// MyOverrideMe doesn't actually override func(), but because assumeoverride
// was set to true, the C++ side will believe it was overridden.
if (!java_director_assumeoverride.isFuncOverridden(overrideMe)) {
throw new RuntimeException ( "isFuncOverridden()" );
}
}
}

View file

@ -0,0 +1,150 @@
import java_director_exception_feature_nspacePackage.*;
import java_director_exception_feature_nspacePackage.MyNS.*;
class java_director_exception_feature_nspace_Consts {
public static final String PINGEXCP1 = "Ping MyJavaException1"; // should get translated through an int on ping
public static final String PINGEXCP2 = "Ping MyJavaException2";
public static final String PONGEXCP1 = "Pong MyJavaException1";
public static final String PONGEXCP2 = "Pong MyJavaException2";
public static final String PONGUNEXPECTED = "Pong MyJavaUnexpected";
public static final String TRANSLATED_NPE = "Pong Translated NPE";
public static final String GENERICPONGEXCP1 = "GenericPong Wrapped MyJavaException1";
public static final String GENERICPONGEXCP2 = "GenericPong New Checked Exception";
public static final String GENERICPONGEXCP3 = "GenericPong New Unchecked Exception";
public static final String GENERICPONGEXCP4 = "GenericPong New Exception Without String ctor";
}
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
class java_director_exception_feature_nspace_NewCheckedException extends Exception {
public java_director_exception_feature_nspace_NewCheckedException(String s) {
super(s);
}
}
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
class java_director_exception_feature_nspace_NewUncheckedException extends RuntimeException {
public java_director_exception_feature_nspace_NewUncheckedException(String s) {
super(s);
}
}
// an exception not constructible from a string,
// to test DirectorException fallback reconstruction
class java_director_exception_feature_nspace_UnconstructibleException extends Exception {
private int extrastate;
public java_director_exception_feature_nspace_UnconstructibleException(int a, String s) {
super(s);
extrastate = a;
}
}
class java_director_exception_feature_nspace_MyFooDirectorImpl extends Foo {
public java_director_exception_feature_nspace_MyFooDirectorImpl() { };
@Override
public String ping(int excp) throws MyJavaException1, MyJavaException2 {
if (excp == 1) throw new MyJavaException1(java_director_exception_feature_nspace_Consts.PINGEXCP1);
if (excp == 2) throw new MyJavaException2(java_director_exception_feature_nspace_Consts.PINGEXCP2);
return "Ping director returned";
}
@Override
public String pong(int excp) throws MyJavaException1, MyJavaException2, MyJavaUnexpected {
if (excp == 1) throw new MyJavaException1(java_director_exception_feature_nspace_Consts.PONGEXCP1);
if (excp == 2) throw new MyJavaException2(java_director_exception_feature_nspace_Consts.PONGEXCP2);
if (excp == 3) throw new MyJavaUnexpected(java_director_exception_feature_nspace_Consts.PONGUNEXPECTED);
if (excp == 4) throw new java.lang.NullPointerException(java_director_exception_feature_nspace_Consts.TRANSLATED_NPE); // should be translated to ::Unexpected
return "Pong director returned";
}
@Override
public String genericpong(int excp) throws MyJavaException1, java_director_exception_feature_nspace_NewCheckedException, java_director_exception_feature_nspace_UnconstructibleException {
if (excp == 1)
throw new MyJavaException1(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP1);
if (excp == 2)
throw new java_director_exception_feature_nspace_NewCheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP2);
if (excp == 3)
throw new java_director_exception_feature_nspace_NewUncheckedException(java_director_exception_feature_nspace_Consts.GENERICPONGEXCP3);
if (excp == 4)
throw new java_director_exception_feature_nspace_UnconstructibleException(1, java_director_exception_feature_nspace_Consts.GENERICPONGEXCP4);
return "GenericPong director returned";
}
}
public class java_director_exception_feature_nspace_runme {
static {
try {
System.loadLibrary("java_director_exception_feature_nspace");
} 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 fail(String msg) {
System.err.println(msg); System.exit(1);
}
public static void failif(boolean cond, String msg) {
if (cond) fail(msg);
}
public static void main(String argv[]) {
Bar b = new Bar(new java_director_exception_feature_nspace_MyFooDirectorImpl());
try {
try { b.ping(0); } catch (Exception e)
{ fail("Exception should not have been thrown: " + e + " from ping(0)"); }
try { b.ping(1); fail("No exception thrown in ping(1)"); } catch (MyJavaException1 e)
// Should say "Threw some integer", see java_director_exception_feature.i Foo::ping throws a "1"
{ failif( ! "Threw some integer".equals(e.getMessage()), "Ping exception not translated through int: '" + e.getMessage() + "'"); }
try { b.ping(2); fail("No exception thrown in ping(2)"); } catch (MyJavaException2 e)
{ failif( ! java_director_exception_feature_nspace_Consts.PINGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(0); } catch (Exception e)
{ fail("Exception should not have been thrown: " + e + " from pong(0)"); }
try { b.pong(1); fail("No exception thrown in pong(1)"); } catch (MyJavaException1 e)
{ failif( ! java_director_exception_feature_nspace_Consts.PONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(2); fail("No exception thrown in pong(2)");} catch (MyJavaException2 e)
{ failif( ! java_director_exception_feature_nspace_Consts.PONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(3); fail("No exception thrown in pong(3)");} catch (MyJavaUnexpected e)
{ failif( ! java_director_exception_feature_nspace_Consts.PONGUNEXPECTED.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(4); fail("No exception thrown in pong(4)"); } catch (MyJavaUnexpected e)
{ failif( ! java_director_exception_feature_nspace_Consts.TRANSLATED_NPE.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.genericpong(0); }
catch (Exception e) {
fail("Exception should not have been thrown: " + e + " from genericpong(0)");
}
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() + "'");
}
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() + "'");
}
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() + "'");
}
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() + "'");
}
}
catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception thrown or exception not mapped properly");
}
}
}

View file

@ -0,0 +1,152 @@
import java_director_exception_feature.*;
class java_director_exception_feature_Consts {
public static final String PINGEXCP1 = "Ping MyJavaException1"; // should get translated through an int on ping
public static final String PINGEXCP2 = "Ping MyJavaException2";
public static final String PONGEXCP1 = "Pong MyJavaException1";
public static final String PONGEXCP2 = "Pong MyJavaException2";
public static final String PONGUNEXPECTED = "Pong MyJavaUnexpected";
public static final String TRANSLATED_NPE = "Pong Translated NPE";
public static final String GENERICPONGEXCP1 = "GenericPong Wrapped MyJavaException1";
public static final String GENERICPONGEXCP2 = "GenericPong New Checked Exception";
public static final String GENERICPONGEXCP3 = "GenericPong New Unchecked Exception";
public static final String GENERICPONGEXCP4 = "GenericPong New Exception Without String ctor";
}
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
class NewCheckedException extends Exception {
public NewCheckedException(String s) {
super(s);
}
}
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
class NewUncheckedException extends RuntimeException {
public NewUncheckedException(String s) {
super(s);
}
}
// an exception not constructable from a string,
// to test DirectorException fallback reconstruction
class UnconstructableException extends Exception {
private int extrastate;
public UnconstructableException(int a, String s) {
super(s);
extrastate = a;
}
}
class java_director_exception_feature_MyFooDirectorImpl extends Foo {
public java_director_exception_feature_MyFooDirectorImpl() { };
@Override
public String ping(int excp) throws MyJavaException1, MyJavaException2 {
if (excp == 1) throw new MyJavaException1(java_director_exception_feature_Consts.PINGEXCP1);
if (excp == 2) throw new MyJavaException2(java_director_exception_feature_Consts.PINGEXCP2);
return "Ping director returned";
}
@Override
public String pong(int excp) throws MyJavaException1, MyJavaException2, MyJavaUnexpected {
if (excp == 1) throw new MyJavaException1(java_director_exception_feature_Consts.PONGEXCP1);
if (excp == 2) throw new MyJavaException2(java_director_exception_feature_Consts.PONGEXCP2);
if (excp == 3) throw new MyJavaUnexpected(java_director_exception_feature_Consts.PONGUNEXPECTED);
if (excp == 4) throw new java.lang.NullPointerException(java_director_exception_feature_Consts.TRANSLATED_NPE); // should be translated to ::Unexpected
return "Pong director returned";
}
@Override
public String genericpong(int excp) throws MyJavaException1, NewCheckedException, UnconstructableException {
if (excp == 1)
throw new MyJavaException1(java_director_exception_feature_Consts.GENERICPONGEXCP1);
if (excp == 2)
throw new NewCheckedException(java_director_exception_feature_Consts.GENERICPONGEXCP2);
if (excp == 3)
throw new NewUncheckedException(java_director_exception_feature_Consts.GENERICPONGEXCP3);
if (excp == 4)
throw new UnconstructableException(1, java_director_exception_feature_Consts.GENERICPONGEXCP4);
return "GenericPong director returned";
}
}
public class java_director_exception_feature_runme {
static {
try {
System.loadLibrary("java_director_exception_feature");
} 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 fail(String msg) {
System.err.println(msg); System.exit(1);
}
public static void failif(boolean cond, String msg) {
if (cond) fail(msg);
}
public static void main(String argv[]) {
Bar b = new Bar(new java_director_exception_feature_MyFooDirectorImpl());
try {
try { b.ping(0); } catch (Exception e)
{ fail("Exception should not have been thrown: " + e + " from ping(0)"); }
try { b.ping(1); fail("No exception thrown in ping(1)"); } catch (MyJavaException1 e)
// Should say "Threw some integer", see java_director_exception_feature.i Foo::ping throws a "1"
{ failif( ! "Threw some integer".equals(e.getMessage()), "Ping exception not translated through int: '" + e.getMessage() + "'"); }
try { b.ping(2); fail("No exception thrown in ping(2)"); } catch (MyJavaException2 e)
{ failif( ! java_director_exception_feature_Consts.PINGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(0); } catch (Exception e)
{ fail("Exception should not have been thrown: " + e + " from pong(0)"); }
try { b.pong(1); fail("No exception thrown in pong(1)"); } catch (MyJavaException1 e)
{ failif( ! java_director_exception_feature_Consts.PONGEXCP1.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(2); fail("No exception thrown in pong(2)");} catch (MyJavaException2 e)
{ failif( ! java_director_exception_feature_Consts.PONGEXCP2.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(3); fail("No exception thrown in pong(3)");} catch (MyJavaUnexpected e)
{ failif( ! java_director_exception_feature_Consts.PONGUNEXPECTED.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.pong(4); fail("No exception thrown in pong(4)"); } catch (MyJavaUnexpected e)
{ failif( ! java_director_exception_feature_Consts.TRANSLATED_NPE.equals(e.getMessage()), "Expected exception has unexpected message: '" + e.getMessage() + "'"); }
try { b.genericpong(0); }
catch (Exception e) {
fail("Exception should not have been thrown: " + e + " from genericpong(0)");
}
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() + "'");
}
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() + "'");
}
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() + "'");
}
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() + "'");
}
}
catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception thrown or exception not mapped properly");
}
}
}

View file

@ -13,6 +13,16 @@ public class java_director_runme {
}
}
private static void WaitForGC()
{
System.gc();
System.runFinalization();
try {
java.lang.Thread.sleep(10);
} catch (java.lang.InterruptedException e) {
}
}
public static void main(String argv[]) {
QuuxContainer qc = createContainer();
@ -31,24 +41,21 @@ public class java_director_runme {
qc = null;
/* Watch qc get reaped, which causes the C++ object to delete
objects from the internal vector */
System.gc();
System.runFinalization();
// Give the finalizers a chance to run
try {
Thread.sleep(50);
} catch (InterruptedException e) {
{
int countdown = 500;
int expectedCount = 0;
while (true) {
WaitForGC();
if (--countdown == 0)
break;
if (Quux.instances() == expectedCount)
break;
};
int actualCount = Quux.instances();
if (actualCount != expectedCount)
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
}
/* Watch the Quux objects formerly in the QuuxContainer object
get reaped */
System.gc();
System.runFinalization();
instances = Quux.instances();
if (instances != 0)
throw new RuntimeException("Quux instances should be 0, actually " + instances);
/* Test Quux1's director disconnect method rename */
Quux1 quux1 = new Quux1("quux1");
if (quux1.disconnectMethodCalled)

Some files were not shown because too many files have changed in this diff Show more