Merge trunk (up to just after swig 2.0.5 release - rev 13009) to gsoc2008-cherylfoil

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13017 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-04-27 18:55:37 +00:00
commit af1c6ac3c3
1811 changed files with 94580 additions and 35569 deletions

View file

@ -2,10 +2,12 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, Java, PHP multiple inheritance */
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, D, Java, PHP multiple inheritance */
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */
%inline %{
#if defined(_MSC_VER)

View file

@ -9,116 +9,75 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
# these cpp tests generate warnings/errors when compiling
# the wrapper .cxx file.
CPP_TEST_BROKEN_CXX =
# the error is wrap:action code generated by swig. \
# error: can't convert [std::string] 'b' to 'bool' \
# might just need a bool overload op for std::string. \
global_vars \
# same as w/ global_vars but with more errors in cxx file \
naturalvar \
# these cpp tests aren't working. Fix 'em
# need to further separate these into tests requiring
# std libraries, or the $ldestructor problem.
CPP_TEST_BROKEN_ACL = \
array_member \
char_strings \
class_ignore \
constant_pointers \
contract \
allprotected \
# 'throws' typemap entries. \
cplusplus_throw \
cpp_basic \
cpp_enum \
cpp_typedef \
default_constructor \
# 'throws' typemap entries. \
default_args \
# missing typemaps. suspect module support needed \
dynamic_cast \
enum_thorough \
extend_variable \
global_vars \
import_nomodule \
kind \
li_carrays \
# cdata.i support needed \
li_cdata \
li_windows \
namespace_class \
namespace_spaces \
naturalvar \
# warning generated. otherwise all good. \
operator_overload \
overload_simple \
register_par \
# std_common.i support \
sizet \
smart_pointer_extend \
smart_pointer_namespace \
template \
template_classes \
# std_vector.i support. \
template_default \
template_default_inherit \
template_enum \
template_explicit \
template_extend_overload \
template_ns \
template_ns4 \
template_ns_enum \
template_rename \
template_retvalue \
template_static \
template_tbase_template \
template_typedef \
template_typedef_cplx \
template_typedef_cplx2 \
template_typedef_cplx3 \
template_typedef_cplx4 \
template_typedef_cplx5 \
template_typedef_ns \
template_typedef_rec \
threads \
typedef_array_member \
typedef_sizet \
# *** line 31. can't copy typemap?? \
typemap_namespace \
union_scope \
using_pointers \
valuewrapper_opaque \
varargs \
virtual_poly \
voidtest \
wrapmacro
# these aren't working due to longlong support. (low hanging fruit)
CPP_TEST_BROKEN_LONGLONG = \
arrays_dimensionless \
arrays_global \
arrays_global_twodim \
li_stdint \
li_typemaps \
li_windows \
long_long_apply \
mixed_types \
primitive_ref \
reference_global_vars \
template_default_arg
# These are currently unsupported.
CPP_TEST_CASES_ACL_UNSUPPORTED = \
# contract support \
aggregate \
# directors support \
apply_signed_char \
# contract support \
contract \
director_abstract \
director_basic \
director_constructor \
director_detect \
director_default \
director_enum \
director_exception \
director_frob \
director_finalizer \
director_nested \
director_protected \
director_redefined \
director_unroll \
director_using \
director_wombat \
exception_order \
# 'throws' typemap support \
extern_throws \
throw_exception
throw_exception \
using_pointers \
C_TEST_CASES_ACL_BROKEN = \
arrays \
enums \
extern_declaration \
immutable \
integers \
# 'cdate.i' module support \
li_cdata \
# adding an existing type defnition... \
typedef_struct \
# swigrun.swg support. \
typemap_subst
C_TEST_BROKEN_LONGLONG = \
@ -128,12 +87,14 @@ C_TEST_BROKEN_LONGLONG = \
# std lib support hasn't been done yet.
SKIP_CPP_STD_CASES = Yes
C_TEST_CASES =
CPP_TEST_CASES =
include $(srcdir)/../common.mk
# Overridden variables here
# SWIGOPT += -debug-module 4
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
@ -153,13 +114,12 @@ include $(srcdir)/../common.mk
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.lisp appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(ALLEGROCLBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(ALLEGROCLBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean: (does nothing, we dont generate extra allegrocl code)
%.clean:
@rm -f $*.cl
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile allegrocl_clean

View file

@ -1,12 +1,43 @@
%module array_typedef_memberin
%inline %{
typedef short arr_short8[8];
typedef short Eight[8];
typedef const short ConstEight[8];
namespace ArrayExample
{
class ExampleDetail
{
public:
arr_short8 node_list;
};
Eight node_list;
#ifndef _MSC_VER
const Eight node_list2;
ConstEight node_list3;
#else
Eight node_list2;
Eight node_list3;
#endif
void fn1(Eight a) {}
void fn2(const Eight a) {}
void fn3(ConstEight a) {}
void fn4(Eight* a) {}
void fn5(ConstEight* a) {}
void fn6(const ConstEight* a) {}
void fn7(Eight*& a) {}
void fn8(ConstEight*& a) {}
void fn9(const ConstEight*& a) {}
};
}
typedef int Four[4];
typedef const int ConstFour[4];
void test_1(int (*v)[4]) {}
void test_2(Four *v) {}
void test_3(const Four *v) {}
void test_4(ConstFour *v) {}
void test_5(const int (*v)[4]) {}
void test_3r(const Four *&v) {}
void test_4r(ConstFour *&v) {}
%}

View file

@ -0,0 +1,135 @@
%module(docstring="hello") autodoc
%feature("autodoc");
// special typemap and its docs
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;";
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
// testing for different documentation levels
%feature("autodoc","0") A::func0; // names
%feature("autodoc","1") A::func1; // names + types
%feature("autodoc","2") A::func2; // extended
%feature("autodoc","3") A::func3; // extended + types
%feature("autodoc","0") A::func0default; // names
%feature("autodoc","1") A::func1default; // names + types
%feature("autodoc","2") A::func2default; // extended
%feature("autodoc","3") A::func3default; // extended + types
%feature("autodoc","0") A::func0static; // names
%feature("autodoc","1") A::func1static; // names + types
%feature("autodoc","2") A::func2static; // extended
%feature("autodoc","3") A::func3static; // extended + types
%feature("autodoc","0") A::variable_a; // names
%feature("autodoc","1") A::variable_b; // names + types
%feature("autodoc","2") A::variable_c; // extended
%feature("autodoc","3") A::variable_d; // extended + types
%feature("autodoc","just a string") A::funk; // names
%inline {
enum Hola {
hi, hello
};
struct A {
A(int a, short b, Hola h) {}
int funk(int a) { return a; }
int func0(short, int c, int d) { return c; }
int func1(short, int c, int d) { return c; }
int func2(short, int c, int d) { return c; }
int func3(short, int c, int d) { return c; }
int func0default(A *e, short, int c, int d, double f = 2) { return 0; }
int func1default(A *e, short, int c, int d, double f = 2) { return 0; }
int func2default(A *e, short, int c, int d, double f = 2) { return 0; }
int func3default(A *e, short, int c, int d, double f = 2) { return 0; }
static int func0static(A *e, short, int c, int d, double f = 2) { return 0; }
static int func1static(A *e, short, int c, int d, double f = 2) { return 0; }
static int func2static(A *e, short, int c, int d, double f = 2) { return 0; }
static int func3static(A *e, short, int c, int d, double f = 2) { return 0; }
int variable_a;
int variable_b;
int variable_c;
int variable_d;
};
}
// deleting typemaps and docs
%typemap(in) (int c, int d) ;
%typemap(doc) (int c, int d);
// docs for some parameters
%typemap(doc) int a "a: special comment for parameter a";
%typemap(doc) int b "b: another special comment for parameter b";
%feature("autodoc","0") C::C(int a, int b, Hola h); // names
%feature("autodoc","1") D::D(int a, int b, Hola h); // names + types
%feature("autodoc","2") E::E(int a, int b, Hola h); // extended
%feature("autodoc","3") F::F(int a, int b, Hola h); // extended + types
%inline {
struct B {
B(int a, int b, Hola h) {}
int funk(int c, int d) { return c; }
};
struct C {
C(int a, int b, Hola h) {}
};
struct D {
D(int a, int b, Hola h) {}
};
struct E {
E(int a, int b, Hola h) {}
};
struct F {
F(int a, int b, Hola h) {}
};
int funk(A *e, short, int c, int d) { return c; }
int funkdefaults(A *e, short, int c, int d, double f = 2) { return c; }
}
%include <typemaps.i>
%inline %{
int func_input(int *INPUT) {
return 1;
}
int func_output(int *OUTPUT) {
*OUTPUT = 2;
return 1;
}
int func_inout(int *INOUT) {
*INOUT += 1;
return 1;
}
%}
%callback("%(uppercase)s_CALLBACK") func_cb;
%inline {
int func_cb(int c, int d) { return c; }
}
// Bug 3310528
%feature("autodoc","1") banana; // names + types
%inline %{
typedef struct tagS {
int a;
char b;
} S;
typedef int Integer;
void banana(S *a, const struct tagS *b, int c, Integer d) {}
%}

View file

@ -0,0 +1,33 @@
%module catches
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
%}
%include <exception.i> // for throws(...) typemap
%catches(int, const char *, const ThreeException&) test_catches(int i);
%catches(int, ...) test_exception_specification(int i); // override the exception specification
%catches(...) test_catches_all(int i);
%inline %{
struct ThreeException {};
void test_catches(int i) {
if (i == 1) {
throw int(1);
} else if (i == 2) {
throw (const char *)"two";
} else if (i == 3) {
throw ThreeException();
}
}
void test_exception_specification(int i) throw(int, const char *, const ThreeException&) {
test_catches(i);
}
void test_catches_all(int i) {
test_catches(i);
}
%}

View file

@ -11,10 +11,14 @@ top_builddir = @top_builddir@
include $(srcdir)/../common.mk
# Overridden variables here
# no C++ tests for now
CPP_TEST_CASES =
#C_TEST_CASES +=
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
@ -34,9 +38,9 @@ CPP_TEST_CASES =
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.lisp appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CFFIBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CFFIBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean: (does nothing, we dont generate extra cffi code)
%.clean:

View file

@ -0,0 +1,29 @@
/*
A test case for testing non null terminated char pointers.
*/
%module char_binary
%apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) }
%inline %{
struct Test {
size_t strlen(const char *str, size_t len) {
return len;
}
};
typedef char namet[5];
namet var_namet;
typedef char* pchar;
pchar var_pchar;
%}
// Remove string handling typemaps and treat as pointer
%typemap(freearg) SWIGTYPE * ""
%apply SWIGTYPE * { char * }
%include "carrays.i"
%array_functions(char, pchar);

View file

@ -9,13 +9,19 @@ below.
%warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) global_char_array1; // Unable to set variable of type char[]
%warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) global_const_char; // Setting a const char * variable may leak memory.
#ifdef SWIG_ALLEGRO_CL
%{
#include <stdio.h>
%}
#endif
%{
#define OTHERLAND_MSG "Little message from the safe world."
#define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible."
static char *global_str = NULL;
const int UINT_DIGITS = 10; // max unsigned int is 4294967295
bool check(const char *str, unsigned int number) {
bool check(const char *const str, unsigned int number) {
static char expected[256];
sprintf(expected, "%s%d", OTHERLAND_MSG, number);
bool matches = (strcmp(str, expected) == 0);
@ -99,10 +105,28 @@ bool SetConstCharArrayStaticString(const char str[], unsigned int number) {
return check(static_str, number);
}
bool SetCharConstStaticString(char *const str, unsigned int number) {
static char static_str[] = CPLUSPLUS_MSG;
strcpy(static_str, str);
return check(static_str, number);
}
bool SetConstCharConstStaticString(const char *const str, unsigned int number) {
static char static_str[] = CPLUSPLUS_MSG;
strcpy(static_str, str);
return check(static_str, number);
}
// get set function
char *CharPingPong(char *str) {
return str;
}
char *CharArrayPingPong(char abcstr[]) {
return abcstr;
}
char *CharArrayDimsPingPong(char abcstr[16]) {
return abcstr;
}
// variables
char *global_char = NULL;
@ -143,6 +167,18 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG;
%inline %{
// char *& tests
char *&GetCharPointerRef() {
static char str[] = CPLUSPLUS_MSG;
static char *ptr = str;
return ptr;
}
bool SetCharPointerRef(char *&str, unsigned int number) {
static char static_str[] = CPLUSPLUS_MSG;
strcpy(static_str, str);
return check(static_str, number);
}
const char *&GetConstCharPointerRef() {
static const char str[] = CPLUSPLUS_MSG;
static const char *ptr = str;

View file

@ -19,74 +19,77 @@ SKIP_CPP_STD_CASES = Yes
CPP_TEST_CASES += li_std_string
EXTRA_TEST_CASES += ext_test.externaltest
EXTRA_TEST_CASES += chicken_ext_test.externaltest
include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -nounit
# Custom tests - tests with additional commandline options
# If there exists a PROXYSUFFIX runme file, we also generate the wrapper
# with the -proxy argument
%.cppproxy: SWIGOPT += -proxy
%.cppproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
%.cproxy: SWIGOPT += -proxy
%.cproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
%.multiproxy: SWIGOPT += -proxy -noclosuses
%.multiproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then ( \
$(MAKE) $*.cppproxy; ) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
$(MAKE) $*.cppproxy; \
fi
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then ( \
$(MAKE) $*.cproxy; ) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
$(MAKE) $*.cproxy; \
fi
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_testcase)
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then ( \
$(MAKE) $*.multiproxy; ) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(PROXYSUFFIX) ]; then \
$(MAKE) $*.multiproxy; \
fi
%.externaltest:
$(setup)
+$(swig_and_compile_external)
$(run_testcase)
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.scm appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CHICKEN_CSI) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
# If there exists a PROXYSUFFIX runme file, we also generate the wrapper
# with the -proxy argument
%.cppproxy: SWIGOPT += -proxy
%.cppproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
%.cppproxy:
echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
+$(swig_and_compile_cpp)
$(run_testcase)
%.cproxy: SWIGOPT += -proxy
%.cproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
%.cproxy:
echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
+$(swig_and_compile_c)
$(run_testcase)
%.multiproxy: SWIGOPT += -proxy -noclosuses
%.multiproxy: SCRIPTSUFFIX = $(PROXYSUFFIX)
%.multiproxy:
echo "$(ACTION)ing testcase $* (with run test) under chicken with -proxy"
+$(swig_and_compile_multi_cpp)
$(run_testcase)
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.scm appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CHICKEN_CSI) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean
%.clean:

View file

@ -1,4 +1,4 @@
(load "ext_test.so")
(load "chicken_ext_test.so")
(define a (test-create))

View file

@ -1,4 +1,4 @@
%module ext_test
%module chicken_ext_test
/* just use the imports_a.h header... for this test we only need a class */
%{

View file

@ -0,0 +1,10 @@
%module class_forward
%inline %{
struct A {
class B;
};
class C : public A {
};
%}

View file

@ -11,10 +11,14 @@ top_builddir = @top_builddir@
include $(srcdir)/../common.mk
# Overridden variables here
# no C++ tests for now
CPP_TEST_CASES =
#C_TEST_CASES +=
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
@ -34,9 +38,9 @@ CPP_TEST_CASES =
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.lisp appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CLISPBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(CLISPBIN) -batch -s $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean: (does nothing, we dont generate extra clisp code)
%.clean:

View file

@ -16,8 +16,8 @@
# b) Define rules for %.ctest, %.cpptest, %.multicpptest and %.clean.
# c) Define srcdir, top_srcdir and top_builddir (these are the
# equivalent to configure's variables of the same name).
# 3) One off special commandline options can be achieved by adding a
# test case to CUSTOM_TEST_CASES and defining rules to run and test.
# 3) One off special commandline options for a testcase can be added.
# See custom tests below.
#
# The 'check' target runs the testcases including SWIG invocation,
# C/C++ compilation, target language compilation (if any) and runtime
@ -28,12 +28,17 @@
# The 'clean' target cleans up.
#
# Note that the RUNTOOL, COMPILETOOL and SWIGTOOL variables can be used
# for # invoking tools for the runtime tests and target language
# compiler (eg javac) respectively. For example, valgrind can be used
# for memory checking of the runtime tests using:
# make RUNTOOL="valgrind --leak-check-full"
# for invoking tools for the runtime tests and target language
# compiler (eg javac), and on SWIG respectively. For example, valgrind
# can be used for memory checking of the runtime tests using:
# make RUNTOOL="valgrind --leak-check=full"
# and valgrind can be used when invoking SWIG using:
# make SWIGTOOL="valgrind --tool=memcheck"
# make SWIGTOOL="valgrind --tool=memcheck --trace-children=yes"
# Note: trace-children needed because of preinst-swig shell wrapper
# to the swig executable.
#
# An individual test run can be debugged easily:
# make director_string.cpptest RUNTOOL="gdb --args"
#
# The variables below can be overridden after including this makefile
#######################################################################
@ -59,36 +64,37 @@ CXXSRCS =
CSRCS =
TARGETPREFIX =
TARGETSUFFIX =
SWIGOPT = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$(LANGUAGE) -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE) -DSWIG_NOEXTRA_QUALIFICATION
INCLUDES = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$(LANGUAGE) -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
SWIGOPT = -outcurrentdir -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
INCLUDES = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
LIBS = -L.
LIBPREFIX = lib
ACTION = check
INTERFACEDIR = $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/
#
# Please keep test cases in alphabetical order.
# Note that any whitespace after the last entry in each list will break make
#
# Broken C++ test cases. (Can be run individually using make testcase.cpptest.)
# Broken C++ test cases. (Can be run individually using: make testcase.cpptest)
CPP_TEST_BROKEN += \
constants \
cpp_broken \
exception_partial_info \
extend_variable \
namespace_union \
nested_comment \
li_std_vector_ptr \
li_boost_shared_ptr_template \
overload_complicated \
template_default_pointer \
template_expr
# Broken C test cases. (Can be run individually using make testcase.ctest.)
# Broken C test cases. (Can be run individually using: make testcase.ctest)
C_TEST_BROKEN += \
tag_no_clash_with_variable
# C++ test cases. (Can be run individually using make testcase.cpptest.)
# C++ test cases. (Can be run individually using: make testcase.cpptest)
CPP_TEST_CASES += \
abstract_access \
abstract_inherit \
@ -113,11 +119,15 @@ CPP_TEST_CASES += \
arrays_global \
arrays_global_twodim \
arrays_scope \
autodoc \
bloody_hell \
bools \
catches \
cast_operator \
casts \
char_binary \
char_strings \
class_forward \
class_ignore \
class_scope_weird \
compactdefaultargs \
@ -128,6 +138,7 @@ CPP_TEST_CASES += \
constructor_exception \
constructor_explicit \
constructor_ignore \
constructor_rename \
constructor_value \
contract \
conversion \
@ -141,13 +152,16 @@ CPP_TEST_CASES += \
cpp_static \
cpp_typedef \
default_args \
default_arg_values \
default_constructor \
defvalue_constructor \
derived_byvalue \
derived_nested \
destructor_reprotected \
director_abstract \
director_alternating \
director_basic \
director_binary_string \
director_classes \
director_classic \
director_constructor \
@ -159,11 +173,14 @@ CPP_TEST_CASES += \
director_finalizer \
director_frob \
director_ignore \
director_keywords \
director_namespace_clash \
director_nspace \
director_nested \
director_overload \
director_primitives \
director_protected \
director_protected_overloaded \
director_redefined \
director_thread \
director_unroll \
@ -172,6 +189,7 @@ CPP_TEST_CASES += \
disown \
dynamic_cast \
empty \
enum_rename \
enum_scope_template \
enum_template \
enum_thorough \
@ -181,17 +199,24 @@ CPP_TEST_CASES += \
evil_diamond_prop \
exception_order \
extend \
extend_constructor_destructor \
extend_default \
extend_placement \
extend_template \
extend_template_ns \
extend_typedef_class \
extern_c \
extern_namespace \
extern_throws \
expressions \
features \
fragments \
friends \
funcptr_cpp \
fvirtual \
global_namespace \
global_ns_arg \
global_scope_types \
global_vars \
grouping \
ignore_parameter \
@ -202,19 +227,24 @@ CPP_TEST_CASES += \
inherit_target_language \
inherit_void_arg \
inline_initializer \
insert_directive \
keyword_rename \
kind \
langobj \
li_attribute \
li_boost_shared_ptr \
li_boost_shared_ptr_bits \
li_boost_shared_ptr_template \
li_carrays \
li_cdata \
li_cpointer \
li_stdint \
li_typemaps \
li_typemaps_apply \
li_windows \
long_long_apply \
memberin_extend \
member_funcptr_galore \
member_pointer \
member_template \
minherit \
@ -231,27 +261,38 @@ CPP_TEST_CASES += \
namespace_template \
namespace_typedef_class \
namespace_typemap \
namespace_union \
namespace_virtual_method \
nspace \
nspace_extend \
naturalvar \
nested_class \
nested_comment \
nested_workaround \
newobject1 \
null_pointer \
operator_overload \
operator_overload_break \
operator_pointer_ref \
operbool \
ordering \
overload_copy \
overload_method \
overload_extend \
overload_rename \
overload_return_type \
overload_simple \
overload_subtype \
overload_template \
overload_template_fast \
pointer_reference \
preproc_constants \
primitive_ref \
private_assign \
protected_rename \
pure_virtual \
redefined \
redefined_not \
refcount \
reference_global_vars \
register_par \
@ -260,6 +301,10 @@ CPP_TEST_CASES += \
rename3 \
rename4 \
rename_scope \
rename_simple \
rename_strip_encoder \
rename_pcre_encoder \
rename_pcre_enum \
restrict_cplusplus \
return_const_value \
return_value_scope \
@ -268,6 +313,7 @@ CPP_TEST_CASES += \
sizet \
smart_pointer_const \
smart_pointer_const2 \
smart_pointer_const_overload \
smart_pointer_extend \
smart_pointer_member \
smart_pointer_multi \
@ -280,19 +326,23 @@ CPP_TEST_CASES += \
smart_pointer_rename \
smart_pointer_simple \
smart_pointer_static \
smart_pointer_template_const_overload \
smart_pointer_templatemethods \
smart_pointer_templatevariables \
smart_pointer_typedef \
special_variables \
special_variable_macros \
static_array_member \
static_const_member \
static_const_member_2 \
struct_initialization_cpp \
struct_value \
template \
symbol_clash \
template_arg_replace \
template_arg_scope \
template_arg_typename \
template_array_numeric \
template_basic \
template_base_template \
template_classes \
template_const_ref \
@ -301,6 +351,7 @@ CPP_TEST_CASES += \
template_default2 \
template_default_arg \
template_default_class_parms \
template_default_class_parms_typedef \
template_default_inherit \
template_default_qualify \
template_default_vw \
@ -317,6 +368,8 @@ CPP_TEST_CASES += \
template_inherit_abstract \
template_int_const \
template_methods \
template_nested \
template_nested_typemaps \
template_ns \
template_ns2 \
template_ns3 \
@ -326,6 +379,8 @@ CPP_TEST_CASES += \
template_ns_inherit \
template_ns_scope \
template_partial_arg \
template_partial_specialization \
template_partial_specialization_typedef \
template_qualifier \
template_qualifier \
template_ref_type \
@ -338,19 +393,25 @@ CPP_TEST_CASES += \
template_tbase_template \
template_template_parameters \
template_typedef \
template_typedef_class_template \
template_typedef_cplx \
template_typedef_cplx2 \
template_typedef_cplx3 \
template_typedef_cplx4 \
template_typedef_cplx5 \
template_typedef_funcptr \
template_typedef_inherit \
template_typedef_ns \
template_typedef_ptr \
template_typedef_rec \
template_typemaps \
template_typemaps_typedef \
template_typemaps_typedef2 \
template_using \
template_virtual \
template_whitespace \
threads \
threads_exception \
throw_exception \
typedef_array_member \
typedef_class \
@ -361,9 +422,16 @@ CPP_TEST_CASES += \
typedef_scope \
typedef_sizet \
typedef_struct \
typemap_arrays \
typemap_delete \
typemap_global_scope \
typemap_manyargs \
typemap_namespace \
typemap_ns_using \
typemap_numinputs \
typemap_template \
typemap_out_optimal \
typemap_qualifier_strip \
typemap_variables \
typemap_various \
typename \
@ -375,6 +443,7 @@ CPP_TEST_CASES += \
using_extend \
using_inherit \
using_namespace \
using_namespace_loop \
using_pointers \
using_private \
using_protected \
@ -383,9 +452,12 @@ CPP_TEST_CASES += \
valuewrapper_const \
valuewrapper_opaque \
varargs \
varargs_overload \
virtual_destructor \
virtual_poly \
virtual_vs_nonvirtual_base \
voidtest \
wallkw \
wrapmacro
#
@ -394,16 +466,20 @@ CPP_TEST_CASES += \
CPP_STD_TEST_CASES += \
director_string \
ignore_template_constructor \
li_std_combinations \
li_std_deque \
li_std_except \
li_std_map \
li_std_pair \
li_std_string \
li_std_vector \
li_std_vector_enum \
naturalvar \
smart_pointer_inherit \
template_typedef_fnc \
template_type_namespace \
template_opaque
# li_std_list
ifndef SKIP_CPP_STD_CASES
@ -411,17 +487,18 @@ CPP_TEST_CASES += ${CPP_STD_TEST_CASES}
endif
# C test cases. (Can be run individually using make testcase.ctest.)
# C test cases. (Can be run individually using: make testcase.ctest)
C_TEST_CASES += \
arrays \
char_constant \
const_const \
constant_expr \
empty \
enums \
extern_declaration \
funcptr \
function_typedef \
immutable \
immutable_values \
inctest \
integers \
keyword_rename \
@ -433,34 +510,48 @@ C_TEST_CASES += \
li_cpointer \
li_math \
long_long \
memberin_extend_c \
name \
nested \
nested_structs \
newobject2 \
overload_extend \
overload_extendc \
preproc \
preproc_constants_c \
preproc_defined \
preproc_include \
preproc_line_file \
ret_by_value \
simple_array \
sizeof_pointer \
sneaky1 \
struct_rename \
struct_initialization \
typedef_struct \
typemap_subst \
union_parameter \
unions
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest.)
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
MULTI_CPP_TEST_CASES += \
clientdata_prop \
imports \
import_stl \
packageoption \
mod \
template_typedef_import \
multi_import
# Custom tests - tests with additional commandline options
wallkw.cpptest: SWIGOPT += -Wallkw
preproc_include.ctest: SWIGOPT += -includeall
NOT_BROKEN_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \
$(C_TEST_CASES:=.ctest) \
$(MULTI_CPP_TEST_CASES:=.multicpptest) \
$(CUSTOM_TEST_CASES:=.customtest) \
$(EXTRA_TEST_CASES)
BROKEN_TEST_CASES = $(CPP_TEST_BROKEN:=.cpptest) \
@ -469,7 +560,6 @@ BROKEN_TEST_CASES = $(CPP_TEST_BROKEN:=.cpptest) \
ALL_CLEAN = $(CPP_TEST_CASES:=.clean) \
$(C_TEST_CASES:=.clean) \
$(MULTI_CPP_TEST_CASES:=.clean) \
$(CUSTOM_TEST_CASES:=.clean) \
$(CPP_TEST_BROKEN:=.clean) \
$(C_TEST_BROKEN:=.clean)
@ -490,14 +580,14 @@ swig_and_compile_cpp = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACE="$*.i" \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)_cpp
swig_and_compile_c = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CSRCS="$(CSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACE="$*.i" \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)
swig_and_compile_multi_cpp = \
@ -505,7 +595,7 @@ swig_and_compile_multi_cpp = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACE="$$f.i" \
TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \
$(LANGUAGE)$(VARIANT)_cpp; \
done
@ -517,7 +607,7 @@ swig_and_compile_external = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS) $*_external.cxx" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACE="$*.i" \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)_cpp
swig_and_compile_runtime = \

View file

@ -0,0 +1,11 @@
%module constant_expr;
/* Tests of constant expressions. */
%inline %{
/* % didn't work in SWIG 1.3.40 and earlier. */
const int X = 123%7;
#define FOO 12 % 9
double d_array[12 % 9];
%}

View file

@ -5,6 +5,8 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is
%module constant_pointers
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */
%inline %{
@ -49,7 +51,7 @@ public:
private:
MemberVariablesTest& operator=(const MemberVariablesTest&);
};
void foo(const int *const i) {}
void foofunction(const int *const i) {}
typedef int *typedef1, typedef2, *const typedef3;
int int1, int2=2, *int3, *const int4 = &GlobalInt;
@ -70,6 +72,8 @@ public:
void ret6(int*& a) {}
int*& ret7() {return GlobalIntPtr;}
void ret8(int*const& a) {}
int*const& ret9() {return GlobalIntPtr;}
ReturnValuesTest() : int3(NULL) {}
private:
ReturnValuesTest& operator=(const ReturnValuesTest&);
@ -112,7 +116,7 @@ int* const globalRet2() {return &GlobalInt;}
return b;
}
B const*& cbar(B const*& b) {
B *const& cbar(B *const& b) {
return b;
}
}
@ -121,7 +125,8 @@ int* const globalRet2() {return &GlobalInt;}
%{
static int wxEVT_COMMAND_BUTTON_CLICKEDv;
static int **wxEVT_COMMAND_BUTTON_CLICKEDp;
static int *wxEVT_COMMAND_BUTTON_CLICKEDp;
static int **wxEVT_COMMAND_BUTTON_CLICKEDpp = &wxEVT_COMMAND_BUTTON_CLICKEDp;
#if defined(SWIGR)
#undef lang1 /* conflicts with symbol in R internals */
#endif
@ -137,7 +142,7 @@ char *langs[] ={ lang1 };
#define EWXWEXPORT_VAR
const int* wxEVENT_COMMAND_BUTTON_CLICKEDr = (int*) &wxEVT_COMMAND_BUTTON_CLICKEDv;
const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDp;
const int* wxEVENT_COMMAND_BUTTON_CLICKEDp = (int*) *wxEVT_COMMAND_BUTTON_CLICKEDpp;
char **languages1 = &langs[0];
char **languages2 = (char **)&langs[0];
}

View file

@ -73,10 +73,6 @@ public:
%include "std_vector.i"
#if defined(SWIGCSHARP)
SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(Flow, Space::Flow)
#endif
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
#define SWIG_GOOD_VECTOR
%ignore std::vector<Space::Flow>::vector(size_type);

View file

@ -0,0 +1,12 @@
%module constructor_rename
%{
struct Foo {
Foo() {}
};
%}
struct Foo {
%rename(RenamedConstructor) Foo();
Foo() {}
};

View file

@ -3,12 +3,17 @@
%warnfilter(SWIGWARN_RUBY_MULTIPLE_INHERITANCE,
SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, Java, PHP multiple inheritance */
SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, D, Java, PHP multiple inheritance */
#ifdef SWIGCSHARP
%ignore B::bar; // otherwise get a warning: `C.bar' no suitable methods found to override
#endif
#ifdef SWIGD
%ignore B::bar; // Prevents getting an error that C.bar does not override any function because multiple inheritance is not supported.
#endif
%contract test_preassert(int a, int b) {
require:
a > 0;
@ -201,3 +206,33 @@ struct E {
};
%}
// Namespace
%{
namespace myNames {
class myClass
{
public:
myClass(int i) {}
};
}
%}
namespace myNames {
%contract myClass::myClass( int i ) {
require:
i > 0;
}
class myClass
{
public:
myClass(int i) {}
};
}

View file

@ -8,6 +8,12 @@
%newobject Bar::testFoo;
%{
#if defined(__SUNPRO_CC)
#pragma error_messages (off, wbadasg) /* Assigning extern "C" ... */
#endif
%}
%inline %{
class Foo {

View file

@ -1,36 +1,6 @@
%module cpp_broken
// bug #1060789
%inline %{
#define MASK(shift, size) (((1 << (size)) - 1) << (shift))
#define SOME_MASK_DEF (80*MASK(8, 10))
%}
// bug #1060079
%inline %{
#define FIELD(name, width) unsigned int name:width
#define SOME_CONST 2
#define NEXT_CONST (2 * SOME_CONST)
typedef struct {
FIELD(a, SOME_CONST);
FIELD(b, NEXT_CONST);
} MyStruct_t;
%}
%{
#ifdef max
#undef max
#endif
%}
// bug #994301
%inline %{
#define max(a,b) ((a) > (b) ? (a) : (b))
%}
// bug #940318
%inline %{
typedef enum {
@ -40,36 +10,3 @@ eZero = 0
%}
// bug #754443
%inline %{
#define MAG_STYLE_BORDER_OFFS 0
#define MAG_STYLE_BORDER_BITS 3
#define MAG_STYLE_BORDER_MASK (((1UL<<MAG_STYLE_BORDER_BITS)-1)<<MAG_STYLE_BORDER_OFFS)
/* these CANNOT be combined */
#define MAG_STYLE_BORDER_NONE (1 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_STATIC (2 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_SIMPLE (3 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_RAISED (4 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_DOUBLE (5 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_DEFAULT MAG_STYLE_BORDER_SIMPLE
#define MAG_STYLE_CAPTION_OFFS ( MAG_STYLE_BORDER_OFFS + MAG_STYLE_BORDER_BITS )
#define MAG_STYLE_CAPTION_BITS 8
#define MAG_STYLE_CAPTION_MASK (((1UL<<MAG_STYLE_CAPTION_BITS)-1)<<MAG_STYLE_CAPTION_OFFS)
/* these CAN be combined */
#define MAG_STYLE_CAPTION_NONE ( 1 << ( 0 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_PRESENT ( 1 << ( 1 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_SYSMENU ( 1 << ( 2 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_MINIMIZE ( 1 << ( 3 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_MAXIMIZE ( 1 << ( 4 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_RESIZE ( 1 << ( 5 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_TINYHOR ( 1 << ( 6 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_TINYVER ( 1 << ( 7 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_DEFAULT ( MAG_STYLE_CAPTION_RESIZE + MAG_STYLE_CAPTION_MAXIMIZE + MAG_STYLE_CAPTION_MINIMIZE + MAG_STYLE_CAPTION_SYSMENU + MAG_STYLE_CAPTION_PRESENT )
%}

View file

@ -24,7 +24,6 @@ struct StructWithEnums {
enum SOME_ENUM& enum_test8() { return some_enum; };
};
struct Foo
{
enum {Hi, Hello } hola;
@ -41,3 +40,15 @@ extern "C"
}
%}
// Using true and false in enums is legal in C++. Quoting the standard:
// [dcl.enum]
// ... The constant-expression shall be of integral or enumeration type.
// [basic.fundamental]
// ... Types bool, char, wchar_t, and the signed and unsigned integer
// types are collectively called integral types.
// So this shouldn't lead to a warning, at least in C++ mode.
%inline %{
typedef enum { PLAY = true, STOP = false } play_state;
%}

View file

@ -26,9 +26,13 @@ public:
// Test that the correct types are used for typedef struct declarations
typedef struct {
int something;
void m() {}
} UnnamedStruct;
typedef struct NamedStruct {
int something;
void m() {}
} TypedefNamedStruct;
typedef TypedefNamedStruct DoubleTypedef;

View file

@ -5,28 +5,36 @@
LANGUAGE = csharp
SCRIPTSUFFIX = _runme.cs
INTERPRETER = @CSHARPCILINTERPRETER@
INTERPRETER_FLAGS = @CSHARPCILINTERPRETER_FLAGS@
CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@"
CSHARPCYGPATH_W = @CSHARPCYGPATH_W@
srcdir = @srcdir@
top_srcdir = @top_srcdir@/..
top_builddir = @top_builddir@/..
top_srcdir = ../@top_srcdir@
top_builddir = ../@top_builddir@
CPP_TEST_CASES = \
csharp_attributes \
csharp_exceptions \
csharp_features \
csharp_lib_arrays \
csharp_prepost \
csharp_typemaps \
enum_thorough_simple \
enum_thorough_typesafe \
exception_partial_info
CUSTOM_TEST_CASES = intermediary_classname
exception_partial_info \
intermediary_classname \
li_boost_intrusive_ptr
include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -namespace $*Namespace $(SWIGOPTSPECIAL)
SWIGOPT += -namespace $*Namespace
CSHARPFLAGSSPECIAL =
# Custom tests - tests with additional commandline options
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
# Rules for the different types of tests
%.cpptest:
@ -44,10 +52,6 @@ SWIGOPT += -namespace $*Namespace $(SWIGOPTSPECIAL)
+(cd $* && $(swig_and_compile_multi_cpp))
+$(run_testcase)
# Rules for custom tests
intermediary_classname.customtest:
$(MAKE) intermediary_classname.cpptest SWIGOPTSPECIAL="-dllimport intermediary_classname"
# Makes a directory for the testcase if it does not exist
setup = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
@ -56,31 +60,31 @@ setup = \
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
fi;
mkdir $*; \
fi
# Compiles C# files then runs the testcase. A testcase is only run if
# a file is found which has _runme.cs appended after the testcase name.
# Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX.
# DYLD_FALLBACK_LIBRARY_PATH is cleared for MacOSX.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \
CSHARPFLAGS='-nologo -out:$*_runme.exe' \
CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` \
$*$(CSHARPPATHSEPARATOR)*.cs' csharp_compile && \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; ) \
else ( \
CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \
CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(INTERPRETER) $(INTERPRETER_FLAGS) $*_runme.exe; \
else \
cd $* && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
CSHARPFLAGS='-nologo -t:module -out:$*.netmodule' \
CSHARPSRCS='*.cs' csharp_compile; ); \
fi;
CSHARPFLAGS='-nologo -debug+ $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \
CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \
fi
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
fi;
rm -rf $*; \
fi
clean:
@rm -f *.exe *.exe.mdb

0
Examples/test-suite/csharp/bools_runme.cs Executable file → Normal file
View file

View file

@ -0,0 +1,66 @@
using System;
using catchesNamespace;
public class runme {
static void Main() {
// test_catches()
try {
catches.test_catches(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ int exception thrown, value: 1")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_catches(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "two")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_catches(3);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ ThreeException const & exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
// test_exception_specification()
try {
catches.test_exception_specification(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ int exception thrown, value: 1")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_exception_specification(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_exception_specification(3);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
// test_catches_all()
try {
catches.test_catches_all(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
}
}

View file

@ -76,6 +76,16 @@ public class char_strings_runme {
throw new Exception("Test char set 6 failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetCharConstStaticString(OTHERLAND_MSG + i, i))
throw new Exception("Test char set 7 failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharConstStaticString(OTHERLAND_MSG + i, i))
throw new Exception("Test char set 8 failed, iteration " + i);
}
// get set function
for (i=0; i<count*10; i++) {
string ping = OTHERLAND_MSG + i;
@ -120,15 +130,26 @@ public class char_strings_runme {
// char *& tests
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
String str = char_strings.GetCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
if (!char_strings.SetCharPointerRef(OTHERLAND_MSG + i, i))
throw new Exception("Test char pointer ref set failed, iteration " + i);
}
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test const char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
throw new Exception("Test const char pointer ref set failed, iteration " + i);
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.ComponentModel;
using csharp_attributesNamespace;
public class runme
@ -171,6 +172,24 @@ public class runme
if (Attribute.GetCustomAttribute(member, typeof(Eurostar2Attribute)) == null)
throw new Exception("No attribute for " + member.Name);
}
// Enum value attributes
Type walesType = typeof(MoreStations.Wales);
{
MemberInfo member = (MemberInfo)walesType.GetMember("Cardiff")[0];
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
if (attribute == null)
throw new Exception("No attribute for " + member.Name);
if (attribute.Description != "Cardiff city station")
throw new Exception("Incorrect attribute value for " + member.Name);
}
{
MemberInfo member = (MemberInfo)walesType.GetMember("Swansea")[0];
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
if (attribute == null)
throw new Exception("No attribute for " + member.Name);
if (attribute.Description != "Swansea city station")
throw new Exception("Incorrect attribute value for " + member.Name);
}
// Enum csattribute typemap
{
Type cymrutype = typeof(Cymru);
@ -179,6 +198,8 @@ public class runme
if (tgv == null)
throw new Exception("No attribute for Cymru");
}
// No runtime test for directorinattributes and directoroutattributes
}
}
@ -237,3 +258,9 @@ public class ThreadSafeAttribute : Attribute {
public ThreadSafeAttribute() {}
}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class DirectorIntegerOutAttribute : Attribute {}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class DirectorIntegerInAttribute : Attribute {}

View file

@ -0,0 +1,70 @@
using System;
using csharp_lib_arraysNamespace;
public class runme
{
static void Main()
{
{
int[] source = { 1, 2, 3, 4, 5 };
int[] target = new int[ source.Length ];
csharp_lib_arrays.myArrayCopy( source, target, target.Length );
CompareArrays(source, target);
}
{
int[] source = { 1, 2, 3, 4, 5 };
int[] target = new int[ source.Length ];
csharp_lib_arrays.myArrayCopyUsingFixedArrays( source, target, target.Length );
CompareArrays(source, target);
}
{
int[] source = { 1, 2, 3, 4, 5 };
int[] target = new int[] { 6, 7, 8, 9, 10 };
csharp_lib_arrays.myArraySwap( source, target, target.Length );
for (int i=0; i<target.Length; ++i)
target[i] += 5;
CompareArrays(source, target);
}
{
int[] source = { 1, 2, 3, 4, 5 };
int[] target = new int[] { 6, 7, 8, 9, 10 };
csharp_lib_arrays.myArraySwapUsingFixedArrays( source, target, target.Length );
for (int i=0; i<target.Length; ++i)
target[i] += 5;
CompareArrays(source, target);
}
}
static void CompareArrays( int[] a, int[] b )
{
if (a.Length != b.Length)
throw new Exception("size mismatch");
for(int i=0; i<a.Length; ++i) {
if (a[i] != b[i]) {
Console.Error.WriteLine("a:");
PrintArray(a);
Console.Error.WriteLine("b:");
PrintArray(b);
throw new Exception("element mismatch");
}
}
}
static void PrintArray( int[] a )
{
foreach ( int i in a )
Console.Error.Write( "{0} ", i );
Console.Error.WriteLine();
}
}

View file

@ -55,6 +55,43 @@ public class csharp_prepost_runme {
throw new Exception("Expecting CustomInt attribute");
}
}
// Dates
{
// pre post typemap attributes example
System.DateTime dateIn = new System.DateTime(2011, 4, 13);
System.DateTime dateOut = new System.DateTime();
// Note in calls below, dateIn remains unchanged and dateOut
// is set to a new value by the C++ call
csharp_prepostNamespace.Action action = new csharp_prepostNamespace.Action(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
dateIn = new System.DateTime(2012, 7, 14);
action.doSomething(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
System.DateTime refDate = new System.DateTime(1999, 12, 31);
if (csharp_prepost.ImportantDate != refDate)
throw new Exception("dates wrong");
refDate = new System.DateTime(1999, 12, 31);
csharp_prepost.ImportantDate = refDate;
System.DateTime importantDate = csharp_prepost.ImportantDate;
if (importantDate != refDate)
throw new Exception("dates wrong");
System.DateTime christmasEve = new System.DateTime(2000, 12, 24);
csharp_prepost.addYears(ref christmasEve, 10);
if (christmasEve != new System.DateTime(2010, 12, 24))
throw new Exception("dates wrong");
Person person = new Person();
person.Birthday = christmasEve;
if (person.Birthday != christmasEve)
throw new Exception("dates wrong");
}
}
private static void Assert(double d1, double d2) {
if (d1 != d2)

View file

@ -0,0 +1,11 @@
using System;
using director_alternatingNamespace;
public class director_alternating_runme {
public static void Main() {
if (director_alternating.getBar().id() != director_alternating.idFromGetBar())
throw new Exception("idFromGetBar failed");
}
}

0
Examples/test-suite/csharp/director_classic_runme.cs Executable file → Normal file
View file

View file

@ -0,0 +1,32 @@
using System;
using director_nspaceNamespace;
public class bools_runme {
public static void Main() {
}
}
class director_nspace_MyBarFoo : director_nspaceNamespace.Bar.Foo {
public override String ping() {
return "director_nspace_MyBarFoo.ping();";
}
public override String pong() {
return "director_nspace_MyBarFoo.pong();" + ping();
}
public override String fooBar(director_nspaceNamespace.Bar.FooBar fooBar) {
return fooBar.FooBarDo();
}
public override director_nspaceNamespace.Bar.Foo makeFoo() {
return new director_nspaceNamespace.Bar.Foo();
}
public override director_nspaceNamespace.Bar.FooBar makeFooBar() {
return new director_nspaceNamespace.Bar.FooBar();
}
}

View file

@ -16,6 +16,7 @@ public class runme
Foo f = b.create();
FooBar fb = new FooBar();
FooBar2 fb2 = new FooBar2();
FooBar3 fb3 = new FooBar3();
String s;
s = fb.used();
@ -37,6 +38,21 @@ public class runme
s = fb.pong();
if ( s != ("Bar::pong();Foo::pong();FooBar::ping();"))
throw new Exception("bad FooBar::pong");
// if (fb3.cheer() != "FooBar3::cheer();")
// throw new Exception("bad fb3::cheer");
if (fb2.callping() != "FooBar2::ping();")
throw new Exception("bad fb2.callping");
if (fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();")
throw new Exception("bad fb2.callcheer");
if (fb3.callping() != "Bar::ping();")
throw new Exception("bad fb3.callping");
if (fb3.callcheer() != "FooBar3::cheer();")
throw new Exception("bad fb3.callcheer");
}
}
@ -69,4 +85,16 @@ class FooBar2 : Bar
}
}
class FooBar3 : Bar
{
public FooBar3() : base()
{
}
protected override String cheer()
{
return "FooBar3::cheer();";
}
}
}

63
Examples/test-suite/csharp/enum_thorough_runme.cs Executable file → Normal file
View file

@ -358,14 +358,75 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed");
}
{
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if ((int)enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed");
if ((int)enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed");
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed");
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if ((int)enum_thorough.repeatTest(repeat.one) != 1) throw new Exception("repeatTest 1 failed");
if ((int)enum_thorough.repeatTest(repeat.initial) != 1) throw new Exception("repeatTest 2 failed");
if ((int)enum_thorough.repeatTest(repeat.two) != 2) throw new Exception("repeatTest 3 failed");
if ((int)enum_thorough.repeatTest(repeat.three) != 3) throw new Exception("repeatTest 4 failed");
if ((int)enum_thorough.repeatTest(repeat.last) != 3) throw new Exception("repeatTest 5 failed");
if ((int)enum_thorough.repeatTest(repeat.llast) != 3) throw new Exception("repeatTest 5 failed");
if ((int)enum_thorough.repeatTest(repeat.end) != 3) throw new Exception("repeatTest 6 failed");
}
// different types
{
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typeint) != 10) throw new Exception("differentTypes 1 failed");
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typeboolfalse) != 0) throw new Exception("differentTypes 2 failed");
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typebooltrue) != 1) throw new Exception("differentTypes 3 failed");
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typebooltwo) != 2) throw new Exception("differentTypes 4 failed");
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typechar) != 'C') throw new Exception("differentTypes 5 failed");
if ((int)enum_thorough.differentTypesTest(DifferentTypes.typedefaultint) != 'D') throw new Exception("differentTypes 6 failed");
int global_enum = enum_thorough.global_typeint;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
global_enum = enum_thorough.global_typeboolfalse;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 0) throw new Exception("global differentTypes 2 failed");
global_enum = enum_thorough.global_typebooltrue;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 1) throw new Exception("global differentTypes 3 failed");
global_enum = enum_thorough.global_typebooltwo;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 2) throw new Exception("global differentTypes 4 failed");
global_enum = enum_thorough.global_typechar;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
global_enum = enum_thorough.global_typedefaultint;
if ((int)enum_thorough.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
}
}
}

View file

@ -358,14 +358,75 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed");
}
{
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed");
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_simple.repeatTest(enum_thorough_simple.one) != 1) throw new Exception("repeatTest 1 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.initial) != 1) throw new Exception("repeatTest 2 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.two) != 2) throw new Exception("repeatTest 3 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.three) != 3) throw new Exception("repeatTest 4 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.last) != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.llast) != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.end) != 3) throw new Exception("repeatTest 6 failed");
}
// different types
{
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typeint) != 10) throw new Exception("differentTypes 1 failed");
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typeboolfalse) != 0) throw new Exception("differentTypes 2 failed");
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typebooltrue) != 1) throw new Exception("differentTypes 3 failed");
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typebooltwo) != 2) throw new Exception("differentTypes 4 failed");
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typechar) != 'C') throw new Exception("differentTypes 5 failed");
if (enum_thorough_simple.differentTypesTest(enum_thorough_simple.typedefaultint) != 'D') throw new Exception("differentTypes 6 failed");
int global_enum = enum_thorough_simple.global_typeint;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
global_enum = enum_thorough_simple.global_typeboolfalse;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 0) throw new Exception("global differentTypes 2 failed");
global_enum = enum_thorough_simple.global_typebooltrue;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 1) throw new Exception("global differentTypes 3 failed");
global_enum = enum_thorough_simple.global_typebooltwo;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 2) throw new Exception("global differentTypes 4 failed");
global_enum = enum_thorough_simple.global_typechar;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
global_enum = enum_thorough_simple.global_typedefaultint;
if (enum_thorough_simple.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
}
}
}

View file

@ -358,14 +358,75 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero).swigValue != 0) throw new Exception("ignoreATest 0 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three).swigValue != 3) throw new Exception("ignoreATest 3 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten).swigValue != 10) throw new Exception("ignoreATest 10 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven).swigValue != 11) throw new Exception("ignoreATest 11 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen).swigValue != 13) throw new Exception("ignoreATest 13 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen).swigValue != 14) throw new Exception("ignoreATest 14 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty).swigValue != 20) throw new Exception("ignoreATest 20 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty).swigValue != 30) throw new Exception("ignoreATest 30 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two).swigValue != 32) throw new Exception("ignoreATest 32 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three).swigValue != 33) throw new Exception("ignoreATest 33 failed");
}
{
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven).swigValue != 11) throw new Exception("ignoreBTest 11 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve).swigValue != 12) throw new Exception("ignoreBTest 12 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one).swigValue != 31) throw new Exception("ignoreBTest 31 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two).swigValue != 32) throw new Exception("ignoreBTest 32 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one).swigValue != 41) throw new Exception("ignoreBTest 41 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two).swigValue != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten).swigValue != 10) throw new Exception("ignoreCTest 10 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve).swigValue != 12) throw new Exception("ignoreCTest 12 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty).swigValue != 30) throw new Exception("ignoreCTest 30 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two).swigValue != 32) throw new Exception("ignoreCTest 32 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty).swigValue != 40) throw new Exception("ignoreCTest 40 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two).swigValue != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if (enum_thorough_typesafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one).swigValue != 21) throw new Exception("ignoreDTest 21 failed");
if (enum_thorough_typesafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two).swigValue != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero).swigValue != 0) throw new Exception("ignoreETest 0 failed");
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one).swigValue != 21) throw new Exception("ignoreETest 21 failed");
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two).swigValue != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_typesafe.repeatTest(repeat.one).swigValue != 1) throw new Exception("repeatTest 1 failed");
if (enum_thorough_typesafe.repeatTest(repeat.initial).swigValue != 1) throw new Exception("repeatTest 2 failed");
if (enum_thorough_typesafe.repeatTest(repeat.two).swigValue != 2) throw new Exception("repeatTest 3 failed");
if (enum_thorough_typesafe.repeatTest(repeat.three).swigValue != 3) throw new Exception("repeatTest 4 failed");
if (enum_thorough_typesafe.repeatTest(repeat.last).swigValue != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed");
}
// different types
{
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typebooltrue).swigValue != 1) throw new Exception("differentTypes 2 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typebooltwo).swigValue != 2) throw new Exception("differentTypes 3 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeboolfalse).swigValue != 0) throw new Exception("differentTypes 4 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typechar).swigValue != (int)'C') throw new Exception("differentTypes 5 failed");
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typedefaultint).swigValue != (int)'D') throw new Exception("differentTypes 6 failed");
int global_enum = enum_thorough_typesafe.global_typeint;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
global_enum = enum_thorough_typesafe.global_typeboolfalse;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 0) throw new Exception("global differentTypes 2 failed");
global_enum = enum_thorough_typesafe.global_typebooltrue;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 1) throw new Exception("global differentTypes 3 failed");
global_enum = enum_thorough_typesafe.global_typebooltwo;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 2) throw new Exception("global differentTypes 4 failed");
global_enum = enum_thorough_typesafe.global_typechar;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'C') throw new Exception("global differentTypes 5 failed");
global_enum = enum_thorough_typesafe.global_typedefaultint;
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 'D') throw new Exception("global differentTypes 6 failed");
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using exception_orderNamespace;
public class runme {
static void Main() {
A a = new A();
try {
a.foo();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E1 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.bar();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E2 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.foobar();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "postcatch unknown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.barfoo(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E1 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.barfoo(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E2 * exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
}
}

View file

@ -0,0 +1,43 @@
using System;
using friendsNamespace;
public class friends_runme {
public static void Main() {
A a = new A(2);
if (friends.get_val1(a) != 2)
throw new Exception("failed");
if (friends.get_val2(a) != 4)
throw new Exception("failed");
if (friends.get_val3(a) != 6)
throw new Exception("failed");
// nice overload working fine
if (friends.get_val1(1,2,3) != 1)
throw new Exception("failed");
B b = new B(3);
// David's case
if (friends.mix(a,b) != 5)
throw new Exception("failed");
D_d di = new D_d(2);
D_d dd = new D_d(3.3);
// incredible template overloading working just fine
if (friends.get_val1(di) != 2)
throw new Exception("failed");
if (friends.get_val1(dd) != 3.3)
throw new Exception("failed");
friends.set(di, 4);
friends.set(dd, 1.3);
if (friends.get_val1(di) != 4)
throw new Exception("failed");
if (friends.get_val1(dd) != 1.3)
throw new Exception("failed");
}
}

View file

@ -0,0 +1,24 @@
using System;
using inherit_target_languageNamespace;
public class inherit_target_language_runme {
public static void Main() {
new Derived1().targetLanguageBaseMethod();
new Derived2().targetLanguageBaseMethod();
new MultipleDerived1().targetLanguageBaseMethod();
new MultipleDerived2().targetLanguageBaseMethod();
new MultipleDerived3().f();
new MultipleDerived4().g();
BaseX baseX = new BaseX();
baseX.basex();
baseX.targetLanguageBase2Method();
DerivedX derivedX = new DerivedX();
derivedX.basex();
derivedX.derivedx();
derivedX.targetLanguageBase2Method();
}
}

View file

@ -0,0 +1,78 @@
// Ported from Python li_attribute_runme.py
using System;
using li_attributeNamespace;
public class li_attribute_runme {
public static void Main() {
A aa = new A(1,2,3);
if (aa.a != 1)
throw new ApplicationException("error");
aa.a = 3;
if (aa.a != 3)
throw new ApplicationException("error");
if (aa.b != 2)
throw new ApplicationException("error");
aa.b = 5;
if (aa.b != 5)
throw new ApplicationException("error");
if (aa.d != aa.b)
throw new ApplicationException("error");
if (aa.c != 3)
throw new ApplicationException("error");
//aa.c = 5;
//if (aa.c != 3)
// throw new ApplicationException("error");
Param_i pi = new Param_i(7);
if (pi.value != 7)
throw new ApplicationException("error");
pi.value=3;
if (pi.value != 3)
throw new ApplicationException("error");
B b = new B(aa);
if (b.a.c != 3)
throw new ApplicationException("error");
// class/struct attribute with get/set methods using return/pass by reference
MyFoo myFoo = new MyFoo();
myFoo.x = 8;
MyClass myClass = new MyClass();
myClass.Foo = myFoo;
if (myClass.Foo.x != 8)
throw new ApplicationException("error");
// class/struct attribute with get/set methods using return/pass by value
MyClassVal myClassVal = new MyClassVal();
if (myClassVal.ReadWriteFoo.x != -1)
throw new ApplicationException("error");
if (myClassVal.ReadOnlyFoo.x != -1)
throw new ApplicationException("error");
myClassVal.ReadWriteFoo = myFoo;
if (myClassVal.ReadWriteFoo.x != 8)
throw new ApplicationException("error");
if (myClassVal.ReadOnlyFoo.x != 8)
throw new ApplicationException("error");
// string attribute with get/set methods using return/pass by value
MyStringyClass myStringClass = new MyStringyClass("initial string");
if (myStringClass.ReadWriteString != "initial string")
throw new ApplicationException("error");
if (myStringClass.ReadOnlyString != "initial string")
throw new ApplicationException("error");
myStringClass.ReadWriteString = "changed string";
if (myStringClass.ReadWriteString != "changed string")
throw new ApplicationException("error");
if (myStringClass.ReadOnlyString != "changed string")
throw new ApplicationException("error");
}
}

View file

@ -0,0 +1,20 @@
using System;
using li_boost_shared_ptr_bitsNamespace;
public class runme
{
static void Main()
{
VectorIntHolder v = new VectorIntHolder();
v.Add(new IntHolder(11));
v.Add(new IntHolder(22));
v.Add(new IntHolder(33));
int sum = li_boost_shared_ptr_bits.sum(v);
if (sum != 66)
throw new ApplicationException("sum is wrong");
HiddenDestructor hidden = HiddenDestructor.create();
hidden.Dispose();
}
}

View file

@ -345,6 +345,16 @@ public class runme
verifyCount(1, kret);
}
// 3rd derived class
{
Klass k = new Klass3rdDerived("me oh my");
String val = k.getValue();
verifyValue("me oh my-3rdDerived", val);
verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values
val = li_boost_shared_ptr.test3rdupcast(k);
verifyValue("me oh my-3rdDerived", val);
verifyCount(3, k);
}
////////////////////////////////// Member variables ////////////////////////////////////////
// smart pointer by value

View file

@ -0,0 +1,31 @@
using System;
using li_std_combinationsNamespace;
public class li_std_combinations_runme {
public static void Main() {
VectorPairIntString vpis = new VectorPairIntString();
vpis.Add(new PairIntString(123, "one hundred and twenty three"));
VectorString vs = new VectorString();
vs.Add("hi");
PairIntVectorString pivs = new PairIntVectorString(456, vs);
if (pivs.second[0] != "hi")
throw new ApplicationException("PairIntVectorString");
VectorVectorString vvs = new VectorVectorString();
vvs.Add(vs);
PairIntPairIntString pipis = new PairIntPairIntString(12, new PairIntString(3, "4"));
if (pipis.first != 12)
throw new ApplicationException("PairIntPairIntString");
PairDoubleString pds = new PairDoubleString(12.34, "okay");
VectorPairDoubleString vpds = new VectorPairDoubleString();
vpds.Add(pds);
// Check SWIG_STD_VECTOR_ENHANCED macro - it provides the Contains method
if (!vpds.Contains(pds))
throw new ApplicationException("VectorPairDoubleString");
}
}

View file

@ -0,0 +1,251 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* li_std_map_runme.cs
*
* SWIG C# tester for std_map.i
* Implementation by Yuval Baror (http://yuval.bar-or.org)
*
* This class tests all the functionality of the std_map.i wrapper.
* Upon successful testing, the main function doesn't print out anything.
* If any error is found - it will be printed on the screen.
* ----------------------------------------------------------------------------- */
using System;
using System.Collections.Generic;
using li_std_mapNamespace;
public class li_std_map_runme {
private static readonly int collectionSize = 20;
private static readonly int midCollection = collectionSize / 2;
public static void Main()
{
// Set up an int int map
StringIntMap simap = new StringIntMap();
for (int i = 0; i < collectionSize; i++)
{
int val = i * 18;
simap.Add(i.ToString(), val);
}
// Count property test
if (simap.Count != collectionSize)
throw new Exception("Count test failed");
// IsReadOnly property test
if (simap.IsReadOnly)
throw new Exception("IsReadOnly test failed");
// Item indexing test
simap["0"] = 200;
if (simap["0"] != 200)
throw new Exception("Item property test failed");
simap["0"] = 0 * 18;
// ContainsKey() test
for (int i = 0; i < collectionSize; i++)
{
if (!simap.ContainsKey(i.ToString()))
throw new Exception("ContainsKey test " + i + " failed");
}
// ContainsKey() test
for (int i = 0; i < collectionSize; i++)
{
if (!simap.Contains(new KeyValuePair<string, int>(i.ToString(), i * 18)))
throw new Exception("Contains test " + i + " failed");
}
// TryGetValue() test
int value;
bool rc = simap.TryGetValue("3", out value);
if (rc != true || value != (3 * 18))
throw new Exception("TryGetValue test 1 failed");
rc = simap.TryGetValue("-1", out value);
if (rc != false)
throw new Exception("TryGetValue test 2 failed");
// Keys and Values test
{
IList<string> keys = new List<string>(simap.Keys);
IList<int> values = new List<int>(simap.Values);
Dictionary<string, int> check = new Dictionary<string, int>();
if (keys.Count != collectionSize)
throw new Exception("Keys count test failed");
if (values.Count != collectionSize)
throw new Exception("Values count test failed");
for (int i = 0; i < keys.Count; i++)
{
if (simap[keys[i]] != values[i])
throw new Exception("Keys and values test failed for index " + i);
check.Add(keys[i], values[i]);
}
for (int i = 0; i < collectionSize; i++)
{
if (!check.ContainsKey(i.ToString()))
throw new Exception("Keys and Values ContainsKey test " + i + " failed");
}
}
// Add and Remove test
for (int i = 100; i < 103; i++)
{
simap.Add(i.ToString(), i * 18);
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
throw new Exception("Add test failed for index " + i);
simap.Remove(i.ToString());
if (simap.ContainsKey(i.ToString()))
throw new Exception("Remove test failed for index " + i);
}
for (int i = 200; i < 203; i++)
{
simap.Add(new KeyValuePair<string, int>(i.ToString(), i * 18));
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
throw new Exception("Add explicit test failed for index " + i);
simap.Remove(new KeyValuePair<string, int>(i.ToString(), i * 18));
if (simap.ContainsKey(i.ToString()))
throw new Exception("Remove explicit test failed for index " + i);
}
// Duplicate key test
try
{
simap.Add("3", 0);
throw new Exception("Adding duplicate key test failed");
}
catch (ArgumentException)
{
}
// CopyTo() test
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize];
simap.CopyTo(outputarray);
foreach (KeyValuePair<string, int> val in outputarray)
{
if (simap[val.Key] != val.Value)
throw new Exception("CopyTo (1) test failed, index:" + val.Key);
}
}
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[midCollection + collectionSize];
simap.CopyTo(outputarray, midCollection);
for (int i = midCollection; i < midCollection + collectionSize; i++)
{
KeyValuePair<string, int> val = outputarray[i];
if (simap[val.Key] != val.Value)
throw new Exception("CopyTo (2) test failed, index:" + val.Key);
}
}
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize - 1];
try
{
simap.CopyTo(outputarray);
throw new Exception("CopyTo (4) test failed");
}
catch (ArgumentException)
{
}
}
// Clear test
simap.Clear();
if (simap.Count != 0)
throw new Exception("Clear test failed");
// Test wrapped methods
for (int i = 1; i <= 5; i++)
{
simap[i.ToString()] = i;
}
double avg = li_std_map.valueAverage(simap);
if (avg != 3.0)
throw new Exception("Wrapped method valueAverage test failed. Got " + avg);
string keyStringified = li_std_map.stringifyKeys(simap);
if (keyStringified != " 1 2 3 4 5")
throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified);
// Test a map with a new complex type (Struct)
{
IntStructMap ismap = new IntStructMap();
for (int i = 0; i < 10; i++)
{
ismap.Add(i, new Struct(i * 10.1));
}
if (ismap.Count != 10)
throw new Exception("Count test on complex type map failed");
foreach (KeyValuePair<int, Struct> p in ismap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on complex type map failed for index " + p.Key);
}
}
// Test a map of pointers
{
IntStructPtrMap ispmap = new IntStructPtrMap();
for (int i = 0; i < 10; i++)
{
ispmap.Add(i, new Struct(i * 10.1));
}
if (ispmap.Count != 10)
throw new Exception("Count test on complex type pointer map failed");
foreach (KeyValuePair<int, Struct> p in ispmap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key);
}
}
{
IntStructConstPtrMap iscpmap = new IntStructConstPtrMap();
for (int i = 0; i < 10; i++)
{
iscpmap.Add(i, new Struct(i * 10.1));
}
if (iscpmap.Count != 10)
throw new Exception("Count test on complex type const pointer map failed");
foreach (KeyValuePair<int, Struct> p in iscpmap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key);
}
}
// Test complex type as key (Struct)
{
StructIntMap limap = new StructIntMap();
Struct s7 = new Struct(7);
Struct s8 = new Struct(8);
limap[s7] = 8;
if (limap[s7] != 8)
throw new Exception("Assignment test on complex key map failed");
if (!limap.ContainsKey(s7))
throw new Exception("Key test (1) on complex key map failed");
if (limap.ContainsKey(s8))
throw new Exception("Key test (2) on complex key map failed");
}
// All done
}
}

View file

@ -0,0 +1,27 @@
// This test tests all the methods in the C# collection wrapper
using System;
using li_std_vector_enumNamespace;
public class li_std_vector_enum_runme {
public static void Main() {
EnumVector ev = new EnumVector();
check((int)ev.nums[0], 10);
check((int)ev.nums[1], 20);
check((int)ev.nums[2], 30);
int expected = 10;
foreach (EnumVector.numbers val in ev.nums) {
check((int)val, expected);
expected += 10;
}
}
private static void check(int a, int b) {
if (a != b)
throw new ApplicationException("values don't match");
}
}

View file

@ -82,14 +82,17 @@ public class li_std_vector_runme {
} catch (ArgumentException) {
}
}
#if SWIG_DOTNET_1
{
// runtime check that 2D arrays fail
double[,] outputarray = new double[collectionSize,collectionSize];
try {
vect.CopyTo(outputarray);
throw new Exception("CopyTo (5) test failed");
throw new Exception("CopyTo (5a) test failed");
} catch (ArgumentException) {
}
}
#endif
{
StructVector inputvector = new StructVector();
int arrayLen = 10;
@ -150,10 +153,14 @@ public class li_std_vector_runme {
}
}
try {
new DoubleVector(null);
new DoubleVector((System.Collections.ICollection)null);
throw new Exception("ICollection constructor null test failed");
} catch (ArgumentNullException) {
}
{
// Collection initializer test, requires C# 3.0
// myDoubleVector = new DoubleVector() { 123.4, 567.8, 901.2 };
}
// IndexOf() test
for (int i=0; i<collectionSize; i++) {
@ -174,6 +181,13 @@ public class li_std_vector_runme {
throw new Exception("LastIndexOf non-existent test failed");
if (dv.LastIndexOf(33.3) != 6)
throw new Exception("LastIndexOf position test failed");
// Copy constructor test
DoubleVector dvCopy = new DoubleVector(dv);
for (int i=0; i<doubleArray.Length; i++) {
if (doubleArray[i] != dvCopy[i])
throw new Exception("Copy constructor failed, index:" + i);
}
}
{
// Repeat() test
@ -187,11 +201,22 @@ public class li_std_vector_runme {
throw new Exception("Repeat count test failed");
// Also tests enumerator
System.Collections.IEnumerator myEnumerator = dv.GetEnumerator();
while ( myEnumerator.MoveNext() ) {
if ((double)myEnumerator.Current != 77.7)
throw new Exception("Repeat test failed");
{
System.Collections.IEnumerator myEnumerator = dv.GetEnumerator();
while ( myEnumerator.MoveNext() ) {
if ((double)myEnumerator.Current != 77.7)
throw new Exception("Repeat (1) test failed");
}
}
#if !SWIG_DOTNET_1
{
System.Collections.Generic.IEnumerator<double> myEnumerator = dv.GetEnumerator();
while ( myEnumerator.MoveNext() ) {
if (myEnumerator.Current != 77.7)
throw new Exception("Repeat (2) test failed");
}
}
#endif
}
{
@ -516,6 +541,13 @@ public class li_std_vector_runme {
li_std_vector.halve_in_place(dvec);
}
// Dispose()
{
using (StructVector vs = new StructVector( new Struct[] { new Struct(0.0), new Struct(11.1) } ) )
using (DoubleVector vd = new DoubleVector( new double[] { 0.0, 11.1 } ) ) {
}
}
// More wrapped methods
{
RealVector v0 = li_std_vector.vecreal(new RealVector());

0
Examples/test-suite/csharp/li_std_wstring_runme.cs Executable file → Normal file
View file

View file

@ -0,0 +1,39 @@
using System;
public class runme
{
static void Main()
{
{
// constructors and destructors
nspace_extendNamespace.Outer.Inner1.Color color1 = new nspace_extendNamespace.Outer.Inner1.Color();
nspace_extendNamespace.Outer.Inner1.Color color = new nspace_extendNamespace.Outer.Inner1.Color(color1);
color1.Dispose();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendNamespace.Outer.Inner1.Color.colorStaticMethod(20.0);
nspace_extendNamespace.Outer.Inner1.Color created = nspace_extendNamespace.Outer.Inner1.Color.create();
created.Dispose();
}
{
// constructors and destructors
nspace_extendNamespace.Outer.Inner2.Color color2 = new nspace_extendNamespace.Outer.Inner2.Color();
nspace_extendNamespace.Outer.Inner2.Color color = new nspace_extendNamespace.Outer.Inner2.Color(color2);
color2.Dispose();
color2 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendNamespace.Outer.Inner2.Color.colorStaticMethod(20.0);
nspace_extendNamespace.Outer.Inner2.Color created = nspace_extendNamespace.Outer.Inner2.Color.create();
created.Dispose();
// Same class different namespaces
nspace_extendNamespace.Outer.Inner1.Color col1 = new nspace_extendNamespace.Outer.Inner1.Color();
nspace_extendNamespace.Outer.Inner2.Color col2 = nspace_extendNamespace.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
}
}
}

View file

@ -0,0 +1,76 @@
using System;
public class runme
{
static void Main()
{
// constructors and destructors
nspaceNamespace.Outer.Inner1.Color color1 = new nspaceNamespace.Outer.Inner1.Color();
nspaceNamespace.Outer.Inner1.Color color = new nspaceNamespace.Outer.Inner1.Color(color1);
color1.Dispose();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspaceNamespace.Outer.Inner1.Color.colorStaticMethod(20.0);
nspaceNamespace.Outer.Inner1.Color created = nspaceNamespace.Outer.Inner1.Color.create();
created.Dispose();
// class enums
nspaceNamespace.Outer.SomeClass someClass = new nspaceNamespace.Outer.SomeClass();
nspaceNamespace.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel();
if (channel != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission)
throw new ApplicationException("Transmission wrong");
// class anonymous enums
int val1 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal1;
int val2 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal2;
if (val1 != 0 || val2 != 0x22)
throw new ApplicationException("ColorEnumVal wrong");
// instance member variables
color.instanceMemberVariable = 123;
if (color.instanceMemberVariable != 123)
throw new ApplicationException("instance member variable failed");
// static member variables
nspaceNamespace.Outer.Inner1.Color.staticMemberVariable = 789;
if (nspaceNamespace.Outer.Inner1.Color.staticMemberVariable != 789)
throw new ApplicationException("static member variable failed");
if (nspaceNamespace.Outer.Inner1.Color.staticConstMemberVariable != 222)
throw new ApplicationException("static const member variable failed");
if (nspaceNamespace.Outer.Inner1.Color.staticConstEnumMemberVariable != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission)
throw new ApplicationException("static const enum member variable failed");
// check globals in a namespace don't get mangled with the nspaceNamespace option
nspaceNamespace.nspace.namespaceFunction(color);
nspaceNamespace.nspace.namespaceVar = 111;
if (nspaceNamespace.nspace.namespaceVar != 111)
throw new ApplicationException("global var failed");
// Same class different namespaces
nspaceNamespace.Outer.Inner1.Color col1 = new nspaceNamespace.Outer.Inner1.Color();
nspaceNamespace.Outer.Inner2.Color col2 = nspaceNamespace.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
// global enums
nspaceNamespace.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel();
if (outerChannel1 != nspaceNamespace.Outer.Inner1.Channel.Transmission1)
throw new ApplicationException("Transmission1 wrong");
nspaceNamespace.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel();
if (outerChannel2 != nspaceNamespace.Outer.Inner2.Channel.Transmission2)
throw new ApplicationException("Transmission2 wrong");
// turn feature off / ignoring
nspaceNamespace.Outer.namespce ns = new nspaceNamespace.Outer.namespce();
ns.Dispose();
nspaceNamespace.NoNSpacePlease nons = new nspaceNamespace.NoNSpacePlease();
nons.Dispose();
// Derived class
nspaceNamespace.Outer.Inner3.Blue blue3 = new nspaceNamespace.Outer.Inner3.Blue();
blue3.blueInstanceMethod();
nspaceNamespace.Outer.Inner4.Blue blue4 = new nspaceNamespace.Outer.Inner4.Blue();
blue4.blueInstanceMethod();
}
}

View file

View file

@ -7,8 +7,8 @@ public class runme
{
int f = overload_template.foo();
f += overload_template.max(3,4);
double b = overload_template.max(3.4,5.2);
f += overload_template.maximum(3,4);
double b = overload_template.maximum(3.4,5.2);
b++; // warning suppression
// mix 1

View file

@ -12,6 +12,9 @@ public class pointer_reference_runme {
Struct ss = new Struct(20);
pointer_reference.set(ss);
if (Struct.instance.value != 20) throw new Exception("set test failed");
if (pointer_reference.overloading(1) != 111) throw new Exception("overload test 1 failed");
if (pointer_reference.overloading(ss) != 222) throw new Exception("overload test 2 failed");
}
}

View file

@ -0,0 +1,70 @@
using System;
using System.Reflection;
using preproc_constants_cNamespace;
// Same as preproc_constants_c.i testcase, but bool types are int instead
public class runme {
static void Main() {
assert( typeof(int) == preproc_constants_c.CONST_INT1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_INT2.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT1.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT2.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT3.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT4.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG2.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG3.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG4.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG1.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG2.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG3.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG4.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG1.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG2.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG3.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG4.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE1.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE2.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE3.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE4.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE5.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE6.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_BOOL1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_BOOL2.GetType() );
assert( typeof(char) == preproc_constants_c.CONST_CHAR.GetType() );
assert( typeof(string) == preproc_constants_c.CONST_STRING1.GetType() );
assert( typeof(string) == preproc_constants_c.CONST_STRING2.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_BOOL.GetType() );
// assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_INT.GetType() );
assert( typeof(uint) == preproc_constants_c.INT_AND_UINT.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_LONG.GetType() );
assert( typeof(uint) == preproc_constants_c.INT_AND_ULONG.GetType() );
assert( typeof(long) == preproc_constants_c.INT_AND_LLONG.GetType() );
assert( typeof(ulong) == preproc_constants_c.INT_AND_ULLONG.GetType() );
assert( typeof(int ) == preproc_constants_c.BOOL_AND_BOOL.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_MULTIPLY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_DIVIDE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_PLUS.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_MINUS.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LSHIFT.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_RSHIFT.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LTE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_GTE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_INEQUALITY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_EQUALITY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_AND.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_XOR.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_OR.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
}
static void assert(bool assertion) {
if (!assertion)
throw new ApplicationException("test failed");
}
}

View file

@ -0,0 +1,69 @@
using System;
using System.Reflection;
using preproc_constantsNamespace;
public class runme {
static void Main() {
assert( typeof(int) == preproc_constants.CONST_INT1.GetType() );
assert( typeof(int) == preproc_constants.CONST_INT2.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT1.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT2.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT3.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT4.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG1.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG2.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG3.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG4.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG1.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG2.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG3.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG4.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG1.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG2.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG3.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG4.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE1.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE2.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE3.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE4.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE5.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE6.GetType() );
assert( typeof(bool) == preproc_constants.CONST_BOOL1.GetType() );
assert( typeof(bool) == preproc_constants.CONST_BOOL2.GetType() );
assert( typeof(char) == preproc_constants.CONST_CHAR.GetType() );
assert( typeof(string) == preproc_constants.CONST_STRING1.GetType() );
assert( typeof(string) == preproc_constants.CONST_STRING2.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_BOOL.GetType() );
// assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_INT.GetType() );
assert( typeof(uint) == preproc_constants.INT_AND_UINT.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_LONG.GetType() );
assert( typeof(uint) == preproc_constants.INT_AND_ULONG.GetType() );
assert( typeof(long) == preproc_constants.INT_AND_LLONG.GetType() );
assert( typeof(ulong) == preproc_constants.INT_AND_ULLONG.GetType() );
assert( typeof(int ) == preproc_constants.BOOL_AND_BOOL.GetType() );
assert( typeof(int) == preproc_constants.EXPR_MULTIPLY.GetType() );
assert( typeof(int) == preproc_constants.EXPR_DIVIDE.GetType() );
assert( typeof(int) == preproc_constants.EXPR_PLUS.GetType() );
assert( typeof(int) == preproc_constants.EXPR_MINUS.GetType() );
assert( typeof(int) == preproc_constants.EXPR_LSHIFT.GetType() );
assert( typeof(int) == preproc_constants.EXPR_RSHIFT.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LTE.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_GTE.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_INEQUALITY.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_EQUALITY.GetType() );
assert( typeof(int) == preproc_constants.EXPR_AND.GetType() );
assert( typeof(int) == preproc_constants.EXPR_XOR.GetType() );
assert( typeof(int) == preproc_constants.EXPR_OR.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
}
static void assert(bool assertion) {
if (!assertion)
throw new ApplicationException("test failed");
}
}

View file

@ -0,0 +1,12 @@
using System;
using rename_pcre_encoderNamespace;
public class runme {
static void Main() {
SomeWidget w = new SomeWidget();
w.putBorderWidth(17);
if ( w.getBorderWidth() != 17 )
throw new Exception(String.Format("Border with should be 17, not {0}",
w.getBorderWidth()));
}
}

View file

@ -0,0 +1,24 @@
using System;
using rename_pcre_enumNamespace;
public class runme {
static void Main() {
Foo foo = Foo.First;
if ( foo == Foo.Second )
throw new Exception("Enum values should be different");
// Check that Foo_Max enum element was ignored.
int numFooEnumElements = Enum.GetValues(typeof(Foo)).Length;
if ( numFooEnumElements != 2 )
throw new Exception(String.Format("Enum should have 2 elements, not {0}",
numFooEnumElements));
BoundaryCondition bc = BoundaryCondition.MaxMax;
if ( (int)bc != 2 )
throw new Exception("Wrong enum value");
Colour c = Colour.red;
if ( c == Colour.blue )
throw new Exception("Enum values should be different");
}
}

View file

@ -0,0 +1,30 @@
using System;
using rename_simpleNamespace;
public class rename_simple_runme {
public static void Main() {
NewStruct s = new NewStruct();
check(111, s.NewInstanceVariable, "NewInstanceVariable");
check(222, s.NewInstanceMethod(), "NewInstanceMethod");
check(333, NewStruct.NewStaticMethod(), "NewStaticMethod");
check(444, NewStruct.NewStaticVariable, "NewStaticVariable");
check(555, rename_simple.NewFunction(), "NewFunction");
check(666, rename_simple.NewGlobalVariable, "NewGlobalVariable");
s.NewInstanceVariable = 1111;
NewStruct.NewStaticVariable = 4444;
rename_simple.NewGlobalVariable = 6666;
check(1111, s.NewInstanceVariable, "NewInstanceVariable");
check(4444, NewStruct.NewStaticVariable, "NewStaticVariable");
check(6666, rename_simple.NewGlobalVariable, "NewGlobalVariable");
}
public static void check(int expected, int actual, string msg) {
if (expected != actual)
throw new Exception("Failed: Expected: " + expected + " actual: " + actual + " " + msg);
}
}

View file

@ -0,0 +1,22 @@
using System;
using special_variable_macrosNamespace;
public class runme {
static void Main() {
Name name = new Name();
if (special_variable_macros.testFred(name) != "none")
throw new Exception("test failed");
if (special_variable_macros.testJack(name) != "$specialname")
throw new Exception("test failed");
if (special_variable_macros.testJill(name) != "jilly")
throw new Exception("test failed");
if (special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap")
throw new Exception("test failed");
if (special_variable_macros.testJim(name) != "multiname num")
throw new Exception("test failed");
if (special_variable_macros.testJohn(new PairIntBool(10, false)) != 123)
throw new Exception("test failed");
NewName newName = NewName.factory("factoryname");
name = newName.getStoredName();
}
}

View file

@ -0,0 +1,13 @@
using System;
using typemap_out_optimalNamespace;
public class typemap_out_optimal_runme {
public static XX x = null;
public static void Main() {
XX.debug = false;
x = XX.create();
}
}

View file

@ -1,4 +1,4 @@
%module csharp_attributes
%module(directors="1") csharp_attributes
// Test the inattributes and outattributes typemaps
%typemap(cstype, outattributes="[IntOut]", inattributes="[IntIn]") int "int"
@ -15,6 +15,8 @@ public:
int GlobalFunction(int myInt) { return myInt; }
%}
//%include "enumsimple.swg"
//%include "enumtypesafe.swg"
// Test the attributes feature
%csattributes MoreStations::MoreStations() "[InterCity1]"
@ -25,6 +27,8 @@ int GlobalFunction(int myInt) { return myInt; }
%csattributes Wales "[InterCity6]"
%csattributes Paddington() "[InterCity7]"
%csattributes DidcotParkway "[InterCity8]"
%csattributes MoreStations::Cardiff "[System.ComponentModel.Description(\"Cardiff city station\")]"
%csattributes Swansea "[System.ComponentModel.Description(\"Swansea city station\")]"
%typemap(csattributes) MoreStations "[Eurostar1]"
%typemap(csattributes) MoreStations::Wales "[Eurostar2]"
@ -46,3 +50,13 @@ enum Cymru { Llanelli };
double MoreStations::WestonSuperMare = 0.0;
%}
// Test directorinattributes and directoroutattributes
%typemap(imtype, directoroutattributes="[DirectorIntegerOut]", directorinattributes="[DirectorIntegerIn]") int "int"
%feature("director") YetMoreStations;
%inline %{
struct YetMoreStations {
virtual int Slough(int x) { return x; }
virtual ~YetMoreStations() {}
};
%}

View file

@ -0,0 +1,61 @@
%module csharp_lib_arrays
%include "arrays_csharp.i"
%apply int INPUT[] { int* sourceArray }
%apply int OUTPUT[] { int* targetArray }
%apply int INOUT[] { int* array1 }
%apply int INOUT[] { int* array2 }
%inline %{
/* copy the contents of the first array to the second */
void myArrayCopy( int* sourceArray, int* targetArray, int nitems ) {
int i;
for ( i = 0; i < nitems; i++ ) {
targetArray[ i ] = sourceArray[ i ];
}
}
/* swap the contents of the two arrays */
void myArraySwap( int* array1, int* array2, int nitems ) {
int i, temp;
for ( i = 0; i < nitems; i++ ) {
temp = array1[ i ];
array1[ i ] = array2[ i ];
array2[ i ] = temp;
}
}
%}
%clear int* sourceArray;
%clear int* targetArray;
%clear int* array1;
%clear int* array2;
// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
%csmethodmodifiers myArrayCopyUsingFixedArrays "public unsafe";
%csmethodmodifiers myArraySwapUsingFixedArrays "public unsafe";
%apply int FIXED[] { int* sourceArray }
%apply int FIXED[] { int* targetArray }
%inline %{
void myArrayCopyUsingFixedArrays( int *sourceArray, int* targetArray, int nitems ) {
myArrayCopy(sourceArray, targetArray, nitems);
}
%}
%apply int FIXED[] { int* array1 }
%apply int FIXED[] { int* array2 }
%inline %{
void myArraySwapUsingFixedArrays( int* array1, int* array2, int nitems ) {
myArraySwap(array1, array2, nitems);
}
%}

View file

@ -25,7 +25,10 @@
"$csclassname.getCPtr(d$csinput)"
// post only in csin typemap
%typemap(csin, post=" int size = $csinput.Count;\n for (int i=0; i<size; ++i) {\n $csinput[i] /= 100;\n }") std::vector<double> &vpost
%typemap(csin, post=" int size = $csinput.Count;\n"
" for (int i=0; i<size; ++i) {\n"
" $csinput[i] /= 100;\n"
" }") std::vector<double> &vpost
"$csclassname.getCPtr($csinput)"
%inline %{
@ -76,7 +79,7 @@ struct PrePost2 {
// Check attributes in the typemaps
%typemap(cstype, inattributes="[CustomInt]") int val "int"
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int "tmp_$csinput"
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput"
%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"
%inline %{
@ -185,5 +188,8 @@ void subtractYears(CDate *pDate, int years) {
%inline %{
CDate ImportantDate = CDate(1999, 12, 31);
struct Person {
CDate Birthday;
};
%}

View file

@ -101,3 +101,19 @@ Number times12(const Number* num) {
%inline %{
int myInt = 0;
%}
// Illegal special variable crash
%typemap(cstype) WasCrashing "$csclassname /*cstype $*csclassname*/" // $*csclassname was causing crash
%inline %{
struct WasCrashing {};
void hoop(WasCrashing was) {}
%}
// Enum underlying type
%typemap(csbase) BigNumbers "uint"
%inline %{
enum BigNumbers { big=0x80000000, bigger };
%}

View file

@ -0,0 +1,80 @@
#######################################################################
# Makefile for D test-suite
#######################################################################
LANGUAGE = d
srcdir = @srcdir@
top_srcdir = ../@top_srcdir@
top_builddir = ../@top_builddir@
ifeq (2,$(D_VERSION))
VERSIONSUFFIX = .2
else
VERSIONSUFFIX = .1
endif
TESTSUFFIX = _runme$(VERSIONSUFFIX).d
CPP_TEST_CASES = \
d_nativepointers \
exception_partial_info
include $(srcdir)/../common.mk
# Override some variables from common.mk:
TARGETSUFFIX = _wrap
SWIGOPT+=-splitproxy -package $*
# Rules for the different types of tests
%.cpptest:
$(setup)
+(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_cpp))
+$(run_testcase)
%.ctest:
$(setup)
+(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_c))
+$(run_testcase)
%.multicpptest:
$(setup)
+(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_multi_cpp))
+$(run_testcase)
# Makes a directory for the testcase if it does not exist
setup = \
if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
else \
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $*$(VERSIONSUFFIX) ]; then \
mkdir $*$(VERSIONSUFFIX); \
fi; \
if [ ! -d $*$(VERSIONSUFFIX)/$* ]; then \
mkdir $*$(VERSIONSUFFIX)/$*; \
fi
# Compiles D files then runs the testcase. A testcase is only run if
# a file is found which has _runme.d appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
cd $*$(VERSIONSUFFIX) && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
DFLAGS='-of$*_runme' \
DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) `find $* -name *.d`' d_compile && \
env LD_LIBRARY_PATH=".:$$LD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme; \
else \
cd $*$(VERSIONSUFFIX) && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
DFLAGS='-c' \
DSRCS='`find $* -name *.d`' d_compile && cd .. ; \
fi
# Clean: remove testcase directories
%.clean:
@if [ -d $*$(VERSIONSUFFIX) ]; then \
rm -rf $*$(VERSIONSUFFIX); \
fi

View file

@ -0,0 +1,7 @@
D language module testsuite
---------------------------
Please see ../README for the common readme file.
By default the D1 version is built, set D_VERSION=2 (in the environment or at
the make command line) to run it for D2 instead.

View file

@ -0,0 +1,25 @@
module aggregate_runme;
import aggregate.aggregate;
void main() {
// Confirm that move() returns correct results under normal use.
int result = move(UP);
if (result != UP) throw new Exception("UP failed");
result = move(DOWN);
if (result != DOWN) throw new Exception("DOWN failed");
result = move(LEFT);
if (result != LEFT) throw new Exception("LEFT failed");
result = move(RIGHT);
if (result != RIGHT) throw new Exception("RIGHT failed");
// Confirm that move() raises an exception when the contract is violated.
try {
move(0);
throw new Exception("0 test failed");
}
catch (Exception e) {}
}

View file

@ -0,0 +1,25 @@
module aggregate_runme;
import aggregate.aggregate;
void main() {
// Confirm that move() returns correct results under normal use.
int result = move(UP);
if (result != UP) throw new Exception("UP failed");
result = move(DOWN);
if (result != DOWN) throw new Exception("DOWN failed");
result = move(LEFT);
if (result != LEFT) throw new Exception("LEFT failed");
result = move(RIGHT);
if (result != RIGHT) throw new Exception("RIGHT failed");
// Confirm that move() raises an exception when the contract is violated.
try {
move(0);
throw new Exception("0 test failed");
}
catch (Exception e) {}
}

View file

@ -0,0 +1,65 @@
module allprotected_runme;
import allprotected.Klass;
import allprotected.ProtectedBase;
void main() {
auto mpb = new MyProtectedBase("MyProtectedBase");
mpb.accessProtected();
}
class MyProtectedBase : ProtectedBase {
public:
this(char[] name) {
super(name);
}
void accessProtected() {
char[] s = virtualMethod();
if (s != "ProtectedBase")
throw new Exception("Failed");
Klass k = instanceMethod(new Klass("xyz"));
if (k.getName() != "xyz")
throw new Exception("Failed");
k = instanceOverloaded(new Klass("xyz"));
if (k.getName() != "xyz")
throw new Exception("Failed");
k = instanceOverloaded(new Klass("xyz"), "abc");
if (k.getName() != "abc")
throw new Exception("Failed");
k = staticMethod(new Klass("abc"));
if (k.getName() != "abc")
throw new Exception("Failed");
k = staticOverloaded(new Klass("xyz"));
if (k.getName() != "xyz")
throw new Exception("Failed");
k = staticOverloaded(new Klass("xyz"), "abc");
if (k.getName() != "abc")
throw new Exception("Failed");
instanceMemberVariable = 30;
int i = instanceMemberVariable;
if (i != 30)
throw new Exception("Failed");
staticMemberVariable = 40;
i = staticMemberVariable;
if (i != 40)
throw new Exception("Failed");
i = staticConstMemberVariable;
if (i != 20)
throw new Exception("Failed");
anEnum = ProtectedBase.AnEnum.EnumVal1;
ProtectedBase.AnEnum ae = anEnum;
if (ae != ProtectedBase.AnEnum.EnumVal1)
throw new Exception("Failed");
}
}

View file

@ -0,0 +1,63 @@
module allprotected_runme;
import allprotected.Klass;
import allprotected.ProtectedBase;
import std.conv : text;
import std.exception : enforce;
void main() {
auto mpb = new MyProtectedBase("MyProtectedBase");
mpb.accessProtected();
}
class MyProtectedBase : ProtectedBase {
public:
this(string name) {
super(name);
}
void accessProtected() {
string s = virtualMethod();
enforce(s == "ProtectedBase", "Failed, got '" ~ s ~ "'");
Klass k;
void expect(string name) {
auto kName = k.getName();
enforce(kName == name, "Failed, expected '" ~ name ~ "' instead of '" ~
kName ~ "'.");
}
k = instanceMethod(new Klass("xyz"));
expect("xyz");
k = instanceOverloaded(new Klass("xyz"));
expect("xyz");
k = instanceOverloaded(new Klass("xyz"), "abc");
expect("abc");
k = staticMethod(new Klass("abc"));
expect("abc");
k = staticOverloaded(new Klass("xyz"));
expect("xyz");
k = staticOverloaded(new Klass("xyz"), "abc");
expect("abc");
instanceMemberVariable = 30;
int i = instanceMemberVariable;
enforce(i == 30, text("Failed, expected ", 30, "instead of ", i));
staticMemberVariable = 40;
i = staticMemberVariable;
enforce(i == 40, text("Failed, expected ", 40, "instead of ", i));
i = staticConstMemberVariable;
enforce(i == 20, text("Failed, expected ", 20, "instead of ", i));
anEnum = ProtectedBase.AnEnum.EnumVal1;
ProtectedBase.AnEnum ae = anEnum;
enforce(ae == ProtectedBase.AnEnum.EnumVal1);
}
}

View file

@ -0,0 +1,12 @@
module apply_strings_runme;
import apply_strings.apply_strings;
const char[] TEST_MESSAGE = "A message from target language to the C++ world and back again.";
void main() {
if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
auto pChar = CharFunction(null);
if (pChar !is null) throw new Exception("CharFunction failed");
}

View file

@ -0,0 +1,12 @@
module apply_strings_runme;
import apply_strings.apply_strings;
enum string TEST_MESSAGE = "A message from target language to the C++ world and back again.";
void main() {
if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
auto pChar = CharFunction(null);
if (pChar !is null) throw new Exception("CharFunction failed");
}

View file

@ -0,0 +1,20 @@
/// This is the bool runtime testcase. It checks that the C++ bool type works.
module bools_runme;
import bools.bools;
void main() {
bool t = true;
bool f = false;
check_bo(f);
check_bo(t);
}
void check_bo(bool input) {
for (int i = 0; i < 1000; ++i) {
if (bo(input) != input) {
throw new Exception("Runtime test check_bo failed.");
}
}
}

View file

@ -0,0 +1,20 @@
/// This is the bool runtime testcase. It checks that the C++ bool type works.
module bools_runme;
import bools.bools;
void main() {
bool t = true;
bool f = false;
check_bo(f);
check_bo(t);
}
void check_bo(bool input) {
for (int i = 0; i < 1000; ++i) {
if (bo(input) != input) {
throw new Exception("Runtime test check_bo failed.");
}
}
}

View file

@ -0,0 +1,33 @@
module catches_runme;
import catches.catches;
void main() {
test({ test_catches(1); }, "C++ int exception thrown, value: 1");
test({ test_catches(2); }, "two");
test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
test({ test_exception_specification(2); }, "unknown exception");
test({ test_exception_specification(3); }, "unknown exception");
test({ test_catches_all(1); }, "unknown exception");
}
void test(void delegate() command, char[] expectedMessage) {
bool didntThrow;
try {
command();
didntThrow = true;
} catch (Exception e) {
if (e.msg != expectedMessage) {
throw new Exception("Failed to propagate C++ exception. Expected '" ~
expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
}
}
if (didntThrow) {
throw new Exception("Failed to propagate C++ exception. Expected '" ~
expectedMessage ~ "', but no exception was thrown.");
}
}

View file

@ -0,0 +1,33 @@
module catches_runme;
import catches.catches;
void main() {
test({ test_catches(1); }, "C++ int exception thrown, value: 1");
test({ test_catches(2); }, "two");
test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
test({ test_exception_specification(2); }, "unknown exception");
test({ test_exception_specification(3); }, "unknown exception");
test({ test_catches_all(1); }, "unknown exception");
}
void test(void delegate() command, string expectedMessage) {
bool didntThrow;
try {
command();
didntThrow = true;
} catch (Exception e) {
if (e.msg != expectedMessage) {
throw new Exception("Failed to propagate C++ exception. Expected '" ~
expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
}
}
if (didntThrow) {
throw new Exception("Failed to propagate C++ exception. Expected '" ~
expectedMessage ~ "', but no exception was thrown.");
}
}

View file

@ -0,0 +1,151 @@
module char_strings_runme;
import tango.text.convert.Integer;
import char_strings.char_strings;
const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
const char[] OTHERLAND_MSG = "Little message from the safe world.";
void main() {
const uint count = 10000;
uint i = 0;
// get functions
for (i=0; i<count; i++) {
char[] str = GetCharHeapString();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char get 1 failed, iteration " ~ toString(i));
DeleteCharHeapString();
}
for (i=0; i<count; i++) {
char[] str = GetConstCharProgramCodeString();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char get 2 failed, iteration " ~ toString(i));
DeleteCharHeapString();
}
for (i=0; i<count; i++) {
char[] str = GetCharStaticString();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char get 3 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
char[] str = GetCharStaticStringFixed();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char get 4 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
char[] str = GetConstCharStaticStringFixed();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char get 5 failed, iteration " ~ toString(i));
}
// set functions
for (i=0; i<count; i++) {
if (!SetCharHeapString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 1 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetCharStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 2 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 3 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetConstCharHeapString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 4 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetConstCharStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 5 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetConstCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 6 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 7 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetConstCharConstStaticString(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char set 8 failed, iteration " ~ toString(i));
}
// get set function
for (i=0; i<count*10; i++) {
char[] ping = OTHERLAND_MSG ~ toString(i);
char[] pong = CharPingPong(ping);
if (ping != pong)
throw new Exception("Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
}
// variables
for (i=0; i<count; i++) {
global_char = OTHERLAND_MSG ~ toString(i);
if (global_char != OTHERLAND_MSG ~ toString(i))
throw new Exception("Test variables 1 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
global_char_array1 = OTHERLAND_MSG ~ toString(i);
if (global_char_array1 != OTHERLAND_MSG ~ toString(i))
throw new Exception("Test variables 2 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
global_char_array2 = OTHERLAND_MSG ~ toString(i);
if (global_char_array2 != OTHERLAND_MSG ~ toString(i))
throw new Exception("Test variables 3 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (global_const_char != CPLUSPLUS_MSG)
throw new Exception("Test variables 4 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (global_const_char_array1 != CPLUSPLUS_MSG)
throw new Exception("Test variables 5 failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (global_const_char_array2 != CPLUSPLUS_MSG)
throw new Exception("Test variables 6 failed, iteration " ~ toString(i));
}
// char *& tests
for (i=0; i<count; i++) {
char[] str = GetCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char pointer ref get failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test char pointer ref set failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
char[] str = GetConstCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test const char pointer ref get failed, iteration " ~ toString(i));
}
for (i=0; i<count; i++) {
if (!SetConstCharPointerRef(OTHERLAND_MSG ~ toString(i), i))
throw new Exception("Test const char pointer ref set failed, iteration " ~ toString(i));
}
}

View file

@ -0,0 +1,123 @@
module char_strings_runme;
import std.conv;
import std.exception;
import std.range;
import char_strings.char_strings;
enum CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
enum OTHERLAND_MSG = "Little message from the safe world.";
enum TEST_RANGE = iota(0, 10000);
void main() {
// get functions
foreach (i; TEST_RANGE) {
enforce(GetCharHeapString() == CPLUSPLUS_MSG, "Test char get 1 failed, iteration " ~ to!string(i));
DeleteCharHeapString();
}
foreach (i; TEST_RANGE) {
enforce(GetConstCharProgramCodeString() == CPLUSPLUS_MSG, "Test char get 2 failed, iteration " ~ to!string(i));
DeleteCharHeapString();
}
foreach (i; TEST_RANGE) {
enforce(GetCharStaticString() == CPLUSPLUS_MSG, "Test char get 3 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(GetCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 4 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(GetConstCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 5 failed, iteration " ~ to!string(i));
}
// set functions
foreach (i; TEST_RANGE) {
enforce(SetCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 1 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 2 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 3 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetConstCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 4 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetConstCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 5 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetConstCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 6 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 7 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetConstCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 8 failed, iteration " ~ to!string(i));
}
// get set function
foreach (i; TEST_RANGE) {
string ping = OTHERLAND_MSG ~ to!string(i);
string pong = CharPingPong(ping);
enforce(ping == pong, "Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong);
}
// variables
foreach (i; TEST_RANGE) {
const msg = OTHERLAND_MSG ~ to!string(i);
global_char = msg;
enforce(global_char == msg, "Test variables 1 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
const msg = OTHERLAND_MSG ~ to!string(i);
global_char_array1 = msg;
enforce(global_char_array1 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
const msg = OTHERLAND_MSG ~ to!string(i);
global_char_array2 = msg;
enforce(global_char_array2 == msg, "Test variables 2 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(global_const_char == CPLUSPLUS_MSG, "Test variables 4 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(global_const_char_array1 == CPLUSPLUS_MSG, "Test variables 5 failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(global_const_char_array2 == CPLUSPLUS_MSG, "Test variables 6 failed, iteration " ~ to!string(i));
}
// char *& tests
foreach (i; TEST_RANGE) {
enforce(GetCharPointerRef() == CPLUSPLUS_MSG, "Test char pointer ref get failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test char pointer ref set failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(GetConstCharPointerRef() == CPLUSPLUS_MSG, "Test const char pointer ref get failed, iteration " ~ to!string(i));
}
foreach (i; TEST_RANGE) {
enforce(SetConstCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test const char pointer ref set failed, iteration " ~ to!string(i));
}
}

View file

@ -0,0 +1,31 @@
module constover_runme;
import constover.constover;
import constover.Foo;
void main() {
char[] p = test("test");
if (p != "test")
throw new Exception("test failed!");
p = test_pconst("test");
if (p != "test_pconst")
throw new Exception("test_pconst failed!");
auto f = new Foo();
p = f.test("test");
if (p != "test")
throw new Exception("member-test failed!");
p = f.test_pconst("test");
if (p != "test_pconst")
throw new Exception("member-test_pconst failed!");
p = f.test_constm("test");
if (p != "test_constmethod")
throw new Exception("member-test_constm failed!");
p = f.test_pconstm("test");
if (p != "test_pconstmethod")
throw new Exception("member-test_pconstm failed!");
}

View file

@ -0,0 +1,16 @@
module constover_runme;
import std.exception;
import constover.constover;
import constover.Foo;
void main() {
enforce(test("test") == "test", "test failed!");
enforce(test_pconst("test") == "test_pconst", "test_pconst failed!");
auto f = new Foo();
enforce(f.test("test") == "test", "member-test failed!");
enforce(f.test_pconst("test") == "test_pconst", "member-test_pconst failed!");
enforce(f.test_constm("test") == "test_constmethod", "member-test_constm failed!");
enforce(f.test_pconstm("test") == "test_pconstmethod", "member-test_pconstm failed!");
}

View file

@ -0,0 +1,38 @@
module d_nativepointers_runnme;
import d_nativepointers.d_nativepointers;
import d_nativepointers.SomeClass;
import d_nativepointers.SWIGTYPE_p_OpaqueClass;
import d_nativepointers.SWIGTYPE_p_p_SomeClass;
import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
extern(C) alias void function(int**, char***) GType;
void main() {
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, GType);
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
{
static assert(is(int* function(int*) == typeof(&refA)));
int v = 2;
assert(*refA(&v) == 2);
}
{
static assert(is(float** function(float**) == typeof(&refB)));
float v = 1.0;
float* p = &v;
assert(**refB(&p) == 1.0);
}
}
void check(alias F, T)() {
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
}

View file

@ -0,0 +1,38 @@
module d_nativepointers_runnme;
import d_nativepointers.d_nativepointers;
import d_nativepointers.SomeClass;
import d_nativepointers.SWIGTYPE_p_OpaqueClass;
import d_nativepointers.SWIGTYPE_p_p_SomeClass;
import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
extern(C) alias void function(int**, char***) GType;
void main() {
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, GType);
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
{
static assert(is(int* function(int*) == typeof(&refA)));
int v = 2;
assert(*refA(&v) == 2);
}
{
static assert(is(float** function(float**) == typeof(&refB)));
float v = 1.0;
float* p = &v;
assert(**refB(&p) == 1.0);
}
}
void check(alias F, T)() {
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
}

View file

@ -0,0 +1,127 @@
module default_args_runme;
import default_args.default_args;
import default_args.ConstMethods;
import default_args.EnumClass;
import default_args.Except;
import default_args.Foo;
import default_args.Klass;
import default_args.Statics;
import default_args.Tricky;
void main() {
if (anonymous() != 7771)
throw new Exception("anonymous (1) failed");
if (anonymous(1234) != 1234)
throw new Exception("anonymous (2) failed");
if (booltest() != true)
throw new Exception("booltest (1) failed");
if (booltest(true) != true)
throw new Exception("booltest (2) failed");
if (booltest(false) != false)
throw new Exception("booltest (3) failed");
auto ec = new EnumClass();
if (ec.blah() != true)
throw new Exception("EnumClass failed");
if (casts1() != null)
throw new Exception("casts1 failed");
if (casts2() != "Hello")
throw new Exception("casts2 failed");
if (casts1("Ciao") != "Ciao")
throw new Exception("casts1 not default failed");
if (chartest1() != 'x')
throw new Exception("chartest1 failed");
if (chartest2() != '\0')
throw new Exception("chartest2 failed");
if (chartest1('y') != 'y')
throw new Exception("chartest1 not default failed");
if (chartest1('y') != 'y')
throw new Exception("chartest1 not default failed");
if (reftest1() != 42)
throw new Exception("reftest1 failed");
if (reftest1(400) != 400)
throw new Exception("reftest1 not default failed");
if (reftest2() != "hello")
throw new Exception("reftest2 failed");
// rename
auto foo = new Foo();
foo.newname();
foo.newname(10);
foo.renamed3arg(10, 10.0);
foo.renamed2arg(10);
foo.renamed1arg();
// exception specifications
testException( { exceptionspec(); }, "exceptionspec 1" );
testException( { exceptionspec(-1); }, "exceptionspec 2" );
testException( { exceptionspec(100); }, "exceptionspec 3" );
auto ex = new Except(false);
testException( { ex.exspec(); }, "exspec 1" );
testException( { ex.exspec(-1); }, "exspec 2" );
testException( { ex.exspec(100); }, "exspec 3" );
testException( { ex = new Except(true); }, "Except constructor 1" );
testException( { ex = new Except(true, -2); }, "Except constructor 2" );
// Default parameters in static class methods
if (Statics.staticmethod() != 10+20+30)
throw new Exception("staticmethod 1 failed");
if (Statics.staticmethod(100) != 100+20+30)
throw new Exception("staticmethod 2 failed");
if (Statics.staticmethod(100,200,300) != 100+200+300)
throw new Exception("staticmethod 3 failed");
auto tricky = new Tricky();
if (tricky.privatedefault() != 200)
throw new Exception("privatedefault failed");
if (tricky.protectedint() != 2000)
throw new Exception("protectedint failed");
if (tricky.protecteddouble() != 987.654)
throw new Exception("protecteddouble failed");
if (tricky.functiondefault() != 500)
throw new Exception("functiondefault failed");
if (tricky.contrived() != 'X')
throw new Exception("contrived failed");
if (constructorcall().val != -1)
throw new Exception("constructorcall test 1 failed");
if (constructorcall(new Klass(2222)).val != 2222)
throw new Exception("constructorcall test 2 failed");
if (constructorcall(new Klass()).val != -1)
throw new Exception("constructorcall test 3 failed");
// const methods
auto cm = new ConstMethods();
if (cm.coo() != 20)
throw new Exception("coo test 1 failed");
if (cm.coo(1.0) != 20)
throw new Exception("coo test 2 failed");
}
void testException(void delegate() command, char[] testName) {
bool didntThrow;
try {
command();
didntThrow = true;
} catch (Exception e) {}
if (didntThrow) {
throw new Exception(testName ~ " failed");
}
}

View file

@ -0,0 +1,84 @@
module default_args_runme;
import std.exception;
import default_args.default_args;
import default_args.ConstMethods;
import default_args.EnumClass;
import default_args.Except;
import default_args.Foo;
import default_args.Klass;
import default_args.Statics;
import default_args.Tricky;
void main() {
enforce(anonymous() == 7771, "anonymous (1) failed");
enforce(anonymous(1234) == 1234,"anonymous (2) failed");
enforce(booltest() == true, "booltest (1) failed");
enforce(booltest(true) == true, "booltest (2) failed");
enforce(booltest(false) == false, "booltest (3) failed");
enforce((new EnumClass()).blah() == true, "EnumClass failed");
enforce(casts1() == null, "casts1 failed");
enforce(casts2() == "Hello", "casts2 failed");
enforce(casts1("Ciao") == "Ciao", "casts1 not default failed");
enforce(chartest1() == 'x', "chartest1 failed");
enforce(chartest2() == '\0', "chartest2 failed");
enforce(chartest1('y') == 'y', "chartest1 not default failed");
enforce(chartest1('y') == 'y', "chartest1 not default failed");
enforce(reftest1() == 42, "reftest1 failed");
enforce(reftest1(400) == 400, "reftest1 not default failed");
enforce(reftest2() == "hello", "reftest2 failed");
// rename
auto foo = new Foo();
foo.newname();
foo.newname(10);
foo.renamed3arg(10, 10.0);
foo.renamed2arg(10);
foo.renamed1arg();
// exception specifications
enforceThrows( (){ exceptionspec(); }, "exceptionspec 1" );
enforceThrows( (){ exceptionspec(-1); }, "exceptionspec 2" );
enforceThrows( (){ exceptionspec(100); }, "exceptionspec 3" );
auto ex = new Except(false);
enforceThrows( (){ ex.exspec(); }, "exspec 1" );
enforceThrows( (){ ex.exspec(-1); }, "exspec 2" );
enforceThrows( (){ ex.exspec(100); }, "exspec 3" );
enforceThrows( (){ ex = new Except(true); }, "Except constructor 1" );
enforceThrows( (){ ex = new Except(true, -2); }, "Except constructor 2" );
// Default parameters in static class methods
enforce(Statics.staticmethod() == 10+20+30, "staticmethod 1 failed");
enforce(Statics.staticmethod(100) == 100+20+30, "staticmethod 2 failed");
enforce(Statics.staticmethod(100,200,300) == 100+200+300, "staticmethod 3 failed");
auto tricky = new Tricky();
enforce(tricky.privatedefault() == 200, "privatedefault failed");
enforce(tricky.protectedint() == 2000, "protectedint failed");
enforce(tricky.protecteddouble() == 987.654, "protecteddouble failed");
enforce(tricky.functiondefault() == 500, "functiondefault failed");
enforce(tricky.contrived() == 'X', "contrived failed");
enforce(constructorcall().val == -1, "constructorcall test 1 failed");
enforce(constructorcall(new Klass(2222)).val == 2222, "constructorcall test 2 failed");
enforce(constructorcall(new Klass()).val == -1, "constructorcall test 3 failed");
// const methods
const cm = new ConstMethods();
enforce(cm.coo() == 20, "coo test 1 failed");
enforce(cm.coo(1.0) == 20, "coo test 2 failed");
}
private void enforceThrows(void delegate() dg, string errorMessage) {
bool hasThrown;
try {
dg();
} catch (Exception) {
hasThrown = true;
} finally {
if (!hasThrown) {
throw new Exception(errorMessage);
}
}
}

View file

@ -0,0 +1,30 @@
module default_constructor_runme;
import default_constructor.FFF;
import default_constructor.G;
void main() {
// Protected destructor test.
try {
{
scope g = new G();
}
throw new Exception("Protected destructor exception should have been thrown");
} catch (Exception e) {
if (e.msg != "C++ destructor does not have public access") {
throw e;
}
}
// Private destructor test.
try {
{
scope f = new FFF();
}
throw new Exception("Private destructor exception should have been thrown");
} catch (Exception e) {
if (e.msg != "C++ destructor does not have public access") {
throw e;
}
}
}

View file

@ -0,0 +1,25 @@
module default_constructor_runme;
import default_constructor.FFF;
import default_constructor.G;
void main() {
// D2 does not support something akin to D1/Tango dispose() for deterministic
// destruction yet.
// enforceThrows((){ scope g = new G(); }, "Protected destructor exception should have been thrown");
// enforceThrows((){ scope f = new FFF(); }, "Private destructor exception should have been thrown");
}
private void enforceThrows(void delegate() dg, string errorMessage) {
bool hasThrown;
try {
dg();
} catch (Exception) {
hasThrown = true;
} finally {
if (!hasThrown) {
throw new Exception(errorMessage);
}
}
}

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,59 @@
module director_basic_runme;
import director_basic.A1;
import director_basic.Bar;
import director_basic.Foo;
import director_basic.MyClass;
void main() {
auto a = new director_basic_MyFoo();
if (a.ping() != "director_basic_MyFoo::ping()") {
throw new Exception("a.ping()");
}
if (a.pong() != "Foo::pong();director_basic_MyFoo::ping()") {
throw new Exception("a.pong()");
}
auto b = new Foo();
if (b.ping() != "Foo::ping()") {
throw new Exception("b.ping()");
}
if (b.pong() != "Foo::pong();Foo::ping()") {
throw new Exception("b.pong()");
}
{
scope a1 = new A1(1, false);
}
{
auto my = new MyOverriddenClass();
my.expectNull = true;
if (MyClass.call_pmethod(my, null) !is null)
throw new Exception("null pointer conversion problem");
auto myBar = new Bar();
my.expectNull = false;
auto myNewBar = MyClass.call_pmethod(my, myBar);
if (myNewBar is null)
throw new Exception("non-null pointer conversion problem");
myNewBar.x = 10;
}
}
class director_basic_MyFoo : Foo {
public override char[] ping() {
return "director_basic_MyFoo::ping()";
}
}
class MyOverriddenClass : MyClass {
public bool expectNull = false;
public bool nonNullReceived = false;
public override Bar pmethod(Bar b) {
if (expectNull && (b !is null))
throw new Exception("null not received as expected");
return b;
}
}

View file

@ -0,0 +1,46 @@
module director_basic_runme;
import std.exception;
import director_basic.A1;
import director_basic.Bar;
import director_basic.Foo;
import director_basic.MyClass;
void main() {
auto a = new director_basic_MyFoo();
enforce(a.ping() == "director_basic_MyFoo::ping()", "a.ping()");
enforce(a.pong() == "Foo::pong();director_basic_MyFoo::ping()", "a.pong()");
auto b = new Foo();
enforce(b.ping() == "Foo::ping()", "b.ping()");
enforce(b.pong() == "Foo::pong();Foo::ping()", "b.pong()");
{
scope a1 = new A1(1, false);
}
auto my = new MyOverriddenClass();
my.expectNull = true;
enforce(MyClass.call_pmethod(my, null) is null, "null pointer conversion problem");
auto myBar = new Bar();
my.expectNull = false;
auto myNewBar = MyClass.call_pmethod(my, myBar);
enforce(myNewBar !is null, "non-null pointer conversion problem");
myNewBar.x = 10;
}
class director_basic_MyFoo : Foo {
public override string ping() {
return "director_basic_MyFoo::ping()";
}
}
class MyOverriddenClass : MyClass {
public bool expectNull = false;
public bool nonNullReceived = false;
public override Bar pmethod(Bar b) {
if (expectNull && (b !is null))
throw new Exception("null not received as expected");
return b;
}
}

View file

@ -0,0 +1,168 @@
/**
* This test demonstrates director classes when the types are classes. Shown are
* virtual function calls which use classes passed by
* - Value
* - Reference
* - Pointer
* as both parameters and return values
*
* The test also demonstrates directors used with:
* - method overloading
* - default parameters
*
* Note: Methods with default parameters that call up from C++ cannot call the
* overloaded D methods, see DefaultParms method.
* Expected output if PrintDebug enabled:
* ------------ Start ------------
* Base - Val(444.555)
* Base - Ref(444.555)
* Base - Ptr(444.555)
* Base - FullyOverloaded(int 10)
* Base - FullyOverloaded(bool 1)
* Base - SemiOverloaded(int -678)
* Base - SemiOverloaded(bool 1)
* Base - DefaultParms(10, 2.2)
* Base - DefaultParms(10, 1.1)
* --------------------------------
* Derived - Val(444.555)
* Derived - Ref(444.555)
* Derived - Ptr(444.555)
* Derived - FullyOverloaded(int 10)
* Derived - FullyOverloaded(bool 1)
* Derived - SemiOverloaded(int -678)
* Base - SemiOverloaded(bool 1)
* Derived - DefaultParms(10, 2.2)
* Derived - DefaultParms(10, 1.1)
* --------------------------------
* DDerived - Val(444.555)
* DDerived - Ref(444.555)
* DDerived - Ptr(444.555)
* DDerived - FullyOverloaded(int 10)
* DDerived - FullyOverloaded(bool True)
* DDerived - SemiOverloaded(-678)
* Base - SemiOverloaded(bool 1)
* DDerived - DefaultParms(10, 2.2)
* DDerived - DefaultParms(10, 1.1)
* ------------ Finish ------------
*/
module director_classes_runme;
import tango.io.Stdout;
import tango.text.Util;
import director_classes.director_classes;
import director_classes.Caller;
import director_classes.Base;
import director_classes.Derived;
import director_classes.DoubleHolder;
void main() {
if (PrintDebug) Stdout.formatln("------------ Start ------------ ");
auto myCaller = new Caller();
// Test C++ base class.
{
scope myBase = new Base(100.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout.formatln("--------------------------------");
// Test vanilla C++ wrapped derived class.
{
scope myBase = new Derived(200.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout.formatln("--------------------------------");
// Test director / D derived class.
{
scope myBase = new DDerived(300.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout.formatln("------------ Finish ------------ ");
}
void makeCalls(Caller myCaller, Base myBase) {
char[] myBaseType = myBase.classinfo.name.split(".")[$-1];
myCaller.set(myBase);
DoubleHolder dh = new DoubleHolder(444.555);
// Class pointer, reference and pass by value tests
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed");
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed");
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed");
// Fully overloaded method test (all methods in base class are overloaded)
if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed");
if (myCaller.FullyOverloadedCall(true) != myBaseType ~ "::FullyOverloaded(bool)") throw new Exception("[5] failed");
// Semi overloaded method test (some methods in base class are overloaded)
if (myCaller.SemiOverloadedCall(-678) != myBaseType ~ "::SemiOverloaded(int)") throw new Exception("[6] failed");
if (myCaller.SemiOverloadedCall(true) != "Base" ~ "::SemiOverloaded(bool)") throw new Exception("[7] failed");
// Default parameters methods test
if (myCaller.DefaultParmsCall(10, 2.2) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[8] failed");
if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no way to do this any other way
if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[9] failed");
} else {
if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int)") throw new Exception("[10] failed");
}
myCaller.reset();
}
public class DDerived : Base {
public this(double dd) {
super(dd);
}
public override DoubleHolder Val(DoubleHolder x) {
if (PrintDebug) Stdout.formatln("DDerived - Val({0:d3})", x.val);
return x;
}
public override DoubleHolder Ref(DoubleHolder x) {
if (PrintDebug) Stdout.formatln("DDerived - Ref({0:d3})", x.val);
return x;
}
public override DoubleHolder Ptr(DoubleHolder x) {
if (PrintDebug) Stdout.formatln("DDerived - Ptr({0:d3})", x.val);
return x;
}
public override char[] FullyOverloaded(int x) {
if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x);
return "DDerived::FullyOverloaded(int)";
}
public override char[] FullyOverloaded(bool x) {
if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(bool {0})", x);
return "DDerived::FullyOverloaded(bool)";
}
public override char[] SemiOverloaded(int x) {
char[] ret = "DDerived::SemiOverloaded(int)";
if (PrintDebug) Stdout.formatln("DDerived - SemiOverloaded({0})", x);
return ret;
}
alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x).
public override char[] DefaultParms(int x, double y) {
char[] ret = "DDerived::DefaultParms(int, double)";
if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0}, {1:d1})", x, y);
return ret;
}
// This method will never be called from C++ code because the two-parameter
// DefaultParams() has a default value for the second parameter there. It is
// only here to ensure consistent behavior for calls from C++ and D code.
public override char[] DefaultParms(int x) {
if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0})", x);
return DefaultParms(x, 1.1/*use C++ default here*/);
}
}

View file

@ -0,0 +1,169 @@
/**
* This test demonstrates director classes when the types are classes. Shown are
* virtual function calls which use classes passed by
* - Value
* - Reference
* - Pointer
* as both parameters and return values
*
* The test also demonstrates directors used with:
* - method overloading
* - default parameters
*
* Note: Methods with default parameters that call up from C++ cannot call the
* overloaded D methods, see DefaultParms method.
* Expected output if PrintDebug enabled:
* ------------ Start ------------
* Base - Val(444.555)
* Base - Ref(444.555)
* Base - Ptr(444.555)
* Base - FullyOverloaded(int 10)
* Base - FullyOverloaded(bool 1)
* Base - SemiOverloaded(int -678)
* Base - SemiOverloaded(bool 1)
* Base - DefaultParms(10, 2.2)
* Base - DefaultParms(10, 1.1)
* --------------------------------
* Derived - Val(444.555)
* Derived - Ref(444.555)
* Derived - Ptr(444.555)
* Derived - FullyOverloaded(int 10)
* Derived - FullyOverloaded(bool 1)
* Derived - SemiOverloaded(int -678)
* Base - SemiOverloaded(bool 1)
* Derived - DefaultParms(10, 2.2)
* Derived - DefaultParms(10, 1.1)
* --------------------------------
* DDerived - Val(444.555)
* DDerived - Ref(444.555)
* DDerived - Ptr(444.555)
* DDerived - FullyOverloaded(int 10)
* DDerived - FullyOverloaded(bool true)
* DDerived - SemiOverloaded(-678)
* Base - SemiOverloaded(bool 1)
* DDerived - DefaultParms(10, 2.2)
* DDerived - DefaultParms(10, 1.1)
* ------------ Finish ------------
*/
module director_classes_runme;
import std.exception;
import std.stdio;
import std.string;
import director_classes.director_classes;
import director_classes.Caller;
import director_classes.Base;
import director_classes.Derived;
import director_classes.DoubleHolder;
void main() {
if (PrintDebug) writeln("------------ Start ------------ ");
auto myCaller = new Caller();
// Test C++ base class.
{
scope myBase = new Base(100.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) writeln("--------------------------------");
// Test vanilla C++ wrapped derived class.
{
scope myBase = new Derived(200.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) writeln("--------------------------------");
// Test director / D derived class.
{
scope myBase = new DDerived(300.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) writeln("------------ Finish ------------ ");
}
void makeCalls(Caller myCaller, Base myBase) {
string myBaseType = myBase.classinfo.name.split(".")[$-1];
myCaller.set(myBase);
DoubleHolder dh = new DoubleHolder(444.555);
// Class pointer, reference and pass by value tests
enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed");
enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed");
enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed");
// Fully overloaded method test (all methods in base class are overloaded)
enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed");
enforce(myCaller.FullyOverloadedCall(true) == myBaseType ~ "::FullyOverloaded(bool)", "[5] failed");
// Semi overloaded method test (some methods in base class are overloaded)
enforce(myCaller.SemiOverloadedCall(-678) == myBaseType ~ "::SemiOverloaded(int)", "[6] failed");
enforce(myCaller.SemiOverloadedCall(true) == "Base" ~ "::SemiOverloaded(bool)", "[7] failed");
// Default parameters methods test
enforce(myCaller.DefaultParmsCall(10, 2.2) == myBaseType ~ "::DefaultParms(int, double)", "[8] failed");
if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no other way to do this
enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int, double)", "[9] failed");
} else {
enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int)", "[10] failed");
}
myCaller.reset();
}
public class DDerived : Base {
public this(double dd) {
super(dd);
}
public override DoubleHolder Val(DoubleHolder x) {
if (PrintDebug) writefln("DDerived - Val(%s)", x.val);
return x;
}
public override DoubleHolder Ref(DoubleHolder x) {
if (PrintDebug) writefln("DDerived - Ref(%s)", x.val);
return x;
}
public override DoubleHolder Ptr(DoubleHolder x) {
if (PrintDebug) writefln("DDerived - Ptr(%s)", x.val);
return x;
}
public override string FullyOverloaded(int x) {
if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x);
return "DDerived::FullyOverloaded(int)";
}
public override string FullyOverloaded(bool x) {
if (PrintDebug) writefln("DDerived - FullyOverloaded(bool %s)", x);
return "DDerived::FullyOverloaded(bool)";
}
public override string SemiOverloaded(int x) {
string ret = "DDerived::SemiOverloaded(int)";
if (PrintDebug) writefln("DDerived - SemiOverloaded(%s)", x);
return ret;
}
alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x).
public override string DefaultParms(int x, double y) {
string ret = "DDerived::DefaultParms(int, double)";
if (PrintDebug) writefln("DDerived - DefaultParms(%s, %s)", x, y);
return ret;
}
// This method will never be called from C++ code because the two-parameter
// DefaultParams() has a default value for the second parameter there. It is
// only here to ensure consistent behavior for calls from C++ and D code.
public override string DefaultParms(int x) {
if (PrintDebug) writefln("DDerived - DefaultParms(%s)", x);
return DefaultParms(x, 1.1/*use C++ default here*/);
}
}

View file

@ -0,0 +1,207 @@
module director_classic_runme;
import tango.io.Stdout;
import director_classic.Caller;
import director_classic.Person;
import director_classic.Child;
import director_classic.GrandChild;
import director_classic.OrphanPerson;
import director_classic.OrphanChild;
const bool TRACE = false;
void main() {
{
scope person = new Person();
check(person, "Person");
}
{
scope person = new Child();
check(person, "Child");
}
{
scope person = new GrandChild();
check(person, "GrandChild");
}
{
scope person = new TargetLangPerson();
check(person, "TargetLangPerson");
}
{
scope person = new TargetLangChild();
check(person, "TargetLangChild");
}
{
scope person = new TargetLangGrandChild();
check(person, "TargetLangGrandChild");
}
// Semis - don't override id() in target language
{
scope person = new TargetLangSemiPerson();
check(person, "Person");
}
{
scope person = new TargetLangSemiChild();
check(person, "Child");
}
{
scope person = new TargetLangSemiGrandChild();
check(person, "GrandChild");
}
// Orphans - don't override id() in C++
{
scope person = new OrphanPerson();
check(person, "Person");
}
{
scope person = new OrphanChild();
check(person, "Child");
}
{
scope person = new TargetLangOrphanPerson();
check(person, "TargetLangOrphanPerson");
}
{
scope person = new TargetLangOrphanChild();
check(person, "TargetLangOrphanChild");
}
// Duals - id() makes an upcall to the base id()
{
scope person = new TargetLangDualPerson();
check(person, "TargetLangDualPerson + Person");
}
{
scope person = new TargetLangDualChild();
check(person, "TargetLangDualChild + Child");
}
{
scope person = new TargetLangDualGrandChild();
check(person, "TargetLangDualGrandChild + GrandChild");
}
// Mix Orphans and Duals
{
scope person = new TargetLangDualOrphanPerson();
check(person, "TargetLangDualOrphanPerson + Person");
}
{
scope person = new TargetLangDualOrphanChild();
check(person, "TargetLangDualOrphanChild + Child");
}
}
void check(Person person, char[] expected) {
char[] ret;
// Normal D polymorphic call.
ret = person.id();
if (TRACE)
Stdout(ret).newline;
if (ret != expected)
throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
// Polymorphic call from C++.
Caller caller = new Caller();
caller.setCallback(person);
ret = caller.call();
if (TRACE)
Stdout(ret).newline;
if (ret != expected)
throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
// Polymorphic call of object created in D and passed to C++ and back again.
Person baseclass = caller.baseClass();
ret = baseclass.id();
if (TRACE)
Stdout(ret).newline;
if (ret != expected)
throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected);
caller.resetCallback();
if (TRACE)
Stdout("----------------------------------------").newline;
}
// »Full« target language persons.
class TargetLangPerson : Person {
public override char[] id() {
return "TargetLangPerson";
}
}
class TargetLangChild : Child {
public override char[] id() {
return "TargetLangChild";
}
}
class TargetLangGrandChild : GrandChild {
public override char[] id() {
return "TargetLangGrandChild";
}
}
// Semis - don't override id() in target language
class TargetLangSemiPerson : Person {
// No id() override
}
class TargetLangSemiChild : Child {
// No id() override
}
class TargetLangSemiGrandChild : GrandChild {
// No id() override
}
// Orphans - don't override id() in C++
class TargetLangOrphanPerson : OrphanPerson {
public override char[] id() {
return "TargetLangOrphanPerson";
}
}
class TargetLangOrphanChild : OrphanChild {
public override char[] id() {
return "TargetLangOrphanChild";
}
}
// Duals - id() makes an upcall to the base id()
class TargetLangDualPerson : Person {
public override char[] id() {
return "TargetLangDualPerson + " ~ super.id();
}
}
class TargetLangDualChild : Child {
public override char[] id() {
return "TargetLangDualChild + " ~ super.id();
}
}
class TargetLangDualGrandChild : GrandChild {
public override char[] id() {
return "TargetLangDualGrandChild + " ~ super.id();
}
}
// Mix Orphans and Duals
class TargetLangDualOrphanPerson : OrphanPerson {
public override char[] id() {
return "TargetLangDualOrphanPerson + " ~ super.id();
}
}
class TargetLangDualOrphanChild : OrphanChild {
public override char[] id() {
return "TargetLangDualOrphanChild + " ~ super.id();
}
}

View file

@ -0,0 +1,202 @@
module director_classic_runme;
import std.exception;
import std.stdio;
import director_classic.Caller;
import director_classic.Person;
import director_classic.Child;
import director_classic.GrandChild;
import director_classic.OrphanPerson;
import director_classic.OrphanChild;
enum TRACE = false;
void main() {
{
scope person = new Person();
check(person, "Person");
}
{
scope person = new Child();
check(person, "Child");
}
{
scope person = new GrandChild();
check(person, "GrandChild");
}
{
scope person = new TargetLangPerson();
check(person, "TargetLangPerson");
}
{
scope person = new TargetLangChild();
check(person, "TargetLangChild");
}
{
scope person = new TargetLangGrandChild();
check(person, "TargetLangGrandChild");
}
// Semis - don't override id() in target language
{
scope person = new TargetLangSemiPerson();
check(person, "Person");
}
{
scope person = new TargetLangSemiChild();
check(person, "Child");
}
{
scope person = new TargetLangSemiGrandChild();
check(person, "GrandChild");
}
// Orphans - don't override id() in C++
{
scope person = new OrphanPerson();
check(person, "Person");
}
{
scope person = new OrphanChild();
check(person, "Child");
}
{
scope person = new TargetLangOrphanPerson();
check(person, "TargetLangOrphanPerson");
}
{
scope person = new TargetLangOrphanChild();
check(person, "TargetLangOrphanChild");
}
// Duals - id() makes an upcall to the base id()
{
scope person = new TargetLangDualPerson();
check(person, "TargetLangDualPerson + Person");
}
{
scope person = new TargetLangDualChild();
check(person, "TargetLangDualChild + Child");
}
{
scope person = new TargetLangDualGrandChild();
check(person, "TargetLangDualGrandChild + GrandChild");
}
// Mix Orphans and Duals
{
scope person = new TargetLangDualOrphanPerson();
check(person, "TargetLangDualOrphanPerson + Person");
}
{
scope person = new TargetLangDualOrphanChild();
check(person, "TargetLangDualOrphanChild + Child");
}
}
void check(Person person, string expected) {
string ret;
// Normal D polymorphic call.
ret = person.id();
if (TRACE) writeln(ret);
enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
// Polymorphic call from C++.
auto caller = new Caller();
caller.setCallback(person);
ret = caller.call();
if (TRACE) writeln(ret);
enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
// Polymorphic call of object created in D and passed to C++ and back again.
Person baseclass = caller.baseClass();
ret = baseclass.id();
if (TRACE) writeln(ret);
enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected);
caller.resetCallback();
if (TRACE)
writeln("----------------------------------------");
}
// »Full« target language persons.
class TargetLangPerson : Person {
public override string id() {
return "TargetLangPerson";
}
}
class TargetLangChild : Child {
public override string id() {
return "TargetLangChild";
}
}
class TargetLangGrandChild : GrandChild {
public override string id() {
return "TargetLangGrandChild";
}
}
// Semis - don't override id() in target language
class TargetLangSemiPerson : Person {
// No id() override
}
class TargetLangSemiChild : Child {
// No id() override
}
class TargetLangSemiGrandChild : GrandChild {
// No id() override
}
// Orphans - don't override id() in C++
class TargetLangOrphanPerson : OrphanPerson {
public override string id() {
return "TargetLangOrphanPerson";
}
}
class TargetLangOrphanChild : OrphanChild {
public override string id() {
return "TargetLangOrphanChild";
}
}
// Duals - id() makes an upcall to the base id()
class TargetLangDualPerson : Person {
public override string id() {
return "TargetLangDualPerson + " ~ super.id();
}
}
class TargetLangDualChild : Child {
public override string id() {
return "TargetLangDualChild + " ~ super.id();
}
}
class TargetLangDualGrandChild : GrandChild {
public override string id() {
return "TargetLangDualGrandChild + " ~ super.id();
}
}
// Mix Orphans and Duals
class TargetLangDualOrphanPerson : OrphanPerson {
public override string id() {
return "TargetLangDualOrphanPerson + " ~ super.id();
}
}
class TargetLangDualOrphanChild : OrphanChild {
public override string id() {
return "TargetLangDualOrphanChild + " ~ super.id();
}
}

View file

@ -0,0 +1,39 @@
module director_ignore_runme;
import director_ignore.DIgnores;
import director_ignore.DAbstractIgnores;
void main() {
// Just check the classes can be instantiated and other methods work as expected
auto a = new DIgnoresDerived();
if (a.Triple(5) != 15)
throw new Exception("Triple failed");
auto b = new DAbstractIgnoresDerived();
if (b.Quadruple(5) != 20)
throw new Exception("Quadruple failed");
}
class DIgnoresDerived : DIgnores {
public:
// These will give a warning if the %ignore is not working
int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedMethod(int n, int xoffset) { return 0; }
int OverloadedMethod(int n) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
int OverloadedProtectedMethod(int n) { return 0; }
}
class DAbstractIgnoresDerived : DAbstractIgnores {
public:
// These will give a warning if the %ignore is not working
int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedMethod(int n, int xoffset) { return 0; }
int OverloadedMethod(int n) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
int OverloadedProtectedMethod(int n) { return 0; }
}

View file

@ -0,0 +1,42 @@
module director_ignore_runme;
import std.exception;
import director_ignore.DIgnores;
import director_ignore.DAbstractIgnores;
void main() {
// Just check the classes can be instantiated and other methods work as expected
auto a = new DIgnoresDerived();
enforce(a.Triple(5) == 15, "Triple failed");
auto b = new DAbstractIgnoresDerived();
enforce(b.Quadruple(5) == 20, "Quadruple failed");
}
class DIgnoresDerived : DIgnores {
public:
// These will give a warning if the %ignore is not working
int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedMethod(int n, int xoffset) { return 0; }
int OverloadedMethod(int n) { return 0; }
alias super.OverloadedMethod OverloadedMethod;
protected:
int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
int OverloadedProtectedMethod(int n) { return 0; }
}
class DAbstractIgnoresDerived : DAbstractIgnores {
public:
// These will give a warning if the %ignore is not working
int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedMethod(int n, int xoffset) { return 0; }
int OverloadedMethod(int n) { return 0; }
alias super.OverloadedMethod OverloadedMethod;
protected:
int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; }
int OverloadedProtectedMethod(int n, int xoffset) { return 0; }
int OverloadedProtectedMethod(int n) { return 0; }
}

View file

@ -0,0 +1,122 @@
/**
* This test program shows a D class DDerived inheriting from Base.
*
* Three types of classes are created and the virtual methods called to
* demonstrate:
* - Wide variety of primitive types
* - Calling methods with zero, one or more parameters
* - Director methods that are not overridden in D
* - Director classes that are not overridden at all in D, i.e. non-director
* behaviour is as expected for director classes
* - Inheritance hierarchy using director methods
* - Return types working as well as parameters
*
* The Caller class is a tester class which calls the virtual functions from C++.
*/
module director_primitives_runme;
import tango.io.Stdout;
import director_primitives.director_primitives;
import director_primitives.Base;
import director_primitives.Caller;
import director_primitives.Derived;
import director_primitives.HShadowMode;
void main() {
PrintDebug = false;
if (PrintDebug) Stdout("------------ Start ------------ ").newline;
Caller myCaller = new Caller();
// Test C++ base class.
{
scope myBase = new Base(100.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout("--------------------------------").newline;
// Test vanilla C++ wrapped derived class.
{
scope Base myBase = new Derived(100.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout("--------------------------------").newline;
// Test director/D derived class.
{
scope Base myBase = new DDerived(300.0);
makeCalls(myCaller, myBase);
}
if (PrintDebug) Stdout("------------ Finish ------------ ").newline;
}
void makeCalls(Caller myCaller, Base myBase) {
myCaller.set(myBase);
myCaller.NoParmsMethodCall();
if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed");
if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed");
if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed");
if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed");
if (myCaller.FloatMethodCall(-123.456f) != -123.456f) throw new Exception("failed");
if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed");
if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed");
if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed");
myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard);
myCaller.NotOverriddenMethodCall();
myCaller.reset();
}
class DDerived : Base {
public:
this(double dd) {
super(dd);
}
override void NoParmsMethod() {
if (PrintDebug) Stdout("DDerived - NoParmsMethod()").newline;
}
override bool BoolMethod(bool x) {
if (PrintDebug) Stdout.formatln("DDerived - BoolMethod({0})", x);
return x;
}
override int IntMethod(int x) {
if (PrintDebug) Stdout.formatln("DDerived - IntMethod({0})", x);
return x;
}
override uint UIntMethod(uint x) {
if (PrintDebug) Stdout.formatln("DDerived - UIntMethod({0})", x);
return x;
}
override float FloatMethod(float x) {
if (PrintDebug) Stdout.formatln("DDerived - FloatMethod({0})", x);
return x;
}
override char[] CharPtrMethod(char[] x) {
if (PrintDebug) Stdout.formatln("DDerived - CharPtrMethod({0})", x);
return x;
}
override char[] ConstCharPtrMethod(char[] x) {
if (PrintDebug) Stdout.formatln("DDerived - ConstCharPtrMethod({0})", x);
return x;
}
override HShadowMode EnumMethod(HShadowMode x) {
if (PrintDebug) Stdout.formatln("DDerived - EnumMethod({0})", x);
return x;
}
override void ManyParmsMethod(bool b, int i, uint u, float f, char[] c, char[] cc, HShadowMode h) {
if (PrintDebug) Stdout.formatln("DDerived - ManyParmsMethod({0}, {1}, {2}, {3:d3}, {4}, {5}, {6})", b, i, u, f, c, cc, h);
}
}

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