diff --git a/Examples/test-suite/java/template_default_arg_runme.java b/Examples/test-suite/java/template_default_arg_runme.java index 28326373a..7f59cc57e 100644 --- a/Examples/test-suite/java/template_default_arg_runme.java +++ b/Examples/test-suite/java/template_default_arg_runme.java @@ -59,6 +59,56 @@ public class template_default_arg_runme { y.meth(new Hello_int()); y.meth(); } + + { + Foo_Z_8 fz = new Foo_Z_8(); + X_Foo_Z_8 x = new X_Foo_Z_8(); + Foo_Z_8 fzc = x.meth(fz); + } + + // Templated functions + { + // plain function: int ott(Foo) + if (template_default_arg.ott(new Foo_int()) != 30) + throw new RuntimeException("ott test 1 failed"); + + // %template(ott) ott; + if (template_default_arg.ott() != 10) + throw new RuntimeException("ott test 2 failed"); + if (template_default_arg.ott(1) != 10) + throw new RuntimeException("ott test 3 failed"); + if (template_default_arg.ott(1, 1) != 10) + throw new RuntimeException("ott test 4 failed"); + + if (template_default_arg.ott("hi") != 20) + throw new RuntimeException("ott test 5 failed"); + if (template_default_arg.ott("hi", 1) != 20) + throw new RuntimeException("ott test 6 failed"); + if (template_default_arg.ott("hi", 1, 1) != 20) + throw new RuntimeException("ott test 7 failed"); + + // %template(ott) ott; + if (template_default_arg.ottstring(new Hello_int(), "hi") != 40) + throw new RuntimeException("ott test 8 failed"); + + if (template_default_arg.ottstring(new Hello_int()) != 40) + throw new RuntimeException("ott test 9 failed"); + + // %template(ott) ott; + if (template_default_arg.ottint(new Hello_int(), 1) != 50) + throw new RuntimeException("ott test 10 failed"); + + if (template_default_arg.ottint(new Hello_int()) != 50) + throw new RuntimeException("ott test 11 failed"); + + // %template(ott) ott; + if (template_default_arg.ott(new Hello_int(), 1.0) != 60) + throw new RuntimeException("ott test 12 failed"); + + if (template_default_arg.ott(new Hello_int()) != 60) + throw new RuntimeException("ott test 13 failed"); + + } } } diff --git a/Examples/test-suite/perl5/template_default_arg_runme.pl b/Examples/test-suite/perl5/template_default_arg_runme.pl new file mode 100644 index 000000000..528e35e88 --- /dev/null +++ b/Examples/test-suite/perl5/template_default_arg_runme.pl @@ -0,0 +1,115 @@ +use template_default_arg; + +{ + $helloInt = new template_default_arg::Hello_int(); + $helloInt->foo(0); +} +{ + $x = new template_default_arg::X_int(); + if ($x->meth(20.0, 200) != 200) { + die "X_int test 1 failed"; + } + if ($x->meth(20) != 20) { + die "X_int test 2 failed"; + } + if ($x->meth() != 0) { + die "X_int test 3 failed"; + } +} + +{ + $y = new template_default_arg::Y_unsigned(); + if ($y->meth(20.0, 200) != 200) { + die "Y_unsigned test 1 failed"; + } + if ($y->meth(20) != 20) { + die "Y_unsigned test 2 failed"; + } + if ($y->meth() != 0) { + die "Y_unsigned test 3 failed"; + } +} + +{ + $x = new template_default_arg::X_longlong(); + $x = new template_default_arg::X_longlong(20.0); + $x = new template_default_arg::X_longlong(20.0, 200); +} +{ + $x = new template_default_arg::X_int(); + $x = new template_default_arg::X_int(20.0); + $x = new template_default_arg::X_int(20.0, 200); +} +{ + $x = new template_default_arg::X_hello_unsigned(); + $x = new template_default_arg::X_hello_unsigned(20.0); + $x = new template_default_arg::X_hello_unsigned(20.0, new template_default_arg::Hello_int()); +} +{ + $y = new template_default_arg::Y_hello_unsigned(); + $y->meth(20.0, new template_default_arg::Hello_int()); + $y->meth(new template_default_arg::Hello_int()); + $y->meth(); +} + +{ + $fz = new template_default_arg::Foo_Z_8(); + $x = new template_default_arg::X_Foo_Z_8(); + $fzc = $x->meth($fz); +} + +# Templated functions +{ + # plain function: int ott(Foo) + if (template_default_arg::ott(new template_default_arg::Foo_int()) != 30) { + die "ott test 1 failed"; + } + + # %template(ott) ott; + if (template_default_arg::ott() != 10) { + die "ott test 2 failed"; + } + if (template_default_arg::ott(1) != 10) { + die "ott test 3 failed"; + } + if (template_default_arg::ott(1, 1) != 10) { + die "ott test 4 failed"; + } + + if (template_default_arg::ott("hi") != 20) { + die "ott test 5 failed"; + } + if (template_default_arg::ott("hi", 1) != 20) { + die "ott test 6 failed"; + } + if (template_default_arg::ott("hi", 1, 1) != 20) { + die "ott test 7 failed"; + } + + # %template(ott) ott; + if (template_default_arg::ottstring(new template_default_arg::Hello_int(), "hi") != 40) { + die "ott test 8 failed"; + } + + if (template_default_arg::ottstring(new template_default_arg::Hello_int()) != 40) { + die "ott test 9 failed"; + } + + # %template(ott) ott; + if (template_default_arg::ottint(new template_default_arg::Hello_int(), 1) != 50) { + die "ott test 10 failed"; + } + + if (template_default_arg::ottint(new template_default_arg::Hello_int()) != 50) { + die "ott test 11 failed"; + } + + # %template(ott) ott; + if (template_default_arg::ott(new template_default_arg::Hello_int(), 1.0) != 60) { + die "ott test 12 failed"; + } + + if (template_default_arg::ott(new template_default_arg::Hello_int()) != 60) { + die "ott test 13 failed"; + } +} diff --git a/Examples/test-suite/template_default_arg.i b/Examples/test-suite/template_default_arg.i index aa4fbc733..73e014f41 100644 --- a/Examples/test-suite/template_default_arg.i +++ b/Examples/test-suite/template_default_arg.i @@ -77,4 +77,21 @@ %} +// Templated functions +%inline %{ + // Templated methods which are overloaded and have default args, and %template which + // uses the same name as the C++ functions and overload on the template parameters and + // specialization thrown in too. Wow, SWIG can handle this insane stuff! + template int ott(T t = 0, const U& u = U()) { return 10; } + template int ott(const char *msg, T t = 0, const U& u = U()) { return 20; } + int ott(Foo) { return 30; } + template int ott(Hello h, T t = 0) { return 40; } + template<> int ott(Hello h, int t) { return 50; } + template<> int ott(Hello h, double t) { return 60; } +%} + +%template(ott) ott; +%template(ott) ott; +%template(ottint) ott; // default arg requires a rename +%template(ottstring) ott; // default arg requires a rename