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,42 @@
SWIG testsuite README file
--------------------------
This testsuite is here to ensure SWIG can handle a wide range of c/c++
syntax. The testsuite comprises many testcases in this directory. Each
test case is tested under each of the language modules thereby
thoroughly testing all of SWIG. It ensures that each of the language
modules are at a similar standard.
Those modules that support shadow classes run the tests producing
shadow classes to test the full language module functionality.
Some test cases need a runtime test. These need implementing in each
of the language modules. The language modules look for a file in the
language specific test-suite directory which has _runme appended after
the testcase name. If one is found it will be run as part of the test.
Some language modules add to this common set of test cases for
language specific tests. These can be found in the appropriate
language test-suite directory. There is also a README in each of the
language module directories.
For each testcase a message showing which testcase is being tested is
displayed. Nothing else is printed unless the test fails.
Some Developer Guidelines
-------------------------
Note that the whole test suite need not be run each time a testcase is
modified. An individual testcase may be run by going to the language
module test-suite directory and using make testcasename.xxx where xxx
is the type of test (eg cpptest). See common.mk. make -s doesn't print
any junk on the screen and is useful for emulating the way make check
works from the SWIG root directory.
If there are runtime tests needed, don't print anything unless there
is an error in which case stderr is suggested.
Please set the name of the module to the same name as the testcase,
otherwise modules will not be found.

View file

@ -0,0 +1,20 @@
%module abstract_inherit
%warnfilter(403) Spam;
%warnfilter(403) Bar;
%inline %{
class Foo {
public:
virtual int blah() = 0;
};
class Bar : public Foo { };
class Spam: public Foo {
public:
Spam() { }
};
%}

View file

@ -0,0 +1,21 @@
%module abstract_inherit_ok
%feature("notabstract") Spam;
%warnfilter(403) Spam;
%inline %{
class Foo {
public:
virtual int blah() = 0;
};
class Spam: public Foo {
public:
Spam() { }
#ifndef SWIG
int blah() { return 0; }
#endif
};
%}

View file

@ -0,0 +1,25 @@
%module abstract_signature
%warnfilter(801) abstract_foo; // Ruby, wrong class name
%warnfilter(801) abstract_bar; // Ruby, wrong class name
%inline %{
class abstract_foo
{
public:
abstract_foo() { };
virtual ~abstract_foo() { };
virtual int meth(int meth_param) = 0;
};
class abstract_bar : public abstract_foo
{
public:
abstract_bar() { };
virtual ~abstract_bar() { };
int meth(int meth_param_1, int meth_param_2) { return 0; }
};
%}

View file

@ -0,0 +1,52 @@
%module abstract_typedef
%inline %{
struct Engine
{
};
struct Object
{
virtual bool write(Engine& archive) const = 0;
};
typedef Engine PersEngine;
typedef Object PersClassBase;
class A : public PersClassBase
{
// This works always
// bool write(Engine& archive) const;
// This doesn't with Swig 1.3.17.
// But it works fine with 1.3.16
bool write(PersEngine& archive) const
{
return true;
}
};
%}
/*
Problem related to the direct comparison of strings
in the file allocate.cxx (line 55)
......
String *local_decl = Getattr(dn,"decl");
if (local_decl && !Strcmp(local_decl, base_decl)) {
......
with the direct string comparison, no equivalent types
are checked and the two 'write' functions appear to be
different because
"q(const).f(r.bss::PersEngine)." != "q(const).f(r.bss::Engine)."
*/

View file

@ -0,0 +1,20 @@
%module add_link
%extend Foo {
Foo *blah() {
return new Foo();
}
};
%inline %{
class Foo {
public:
Foo() { };
};
%}

View file

@ -0,0 +1,12 @@
/* This interface file checks whether the SWIG parses anonymous
arguments with default values. Bug reported by Annalisa Terracina
<annalisa.terracina@datamat.it> on 2001-07-03.
*/
%module anonymous_arg
void foo(int = 7771);
%{
void foo(int x) {}
%}

View file

@ -0,0 +1,37 @@
/* This interface file checks how well SWIG handles passing data back
through arguments WITHOUT returning it seperatly; for the cases where
maybe multiple values are passed by refernce and all want changing */
%module argout
%include cpointer.i
%pointer_functions(int,intp);
%inline %{
// returns old value
int incp(int *value) {
return (*value)++;
}
// returns old value
int incr(int &value) {
return value++;
}
typedef int & IntRef;
// returns old value
int inctr(IntRef value) {
return value++;
}
// example of the old DB login type routines where you keep
// a void* which it points to its opaque struct when you login
// So login function takes a void**
void voidhandle(void** handle) {
*handle=(void*)"Here it is";
}
char * handle(void* handle) {
return (char *)handle;
}
%}

View file

@ -0,0 +1,12 @@
// A module with a function that involves pointers to arrays
%module arrayptr
%inline %{
void foo(int (*x)[10]) {
}
%}

View file

@ -0,0 +1,52 @@
/*
This test case tests that various types of arrays are working.
*/
%module arrays
%pragma make_default
%inline %{
#define ARRAY_LEN 2
typedef enum {One, Two, Three, Four, Five} finger;
typedef struct {
double double_field;
} SimpleStruct;
typedef struct {
char array_c [ARRAY_LEN];
signed char array_sc[ARRAY_LEN];
unsigned char array_uc[ARRAY_LEN];
short array_s [ARRAY_LEN];
unsigned short array_us[ARRAY_LEN];
int array_i [ARRAY_LEN];
unsigned int array_ui[ARRAY_LEN];
long array_l [ARRAY_LEN];
unsigned long array_ul[ARRAY_LEN];
long long array_ll[ARRAY_LEN];
float array_f [ARRAY_LEN];
double array_d [ARRAY_LEN];
SimpleStruct array_struct[ARRAY_LEN];
SimpleStruct* array_structpointers[ARRAY_LEN];
int* array_ipointers [ARRAY_LEN];
finger array_enum[ARRAY_LEN];
finger* array_enumpointers[ARRAY_LEN];
const int array_const_i[ARRAY_LEN];
} ArrayStruct;
void fn_taking_arrays(SimpleStruct array_struct[ARRAY_LEN]) {}
/* Pointer helper functions used in the Java run test */
int* newintpointer() {
return (int*)malloc(sizeof(int));
}
void setintfrompointer(int* intptr, int value) {
*intptr = value;
}
int getintfrompointer(int* intptr) {
return *intptr;
}
%}

View file

@ -0,0 +1,37 @@
/*
This test case tests that various types of arrays are working.
*/
%module arrays_global
%pragma make_default
%inline %{
#define ARRAY_LEN 2
typedef enum {One, Two, Three, Four, Five} finger;
typedef struct {
double double_field;
} SimpleStruct;
char array_c [ARRAY_LEN];
signed char array_sc[ARRAY_LEN];
unsigned char array_uc[ARRAY_LEN];
short array_s [ARRAY_LEN];
unsigned short array_us[ARRAY_LEN];
int array_i [ARRAY_LEN];
unsigned int array_ui[ARRAY_LEN];
long array_l [ARRAY_LEN];
unsigned long array_ul[ARRAY_LEN];
long long array_ll[ARRAY_LEN];
float array_f [ARRAY_LEN];
double array_d [ARRAY_LEN];
SimpleStruct array_struct[ARRAY_LEN];
SimpleStruct* array_structpointers[ARRAY_LEN];
int* array_ipointers [ARRAY_LEN];
finger array_enum[ARRAY_LEN];
finger* array_enumpointers[ARRAY_LEN];
const int array_const_i[ARRAY_LEN] = {10, 20};
%}

View file

@ -0,0 +1,42 @@
/*
Two dimension arrays
*/
%module arrays_global_twodim
%inline %{
#define ARRAY_LEN_X 2
#define ARRAY_LEN_Y 4
typedef enum {One, Two, Three, Four, Five} finger;
typedef struct {
double double_field;
} SimpleStruct;
char array_c [ARRAY_LEN_X][ARRAY_LEN_Y];
signed char array_sc[ARRAY_LEN_X][ARRAY_LEN_Y];
unsigned char array_uc[ARRAY_LEN_X][ARRAY_LEN_Y];
short array_s [ARRAY_LEN_X][ARRAY_LEN_Y];
unsigned short array_us[ARRAY_LEN_X][ARRAY_LEN_Y];
int array_i [ARRAY_LEN_X][ARRAY_LEN_Y];
unsigned int array_ui[ARRAY_LEN_X][ARRAY_LEN_Y];
long array_l [ARRAY_LEN_X][ARRAY_LEN_Y];
unsigned long array_ul[ARRAY_LEN_X][ARRAY_LEN_Y];
long long array_ll[ARRAY_LEN_X][ARRAY_LEN_Y];
float array_f [ARRAY_LEN_X][ARRAY_LEN_Y];
double array_d [ARRAY_LEN_X][ARRAY_LEN_Y];
SimpleStruct array_struct[ARRAY_LEN_X][ARRAY_LEN_Y];
SimpleStruct* array_structpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
int* array_ipointers [ARRAY_LEN_X][ARRAY_LEN_Y];
finger array_enum[ARRAY_LEN_X][ARRAY_LEN_Y];
finger* array_enumpointers[ARRAY_LEN_X][ARRAY_LEN_Y];
const int array_const_i[ARRAY_LEN_X][ARRAY_LEN_Y] = { {10, 11, 12, 13}, {14, 15, 16, 17} };
void fn_taking_arrays(SimpleStruct array_struct[ARRAY_LEN_X][ARRAY_LEN_Y]) {}
int get_2d_array(int (*array)[ARRAY_LEN_Y], int x, int y){
return array[x][y];
}
%}

View file

@ -0,0 +1,19 @@
%module arrays_scope
%inline %{
enum { ASIZE = 256 };
namespace foo {
enum { BSIZE = 512 };
class Bar {
public:
enum { CSIZE = 768 };
int adata[ASIZE];
int bdata[BSIZE];
int cdata[CSIZE];
void blah(int x[ASIZE], int y[BSIZE], int z[CSIZE]) { };
};
}
%}

View file

@ -0,0 +1,9 @@
// [ 548272] Default arguments
%module bool_default
%inline %{
bool foo(bool x = true) {
return !x;
}
%}

View file

@ -0,0 +1,21 @@
%module casts
%inline %{
class A {
public:
A() {}
void hello()
{
}
};
class B : public A
{
public:
B() {}
};
%}

View file

@ -0,0 +1,11 @@
/* This interface file tests whether character constants are correctly
wrapped as procedures returning Scheme characters (rather than
Scheme strings).
*/
%module char_constant
#define CHAR_CONSTANT 'x'
#define STRING_CONSTANT "xyzzy"

View file

@ -0,0 +1,20 @@
%module class_ignore
%ignore Foo;
%inline %{
class Foo {
public:
virtual char *blah() = 0;
};
class Bar : public Foo {
public:
virtual char *blah() { return (char *) "Bar::blah"; }
};
char *do_blah(Foo *f) {
return f->blah();
}
%}

View file

@ -0,0 +1,291 @@
#######################################################################
# $Header$
#
# SWIG test suite makefile.
# The test suite comprises many different test cases, which have
# typically produced bugs in the past. The aim is to have the test
# cases compiling for every language modules. Some testcase have
# a runtime test which is written in each of the module's language.
#
# This makefile runs SWIG on the testcases, compiles the c/c++ code
# then builds the object code for use by the language.
# To complete a test in a language follow these guidelines:
# 1) Add testcases to CPP_TEST_CASES (c++) or C_TEST_CASES (c) or
# MULTI_CPP_TEST_CASES (multi-module c++ tests)
# 2) If not already done, create a makefile which:
# a) Defines LANGUAGE matching a language rule in Examples/Makefile,
# for example LANGUAGE = java
# b) Define rules for %.ctest, %.cpptest, %.multicpptest and %.clean.
#
# The variables below can be overridden after including this makefile
#######################################################################
#######################################################################
# Variables
#######################################################################
TOP = ../..
SWIG = $(TOP)/../swig
SWIG_LIB = $(TOP)/../Lib
TEST_SUITE = test-suite
CXXSRCS =
CSRCS =
TARGETPREFIX =
TARGETSUFFIX =
SWIGOPT = -I$(TOP)/$(TEST_SUITE)
INCLUDES = -I$(TOP)/$(TEST_SUITE)
RUNTIMEDIR = ../$(TOP)/Runtime/.libs
DYNAMIC_LIB_PATH = $(RUNTIMEDIR):.
# Please keep test cases in alphabetical order.
#
# EXCEPTION: PLEASE PUT BROKEN TEST CASES AT THE TOP OF THIS LIST.
# C++ test cases. (Can be run individually using make testcase.cpptest.)
CPP_TEST_BROKEN = \
abstract_typedef \
namespace_nested \
template_default_arg \
using_namespace
CPP_TEST_CASES += $(CPP_TEST_BROKEN)
CPP_TEST_CASES += \
abstract_inherit \
abstract_inherit_ok \
abstract_signature \
add_link \
anonymous_arg \
argout \
arrays_global \
arrays_global_twodim \
arrays_scope \
bool_default \
casts \
class_ignore \
const_const_2 \
constant_pointers \
constover \
constructor_exception \
constructor_explicit \
constructor_value \
conversion \
conversion_namespace \
conversion_ns_template \
cplusplus_throw \
cpp_enum \
cpp_enum_scope \
cpp_enum_scope \
cpp_namespace \
cpp_nodefault \
cpp_static \
cpp_typedef \
default_cast \
default_constructor \
default_ns \
default_ref \
dynamic_cast \
enum_scope \
enum_scope_template \
enum_var \
evil_diamond \
evil_diamond_ns \
evil_diamond_prop \
explicit \
extend_template \
extend_template_ns \
grouping \
ignore_parameter \
import_nomodule \
inherit_missing \
kind \
lib_carrays \
lib_cdata \
lib_cpointer \
lib_std_deque \
lib_std_string \
lib_std_vector \
lib_typemaps \
member_template \
minherit \
name_cxx \
name_inherit \
namespace_enum \
namespace_extend \
namespace_template \
namespace_typemap \
newobject1 \
overload_complicated \
overload_copy \
overload_extend \
overload_simple \
overload_subtype \
overload_template \
pointer_reference \
primitive_ref \
private_assign \
pure_virtual \
rename_default \
rename_default \
rename_scope \
return_value_scope \
rname \
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 \
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_const_ref \
template_construct \
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_qualifier \
template_rename \
template_retvalue \
template_specialization \
template_static \
template_tbase_template \
template_type_namespace \
template_typedef \
template_typedef_cplx \
template_typedef_cplx2 \
template_typedef_cplx3 \
template_typedef_cplx4 \
template_virtual \
template_whitespace \
throw_exception \
typedef_array_member \
typedef_funcptr \
typedef_inherit \
typedef_mptr \
typedef_reference \
typedef_scope \
typemap_namespace \
typemap_ns_using \
typename \
union_scope \
using1 \
using2 \
using_composition \
using_extend \
using_inherit \
using_private \
using_protected \
valuewrapper_base \
virtual_destructor \
voidtest
# C test cases. (Can be run individually using make testcase.ctest.)
C_TEST_CASES += \
arrayptr \
arrays \
char_constant \
const_const \
defineop \
defines \
enum \
lib_carrays \
lib_cdata \
lib_cmalloc \
lib_constraints \
lib_cpointer \
lib_math \
long_long \
macro_2 \
name \
nested \
newobject2 \
overload_extendc \
preproc_1 \
preproc_2 \
preproc_3 \
ret_by_value \
sizeof_pointer \
sneaky1 \
typemap_subst \
unions
MULTI_CPP_TEST_CASES += \
imports \
template_typedef_import
ALL_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \
$(C_TEST_CASES:=.ctest) \
$(MULTI_CPP_TEST_CASES:=.multicpptest)
ALL_CLEAN = $(CPP_TEST_CASES:=.clean) \
$(C_TEST_CASES:=.clean) \
$(MULTI_CPP_TEST_CASES:=.clean)
#######################################################################
# The following applies for all module languages
#######################################################################
all: $(ALL_TEST_CASES)
check: all
swig_and_compile_cpp = \
$(MAKE) -f $(TOP)/Makefile CXXSRCS="$(CXXSRCS)" SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)_cpp
swig_and_compile_c = \
$(MAKE) -f $(TOP)/Makefile CSRCS="$(CSRCS)" SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)
swig_and_compile_multi_cpp = \
for f in `cat $(TOP)/$(TEST_SUITE)/$*.list` ; do \
$(MAKE) -f $(TOP)/Makefile CXXSRCS="$(CXXSRCS)" SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" RUNTIMEDIR="$(RUNTIMEDIR)" \
TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACE="$$f.i" \
NOLINK=true $(LANGUAGE)$(VARIANT)_multi_cpp; \
done
setup = \
@if [ -f $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
echo "Checking testcase $* (with run test) under $(LANGUAGE)" ; \
else \
echo "Checking testcase $* under $(LANGUAGE)" ; \
fi;
#######################################################################
# Clean
#######################################################################
clean: $(ALL_CLEAN)

View file

@ -0,0 +1,13 @@
/* This interface file tests whether SWIG handles types like
"const int *const" right.
SWIG 1.3a5 signals a syntax error.
*/
%module const_const
%typemap(in) const int *const { $1 = NULL; }
%inline %{
void foo(const int *const i) {}
%}

View file

@ -0,0 +1,21 @@
/* This interface file tests whether SWIG handles doubly constant
methods right. SF Bug #216057 against Swig 1.3a5, reported by
Mike Romberg <romberg@users.sf.net>
*/
%module const_const_2
%inline %{
class Spam {
public:
Spam() {}
};
class Eggs {
public:
Eggs() {}
const Spam *spam(void) const { return new Spam(); }
};
%}

View file

@ -0,0 +1,74 @@
/*
This testcase primarily test constant pointers, eg int* const. Only a getter is expected to be produced when wrapping constant pointer variables. A number of other const issues are also tested.
*/
%module constant_pointers
%inline %{
int GlobalInt;
const int ConstInt=2;
int* GlobalIntPtr=&GlobalInt;
int* const GlobalConstIntPtr=&GlobalInt;
#define ARRAY_SIZE 2
class ParametersTest {
public:
void param1(int* a) {}
void param2(const int* a) {}
void param3(int* const a) {}
void param4(int const a) {}
void param5(const int a) {}
void param6(int& a) {}
void param7(const int& a) {}
void param8(int const& a) {}
void param9(int*& a) {}
void param10(int* const& a) {}
void param11(const int* const a) {}
void param_array1(int* a[ARRAY_SIZE]) {}
void param_array2(const int* a[ARRAY_SIZE]) {}
void param_array3(int* const a[ARRAY_SIZE]) {}
void param_array4(int const a[ARRAY_SIZE]) {}
void param_array5(const int a[ARRAY_SIZE]) {}
void param_array6(const int* const a[ARRAY_SIZE]) {}
};
class MemberVariablesTest {
public:
int* member1;
ParametersTest* member2;
int* const member3;
ParametersTest* const member4;
int* array_member1[ARRAY_SIZE];
ParametersTest* array_member2[ARRAY_SIZE];
int* const array_member3[ARRAY_SIZE];
ParametersTest* const array_member4[ARRAY_SIZE];
MemberVariablesTest() : member3(NULL), member4(NULL) {}
};
void foo(const int *const i) {}
typedef int *typedef1, typedef2, *const typedef3;
int int1, int2=2, *int3, *const int4 = &GlobalInt;
class ReturnValuesTest {
public:
typedef1 td1;
typedef2 td2;
int int1, int2, *const int3, *int4, array1[ARRAY_SIZE], *const array2[ARRAY_SIZE];
int ret1() {return 5;}
const int ret2() {return 5;}
int ret3() {return 5;}
const int* ret4() {return &ConstInt;}
int* const ret5() {return &GlobalInt;}
void ret6(int*& a) {}
int*& ret7() {return GlobalIntPtr;}
ReturnValuesTest() : int3(NULL) {}
};
const int* globalRet1() {return &GlobalInt;};
int* const globalRet2() {return &GlobalInt;};
%}

View file

@ -0,0 +1,38 @@
// This test checks SWIG's code generation for C++ functions
// and methods that differ only in constness.
%module constover
%rename(test_pconst) test(const char *);
%rename(test_constm) test(char *) const;
%rename(test_pconstm) test(const char *) const;
%inline %{
char *test(char *x) {
return (char *) "test";
}
char *test(const char *x) {
return (char *) "test_pconst";
}
class Foo {
public:
Foo() { }
char *test(char *x) {
return (char *) "test";
}
char *test(const char *x) {
return (char *) "test_pconst";
}
char *test(char *x) const {
return (char *) "test_constmethod";
}
char *test(const char *x) const {
return (char *) "test_pconstmethod";
}
};
%}

View file

@ -0,0 +1,27 @@
%module constructor_exception
%inline %{
class Error {
};
class Object {
public:
Object(int x) {
if (x < 0) {
throw Error();
}
}
};
class Test {
Object o;
public:
Test(int x) try : o(x) { }
catch (Error &e) {
}
catch (int y) {
}
catch (...) {
}
};
%}

View file

@ -0,0 +1,13 @@
%module constructor_explicit
%inline %{
class Foo {
public:
explicit Foo() { }
};
Foo test(Foo x) {
return x;
}
%}

View file

@ -0,0 +1,15 @@
%module constructor_value
%inline %{
class Foo {
public:
Foo(int a) {};
};
class Bar {
public:
Bar(Foo ci) {}
};
%}

View file

@ -0,0 +1,11 @@
%module conversion
%rename(toFoo) Bar::operator Foo();
%inline %{
struct Foo {
};
struct Bar {
operator Foo () { return Foo(); }
};
%}

View file

@ -0,0 +1,14 @@
%module conversion_namespace
%rename(toFoo) oss::Bar::operator oss::Foo();
%inline %{
namespace oss
{
struct Foo {
};
struct Bar {
operator Foo () { return Foo(); }
};
}
%}

View file

@ -0,0 +1,49 @@
%module conversion_ns_template
%{
namespace oss
{
enum Test {One, Two};
template <Test>
struct Foo {
};
template <Test T>
struct Bar {
operator int() { return 0; }
operator int&() { static int num = 0; return num; }
operator Foo<T>() { return Foo<T>(); }
operator Foo<T>&() { return *(new Foo<T>()); }
};
}
%}
namespace oss
{
enum Test {One, Two};
template <Test>
struct Foo {
};
// these two works
%rename(hello1) Bar<One>::operator int&();
%ignore Bar<One>::operator int();
// these don't
%rename(hello2) Bar<One>::operator Foo<oss::One>&();
%ignore Bar<One>::operator Foo<oss::One>();
template <Test T>
struct Bar {
operator int();
operator int&();
operator Foo<T>();
operator Foo<T>&();
};
}
namespace oss
{
%template(Foo_One) Foo<One>;
%template(Bar_One) Bar<One>;
}

View file

@ -0,0 +1,22 @@
/* This interface file checks whether the SWIG parses the throw
directive in combination with the const directive. Bug reported by
Scott B. Drummonds, 08 June 2001.
*/
%module cplusplus_throw
%pragma no_default
%inline %{
class Foo { };
class Bar {
public:
void baz() const { };
void foo() throw (Foo) { };
void bazfoo() const throw (int) { };
};
%}

View file

@ -0,0 +1,27 @@
/*
The primary purpose of this testcase is to ensure that enums used along with the 'enum' keyword compile under c++.
*/
%module cpp_enum
%inline %{
enum SOME_ENUM {ENUM_ONE, ENUM_TWO};
struct StructWithEnums {
StructWithEnums() : some_enum(ENUM_ONE) {};
enum SOME_ENUM some_enum;
void enum_test1(enum SOME_ENUM param1, enum SOME_ENUM* param2, enum SOME_ENUM& param3) {};
void enum_test2(SOME_ENUM param1, SOME_ENUM* param2, SOME_ENUM& param3) {};
SOME_ENUM enum_test3() { return ENUM_ONE; };
enum SOME_ENUM enum_test4() { return ENUM_TWO; };
SOME_ENUM* enum_test5() { return &some_enum; };
enum SOME_ENUM* enum_test6() { return &some_enum; };
SOME_ENUM& enum_test7() { return some_enum; };
enum SOME_ENUM& enum_test8() { return some_enum; };
};
%}

View file

@ -0,0 +1,17 @@
%module cpp_enum_scope
// This tests to make sure default arguments are handled correctly
// when scoped.
%inline %{
enum flavor { BITTER, SWEET };
class Foo {
public:
enum speed { FAST, SLOW };
// Note: default values should be Foo::FAST and SWEET
void blah(speed s = FAST, flavor f = SWEET) {};
};
%}

View file

@ -0,0 +1,104 @@
// C++ namespace tests
%module cpp_namespace
%inline %{
typedef int Bad;
/* A very basic namespace */
namespace example {
typedef char *Bad;
int fact(int n) {
if (n <= 0) return 1;
else return n*fact(n-1);
}
int Foo = 42;
class Test {
public:
Test() { };
~Test() { };
char *method() {
return (char *) "Test::method";
}
};
typedef Test *TestPtr;
void weird(Bad x, ::Bad y) { };
}
char *do_method(example::TestPtr t) {
return t->method();
}
namespace ex = example;
char *do_method2(ex::TestPtr t) {
return t->method();
}
%}
// Some more complicated namespace examples
%inline %{
namespace Foo {
typedef int Integer;
class Test2 {
public:
virtual char *method() {
return (char *) "Test2::method";
}
};
typedef Test2 *Test2Ptr;
}
namespace Foo2 {
using Foo::Integer;
using Foo::Test2;
class Test3 : public Test2 {
public:
virtual char *method() {
return (char *) "Test3::method";
}
};
typedef Test3 *Test3Ptr;
typedef Test3 Test3Alt;
}
namespace Foo3 {
using namespace Foo2;
class Test4 : public Test3 {
public:
virtual char *method() {
return (char *) "Test4::method";
}
};
Integer foo3(Integer x) { return x; }
typedef Test4 *Test4Ptr;
}
using Foo2::Test3Alt;
using Foo3::Integer;
class Test5 : public Test3Alt {
public:
virtual char *method() {
return (char *) "Test5::method";
}
};
char *do_method3(Foo::Test2 *t, Integer x) {
return t->method();
}
%}

View file

@ -0,0 +1,42 @@
// This file tests SWIG pass/return by value for
// a class with no default constructor
%module cpp_nodefault
%inline %{
class Foo {
public:
int a;
Foo(int x, int y) { }
~Foo() {
printf("Destroying foo\n");
}
};
Foo create(int x, int y) {
return Foo(x,y);
}
typedef Foo Foo_t;
void consume(Foo f, Foo_t g) {}
class Bar {
public:
void consume(Foo f, Foo_t g) {}
Foo create(int x, int y) {
return Foo(x,y);
}
};
%}
%{
Foo gvar = Foo(3,4);
%}
Foo gvar;

View file

@ -0,0 +1,24 @@
/*
Testcase to test c++ static member variables and static functions.
Tests Sourceforge bug #444748.
*/
%module cpp_static
%inline %{
class StaticMemberTest {
public:
static int static_int;
};
class StaticFunctionTest {
public:
static void static_func() {};
};
%}
%{
int StaticMemberTest::static_int;
%}

View file

@ -0,0 +1,46 @@
// This file tests SWIG's tracking of C++ typedef declarations
%module cpp_typedef
%{
class Bar {
public:
};
%}
%inline %{
class Foo {
public:
typedef Bar SomeBar;
typedef SomeBar SomeOtherBar;
SomeOtherBar bar() {
SomeOtherBar b;
return b;
}
static SomeOtherBar sbar() {
SomeOtherBar b;
return b;
}
};
// Test that the correct types are used for typedef struct declarations
typedef struct {
} UnnamedStruct;
typedef struct NamedStruct {
} TypedefNamedStruct;
typedef TypedefNamedStruct DoubleTypedef;
class Test {
public:
UnnamedStruct test1(UnnamedStruct a) {return a;};
struct NamedStruct test2(struct NamedStruct a) {return a;};
TypedefNamedStruct test3(TypedefNamedStruct a) {return a;};
DoubleTypedef test4(DoubleTypedef a) {return a;};
};
%}

View file

@ -0,0 +1,6 @@
%module default_cast
%inline %{
void foo(const char *m = (const char *) NULL) { };
%}

View file

@ -0,0 +1,109 @@
// This module tests default constructor generation under a
// number of different conditions
%module default_constructor
%warnfilter(802, 813) EB; /* Ruby, Java multiple inheritance */
%warnfilter(802, 813) AD; /* Ruby, Java multiple inheritance */
%warnfilter(510) F; /* friend function */
%inline %{
/* A class with a public default constructor */
class A {
public:
A() { };
};
/* This class should get default constructor/destructors */
class AA : public A {
};
/* A class with a public constructor, but not default */
class B {
private:
B() { }
public:
B(int x, int y) { }
};
/* This class should get no default constructor, but a destructor */
class BB : public B {
};
/* A class with a protected constructor */
class C {
protected:
C() { };
public:
};
/* This class does get a default constructor/destructor */
class CC : public C {
};
/* A class with a private constructor */
class D {
private:
D() { };
public:
void foo() { };
};
/* This class does not get a default constructor */
class DD: public D {
};
/* No default constructor. A is okay, but D is not */
class AD: public A, public D {
};
/* This class has a default constructor because of optional arguments */
class E {
public:
E(int x = 0, int y = 0) { }
};
/* This should get a default constructor */
class EE : public E {
};
/* This class should not get a default constructor. B doesn't have one */
class EB : public E, public B {
};
/* A class with a private destructor */
class F {
private:
~F() { }
public:
void foo(int, int) { }
friend void bar(F *);
};
void bar(F *) { }
class FFF : public F {
};
/* A class with a protected destructor */
class G {
protected:
~G() { }
};
class GG : public G {
};
%}

View file

@ -0,0 +1,23 @@
%module default_ns
%inline %{
namespace AType
{
enum AType
{
NoType
};
}
void dummy(AType::AType aType = AType::NoType) {}
namespace A {
namespace B {
int CONST_NUM = 10;
}
int function(int i = B::CONST_NUM) { return 0; }
}
%}

View file

@ -0,0 +1,12 @@
%module default_ref
%inline %{
#include <string>
void test1(const int &x = 42) {
}
void test2(const std::string &x = "hello") {
}
%}

View file

@ -0,0 +1,22 @@
/*
This testcase tests operators for defines
*/
%module defineop
#define A1 1 + 2
#define A2 3 - 4
#define A3 5 * 6
#define A4 7 / 8
#define A5 9 >> 10
#define A6 11 << 12
#define A7 13 & 14
#define A8 15 | 16
#define A9 17 ^ 18
#define A10 19 && 20
#define A11 21 || 21
#define A12 ~22
#define A13 !23

View file

@ -0,0 +1,18 @@
/*
This testcase tests for embedded defines and embedded %constants
*/
%module defines
%pragma make_default
%inline %{
typedef struct EmbeddedDefines {
int dummy;
#define EMBEDDED_DEFINE 44
#ifdef SWIG
%constant EMBEDDED_SWIG_CONSTANT = 55;
#endif
} EmbeddedDefines;
%}

View file

@ -0,0 +1,65 @@
/* File : example.i */
%module dynamic_cast
#ifndef SWIGJAVA
%apply SWIGTYPE *DYNAMIC { Foo * };
#endif
%inline %{
class Foo {
public:
virtual Foo *blah() {
return this;
}
};
%}
#ifdef SWIGJAVA
%typemap(out) Foo *blah {
Bar *downcast = dynamic_cast<Bar *>($1);
*(Bar **)&$result = downcast;
}
%typemap(javaout) Foo * {
return new Bar($jnicall, $owner);
}
#endif
%inline %{
class Bar : public Foo {
public:
virtual Foo *blah() {
return (Foo *) this;
}
virtual char * test() {
return (char *) "Bar::test";
}
};
char *do_test(Bar *b) {
return b->test();
}
%}
#ifndef SWIGJAVA
// A general purpose function for dynamic casting of a Foo *
%{
static swig_type_info *
Foo_dynamic(void **ptr) {
Bar *b;
b = dynamic_cast<Bar *>((Foo *) *ptr);
if (b) {
*ptr = (void *) b;
return SWIGTYPE_p_Bar;
}
return 0;
}
%}
// Register the above casting function
DYNAMIC_CAST(SWIGTYPE_p_Foo, Foo_dynamic);
#endif

View file

@ -0,0 +1,26 @@
/* Test whether anonymous enums are supported well. */
%module "enum"
%inline %{
typedef enum {
CSP_ITERATION_FWD,
CSP_ITERATION_BWD
} foo1;
typedef enum foo2 {
ABCDE = 0,
FGHJI = 1
} foo3;
void
bar1(foo1 x) {}
void
bar2(enum foo2 x) {}
void
bar3(foo3 x) {}
%}

View file

@ -0,0 +1,16 @@
%module enum_scope
#ifdef SWIGPHP
// php internal naming conflict
%rename (chops) chop;
#endif
%inline %{
class Tree {
public:
enum types {Oak, Fir, Cedar};
void chop(enum types type) {}
};
enum Tree::types chop(enum Tree::types type) { return type; }
%}

View file

@ -0,0 +1,20 @@
%module enum_scope_template
#ifdef SWIGPHP
// php internal naming conflict
%rename (chops) chop;
#endif
%inline %{
template<class T> class Tree {
public:
enum types {Oak, Fir, Cedar};
void chop(enum types type) {}
};
enum Tree<int>::types chop(enum Tree<int>::types type) { return type; }
%}
%template(TreeInt) Tree<int>;

View file

@ -0,0 +1,8 @@
%module enum_var
%inline %{
enum Fruit { APPLE, PEAR };
Fruit test;
%}

View file

@ -0,0 +1,4 @@
%module xxx
%name() int foo;

View file

@ -0,0 +1,5 @@
%module xxx
%native(foo) int foo;

View file

@ -0,0 +1,8 @@
%module xxx
int class(int x);

View file

@ -0,0 +1,4 @@
%module xxx
int foo(int x = 42 || 3);

View file

@ -0,0 +1,8 @@
%module xxx
int foo(%val int *x, %out int *y);

View file

@ -0,0 +1,4 @@
%module xxx
int foo(int x = '');

View file

@ -0,0 +1,7 @@
%module xxx
enum stuff {
FOO = 'x',
BAR = 3.14159
};

View file

@ -0,0 +1,8 @@
%module xxx
int foo(int x);
%}

View file

@ -0,0 +1,7 @@
%module xxx
int foo(int);
}

View file

@ -0,0 +1,6 @@
%module xxx
int foo(unsigned unsigned int x);
int bar(signed signed y);
int spam(unsigned signed int x);

View file

@ -0,0 +1,3 @@
%module xxx
%insert("header") "missing_file.i";

View file

@ -0,0 +1,6 @@
%module xxx
int foo(long short x);
int bar(short long y);
int spam(long long long x);
int grok(short short int x);

View file

@ -0,0 +1,10 @@
%module xxx
int foo(int x) {
int y;

View file

@ -0,0 +1,4 @@
%module xxx
int foo(int)
int bar(int,int);

View file

@ -0,0 +1,20 @@
%module xxx
int foo(int x, int y);
int foo;
int bar(int x);
struct bar {
int y;
};
%rename(bar) spam;
int spam(int);

View file

@ -0,0 +1,3 @@
%module xxx
int foo(int x, ...);

View file

@ -0,0 +1,7 @@
%module xxx
%varargs(0,int x = 0) foo;
int foo(int x, ...);

View file

@ -0,0 +1,7 @@
%module xxx
extern "INTERCAL" {
int foo(int);
};
extern "INTERCAL" int blah(int);

View file

@ -0,0 +1,23 @@
%module xxx
%extend foo {
int bar() {
}
};
struct foo {
int bar();
int spam();
};
%extend foo {
int spam();
};

View file

@ -0,0 +1,6 @@
%module xxx
%extend foo {
int bar() {
}
};

View file

@ -0,0 +1,7 @@
%module xxx
namespace foo {
%inline %{
int bar(int x) { }
%}
}

View file

@ -0,0 +1,11 @@
%module xxx
int foo(vector<int);

View file

@ -0,0 +1,14 @@
%module xxx
namespace blah {
}
namespace B = blah;
namespace B {
}

View file

@ -0,0 +1,4 @@
%module xxx
int blah;
namespace B = blah;

View file

@ -0,0 +1,3 @@
%module xxx
namespace B = blah;

View file

@ -0,0 +1,13 @@
%module xxx
class Foo {
public:
class Bar {
};
};
class Spam {
public:
class Grok {
} x;
};

View file

@ -0,0 +1,4 @@
%module xxx
class Bar : foo {
};

View file

@ -0,0 +1,7 @@
%module xxx
class Foo : public Bar {
};
class Spam : public Bar<int> {
};

View file

@ -0,0 +1,15 @@
%module xxx
int foo(int x);
int foo(double x);
class Foo {
public:
int bar(int);
int bar(double);
};
class Spam {
public:
Spam();
Spam(int);
};

View file

@ -0,0 +1,7 @@
%module xxx
class foo {
static const int BAR = 42;
public:
int blah(int x = BAR);
};

View file

@ -0,0 +1,11 @@
%module xxx
class Foo {
};
class Bar : private Foo {
};
class Spam : protected Foo {
};

View file

@ -0,0 +1,8 @@
%module xxx
template<T> T blah(T x);

View file

@ -0,0 +1,10 @@
%module xxx
template<typename T> T blah(T x) { };
%template(blahi) blah<int,double>;
%template(blahf) blah<>;

View file

@ -0,0 +1,9 @@
%module xxx
int blah;
%template(blahi) blah<int>;

View file

@ -0,0 +1,4 @@
%module xxx
template<class T> class vector<T *> {
};

View file

@ -0,0 +1,7 @@
%module xxx
template<class T> T blah(T x) { };
%template(iblah) blah<int>;
%template(iiblah) blah<int>;

View file

@ -0,0 +1,7 @@
%module xxx
%template(blahi) blah<int>;

View file

@ -0,0 +1,9 @@
%module xxx
int blah;
using namespace blah;

View file

@ -0,0 +1,9 @@
%module xxx
using foo::bar;
using namespace foo;

View file

@ -0,0 +1,103 @@
#!/bin/sh
echo "---------------------------------------"
echo "Testing SWIG error and warning messages"
echo "---------------------------------------"
SWIG='../../../swig -I../../../Lib'
# Files run in C mode
CFILES='
c_bad_name
c_bad_native
c_class
c_default_error
c_deprecated
c_empty_char
c_enum_badvalue
c_extra_rblock
c_extra_rbrace
c_extra_unsigned
c_insert_missing
c_long_short
c_missing_rbrace
c_missing_semi
c_redefine
c_varargs
c_varargs_neg
nomodule
pp_badeval
pp_defined
pp_macro_args
pp_macro_badchar
pp_macro_nargs
pp_macro_redef
pp_macro_rparen
pp_macro_unterminated
pp_misplaced_elif
pp_misplaced_else
pp_missing_enddef
pp_missing_endif
pp_missing_file
pp_missing_rblock
pp_unterm_char
pp_unterm_comment
pp_unterm_string
swig_apply_nargs
swig_identifier
swig_insert_bad
swig_typemap_copy
swig_typemap_old
'
# Files run in C++ mode
CPPFILES='
cpp_bad_extern
cpp_extend_redefine
cpp_extend_undefined
cpp_inline_namespace
cpp_missing_rtemplate
cpp_namespace_alias
cpp_namespace_aliasnot
cpp_namespace_aliasundef
cpp_nested
cpp_no_access
cpp_nobase
cpp_overload
cpp_private_defvalue
cpp_private_inherit
cpp_template_argname
cpp_template_nargs
cpp_template_not
cpp_template_partial
cpp_template_repeat
cpp_template_undef
cpp_using_not
cpp_using_undef
'
LOGFILE='test.log'
SWIGOPT=$*
rm -f ${LOGFILE}
echo "SWIG error and warning test. opts=${SWIGOPT}" >> ${LOGFILE}
echo "-----------------------------------------------------------" >> ${LOGFILE}
for i in ${CFILES}; do
echo " Testing : ${i}.i";
echo "" >> ${LOGFILE};
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
${SWIG} -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
done
for i in ${CPPFILES}; do
echo " Testing : ${i}.i";
echo "" >> ${LOGFILE}
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
${SWIG} -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
done
echo ""
echo "Results written to '${LOGFILE}'"

View file

@ -0,0 +1,2 @@
/* No module name */
int foo(int);

View file

@ -0,0 +1,11 @@
%module xxx
#if FOO==4
#elif FOO==4+
#endif

View file

@ -0,0 +1,7 @@
%module xxx
#if defined()
#endif
#if defined
#endif

View file

@ -0,0 +1,7 @@
%module xxx
#define foo(a,x) a x
#if foo
#endif

View file

@ -0,0 +1,5 @@
%module xxx
#define f@oo(a,x) a + x
#define foo(a@,x) a + x

View file

@ -0,0 +1,16 @@
%module xxx
#define foo(a,x) a x
#define bar(x) x
#define spam() /**/
foo(3)
foo(3,4,5)
bar()
bar(2,3)
spam(1)

View file

@ -0,0 +1,8 @@
%module xxx
#define foo(a,x) a+x
#define foo 4
/* Should not generate an error */
#define foo 4

View file

@ -0,0 +1,3 @@
%module xxx
#define foo(a,x 3

View file

@ -0,0 +1,7 @@
%module xxx
#define foo(a,x) a+x
foo(3,

View file

@ -0,0 +1,7 @@
%module xxx
#elif foo == 3
int x;
#endif

View file

@ -0,0 +1,7 @@
%module xxx
#else
int x;
#endif

View file

@ -0,0 +1,7 @@
%module xxx
%define FOO
int x;

View file

@ -0,0 +1,6 @@
%module xxx
#ifdef FOO
int x;

View file

@ -0,0 +1,3 @@
%module test
%include "missing_filename.i"

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