diff options
Diffstat (limited to 'Examples/test-suite')
20 files changed, 340 insertions, 102 deletions
diff --git a/Examples/test-suite/argcargvtest.i b/Examples/test-suite/argcargvtest.i index 5711441d9..e14e370d8 100644 --- a/Examples/test-suite/argcargvtest.i +++ b/Examples/test-suite/argcargvtest.i @@ -1,6 +1,6 @@ %module argcargvtest -#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) +#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCAML) && !defined(SWIGR) && !defined(SWIGSCILAB) %include <argcargv.i> %apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) } diff --git a/Examples/test-suite/arrays.i b/Examples/test-suite/arrays.i index 07162aa90..f98dd0718 100644 --- a/Examples/test-suite/arrays.i +++ b/Examples/test-suite/arrays.i @@ -73,4 +73,8 @@ typedef struct { cartPosition_t p; } CartPoseData_t; +/* Test left shift in array size doesn't trigger "Bad template type" error. + * Regression test for https://sourceforge.net/p/swig/bugs/983/ */ +char array_shifted_size[(1<<2)]; + %} diff --git a/Examples/test-suite/go/argcargvtest_runme.go b/Examples/test-suite/go/argcargvtest_runme.go new file mode 100644 index 000000000..3da3d76dd --- /dev/null +++ b/Examples/test-suite/go/argcargvtest_runme.go @@ -0,0 +1,22 @@ +package main + +import wrap "swigtests/argcargvtest" + +func main() { + largs := []string{"hi", "hola", "hello"} + if ri := wrap.Mainc(largs); ri != 3 { + panic(ri) + } + + targs := []string{"hi", "hola"} + if rs := wrap.Mainv(targs, 1); rs != "hola" { + panic(rs) + } + +// For dynamically typed languages we test this throws an exception or similar +// at runtime, but for Go this doesn't even compile (but we can't easily +// test for that here). +// wrap.Mainv("hello", 1) + + wrap.InitializeApp(largs) +} diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 4835453cc..b2acbd8f2 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -25,9 +25,22 @@ SWIGEXE = $(top_builddir)/swig SWIG_LIB_DIR = $(top_srcdir)/Lib ifneq (, $(ENGINE)) - JSENGINE=$(ENGINE) + JSENGINE=$(ENGINE) else - JSENGINE=node +ifneq (, $(NODEJS)) + JSENGINE=node +else +ifneq (, @JSCENABLED@) + JSENGINE=jsc +else +ifneq (, @JSV8ENABLED@) + JSENGINE=v8 +else + # Shouldn't happen, but avoid empty value if it does. + JSENGINE=node +endif +endif +endif endif ifneq (, $(V8_VERSION)) @@ -47,9 +60,9 @@ _setup = \ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $*" ; \ fi; -ifeq (node,$(JSENGINE)) +SWIGOPT += -$(JSENGINE) - SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1 +ifeq (node,$(JSENGINE)) # shut up some warnings @@ -105,8 +118,6 @@ ifeq (node,$(JSENGINE)) else - SWIGOPT += -$(JSENGINE) - run_testcase = \ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ $(RUNTOOL) $(top_builddir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \ diff --git a/Examples/test-suite/javascript/ignore_parameter_runme.js b/Examples/test-suite/javascript/ignore_parameter_runme.js new file mode 100644 index 000000000..07dcf2f7d --- /dev/null +++ b/Examples/test-suite/javascript/ignore_parameter_runme.js @@ -0,0 +1,24 @@ +const ignore_parameter = require('ignore_parameter'); + +function check(a, b) { + if (a !== b) throw new Error(`'${a}' != '${b}`); +} + +check(ignore_parameter.jaguar(200, 0), "hello"); +check(ignore_parameter.lotus("foo", 1), 101); +check(ignore_parameter.tvr("bar", 2), 8.8); +check(ignore_parameter.ferrari(), 101); +check(ignore_parameter.fiat(17), 17); + +car = new ignore_parameter.SportsCars(); +check(car.daimler(200, 0), "hello"); +check(car.astonmartin("foo", 1), 101); +check(car.bugatti("bar", 2), 8.8); +check(car.lamborghini(), 101); +check(car.maseratti(289), 289); +check(car.audi(), 8.8); + +new ignore_parameter.MiniCooper(200, 0); +new ignore_parameter.MorrisMinor("baz", 0); +new ignore_parameter.FordAnglia("quux", 200); +new ignore_parameter.AustinAllegro(); diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 47a9090b7..6f8fec130 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -1,9 +1,10 @@ %module li_std_string %include <std_string.i> -#if defined(SWIGUTL) +#if defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGUTL) %apply std::string& INPUT { std::string &input } %apply std::string& INOUT { std::string &inout } +%apply std::string& OUTPUT { std::string &output } #endif // throw is invalid in C++17 and later, only SWIG to use it @@ -53,13 +54,28 @@ std::string& test_reference_out() { } std::string test_reference_input(std::string &input) { - return input; + // For PHP to allow checking that we haven't used the default string& + // typemap which wraps as a PHP pass-by-reference string parameter. + std::string copy = input; + input = "MODIFIED"; + return copy; } void test_reference_inout(std::string &inout) { inout += inout; } +void test_reference_output(std::string &output) { + output = "output"; +} + +#ifdef SWIGPHP +// Test PHP-specific default wrapping string& as pass-by-ref PHP string. +void test_reference_php(std::string &s) { + s += ".php"; +} +#endif + void test_throw() TESTCASE_THROW1(std::string){ static std::string x = "test_throw message"; throw x; diff --git a/Examples/test-suite/lua/li_std_string_runme.lua b/Examples/test-suite/lua/li_std_string_runme.lua index 40de81e44..4e6dbe7f1 100644 --- a/Examples/test-suite/lua/li_std_string_runme.lua +++ b/Examples/test-suite/lua/li_std_string_runme.lua @@ -44,6 +44,12 @@ test_reference(robj) test_reference(obj) -- object ptr is ok test_reference(cobj) -- obj const ptr is also ok +-- Test INPUT, INOUT and OUTPUT string& typemaps: +assert(test_reference_input("hello")=="hello") +s=test_reference_inout("hello") +assert(s=="hellohello") +assert(test_reference_output()=="output") + -- throwing string ok,ex=pcall(test_throw) assert(ok==false and type(ex)=="string") -- failed & threw string diff --git a/Examples/test-suite/ocaml/extend_template_method_runme.ml b/Examples/test-suite/ocaml/extend_template_method_runme.ml new file mode 100644 index 000000000..5f418c927 --- /dev/null +++ b/Examples/test-suite/ocaml/extend_template_method_runme.ml @@ -0,0 +1,20 @@ +open Swig +open Extend_template_method + +let _ = + let em = new_ExtendMe '() in + assert (em -> do_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_overloaded_stuff ("hello there") as string = "hello there"); + + assert (_ExtendMe_static_method '(123) as int = 123); + ignore (new_ExtendMe '(123)); + let em = new_TemplateExtend '() in + assert (em -> do_template_stuff_double (1, 1.1) as float = 1.1); + assert (em -> do_template_stuff_string (1, "hello there") as string = "hello there"); + assert (em -> do_template_overloaded_stuff (1.1) as float = 1.1); + assert (em -> do_template_overloaded_stuff ("hello there") as string = "hello there"); + assert (_TemplateExtend_static_template_method '(123) as int = 123); + ignore (new_TemplateExtend '(123)) +;; diff --git a/Examples/test-suite/ocaml/li_std_string_runme.ml b/Examples/test-suite/ocaml/li_std_string_runme.ml new file mode 100644 index 000000000..5f8c98a6b --- /dev/null +++ b/Examples/test-suite/ocaml/li_std_string_runme.ml @@ -0,0 +1,44 @@ +open Swig +open Li_std_string + +let _ = + assert (_test_value '("Fee") as string = "Fee"); + try + ignore (_test_value '(None)); assert false + with Invalid_argument _ -> () + + assert (_test_const_reference '("Fee") as string = "Fee"); + try + ignore (_test_const_reference '(None)); assert false + with Invalid_argument _ -> () + + let stringPtr = _test_pointer_out '() in + ignore (_test_pointer '(stringPtr)); + let stringPtr = _test_const_pointer_out '() in + ignore (_test_const_pointer '(stringPtr)); + let stringPtr = _test_reference_out '() in + ignore (_test_reference '(stringPtr)); + + try + ignore (_test_throw '()); assert false + with Failure s -> assert (s = "test_throw message") + try + ignore (_test_const_reference_throw '()); assert false + with Failure s -> assert (s = "test_const_reference_throw message") + assert (_GlobalString2 '() as string = "global string 2"); + let s = C_string "initial string" in + ignore (_GlobalString2 '(s)); + assert (_GlobalString2 '() = s); + assert (_ConstGlobalString '() as string = "const global string"); + + let myStructure = new_Structure '() in + assert (myStructure -> "[MemberString2]" () as string = "member string 2"); + assert (myStructure -> "[MemberString2]" (s) = C_void); + assert (myStructure -> "[MemberString2]" () = s); + assert (myStructure -> "[ConstMemberString]" () as string = "const member string"); + + assert (_Structure_StaticMemberString2 '() as string = "static member string 2"); + ignore (_Structure_StaticMemberString2 '(s)); + assert (_Structure_StaticMemberString2 '() = s); + assert (_Structure_ConstStaticMemberString '() as string = "const static member string") +;; diff --git a/Examples/test-suite/ocaml/template_methods_runme.ml b/Examples/test-suite/ocaml/template_methods_runme.ml new file mode 100644 index 000000000..aaa5a3416 --- /dev/null +++ b/Examples/test-suite/ocaml/template_methods_runme.ml @@ -0,0 +1,25 @@ +open Swig +open Template_methods + +let _ = + let num = C_float 1. in + assert (_convolve1Bool '() as int = 0); + assert (_convolve1Bool '(true) = C_void); + assert (_convolve2Float '() as int = 0); + assert (_convolve3FloatRenamed '(num) = C_void); + assert (_convolve4Float '() as int = 0); + assert (_convolve4FloatRenamed '(num) = C_void); + assert (_convolve5FloatRenamed '() as int = 0); + assert (_convolve5FloatRenamed '(num) = C_void); + + let k = new_Klass '() in + assert (k -> KlassTMethodBoolRenamed (true) as bool = true); + assert (k -> KlassTMethodBool () = C_void); + assert (_Klass_KlassStaticTMethodBoolRenamed '(true) as bool = true); + assert (_Klass_KlassStaticTMethodBool '() = C_void); + + let cp = new_ComponentProperties '() in + assert (cp -> adda ("key1", "val1", "key2", 22.2) = C_void); + assert (cp -> adda ("key1", "val1", "key2", "val2", "key3", "val3") = C_void); + assert (cp -> adda ("key1", 1, "key2", 2, "key3", 3) = C_void) +;; diff --git a/Examples/test-suite/perl5/li_std_string_runme.pl b/Examples/test-suite/perl5/li_std_string_runme.pl index e6358ff1f..3c3f9d5b4 100644 --- a/Examples/test-suite/perl5/li_std_string_runme.pl +++ b/Examples/test-suite/perl5/li_std_string_runme.pl @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 30; +use Test::More tests => 31; BEGIN { use_ok('li_std_string') } require_ok('li_std_string'); @@ -77,6 +77,7 @@ is(li_std_string::test_reference_input("hello"), "hello", "reference_input"); is(li_std_string::test_reference_inout("hello"), "hellohello", "reference_inout"); +is(li_std_string::test_reference_output(), "output", "reference_output"); no strict; my $gen1 = new li_std_string::Foo(); diff --git a/Examples/test-suite/php/arrays_runme.php b/Examples/test-suite/php/arrays_runme.php index eb06fbfd8..1d9e44d76 100644 --- a/Examples/test-suite/php/arrays_runme.php +++ b/Examples/test-suite/php/arrays_runme.php @@ -4,7 +4,7 @@ require "tests.php"; check::functions(array('fn_taking_arrays','newintpointer','setintfrompointer','getintfrompointer','array_pointer_func')); check::classes(array('arrays','SimpleStruct','ArrayStruct','CartPoseData_t')); -check::globals(array()); +check::globals(array('array_shifted_size')); $ss=new simplestruct(); check::classname('simplestruct',$ss); diff --git a/Examples/test-suite/php/catches_strings_runme.php b/Examples/test-suite/php/catches_strings_runme.php index f727ea26a..758c3f618 100644 --- a/Examples/test-suite/php/catches_strings_runme.php +++ b/Examples/test-suite/php/catches_strings_runme.php @@ -6,7 +6,7 @@ $exception_thrown = false; try { StringsThrower::charstring(); } catch (Exception $e) { - check::str_contains($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}"); + check::equal($e->getMessage(), "charstring message", "incorrect exception message: {$e->getMessage()}"); $exception_thrown = true; } check::equal($exception_thrown, true, "Should have thrown an exception"); @@ -15,7 +15,7 @@ $exception_thrown = false; try { StringsThrower::stdstring(); } catch (Exception $e) { - check::str_contains($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}"); + check::equal($e->getMessage(), "stdstring message", "incorrect exception message: {$e->getMessage()}"); $exception_thrown = true; } check::equal($exception_thrown, true, "Should have thrown an exception"); diff --git a/Examples/test-suite/php/default_args_runme.php b/Examples/test-suite/php/default_args_runme.php index 59350644f..cf4932209 100644 --- a/Examples/test-suite/php/default_args_runme.php +++ b/Examples/test-suite/php/default_args_runme.php @@ -42,19 +42,6 @@ check::equal($f->double_if_void_ptr_is_null(6, Null), 12, "\$f->double_if_void_p check::equal($f->double_if_void_ptr_is_null(7), 14, "\$f->double_if_void_ptr_is_null(7)"); -# For the testcases below, PHP 7 emits an error, while PHP 8 throws an -# exception. To simplify the testcases we install an error handler function -# for PHP7 which throws an ArgumentCountError exception (which we have to -# define ourselves for PHP 7.0). - -if (PHP_MAJOR_VERSION == 7) { - if (PHP_MINOR_VERSION == 0) { - # ArgumentCountError was added in PHP 7.1. - class ArgumentCountError extends Error {} - } - $old_error_handler = set_error_handler(function($n,$s,$f,$l){throw preg_match('/^Wrong parameter count/', $s) ? new ArgumentCountError($s) : new Error($s);}); -} - try { $f = new Foo(1); check::fail("Foo::Foo ignore is not working"); @@ -91,10 +78,6 @@ try { } catch (Error $e) { } -if (PHP_MAJOR_VERSION == 7) { - set_error_handler($old_error_handler); -} - check::equal(Klass::inc(100, new Klass(22))->val, 122, "Klass::inc failed"); check::equal(klass::inc(100)->val, 99, "klass::inc failed"); @@ -143,19 +126,17 @@ check::equal(chartest5(), "B", "chartest5()"); check::equal(chartest6(), "C", "chartest6()"); -if (PHP_MAJOR_VERSION >= 8) { - // Regression test for bug in initial implementation of PHP type declarations. - $p = (new ReflectionMethod('TrickyInPython', 'value_m1'))->getParameters(); - // empty array in buggy version - check::equal(count($p), 2, "Expected 2 parameters"); - check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); - check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); - - $p = (new ReflectionMethod('EnumClass', 'blah'))->getParameters(); - // empty array in buggy version - check::equal(count($p), 2, "Expected 2 parameters"); - check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); - check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); -} +// Regression test for bug in initial implementation of PHP type declarations. +$p = (new ReflectionMethod('TrickyInPython', 'value_m1'))->getParameters(); +// empty array in buggy version +check::equal(count($p), 2, "Expected 2 parameters"); +check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); +check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); + +$p = (new ReflectionMethod('EnumClass', 'blah'))->getParameters(); +// empty array in buggy version +check::equal(count($p), 2, "Expected 2 parameters"); +check::equal((string)$p[0]->getType(), 'int', "Expected int parameter"); +check::equal((string)$p[1]->getType(), 'int', "Expected int parameter"); check::done(); diff --git a/Examples/test-suite/php/director_classes_runme.php b/Examples/test-suite/php/director_classes_runme.php index d187ed82e..170e10f26 100644 --- a/Examples/test-suite/php/director_classes_runme.php +++ b/Examples/test-suite/php/director_classes_runme.php @@ -8,65 +8,30 @@ check::classes(array('director_classes', 'Base', 'BaseClass', 'Caller', 'Derived // New vars check::globals(array('PrintDebug')); -if (PHP_MAJOR_VERSION < 8) { - // Without type declarations since we don't generate them for PHP < 8 - // and we need to be compatible with method declarations in Base. - class PHPDerived extends Base { - function Val($x) { return $x; } - function Ref($x) { return $x; } - function Ptr($x) { return $x; } - function ConstPtrRef($x) { return $x; } - function FullyOverloaded($x) { - $rv = parent::FullyOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function SemiOverloaded($x) { - # this is going to be awkward because we can't really - # semi-overload in PHP, but we can sort of fake it. - if (!is_int($x)) { - return parent::SemiOverloaded($x); - } - $rv = parent::SemiOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function DefaultParms($x, $y = 1.1) { - $rv = parent::DefaultParms($x, $y); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } +class PHPDerived extends Base { + function Val(DoubleHolder $x) { return $x; } + function Ref(DoubleHolder $x) { return $x; } + function Ptr(?DoubleHolder $x) { return $x; } + function ConstPtrRef(?DoubleHolder $x) { return $x; } + function FullyOverloaded($x) { + $rv = parent::FullyOverloaded($x); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; } -} else { - class PHPDerived extends Base { - function Val(DoubleHolder $x) { return $x; } - function Ref(DoubleHolder $x) { return $x; } - // PHP 7.0 fails to parse the `?` - revert once we drop 7.0 support: - // function Ptr(?DoubleHolder $x) { return $x; } - function Ptr($x) { return $x; } - // PHP 7.0 fails to parse the `?` - revert once we drop 7.0 support: - // function ConstPtrRef(?DoubleHolder $x) { return $x; } - function ConstPtrRef($x) { return $x; } - function FullyOverloaded($x) { - $rv = parent::FullyOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function SemiOverloaded($x) { - # this is going to be awkward because we can't really - # semi-overload in PHP, but we can sort of fake it. - if (!is_int($x)) { - return parent::SemiOverloaded($x); - } - $rv = parent::SemiOverloaded($x); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; - } - function DefaultParms(int $x, float $y = 1.1) { - $rv = parent::DefaultParms($x, $y); - $rv = preg_replace('/Base/', 'PHPDerived', $rv); - return $rv; + function SemiOverloaded($x) { + # this is going to be awkward because we can't really + # semi-overload in PHP, but we can sort of fake it. + if (!is_int($x)) { + return parent::SemiOverloaded($x); } + $rv = parent::SemiOverloaded($x); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; + } + function DefaultParms(int $x, float $y = 1.1) { + $rv = parent::DefaultParms($x, $y); + $rv = preg_replace('/Base/', 'PHPDerived', $rv); + return $rv; } } diff --git a/Examples/test-suite/php/director_thread_runme.php b/Examples/test-suite/php/director_thread_runme.php index 190dbad71..e4eb3684a 100644 --- a/Examples/test-suite/php/director_thread_runme.php +++ b/Examples/test-suite/php/director_thread_runme.php @@ -3,7 +3,7 @@ require "tests.php"; # Fails in a ZTS-build of PHP5 - see: https://github.com/swig/swig/pull/155 -# FIXME: Does this still fail in a threaded build of PHP7? +# FIXME: Does this still fail in a threaded build of PHP8? exit(0); // New functions diff --git a/Examples/test-suite/php/li_std_string_runme.php b/Examples/test-suite/php/li_std_string_runme.php index 680b7ce98..390b7e17b 100644 --- a/Examples/test-suite/php/li_std_string_runme.php +++ b/Examples/test-suite/php/li_std_string_runme.php @@ -49,6 +49,50 @@ Structure::StaticMemberString2($s); check::equal(Structure::StaticMemberString2(), $s, "StaticMemberString2 test 2"); check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test"); +// Test INPUT, INOUT and OUTPUT string& typemaps: +$input = "hello"; +check::equal(li_std_string::test_reference_input($input), "hello"); +// $input should be unchanged - this check is to catch if we incorrectly used +// the default string& typemap: +check::equal($input, "hello"); +$s = li_std_string::test_reference_inout($input); +check::equal($s, "hellohello"); +// $input should be unchanged - this check is to catch if we incorrectly used +// the default string& typemap: +check::equal($input, "hello"); +check::equal(li_std_string::test_reference_output(), "output"); + +// Test default PHP wrapping of std::string& as a by-ref PHP string parameter: +$s = "byref"; +check::equal(li_std_string::test_reference_php($s), null); +check::equal($s, "byref.php"); + +// Test throwing strings: +try { + test_throw(); + check::fail("test_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "test_throw message"); +} +try { + test_const_reference_throw(); + check::fail("test_const_reference_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "test_const_reference_throw message"); +} +try { + test_pointer_throw(); + check::fail("test_pointer_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "foo"); +} +try { + test_const_pointer_throw(); + check::fail("test_const_pointer_throw() didn't throw"); +} catch (Exception $s) { + check::equal($s->getMessage(), "foo"); +} + // This used to give "Undefined variable: r" li_std_string::test_const_reference_returning_void("foo"); diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i index 5ebf0a099..f000446c4 100644 --- a/Examples/test-suite/preproc_defined.i +++ b/Examples/test-suite/preproc_defined.i @@ -123,3 +123,66 @@ void another_macro_checking(void) { #if 0 # wobble wobble #endif + +/* Regression test for https://sourceforge.net/p/swig/bugs/1163/ + * ONE(1)(2) should expand to `2` but SWIG was expanding it to `TWO(2)` + * which results in the generated C wrapper failing to compile. + */ +#define ONE(X) TWO +#define TWO(X) X +%constant int a = ONE(1)(2); +#define XXX TWO +%constant int b = XXX(42); +#undef ONE +#undef TWO + +/* + * The behaviour of Self-Referential Macros is defined + * https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Self-Referential-Macros.html + */ +%inline %{ +const int y = 0; +%} + +#define x (4 + y) +#define y (2 * x) + +%constant int z = y; + +#undef y +#undef x + +/* Regression test for #ifdef and #ifndef not working inside a %define. + * https://github.com/swig/swig/issues/2183 + */ +#undef THISMACROISNOTDEFINED /* Make sure! */ +#define THISMACROISDEFINED + +%define %test() + +#ifdef THISMACROISNOTDEFINED +# error #ifdef inside percent-define failed +#endif +#ifndef THISMACROISDEFINED +# error #ifndef inside percent-define failed +#endif +/* Check pre-defined macro too. */ +#ifndef SWIG +# error #ifndef inside percent-define failed +#endif + +/* These cases already worked, but should still have test coverage. */ +#if defined THISMACROISNOTDEFINED +# error #if defined inside percent-define failed +#endif +#if !defined THISMACROISDEFINED +# error #if !defined inside percent-define failed +#endif +/* Check pre-defined macro too. */ +#if !defined SWIG +# error #if !defined inside percent-define failed +#endif + +%enddef + +%test() diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py index af46816be..37441db52 100644 --- a/Examples/test-suite/python/preproc_defined_runme.py +++ b/Examples/test-suite/python/preproc_defined_runme.py @@ -9,3 +9,12 @@ d.defined = 10 preproc_defined.thing(10) preproc_defined.stuff(10) preproc_defined.bumpf(10) + +if preproc_defined.a != 2: + raise RuntimeError + +if preproc_defined.b != 42: + raise RuntimeError + +if preproc_defined.z != 8: + raise RuntimeError diff --git a/Examples/test-suite/ruby/li_std_string_runme.rb b/Examples/test-suite/ruby/li_std_string_runme.rb index dc85b5dab..c964808fa 100644 --- a/Examples/test-suite/ruby/li_std_string_runme.rb +++ b/Examples/test-suite/ruby/li_std_string_runme.rb @@ -122,6 +122,9 @@ s = test_reference_inout("hello") if (s != "hellohello") raise RuntimeError end +if (test_reference_output() != "output") + raise RuntimeError +end if (stdstring_empty() != "") |