tests for default arguments in templated functions added

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6403 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2004-10-16 21:03:08 +00:00
commit 647ec0d634
3 changed files with 182 additions and 0 deletions

View file

@ -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<int>)
if (template_default_arg.ott(new Foo_int()) != 30)
throw new RuntimeException("ott test 1 failed");
// %template(ott) ott<int, int>;
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<const char *>;
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<int>;
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<double>;
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");
}
}
}

View file

@ -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<int>)
if (template_default_arg::ott(new template_default_arg::Foo_int()) != 30) {
die "ott test 1 failed";
}
# %template(ott) ott<int, int>;
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<const char *>;
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<int>;
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<double>;
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";
}
}

View file

@ -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<typename T, typename U> int ott(T t = 0, const U& u = U()) { return 10; }
template<typename T, typename U> int ott(const char *msg, T t = 0, const U& u = U()) { return 20; }
int ott(Foo<int>) { return 30; }
template<typename T> int ott(Hello<int> h, T t = 0) { return 40; }
template<> int ott<int>(Hello<int> h, int t) { return 50; }
template<> int ott(Hello<int> h, double t) { return 60; }
%}
%template(ott) ott<int, int>;
%template(ott) ott<double>;
%template(ottint) ott<int>; // default arg requires a rename
%template(ottstring) ott<const char *>; // default arg requires a rename