The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
1508 changed files with 125983 additions and 44037 deletions

View file

@ -0,0 +1,185 @@
abstract_inherit
abstract_inherit_ok
add_link
anonymous_arg
argout
arrayptr
arrays
arrays_global
arrays_global_twodim
arrays_scope
bool_default
casts
char_constant
class_ignore
constant_pointers
constover
constructor_exception
constructor_explicit
constructor_value
const_const
const_const_2
conversion
conversion_namespace
conversion_ns_template
cplusplus_throw
cpp_enum
cpp_enum_scope
cpp_namespace
cpp_nodefault
cpp_static
cpp_typedef
CVS
default_cast
default_constructor
default_ns
default_ref
defineop
defines
dynamic_cast
enum
enum_scope
enum_scope_template
enum_var
evil_diamond
evil_diamond_ns
evil_diamond_prop
explicit
extend_template
extend_template_ns
grouping
ignore_parameter
imports
import_nomodule
inherit_missing
java_constants
java_pragmas
java_throws
java_typemaps_proxy
java_typemaps_typewrapper
kind
lib_carrays
lib_cdata
lib_cmalloc
lib_constraints
lib_cpointer
lib_math
lib_std_deque
lib_std_string
lib_std_vector
lib_typemaps
long_long
macro_2
member_template
minherit
name
namespace_enum
namespace_extend
namespace_nested
namespace_template
namespace_typemap
name_cxx
name_inherit
nested
newobject1
newobject2
overload_complicated
overload_copy
overload_extend
overload_extendc
overload_simple
overload_subtype
overload_template
pointer_reference
preproc_1
preproc_2
preproc_3
primitive_ref
private_assign
pure_virtual
rename_default
rename_scope
return_value_scope
ret_by_value
rname
sizeof_pointer
smart_pointer_const
smart_pointer_multi
smart_pointer_multi_typedef
smart_pointer_not
smart_pointer_overload
smart_pointer_protected
smart_pointer_rename
smart_pointer_simple
smart_pointer_typedef
sneaky1
static_array_member
static_const_member
static_const_member_2
struct_value
template
template_arg_scope
template_arg_typename
template_base_template
template_classes
template_construct
template_const_ref
template_default
template_default2
template_default_inherit
template_default_qualify
template_enum
template_enum_ns_inherit
template_enum_typedef
template_forward
template_inherit
template_inherit_abstract
template_int_const
template_ns
template_ns2
template_ns3
template_ns4
template_ns_enum
template_ns_enum2
template_ns_inherit
template_ns_scope
template_qualifier
template_rename
template_retvalue
template_specialization
template_static
template_tbase_template
template_typedef
template_typedef_cplx
template_typedef_cplx2
template_typedef_cplx3
template_typedef_cplx4
template_typedef_import
template_type_namespace
template_virtual
template_whitespace
throw_exception
typedef_funcptr
typedef_inherit
typedef_mptr
typedef_reference
typedef_scope
typemap_namespace
typemap_ns_using
typemap_subst
typename
unions
union_scope
using1
using2
using_composition
using_extend
using_inherit
using_namespace
using_private
using_protected
valuewrapper_base
virtual_destructor
voidtest
*.class

View file

@ -0,0 +1,72 @@
#######################################################################
# $Header$
# Makefile for java test-suite
#######################################################################
LANGUAGE = java
SCRIPTSUFFIX = _runme.java
C_TEST_CASES = \
java_lib_arrays
CPP_TEST_CASES = \
java_constants \
java_jnitypes \
java_pragmas \
java_throws \
java_typemaps_proxy \
java_typemaps_typewrapper
include ../common.mk
# Overridden variables here
TOP = ../../..
SWIGOPT = -I$(TOP)/$(TEST_SUITE) -package $*
#Target prefix cannot be used on Windows
#TARGETPREFIX = lib
# Rules for the different types of tests
%.cpptest:
$(setup) \
(cd $*; $(swig_and_compile_cpp); ); \
$(run_testcase)
%.ctest:
$(setup) \
(cd $*; $(swig_and_compile_c); ); \
$(run_testcase)
%.multicpptest:
$(setup) \
(cd $*; $(swig_and_compile_multi_cpp); ); \
$(run_testcase)
# Makes a directory for the testcase if it does not exist
setup = \
@if [ -f $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
echo "Checking testcase $* (with run test) under $(LANGUAGE)" ; \
else \
echo "Checking testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
fi;
# Compiles java files then runs the testcase. A testcase is only run if
# a file is found which has _runme.java appended after the testcase name.
# Note Java uses LD_LIBRARY_PATH under Unix and PATH under Cygwin.
run_testcase = \
(cd $*; javac *.java; ); \
if [ -f $*\_runme.java ]; then ( \
javac $*\_runme.java; \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" java $*\_runme;) \
fi;
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
fi;
clean:
@rm -f *.class

View file

@ -0,0 +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.
Any testcases which have _runme.java appended after the testcase name will be detected and run.

View file

@ -0,0 +1,33 @@
// Two dimension arrays test
import arrays_global_twodim.*;
public class arrays_global_twodim_runme {
static {
try {
System.loadLibrary("arrays_global_twodim");
} 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[])
{
SWIGTYPE_p_a_4__int constintarray2d = arrays_global_twodim.getArray_const_i();
SWIGTYPE_p_a_4__int intarray2d = arrays_global_twodim.getArray_i();
// Set all the non const int array members from the const int array members and check
arrays_global_twodim.setArray_i(constintarray2d);
int count = 10;
for (int x=0; x<arrays_global_twodim.ARRAY_LEN_X; x++) {
for (int y=0; y<arrays_global_twodim.ARRAY_LEN_Y; y++) {
if ( arrays_global_twodim.get_2d_array(intarray2d, x, y) != count++) {
System.out.println("Value incorrect array_i[" + x + "][" + y + "]");
System.exit(1);
}
}
}
}
}

View file

@ -0,0 +1,30 @@
// This is the cpp_typedef runtime testcase. It checks that shadow classes are
// generated for typedef'd types.
import cpp_typedef.*;
public class cpp_typedef_runme {
static {
try {
System.loadLibrary("cpp_typedef");
} 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[]) {
Test test = new Test();
UnnamedStruct unnamed = new UnnamedStruct();
TypedefNamedStruct named = new TypedefNamedStruct();
UnnamedStruct unnamed2 = test.test1(unnamed);
TypedefNamedStruct named2 = test.test2(named);
TypedefNamedStruct named3 = test.test3(named);
TypedefNamedStruct named4 = test.test4(named);
}
}

View file

@ -0,0 +1,29 @@
import dynamic_cast.*;
public class dynamic_cast_runme {
static {
try {
System.loadLibrary("dynamic_cast");
} 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 f = new Foo();
Bar b = new Bar();
Foo x = f.blah();
Foo y = b.blah();
// 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);
}
}
}

View file

@ -0,0 +1,36 @@
// Runtime test checking the %typemap(ignore) macro
import ignore_parameter.*;
public class ignore_parameter_runme {
static {
try {
System.loadLibrary("ignore_parameter");
} 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[])
{
// 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()");}
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()");}
// Check constructors are also generated correctly
MiniCooper mc = new MiniCooper(200, 0.0);
MorrisMinor mm = new MorrisMinor("slow", 0.0);
FordAnglia fa = new FordAnglia("slow", 200);
AustinAllegro aa = new AustinAllegro();
}
}

View file

@ -0,0 +1,24 @@
// This is the imports runtime testcase. It shows that the %import directive
// is working correctly
import imports.*;
public class imports_runme {
static {
try {
System.loadLibrary("imports_a");
System.loadLibrary("imports_b");
} 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[]) {
B b = new B();
b.hello(); //call member function in A which is in a different SWIG generated library.
}
}

View file

@ -0,0 +1,29 @@
import java_constants.*;
public class java_constants_runme {
static {
try {
System.loadLibrary("java_constants");
} 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[])
{
int number = 200;
// Switch statement will only compile if these constants are initialised
// from a constant Java value, that is not from a function call
switch(number) {
case java_constants.CHINA:
break;
case java_constants.BRISTOLS:
break;
default:
break;
}
}
}

View file

@ -0,0 +1,57 @@
import java_jnitypes.*;
public class java_jnitypes_runme {
static {
try {
System.loadLibrary("java_jnitypes");
} 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 class Test {
}
public static void main(String argv[]) {
Test test = new Test();
boolean booleanArray[] = new boolean[] {true, false};
char charArray[] = new char[] {10, 20};
byte byteArray[] = new byte[] {'A', 'B'};
short shortArray[] = new short[] {10, 20};
int intArray[] = new int[] {10, 20};
long longArray[] = new long[] {10, 20};
float floatArray[] = new float[] {(float)10.0, (float)20.0};
double doubleArray[] = new double[] {10.0, 20.0};
Test objectArray[] = new Test[] {new Test(), test};
if (java_jnitypes.jnifunc(true) != true) testFailed("jboolean");
if (java_jnitypes.jnifunc(100) != 100) testFailed("jchar");
if (java_jnitypes.jnifunc('A') != 'A') testFailed("jbyte");
if (java_jnitypes.jnifunc(100) != 100) testFailed("jshort");
if (java_jnitypes.jnifunc(100) != 100) testFailed("jint");
if (java_jnitypes.jnifunc(100) != 100) testFailed("jlong");
if (java_jnitypes.jnifunc(100) != 100) testFailed("jfloat");
if (java_jnitypes.jnifunc(100.0) != 100) testFailed("jdouble");
if (java_jnitypes.jnifunc("100") != "100") testFailed("jstring");
if (java_jnitypes.jnifunc(test) != test) testFailed("jobject");
if (java_jnitypes.jnifunc(booleanArray)[1] != false) testFailed("jbooleanArray");
if (java_jnitypes.jnifunc(charArray)[1] != 20) testFailed("jcharArray");
if (java_jnitypes.jnifunc(byteArray)[1] != 'B') testFailed("jbyteArray");
if (java_jnitypes.jnifunc(shortArray)[1] != 20) testFailed("jshortArray");
if (java_jnitypes.jnifunc(intArray)[1] != 20) testFailed("jintArray");
if (java_jnitypes.jnifunc(longArray)[1] != 20) testFailed("jlongArray");
if (java_jnitypes.jnifunc(floatArray)[1] != 20.0) testFailed("jfloatArray");
if (java_jnitypes.jnifunc(doubleArray)[1] != 20.0) testFailed("jdoubleArray");
if (java_jnitypes.jnifunc(objectArray)[1] != test) testFailed("jobjectArray");
}
public static void testFailed(String str) {
System.err.println(str + " test failed");
System.exit(1);
}
}

View file

@ -0,0 +1,150 @@
// This is the java_lib_arrays runtime testcase. It ensures that a getter and a setter has
// been produced for array members and that they function as expected. It is a
// pretty comprehensive test for all the Java array library typemaps.
import java_lib_arrays.*;
public class java_lib_arrays_runme {
static {
try {
System.loadLibrary("java_lib_arrays");
} 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[]) {
// Check array member variables
ArrayStruct as = new ArrayStruct();
// Create arrays for all the array types that ArrayStruct can handle
String array_c = "X";
byte[] array_sc = {10, 20};
short[] array_uc = {101, 201};
short[] array_s = {1002, 2002};
int[] array_us = {1003, 2003};
int[] array_i = {1004, 2004};
long[] array_ui = {1005, 2005};
int[] array_l = {1006, 2006};
long[] array_ul = {1007, 2007};
long[] array_ll = {1008, 2008};
float[] array_f = {1009.1f, 2009.1f};
double[] array_d = {1010.2f, 2010.2f};
int[] array_enum = {java_lib_arrays.Three, java_lib_arrays.Four};
SimpleStruct[] array_struct={new SimpleStruct(), new SimpleStruct()};
array_struct[0].setDouble_field(222.333);
array_struct[1].setDouble_field(444.555);
// Now set the array members and check that they have been set correctly
as.setArray_c(array_c);
check_string(array_c, as.getArray_c());
as.setArray_sc(array_sc);
check_byte_array(array_sc, as.getArray_sc());
as.setArray_uc(array_uc);
check_short_array(array_uc, as.getArray_uc());
as.setArray_s(array_s);
check_short_array(array_s, as.getArray_s());
as.setArray_us(array_us);
check_int_array(array_us, as.getArray_us());
as.setArray_i(array_i);
check_int_array(array_i, as.getArray_i());
as.setArray_ui(array_ui);
check_long_array(array_ui, as.getArray_ui());
as.setArray_l(array_l);
check_int_array(array_l, as.getArray_l());
as.setArray_ul(array_ul);
check_long_array(array_ul, as.getArray_ul());
as.setArray_ll(array_ll);
check_long_array(array_ll, as.getArray_ll());
as.setArray_f(array_f);
check_float_array(array_f, as.getArray_f());
as.setArray_d(array_d);
check_double_array(array_d, as.getArray_d());
as.setArray_enum(array_enum);
check_int_array(array_enum, as.getArray_enum());
as.setArray_struct(array_struct);
check_struct_array(array_struct, as.getArray_struct());
}
// Functions to check that the array values were set correctly
public static void check_string(String original, String checking) {
if (!checking.equals(original)) {
System.err.println("Runtime test failed. checking = [" + checking + "]");
System.exit(1);
}
}
public static void check_byte_array(byte[] original, byte[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_short_array(short[] original, short[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_int_array(int[] original, int[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_long_array(long[] original, long[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_float_array(float[] original, float[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_double_array(double[] original, double[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i] != original[i]) {
System.err.println("Runtime test failed. checking[" + i + "]=" + checking[i]);
System.exit(1);
}
}
}
public static void check_struct_array(SimpleStruct[] original, SimpleStruct[] checking) {
for (int i=0; i<original.length; i++) {
if (checking[i].getDouble_field() != original[i].getDouble_field()) {
System.err.println("Runtime test failed. checking[" + i + "].double_field=" + checking[i].getDouble_field());
System.exit(1);
}
}
}
}

View file

@ -0,0 +1,15 @@
import java_pragmas.*;
public class java_pragmas_runme {
// No system.loadLibrary() as the JNI class will do this
public static void main(String argv[])
{
// Call a JNI class function. Normally this is not possible as the class is protected, however, the jniclassmodifiers pragma has changed this.
long int_pointer = java_pragmasJNI.get_int_pointer();
java_pragmas.added_function("hello");
}
}

View file

@ -0,0 +1,46 @@
import java_throws.*;
public class java_throws_runme {
static {
try {
System.loadLibrary("java_throws");
} 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[])
{
// Check the exception classes in the main typemaps
boolean pass = false;
// This won't compile unless all of these exceptions are in the throw clause
try {
short s = java_throws.full_of_exceptions(10);
}
catch (ClassNotFoundException e) {}
catch (NoSuchFieldException e) { pass = true; }
catch (InstantiationException e) {}
catch (CloneNotSupportedException e) {}
catch (IllegalAccessException e) {}
if (!pass) {
System.err.println("Test 1 failed");
System.exit(1);
}
// Check the exception class in the throw typemap
try {
java_throws.throw_spec_function(100);
}
catch (IllegalAccessException e) { pass = true; }
if (!pass) {
System.err.println("Test 2 failed");
System.exit(1);
}
}
}

View file

@ -0,0 +1,48 @@
// This is the java_typemaps_proxy runtime testcase. Contrived example checks that the pure Java code from the Java typemaps compiles.
import java_typemaps_proxy.*;
public class java_typemaps_proxy_runme {
static {
try {
System.loadLibrary("java_typemaps_proxy");
} 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[]) {
Greeting greet = new Greeting();
Farewell bye = new Farewell();
// Check that pure Java methods have been added
greet.sayhello();
bye.saybye(new java.math.BigDecimal(java.math.BigInteger.ONE));
// No finalize method so may as well delete manually
bye.delete();
// Check that Greeting is derived from Exception
try {
throw new Greeting();
} catch (Greeting g) {
String msg = g.getMessage();
}
// Check that Greeting has implemented the EventListener interface
Greeting.cheerio(greet);
// The default getCPtr() call in each method will through an exception if null is passed.
// Make sure the modified version works with and without null objects.
Greeting.ciao(null);
Greeting.ciao(greet);
// Create a NULL pointer for Farewell using the constructor with changed modifiers
Farewell nullFarewell = new Farewell(0, false);
}
}

View file

@ -0,0 +1,45 @@
// This is the java_typemaps_typewrapper runtime testcase. Contrived example checks that the pure Java code generated from the Java typemaps compiles.
import java_typemaps_typewrapper.*;
public class java_typemaps_typewrapper_runme {
static {
try {
System.loadLibrary("java_typemaps_typewrapper");
} 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[]) {
SWIGTYPE_p_Greeting greet = SWIGTYPE_p_Greeting.CreateNullPointer();
SWIGTYPE_p_Farewell bye = SWIGTYPE_p_Farewell.CreateNullPointer();
// Check that pure Java methods have been added
greet.sayhello();
bye.saybye(new java.math.BigDecimal(java.math.BigInteger.ONE));
// Check that SWIGTYPE_p_Greeting is derived from Exception
try {
throw SWIGTYPE_p_Greeting.CreateNullPointer();
} catch (SWIGTYPE_p_Greeting g) {
String msg = g.getMessage();
}
// Check that SWIGTYPE_p_Greeting has implemented the EventListener interface
SWIGTYPE_p_Greeting.cheerio(greet);
// The default getCPtr() call in each method will through an exception if null is passed.
// Make sure the modified version works with and without null objects.
java_typemaps_typewrapper.solong(null);
java_typemaps_typewrapper.solong(bye);
// Create a NULL pointer for Farewell using the constructor with changed modifiers
SWIGTYPE_p_Farewell nullFarewell = new SWIGTYPE_p_Farewell(0, false);
}
}

View file

@ -0,0 +1,85 @@
// Check a few of the INPUT, OUTPUT and INOUT typemaps.
import lib_typemaps.*;
import java.math.*;
public class lib_typemaps_runme {
static {
try {
System.loadLibrary("lib_typemaps");
} 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[]) {
// Check double INPUT typemaps
if (lib_typemaps.in_double(22.22) != 22.22) exit_test("in_double");
if (lib_typemaps.inr_double(22.22) != 22.22) exit_test("inr_double");
// Check double OUTPUT typemaps
{
double[] var = {44.44};
lib_typemaps.out_double(22.22, var);
if (var[0] != 22.22) exit_test("out_double");
}
{
double[] var = {44.44};
lib_typemaps.outr_double(22.22, var);
if (var[0] != 22.22) exit_test("outr_double");
}
// Check double INOUT typemaps
{
double[] var = {44.44};
lib_typemaps.inout_double(var);
if (var[0] != 44.44) exit_test("inout_double");
}
{
double[] var = {44.44};
lib_typemaps.inoutr_double(var);
if (var[0] != 44.44) exit_test("inoutr_double");
}
// Check unsigned long long INPUT typemaps
BigInteger forty = new BigInteger("40");
BigInteger twenty = new BigInteger("20");
if (!lib_typemaps.in_ulonglong(twenty).equals(twenty)) exit_test("in_ulonglong");
if (!lib_typemaps.inr_ulonglong(twenty).equals(twenty)) exit_test("inr_ulonglong");
// Check unsigned long long OUTPUT typemaps
{
BigInteger[] var = {new BigInteger("40")};
lib_typemaps.out_ulonglong(twenty, var);
if (!var[0].equals(twenty)) exit_test("out_ulonglong");
}
{
BigInteger[] var = {new BigInteger("40")};
lib_typemaps.outr_ulonglong(twenty, var);
if (!var[0].equals(twenty)) exit_test("outr_ulonglong");
}
// Check unsigned long long INOUT typemaps
{
BigInteger[] var = {new BigInteger("40")};
lib_typemaps.inout_ulonglong(var);
if (!var[0].equals(forty)) exit_test("inout_ulonglong");
}
{
BigInteger[] var = {new BigInteger("40")};
lib_typemaps.inoutr_ulonglong(var);
if (!var[0].equals(forty)) exit_test("inoutr_ulonglong");
}
}
private static void exit_test(String funcName) {
System.err.println("Test FAILED in function " + funcName);
System.exit(1);
}
}

View file

@ -0,0 +1,50 @@
// This is the long_long runtime testcase. It checks that the long long and
// unsigned long long types map correctly to long and BigInteger respectively.
import long_long.*;
import java.math.*;
public class long_long_runme {
static {
try {
System.loadLibrary("long_long");
} 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[]) {
check_ll(0L);
check_ll(0x7FFFFFFFFFFFFFFFL);
check_ll(-10);
check_ull(new BigInteger("0"));
check_ull(new BigInteger("127"));
check_ull(new BigInteger("128"));
check_ull(new BigInteger("9223372036854775807")); //0x7FFFFFFFFFFFFFFFL
check_ull(new BigInteger("18446744073709551615")); //0xFFFFFFFFFFFFFFFFL
}
public static void check_ll(long ll) {
long_long.setLl(ll);
long ll_check = long_long.getLl();
if (ll != ll_check) {
System.err.println("Runtime test using long long failed. ll=" + ll + " ll_check=" + ll_check);
System.exit(1);
}
}
public static void check_ull(BigInteger ull) {
long_long.setUll(ull);
BigInteger ull_check = long_long.getUll();
if (ull.compareTo(ull_check) != 0) {
System.err.println("Runtime test using unsigned long long failed. ull=" + ull.toString() + " ull_check=" + ull_check.toString());
System.exit(1);
}
}
}

View file

@ -0,0 +1,64 @@
// Check that C++ primitive types that are passed by const reference work when
// passed by value from Java
import primitive_ref.*;
import java.math.*;
public class primitive_ref_runme {
static {
try {
System.loadLibrary("primitive_ref");
} 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 (primitive_ref.ref_int(3) != 3) {
System.err.println( "ref_int failed!" );
}
if (primitive_ref.ref_uint(3) != 3) {
System.err.println( "ref_uint failed!" );
}
if (primitive_ref.ref_short((short)3) != 3) {
System.err.println( "ref_short failed!" );
}
if (primitive_ref.ref_ushort(3) != 3) {
System.err.println( "ref_ushort failed!" );
}
if (primitive_ref.ref_long(3) != 3) {
System.err.println( "ref_long failed!" );
}
if (primitive_ref.ref_ulong(3) != 3) {
System.err.println( "ref_ulong failed!" );
}
if (primitive_ref.ref_schar((byte)3) != 3) {
System.err.println( "ref_schar failed!" );
}
if (primitive_ref.ref_uchar((short)3) != 3) {
System.err.println( "ref_uchar failed!" );
}
if (primitive_ref.ref_bool(true) != true) {
System.err.println( "ref_bool failed!" );
}
if (primitive_ref.ref_float((float)3.5) != 3.5) {
System.err.println( "ref_float failed!" );
}
if (primitive_ref.ref_double(3.5) != 3.5) {
System.err.println( "ref_double failed!" );
}
if (primitive_ref.ref_char('x') != 'x') {
System.err.println( "ref_char failed!" );
}
if (primitive_ref.ref_longlong(3) != '3') {
System.err.println( "ref_longlong failed!" );
}
BigInteger bi = new BigInteger("18446744073709551615"); //0xFFFFFFFFFFFFFFFFL
if (bi.compareTo(primitive_ref.ref_ulonglong(bi)) != 0) {
System.err.println( "ref_ulonglong failed!" );
}
}
}

View file

@ -0,0 +1,33 @@
// This is the ret_by_value runtime testcase. It checks that SWIG handles
// return by value okay.
import ret_by_value.*;
public class ret_by_value_runme {
static {
try {
System.loadLibrary("ret_by_value");
} 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[]) {
// Get the test class. Note that this constructor will ensure that the memory created
// in the wrapper is owned by the test class.
test tst = ret_by_value.get_test();
if (tst.getMyInt() != 100 || tst.getMyShort() != 200) {
System.err.println("Runtime test failed. myInt=" + tst.getMyInt() + " myShort=" + tst.getMyShort());
System.exit(1);
}
// Delete memory manually, it should not be deleted again by the test class finalizer
tst.delete();
}
}

View file

@ -0,0 +1,25 @@
// This is the template_classes runtime testcase. It checks that SWIG handles a templated
// class used by another templated class, in particular that the shadow classes can be used.
import template_classes.*;
public class template_classes_runme {
static {
try {
System.loadLibrary("template_classes");
} 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[]) {
RectangleInt rectint = new RectangleInt();
PointInt pi = rectint.getPoint();
int x = pi.getX();
}
}

View file

@ -0,0 +1,68 @@
// This is the union runtime testcase. It ensures that values within a
// union embedded within a struct can be set and read correctly.
import unions.*;
public class unions_runme {
static {
try {
System.loadLibrary("unions");
} 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[]) {
// Create new instances of SmallStruct and BigStruct for later use
SmallStruct small = new SmallStruct();
small.setJill((short)200);
BigStruct big = new BigStruct();
big.setSmallstruct(small);
big.setJack(300);
// Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
// Ensure values in EmbeddedUnionTest are set correctly for each.
EmbeddedUnionTest eut = new EmbeddedUnionTest();
// First check the SmallStruct in EmbeddedUnionTest
eut.setNumber(1);
eut.getUni().setSmall(small);
short Jill1 = eut.getUni().getSmall().getJill();
if (Jill1 != 200) {
System.err.println("Runtime test1 failed. eut.uni.small.jill=" + Jill1);
System.exit(1);
}
int Num1 = eut.getNumber();
if (Num1 != 1) {
System.err.println("Runtime test2 failed. eut.number=" + Num1);
System.exit(1);
}
// Secondly check the BigStruct in EmbeddedUnionTest
eut.setNumber(2);
eut.getUni().setBig(big);
int Jack1 = eut.getUni().getBig().getJack();
if (Jack1 != 300) {
System.err.println("Runtime test3 failed. eut.uni.big.jack=" + Jack1);
System.exit(1);
}
short Jill2 = eut.getUni().getBig().getSmallstruct().getJill();
if (Jill2 != 200) {
System.err.println("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2);
System.exit(1);
}
int Num2 = eut.getNumber();
if (Num2 != 2) {
System.err.println("Runtime test5 failed. eut.number=" + Num2);
System.exit(1);
}
}
}