Merge branch 'master' into C
This commit is contained in:
commit
55741f9e31
1702 changed files with 57386 additions and 21599 deletions
|
|
@ -47,6 +47,6 @@ testdir/README file.
|
|||
Further Documentation
|
||||
---------------------
|
||||
|
||||
There is documentation about the test-suite and how to use use it in
|
||||
There is documentation about the test-suite and how to use it in
|
||||
the SWIG documentation - Doc/Manual/Extending.html#Extending_test_suite.
|
||||
|
||||
|
|
|
|||
|
|
@ -79,5 +79,9 @@ protected:
|
|||
};
|
||||
int ProtectedBase::staticMemberVariable = 10;
|
||||
|
||||
class ProtectedDerived : public ProtectedBase {
|
||||
public:
|
||||
ProtectedDerived(const char *s) : ProtectedBase(s) {}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
%module(docstring="hello.") autodoc
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) inout;
|
||||
|
||||
%feature("autodoc");
|
||||
|
||||
// special typemap and its docs
|
||||
|
|
@ -74,6 +76,10 @@
|
|||
%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
|
||||
%feature("autodoc","0") C::~C(); // names
|
||||
%feature("autodoc","1") D::~D(); // names + types
|
||||
%feature("autodoc","2") E::~E(); // extended
|
||||
%feature("autodoc","3") F::~F(); // extended + types
|
||||
|
||||
%inline {
|
||||
|
||||
|
|
@ -133,6 +139,14 @@ typedef int Integer;
|
|||
void banana(S *a, const struct tagS *b, int c, Integer d) {}
|
||||
%}
|
||||
|
||||
// Check docs for a template type
|
||||
%inline %{
|
||||
template<typename X> struct T {
|
||||
T inout(T t) { return t; }
|
||||
};
|
||||
%}
|
||||
%template(TInteger) T<int>;
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
|
|
@ -140,4 +154,32 @@ bool is_python_builtin() { return true; }
|
|||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
// Autodoc language keywords
|
||||
%feature(autodoc,1) process;
|
||||
%feature(autodoc,1) process2;
|
||||
%feature("compactdefaultargs") process;
|
||||
%feature("compactdefaultargs") process2;
|
||||
%inline %{
|
||||
int process(int from, int in, int var) { return from; }
|
||||
int process2(int from = 0, int _in = 1, int var = 2) { return from; }
|
||||
%}
|
||||
|
||||
%feature(autodoc,1) process3;
|
||||
%feature(autodoc,1) process4;
|
||||
%feature("kwargs") process3;
|
||||
%feature("kwargs") process4;
|
||||
%inline %{
|
||||
int process3(int from, int _in, int var) { return from; }
|
||||
int process4(int from = 0, int _in = 1, int var = 2) { return from; }
|
||||
%}
|
||||
|
||||
// Autodoc for methods with default arguments not directly representable in
|
||||
// target language.
|
||||
%feature(autodoc,0) process_complex_defval;
|
||||
%feature("compactdefaultargs") process_complex_defval;
|
||||
%inline %{
|
||||
const int PROCESS_DEFAULT_VALUE = 17;
|
||||
typedef long int some_type;
|
||||
int process_complex_defval(int val = PROCESS_DEFAULT_VALUE, int factor = some_type(-1)) { return val*factor; }
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
%module catches
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW3(T1, T2, T3) throw(T1, T2, T3)
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#define TESTCASE_THROW3(T1, T2, T3)
|
||||
%}
|
||||
|
||||
%include <exception.i> // for throws(...) typemap
|
||||
|
|
@ -23,7 +23,7 @@ void test_catches(int i) {
|
|||
throw ThreeException();
|
||||
}
|
||||
}
|
||||
void test_exception_specification(int i) throw(int, const char *, const ThreeException&) {
|
||||
void test_exception_specification(int i) TESTCASE_THROW3(int, const char *, const ThreeException&) {
|
||||
test_catches(i);
|
||||
}
|
||||
void test_catches_all(int i) {
|
||||
|
|
|
|||
160
Examples/test-suite/class_scope_namespace.i
Normal file
160
Examples/test-suite/class_scope_namespace.i
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// Test a mix of forward class declarations, class definitions, using declarations and using directives.
|
||||
|
||||
%module class_scope_namespace
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) H::HH;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Space8::I_::II;
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
namespace Space1 {
|
||||
namespace SubSpace1 {
|
||||
struct A {
|
||||
void aa(Space1::SubSpace1::A, SubSpace1::A, A) {}
|
||||
};
|
||||
void aaa(Space1::SubSpace1::A, SubSpace1::A, A) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Space2 {
|
||||
struct B;
|
||||
}
|
||||
using Space2::B;
|
||||
#ifdef __clang__
|
||||
namespace Space2 {
|
||||
struct B {
|
||||
void bb(Space2::B, B) {}
|
||||
};
|
||||
}
|
||||
#else
|
||||
struct B {
|
||||
void bb(Space2::B, B) {}
|
||||
};
|
||||
#endif
|
||||
void bbb(Space2::B, B) {}
|
||||
|
||||
namespace Space3 {
|
||||
namespace SubSpace3 {
|
||||
struct C;
|
||||
struct D;
|
||||
}
|
||||
}
|
||||
struct C;
|
||||
struct D;
|
||||
namespace Space3 {
|
||||
struct C;
|
||||
struct SubSpace3::C {
|
||||
void cc(Space3::SubSpace3::C, SubSpace3::C) {}
|
||||
};
|
||||
using SubSpace3::D;
|
||||
struct SubSpace3::D {
|
||||
void dd(Space3::SubSpace3::D, SubSpace3::D, D) {}
|
||||
};
|
||||
void ccc(Space3::SubSpace3::C, SubSpace3::C) {}
|
||||
void ddd(Space3::SubSpace3::D, SubSpace3::D, D) {}
|
||||
}
|
||||
|
||||
namespace Space4 {
|
||||
namespace SubSpace4 {
|
||||
struct E;
|
||||
}
|
||||
}
|
||||
using namespace Space4;
|
||||
using SubSpace4::E;
|
||||
// Was added to incorrect namespace in swig-3.0.12
|
||||
struct SubSpace4::E {
|
||||
void ee(Space4::SubSpace4::E, SubSpace4::E, E) {}
|
||||
};
|
||||
void eee(Space4::SubSpace4::E, SubSpace4::E, E) {}
|
||||
|
||||
namespace Space5 {
|
||||
namespace SubSpace5 {
|
||||
namespace SubSubSpace5 {
|
||||
struct F;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Space5 {
|
||||
using namespace SubSpace5;
|
||||
using SubSubSpace5::F;
|
||||
// Was added to incorrect namespace in swig-3.0.12
|
||||
struct SubSubSpace5::F {
|
||||
void ff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
|
||||
};
|
||||
void fff(Space5::SubSpace5::SubSubSpace5::F, SubSpace5::SubSubSpace5::F, SubSubSpace5::F, F) {}
|
||||
}
|
||||
|
||||
namespace Space6 {
|
||||
struct G;
|
||||
namespace SubSpace6 {
|
||||
struct G;
|
||||
}
|
||||
}
|
||||
namespace Space6 {
|
||||
struct SubSpace6::G {
|
||||
void gg(Space6::SubSpace6::G, SubSpace6::G) {}
|
||||
};
|
||||
void ggg(Space6::SubSpace6::G, SubSpace6::G) {}
|
||||
}
|
||||
|
||||
struct HH;
|
||||
struct H {
|
||||
struct HH {
|
||||
void hh(H::HH) {}
|
||||
};
|
||||
};
|
||||
void hhh(H::HH) {}
|
||||
|
||||
namespace Space8 {
|
||||
struct II;
|
||||
struct I_ {
|
||||
struct II {
|
||||
void ii(Space8::I_::II, I_::II) {}
|
||||
};
|
||||
};
|
||||
void iii(Space8::I_::II, I_::II) {}
|
||||
}
|
||||
|
||||
struct J;
|
||||
namespace Space9 {
|
||||
namespace SubSpace9 {
|
||||
struct J {
|
||||
void jj(Space9::SubSpace9::J, SubSpace9::J, J) {}
|
||||
};
|
||||
void jjj(Space9::SubSpace9::J, SubSpace9::J, J) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Space10 {
|
||||
struct K;
|
||||
}
|
||||
namespace Space10 {
|
||||
namespace SubSpace10 {
|
||||
struct K {
|
||||
void kk(Space10::SubSpace10::K, SubSpace10::K, K) {}
|
||||
};
|
||||
void kkk(Space10::SubSpace10::K, SubSpace10::K, K) {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OtherSpace {
|
||||
struct L;
|
||||
struct M;
|
||||
}
|
||||
using OtherSpace::L;
|
||||
namespace Space11 {
|
||||
using OtherSpace::M;
|
||||
namespace SubSpace11 {
|
||||
struct L {
|
||||
void ll(Space11::SubSpace11::L, SubSpace11::L, L) {}
|
||||
};
|
||||
void lll(Space11::SubSpace11::L, SubSpace11::L, L) {}
|
||||
struct M {
|
||||
void mm(Space11::SubSpace11::M, SubSpace11::M, M) {}
|
||||
};
|
||||
void mmm(Space11::SubSpace11::M, SubSpace11::M, M) {}
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -83,13 +83,11 @@ Makefile: $(srcdir)/Makefile.in ../../../config.status
|
|||
# Broken C++ test cases. (Can be run individually using: make testcase.cpptest)
|
||||
CPP_TEST_BROKEN += \
|
||||
constants \
|
||||
cpp_broken \
|
||||
director_nested_class \
|
||||
exception_partial_info \
|
||||
extend_variable \
|
||||
li_boost_shared_ptr_template \
|
||||
nested_private \
|
||||
overload_complicated \
|
||||
rename_camel \
|
||||
template_default_pointer \
|
||||
template_private_assignment \
|
||||
|
|
@ -99,7 +97,7 @@ CPP_TEST_BROKEN += \
|
|||
|
||||
# Broken C test cases. (Can be run individually using: make testcase.ctest)
|
||||
C_TEST_BROKEN += \
|
||||
tag_no_clash_with_variable
|
||||
tag_no_clash_with_variable \
|
||||
|
||||
# C++ test cases. (Can be run individually using: make testcase.cpptest)
|
||||
CPP_TEST_CASES += \
|
||||
|
|
@ -136,6 +134,7 @@ CPP_TEST_CASES += \
|
|||
char_binary \
|
||||
char_strings \
|
||||
chartest \
|
||||
class_scope_namespace \
|
||||
class_forward \
|
||||
class_ignore \
|
||||
class_scope_weird \
|
||||
|
|
@ -162,13 +161,20 @@ CPP_TEST_CASES += \
|
|||
cpp_nodefault \
|
||||
cpp_static \
|
||||
cpp_typedef \
|
||||
cpp14_binary_integer_literals \
|
||||
cpp17_hex_floating_literals \
|
||||
cpp17_nested_namespaces \
|
||||
cpp17_nspace_nested_namespaces \
|
||||
cpp17_u8_char_literals \
|
||||
curiously_recurring_template_pattern \
|
||||
default_args \
|
||||
default_arg_expressions \
|
||||
default_arg_values \
|
||||
default_constructor \
|
||||
defvalue_constructor \
|
||||
derived_byvalue \
|
||||
derived_nested \
|
||||
destructor_methodmodifiers \
|
||||
destructor_reprotected \
|
||||
director_abstract \
|
||||
director_alternating \
|
||||
|
|
@ -181,6 +187,8 @@ CPP_TEST_CASES += \
|
|||
director_detect \
|
||||
director_enum \
|
||||
director_exception \
|
||||
director_exception_catches \
|
||||
director_exception_nothrow \
|
||||
director_extend \
|
||||
director_finalizer \
|
||||
director_frob \
|
||||
|
|
@ -192,6 +200,7 @@ CPP_TEST_CASES += \
|
|||
director_nspace_director_name_collision \
|
||||
director_overload \
|
||||
director_overload2 \
|
||||
director_ownership \
|
||||
director_pass_by_value \
|
||||
director_primitives \
|
||||
director_property \
|
||||
|
|
@ -203,6 +212,7 @@ CPP_TEST_CASES += \
|
|||
director_thread \
|
||||
director_unroll \
|
||||
director_using \
|
||||
director_void \
|
||||
director_wombat \
|
||||
disown \
|
||||
dynamic_cast \
|
||||
|
|
@ -226,6 +236,7 @@ CPP_TEST_CASES += \
|
|||
extend_placement \
|
||||
extend_special_variables \
|
||||
extend_template \
|
||||
extend_template_method \
|
||||
extend_template_ns \
|
||||
extend_typedef_class \
|
||||
extern_c \
|
||||
|
|
@ -237,6 +248,7 @@ CPP_TEST_CASES += \
|
|||
friends \
|
||||
friends_template \
|
||||
funcptr_cpp \
|
||||
functors \
|
||||
fvirtual \
|
||||
global_namespace \
|
||||
global_ns_arg \
|
||||
|
|
@ -244,6 +256,7 @@ CPP_TEST_CASES += \
|
|||
global_vars \
|
||||
grouping \
|
||||
ignore_parameter \
|
||||
import_fragments \
|
||||
import_nomodule \
|
||||
inherit \
|
||||
inherit_member \
|
||||
|
|
@ -259,11 +272,11 @@ CPP_TEST_CASES += \
|
|||
langobj \
|
||||
li_attribute \
|
||||
li_attribute_template \
|
||||
li_boost_array \
|
||||
li_boost_shared_ptr \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_template \
|
||||
li_boost_shared_ptr_attribute \
|
||||
li_boost_shared_ptr_bits \
|
||||
li_boost_shared_ptr_director \
|
||||
li_boost_shared_ptr_template \
|
||||
li_carrays_cpp \
|
||||
li_cdata_cpp \
|
||||
li_cpointer_cpp \
|
||||
|
|
@ -277,6 +290,7 @@ CPP_TEST_CASES += \
|
|||
memberin_extend \
|
||||
member_funcptr_galore \
|
||||
member_pointer \
|
||||
member_pointer_const \
|
||||
member_template \
|
||||
minherit \
|
||||
minherit2 \
|
||||
|
|
@ -288,6 +302,7 @@ CPP_TEST_CASES += \
|
|||
multiple_inheritance_shared_ptr \
|
||||
name_cxx \
|
||||
name_warnings \
|
||||
namespace_chase \
|
||||
namespace_class \
|
||||
namespace_enum \
|
||||
namespace_extend \
|
||||
|
|
@ -301,6 +316,7 @@ CPP_TEST_CASES += \
|
|||
namespace_virtual_method \
|
||||
nspace \
|
||||
nspace_extend \
|
||||
native_directive \
|
||||
naturalvar \
|
||||
naturalvar_more \
|
||||
naturalvar_onoff \
|
||||
|
|
@ -308,10 +324,13 @@ CPP_TEST_CASES += \
|
|||
nested_directors \
|
||||
nested_comment \
|
||||
nested_ignore \
|
||||
nested_inheritance_interface \
|
||||
nested_in_template \
|
||||
nested_scope \
|
||||
nested_template_base \
|
||||
nested_workaround \
|
||||
newobject1 \
|
||||
newobject3 \
|
||||
null_pointer \
|
||||
operator_overload \
|
||||
operator_overload_break \
|
||||
|
|
@ -320,10 +339,12 @@ CPP_TEST_CASES += \
|
|||
ordering \
|
||||
overload_arrays \
|
||||
overload_bool \
|
||||
overload_complicated \
|
||||
overload_copy \
|
||||
overload_extend \
|
||||
overload_method \
|
||||
overload_numeric \
|
||||
overload_null \
|
||||
overload_polymorphic \
|
||||
overload_rename \
|
||||
overload_return_type \
|
||||
|
|
@ -335,13 +356,13 @@ CPP_TEST_CASES += \
|
|||
preproc_constants \
|
||||
primitive_ref \
|
||||
private_assign \
|
||||
proxycode \
|
||||
protected_rename \
|
||||
pure_virtual \
|
||||
redefined \
|
||||
redefined_not \
|
||||
refcount \
|
||||
reference_global_vars \
|
||||
register_par \
|
||||
rename1 \
|
||||
rename2 \
|
||||
rename3 \
|
||||
|
|
@ -353,6 +374,7 @@ CPP_TEST_CASES += \
|
|||
rename_pcre_encoder \
|
||||
rename_pcre_enum \
|
||||
rename_predicates \
|
||||
rename_wildcard \
|
||||
restrict_cplusplus \
|
||||
return_const_value \
|
||||
return_value_scope \
|
||||
|
|
@ -386,9 +408,11 @@ CPP_TEST_CASES += \
|
|||
static_array_member \
|
||||
static_const_member \
|
||||
static_const_member_2 \
|
||||
stl_no_default_constructor \
|
||||
string_constants \
|
||||
struct_initialization_cpp \
|
||||
struct_value \
|
||||
swig_exception \
|
||||
symbol_clash \
|
||||
template_arg_replace \
|
||||
template_arg_scope \
|
||||
|
|
@ -397,6 +421,7 @@ CPP_TEST_CASES += \
|
|||
template_basic \
|
||||
template_base_template \
|
||||
template_classes \
|
||||
template_class_reuse_name \
|
||||
template_const_ref \
|
||||
template_construct \
|
||||
template_templated_constructors \
|
||||
|
|
@ -406,11 +431,13 @@ CPP_TEST_CASES += \
|
|||
template_default_arg_overloaded \
|
||||
template_default_arg_overloaded_extend \
|
||||
template_default_arg_virtual_destructor \
|
||||
template_default_cache \
|
||||
template_default_class_parms \
|
||||
template_default_class_parms_typedef \
|
||||
template_default_inherit \
|
||||
template_default_qualify \
|
||||
template_default_vw \
|
||||
template_empty_inherit \
|
||||
template_enum \
|
||||
template_enum_ns_inherit \
|
||||
template_enum_typedef \
|
||||
|
|
@ -427,6 +454,7 @@ CPP_TEST_CASES += \
|
|||
template_methods \
|
||||
template_namespace_forward_declaration \
|
||||
template_using_directive_and_declaration_forward \
|
||||
template_using_directive_typedef \
|
||||
template_nested \
|
||||
template_nested_typemaps \
|
||||
template_ns \
|
||||
|
|
@ -437,6 +465,7 @@ CPP_TEST_CASES += \
|
|||
template_ns_enum2 \
|
||||
template_ns_inherit \
|
||||
template_ns_scope \
|
||||
template_parameters_global_scope \
|
||||
template_partial_arg \
|
||||
template_partial_specialization \
|
||||
template_partial_specialization_typedef \
|
||||
|
|
@ -474,6 +503,7 @@ CPP_TEST_CASES += \
|
|||
throw_exception \
|
||||
typedef_array_member \
|
||||
typedef_class \
|
||||
typedef_classforward_same_name \
|
||||
typedef_funcptr \
|
||||
typedef_inherit \
|
||||
typedef_mptr \
|
||||
|
|
@ -486,6 +516,7 @@ CPP_TEST_CASES += \
|
|||
typemap_array_qualifiers \
|
||||
typemap_delete \
|
||||
typemap_directorout \
|
||||
typemap_documentation \
|
||||
typemap_global_scope \
|
||||
typemap_manyargs \
|
||||
typemap_namespace \
|
||||
|
|
@ -493,6 +524,8 @@ CPP_TEST_CASES += \
|
|||
typemap_numinputs \
|
||||
typemap_template \
|
||||
typemap_template_parm_typedef \
|
||||
typemap_template_parms \
|
||||
typemap_template_typedef \
|
||||
typemap_out_optimal \
|
||||
typemap_qualifier_strip \
|
||||
typemap_variables \
|
||||
|
|
@ -519,15 +552,18 @@ CPP_TEST_CASES += \
|
|||
valuewrapper_opaque \
|
||||
varargs \
|
||||
varargs_overload \
|
||||
variable_replacement \
|
||||
virtual_destructor \
|
||||
virtual_derivation \
|
||||
virtual_poly \
|
||||
virtual_vs_nonvirtual_base \
|
||||
voidtest \
|
||||
wallkw \
|
||||
wrapmacro
|
||||
wrapmacro \
|
||||
|
||||
# C++11 test cases.
|
||||
CPP11_TEST_CASES = \
|
||||
CPP11_TEST_CASES += \
|
||||
cpp11_alias_nested_template_scoping \
|
||||
cpp11_alignment \
|
||||
cpp11_alternate_function_syntax \
|
||||
cpp11_constexpr \
|
||||
|
|
@ -535,23 +571,28 @@ CPP11_TEST_CASES = \
|
|||
cpp11_default_delete \
|
||||
cpp11_delegating_constructors \
|
||||
cpp11_director_enums \
|
||||
cpp11_directors \
|
||||
cpp11_explicit_conversion_operators \
|
||||
cpp11_final_directors \
|
||||
cpp11_final_override \
|
||||
cpp11_function_objects \
|
||||
cpp11_inheriting_constructors \
|
||||
cpp11_initializer_list \
|
||||
cpp11_initializer_list_extend \
|
||||
cpp11_lambda_functions \
|
||||
cpp11_li_std_array \
|
||||
cpp11_noexcept \
|
||||
cpp11_null_pointer_constant \
|
||||
cpp11_raw_string_literals \
|
||||
cpp11_ref_qualifiers \
|
||||
cpp11_ref_qualifiers_rvalue_unignore \
|
||||
cpp11_ref_qualifiers_typemaps \
|
||||
cpp11_result_of \
|
||||
cpp11_rvalue_reference \
|
||||
cpp11_rvalue_reference2 \
|
||||
cpp11_rvalue_reference3 \
|
||||
cpp11_sizeof_object \
|
||||
cpp11_static_assert \
|
||||
cpp11_std_array \
|
||||
cpp11_strongly_typed_enumerations \
|
||||
cpp11_thread_local \
|
||||
cpp11_template_double_brackets \
|
||||
|
|
@ -565,10 +606,35 @@ CPP11_TEST_CASES = \
|
|||
|
||||
# Broken C++11 test cases.
|
||||
CPP11_TEST_BROKEN = \
|
||||
# cpp11_hash_tables \ # not fully implemented yet
|
||||
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
|
||||
# cpp11_reference_wrapper \ # No typemaps
|
||||
|
||||
# Doxygen support test cases: can only be used with languages supporting
|
||||
# Doxygen comment translation, currently only Python and Java.
|
||||
python_HAS_DOXYGEN := 1
|
||||
java_HAS_DOXYGEN := 1
|
||||
|
||||
$(eval HAS_DOXYGEN := $($(LANGUAGE)_HAS_DOXYGEN))
|
||||
|
||||
ifdef HAS_DOXYGEN
|
||||
DOXYGEN_TEST_CASES += \
|
||||
doxygen_alias \
|
||||
doxygen_basic_notranslate \
|
||||
doxygen_basic_translate \
|
||||
doxygen_basic_translate_style2 \
|
||||
doxygen_ignore \
|
||||
doxygen_misc_constructs \
|
||||
doxygen_nested_class \
|
||||
doxygen_parsing \
|
||||
doxygen_parsing_enums \
|
||||
doxygen_translate \
|
||||
doxygen_translate_all_tags \
|
||||
doxygen_translate_links \
|
||||
|
||||
$(DOXYGEN_TEST_CASES:=.cpptest): SWIGOPT += -doxygen
|
||||
|
||||
CPP_TEST_CASES += $(DOXYGEN_TEST_CASES)
|
||||
endif
|
||||
|
||||
#
|
||||
# Put all the heavy STD/STL cases here, where they can be skipped if needed
|
||||
|
|
@ -585,15 +651,15 @@ CPP_STD_TEST_CASES += \
|
|||
li_std_pair_using \
|
||||
li_std_string \
|
||||
li_std_vector \
|
||||
li_std_vector_back_reference \
|
||||
li_std_vector_enum \
|
||||
li_std_vector_member_var\
|
||||
li_std_vector_ptr \
|
||||
li_std_wstring \
|
||||
smart_pointer_inherit \
|
||||
template_typedef_fnc \
|
||||
template_type_namespace \
|
||||
template_opaque
|
||||
# li_std_list
|
||||
|
||||
template_opaque \
|
||||
|
||||
ifndef SKIP_CPP_STD_CASES
|
||||
CPP_TEST_CASES += ${CPP_STD_TEST_CASES}
|
||||
|
|
@ -612,6 +678,7 @@ C_TEST_CASES += \
|
|||
char_constant \
|
||||
const_const \
|
||||
constant_expr \
|
||||
default_args_c \
|
||||
empty_c \
|
||||
enums \
|
||||
enum_forward \
|
||||
|
|
@ -645,8 +712,10 @@ C_TEST_CASES += \
|
|||
preproc \
|
||||
preproc_constants_c \
|
||||
preproc_defined \
|
||||
preproc_gcc_output \
|
||||
preproc_include \
|
||||
preproc_line_file \
|
||||
register_par \
|
||||
ret_by_value \
|
||||
simple_array \
|
||||
sizeof_pointer \
|
||||
|
|
@ -654,21 +723,22 @@ C_TEST_CASES += \
|
|||
string_simple \
|
||||
struct_rename \
|
||||
struct_initialization \
|
||||
typedef_classforward_same_name \
|
||||
typedef_struct \
|
||||
typemap_subst \
|
||||
union_parameter \
|
||||
unions
|
||||
unions \
|
||||
|
||||
|
||||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
||||
MULTI_CPP_TEST_CASES += \
|
||||
clientdata_prop \
|
||||
imports \
|
||||
import_stl \
|
||||
packageoption \
|
||||
imports \
|
||||
mod \
|
||||
multi_import \
|
||||
packageoption \
|
||||
template_typedef_import \
|
||||
multi_import
|
||||
|
||||
# Custom tests - tests with additional commandline options
|
||||
wallkw.cpptest: SWIGOPT += -Wallkw
|
||||
|
|
@ -717,6 +787,10 @@ check-cpp: $(CPP_TEST_CASES:=.cpptest)
|
|||
|
||||
check-cpp11: $(CPP11_TEST_CASES:=.cpptest)
|
||||
|
||||
ifdef HAS_DOXYGEN
|
||||
check-doxygen: $(DOXYGEN_TEST_CASES:=.cpptest)
|
||||
endif
|
||||
|
||||
check-failing-test = \
|
||||
$(MAKE) -s $1.$2 >/dev/null 2>/dev/null && echo "Failing test $1 passed."
|
||||
|
||||
|
|
@ -757,7 +831,7 @@ swig_and_compile_external = \
|
|||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$*_wrap_hdr.h' \
|
||||
$(LANGUAGE)$(VARIANT)_externalhdr; \
|
||||
$(LANGUAGE)$(VARIANT)_externalhdr && \
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS) $*_external.cxx' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
|
||||
|
|
@ -771,7 +845,7 @@ setup = \
|
|||
echo "$(ACTION)ing $(LANGUAGE) testcase $* (with run test)" ; \
|
||||
else \
|
||||
echo "$(ACTION)ing $(LANGUAGE) testcase $*" ; \
|
||||
fi;
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,26 +14,53 @@
|
|||
%template(VectorStdCplx) std::vector<std::complex<double> >;
|
||||
#endif
|
||||
|
||||
%inline
|
||||
%inline
|
||||
{
|
||||
std::complex<double> Conj(const std::complex<double>& a)
|
||||
std::complex<double> Conj(std::complex<double> a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
}
|
||||
|
||||
std::complex<float> Conjf(const std::complex<float>& a)
|
||||
std::complex<float> Conjf(std::complex<float> a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
|
||||
std::vector<std::complex<double> > CopyHalf(std::vector<std::complex<double> > a)
|
||||
{
|
||||
std::vector<std::complex<double> > b(a.size()/2);
|
||||
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ComplexPair
|
||||
{
|
||||
std::complex<double> z1;
|
||||
complex<double> z2;
|
||||
};
|
||||
|
||||
const complex<double>& Conj2(const complex<double>& a)
|
||||
{
|
||||
static complex<double> ret;
|
||||
ret = std::conj(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const complex<float>& Conjf2(const complex<float>& a)
|
||||
{
|
||||
static complex<float> ret;
|
||||
ret = std::conj(a);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const vector<complex<double> >& CopyHalfRef(const vector<complex<double> >& a)
|
||||
{
|
||||
static vector<complex<double> > b;
|
||||
b = CopyHalf(a);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -43,7 +70,7 @@
|
|||
%{
|
||||
%}
|
||||
|
||||
%inline
|
||||
%inline
|
||||
{
|
||||
complex Conj(complex a)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
// %constant and struct
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4190) // warning C4190: 'result' has C-linkage specified, but returns UDT 'Type1' which is incompatible with C
|
||||
|
|
|
|||
|
|
@ -73,12 +73,18 @@ public:
|
|||
|
||||
%include "std_vector.i"
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT) || defined(SWIGSCILAB)
|
||||
#if defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT) || defined(SWIGSCILAB)
|
||||
#define SWIG_GOOD_VECTOR
|
||||
%ignore std::vector<Space::Flow>::vector(size_type);
|
||||
%ignore std::vector<Space::Flow>::resize(size_type);
|
||||
#endif
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
#define SWIG_GOOD_VECTOR
|
||||
%ignore std::vector<Space::Flow>::vector(jint);
|
||||
%ignore std::vector<Space::Flow>::resize(jint);
|
||||
#endif
|
||||
|
||||
#if defined(SWIGTCL) || defined(SWIGPERL)
|
||||
#define SWIG_GOOD_VECTOR
|
||||
/* here, for languages with bad declaration */
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
%module cplusplus_throw
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%nodefaultctor;
|
||||
|
|
@ -20,8 +20,8 @@ class Foo { };
|
|||
class Bar {
|
||||
public:
|
||||
void baz() const { };
|
||||
void foo() throw (Foo) { };
|
||||
void bazfoo() const throw (int) { };
|
||||
void foo() TESTCASE_THROW1(Foo) { };
|
||||
void bazfoo() const TESTCASE_THROW1(int) { };
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
|||
45
Examples/test-suite/cpp11_alias_nested_template_scoping.i
Normal file
45
Examples/test-suite/cpp11_alias_nested_template_scoping.i
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
%module cpp11_alias_nested_template_scoping
|
||||
|
||||
// Test to check a template parameter type is expanded when the template parameter
|
||||
// is used twice in a type name. Expansion was
|
||||
// Y< short >::YYY< T >::value_type >
|
||||
// instead of
|
||||
// Y< short >::YYY< short >::value_type >
|
||||
|
||||
#if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
|
||||
%feature("flatnested") ZZZ;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
template<typename T> struct Y {
|
||||
typedef T value_type;
|
||||
typedef Y YY;
|
||||
template<typename T2> using YYY = Y<T2>;
|
||||
template<typename T2> struct ZZZ {
|
||||
typedef T2 another_type;
|
||||
};
|
||||
value_type create1() const { return T(); }
|
||||
typename Y::value_type create2() const { return T(); }
|
||||
typename Y<T>::value_type create3() const { return T(); }
|
||||
typename YY::value_type create4() const { return T(); }
|
||||
typename Y<T>::YY::value_type create5() const { return T(); }
|
||||
Y<T>::YYY<T>::value_type create6() const { return T(); }
|
||||
typename Y<T>::template ZZZ<T>::another_type create7() const { return T(); }
|
||||
|
||||
// With global scope prefix
|
||||
typename ::Y<T>::value_type create13() const { return T(); }
|
||||
|
||||
typename ::Y<T>::YY::value_type create15() const { return T(); }
|
||||
::Y<T>::YYY<T>::value_type create16() const { return T(); }
|
||||
typename ::Y<T>::template ZZZ<T>::another_type create17() const { return T(); }
|
||||
};
|
||||
%}
|
||||
|
||||
%extend Y {
|
||||
%template() YYY<short>;
|
||||
%template() ZZZ<short>;
|
||||
};
|
||||
// Use above workaround instead of below (which currently gives syntax error)
|
||||
// %template() Y<short>::YYY<short>;
|
||||
|
||||
%template(Yshort) Y<short>;
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
struct A {
|
||||
int member;
|
||||
};
|
||||
const int align1 = alignof(A::member);
|
||||
const int align1 = alignof(int);
|
||||
const int align2 = alignof(int *);
|
||||
%}
|
||||
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -6,13 +6,26 @@
|
|||
struct SomeStruct {
|
||||
int addNormal(int x, int y);
|
||||
auto addAlternate(int x, int y) -> int;
|
||||
auto addAlternateConst(int x, int y) const -> int;
|
||||
auto addAlternateNoExcept(int x, int y) noexcept -> int;
|
||||
auto addAlternateConstNoExcept(int x, int y) const noexcept -> int;
|
||||
auto addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int;
|
||||
auto addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int;
|
||||
|
||||
virtual auto addFinal(int x, int y) const noexcept -> int final { return x + y; }
|
||||
virtual ~SomeStruct() = default;
|
||||
};
|
||||
|
||||
auto SomeStruct::addAlternate(int x, int y) -> int {
|
||||
return x + y;
|
||||
int SomeStruct::addNormal(int x, int y) { return x + y; }
|
||||
auto SomeStruct::addAlternate(int x, int y) -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateConst(int x, int y) const -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateNoExcept(int x, int y) noexcept -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateConstNoExcept(int x, int y) const noexcept -> int { return x + y; }
|
||||
auto SomeStruct::addAlternateMemberPtrParm(int x, int (SomeStruct::*mp)(int, int)) -> int {
|
||||
return 100*x + (this->*mp)(x, x);
|
||||
}
|
||||
auto SomeStruct::addAlternateMemberPtrConstParm(int x, int (SomeStruct::*mp)(int, int) const) const -> int {
|
||||
return 1000*x + (this->*mp)(x, x);
|
||||
}
|
||||
|
||||
int SomeStruct::addNormal(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,26 @@
|
|||
*/
|
||||
%module cpp11_constexpr
|
||||
|
||||
|
||||
%{
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
// Suppress: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior
|
||||
// For MMM() and NNN()
|
||||
#pragma clang diagnostic ignored "-Wconstexpr-not-const"
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIG
|
||||
#define SWIGTESTCONST const
|
||||
#else
|
||||
#define SWIGTESTCONST
|
||||
#endif
|
||||
constexpr int AAA = 10;
|
||||
constexpr const int BBB = 20;
|
||||
constexpr int CCC() { return 30; }
|
||||
constexpr const int DDD() { return 40; }
|
||||
constexpr SWIGTESTCONST int DDD() { return 40; }
|
||||
|
||||
constexpr int XXX() { return 10; }
|
||||
constexpr int YYY = XXX() + 100;
|
||||
|
|
@ -17,7 +32,7 @@ struct ConstExpressions {
|
|||
static constexpr int KKK = 200;
|
||||
static const int LLL = 300;
|
||||
constexpr int MMM() { return 400; }
|
||||
constexpr const int NNN() { return 500; }
|
||||
constexpr SWIGTESTCONST int NNN() { return 500; }
|
||||
// Regression tests for support added in SWIG 3.0.4:
|
||||
static constexpr const int JJJ1 = 101;
|
||||
constexpr static int KKK1 = 201;
|
||||
|
|
|
|||
|
|
@ -17,20 +17,26 @@ public:
|
|||
};
|
||||
|
||||
struct A1 {
|
||||
void func(int i) {}
|
||||
void funk(int i) {}
|
||||
A1() = default;
|
||||
~A1() = default;
|
||||
void func(double i) = delete; /* Don't cast double to int. Compiler returns an error */
|
||||
void funk(double i) = delete; /* Don't cast double to int. Compiler returns an error */
|
||||
private:
|
||||
A1(const A1&);
|
||||
};
|
||||
A1::A1(const A1&) = default;
|
||||
|
||||
struct A2 {
|
||||
void func(int i) {}
|
||||
void funk(int i) {}
|
||||
|
||||
// Workaround clang 10.0.1 -std=c++17 linker error (oddly for Java and not Python):
|
||||
// Undefined symbols for architecture x86_64:"___cxa_deleted_virtual", referenced from: vtable for A2
|
||||
#if !(defined(__clang__) && __cplusplus >= 201703L)
|
||||
virtual void fff(int) = delete;
|
||||
#endif
|
||||
|
||||
virtual ~A2() = default;
|
||||
template<class T> void func(T) = delete;
|
||||
template<class T> void funk(T) = delete;
|
||||
};
|
||||
|
||||
struct trivial {
|
||||
|
|
|
|||
16
Examples/test-suite/cpp11_directors.i
Normal file
16
Examples/test-suite/cpp11_directors.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
%module(directors="1") cpp11_directors
|
||||
%feature("director");
|
||||
|
||||
%inline %{
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() noexcept {}
|
||||
virtual int ping() noexcept = 0;
|
||||
virtual int pong() noexcept = 0;
|
||||
virtual int pang() const& noexcept = 0;
|
||||
virtual int peng() & noexcept = 0;
|
||||
virtual int pung() & = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
33
Examples/test-suite/cpp11_final_directors.i
Normal file
33
Examples/test-suite/cpp11_final_directors.i
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%module(directors="1") cpp11_final_directors
|
||||
|
||||
%director Derived;
|
||||
|
||||
// Check SWIG will not wrap these classes as directors where the destructors are final
|
||||
%director BaseFinalDestructor;
|
||||
%director BaseFinalDestructor2;
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_DIRECTOR_FINAL) BaseFinalDestructor::~BaseFinalDestructor;
|
||||
%warnfilter(SWIGWARN_LANG_DIRECTOR_FINAL) BaseFinalDestructor2::~BaseFinalDestructor2;
|
||||
|
||||
%inline %{
|
||||
struct Base {
|
||||
virtual void basemeth() final {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
struct Derived : Base {
|
||||
virtual int derivedmeth() final { return 1; }
|
||||
virtual int meth() { return 2; }
|
||||
virtual ~Derived() {}
|
||||
};
|
||||
|
||||
struct BaseFinalDestructor {
|
||||
virtual void basefinalmeth() final {}
|
||||
virtual ~BaseFinalDestructor() final {}
|
||||
};
|
||||
|
||||
struct BaseFinalDestructor2 {
|
||||
virtual void basefinalmeth() {}
|
||||
virtual ~BaseFinalDestructor2() final {}
|
||||
};
|
||||
%}
|
||||
|
|
@ -6,6 +6,12 @@
|
|||
%warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final'
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override'
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Base {
|
||||
|
|
@ -16,6 +22,8 @@ struct Base {
|
|||
virtual void finaloverride2() {}
|
||||
virtual void finaloverride3() {}
|
||||
virtual void finaloverride4() const {}
|
||||
virtual void finaloverride5() {}
|
||||
virtual void finaloverride6() const {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
|
|
@ -31,6 +39,8 @@ struct Derived /*final*/ : Base {
|
|||
virtual void finaloverride2() override final {}
|
||||
virtual void finaloverride3() noexcept override final {}
|
||||
virtual void finaloverride4() const noexcept override final {}
|
||||
virtual void finaloverride5() TESTCASE_THROW1(int) override final {}
|
||||
virtual void finaloverride6() const TESTCASE_THROW1(int) override final {}
|
||||
virtual ~Derived() override final {}
|
||||
};
|
||||
void Derived::override2() const noexcept {}
|
||||
|
|
@ -78,6 +88,7 @@ struct Destructors4 : Base {
|
|||
struct FinalOverrideMethods {
|
||||
virtual void final() {}
|
||||
virtual void override(int) {}
|
||||
virtual ~FinalOverrideMethods() = default;
|
||||
};
|
||||
struct FinalOverrideVariables {
|
||||
int final;
|
||||
|
|
@ -126,3 +137,4 @@ void DerivedNoVirtualStruct::cd() {}
|
|||
void DerivedNoVirtualStruct::ef() {}
|
||||
DerivedNoVirtualStruct::~DerivedNoVirtualStruct() {}
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,19 +4,27 @@
|
|||
|
||||
%inline %{
|
||||
#include <set>
|
||||
//#include <map>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
//#include <unordered_map>
|
||||
#include <unordered_map>
|
||||
%}
|
||||
|
||||
%include "std_set.i"
|
||||
//%include "std_map.i"
|
||||
%include "std_multiset.i"
|
||||
%include "std_map.i"
|
||||
%include "std_multimap.i"
|
||||
%include "std_unordered_set.i"
|
||||
//%include "std_unordered_map.i"
|
||||
%include "std_unordered_multiset.i"
|
||||
%include "std_unordered_map.i"
|
||||
%include "std_unordered_multimap.i"
|
||||
%template (SetInt) std::set<int>;
|
||||
//%template (MapIntInt) std::map<int, int>;
|
||||
%template (MultiSetInt) std::multiset<int>;
|
||||
%template (MapIntInt) std::map<int, int>;
|
||||
%template (MultiMapIntInt) std::multimap<int, int>;
|
||||
%template (UnorderedSetInt) std::unordered_set<int>;
|
||||
//%template (UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template (UnorderedMultiSetInt) std::unordered_multiset<int>;
|
||||
%template (UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template (UnorderedMultiMapIntInt) std::unordered_multimap<int, int>;
|
||||
|
||||
%inline %{
|
||||
using namespace std;
|
||||
|
|
@ -25,19 +33,19 @@ class MyClass {
|
|||
public:
|
||||
set<int> getSet() { return _set; }
|
||||
void addSet(int elt) { _set.insert(_set.begin(), elt); }
|
||||
// map<int, int> getMap() { return _map; }
|
||||
// void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); }
|
||||
map<int, int> getMap() { return _map; }
|
||||
void addMap(int elt1, int elt2) { _map.insert(make_pair(elt1, elt2)); }
|
||||
|
||||
unordered_set<int> getUnorderedSet() { return _unordered_set; }
|
||||
void addUnorderedSet(int elt) { _unordered_set.insert(_unordered_set.begin(), elt); }
|
||||
// unordered_map<int, int> getUnorderedMap() { return _unordered_map; }
|
||||
// void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); }
|
||||
unordered_map<int, int> getUnorderedMap() { return _unordered_map; }
|
||||
void addUnorderedMap(int elt1, int elt2) { _unordered_map.insert(make_pair(elt1, elt2)); }
|
||||
private:
|
||||
set<int> _set;
|
||||
// map<int, int> _map;
|
||||
map<int, int> _map;
|
||||
|
||||
unordered_set<int> _unordered_set;
|
||||
// unordered_map<int, int> _unordered_map;
|
||||
unordered_map<int, int> _unordered_map;
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,21 @@
|
|||
%ignore A::A(std::initializer_list<int>);
|
||||
%ignore B::method;
|
||||
|
||||
%typemap(in) std::initializer_list<const char *> {
|
||||
%typemap(in) std::initializer_list<const char *> %{
|
||||
$1 = {"Ab", "Fab"};
|
||||
}
|
||||
%}
|
||||
|
||||
%begin %{
|
||||
#if __GNUC__ >= 9
|
||||
/* warning: ‘new’ of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime] */
|
||||
/* incorrect warning for C::C(std::initializer_list<const char *>) */
|
||||
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
class A {
|
||||
public:
|
||||
|
|
@ -26,9 +35,16 @@ public:
|
|||
void method(std::initializer_list<int> init) {}
|
||||
};
|
||||
class C {
|
||||
std::string joined;
|
||||
public:
|
||||
C(std::initializer_list<const char *>) {}
|
||||
C(std::initializer_list<const char *> init) {
|
||||
for (auto& val : init)
|
||||
joined += val;
|
||||
}
|
||||
C() {}
|
||||
const char * get_joined_string() {
|
||||
return joined.c_str();
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,14 @@
|
|||
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::lambda19;
|
||||
%warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::Space2::lambda20;
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW0() throw()
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW0()
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
/* Defined lambda function with return value. */
|
||||
auto lambda1 = [](int x, int y) -> int { return x+y; };
|
||||
|
|
@ -35,14 +43,17 @@ auto lambda1 = [](int x, int y) -> int { return x+y; };
|
|||
single statement "return expr;". */
|
||||
auto lambda2 = [](int x, int y) { return x+y; };
|
||||
|
||||
auto lambda3 = [&](int x, int y) { return x+y; };
|
||||
auto lambda4 = [=](int x, int y) { return x+y; };
|
||||
int thing = 0;
|
||||
#ifdef SWIG
|
||||
// Not strictly correct as captured variables should have non-automatic storage duration, ie shouldn't capture globals. gcc-4.7 warns about this, but we check that SWIG can parse this anyway.
|
||||
// This is not strictly legal: non-local lambda expression cannot have a capture-default
|
||||
// gcc-4.7 warns about this and gcc-9 gives an error, but we check that SWIG can parse this anyway.
|
||||
auto lambda3 = [&](int x, int y) { return x+y; };
|
||||
auto lambda4 = [=](int x, int y) { return x+y; };
|
||||
auto lambda5 = [=,&thing]() { return thing; };
|
||||
#else
|
||||
auto lambda5 = [=]() { return thing; };
|
||||
auto lambda3 = [](int x, int y) { return x+y; };
|
||||
auto lambda4 = [](int x, int y) { return x+y; };
|
||||
auto lambda5 = []() { return thing; };
|
||||
#endif
|
||||
|
||||
void fn() {
|
||||
|
|
@ -51,22 +62,27 @@ void fn() {
|
|||
}
|
||||
auto lambda6 = [] (int a, int b) mutable { return a + b; };
|
||||
auto lambda7 = [] (int x, int y) -> int { return x+y; };
|
||||
auto lambda8 = [] (int x, int y) throw() -> int { return x+y; };
|
||||
auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; };
|
||||
auto lambda10 = [] (int x, int y) throw(int) { return x+y; };
|
||||
auto lambda11 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
auto lambda8 = [] (int x, int y) TESTCASE_THROW0() -> int { return x+y; };
|
||||
auto lambda9 = [] (int x, int y) mutable TESTCASE_THROW0() -> int { return x+y; };
|
||||
auto lambda10 = [] (int x, int y) TESTCASE_THROW1(int) { return x+y; };
|
||||
auto lambda11 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
auto lambda12 = [] (int a, int b) { return a + b; }(1, 2);
|
||||
auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2);
|
||||
auto lambda14 = [] () throw () {};
|
||||
auto lambda15 = [] () mutable throw () {};
|
||||
auto lambda14 = [] () TESTCASE_THROW0() {};
|
||||
auto lambda15 = [] () mutable TESTCASE_THROW0() {};
|
||||
auto lambda16 = [] { return thing; };
|
||||
auto lambda17 = [] { return thing; }();
|
||||
constexpr auto lambda18 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
#if defined(SWIG) || (defined(__cplusplus) && __cplusplus >= 201703L)
|
||||
#define CONSTEXPR constexpr
|
||||
#else
|
||||
#define CONSTEXPR
|
||||
#endif
|
||||
CONSTEXPR auto lambda18 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
|
||||
namespace Space1 {
|
||||
constexpr auto lambda19 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
CONSTEXPR auto lambda19 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
namespace Space2 {
|
||||
constexpr auto lambda20 = [] (int x, int y) mutable throw(int) { return x+y; };
|
||||
CONSTEXPR auto lambda20 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +118,6 @@ int runLambdaInline() {
|
|||
// TODO
|
||||
int(*lambda101notauto)(int, int) = [] (int a, int b) { return a + b; };
|
||||
int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2);
|
||||
void lambda_init(int = ([=]{ return 0; })());
|
||||
void lambda_init(int = ([]{ return 0; })());
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
%ignore NoExceptClass(NoExceptClass&&);
|
||||
%rename(Assignment) NoExceptClass::operator=;
|
||||
|
||||
%{
|
||||
extern "C" void global_noexcept(int, bool) noexcept {}
|
||||
%}
|
||||
%inline %{
|
||||
|
||||
extern "C" void global_noexcept(int, bool) noexcept;
|
||||
extern "C" void global_noexcept2(int, bool) noexcept {}
|
||||
|
||||
struct NoExceptClass {
|
||||
static const bool VeryTrue = true;
|
||||
|
|
@ -14,7 +18,7 @@ struct NoExceptClass {
|
|||
NoExceptClass(const NoExceptClass&) noexcept {}
|
||||
NoExceptClass(NoExceptClass&&) noexcept {}
|
||||
NoExceptClass& operator=(const NoExceptClass&) noexcept { return *this; }
|
||||
~NoExceptClass() noexcept {}
|
||||
virtual ~NoExceptClass() noexcept {}
|
||||
|
||||
void noex0() noexcept {}
|
||||
void noex1() noexcept(sizeof(int) == 4) {}
|
||||
|
|
@ -27,8 +31,13 @@ struct NoExceptClass {
|
|||
void noo1() const noexcept {}
|
||||
static void noo2() noexcept {}
|
||||
virtual void noo3() const noexcept {}
|
||||
|
||||
// Workaround clang 10.0.1 -std=c++17 linker error (oddly for Java and not Python):
|
||||
// Undefined symbols for architecture x86_64: "___cxa_deleted_virtual", referenced from: vtable for NoExceptClass
|
||||
#if !(defined(__clang__) && __cplusplus >= 201703L)
|
||||
virtual void noo4() const noexcept = delete;
|
||||
virtual void noo5() const throw() = delete;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct NoExceptAbstract {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) hh;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ii;
|
||||
|
||||
#if defined(SWIGTCL) || defined(SWIGCSHARP) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGPYTHON) || defined(SWIGJAVA)
|
||||
%include <std_wstring.i>
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
|
@ -45,6 +47,9 @@ wstring aa = L"Wide string";
|
|||
const char *bb = u8"UTF-8 string";
|
||||
const char16_t *cc = u"UTF-16 string";
|
||||
const char32_t *dd = U"UTF-32 string";
|
||||
// New char literals
|
||||
char16_t char16_t_char = u'a';
|
||||
char32_t char32_t_char = U'b';
|
||||
%}
|
||||
|
||||
/* Raw string literals */
|
||||
|
|
@ -57,3 +62,43 @@ const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX";
|
|||
const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
|
||||
%}
|
||||
|
||||
// Constants
|
||||
#if defined(SWIGJAVA)
|
||||
%javaconst(1);
|
||||
#elif SWIGCSHARP
|
||||
%csconst(1);
|
||||
#elif SWIGD
|
||||
%dmanifestconst;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#define jj ")I'm an \"ascii\" \\ string constant."
|
||||
#define kk R"XXX()I'm an "ascii" \ string constant.)XXX";
|
||||
%}
|
||||
|
||||
%constant mm = R"XXX()I'm an "ascii" \ string constant with multiple
|
||||
|
||||
lines.)XXX";
|
||||
|
||||
// docstring feature
|
||||
%feature("docstring") RawStringDoc::WW "Single line documentation comment"
|
||||
%feature("docstring") RawStringDoc::XX %{
|
||||
Multi-line
|
||||
documentation
|
||||
comment
|
||||
%}
|
||||
%feature("docstring") RawStringDoc::YY R"RRR(Single line "raw string" documentation comment)RRR"
|
||||
%feature("docstring") RawStringDoc::ZZ R"FOO(Documentation comment
|
||||
|
||||
as a "raw string"
|
||||
on multiple lines including a \ backslash)FOO"
|
||||
|
||||
%inline %{
|
||||
struct RawStringDoc {
|
||||
void WW() {}
|
||||
void XX() {}
|
||||
void YY() {}
|
||||
void ZZ() {}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
226
Examples/test-suite/cpp11_ref_qualifiers.i
Normal file
226
Examples/test-suite/cpp11_ref_qualifiers.i
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
%module cpp11_ref_qualifiers
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%ignore Host::h() const &;
|
||||
|
||||
// Basic testing
|
||||
%inline %{
|
||||
using std::string;
|
||||
class Host {
|
||||
string s;
|
||||
public:
|
||||
string h1() & { return string(); }
|
||||
string h2() const & { return string(); }
|
||||
string h3() && { return std::move(string()); }
|
||||
string h4() const && { return std::move(string()); }
|
||||
string h5() const { return string(); }
|
||||
string h6() volatile const & { return string(); }
|
||||
string h7() const volatile & { return string(); }
|
||||
string h8() volatile const && { return std::move(string()); }
|
||||
string h9() const volatile && { return std::move(string()); }
|
||||
|
||||
string h() & { return string(); }
|
||||
string h() const & { return string(); }
|
||||
string h() && { return std::move(string()); }
|
||||
string h() const && { return std::move(string()); }
|
||||
};
|
||||
%}
|
||||
|
||||
// %feature testing
|
||||
%feature("except") F1() & %{ result = "F1"; %}
|
||||
%feature("except") F2 %{ result = "F2"; %}
|
||||
%feature("except") F3 %{ result = "F3"; %}
|
||||
%feature("except") F3() %{ _should_not_be_used_ %}
|
||||
|
||||
%feature("except") C1(int i) const & %{ result = "C1"; %}
|
||||
%feature("except") C2 %{ result = "C2"; %}
|
||||
%feature("except") C3 %{ result = "C3"; %}
|
||||
%feature("except") C3(int i) %{ _should_not_be_used_ %}
|
||||
|
||||
%inline %{
|
||||
struct Features {
|
||||
string F1() & { return string(); }
|
||||
string F2() & { return string(); }
|
||||
string F3() & { return string(); }
|
||||
|
||||
string C1(int i) const & { return string(); }
|
||||
string C2(int i) const & { return string(); }
|
||||
string C3(int i) const & { return string(); }
|
||||
};
|
||||
%}
|
||||
|
||||
// %rename testing
|
||||
%rename(RR1) R1;
|
||||
%rename(RR2) R2() &;
|
||||
%rename(RR3) R3;
|
||||
%rename(RR3Bad) R3();
|
||||
|
||||
%rename(SS1) S1;
|
||||
%rename(SS2) S2(int i) const &;
|
||||
%rename(SS3) S3;
|
||||
%rename(SS3Bad) S3(int i);
|
||||
%rename(SS3BadConst) S3(int i) const;
|
||||
%rename(SS3BadLValue) S3(int i) &;
|
||||
|
||||
%inline %{
|
||||
struct Renames {
|
||||
string R1() & { return string(); }
|
||||
string R2() & { return string(); }
|
||||
string R3() & { return string(); }
|
||||
|
||||
string S1(int i) const & { return string(); }
|
||||
string S2(int i) const & { return string(); }
|
||||
string S3(int i) const & { return string(); }
|
||||
};
|
||||
%}
|
||||
|
||||
// Conversion operators
|
||||
%rename(StringConvertCopy) operator string() &;
|
||||
%rename(StringConvertMove) operator string() &&;
|
||||
%feature("ignore", "0") operator string() &&; // unignore as it is ignored by default
|
||||
|
||||
%inline %{
|
||||
struct ConversionOperators {
|
||||
virtual operator string() & { return string(); }
|
||||
virtual operator string() && { return std::move(string()); }
|
||||
virtual ~ConversionOperators() {}
|
||||
};
|
||||
struct ConversionOperators2 {
|
||||
virtual operator string() && { return std::move(string()); }
|
||||
virtual ~ConversionOperators2() {}
|
||||
};
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FF(bool) { return 0; }
|
||||
short CC(bool) const & { return 0; }
|
||||
};
|
||||
|
||||
class MemberFuncPtrs
|
||||
{
|
||||
public:
|
||||
// member ref-qualified function pointers, unnamed parameters
|
||||
int aaa1(short (Funcs::*)(bool) &) const;
|
||||
int aaa2(short (Funcs::* const *&)(bool) &) const;
|
||||
int aaa3(short (Funcs::* *&)(bool) &) const;
|
||||
int aaa4(short (Funcs::* *const&)(bool) &) const;
|
||||
int aaa5(short (Funcs::* &)(bool) &) const;
|
||||
int aaa6(short (Funcs::* const)(bool) &) const;
|
||||
int aaa7(short (Funcs::* const&)(bool) &) const;
|
||||
|
||||
int aaa8(short (Funcs::* const&)(bool) &&) const;
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, unnamed parameters
|
||||
int bbb1(short (Funcs::*)(bool) const &) const;
|
||||
int bbb2(short (Funcs::* const *&)(bool) const &) const;
|
||||
int bbb3(short (Funcs::* *&)(bool) const &) const;
|
||||
int bbb4(short (Funcs::* *const&)(bool) const &) const;
|
||||
int bbb5(short (Funcs::* &)(bool) const &) const;
|
||||
int bbb6(short (Funcs::* const)(bool) const &) const;
|
||||
int bbb7(short (Funcs::* const&)(bool) const &) const;
|
||||
|
||||
int bbb8(short (Funcs::*)(bool) const &&) const;
|
||||
|
||||
// member ref-qualified function pointers, named parameters
|
||||
int qqq1(short (Funcs::* qq1)(bool) &) const;
|
||||
int qqq2(short (Funcs::* const *& qq2)(bool) &) const;
|
||||
int qqq3(short (Funcs::* *& qq3)(bool) &) const;
|
||||
int qqq4(short (Funcs::* *const& qq4)(bool) &) const;
|
||||
int qqq5(short (Funcs::* & qq5)(bool) &) const;
|
||||
int qqq6(short (Funcs::* const qq6)(bool) &) const;
|
||||
int qqq7(short (Funcs::* const& qq7)(bool) &) const;
|
||||
|
||||
int qqq8(short (Funcs::* const& qq8)(bool) &&) const;
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, named parameters
|
||||
int rrr1(short (Funcs::* rr1)(bool) const &) const;
|
||||
int rrr2(short (Funcs::* const *& rr2)(bool) const &) const;
|
||||
int rrr3(short (Funcs::* *& rr3)(bool) const &) const;
|
||||
int rrr4(short (Funcs::* *const& rr4)(bool) const &) const;
|
||||
int rrr5(short (Funcs::* & rr5)(bool) const &) const;
|
||||
int rrr6(short (Funcs::* const rr6)(bool) const &) const;
|
||||
int rrr7(short (Funcs::* const& rr7)(bool) const &) const;
|
||||
|
||||
int rrr8(short (Funcs::* rr1)(bool) const &&) const;
|
||||
};
|
||||
|
||||
// member ref-qualified function pointers, unnamed parameters
|
||||
int MemberFuncPtrs::aaa1(short (Funcs::*)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa3(short (Funcs::* *&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa4(short (Funcs::* *const&)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa5(short (Funcs::* &)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa6(short (Funcs::* const)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::aaa7(short (Funcs::* const&)(bool) &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::aaa8(short (Funcs::* const&)(bool) &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, unnamed parameters
|
||||
int MemberFuncPtrs::bbb1(short (Funcs::*)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb2(short (Funcs::* const *&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb3(short (Funcs::* *&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb4(short (Funcs::* *const&)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb5(short (Funcs::* &)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb6(short (Funcs::* const)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::bbb7(short (Funcs::* const&)(bool) const &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::bbb8(short (Funcs::*)(bool) const &&) const { return 0; }
|
||||
|
||||
// member ref-qualified function pointers, named parameters
|
||||
int MemberFuncPtrs::qqq1(short (Funcs::* qq1)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq2(short (Funcs::* const *& qq2)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq3(short (Funcs::* *& qq3)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq4(short (Funcs::* *const& qq4)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool) &) const { return 0; }
|
||||
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool) &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::qqq8(short (Funcs::* const& qq8)(bool) &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified function pointers, named parameters
|
||||
int MemberFuncPtrs::rrr1(short (Funcs::* rr1)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr2(short (Funcs::* const *& rr2)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr3(short (Funcs::* *& rr3)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr4(short (Funcs::* *const& rr4)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr5(short (Funcs::* & rr5)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr6(short (Funcs::* const rr6)(bool) const &) const { return 0; }
|
||||
int MemberFuncPtrs::rrr7(short (Funcs::* const& rr7)(bool) const &) const { return 0; }
|
||||
|
||||
int MemberFuncPtrs::rrr8(short (Funcs::* rr1)(bool) const &&) const { return 0; }
|
||||
|
||||
// member cv-qualified and ref-qualified pointer variables
|
||||
short (Funcs::* cc1)(bool) const & = &Funcs::CC;
|
||||
|
||||
short (Funcs::* const * ccextra2)(bool) const & = &cc1;
|
||||
short (Funcs::* * ccextra3)(bool) const & = &cc1;
|
||||
short (Funcs::* *const ccextra4)(bool) const & = &cc1;
|
||||
|
||||
short (Funcs::* const *& cc2)(bool) const & = ccextra2;
|
||||
short (Funcs::* *& cc3)(bool) const & = ccextra3;
|
||||
short (Funcs::* *const& cc4)(bool) const & = ccextra4;
|
||||
short (Funcs::* & cc5)(bool) const & = cc1;
|
||||
short (Funcs::* const cc6)(bool) const & = &Funcs::CC;
|
||||
short (Funcs::* const& cc7)(bool) const & = cc1;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Funktions {
|
||||
int addByValue(const int &a, int b) const & { return a+b; }
|
||||
int * addByPointer(const int &a, int b) const & { static int val; val = a+b; return &val; }
|
||||
int & addByReference(const int &a, int b) const & { static int val; val = a+b; return val; }
|
||||
};
|
||||
|
||||
int call1(int (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
|
||||
//int call2(int * (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return *(f.*d)(a, b); }
|
||||
//int call3(int & (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
|
||||
%}
|
||||
%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const & = &Funktions::addByValue;
|
||||
15
Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
Normal file
15
Examples/test-suite/cpp11_ref_qualifiers_rvalue_unignore.i
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%module cpp11_ref_qualifiers_rvalue_unignore
|
||||
|
||||
// This is a minimal test that does not include any C++ headers to make sure the required
|
||||
// <memory> header is generated from a fragment for the generated std::move call
|
||||
|
||||
// m1 and m2 are ignored by default, unignore them
|
||||
%feature("ignore", "0") RefQualifier::m1() &&;
|
||||
%feature("ignore", "0") RefQualifier::m2() const &&;
|
||||
|
||||
%inline %{
|
||||
struct RefQualifier {
|
||||
void m1() && {}
|
||||
void m2() const && {}
|
||||
};
|
||||
%}
|
||||
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
74
Examples/test-suite/cpp11_ref_qualifiers_typemaps.i
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
%module cpp11_ref_qualifiers_typemaps
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*) %{
|
||||
_this_will_fail_to_compile_if_used_
|
||||
%}
|
||||
|
||||
// typemaps to completely ignore the input parm and override it
|
||||
%typemap(in) short (Funcs::*ff)(bool) const %{ $1 = &Funcs::FFF2; %}
|
||||
%typemap(in) short (Funcs::*cc)(bool) & %{ $1 = &Funcs::CCC5; %}
|
||||
%typemap(in) short (Funcs::*gg)(bool) const & %{ $1 = &Funcs::GGG8; %}
|
||||
%typemap(in) short (Funcs::*hh)(bool) && %{ $1 = &Funcs::HHH11; %}
|
||||
|
||||
%typemap(in) short (Funcs::*)(bool) const %{ $1 = &Funcs::FFF3; %}
|
||||
%typemap(in) short (Funcs::*)(bool) & %{ $1 = &Funcs::CCC6; %}
|
||||
%typemap(in) short (Funcs::*)(bool) const & %{ $1 = &Funcs::GGG9; %}
|
||||
%typemap(in) short (Funcs::*)(bool) && %{ $1 = &Funcs::HHH12; %}
|
||||
|
||||
%inline %{
|
||||
struct Funcs {
|
||||
short FFF1(bool) const { return 1; }
|
||||
short FFF2(bool) const { return 2; }
|
||||
short FFF3(bool) const { return 3; }
|
||||
short CCC4(bool) & { return 4; }
|
||||
short CCC5(bool) & { return 5; }
|
||||
short CCC6(bool) & { return 6; }
|
||||
short GGG7(bool) const & { return 7; }
|
||||
short GGG8(bool) const & { return 8; }
|
||||
short GGG9(bool) const & { return 9; }
|
||||
short HHH10(bool) && { return 10; }
|
||||
short HHH11(bool) && { return 11; }
|
||||
short HHH12(bool) && { return 12; }
|
||||
};
|
||||
struct TypemapsNamedParms
|
||||
{
|
||||
short fff(short (Funcs::*ff)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*ff)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*cc)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*cc)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*gg)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*gg)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*hh)(bool) &&) {
|
||||
return (Funcs().*hh)(true);
|
||||
}
|
||||
};
|
||||
struct TypemapsUnnamedParms
|
||||
{
|
||||
short fff(short (Funcs::*f)(bool) const) {
|
||||
Funcs funcs;
|
||||
return (funcs.*f)(true);
|
||||
}
|
||||
short ccc(short (Funcs::*c)(bool) &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*c)(true);
|
||||
}
|
||||
short ggg(short (Funcs::*g)(bool) const &) {
|
||||
Funcs funcs;
|
||||
return (funcs.*g)(true);
|
||||
}
|
||||
short hhh(short (Funcs::*h)(bool) &&) {
|
||||
return (Funcs().*h)(true);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%constant short (Funcs::*FF1_MFP)(bool) const = &Funcs::FFF1;
|
||||
%constant short (Funcs::*CC4_MFP)(bool) & = &Funcs::CCC4;
|
||||
%constant short (Funcs::*GG7_MFP)(bool) const & = &Funcs::GGG7;
|
||||
%constant short (Funcs::*HH10_MFP)(bool) && = &Funcs::HHH10;
|
||||
|
|
@ -23,7 +23,7 @@ struct Thingy {
|
|||
int val;
|
||||
int &lvalref;
|
||||
int &&rvalref;
|
||||
Thingy(int v) : val(v), lvalref(val), rvalref(22) {}
|
||||
Thingy(int v, int &&rvalv) : val(v), lvalref(val), rvalref(std::move(rvalv)) {}
|
||||
void refIn(long &i) {}
|
||||
void rvalueIn(long &&i) {}
|
||||
short && rvalueInOut(short &&i) { return std::move(i); }
|
||||
|
|
@ -31,8 +31,8 @@ struct Thingy {
|
|||
// test both primitive and user defined rvalue reference default arguments and compactdefaultargs
|
||||
void compactDefaultArgs(const bool &&b = (const bool &&)PublicGlobalTrue, const UserDef &&u = (const UserDef &&)PublicUserDef) {}
|
||||
void privateDefaultArgs(const bool &&b = (const bool &&)PrivateTrue) {}
|
||||
operator int &&() { return std::move(0); }
|
||||
Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(copy_int(rhs.rvalref)) {}
|
||||
operator int &&() { return std::move(val); }
|
||||
Thingy(const Thingy& rhs) : val(rhs.val), lvalref(rhs.lvalref), rvalref(std::move(rhs.rvalref)) {}
|
||||
Thingy& operator=(const Thingy& rhs) {
|
||||
val = rhs.val;
|
||||
lvalref = rhs.lvalref;
|
||||
|
|
@ -41,23 +41,25 @@ struct Thingy {
|
|||
}
|
||||
private:
|
||||
static const bool PrivateTrue;
|
||||
int copy_int(int& i) { return i; }
|
||||
Thingy();
|
||||
};
|
||||
const bool Thingy::PrivateTrue = true;
|
||||
|
||||
short && globalRvalueInOut(short &&i) { return std::move(i); }
|
||||
|
||||
Thingy &&globalrrval = Thingy(55);
|
||||
int glob = 123;
|
||||
|
||||
short && func(short &&i) { return std::move(i); }
|
||||
Thingy getit() { return Thingy(22); }
|
||||
Thingy &&globalrrval = Thingy(55, std::move(glob));
|
||||
|
||||
short && funk(short &&i) { return std::move(i); }
|
||||
Thingy getit() { return Thingy(22, std::move(glob)); }
|
||||
|
||||
void rvalrefFunction1(int &&v = (int &&)5) {}
|
||||
void rvalrefFunctionBYVAL(short (Thingy::*memFunc)(short)) {}
|
||||
void rvalrefFunctionLVALUE(short &(Thingy::*memFunc)(short &)) {}
|
||||
void rvalrefFunction2(short && (Thingy::*memFunc)(short &&)) {}
|
||||
void rvalrefFunction3(short && (*memFunc)(short &&)) {}
|
||||
void rvalrefFunctionBYVAL(short (Thingy::*fptr)(short)) {}
|
||||
void rvalrefFunctionPTR(short * (*fptr)(short *)) {}
|
||||
void rvalrefFunctionLVALUE(short & (Thingy::*fptr)(short &)) {}
|
||||
void rvalrefFunction2(short && (Thingy::*fptr)(short &&)) {}
|
||||
void rvalrefFunction3(short && (*fptr)(short &&)) {}
|
||||
|
||||
template <typename T> struct RemoveReference {
|
||||
typedef T type;
|
||||
|
|
|
|||
|
|
@ -26,12 +26,18 @@ void takeit5(Thing const*const&& t) {}
|
|||
|
||||
struct Containing {
|
||||
Thing && member_rvalue_ref;
|
||||
Thing *&& member_rvalue_ref_ptr1 = 0;
|
||||
Thing const*&& member_rvalue_ref_ptr2 = 0;
|
||||
Thing *const&& member_rvalue_ref_ptr3 = 0;
|
||||
Thing const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
Thing *&& member_rvalue_ref_ptr1;
|
||||
Thing const*&& member_rvalue_ref_ptr2;
|
||||
Thing *const&& member_rvalue_ref_ptr3;
|
||||
Thing const*const &&member_rvalue_ref_ptr4;
|
||||
|
||||
Containing() : member_rvalue_ref(Thing()) {}
|
||||
Containing(Thing&&r, Thing*&& r1, Thing const*&& r2, Thing *const&& r3, Thing const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
member_rvalue_ref_ptr1(std::move(r1)),
|
||||
member_rvalue_ref_ptr2(std::move(r2)),
|
||||
member_rvalue_ref_ptr3(std::move(r3)),
|
||||
member_rvalue_ref_ptr4(std::move(r4))
|
||||
{}
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
@ -57,11 +63,17 @@ void int_takeit5(int const*const&& t) {}
|
|||
|
||||
struct IntContaining {
|
||||
int && member_rvalue_ref;
|
||||
int *&& member_rvalue_ref_ptr1 = 0;
|
||||
int const*&& member_rvalue_ref_ptr2 = 0;
|
||||
int *const&& member_rvalue_ref_ptr3 = 0;
|
||||
int const*const &&member_rvalue_ref_ptr4 = 0;
|
||||
int *&& member_rvalue_ref_ptr1;
|
||||
int const*&& member_rvalue_ref_ptr2;
|
||||
int *const&& member_rvalue_ref_ptr3;
|
||||
int const*const &&member_rvalue_ref_ptr4;
|
||||
|
||||
IntContaining() : member_rvalue_ref(55) {}
|
||||
IntContaining(int&& r, int*&& r1, int const*&& r2, int *const&& r3, int const*const && r4) :
|
||||
member_rvalue_ref(std::move(r)),
|
||||
member_rvalue_ref_ptr1(std::move(r1)),
|
||||
member_rvalue_ref_ptr2(std::move(r2)),
|
||||
member_rvalue_ref_ptr3(std::move(r3)),
|
||||
member_rvalue_ref_ptr4(std::move(r4))
|
||||
{}
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
57
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
%module cpp11_shared_ptr_const
|
||||
|
||||
%{
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class Foo
|
||||
{
|
||||
int m;
|
||||
public:
|
||||
Foo(int i) : m(i) {}
|
||||
int get_m() { return m;}
|
||||
};
|
||||
|
||||
std::shared_ptr<Foo> foo(Foo v) {
|
||||
return std::shared_ptr<Foo>(new Foo(v));
|
||||
}
|
||||
|
||||
std::shared_ptr<const Foo> const_foo(Foo v) {
|
||||
return std::shared_ptr<const Foo>(new Foo(v));
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) {
|
||||
std::vector<std::shared_ptr<Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) {
|
||||
std::vector<std::shared_ptr<const Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(v)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(Foo);
|
||||
|
||||
%template (FooVector) std::vector<std::shared_ptr<Foo> >;
|
||||
%template (FooConstVector) std::vector<std::shared_ptr<Foo const> >;
|
||||
|
||||
class Foo
|
||||
{
|
||||
int m;
|
||||
public:
|
||||
Foo(int i);
|
||||
int get_m();
|
||||
};
|
||||
std::shared_ptr<Foo> foo(Foo v);
|
||||
std::shared_ptr<const Foo> const_foo(Foo v);
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec(Foo v) const;
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec(Foo v) const;
|
||||
|
||||
50
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
50
Examples/test-suite/cpp11_shared_ptr_nullptr_in_containers.i
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
%module cpp11_shared_ptr_nullptr_in_containers
|
||||
|
||||
%{
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class C;
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(C)
|
||||
|
||||
%inline %{
|
||||
|
||||
class C {
|
||||
int m;
|
||||
public:
|
||||
C() : m(-1) {}
|
||||
C(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%template() std::vector<std::shared_ptr<C> >;
|
||||
|
||||
%inline %{
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_vec_c_shared_ptr() {
|
||||
std::vector<std::shared_ptr<C> > ret(3);
|
||||
ret[0] = std::shared_ptr<C>(new C(0));
|
||||
ret[2] = std::shared_ptr<C>(new C(2));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<C> > ret_arg_vec(const std::vector<std::shared_ptr<C> >& v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
bool is_last_null(const std::vector<std::shared_ptr<C> >& v) {
|
||||
if( v.back() ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
89
Examples/test-suite/cpp11_shared_ptr_overload.i
Normal file
89
Examples/test-suite/cpp11_shared_ptr_overload.i
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
%module cpp11_shared_ptr_overload
|
||||
|
||||
// Tests to ensure valid overloading in C++ between shared_ptr and other types result in code that compiles
|
||||
// and all but the 1st overloaded method are automatically ignored/shadowed.
|
||||
// Tests the 'equivalent' attribute in the 'typecheck' typemap.
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseA(std::shared_ptr<MyType> mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseB(int, std::shared_ptr<MyType> mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>);
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseX(MyType &mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseY(int, MyType &mytype);
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) UseZ(int, MyType &mytype, std::shared_ptr<MyType>);
|
||||
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo1;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo2;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo3;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo4;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo5;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo6;
|
||||
%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED,SWIGWARN_LANG_OVERLOAD_SHADOW) Combo7;
|
||||
|
||||
%shared_ptr(MyType);
|
||||
|
||||
%inline %{
|
||||
#include <memory>
|
||||
#include <string>
|
||||
struct MyType {
|
||||
std::string val;
|
||||
MyType(std::string val = std::string()) : val(val) {}
|
||||
};
|
||||
|
||||
// ref
|
||||
std::string UseA(MyType &mytype) { return mytype.val + " ref"; }
|
||||
std::string UseA(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
|
||||
std::string UseB(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||
std::string UseB(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
|
||||
std::string UseC(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
|
||||
std::string UseC(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||
|
||||
// sharedptr
|
||||
std::string UseX(std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
std::string UseX(MyType &mytype) { return mytype.val + " ref"; }
|
||||
|
||||
std::string UseY(int, std::shared_ptr<MyType> mytype) { return mytype->val + " sharedptr"; }
|
||||
std::string UseY(int, MyType &mytype) { return mytype.val + " ref"; }
|
||||
|
||||
std::string UseZ(int, std::shared_ptr<MyType> mytype, std::shared_ptr<MyType>) { return mytype->val + " sharedptr"; }
|
||||
std::string UseZ(int, MyType &mytype, std::shared_ptr<MyType>) { return mytype.val + " ref"; }
|
||||
|
||||
// Combo1-4
|
||||
std::string Combo1(MyType mytype) { return mytype.val + "Combo1"; }
|
||||
std::string Combo1(MyType *mytype) { return ""; }
|
||||
std::string Combo1(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo1(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
|
||||
std::string Combo2(MyType *mytype) { return mytype->val + "Combo2"; }
|
||||
std::string Combo2(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo2(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
std::string Combo2(MyType mytype) { return ""; }
|
||||
|
||||
std::string Combo3(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo3"; }
|
||||
std::string Combo3(std::shared_ptr<MyType>* mytype) { return ""; }
|
||||
std::string Combo3(MyType mytype) { return ""; }
|
||||
std::string Combo3(MyType *mytype) { return ""; }
|
||||
|
||||
std::string Combo4(std::shared_ptr<MyType>* mytype) { return (*mytype)->val + "Combo4"; }
|
||||
std::string Combo4(MyType mytype) { return ""; }
|
||||
std::string Combo4(MyType *mytype) { return ""; }
|
||||
std::string Combo4(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
|
||||
// Combo5-7
|
||||
std::string Combo5(MyType &mytype) { return mytype.val + "Combo5"; }
|
||||
std::string Combo5(MyType *mytype) { return ""; }
|
||||
std::string Combo5(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
|
||||
std::string Combo6(MyType *mytype) { return mytype->val + "Combo6"; }
|
||||
std::string Combo6(std::shared_ptr<MyType> mytype) { return ""; }
|
||||
std::string Combo6(MyType &mytype) { return ""; }
|
||||
|
||||
std::string Combo7(std::shared_ptr<MyType> mytype) { return mytype->val + "Combo7"; }
|
||||
std::string Combo7(MyType &mytype) { return ""; }
|
||||
std::string Combo7(MyType *mytype) { return ""; }
|
||||
%}
|
||||
188
Examples/test-suite/cpp11_shared_ptr_upcast.i
Normal file
188
Examples/test-suite/cpp11_shared_ptr_upcast.i
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
%module cpp11_shared_ptr_upcast
|
||||
|
||||
%{
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
%}
|
||||
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%{
|
||||
|
||||
class Base {
|
||||
int m;
|
||||
public:
|
||||
Base() : m(-1) {}
|
||||
Base(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
int n;
|
||||
public:
|
||||
Derived() : n(-2) {}
|
||||
Derived(int i) : n(i) {}
|
||||
int get_n() { return n; }
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
typedef std::shared_ptr<Derived> DerivedPtr;
|
||||
|
||||
// non-overloaded
|
||||
int derived_num1(DerivedPtr v) {
|
||||
return v == nullptr ? 999 : (*v).get_n();
|
||||
}
|
||||
|
||||
int derived_num2(std::vector<DerivedPtr> v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_n();
|
||||
}
|
||||
|
||||
int derived_num3(std::map<int, DerivedPtr> v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_n();
|
||||
}
|
||||
|
||||
int base_num1(BasePtr v) {
|
||||
return v == nullptr ? 999 : (*v).get_m();
|
||||
}
|
||||
|
||||
int base_num2(std::vector<BasePtr > v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_m();
|
||||
}
|
||||
|
||||
int base_num3(std::map<int, BasePtr > v) {
|
||||
return v[0] == nullptr ? 999 : (*v[0]).get_m();
|
||||
}
|
||||
|
||||
// overloaded
|
||||
int derived_num(DerivedPtr v) {
|
||||
return derived_num1(v);
|
||||
}
|
||||
|
||||
int derived_num(std::vector<DerivedPtr> v) {
|
||||
return derived_num2(v);
|
||||
}
|
||||
|
||||
int derived_num(std::map<int, DerivedPtr> v) {
|
||||
return derived_num3(v);
|
||||
}
|
||||
|
||||
int base_num(BasePtr v) {
|
||||
return base_num1(v);
|
||||
}
|
||||
|
||||
int base_num(std::vector<BasePtr > v) {
|
||||
return base_num2(v);
|
||||
}
|
||||
|
||||
int base_num(std::map<int, BasePtr > v) {
|
||||
return base_num3(v);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
%shared_ptr(Base);
|
||||
%shared_ptr(Derived);
|
||||
|
||||
%template(BaseList) std::vector<std::shared_ptr<Base> >;
|
||||
%template(DerivedList) std::vector<std::shared_ptr<Derived> >;
|
||||
|
||||
%template(BaseMap) std::map<int, std::shared_ptr<Base> >;
|
||||
%template(DerivedMap) std::map<int, std::shared_ptr<Derived> >;
|
||||
|
||||
class Base {
|
||||
int m;
|
||||
public:
|
||||
Base();
|
||||
int get_m();
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
int n;
|
||||
public:
|
||||
Derived();
|
||||
Derived(int i);
|
||||
int get_n();
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Base> BasePtr;
|
||||
typedef std::shared_ptr<Derived> DerivedPtr;
|
||||
|
||||
// non-overloaded
|
||||
int derived_num1(DerivedPtr);
|
||||
int derived_num2(std::vector<std::shared_ptr<Derived> > v);
|
||||
int derived_num3(std::map<int, DerivedPtr> v);
|
||||
int base_num1(BasePtr);
|
||||
int base_num2(std::vector<std::shared_ptr<Base> > v);
|
||||
int base_num3(std::map<int, BasePtr > v);
|
||||
|
||||
// overloaded
|
||||
int derived_num(DerivedPtr);
|
||||
int derived_num(std::vector<std::shared_ptr<Derived> > v);
|
||||
int derived_num(std::map<int, DerivedPtr> v);
|
||||
int base_num(BasePtr);
|
||||
int base_num(std::vector<std::shared_ptr<Base> > v);
|
||||
int base_num(std::map<int, BasePtr > v);
|
||||
|
||||
// ptr to shared_ptr
|
||||
%shared_ptr(Base2);
|
||||
%shared_ptr(Derived2)
|
||||
|
||||
%inline %{
|
||||
class Base2 {
|
||||
int m;
|
||||
public:
|
||||
Base2() : m(-1) {}
|
||||
Base2(int i) : m(i) {}
|
||||
int get_m() { return m; }
|
||||
};
|
||||
|
||||
|
||||
class Derived2 : public Base2 {
|
||||
int n;
|
||||
public:
|
||||
Derived2() : n(0) {}
|
||||
Derived2(int i) : n(i) {}
|
||||
int get_n_2() { return n; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template(Base2List) std::vector<std::shared_ptr<Base2> * >;
|
||||
%template(Base2Map) std::map<int, std::shared_ptr<Base2> * >;
|
||||
|
||||
%template(Derived2List) std::vector<std::shared_ptr<Derived2> * >;
|
||||
%template(Derived2Map) std::map<int, std::shared_ptr<Derived2> * >;
|
||||
|
||||
%inline %{
|
||||
typedef std::shared_ptr<Derived2> * Derived2Ptr;
|
||||
typedef std::shared_ptr<Base2> * Base2Ptr;
|
||||
|
||||
int base2_num1(Base2Ptr v) {
|
||||
return v == nullptr ? 999 : *v == nullptr ? 888 : (*v)->get_m();
|
||||
}
|
||||
|
||||
int base2_num2(std::vector<Base2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_m();
|
||||
}
|
||||
|
||||
int base2_num3(std::map<int, Base2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_m();
|
||||
}
|
||||
|
||||
int derived2_num1(Derived2Ptr v) {
|
||||
return v == nullptr ? 999 : *v == nullptr ? 888 : (*v)->get_n_2();
|
||||
}
|
||||
|
||||
int derived2_num2(std::vector<Derived2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_n_2();
|
||||
}
|
||||
|
||||
int derived2_num3(std::map<int, Derived2Ptr> v) {
|
||||
return v[0] == nullptr ? 999 : *v[0] == nullptr ? 888 : (*v[0])->get_n_2();
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,12 +1,32 @@
|
|||
/* This test case checks whether SWIG correctly parses and ignores the
|
||||
keywords "static_assert()" inside the class or struct.
|
||||
/* This test case checks whether SWIG correctly parses and ignores
|
||||
"static_assert()" in various places.
|
||||
*/
|
||||
%module cpp11_static_assert
|
||||
|
||||
%inline %{
|
||||
static_assert(sizeof(int) >= 2, "What? int size is invalid!");
|
||||
|
||||
namespace dummy {
|
||||
// C++17 allows the message to be omitted, so check that works too.
|
||||
// But only show the C++17 version to SWIG, as the compiler may
|
||||
// lack C++17 support.
|
||||
#ifdef SWIG
|
||||
static_assert(sizeof(int) >= sizeof(short));
|
||||
#else
|
||||
static_assert(sizeof(int) >= sizeof(short), "blah");
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Check1 {
|
||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
||||
Check1() {
|
||||
#ifdef SWIG
|
||||
static_assert(true);
|
||||
#else
|
||||
static_assert(true, "true");
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%module cpp11_li_std_array
|
||||
%module cpp11_std_array
|
||||
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA)
|
||||
#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
|
||||
%{
|
||||
#include <array>
|
||||
11
Examples/test-suite/cpp11_std_unordered_map.i
Normal file
11
Examples/test-suite/cpp11_std_unordered_map.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%module cpp11_std_unordered_map
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_unordered_map.i>
|
||||
|
||||
%template(UnorderedMapIntInt) std::unordered_map<int, int>;
|
||||
%template(UnorderedMapStringInt) std::unordered_map<std::string, int>;
|
||||
|
||||
%inline %{
|
||||
std::unordered_map<std::string, int, std::hash< std::string >,std::equal_to< std::string >,std::allocator< std::pair< std::string const,int > > > inout(std::unordered_map<std::string, int> m) { return m; }
|
||||
%}
|
||||
7
Examples/test-suite/cpp11_std_unordered_multimap.i
Normal file
7
Examples/test-suite/cpp11_std_unordered_multimap.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module cpp11_std_unordered_multimap
|
||||
|
||||
%include <std_pair.i>
|
||||
%include <std_unordered_multimap.i>
|
||||
|
||||
%template(PairIntInt) std::pair<int,int>;
|
||||
%template(UnorderedMultiMapIntInt) std::unordered_multimap<int, int>;
|
||||
5
Examples/test-suite/cpp11_std_unordered_multiset.i
Normal file
5
Examples/test-suite/cpp11_std_unordered_multiset.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%module cpp11_std_unordered_multiset
|
||||
|
||||
%include <std_unordered_multiset.i>
|
||||
|
||||
%template(UnorderedMultiSetInt) std::unordered_multiset<int>;
|
||||
7
Examples/test-suite/cpp11_std_unordered_set.i
Normal file
7
Examples/test-suite/cpp11_std_unordered_set.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module cpp11_std_unordered_set
|
||||
|
||||
%include <std_string.i>
|
||||
%include <std_unordered_set.i>
|
||||
|
||||
%template(UnorderedSetInt) std::unordered_set<int>;
|
||||
%template(UnorderedSetString) std::unordered_set<std::string>;
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
%inline %{
|
||||
|
||||
template<typename T> struct Temper {
|
||||
template<typename T> class Temper {
|
||||
public:
|
||||
T val;
|
||||
};
|
||||
|
||||
|
|
@ -18,14 +19,20 @@ public:
|
|||
int memberFunction() { return 100; }
|
||||
};
|
||||
|
||||
class B {
|
||||
public:
|
||||
short member;
|
||||
short memberFunction() { return 100; }
|
||||
};
|
||||
|
||||
template class Temper<A>;
|
||||
extern template class Temper<A>;
|
||||
extern template class Temper<B>;
|
||||
|
||||
template class Temper<A*>;
|
||||
extern template class Temper<A*>;
|
||||
extern template class Temper<B*>;
|
||||
|
||||
template class Temper<int>;
|
||||
extern template class Temper<int>;
|
||||
extern template class Temper<short>;
|
||||
%}
|
||||
|
||||
%template(TemperInt) Temper<int>;
|
||||
|
|
|
|||
|
|
@ -1,56 +1,86 @@
|
|||
/* This testcase checks whether SWIG correctly parses alias templates. */
|
||||
/* This testcase checks whether SWIG correctly handles alias templates. */
|
||||
%module cpp11_template_typedefs
|
||||
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefName;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) TypedefNamePtr;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_TEMPLATE) MyIntKeyClass;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) PF;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator1;
|
||||
%warnfilter(SWIGWARN_CPP11_ALIAS_DECLARATION) BucketAllocator2;
|
||||
|
||||
// This warning should go away when type aliasing is supported
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_USING_UNDEF // Nothing known about 'p.SomeType< char *,T2,4 >'.
|
||||
|
||||
%inline %{
|
||||
template< typename T1, typename T2, int >
|
||||
|
||||
template<typename T>
|
||||
using ptr_t = T*;
|
||||
|
||||
namespace ns {
|
||||
|
||||
template<typename T1, typename T2, int N>
|
||||
class SomeType {
|
||||
public:
|
||||
using type1_t = T1;
|
||||
using type2_t = T2;
|
||||
T1 a;
|
||||
T2 b;
|
||||
int c;
|
||||
constexpr int get_n() const { return N; }
|
||||
};
|
||||
|
||||
// template aliasing
|
||||
template< typename T2 >
|
||||
using TypedefName = SomeType<char*, T2, 5>;
|
||||
template< typename T2 >
|
||||
using TypedefNamePtr = SomeType<char*, T2, 4>*;
|
||||
|
||||
// type aliasing
|
||||
typedef void (*PFD)(double); // Old style
|
||||
using PF = void (*)(double); // New introduced syntax
|
||||
|
||||
|
||||
// use of template aliasing
|
||||
template<typename Key,typename Val>
|
||||
class MyCPP11Class {
|
||||
// Specialization for T1=const char*, T2=bool
|
||||
template<int N>
|
||||
class SomeType<const char*, bool, N> {
|
||||
public:
|
||||
using type1_t = const char*;
|
||||
using type2_t = bool;
|
||||
type1_t a;
|
||||
type2_t b;
|
||||
constexpr int get_n() const { return 3 * N; }
|
||||
};
|
||||
template<typename VAL> using MyIntKeyClass = MyCPP11Class<int,VAL>;
|
||||
MyIntKeyClass<char> intchar;
|
||||
|
||||
TypedefName<int> alias1(TypedefName<int> a) { return a; }
|
||||
TypedefNamePtr<int> alias1(TypedefNamePtr<int> a = nullptr) { return a; }
|
||||
%}
|
||||
// alias templates
|
||||
template<typename T2>
|
||||
using TypedefName = SomeType<const char*, T2, 5>;
|
||||
template<typename T2>
|
||||
using TypedefNamePtr = ptr_t<SomeType<const char*, T2, 4>>;
|
||||
|
||||
// alias template that returns T2 for a SomeType<T1,T2,N> class
|
||||
template<typename T>
|
||||
using T2_of = typename T::type2_t;
|
||||
|
||||
T2_of<TypedefName<int>> get_SomeType_b(const SomeType<const char*, int, 5>& x) { return x.b; }
|
||||
|
||||
template<typename T>
|
||||
T2_of<TypedefName<T>> get_SomeType_b2(const TypedefName<T>& x) { return x.b; }
|
||||
|
||||
} // namespace ns
|
||||
|
||||
ns::TypedefName<int> create_TypedefName() { return { "hello", 10}; }
|
||||
ns::TypedefName<bool> create_TypedefNameBool() { return { "hello", true}; }
|
||||
ns::TypedefNamePtr<int> identity(ns::TypedefNamePtr<int> a = nullptr) { return a; }
|
||||
|
||||
%inline %{
|
||||
typedef double Val;
|
||||
template<typename T> struct ListBucket {
|
||||
};
|
||||
namespace Alloc {
|
||||
template<typename T> struct rebind {
|
||||
typedef int other;
|
||||
using other = int;
|
||||
};
|
||||
}
|
||||
|
||||
using BucketAllocator1 = typename Alloc::template rebind<ListBucket<Val>>::other;
|
||||
using BucketAllocator2 = typename Alloc::template rebind<::template ListBucket<double>>::other;
|
||||
|
||||
BucketAllocator1 get_bucket_allocator1() { return 1; }
|
||||
BucketAllocator2 get_bucket_allocator2() { return 2; }
|
||||
%}
|
||||
|
||||
%immutable ns::SomeType::a;
|
||||
|
||||
// %template() directives
|
||||
|
||||
%template(SomeTypeInt5) ns::SomeType<const char*, int, 5>;
|
||||
%template(SomeTypeInt4) ns::SomeType<const char*, int, 4>;
|
||||
%template(SomeTypeBool5) ns::SomeType<const char*, bool, 5>;
|
||||
|
||||
%template(ListBucketDouble) ListBucket<Val>;
|
||||
%template(RebindListBucketDouble) Alloc::rebind<ListBucket<Val>>;
|
||||
|
||||
%template() ptr_t<ns::SomeType<const char*, int, 4>>;
|
||||
%template() ns::TypedefName<int>;
|
||||
%template() ns::TypedefName<bool>;
|
||||
%template() ns::TypedefNamePtr<int>;
|
||||
%template() ns::T2_of<ns::TypedefName<int>>;
|
||||
|
||||
%template(get_SomeType_b2) ns::get_SomeType_b2<int>;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ extern "C++" thread_local int ecpptval;
|
|||
|
||||
thread_local int ThreadLocals::stval = 11;
|
||||
thread_local int ThreadLocals::tsval = 22;
|
||||
#if !defined(_MSC_VER)
|
||||
thread_local const int ThreadLocals::stcval88;
|
||||
thread_local const int ThreadLocals::tscval99;
|
||||
#endif
|
||||
%}
|
||||
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -108,5 +108,5 @@ PairSubclass::data_t plus1(PairSubclass::const_ref_data_t x) { return x + 1; }
|
|||
using callback_t = int(*)(int);
|
||||
|
||||
callback_t get_callback() { return mult2; }
|
||||
int call(callback_t func, int param) { return func(param); }
|
||||
int call(callback_t funk, int param) { return funk(param); }
|
||||
%}
|
||||
|
|
|
|||
31
Examples/test-suite/cpp14_binary_integer_literals.i
Normal file
31
Examples/test-suite/cpp14_binary_integer_literals.i
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
%module cpp14_binary_integer_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201402L
|
||||
#define CPP14 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
int b1 = 0b1;
|
||||
int b2 = 0b10;
|
||||
long b3 = 0b11l;
|
||||
unsigned long b4 = 0b100ul;
|
||||
unsigned long b5 = 0B101UL;
|
||||
|
||||
%{
|
||||
#if defined(CPP14)
|
||||
int b1 = 0b1;
|
||||
int b2 = 0b10;
|
||||
long b3 = 0b11l;
|
||||
unsigned long b4 = 0b100ul;
|
||||
unsigned long b5 = 0B101UL;
|
||||
#else
|
||||
int b1 = 1;
|
||||
int b2 = 2;
|
||||
long b3 = 3;
|
||||
unsigned long b4 = 4;
|
||||
unsigned long b5 = 5;
|
||||
#endif
|
||||
%}
|
||||
43
Examples/test-suite/cpp17_hex_floating_literals.i
Normal file
43
Examples/test-suite/cpp17_hex_floating_literals.i
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
%module cpp17_hex_floating_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
double f1 = 0x.0p1;
|
||||
double f2 = 0x0.p1;
|
||||
double f3 = 0x0.0p-1;
|
||||
double f4 = 0xf.p-1;
|
||||
double f5 = 0xA.0p1;
|
||||
double f6 = 0x0.10P+10;
|
||||
double f7 = 0xb2F.p2;
|
||||
float f8 = 0x1234AP1F;
|
||||
float f9 = 0x45A1.D1A2p+10f;
|
||||
|
||||
%{
|
||||
#if defined(CPP17)
|
||||
double f1 = 0x.0p1;
|
||||
double f2 = 0x0.p1;
|
||||
double f3 = 0x0.0p-1;
|
||||
double f4 = 0xf.p-1;
|
||||
double f5 = 0xA.0p1;
|
||||
double f6 = 0x0.10P+10;
|
||||
double f7 = 0xb2F.p2;
|
||||
float f8 = 0x1234AP1F;
|
||||
float f9 = 0x45A1.D1A2p+10f;
|
||||
#else
|
||||
double f1 = 0.;
|
||||
double f2 = 0.;
|
||||
double f3 = 0.;
|
||||
double f4 = 7.5;
|
||||
double f5 = 20.;
|
||||
double f6 = 64.;
|
||||
double f7 = 11452.;
|
||||
float f8 = 149140.f;
|
||||
float f9 = 18253638.f;
|
||||
#endif
|
||||
%}
|
||||
199
Examples/test-suite/cpp17_nested_namespaces.i
Normal file
199
Examples/test-suite/cpp17_nested_namespaces.i
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
%module cpp17_nested_namespaces
|
||||
// Tests c++17 style nested namespaces
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
#define CPP17 1
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++98 style (non-nested) namespaces
|
||||
namespace A1 {
|
||||
struct A1Struct {
|
||||
void A1Method() {}
|
||||
};
|
||||
namespace B1 {
|
||||
struct B1Struct {
|
||||
void B1Method() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
#if defined(CPP17)
|
||||
namespace A1::B1 {
|
||||
#else
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
#endif
|
||||
A1Struct createA1Struct() { return ::A1::A1Struct(); }
|
||||
B1Struct createB1Struct() { return ::A1::B1::B1Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
namespace C1 {
|
||||
struct C1Struct {
|
||||
void C1Method() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A1::B1::C1 {
|
||||
#else
|
||||
namespace A1 {
|
||||
namespace B1 {
|
||||
namespace C1 {
|
||||
#endif
|
||||
C1Struct createC1Struct() { return ::A1::B1::C1::C1Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++17 style (nested) namespaces
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
#endif
|
||||
struct B2Struct {
|
||||
void B2Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
#endif
|
||||
B2Struct createB2Struct() { return ::A2::B2::B2Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2::C2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
namespace C2 {
|
||||
#endif
|
||||
struct C2Struct {
|
||||
void C2Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A2::B2::C2 {
|
||||
#else
|
||||
namespace A2 {
|
||||
namespace B2 {
|
||||
namespace C2 {
|
||||
#endif
|
||||
C2Struct createC2Struct() { return ::A2::B2::C2::C2Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
// Tests with namespaces already defined using C++17 style (nested) namespaces to 3 levels
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3::C3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
namespace C3 {
|
||||
#endif
|
||||
struct C3Struct {
|
||||
void C3Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3::C3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
namespace C3 {
|
||||
#endif
|
||||
C3Struct createC3Struct() { return ::A3::B3::C3::C3Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
#endif
|
||||
struct B3Struct {
|
||||
void B3Method() {}
|
||||
};
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CPP17)
|
||||
namespace A3::B3 {
|
||||
#else
|
||||
namespace A3 {
|
||||
namespace B3 {
|
||||
#endif
|
||||
B3Struct createB3Struct() { return ::A3::B3::B3Struct(); }
|
||||
#if !defined(CPP17)
|
||||
}
|
||||
}
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
13
Examples/test-suite/cpp17_nspace_nested_namespaces.i
Normal file
13
Examples/test-suite/cpp17_nspace_nested_namespaces.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%module cpp17_nspace_nested_namespaces
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||
#endif
|
||||
|
||||
// nspace feature only supported by these languages
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
|
||||
%nspace;
|
||||
#endif
|
||||
|
||||
|
||||
%include "cpp17_nested_namespaces.i"
|
||||
26
Examples/test-suite/cpp17_u8_char_literals.i
Normal file
26
Examples/test-suite/cpp17_u8_char_literals.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%module cpp17_u8_char_literals
|
||||
|
||||
// Tests are designed so that code compiles with C++98 compilers
|
||||
|
||||
%{
|
||||
#if __cplusplus >= 201703L
|
||||
#define CPP17 1
|
||||
#endif
|
||||
%}
|
||||
|
||||
// UTF-8 character literals will (apparently) have type char8_t in C++20.
|
||||
char a = u8'a';
|
||||
char u = u8'u';
|
||||
char u8 = u8'8';
|
||||
|
||||
%{
|
||||
#if defined(CPP17)
|
||||
char a = u8'a';
|
||||
char u = u8'u';
|
||||
char u8 = u8'8';
|
||||
#else
|
||||
char a = 'a';
|
||||
char u = 'u';
|
||||
char u8 = '8';
|
||||
#endif
|
||||
%}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
%module cpp_broken
|
||||
|
||||
|
||||
// bug #940318
|
||||
%inline %{
|
||||
typedef enum {
|
||||
eZero = 0
|
||||
#define ONE 1
|
||||
} EFoo;
|
||||
%}
|
||||
|
||||
|
||||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
%module cpp_namespace
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
typedef int Bad;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ Tests Sourceforge bug #444748.
|
|||
class StaticMemberTest {
|
||||
public:
|
||||
static int static_int;
|
||||
static int grab_int() { return static_int; }
|
||||
};
|
||||
|
||||
class StaticFunctionTest {
|
||||
|
|
@ -22,5 +23,30 @@ public:
|
|||
%}
|
||||
|
||||
%{
|
||||
int StaticMemberTest::static_int;
|
||||
int StaticMemberTest::static_int = 99;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct StaticBase {
|
||||
static int statty;
|
||||
static int grab_statty_base() { return statty; }
|
||||
virtual ~StaticBase() {}
|
||||
};
|
||||
struct StaticDerived : StaticBase {
|
||||
static int statty;
|
||||
static int grab_statty_derived() { return statty; }
|
||||
};
|
||||
%}
|
||||
|
||||
%{
|
||||
int StaticBase::statty = 11;
|
||||
int StaticDerived::statty = 111;
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
bool is_python_builtin() { return true; }
|
||||
#else
|
||||
bool is_python_builtin() { return false; }
|
||||
#endif
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ top_srcdir = ../@top_srcdir@
|
|||
top_builddir = ../@top_builddir@
|
||||
|
||||
CPP_TEST_CASES = \
|
||||
complextest \
|
||||
csharp_attributes \
|
||||
csharp_swig2_compatibility \
|
||||
csharp_exceptions \
|
||||
csharp_features \
|
||||
csharp_lib_arrays \
|
||||
csharp_lib_arrays_bool \
|
||||
csharp_namespace_system_collision \
|
||||
csharp_prepost \
|
||||
csharp_typemaps \
|
||||
|
|
@ -25,9 +27,14 @@ CPP_TEST_CASES = \
|
|||
enum_thorough_typesafe \
|
||||
exception_partial_info \
|
||||
intermediary_classname \
|
||||
li_boost_intrusive_ptr
|
||||
li_boost_intrusive_ptr \
|
||||
li_std_list \
|
||||
|
||||
CPP11_TEST_CASES = \
|
||||
cpp11_shared_ptr_const \
|
||||
cpp11_shared_ptr_nullptr_in_containers \
|
||||
cpp11_shared_ptr_overload \
|
||||
cpp11_shared_ptr_upcast \
|
||||
cpp11_strongly_typed_enumerations_simple \
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
|
@ -40,7 +47,9 @@ CSHARPFLAGSSPECIAL =
|
|||
|
||||
# Custom tests - tests with additional commandline options
|
||||
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
|
||||
complextest.cpptest: CSHARPFLAGSSPECIAL = -r:System.Numerics.dll
|
||||
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_lib_arrays_bool.cpptest: CSHARPFLAGSSPECIAL = -unsafe
|
||||
csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
|
||||
|
||||
# Rules for the different types of tests
|
||||
|
|
|
|||
|
|
@ -13,6 +13,20 @@ public class runme
|
|||
{
|
||||
MyProtectedBase mpb = new MyProtectedBase("MyProtectedBase");
|
||||
mpb.accessProtected();
|
||||
try {
|
||||
// C++ destructor is protected
|
||||
mpb.Dispose();
|
||||
throw new Exception("failed to catch MethodAccessException");
|
||||
} catch (MethodAccessException) {
|
||||
// Exception message: C++ destructor does not have public access
|
||||
}
|
||||
ProtectedDerived pd = new ProtectedDerived("ProtectedDerived");
|
||||
// Destroying via the ProtectedDerived's destructor should work
|
||||
pd.Dispose();
|
||||
|
||||
ProtectedBase pb = new ProtectedDerived("ProtectedDerived");
|
||||
// ProtectedDerived's destructor should be called via the Dispose(disposing) virtual call
|
||||
pb.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
43
Examples/test-suite/csharp/complextest_runme.cs
Normal file
43
Examples/test-suite/csharp/complextest_runme.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// This is the complex runtime testcase. It checks that the C++ std::complex type works.
|
||||
// It requires .NET 4.0 as the previous versions didn't have System.Numerics.Complex type.
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
using complextestNamespace;
|
||||
|
||||
public class complextest_runme {
|
||||
|
||||
public static void Main() {
|
||||
var a = new Complex(-1, 2);
|
||||
if ( complextest.Conj(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<double> test failed");
|
||||
|
||||
if ( complextest.Conjf(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<float> test failed");
|
||||
|
||||
if ( complextest.Conj2(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<double> test failed");
|
||||
|
||||
if ( complextest.Conjf2(a) != Complex.Conjugate(a) )
|
||||
throw new Exception("std::complex<float> test failed");
|
||||
|
||||
var vec = new VectorStdCplx();
|
||||
vec.Add(new Complex(1, 2));
|
||||
vec.Add(new Complex(2, 3));
|
||||
vec.Add(new Complex(4, 3));
|
||||
vec.Add(new Complex(1, 0));
|
||||
|
||||
if ( complextest.CopyHalf(vec).Count != 2 )
|
||||
throw new Exception("CopyHalf test failed");
|
||||
|
||||
if ( complextest.CopyHalfRef(vec).Count != 2 )
|
||||
throw new Exception("CopyHalfRef test failed");
|
||||
|
||||
var p = new ComplexPair();
|
||||
p.z1 = new Complex(0, 1);
|
||||
p.z2 = new Complex(0, -1);
|
||||
if ( Complex.Conjugate(p.z2) != p.z1 )
|
||||
throw new Exception("vector<complex> test failed");
|
||||
}
|
||||
}
|
||||
82
Examples/test-suite/csharp/cpp11_std_array_runme.cs
Normal file
82
Examples/test-suite/csharp/cpp11_std_array_runme.cs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// This test tests all the methods in the C# collection wrapper
|
||||
using System;
|
||||
using cpp11_std_arrayNamespace;
|
||||
|
||||
public class cpp11_std_array_runme
|
||||
{
|
||||
private static ArrayInt6 ToArray6(int[] a)
|
||||
{
|
||||
if (a.Length != 6)
|
||||
throw new Exception("a is incorrect size");
|
||||
return new ArrayInt6(a);
|
||||
}
|
||||
|
||||
private static void compareContainers(ArrayInt6 actual, int[] expected)
|
||||
{
|
||||
if (actual.Count != expected.Length)
|
||||
throw new Exception("Sizes are different: " + actual.Count + " " + expected.Length);
|
||||
for (int i=0; i<actual.Count; ++i)
|
||||
{
|
||||
int actualValue = actual[i];
|
||||
int expectedValue = expected[i];
|
||||
if (actualValue != expectedValue)
|
||||
throw new Exception("Value is wrong for element " + i + ". Expected " + expectedValue + " got: " + actualValue);
|
||||
}
|
||||
if (actual.IsEmpty)
|
||||
throw new Exception("ai should not be empty");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
ArrayInt6 ai = new ArrayInt6();
|
||||
compareContainers(ai, new int[] { 0, 0, 0, 0, 0, 0 });
|
||||
|
||||
int[] vals = { 10, 20, 30, 40, 50, 60 };
|
||||
for (int i = 0; i < ai.Count; ++i)
|
||||
ai[i] = vals[i];
|
||||
compareContainers(ai, vals);
|
||||
|
||||
// Check return
|
||||
compareContainers(cpp11_std_array.arrayOutVal(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutConstRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutRef(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
compareContainers(cpp11_std_array.arrayOutPtr(), new int[] { -2, -1, 0, 0, 1, 2 });
|
||||
|
||||
// Check passing arguments
|
||||
ai = cpp11_std_array.arrayInVal(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = cpp11_std_array.arrayInConstRef(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_std_array.arrayInRef(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
ai = new ArrayInt6(ToArray6(new int[] { 9, 8, 7, 6, 5, 4 }));
|
||||
cpp11_std_array.arrayInPtr(ai);
|
||||
compareContainers(ai, new int[] { 90, 80, 70, 60, 50, 40 });
|
||||
|
||||
// fill
|
||||
ai.Fill(111);
|
||||
compareContainers(ai, new int[] { 111, 111, 111, 111, 111, 111 });
|
||||
|
||||
// out of range errors
|
||||
try
|
||||
{
|
||||
ai[ai.Count] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
ai[-1] = 0;
|
||||
throw new Exception("Out of range exception not caught");
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Examples/test-suite/csharp/cpp17_nested_namespaces_runme.cs
Normal file
25
Examples/test-suite/csharp/cpp17_nested_namespaces_runme.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using cpp17_nested_namespacesNamespace;
|
||||
|
||||
public class cpp17_nested_namespaces_runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
new A1Struct().A1Method();
|
||||
new B1Struct().B1Method();
|
||||
new C1Struct().C1Method();
|
||||
cpp17_nested_namespaces.createA1Struct().A1Method();
|
||||
cpp17_nested_namespaces.createB1Struct().B1Method();
|
||||
cpp17_nested_namespaces.createC1Struct().C1Method();
|
||||
|
||||
new B2Struct().B2Method();
|
||||
new C2Struct().C2Method();
|
||||
cpp17_nested_namespaces.createB2Struct().B2Method();
|
||||
cpp17_nested_namespaces.createC2Struct().C2Method();
|
||||
|
||||
new B3Struct().B3Method();
|
||||
new C3Struct().C3Method();
|
||||
cpp17_nested_namespaces.createB3Struct().B3Method();
|
||||
cpp17_nested_namespaces.createC3Struct().C3Method();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using cpp17_nspace_nested_namespacesNamespace;
|
||||
|
||||
public class cpp17_nspace_nested_namespaces_runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.A1Struct().A1Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.B1.B1Struct().B1Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A1.B1.C1.C1Struct().C1Method();
|
||||
cpp17_nspace_nested_namespaces.createA1Struct().A1Method();
|
||||
cpp17_nspace_nested_namespaces.createB1Struct().B1Method();
|
||||
cpp17_nspace_nested_namespaces.createC1Struct().C1Method();
|
||||
|
||||
new cpp17_nspace_nested_namespacesNamespace.A2.B2.B2Struct().B2Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A2.B2.C2.C2Struct().C2Method();
|
||||
cpp17_nspace_nested_namespaces.createB2Struct().B2Method();
|
||||
cpp17_nspace_nested_namespaces.createC2Struct().C2Method();
|
||||
|
||||
new cpp17_nspace_nested_namespacesNamespace.A3.B3.B3Struct().B3Method();
|
||||
new cpp17_nspace_nested_namespacesNamespace.A3.B3.C3.C3Struct().C3Method();
|
||||
cpp17_nspace_nested_namespaces.createB3Struct().B3Method();
|
||||
cpp17_nspace_nested_namespaces.createC3Struct().C3Method();
|
||||
}
|
||||
}
|
||||
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
90
Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using csharp_lib_arrays_boolNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyUsingFixedArraysBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT Fixed");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapUsingFixedArraysBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
|
||||
if( runtimeIsMono() )
|
||||
{
|
||||
// Console.Error.WriteLine("Tests are running on mono, failing bool[] tests skipped");
|
||||
// See Mono bug report https://github.com/mono/mono/issues/15592
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = new bool[ source.Length ];
|
||||
|
||||
if( !csharp_lib_arrays_bool.checkBoolArrayCorrect( source, source.Length ) )
|
||||
{
|
||||
throw new Exception("bool[] INPUT incorrect");
|
||||
}
|
||||
|
||||
csharp_lib_arrays_bool.myArrayCopyBool( source, target, target.Length );
|
||||
CompareArrays(source, target, "bool[] INPUT/OUTPUT");
|
||||
}
|
||||
|
||||
{
|
||||
bool[] source = { true, false, false, true, false, true, true, false };
|
||||
bool[] target = { false, true, true, false, true, false, false, true };
|
||||
|
||||
csharp_lib_arrays_bool.myArraySwapBool( source, target, target.Length );
|
||||
|
||||
for (int i=0; i<target.Length; ++i)
|
||||
target[i] = !target[i];
|
||||
|
||||
CompareArrays(source, target, "bool[] INOUT");
|
||||
}
|
||||
}
|
||||
|
||||
static void CompareArrays<T>( T[] a, T[] b, string testName )
|
||||
{
|
||||
if (a.Length != b.Length)
|
||||
throw new Exception("size mismatch");
|
||||
|
||||
for(int i=0; i<a.Length; ++i) {
|
||||
if (a[i].Equals(b[i]) == false) {
|
||||
Console.Error.WriteLine("C# Array mismatch: " + testName);
|
||||
Console.Error.WriteLine("a:");
|
||||
PrintArray(a);
|
||||
Console.Error.WriteLine("b:");
|
||||
PrintArray(b);
|
||||
throw new Exception("element mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintArray<T>( T[] a )
|
||||
{
|
||||
foreach ( T i in a )
|
||||
Console.Error.Write( "{0} ", i );
|
||||
Console.Error.WriteLine();
|
||||
}
|
||||
|
||||
static bool runtimeIsMono()
|
||||
{
|
||||
return Type.GetType ("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +48,36 @@ public class runme
|
|||
if (myNewBar == null)
|
||||
throw new Exception("non-null pointer marshalling problem");
|
||||
myNewBar.x = 10;
|
||||
|
||||
// Low level implementation check
|
||||
// my.testSwigDerivedClassHasMethod();
|
||||
|
||||
// These should not call the C# implementations as they are not overridden
|
||||
int v;
|
||||
v = MyClass.call_nonVirtual(my);
|
||||
if (v != 100) throw new Exception("call_nonVirtual broken() " + v);
|
||||
|
||||
v = MyClass.call_nonOverride(my);
|
||||
if (v != 101) throw new Exception("call_nonOverride broken() " + v);
|
||||
|
||||
// A mix of overridden and non-overridden
|
||||
MyClassEnd myend = new MyClassEnd();
|
||||
MyClass mc = myend;
|
||||
|
||||
v = mc.nonVirtual();
|
||||
if (v != 202) throw new Exception("mc.nonVirtual() broken " + v);
|
||||
|
||||
v = MyClass.call_nonVirtual(mc);
|
||||
if (v != 202) throw new Exception("call_nonVirtual(mc) broken " + v);
|
||||
|
||||
v = MyClass.call_nonVirtual(myend);
|
||||
if (v != 202) throw new Exception("call_nonVirtual(myend) broken" + v);
|
||||
|
||||
v = MyClass.call_nonOverride(mc);
|
||||
if (v != 101) throw new Exception("call_nonOverride(mc) broken" + v);
|
||||
|
||||
v = MyClass.call_nonOverride(myend);
|
||||
if (v != 101) throw new Exception("call_nonOverride(myend) broken" + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +99,30 @@ class MyOverriddenClass : MyClass {
|
|||
throw new Exception("null not received as expected");
|
||||
return b;
|
||||
}
|
||||
|
||||
public new bool nonVirtual() {
|
||||
throw new Exception("non-virtual overrides virtual method");
|
||||
}
|
||||
|
||||
public new virtual bool nonOverride() {
|
||||
throw new Exception("non-override overrides virtual method");
|
||||
}
|
||||
}
|
||||
|
||||
class MyClassMiddle : MyClass {
|
||||
public override int nonVirtual() {
|
||||
return 202;
|
||||
}
|
||||
}
|
||||
|
||||
class MyClassEnd : MyClassMiddle {
|
||||
public new bool nonVirtual() {
|
||||
throw new Exception("non-virtual overrides virtual method");
|
||||
}
|
||||
|
||||
public new virtual bool nonOverride() {
|
||||
throw new Exception("non-override overrides virtual method");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ Expected output if PrintDebug enabled:
|
|||
Base - Val(444.555)
|
||||
Base - Ref(444.555)
|
||||
Base - Ptr(444.555)
|
||||
Base - ConstPtrRef(444.555)
|
||||
Base - FullyOverloaded(int 10)
|
||||
Base - FullyOverloaded(bool 1)
|
||||
Base - SemiOverloaded(int -678)
|
||||
|
|
@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1)
|
|||
Derived - Val(444.555)
|
||||
Derived - Ref(444.555)
|
||||
Derived - Ptr(444.555)
|
||||
Derived - ConstPtrRef(444.555)
|
||||
Derived - FullyOverloaded(int 10)
|
||||
Derived - FullyOverloaded(bool 1)
|
||||
Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1)
|
|||
CSharpDerived - Val(444.555)
|
||||
CSharpDerived - Ref(444.555)
|
||||
CSharpDerived - Ptr(444.555)
|
||||
CSharpDerived - ConstPtrRef(444.555)
|
||||
CSharpDerived - FullyOverloaded(int 10)
|
||||
CSharpDerived - FullyOverloaded(bool True)
|
||||
CSharpDerived - SemiOverloaded(-678)
|
||||
|
|
@ -59,7 +62,7 @@ public class runme
|
|||
|
||||
void run()
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------ ");
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------");
|
||||
|
||||
Caller myCaller = new Caller();
|
||||
|
||||
|
|
@ -85,7 +88,7 @@ public class runme
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------ ");
|
||||
if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase)
|
||||
|
|
@ -99,6 +102,7 @@ public class runme
|
|||
if (myCaller.ValCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.RefCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("failed");
|
||||
if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("failed");
|
||||
|
||||
// Fully overloaded method test (all methods in base class are overloaded)
|
||||
if (NAMESPACE + myCaller.FullyOverloadedCall(10) != myBase.GetType() + "::FullyOverloaded(int)") throw new Exception("failed");
|
||||
|
|
@ -142,6 +146,11 @@ public class CSharpDerived : Base
|
|||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - Ptr({0})", x.val);
|
||||
return x;
|
||||
}
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x)
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - ConstPtrRef({0})", x.val);
|
||||
return x;
|
||||
}
|
||||
public override String FullyOverloaded(int x)
|
||||
{
|
||||
if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - FullyOverloaded(int {0})", x);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,29 @@ public class runme
|
|||
}
|
||||
}
|
||||
|
||||
private class director_smartptr_MyBarFooDerived : FooDerived
|
||||
{
|
||||
public override string ping()
|
||||
{
|
||||
return "director_smartptr_MyBarFooDerived.ping()";
|
||||
}
|
||||
|
||||
public override string pong()
|
||||
{
|
||||
return "director_smartptr_MyBarFooDerived.pong();" + ping();
|
||||
}
|
||||
|
||||
public override string upcall(FooBar fooBarPtr)
|
||||
{
|
||||
return "overrideDerived;" + fooBarPtr.FooBarDo();
|
||||
}
|
||||
|
||||
public override Foo makeFoo()
|
||||
{
|
||||
return new Foo();
|
||||
}
|
||||
}
|
||||
|
||||
private static void check(string got, string expected)
|
||||
{
|
||||
if (got != expected)
|
||||
|
|
@ -49,5 +72,11 @@ public class runme
|
|||
Foo myFoo2 = new Foo().makeFoo();
|
||||
check(myFoo2.pong(), "Foo::pong();Foo::ping()");
|
||||
check(Foo.callPong(myFoo2), "Foo::pong();Foo::ping()");
|
||||
|
||||
FooDerived myBarFooDerived = new director_smartptr_MyBarFooDerived();
|
||||
check(myBarFooDerived.ping(), "director_smartptr_MyBarFooDerived.ping()");
|
||||
check(FooDerived.callPong(myBarFooDerived), "director_smartptr_MyBarFooDerived.pong();director_smartptr_MyBarFooDerived.ping()");
|
||||
check(FooDerived.callUpcall(myBarFooDerived, fooBar), "overrideDerived;Bar::Foo2::Foo2Bar()");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
83
Examples/test-suite/csharp/director_void_runme.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using director_voidNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
System.Threading.Thread.Sleep(10);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
runme r = new runme();
|
||||
r.run();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
Caller caller = new Caller();
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail1 should be 106, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 106)
|
||||
throw new Exception("Fail2 should be 106, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 106)
|
||||
throw new Exception("Fail3 should be 106, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(5);
|
||||
int x = caller.callVirtualIn(dvp, 6);
|
||||
if (x != 12)
|
||||
throw new Exception("Fail1 should be 12, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = Caller.VoidToInt(ptr);
|
||||
if (x != 25)
|
||||
throw new Exception("Fail2 should be 25, got " + x);
|
||||
x = Caller.VoidToInt(dvp.voidPtrOut());
|
||||
if (x != 1234)
|
||||
throw new Exception("Fail3 should be 1234, got " + x);
|
||||
}
|
||||
|
||||
{
|
||||
DirectorVoidPointer dvp = new DirectorVoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 10)
|
||||
throw new Exception("Bad1 should be 10, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 110)
|
||||
throw new Exception("Bad2 should be 110, got " + x);
|
||||
}
|
||||
{
|
||||
DirectorVoidPointer dvp = new director_void_VoidPointer(10);
|
||||
int x = caller.callVirtualOut(dvp);
|
||||
if (x != 1234)
|
||||
throw new Exception("Bad3 should be 1234, got " + x);
|
||||
global::System.IntPtr ptr = dvp.nonVirtualVoidPtrOut();
|
||||
x = dvp.nonVirtualVoidPtrIn(ptr);
|
||||
if (x != 1334)
|
||||
throw new Exception("Bad4 should be 1334, got " + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class director_void_VoidPointer : DirectorVoidPointer {
|
||||
public director_void_VoidPointer(int num) : base(num*num) {
|
||||
}
|
||||
public override int voidPtrIn(global::System.IntPtr p) {
|
||||
return Caller.VoidToInt(p) * 2;
|
||||
}
|
||||
public override global::System.IntPtr voidPtrOut() {
|
||||
setNewValue(1234);
|
||||
return nonVirtualVoidPtrOut();
|
||||
}
|
||||
}
|
||||
|
|
@ -405,6 +405,10 @@ public class runme {
|
|||
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");
|
||||
}
|
||||
{
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue != (('A' << 24) | ('B' << 16) | ('C' << 8) | 'D')) throw new Exception("enumWithMacroTest 1 failed");
|
||||
if (enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD2).swigValue != enum_thorough_typesafe.enumWithMacroTest(enumWithMacro.ABCD).swigValue) throw new Exception("enumWithMacroTest 2 failed");
|
||||
}
|
||||
// different types
|
||||
{
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typeint).swigValue != 10) throw new Exception("differentTypes 1 failed");
|
||||
|
|
@ -413,6 +417,8 @@ public class runme {
|
|||
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");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound).swigValue != (int)'A' + 1) throw new Exception("differentTypes 7 failed");
|
||||
if (enum_thorough_typesafe.differentTypesTest(DifferentTypes.typecharcompound2).swigValue != (int)'B' << 2) throw new Exception("differentTypes 8 failed");
|
||||
|
||||
int global_enum = enum_thorough_typesafe.global_typeint;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != 10) throw new Exception("global differentTypes 1 failed");
|
||||
|
|
@ -426,6 +432,10 @@ public class runme {
|
|||
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");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'A' + 1) throw new Exception("global differentTypes 7 failed");
|
||||
global_enum = enum_thorough_typesafe.global_typecharcompound2;
|
||||
if (enum_thorough_typesafe.globalDifferentTypesTest(global_enum) != (int)'B' << 2) throw new Exception("global differentTypes 8 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
111
Examples/test-suite/csharp/li_boost_shared_ptr_director_runme.cs
Normal file
111
Examples/test-suite/csharp/li_boost_shared_ptr_director_runme.cs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
using System;
|
||||
using li_boost_shared_ptr_directorNamespace;
|
||||
|
||||
public class li_boost_shared_ptr_director_runme {
|
||||
|
||||
private static void check(int got, int expected) {
|
||||
if (got != expected)
|
||||
throw new Exception("Failed, got: " + got + " expected: " + expected);
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
Derived a = new Derived(false);
|
||||
Derived b = new Derived(true);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(a), 1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_shared_ptr(b), -1);
|
||||
check(li_boost_shared_ptr_director.call_ret_c_by_value(a), 1);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_value(a), 5);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_ref(a), 6);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer(a), 7);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref(a), 8);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value(a), 9);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref(a), 10);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer(a), 11);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref(a), 12);
|
||||
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_with_null(a), -2);
|
||||
check(li_boost_shared_ptr_director.call_take_c_by_pointer_ref_with_null(a), -3);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_value_with_null(a), -4);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_ref_with_null(a), -5);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_with_null(a), -6);
|
||||
check(li_boost_shared_ptr_director.call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Derived : Base {
|
||||
|
||||
private bool return_none;
|
||||
|
||||
public Derived(bool flag) : base() {
|
||||
this.return_none = flag;
|
||||
}
|
||||
|
||||
public override C ret_c_shared_ptr() {
|
||||
if (this.return_none)
|
||||
return null;
|
||||
else
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override C ret_c_by_value() {
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override int take_c_by_value(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_ref(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -3;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_value(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -4;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -5;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -6;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer_ref(C c) {
|
||||
if (c != null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,13 @@ public class li_std_auto_ptr_runme {
|
|||
if (Klass.getTotal_count() != 2)
|
||||
throw new Exception("number of objects should be 2");
|
||||
|
||||
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
|
||||
if (Klass.getTotal_count() != 3)
|
||||
throw new Exception("number of objects should be 3");
|
||||
}
|
||||
if (Klass.getTotal_count() != 2)
|
||||
throw new Exception("number of objects should be 2");
|
||||
|
||||
k1 = null;
|
||||
{
|
||||
int countdown = 500;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public class li_std_except_runme {
|
|||
|
||||
public static void Main() {
|
||||
Test test = new Test();
|
||||
try { test.throw_bad_cast(); throw new Exception("throw_bad_cast failed"); } catch (InvalidCastException) {}
|
||||
try { test.throw_bad_exception(); throw new Exception("throw_bad_exception failed"); } catch (ApplicationException) {}
|
||||
try { test.throw_domain_error(); throw new Exception("throw_domain_error failed"); } catch (ApplicationException) {}
|
||||
try { test.throw_exception(); throw new Exception("throw_exception failed"); } catch (ApplicationException) {}
|
||||
|
|
|
|||
402
Examples/test-suite/csharp/li_std_list_runme.cs
Normal file
402
Examples/test-suite/csharp/li_std_list_runme.cs
Normal file
|
|
@ -0,0 +1,402 @@
|
|||
using System;
|
||||
using li_std_listNamespace;
|
||||
|
||||
public class li_std_list_runme {
|
||||
private static readonly int collectionSize = 20;
|
||||
|
||||
public static void Main() {
|
||||
// Setup a list of int
|
||||
IntList list = new IntList();
|
||||
IntList.IntListNode node;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int nb = i * 10;
|
||||
list.Add(nb);
|
||||
}
|
||||
|
||||
// Count property test
|
||||
if (list.Count != collectionSize)
|
||||
throw new Exception("Count test failed");
|
||||
|
||||
// IsReadOnly property test
|
||||
if (list.IsReadOnly)
|
||||
throw new Exception("IsReadOnly test failed");
|
||||
|
||||
// Contains method test
|
||||
if (!list.Contains(0))
|
||||
throw new Exception("Contains method test 1 failed");
|
||||
if (!list.Contains(2 * 10))
|
||||
throw new Exception("Contains method test 2 failed");
|
||||
if (!list.Contains(19 * 10))
|
||||
throw new Exception("Contains method test 3 failed");
|
||||
if (list.Contains(20 * 10))
|
||||
throw new Exception("Contains method test 4 failed");
|
||||
|
||||
// Nodes comparison method overload
|
||||
{
|
||||
IntList.IntListNode temp = new IntList.IntListNode(3);
|
||||
if (list.First == temp)
|
||||
throw new Exception("== overload method test (1) failed");
|
||||
temp = new IntList.IntListNode(0);
|
||||
if (list.First == temp)
|
||||
throw new Exception("== overload method test (2) failed");
|
||||
IntList.IntListNode temp2 = new IntList.IntListNode(0);
|
||||
if (temp == temp2)
|
||||
throw new Exception("== overload method test (3) failed");
|
||||
if (!(list.First == list.First))
|
||||
throw new Exception("== overload method test (4) failed");
|
||||
if (list.First != list.First)
|
||||
throw new Exception("!= overload method test (1) failed");
|
||||
if (!(temp != temp2))
|
||||
throw new Exception("!= overload method test (2) failed");
|
||||
if (list.First.Equals(temp))
|
||||
throw new Exception("Equals method test failed");
|
||||
if (list.First.GetHashCode() == temp.GetHashCode())
|
||||
throw new Exception("GetHashCode method test (1) failed");
|
||||
if (list.First.GetHashCode() == list.First.GetHashCode())
|
||||
throw new Exception("GetHashCode method test (2) failed");
|
||||
|
||||
}
|
||||
|
||||
// Getter test
|
||||
{
|
||||
if (list.First == null)
|
||||
throw new Exception("First getter test (1) failed");
|
||||
if (list.Last == null)
|
||||
throw new Exception("Last getter test (1) failed");
|
||||
if (list.Last.Next != null)
|
||||
throw new Exception("Next getter test (1) failed");
|
||||
if (list.First.Next == null)
|
||||
throw new Exception("Next getter test (2) failed");
|
||||
if (list.First.Previous != null)
|
||||
throw new Exception("Previous getter test (1) failed");
|
||||
if (list.Last.Previous == null)
|
||||
throw new Exception("Previous getter test (2) failed");
|
||||
}
|
||||
|
||||
// AddFirst method test
|
||||
node = list.AddFirst(34);
|
||||
if (list.First.Value != 34 || node.Value != 34 || node != list.First)
|
||||
throw new Exception("AddFirst method test failed");
|
||||
try {
|
||||
list.AddFirst(null);
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddFirst(list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveFirst method test
|
||||
int tmp = list.First.Value;
|
||||
list.RemoveFirst();
|
||||
if (list.First.Value == tmp || list.First.Value != 0 * 10)
|
||||
throw new Exception("RemoveFirst method test failed");
|
||||
|
||||
// AddLast method test
|
||||
node = list.AddLast(8);
|
||||
if (list.Last.Value != 8 || node.Value != 8 || node != list.Last)
|
||||
throw new Exception("AddLast method test failed");
|
||||
try {
|
||||
list.AddLast(null);
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddLast(list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveLast method test
|
||||
int tmp2 = list.Last.Value;
|
||||
list.RemoveLast();
|
||||
if (list.Last.Value == tmp2 || list.Last.Value != (list.Count - 1) * 10)
|
||||
throw new Exception("RemoveLast method test failed");
|
||||
|
||||
// AddBefore method test
|
||||
node = list.AddBefore(list.Last, 17);
|
||||
if (list.Last.Previous.Value != 17 || node.Value != 17 || node != list.Last.Previous)
|
||||
throw new Exception("AddBefore method test (1) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.AddBefore(list.Last, node);
|
||||
throw new Exception("AddBefore method test (2) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
node = new IntList.IntListNode(1);
|
||||
list.AddBefore(null, node);
|
||||
throw new Exception("AddBefore method test (3) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddBefore(list.Last, list.First);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddAfter method test
|
||||
node = list.AddAfter(list.First, 47);
|
||||
if (list.First.Next.Value != 47 || node.Value != 47 || node != list.First.Next)
|
||||
throw new Exception("AddAfter method test (1) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.AddAfter(list.First.Next, node);
|
||||
throw new Exception("AddAfter method test (2) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
list.AddAfter(list.First, list.Last);
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// Find method test
|
||||
node = list.Find(0);
|
||||
if (node == null || node.Value != 0)
|
||||
throw new Exception("Find method test (1) failed");
|
||||
node = list.Find(47);
|
||||
if (node == null || node.Value != 47)
|
||||
throw new Exception("Find method test (2) failed");
|
||||
node = list.Find(190);
|
||||
if (node == null || node.Value != 190)
|
||||
throw new Exception("Find method test (3) failed");
|
||||
node = list.Find(-3);
|
||||
if (node != null)
|
||||
throw new Exception("Find method test (4) failed");
|
||||
|
||||
// Remove method test
|
||||
if (!list.Remove(17) || list.Contains(17) || list.Last.Previous.Value == 17)
|
||||
throw new Exception("Remove method test (1) failed");
|
||||
if (!list.Remove(47) || list.Contains(47) || list.First.Next.Value == 47)
|
||||
throw new Exception("Remove method test (2) failed");
|
||||
if (!list.Remove(0) || list.Contains(0) || list.First.Value == 0)
|
||||
throw new Exception("Remove method test (3) failed");
|
||||
if (!list.Remove(190) || list.Contains(190) || list.Last.Value == 190)
|
||||
throw new Exception("Remove method test (4) failed");
|
||||
try {
|
||||
node = null;
|
||||
list.Remove(node);
|
||||
throw new Exception("Remove method test (5) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
try {
|
||||
node = new IntList.IntListNode(4);
|
||||
list.Remove(node);
|
||||
throw new Exception("Remove method test (5) failed");
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
|
||||
// ICollection constructor test
|
||||
{
|
||||
int[] intArray = new int[] { 0, 11, 22, 33, 44, 55, 33 };
|
||||
IntList il = new IntList(intArray);
|
||||
if (intArray.Length != il.Count)
|
||||
throw new Exception("ICollection constructor length check failed: " + intArray.Length + "-" + il.Count);
|
||||
node = il.First;
|
||||
for (int i = 0; i < intArray.Length; i++) {
|
||||
if (intArray[i] != node.Value)
|
||||
throw new Exception("ICollection constructor failed, index:" + i);
|
||||
node = node.Next;
|
||||
}
|
||||
try {
|
||||
new IntList((System.Collections.ICollection)null);
|
||||
throw new Exception("ICollection constructor null test failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
}
|
||||
|
||||
// Enumerator test
|
||||
{
|
||||
node = list.First;
|
||||
System.Collections.IEnumerator myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if ((int)myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (1) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
System.Collections.Generic.IEnumerator<int> myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if (myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (2) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
IntList.IntListEnumerator myEnumerator = list.GetEnumerator();
|
||||
while (myEnumerator.MoveNext()) {
|
||||
if (myEnumerator.Current != node.Value)
|
||||
throw new Exception("Enumerator (3) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
node = list.First;
|
||||
foreach (var elem in list) {
|
||||
if (elem != node.Value)
|
||||
throw new Exception("Enumerator (4) test failed");
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
|
||||
// CopyTo method test
|
||||
{
|
||||
int[] outputarray = new int[collectionSize - 2];
|
||||
list.CopyTo(outputarray, 0);
|
||||
int index = 0;
|
||||
IntList.IntListNode temp = list.First;
|
||||
foreach (int val in outputarray) {
|
||||
if (temp.Value != val) {
|
||||
throw new Exception("CopyTo method test (1) failed, index:" + index);
|
||||
}
|
||||
index++;
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
DoubleList inputlist = new DoubleList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
double num = i * 10.1;
|
||||
inputlist.Add(num);
|
||||
}
|
||||
double[] outputarray = new double[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
DoubleList.DoubleListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i] != temp.Value)
|
||||
throw new Exception("CopyTo method test (2) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
{
|
||||
StructList inputlist = new StructList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++)
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructList.StructListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("CopyTo method test (3) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("CopyTo method test (4) failed, index:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
}
|
||||
try {
|
||||
list.CopyTo(null, 0);
|
||||
throw new Exception("CopyTo method test (5) failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
|
||||
// Clear() test
|
||||
list.Clear();
|
||||
if (list.Count != 0)
|
||||
throw new Exception("Clear method failed");
|
||||
|
||||
// Finally test the methods being wrapped
|
||||
{
|
||||
IntList il = new IntList();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
il.Add(i);
|
||||
}
|
||||
|
||||
double x = li_std_list.average(il);
|
||||
x += li_std_list.average(new IntList(new int[] { 1, 2, 3, 4 }));
|
||||
|
||||
DoubleList dlist = new DoubleList();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
dlist.Add(i / 2.0);
|
||||
}
|
||||
li_std_list.halve_in_place(dlist);
|
||||
}
|
||||
|
||||
// Dispose()
|
||||
{
|
||||
using (StructList ls = new StructList(new Struct[] { new Struct(0.0), new Struct(11.1) }))
|
||||
using (DoubleList ld = new DoubleList(new double[] { 0.0, 11.1 })) { }
|
||||
}
|
||||
|
||||
// More wrapped methods
|
||||
{
|
||||
FloatList l0 = li_std_list.listreal(new FloatList());
|
||||
float flo = 123.456f;
|
||||
l0.Add(flo);
|
||||
flo = l0.First.Value;
|
||||
|
||||
IntList l1 = li_std_list.listint(new IntList());
|
||||
IntPtrList l2 = li_std_list.listintptr(new IntPtrList());
|
||||
IntConstPtrList l3 = li_std_list.listintconstptr(new IntConstPtrList());
|
||||
|
||||
l1.Add(123);
|
||||
l2.Clear();
|
||||
l3.Clear();
|
||||
|
||||
StructList l4 = li_std_list.liststruct(new StructList());
|
||||
StructPtrList l5 = li_std_list.liststructptr(new StructPtrList());
|
||||
StructConstPtrList l6 = li_std_list.liststructconstptr(new StructConstPtrList());
|
||||
|
||||
l4.Add(new Struct(123));
|
||||
l5.Add(new Struct(123));
|
||||
l6.Add(new Struct(123));
|
||||
}
|
||||
|
||||
// Test lists of pointers
|
||||
{
|
||||
StructPtrList inputlist = new StructPtrList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
}
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructPtrList.StructPtrListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("StructPtrList test (1) failed, i:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != 20.0 + i / 10.0)
|
||||
throw new Exception("StructPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
|
||||
}
|
||||
}
|
||||
|
||||
// Test lists of const pointers
|
||||
{
|
||||
StructConstPtrList inputlist = new StructConstPtrList();
|
||||
int arrayLen = 10;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
inputlist.Add(new Struct(i / 10.0));
|
||||
}
|
||||
Struct[] outputarray = new Struct[arrayLen];
|
||||
inputlist.CopyTo(outputarray, 0);
|
||||
StructConstPtrList.StructConstPtrListNode temp = inputlist.First;
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != temp.Value.num)
|
||||
throw new Exception("StructConstPtrList test (1) failed, i:" + i);
|
||||
temp = temp.Next;
|
||||
}
|
||||
foreach (Struct s in inputlist) {
|
||||
s.num += 20.0;
|
||||
}
|
||||
for (int i = 0; i < arrayLen; i++) {
|
||||
if (outputarray[i].num != 20.0 + i / 10.0)
|
||||
throw new Exception("StructConstPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class li_std_map_runme {
|
|||
|
||||
public static void Main()
|
||||
{
|
||||
// Set up an int int map
|
||||
// Set up an string to int map
|
||||
StringIntMap simap = new StringIntMap();
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
|
|
@ -240,6 +240,20 @@ public class li_std_map_runme {
|
|||
throw new Exception("Key test (2) on complex key map failed");
|
||||
}
|
||||
|
||||
// Custom compare function
|
||||
{
|
||||
StringLengthNumberMap slmap = new StringLengthNumberMap();
|
||||
li_std_map.populate(slmap);
|
||||
|
||||
string keys = string.Join(" ", new List<string>(slmap.Keys));
|
||||
if (keys != "a aa zzz xxxx aaaaa")
|
||||
throw new Exception("Keys are wrong or in wrong order: " + keys);
|
||||
|
||||
string values = string.Join(" ", new List<int>(slmap.Values));
|
||||
if (values != "1 2 3 4 5")
|
||||
throw new Exception("Values are wrong or in wrong order: " + values);
|
||||
}
|
||||
|
||||
// All done
|
||||
}
|
||||
}
|
||||
|
|
|
|||
105
Examples/test-suite/csharp/li_std_set_runme.cs
Normal file
105
Examples/test-suite/csharp/li_std_set_runme.cs
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using li_std_setNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void checkThat(bool mustBeTrue, string message)
|
||||
{
|
||||
if (!mustBeTrue)
|
||||
throw new Exception("Test that the set " + message + " failed");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
StringSet ss = new StringSet();
|
||||
|
||||
// Check the interface methods first.
|
||||
ISet<string> s = ss;
|
||||
|
||||
checkThat(s.Count == 0, "is initially empty");
|
||||
checkThat(!s.Contains("key"), "doesn't contain inexistent element");
|
||||
checkThat(!s.Remove("key"), "returns false when removing inexistent element");
|
||||
|
||||
checkThat(s.Add("key"), "returns true when adding a new element");
|
||||
checkThat(!s.Add("key"), "returns false when adding an existing element");
|
||||
checkThat(s.Contains("key"), "contains the just added element");
|
||||
checkThat(s.Remove("key"), "returns true when removing an existing element");
|
||||
checkThat(s.Count == 0, "is empty again");
|
||||
|
||||
checkThat(s.Add("key1"), "Add(key1) returns true");
|
||||
checkThat(s.Add("key2"), "Add(key2) returns true");
|
||||
checkThat(s.Add("key3"), "Add(key3) returns true");
|
||||
|
||||
// Also check a different interface, providing a different Add() (sic!).
|
||||
ICollection<string> coll = ss;
|
||||
coll.Add("key");
|
||||
checkThat(ss.Count == 4, "contains 4 elements");
|
||||
|
||||
// Now use object-specific methods, mimicking HashSet<>.
|
||||
string val;
|
||||
checkThat(ss.TryGetValue("key1", out val), "could retrieve existing item");
|
||||
checkThat(val.Equals("key1"), "value was returned correctly by TryGetValue()");
|
||||
checkThat(!ss.TryGetValue("no-such-key", out val), "couldn't retrieve inexistent item");
|
||||
checkThat(val == null, "value was reset after failed TryGetValue()");
|
||||
|
||||
IList<string> list = new List<string>();
|
||||
foreach (string str in ss) {
|
||||
list.Add(str);
|
||||
}
|
||||
checkThat(list.Count == 4, "copy contains 4 elements");
|
||||
|
||||
ss.Clear();
|
||||
checkThat(ss.Count == 0, "is empty after Clear()");
|
||||
|
||||
// Check set-theoretic methods.
|
||||
checkThat(new StringSet().SetEquals(new StringSet()), "SetEquals() works for empty sets");
|
||||
checkThat(new StringSet{"foo"}.SetEquals(new StringSet{"foo"}), "SetEquals() works for non-empty sets");
|
||||
checkThat(!new StringSet{"foo"}.SetEquals(new[] {"bar"}), "SetEquals() doesn't always return true");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.ExceptWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar"}), "ExceptWith works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.IntersectWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"baz"}), "IntersectWith works");
|
||||
|
||||
checkThat(ss.IsProperSubsetOf(new[] {"bar", "baz"}), "IsProperSubsetOf works");
|
||||
checkThat(!ss.IsProperSubsetOf(new[] {"baz"}), "!IsProperSubsetOf works");
|
||||
checkThat(ss.IsSubsetOf(new[] {"bar", "baz"}), "IsSubsetOf works");
|
||||
checkThat(!ss.IsSubsetOf(new[] {"bar"}), "!IsSubsetOf works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
checkThat(ss.IsProperSupersetOf(new[] {"bar"}), "IsProperSupersetOf works");
|
||||
checkThat(!ss.IsProperSupersetOf(new[] {"quux"}), "IsProperSupersetOf works");
|
||||
checkThat(ss.IsSupersetOf(new[] {"foo", "bar", "baz"}), "IsProperSupersetOf works");
|
||||
checkThat(!ss.IsSupersetOf(new[] {"foo", "bar", "baz", "quux"}), "IsProperSupersetOf works");
|
||||
|
||||
checkThat(ss.Overlaps(new[] {"foo"}), "Overlaps works");
|
||||
checkThat(!ss.Overlaps(new[] {"moo"}), "!Overlaps works");
|
||||
|
||||
ss.SymmetricExceptWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar", "quux"}), "SymmetricExceptWith works");
|
||||
|
||||
ss = new StringSet{"foo", "bar", "baz"};
|
||||
ss.UnionWith(new[] {"baz", "quux"});
|
||||
checkThat(ss.SetEquals(new[] {"foo", "bar", "baz", "quux"}), "UnionWith works");
|
||||
|
||||
// Check a set of another type.
|
||||
FooSet fooSet = new FooSet();
|
||||
ISet<Foo> fooISet = fooSet;
|
||||
checkThat(fooISet.Count == 0, "is initially empty");
|
||||
checkThat(fooISet.Add(new Foo(17)), "added successfully");
|
||||
checkThat(fooISet.Count == 1, "is not empty any more");
|
||||
|
||||
// And a set of primitive type.
|
||||
IntSet intSet = new IntSet();
|
||||
checkThat(intSet.Count == 0, "is initially empty");
|
||||
checkThat(intSet.Add(17), "17 added successfully");
|
||||
checkThat(!intSet.Add(17), "17 not added again");
|
||||
checkThat(intSet.Count == 1, "not empty any more");
|
||||
checkThat(intSet.Add(289), "289 added successfully");
|
||||
checkThat(intSet.Count == 2, "even less empty now");
|
||||
}
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ public class li_std_vector_runme {
|
|||
throw new Exception("Contains test 4 failed");
|
||||
|
||||
{
|
||||
// ICollection constructor
|
||||
// IEnumerable constructor
|
||||
double[] doubleArray = new double[] { 0.0, 11.1, 22.2, 33.3, 44.4, 55.5, 33.3 };
|
||||
DoubleVector dv = new DoubleVector(doubleArray);
|
||||
if (doubleArray.Length != dv.Count)
|
||||
|
|
@ -177,6 +177,17 @@ public class li_std_vector_runme {
|
|||
if (doubleArray[i] != dvCopy[i])
|
||||
throw new Exception("Copy constructor failed, index:" + i);
|
||||
}
|
||||
if (dvCopy.Count != doubleArray.Length)
|
||||
throw new Exception("Copy constructor lengths mismatch");
|
||||
|
||||
// ToArray test
|
||||
double[] dvArray = dv.ToArray();
|
||||
for (int i=0; i<doubleArray.Length; i++) {
|
||||
if (doubleArray[i] != dvArray[i])
|
||||
throw new Exception("ToArray failed, index:" + i);
|
||||
}
|
||||
if (dvArray.Length != doubleArray.Length)
|
||||
throw new Exception("ToArray lengths mismatch");
|
||||
}
|
||||
{
|
||||
// Repeat() test
|
||||
|
|
@ -619,6 +630,55 @@ public class li_std_vector_runme {
|
|||
}
|
||||
}
|
||||
|
||||
// Test construction
|
||||
{
|
||||
string[] one_two_three = new string[] { "one", "two", "three" };
|
||||
|
||||
// Test construction from array
|
||||
{
|
||||
string[] collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IEnumerable
|
||||
{
|
||||
global::System.Collections.IEnumerable collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IEnumerable<>
|
||||
{
|
||||
global::System.Collections.Generic.IEnumerable<string> collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from IList<>
|
||||
{
|
||||
global::System.Collections.Generic.IList<string> collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from ICollection
|
||||
{
|
||||
global::System.Collections.ICollection collection = one_two_three;
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
|
||||
// Test construction from ICollection<>
|
||||
{
|
||||
global::System.Collections.Generic.ICollection<string> collection = new global::System.Collections.Generic.List<string>(one_two_three);
|
||||
check123(new StringVector(collection));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void check123(StringVector stringv) {
|
||||
string concatenated = "";
|
||||
foreach (string s in stringv)
|
||||
concatenated = concatenated + s;
|
||||
if (concatenated != "onetwothree")
|
||||
throw new Exception("concatenated string failed: " + concatenated);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,74 +3,113 @@ using li_std_wstringNamespace;
|
|||
|
||||
public class runme
|
||||
{
|
||||
static private void check_equal(char a, char b)
|
||||
{
|
||||
if (a != b)
|
||||
throw new Exception("char failed '" + a + "' != '" + b + "'");
|
||||
}
|
||||
|
||||
static private void check_equal(string a, string b)
|
||||
{
|
||||
if (a != b)
|
||||
throw new Exception("string failed '" + a + "' != '" + b + "'");
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
char y='h';
|
||||
char h = 'h';
|
||||
check_equal(li_std_wstring.test_wcvalue(h), h);
|
||||
|
||||
if (li_std_wstring.test_wcvalue(y) != y)
|
||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue(y));
|
||||
string x = "abc";
|
||||
check_equal(li_std_wstring.test_ccvalue(x), x);
|
||||
check_equal(li_std_wstring.test_cvalue(x), x);
|
||||
|
||||
if (li_std_wstring.test_wcvalue_w() != 'W')
|
||||
throw new Exception("bad string mapping:" + li_std_wstring.test_wcvalue_w());
|
||||
check_equal(li_std_wstring.test_wchar_overload(x), x);
|
||||
check_equal(li_std_wstring.test_wchar_overload(), null);
|
||||
|
||||
string x="hello";
|
||||
li_std_wstring.test_pointer(null);
|
||||
li_std_wstring.test_const_pointer(null);
|
||||
|
||||
if (li_std_wstring.test_ccvalue(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_value(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_cvalue(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_reference(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException e) {
|
||||
if (!e.Message.Contains("type is null"))
|
||||
throw new Exception("Missing text " + e);
|
||||
}
|
||||
try {
|
||||
li_std_wstring.test_const_reference(null);
|
||||
throw new Exception("NULL check failed");
|
||||
} catch (ArgumentNullException e) {
|
||||
if (!e.Message.Contains("null wstring"))
|
||||
throw new Exception("Missing text " + e);
|
||||
}
|
||||
|
||||
x = "hello";
|
||||
check_equal(li_std_wstring.test_const_reference(x), x);
|
||||
|
||||
if (li_std_wstring.test_value(x) != x)
|
||||
throw new Exception("bad string mapping: " + x + li_std_wstring.test_value(x));
|
||||
/* Postpone, tricky, std::wstring portability problem.
|
||||
* std::wstring is 2 bytes on Windows, 4 bytes on Linux, LPWSTR is 2 bytes.
|
||||
* .NET marshalling should work on Windows but not Linux.
|
||||
string s = "abc";
|
||||
if (!li_std_wstring.test_equal_abc(s))
|
||||
throw new Exception("Not equal " + s);
|
||||
*/
|
||||
|
||||
if (li_std_wstring.test_const_reference(x) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
try {
|
||||
li_std_wstring.test_throw();
|
||||
} catch (Exception e) {
|
||||
check_equal(e.Message, "throwing test_throw");
|
||||
}
|
||||
|
||||
x = "abc\0def";
|
||||
// Unlike other languages, embedded NULL in std::string not supported
|
||||
// check_equal(li_std_wstring.test_value(x), x);
|
||||
check_equal(li_std_wstring.test_value(x), "abc");
|
||||
check_equal(li_std_wstring.test_ccvalue(x), "abc");
|
||||
check_equal(li_std_wstring.test_wchar_overload(x), "abc");
|
||||
|
||||
string s = "he";
|
||||
s = s + "llo";
|
||||
{
|
||||
// Unicode strings
|
||||
string[] test_strings = {
|
||||
"JP: 日本語", "DE: Kröpeliner Straße" , "RU: Война и мир", "EN: War and Peace"
|
||||
};
|
||||
|
||||
if (s != x)
|
||||
throw new Exception("bad string mapping: " + s + x);
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_value(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_value(s) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_const_reference(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
if (li_std_wstring.test_const_reference(s) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
foreach (string expected in test_strings)
|
||||
{
|
||||
string received = li_std_wstring.test_ccvalue(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
|
||||
string a = s;
|
||||
|
||||
if (li_std_wstring.test_value(a) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
if (li_std_wstring.test_const_reference(a) != x)
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
string b = " world";
|
||||
|
||||
if (a + b != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
if (a + " world" != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
if ("hello" + b != "hello world")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
s = "hello world";
|
||||
|
||||
B myB = new B("hi");
|
||||
|
||||
myB.name = "hello";
|
||||
if (myB.name != "hello")
|
||||
throw new Exception("bad string mapping");
|
||||
|
||||
myB.a = "hello";
|
||||
if (myB.a != "hello")
|
||||
throw new Exception("bad string mapping");
|
||||
/* Not working on Windows okay on Linux
|
||||
foreach (string test_string in test_strings)
|
||||
{
|
||||
foreach (char expected in test_string)
|
||||
{
|
||||
char received = li_std_wstring.test_wcvalue(expected);
|
||||
check_equal(received, expected);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using nested_in_templateNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
var cd = new OuterTemplate1.ConcreteDerived(88);
|
||||
if (cd.m_value != 88)
|
||||
throw new Exception("ConcreteDerived not created correctly");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using nested_inheritance_interfaceNamespace;
|
||||
|
||||
public class nested_inheritance_interface_runme {
|
||||
|
||||
static string SortArrayToString(string[] types) {
|
||||
Array.Sort<string>(types);
|
||||
return string.Join(" ", types);
|
||||
}
|
||||
|
||||
static string SortArrayToString(Type[] types) {
|
||||
List<string> stypes = new List<string>();
|
||||
foreach (Type t in types)
|
||||
stypes.Add(t.Name);
|
||||
return SortArrayToString(stypes.ToArray());
|
||||
}
|
||||
|
||||
private static void takeIA(IASwigInterface ia) {
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
Type[] BNInterfaces = typeof(B.N).GetInterfaces();
|
||||
string expectedInterfacesString = "IASwigInterface IDisposable";
|
||||
string actualInterfacesString = SortArrayToString(BNInterfaces);
|
||||
if (expectedInterfacesString != actualInterfacesString)
|
||||
throw new Exception("Expected interfaces for " + typeof(B.N).Name + ": \n" + expectedInterfacesString + "\n" + "Actual interfaces: \n" + actualInterfacesString);
|
||||
|
||||
if (!typeof(IASwigInterface).IsInterface)
|
||||
throw new Exception(typeof(IASwigInterface).Name + " should be an interface but is not");
|
||||
|
||||
// overloaded methods check
|
||||
B.N d = new B.N();
|
||||
takeIA(d);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class runme {
|
|||
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_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() );
|
||||
|
|
@ -61,7 +61,9 @@ public class runme {
|
|||
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() );
|
||||
|
||||
assert( typeof(double) == preproc_constants_c.EXPR_MIXED1.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
|
||||
assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
if (!assertion)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class runme {
|
|||
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_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() );
|
||||
|
|
@ -60,6 +60,9 @@ public class runme {
|
|||
assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
|
||||
assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
|
||||
assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
|
||||
assert( typeof(double) == preproc_constants.EXPR_MIXED1.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
|
||||
assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
|
||||
|
||||
}
|
||||
static void assert(bool assertion) {
|
||||
|
|
|
|||
33
Examples/test-suite/csharp/proxycode_runme.cs
Normal file
33
Examples/test-suite/csharp/proxycode_runme.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using proxycodeNamespace;
|
||||
|
||||
public class proxycode_runme {
|
||||
|
||||
public static void Main() {
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2a(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2b(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy3().proxycode3(100) != 103)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy4().proxycode4(100) != 104)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy5a().proxycode5((short)100) != (short)100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100, 100) != 255)
|
||||
throw new Exception("Fail");
|
||||
|
||||
uint t1 = 10;
|
||||
uint t2 = 100;
|
||||
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
|
||||
p.useT(t1, t2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
%module csharp_exceptions
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
%}
|
||||
|
||||
%include <exception.i>
|
||||
|
||||
%inline %{
|
||||
|
|
@ -36,21 +42,16 @@
|
|||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
// %exception tests
|
||||
void ThrowByValue() { throw Ex("ThrowByValue"); }
|
||||
void ThrowByReference() { throw Ex("ThrowByReference"); }
|
||||
// %csnothrowexception
|
||||
void NoThrowException() { throw Ex("NoThrowException"); }
|
||||
// exception specifications
|
||||
void ExceptionSpecificationValue() throw(Ex) { throw Ex("ExceptionSpecificationValue"); }
|
||||
void ExceptionSpecificationReference() throw(Ex&) { throw Ex("ExceptionSpecificationReference"); }
|
||||
void ExceptionSpecificationString() throw(const char *) { throw "ExceptionSpecificationString"; }
|
||||
void ExceptionSpecificationInteger() throw(int) { throw 20; }
|
||||
void ExceptionSpecificationValue() TESTCASE_THROW1(Ex) { throw Ex("ExceptionSpecificationValue"); }
|
||||
void ExceptionSpecificationReference() TESTCASE_THROW1(Ex&) { throw Ex("ExceptionSpecificationReference"); }
|
||||
void ExceptionSpecificationString() TESTCASE_THROW1(const char *) { throw "ExceptionSpecificationString"; }
|
||||
void ExceptionSpecificationInteger() TESTCASE_THROW1(int) { throw 20; }
|
||||
%}
|
||||
|
||||
// test exceptions in the default typemaps
|
||||
|
|
@ -64,15 +65,15 @@ void NullValue(Ex e) {}
|
|||
// enums
|
||||
%inline %{
|
||||
enum TestEnum {TestEnumItem};
|
||||
void ExceptionSpecificationEnumValue() throw(TestEnum) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumReference() throw(TestEnum&) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumValue() TESTCASE_THROW1(TestEnum) { throw TestEnumItem; }
|
||||
void ExceptionSpecificationEnumReference() TESTCASE_THROW1(TestEnum&) { throw TestEnumItem; }
|
||||
%}
|
||||
|
||||
// std::string
|
||||
%include <std_string.i>
|
||||
%inline %{
|
||||
void ExceptionSpecificationStdStringValue() throw(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); }
|
||||
void ExceptionSpecificationStdStringReference() throw(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); }
|
||||
void ExceptionSpecificationStdStringValue() TESTCASE_THROW1(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); }
|
||||
void ExceptionSpecificationStdStringReference() TESTCASE_THROW1(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); }
|
||||
void NullStdStringValue(std::string s) {}
|
||||
void NullStdStringReference(std::string &s) {}
|
||||
%}
|
||||
|
|
@ -104,12 +105,8 @@ void MemoryLeakCheck() {
|
|||
%inline %{
|
||||
struct constructor {
|
||||
constructor(std::string s) {}
|
||||
constructor() throw(int) { throw 10; }
|
||||
constructor() TESTCASE_THROW1(int) { throw 10; }
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
// test exception pending in the csout typemaps
|
||||
|
|
@ -239,3 +236,4 @@ struct ThrowsClass {
|
|||
%inline %{
|
||||
void InnerExceptionTest() { throw Ex("My InnerException message"); }
|
||||
%}
|
||||
|
||||
|
|
|
|||
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
78
Examples/test-suite/csharp_lib_arrays_bool.i
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
%module csharp_lib_arrays_bool
|
||||
|
||||
%include "arrays_csharp.i"
|
||||
|
||||
%apply bool INPUT[] { bool* sourceArray }
|
||||
%apply bool OUTPUT[] { bool* targetArray }
|
||||
|
||||
%apply bool INOUT[] { bool* array1 }
|
||||
%apply bool INOUT[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
|
||||
/* copy the contents of the first array to the second */
|
||||
void myArrayCopyBool( bool* sourceArray, bool* targetArray, int nitems ) {
|
||||
int i;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
targetArray[ i ] = sourceArray[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
/* swap the contents of the two arrays */
|
||||
void myArraySwapBool( bool* array1, bool* array2, int nitems ) {
|
||||
int i;
|
||||
bool temp;
|
||||
for ( i = 0; i < nitems; i++ ) {
|
||||
temp = array1[ i ];
|
||||
array1[ i ] = array2[ i ];
|
||||
array2[ i ] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
bool checkBoolArrayCorrect( bool* sourceArray, int sourceArraySize ) {
|
||||
if( sourceArraySize != 8 ) {
|
||||
std::cout << "checkBoolArrayCorrect: Expected array with 8 elements" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return sourceArray[0] == true &&
|
||||
sourceArray[1] == false &&
|
||||
sourceArray[2] == false &&
|
||||
sourceArray[3] == true &&
|
||||
sourceArray[4] == false &&
|
||||
sourceArray[5] == true &&
|
||||
sourceArray[6] == true &&
|
||||
sourceArray[7] == false;
|
||||
}
|
||||
%}
|
||||
|
||||
%clear bool* sourceArray;
|
||||
%clear bool* targetArray;
|
||||
|
||||
%clear bool* array1;
|
||||
%clear bool* array2;
|
||||
|
||||
// Below replicates the above array handling but this time using the pinned (fixed) array typemaps
|
||||
%csmethodmodifiers myArrayCopyUsingFixedArraysBool "public unsafe";
|
||||
%csmethodmodifiers myArraySwapUsingFixedArraysBool "public unsafe";
|
||||
|
||||
%apply bool FIXED[] { bool* sourceArray }
|
||||
%apply bool FIXED[] { bool* targetArray }
|
||||
|
||||
%inline %{
|
||||
void myArrayCopyUsingFixedArraysBool( bool *sourceArray, bool* targetArray, int nitems ) {
|
||||
myArrayCopyBool(sourceArray, targetArray, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
%apply bool FIXED[] { bool* array1 }
|
||||
%apply bool FIXED[] { bool* array2 }
|
||||
|
||||
%inline %{
|
||||
void myArraySwapUsingFixedArraysBool( bool* array1, bool* array2, int nitems ) {
|
||||
myArraySwapBool(array1, array2, nitems);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
|
||||
|
|
@ -24,6 +24,12 @@ CPP_TEST_CASES = \
|
|||
d_nativepointers \
|
||||
exception_partial_info
|
||||
|
||||
CPP11_TEST_CASES = \
|
||||
cpp11_shared_ptr_const \
|
||||
cpp11_shared_ptr_nullptr_in_containers \
|
||||
cpp11_shared_ptr_overload \
|
||||
cpp11_shared_ptr_upcast \
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Overridden variables here
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
* Base - Val(444.555)
|
||||
* Base - Ref(444.555)
|
||||
* Base - Ptr(444.555)
|
||||
* Base - ConstPtrRef(444.555)
|
||||
* Base - FullyOverloaded(int 10)
|
||||
* Base - FullyOverloaded(bool 1)
|
||||
* Base - SemiOverloaded(int -678)
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
* Derived - Val(444.555)
|
||||
* Derived - Ref(444.555)
|
||||
* Derived - Ptr(444.555)
|
||||
* Derived - ConstPtrRef(444.555)
|
||||
* Derived - FullyOverloaded(int 10)
|
||||
* Derived - FullyOverloaded(bool 1)
|
||||
* Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -38,6 +40,7 @@
|
|||
* DDerived - Val(444.555)
|
||||
* DDerived - Ref(444.555)
|
||||
* DDerived - Ptr(444.555)
|
||||
* DDerived - ConstPtrRef(444.555)
|
||||
* DDerived - FullyOverloaded(int 10)
|
||||
* DDerived - FullyOverloaded(bool True)
|
||||
* DDerived - SemiOverloaded(-678)
|
||||
|
|
@ -57,7 +60,7 @@ import director_classes.Derived;
|
|||
import director_classes.DoubleHolder;
|
||||
|
||||
void main() {
|
||||
if (PrintDebug) Stdout.formatln("------------ Start ------------ ");
|
||||
if (PrintDebug) Stdout.formatln("------------ Start ------------");
|
||||
|
||||
auto myCaller = new Caller();
|
||||
|
||||
|
|
@ -83,7 +86,7 @@ void main() {
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (PrintDebug) Stdout.formatln("------------ Finish ------------ ");
|
||||
if (PrintDebug) Stdout.formatln("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase) {
|
||||
|
|
@ -96,6 +99,7 @@ void makeCalls(Caller myCaller, Base myBase) {
|
|||
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");
|
||||
if (myCaller.ConstPtrRefCall(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");
|
||||
|
|
@ -136,6 +140,11 @@ public class DDerived : Base {
|
|||
return x;
|
||||
}
|
||||
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
|
||||
if (PrintDebug) Stdout.formatln("DDerived - ConstPtrRef({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)";
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
* Base - Val(444.555)
|
||||
* Base - Ref(444.555)
|
||||
* Base - Ptr(444.555)
|
||||
* Base - ConstPtrRef(444.555)
|
||||
* Base - FullyOverloaded(int 10)
|
||||
* Base - FullyOverloaded(bool 1)
|
||||
* Base - SemiOverloaded(int -678)
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
* Derived - Val(444.555)
|
||||
* Derived - Ref(444.555)
|
||||
* Derived - Ptr(444.555)
|
||||
* Derived - ConstPtrRef(444.555)
|
||||
* Derived - FullyOverloaded(int 10)
|
||||
* Derived - FullyOverloaded(bool 1)
|
||||
* Derived - SemiOverloaded(int -678)
|
||||
|
|
@ -38,6 +40,7 @@
|
|||
* DDerived - Val(444.555)
|
||||
* DDerived - Ref(444.555)
|
||||
* DDerived - Ptr(444.555)
|
||||
* DDerived - ConstPtrRef(444.555)
|
||||
* DDerived - FullyOverloaded(int 10)
|
||||
* DDerived - FullyOverloaded(bool true)
|
||||
* DDerived - SemiOverloaded(-678)
|
||||
|
|
@ -58,7 +61,7 @@ import director_classes.Derived;
|
|||
import director_classes.DoubleHolder;
|
||||
|
||||
void main() {
|
||||
if (PrintDebug) writeln("------------ Start ------------ ");
|
||||
if (PrintDebug) writeln("------------ Start ------------");
|
||||
|
||||
auto myCaller = new Caller();
|
||||
|
||||
|
|
@ -84,7 +87,7 @@ void main() {
|
|||
makeCalls(myCaller, myBase);
|
||||
}
|
||||
|
||||
if (PrintDebug) writeln("------------ Finish ------------ ");
|
||||
if (PrintDebug) writeln("------------ Finish ------------");
|
||||
}
|
||||
|
||||
void makeCalls(Caller myCaller, Base myBase) {
|
||||
|
|
@ -97,6 +100,7 @@ void makeCalls(Caller myCaller, Base myBase) {
|
|||
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");
|
||||
enforce(myCaller.ConstPtrRefCall(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");
|
||||
|
|
@ -137,6 +141,11 @@ public class DDerived : Base {
|
|||
return x;
|
||||
}
|
||||
|
||||
public override DoubleHolder ConstPtrRef(DoubleHolder x) {
|
||||
if (PrintDebug) writefln("DDerived - ConstPtrRef(%s)", x.val);
|
||||
return x;
|
||||
}
|
||||
|
||||
public override string FullyOverloaded(int x) {
|
||||
if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x);
|
||||
return "DDerived::FullyOverloaded(int)";
|
||||
|
|
|
|||
114
Examples/test-suite/d/li_boost_shared_ptr_director_runme.2.d
Normal file
114
Examples/test-suite/d/li_boost_shared_ptr_director_runme.2.d
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
module li_boost_shared_ptr_director_runme;
|
||||
|
||||
import std.conv;
|
||||
import std.exception;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import li_boost_shared_ptr_director.li_boost_shared_ptr_director;
|
||||
import li_boost_shared_ptr_director.Base;
|
||||
import li_boost_shared_ptr_director.C;
|
||||
|
||||
void check(int got, int expected) {
|
||||
enforce(got == expected, "Failed. got: " ~ to!string(got) ~ " Expected: " ~ to!string(expected));
|
||||
}
|
||||
|
||||
void main() {
|
||||
Derived a = new Derived(false);
|
||||
Derived b = new Derived(true);
|
||||
|
||||
check(call_ret_c_shared_ptr(a), 1);
|
||||
check(call_ret_c_shared_ptr(b), -1);
|
||||
check(call_ret_c_by_value(a), 1);
|
||||
|
||||
check(call_ret_c_shared_ptr(a), 1);
|
||||
check(call_ret_c_shared_ptr(b), -1);
|
||||
check(call_ret_c_by_value(a), 1);
|
||||
|
||||
check(call_take_c_by_value(a), 5);
|
||||
check(call_take_c_by_ref(a), 6);
|
||||
check(call_take_c_by_pointer(a), 7);
|
||||
check(call_take_c_by_pointer_ref(a), 8);
|
||||
check(call_take_c_shared_ptr_by_value(a), 9);
|
||||
check(call_take_c_shared_ptr_by_ref(a), 10);
|
||||
check(call_take_c_shared_ptr_by_pointer(a), 11);
|
||||
check(call_take_c_shared_ptr_by_pointer_ref(a), 12);
|
||||
|
||||
check(call_take_c_by_pointer_with_null(a), -2);
|
||||
check(call_take_c_by_pointer_ref_with_null(a), -3);
|
||||
check(call_take_c_shared_ptr_by_value_with_null(a), -4);
|
||||
check(call_take_c_shared_ptr_by_ref_with_null(a), -5);
|
||||
check(call_take_c_shared_ptr_by_pointer_with_null(a), -6);
|
||||
check(call_take_c_shared_ptr_by_pointer_ref_with_null(a), -7);
|
||||
}
|
||||
|
||||
public class Derived : Base {
|
||||
|
||||
private bool return_none;
|
||||
|
||||
public this(bool flag) {
|
||||
super();
|
||||
this.return_none = flag;
|
||||
}
|
||||
|
||||
public override C ret_c_shared_ptr() {
|
||||
if (this.return_none)
|
||||
return null;
|
||||
else
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override C ret_c_by_value() {
|
||||
return new C();
|
||||
}
|
||||
|
||||
public override int take_c_by_value(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_ref(C c) {
|
||||
return c.get_m();
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
|
||||
public override int take_c_by_pointer_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -3;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_value(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -4;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -5;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -6;
|
||||
}
|
||||
|
||||
public override int take_c_shared_ptr_by_pointer_ref(C c) {
|
||||
if (c !is null)
|
||||
return c.get_m();
|
||||
else
|
||||
return -7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ void main() {
|
|||
static assert(is(char[] == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -61,4 +61,7 @@ void main() {
|
|||
static assert(is(int == typeof(EXPR_LAND())));
|
||||
static assert(is(int == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ void main() {
|
|||
static assert(is(string == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -61,4 +61,7 @@ void main() {
|
|||
static assert(is(int == typeof(EXPR_LAND())));
|
||||
static assert(is(int == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
static assert(is(char[] == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -60,4 +60,7 @@ void main() {
|
|||
static assert(is(bool == typeof(EXPR_LAND())));
|
||||
static assert(is(bool == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
static assert(is(string == typeof(CONST_STRING2())));
|
||||
|
||||
static assert(is(int == typeof(INT_AND_BOOL())));
|
||||
// static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_CHAR())));
|
||||
static assert(is(int == typeof(INT_AND_INT())));
|
||||
static assert(is(uint == typeof(INT_AND_UINT())));
|
||||
static assert(is(c_long == typeof(INT_AND_LONG())));
|
||||
|
|
@ -60,4 +60,7 @@ void main() {
|
|||
static assert(is(bool == typeof(EXPR_LAND())));
|
||||
static assert(is(bool == typeof(EXPR_LOR())));
|
||||
static assert(is(double == typeof(EXPR_CONDITIONAL())));
|
||||
static assert(is(double == typeof(EXPR_MIXED1())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MAX())));
|
||||
static assert(is(int == typeof(EXPR_WCHAR_MIN())));
|
||||
}
|
||||
|
|
|
|||
41
Examples/test-suite/d/proxycode_runme.2.d
Normal file
41
Examples/test-suite/d/proxycode_runme.2.d
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
module proxycode_runme;
|
||||
|
||||
import std.exception;
|
||||
import proxycode.Proxy1;
|
||||
import proxycode.Proxy2;
|
||||
import proxycode.Proxy3;
|
||||
import proxycode.Proxy4;
|
||||
import proxycode.Proxy5a;
|
||||
import proxycode.Proxy5b;
|
||||
import proxycode.Proxy6;
|
||||
|
||||
void main() {
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy1().proxycode1(100) != 101)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2a(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy2().proxycode2b(100) != 102)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy3().proxycode3(100) != 103)
|
||||
throw new Exception("Fail");
|
||||
|
||||
if (new Proxy4().proxycode4(100) != 104)
|
||||
throw new Exception("Fail");
|
||||
// if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144)
|
||||
// throw new Exception("Fail");
|
||||
|
||||
if (new Proxy5a().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100) != 100)
|
||||
throw new Exception("Fail");
|
||||
if (new Proxy5b().proxycode5(100, 100) != 255)
|
||||
throw new Exception("Fail");
|
||||
|
||||
uint t1 = 10;
|
||||
uint t2 = 100;
|
||||
Proxy6 p = new Proxy6().proxyUseT(t1, t2);
|
||||
p.useT(t1, t2);
|
||||
}
|
||||
34
Examples/test-suite/default_arg_expressions.i
Normal file
34
Examples/test-suite/default_arg_expressions.i
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%module default_arg_expressions
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ptr;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) UsdGeomTokensPtr;
|
||||
%immutable UsdGeomTokens;
|
||||
|
||||
%inline %{
|
||||
struct Numbers {
|
||||
int val;
|
||||
int *ptr;
|
||||
Numbers() : val(), ptr(&val) {}
|
||||
};
|
||||
struct TfToken {
|
||||
Numbers val;
|
||||
Numbers *ptr;
|
||||
TfToken() : val(), ptr(&val) {}
|
||||
};
|
||||
struct Tokens {
|
||||
const TfToken face;
|
||||
const TfToken *pface;
|
||||
Tokens() : face(), pface(&face) {}
|
||||
};
|
||||
static Tokens UsdGeomTokens;
|
||||
static Tokens *UsdGeomTokensPtr = &UsdGeomTokens;
|
||||
void CreateMaterialBindSubset1(const Tokens &elementType = UsdGeomTokens) {}
|
||||
void CreateMaterialBindSubset2(int num = UsdGeomTokensPtr->pface->val.val) {}
|
||||
void CreateMaterialBindSubset3(int num = UsdGeomTokensPtr->pface->ptr->val) {}
|
||||
void CreateMaterialBindSubset4(int num = UsdGeomTokensPtr->face.val.val) {}
|
||||
//void CreateMaterialBindSubset5(int num = UsdGeomTokens.face.val.val) {}
|
||||
%}
|
||||
|
|
@ -2,26 +2,51 @@
|
|||
|
||||
%module default_args
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
#endif
|
||||
%}
|
||||
|
||||
// throw is invalid in C++17 and later, only SWIG to use it
|
||||
#define TESTCASE_THROW1(T1) throw(T1)
|
||||
#define TESTCASE_THROW2(T1, T2) throw(T1, T2)
|
||||
%{
|
||||
#define TESTCASE_THROW1(T1)
|
||||
#define TESTCASE_THROW2(T1, T2)
|
||||
%}
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
// All kinds of numbers: hex, octal (which pose special problems to Python), negative...
|
||||
void trickyvalue1(int first, int pos = -1) {}
|
||||
void trickyvalue2(int first, unsigned rgb = 0xabcdef) {}
|
||||
void trickyvalue3(int first, int mode = 0644) {}
|
||||
|
||||
class TrickyInPython {
|
||||
public:
|
||||
int value_m1(int first, int pos = -1) { return pos; }
|
||||
unsigned value_0xabcdef(int first, unsigned rgb = 0xabcdef) { return rgb; }
|
||||
int value_0644(int first, int mode = 0644) { return mode; }
|
||||
int value_perm(int first, int mode = 0640 | 0004) { return mode; }
|
||||
int value_m01(int first, int val = -01) { return val; }
|
||||
bool booltest2(bool x = 0 | 1) { return x; }
|
||||
int max_32bit_int1(int a = 0x7FFFFFFF) { return a; }
|
||||
int max_32bit_int2(int a = 2147483647) { return a; }
|
||||
int min_32bit_int1(int a = -0x80000000) { return a; }
|
||||
long long too_big_32bit_int1(long long a = 0x80000000) { return a; }
|
||||
long long too_big_32bit_int2(long long a = 2147483648LL) { return a; }
|
||||
long long too_small_32bit_int1(long long a = -0x80000001) { return a; }
|
||||
long long too_small_32bit_int2(long long a = -2147483649LL) { return a; }
|
||||
};
|
||||
|
||||
void doublevalue1(int first, double num = 0.0e-1) {}
|
||||
void doublevalue2(int first, double num = -0.0E2) {}
|
||||
|
||||
// Long long arguments are not handled at Python level currently but still work.
|
||||
void seek(long long offset = 0LL) {}
|
||||
void seek2(unsigned long long offset = 0ULL) {}
|
||||
void seek3(long offset = 0L) {}
|
||||
|
|
@ -152,6 +177,9 @@
|
|||
int double_if_handle_is_null(int n, MyHandle h = 0) { return h ? n : 2*n; }
|
||||
int double_if_dbl_ptr_is_null(int n, double* null_by_default)
|
||||
{ return null_by_default ? n : 2*n; }
|
||||
|
||||
void defaulted1(unsigned offset = -1U) {} // minus unsigned!
|
||||
void defaulted2(int offset = -1U) {} // minus unsigned!
|
||||
};
|
||||
int Foo::bar = 1;
|
||||
int Foo::spam = 2;
|
||||
|
|
@ -182,18 +210,18 @@
|
|||
|
||||
// Default parameters with exception specifications
|
||||
%inline %{
|
||||
void exceptionspec(int a = -1) throw (int, const char*) {
|
||||
void exceptionspec(int a = -1) TESTCASE_THROW2(int, const char*) {
|
||||
if (a == -1)
|
||||
throw "ciao";
|
||||
else
|
||||
throw a;
|
||||
}
|
||||
struct Except {
|
||||
Except(bool throwException, int a = -1) throw (int) {
|
||||
Except(bool throwException, int a = -1) TESTCASE_THROW1(int) {
|
||||
if (throwException)
|
||||
throw a;
|
||||
}
|
||||
void exspec(int a = 0) throw (int, const char*) {
|
||||
void exspec(int a = 0) TESTCASE_THROW2(int, const char*) {
|
||||
::exceptionspec(a);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
%module default_args_c
|
||||
|
||||
%{
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
// Suppress: use of logical '||' with constant operand
|
||||
#pragma clang diagnostic ignored "-Wconstant-logical-operand"
|
||||
#endif
|
||||
%}
|
||||
|
||||
/* Default arguments for C code */
|
||||
int foo1(int x = 42 || 3);
|
||||
int foo43(int x = 42 | 3);
|
||||
|
|
@ -12,3 +20,34 @@ int foo43(int x) {
|
|||
return x;
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct FooStruct {
|
||||
int num;
|
||||
};
|
||||
%}
|
||||
%extend FooStruct {
|
||||
void no_arg() {}
|
||||
void one_req(int *required) {}
|
||||
void one_opt(int *optional = NULL) {}
|
||||
void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct StaticStruct {
|
||||
int snum;
|
||||
};
|
||||
%}
|
||||
%extend StaticStruct {
|
||||
static void no_arg() {}
|
||||
static void one_req(int *required) {}
|
||||
static void one_opt(int *optional = NULL) {}
|
||||
static void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%{
|
||||
void global_opts1(int *optional) {}
|
||||
void global_opts2(int *required, int *optional) {}
|
||||
%}
|
||||
void global_opts1(int *optional = NULL) {}
|
||||
void global_opts2(int *required, int *optional = NULL) {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
%module derived_byvalue
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
struct Foo {
|
||||
|
|
|
|||
61
Examples/test-suite/destructor_methodmodifiers.i
Normal file
61
Examples/test-suite/destructor_methodmodifiers.i
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
%module destructor_methodmodifiers
|
||||
|
||||
// This test changes the proxy classes so that they cannot be inherited from in the target language
|
||||
// Previously the %csmethodmodifiers, %dmethodmodifiers, %javamethodmodifiers on destructors were ignored
|
||||
// Now they can control the dispose/Dispose/delete method modifiers
|
||||
|
||||
#if defined(SWIGCSHARP)
|
||||
|
||||
// remove all use of protected and virtual keywords
|
||||
%typemap(csclassmodifiers) NotForDeriving1, NotForDeriving2 "public sealed class"
|
||||
%csmethodmodifiers NotForDeriving1::~NotForDeriving1 "public /*not virtual nor override*/";
|
||||
%csmethodmodifiers NotForDeriving2::~NotForDeriving2 "public /*not virtual nor override*/";
|
||||
|
||||
// remove protected keyword to remove compiler warning
|
||||
%typemap(csbody) NotForDeriving1, NotForDeriving2 %{
|
||||
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
|
||||
private /*protected*/ bool swigCMemOwn;
|
||||
|
||||
internal $csclassname(global::System.IntPtr cPtr, bool cMemoryOwn) {
|
||||
swigCMemOwn = cMemoryOwn;
|
||||
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
|
||||
}
|
||||
|
||||
internal static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
|
||||
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
#elif defined(SWIGD)
|
||||
|
||||
%typemap(dclassmodifiers) NotForDeriving1, NotForDeriving2 "final class"
|
||||
%dmethodmodifiers NotForDeriving1::~NotForDeriving1 "public final";
|
||||
%dmethodmodifiers NotForDeriving2::~NotForDeriving2 "public final";
|
||||
|
||||
#elif defined(SWIGJAVA)
|
||||
|
||||
%typemap(javaclassmodifiers) NotForDeriving1, NotForDeriving2 "public final class"
|
||||
%javamethodmodifiers NotForDeriving1::~NotForDeriving1 "public synchronized final";
|
||||
%javamethodmodifiers NotForDeriving2::~NotForDeriving2 "public synchronized final";
|
||||
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
//#include <iostream>
|
||||
struct NotForDeriving1 {
|
||||
void notvirtual() {}
|
||||
~NotForDeriving1() {
|
||||
// std::cout << "~NotForDeriving1 called" << std::endl;
|
||||
}
|
||||
};
|
||||
struct NotForDeriving2 {
|
||||
void notvirtual() {}
|
||||
#if defined(SWIG)
|
||||
%extend {
|
||||
~NotForDeriving2() {
|
||||
// std::cout << "~NotForDeriving2 called" << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
%}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
%module(directors="1") director_basic
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod;
|
||||
|
||||
%{
|
||||
|
|
@ -65,6 +69,14 @@
|
|||
|
||||
%}
|
||||
|
||||
%typemap(cscode) MyClass %{
|
||||
public void testSwigDerivedClassHasMethod() {
|
||||
if (SwigDerivedClassHasMethod("nonVirtual", swigMethodTypes3))
|
||||
throw new global::System.Exception("non-overriding non-virtual method would be when connecting director");
|
||||
if (SwigDerivedClassHasMethod("nonOverride", swigMethodTypes4))
|
||||
throw new global::System.Exception("non-overriding virtual method would be when connecting director");
|
||||
}
|
||||
%}
|
||||
|
||||
%feature("director") MyClass;
|
||||
|
||||
|
|
@ -121,6 +133,29 @@ public:
|
|||
static Bar * call_pmethod(MyClass *myclass, Bar *b) {
|
||||
return myclass->pmethod(b);
|
||||
}
|
||||
|
||||
virtual int nonVirtual()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
virtual int nonOverride()
|
||||
{
|
||||
return 101;
|
||||
}
|
||||
|
||||
static int call_nonVirtual(MyClass *myclass)
|
||||
{
|
||||
return myclass->nonVirtual();
|
||||
}
|
||||
|
||||
static int call_nonOverride(MyClass *myclass)
|
||||
{
|
||||
return myclass->nonOverride();
|
||||
}
|
||||
|
||||
// Collisions with generated method names
|
||||
virtual void Connect() { }
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ref;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ptr;
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::ConstPtrRef;
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) val;
|
||||
#endif
|
||||
|
||||
%module(directors="1") director_classes
|
||||
|
||||
|
|
@ -43,6 +48,7 @@ public:
|
|||
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Base - Val(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Base - Ref(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Base - Ptr(" << x->val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Base - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
|
||||
|
||||
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(int " << x << ")" << std::endl; return "Base::FullyOverloaded(int)"; }
|
||||
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(bool " << x << ")" << std::endl; return "Base::FullyOverloaded(bool)"; }
|
||||
|
|
@ -68,6 +74,7 @@ public:
|
|||
virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Derived - Val(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Derived - Ref(" << x.val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Derived - Ptr(" << x->val << ")" << std::endl; return x; }
|
||||
virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Derived - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; }
|
||||
|
||||
virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(int " << x << ")" << std::endl; return "Derived::FullyOverloaded(int)"; }
|
||||
virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(bool " << x << ")" << std::endl; return "Derived::FullyOverloaded(bool)"; }
|
||||
|
|
@ -99,6 +106,7 @@ public:
|
|||
DoubleHolder ValCall(DoubleHolder x) { return m_base->Val(x); }
|
||||
DoubleHolder& RefCall(DoubleHolder& x) { return m_base->Ref(x); }
|
||||
DoubleHolder* PtrCall(DoubleHolder* x) { return m_base->Ptr(x); }
|
||||
DoubleHolder *const& ConstPtrRefCall(DoubleHolder *const& cprx) { return m_base->ConstPtrRef(cprx); }
|
||||
std::string FullyOverloadedCall(int x) { return m_base->FullyOverloaded(x); }
|
||||
std::string FullyOverloadedCall(bool x) { return m_base->FullyOverloaded(x); }
|
||||
std::string SemiOverloadedCall(int x) { return m_base->SemiOverloaded(x); }
|
||||
|
|
|
|||
|
|
@ -3,42 +3,47 @@
|
|||
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) return_const_char_star;
|
||||
|
||||
%{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
// define dummy director exception classes to prevent spurious errors
|
||||
// in target languages that do not support directors.
|
||||
|
||||
#ifndef SWIG_DIRECTORS
|
||||
namespace Swig {
|
||||
class DirectorException {};
|
||||
class DirectorMethodException: public Swig::DirectorException {};
|
||||
class DirectorException {};
|
||||
class DirectorMethodException: public Swig::DirectorException {};
|
||||
}
|
||||
#ifndef SWIG_fail
|
||||
#define SWIG_fail
|
||||
#endif
|
||||
#endif /* !SWIG_DIRECTORS */
|
||||
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
#ifdef SWIGPHP
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
if ($error == FAILURE) {
|
||||
Swig::DirectorMethodException::raise("$symname");
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
Swig::DirectorMethodException::raise("$symname");
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (Swig::DirectorException &) { SWIG_fail; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -56,12 +61,12 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
// Change back to old 2.0 default behavior
|
||||
|
||||
%feature("director:except") {
|
||||
jthrowable $error = jenv->ExceptionOccurred();
|
||||
if ($error) {
|
||||
// Dont clear exception, still be active when return to java execution
|
||||
// Essentially ignore exception occurred -- old behavior.
|
||||
return $null;
|
||||
}
|
||||
jthrowable $error = jenv->ExceptionOccurred();
|
||||
if ($error) {
|
||||
// Dont clear exception, still be active when return to java execution
|
||||
// Essentially ignore exception occurred -- old behavior.
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -69,7 +74,7 @@ class DirectorMethodException: public Swig::DirectorException {};
|
|||
#ifdef SWIGRUBY
|
||||
|
||||
%feature("director:except") {
|
||||
throw Swig::DirectorMethodException($error);
|
||||
Swig::DirectorMethodException::raise($error);
|
||||
}
|
||||
|
||||
%exception {
|
||||
|
|
@ -110,6 +115,18 @@ Foo *launder(Foo *f) {
|
|||
%feature("director") Bar;
|
||||
%feature("director") ReturnAllTypes;
|
||||
|
||||
%{
|
||||
// throw is deprecated in C++11 and invalid in C++17 and later
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
#define throw(TYPE1, TYPE2, TYPE3)
|
||||
#else
|
||||
#define throw(TYPE1, TYPE2, TYPE3) throw(TYPE1, TYPE2, TYPE3)
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct Exception1
|
||||
{
|
||||
|
|
@ -122,16 +139,15 @@ Foo *launder(Foo *f) {
|
|||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() throw () {}
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
|
||||
class Bar : public Base
|
||||
{
|
||||
public:
|
||||
virtual std::string ping() throw (Exception1, Exception2&) { return "Bar::ping()"; }
|
||||
virtual std::string pong() throw (Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); }
|
||||
virtual std::string pang() throw () { return "Bar::pang()"; }
|
||||
virtual std::string ping() throw(Exception1, Exception2&, double) { return "Bar::ping()"; }
|
||||
virtual std::string pong() throw(Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); }
|
||||
};
|
||||
|
||||
// Class to allow regression testing SWIG/PHP not checking if an exception
|
||||
|
|
|
|||
25
Examples/test-suite/director_exception_catches.i
Normal file
25
Examples/test-suite/director_exception_catches.i
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
%module(directors="1") director_exception_catches
|
||||
|
||||
%include <std_string.i>
|
||||
%feature("director") BaseClass;
|
||||
|
||||
%{
|
||||
// define dummy director exception classes to prevent spurious errors
|
||||
// in target languages that do not support directors.
|
||||
|
||||
#ifndef SWIG_DIRECTORS
|
||||
namespace Swig {
|
||||
class DirectorException {};
|
||||
}
|
||||
#endif /* !SWIG_DIRECTORS */
|
||||
%}
|
||||
|
||||
%catches(Swig::DirectorException) BaseClass::call_description;
|
||||
|
||||
%inline %{
|
||||
struct BaseClass {
|
||||
virtual std::string description() const = 0;
|
||||
static std::string call_description(BaseClass& bc) { return bc.description(); }
|
||||
virtual ~BaseClass() {}
|
||||
};
|
||||
%}
|
||||
28
Examples/test-suite/director_exception_nothrow.i
Normal file
28
Examples/test-suite/director_exception_nothrow.i
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
%module(directors="1") director_exception_nothrow
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") Bar;
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() throw() {}
|
||||
};
|
||||
|
||||
|
||||
class Bar : public Base
|
||||
{
|
||||
public:
|
||||
virtual std::string pang() throw() { return "Bar::pang()"; }
|
||||
};
|
||||
%}
|
||||
|
|
@ -25,7 +25,7 @@ namespace Swig {
|
|||
size_t ExceptionMethod()
|
||||
{
|
||||
// Check positioning of director code in wrapper file
|
||||
// Below is what we really want to test, but director exceptions vary too much across across all languages
|
||||
// Below is what we really want to test, but director exceptions vary too much across all languages
|
||||
// throw Swig::DirectorException("DirectorException was not in scope!!");
|
||||
// Instead check definition of Director class as that is defined in the same place as DirectorException (director.swg)
|
||||
size_t size = sizeof(Swig::Director);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
%module(directors="1") director_overload
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%feature("director");
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
|
|
|||
72
Examples/test-suite/director_ownership.i
Normal file
72
Examples/test-suite/director_ownership.i
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
%module(directors="1") director_ownership
|
||||
|
||||
// Github issue #1184
|
||||
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("director") example::ContentBase;
|
||||
%feature("director") example::ContentDerived;
|
||||
|
||||
%newobject example::make_content;
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
|
||||
namespace example
|
||||
{
|
||||
|
||||
class ContentBase
|
||||
{
|
||||
public:
|
||||
ContentBase() {}
|
||||
virtual ~ContentBase() {}
|
||||
virtual std::string get_name() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ContentDerived: public ContentBase
|
||||
{
|
||||
public:
|
||||
ContentDerived():ContentBase() { m_name = "ContentDerived"; }
|
||||
virtual ~ContentDerived() {}
|
||||
virtual std::string get_name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
Container() { m_content = 0; }
|
||||
~Container()
|
||||
{
|
||||
clear_content();
|
||||
}
|
||||
// the container takes the ownership of the content
|
||||
void set_content(ContentBase* content)
|
||||
{
|
||||
clear_content();
|
||||
m_content = content;
|
||||
}
|
||||
ContentBase* get_content() { return m_content; }
|
||||
|
||||
private:
|
||||
void clear_content()
|
||||
{
|
||||
if(m_content)
|
||||
{
|
||||
delete m_content;
|
||||
m_content = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ContentBase* m_content;
|
||||
};
|
||||
|
||||
static ContentBase* make_content() { return new ContentDerived(); }
|
||||
|
||||
} // namespace example
|
||||
%}
|
||||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) MyClass::pmethod;
|
||||
|
||||
#ifdef SWIGOCAML
|
||||
%warnfilter(SWIGWARN_PARSE_KEYWORD) method;
|
||||
#endif
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue