default args and overloading runtime tests added
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6559 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3ced17bd35
commit
9a3953578a
2 changed files with 285 additions and 0 deletions
134
Examples/test-suite/csharp/default_args_runme.cs
Normal file
134
Examples/test-suite/csharp/default_args_runme.cs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
using System;
|
||||
using default_argsNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
if (default_args.anonymous() != 7771)
|
||||
throw new Exception("anonymous (1) failed");
|
||||
if (default_args.anonymous(1234) != 1234)
|
||||
throw new Exception("anonymous (2) failed");
|
||||
|
||||
if (default_args.booltest() != true)
|
||||
throw new Exception("booltest (1) failed");
|
||||
if (default_args.booltest(true) != true)
|
||||
throw new Exception("booltest (2) failed");
|
||||
if (default_args.booltest(false) != false)
|
||||
throw new Exception("booltest (3) failed");
|
||||
|
||||
EnumClass ec = new EnumClass();
|
||||
if (ec.blah() != true)
|
||||
throw new Exception("EnumClass failed");
|
||||
|
||||
if (default_args.casts1() != null)
|
||||
throw new Exception("casts1 failed");
|
||||
|
||||
if (default_args.casts2() != "Hello")
|
||||
throw new Exception("casts2 failed");
|
||||
|
||||
if (default_args.casts1("Ciao") != "Ciao")
|
||||
throw new Exception("casts1 not default failed");
|
||||
|
||||
if (default_args.chartest1() != 'x')
|
||||
throw new Exception("chartest1 failed");
|
||||
|
||||
if (default_args.chartest2() != '\0')
|
||||
throw new Exception("chartest2 failed");
|
||||
|
||||
if (default_args.chartest1('y') != 'y')
|
||||
throw new Exception("chartest1 not default failed");
|
||||
|
||||
if (default_args.chartest1('y') != 'y')
|
||||
throw new Exception("chartest1 not default failed");
|
||||
|
||||
if (default_args.reftest1() != 42)
|
||||
throw new Exception("reftest1 failed");
|
||||
|
||||
if (default_args.reftest1(400) != 400)
|
||||
throw new Exception("reftest1 not default failed");
|
||||
|
||||
if (default_args.reftest2() != "hello")
|
||||
throw new Exception("reftest2 failed");
|
||||
|
||||
// rename
|
||||
Foo foo = new Foo();
|
||||
foo.newname();
|
||||
foo.newname(10);
|
||||
|
||||
// exception specifications
|
||||
try {
|
||||
default_args.exceptionspec();
|
||||
throw new Exception("exceptionspec 1 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
default_args.exceptionspec(-1);
|
||||
throw new Exception("exceptionspec 2 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
default_args.exceptionspec(100);
|
||||
throw new Exception("exceptionspec 3 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
Except ex = new Except(false);
|
||||
try {
|
||||
ex.exspec();
|
||||
throw new Exception("exspec 1 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
ex.exspec(-1);
|
||||
throw new Exception("exspec 2 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
ex.exspec(100);
|
||||
throw new Exception("exspec 3 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
ex = new Except(true);
|
||||
throw new Exception("Except constructor 1 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
ex = new Except(true, -2);
|
||||
throw new Exception("Except constructor 2 failed");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// Default parameters in static class methods
|
||||
if (Statics.staticmethod() != 10+20+30)
|
||||
throw new Exception("staticmethod 1 failed");
|
||||
if (Statics.staticmethod(100) != 100+20+30)
|
||||
throw new Exception("staticmethod 2 failed");
|
||||
if (Statics.staticmethod(100,200,300) != 100+200+300)
|
||||
throw new Exception("staticmethod 3 failed");
|
||||
|
||||
|
||||
Tricky tricky = new Tricky();
|
||||
if (tricky.privatedefault() != 200)
|
||||
throw new Exception("privatedefault failed");
|
||||
if (tricky.protectedint() != 2000)
|
||||
throw new Exception("protectedint failed");
|
||||
if (tricky.protecteddouble() != 987.654)
|
||||
throw new Exception("protecteddouble failed");
|
||||
if (tricky.functiondefault() != 500)
|
||||
throw new Exception("functiondefault failed");
|
||||
if (tricky.contrived() != 'X')
|
||||
throw new Exception("contrived failed");
|
||||
|
||||
if (default_args.constructorcall().val != -1)
|
||||
throw new Exception("constructorcall test 1 failed");
|
||||
|
||||
if (default_args.constructorcall(new Klass(2222)).val != 2222)
|
||||
throw new Exception("constructorcall test 2 failed");
|
||||
|
||||
if (default_args.constructorcall(new Klass()).val != -1)
|
||||
throw new Exception("constructorcall test 3 failed");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
151
Examples/test-suite/csharp/overload_template_runme.cs
Normal file
151
Examples/test-suite/csharp/overload_template_runme.cs
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
using System;
|
||||
using overload_templateNamespace;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
int f = overload_template.foo();
|
||||
|
||||
int a = overload_template.max(3,4);
|
||||
double b = overload_template.max(3.4,5.2);
|
||||
|
||||
// mix 1
|
||||
if (overload_template.mix1("hi") != 101)
|
||||
throw new Exception ("mix1(const char*)");
|
||||
|
||||
if (overload_template.mix1(1.0, 1.0) != 102)
|
||||
throw new Exception ("mix1(double, const double &)");
|
||||
|
||||
if (overload_template.mix1(1.0) != 103)
|
||||
throw new Exception ("mix1(double)");
|
||||
|
||||
// mix 2
|
||||
if (overload_template.mix2("hi") != 101)
|
||||
throw new Exception ("mix2(const char*)");
|
||||
|
||||
if (overload_template.mix2(1.0, 1.0) != 102)
|
||||
throw new Exception ("mix2(double, const double &)");
|
||||
|
||||
if (overload_template.mix2(1.0) != 103)
|
||||
throw new Exception ("mix2(double)");
|
||||
|
||||
// mix 3
|
||||
if (overload_template.mix3("hi") != 101)
|
||||
throw new Exception ("mix3(const char*)");
|
||||
|
||||
if (overload_template.mix3(1.0, 1.0) != 102)
|
||||
throw new Exception ("mix3(double, const double &)");
|
||||
|
||||
if (overload_template.mix3(1.0) != 103)
|
||||
throw new Exception ("mix3(double)");
|
||||
|
||||
// Combination 1
|
||||
if (overload_template.overtparams1(100) != 10)
|
||||
throw new Exception ("overtparams1(int)");
|
||||
|
||||
if (overload_template.overtparams1(100.0, 100) != 20)
|
||||
throw new Exception ("overtparams1(double, int)");
|
||||
|
||||
// Combination 2
|
||||
if (overload_template.overtparams2(100.0, 100) != 40)
|
||||
throw new Exception ("overtparams2(double, int)");
|
||||
|
||||
// Combination 3
|
||||
if (overload_template.overloaded() != 60)
|
||||
throw new Exception ("overloaded()");
|
||||
|
||||
if (overload_template.overloaded(100.0, 100) != 70)
|
||||
throw new Exception ("overloaded(double, int)");
|
||||
|
||||
// Combination 4
|
||||
if (overload_template.overloadedagain("hello") != 80)
|
||||
throw new Exception ("overloadedagain(const char *)");
|
||||
|
||||
if (overload_template.overloadedagain() != 90)
|
||||
throw new Exception ("overloadedagain(double)");
|
||||
|
||||
// specializations
|
||||
if (overload_template.specialization(10) != 202)
|
||||
throw new Exception ("specialization(int)");
|
||||
|
||||
if (overload_template.specialization(10.0) != 203)
|
||||
throw new Exception ("specialization(double)");
|
||||
|
||||
if (overload_template.specialization(10, 10) != 204)
|
||||
throw new Exception ("specialization(int, int)");
|
||||
|
||||
if (overload_template.specialization(10.0, 10.0) != 205)
|
||||
throw new Exception ("specialization(double, double)");
|
||||
|
||||
if (overload_template.specialization("hi", "hi") != 201)
|
||||
throw new Exception ("specialization(const char *, const char *)");
|
||||
|
||||
|
||||
// simple specialization
|
||||
overload_template.xyz();
|
||||
overload_template.xyz_int();
|
||||
overload_template.xyz_double();
|
||||
|
||||
|
||||
// a bit of everything
|
||||
if (overload_template.overload("hi") != 0)
|
||||
throw new Exception ("overload()");
|
||||
|
||||
if (overload_template.overload(1) != 10)
|
||||
throw new Exception ("overload(int t)");
|
||||
|
||||
if (overload_template.overload(1, 1) != 20)
|
||||
throw new Exception ("overload(int t, const int &)");
|
||||
|
||||
if (overload_template.overload(1, "hello") != 30)
|
||||
throw new Exception ("overload(int t, const char *)");
|
||||
|
||||
Klass k = new Klass();
|
||||
if (overload_template.overload(k) != 10)
|
||||
throw new Exception ("overload(Klass t)");
|
||||
|
||||
if (overload_template.overload(k, k) != 20)
|
||||
throw new Exception ("overload(Klass t, const Klass &)");
|
||||
|
||||
if (overload_template.overload(k, "hello") != 30)
|
||||
throw new Exception ("overload(Klass t, const char *)");
|
||||
|
||||
if (overload_template.overload(10.0, "hi") != 40)
|
||||
throw new Exception ("overload(double t, const char *)");
|
||||
|
||||
if (overload_template.overload() != 50)
|
||||
throw new Exception ("overload(const char *)");
|
||||
|
||||
|
||||
// everything put in a namespace
|
||||
if (overload_template.nsoverload("hi") != 1000)
|
||||
throw new Exception ("nsoverload()");
|
||||
|
||||
if (overload_template.nsoverload(1) != 1010)
|
||||
throw new Exception ("nsoverload(int t)");
|
||||
|
||||
if (overload_template.nsoverload(1, 1) != 1020)
|
||||
throw new Exception ("nsoverload(int t, const int &)");
|
||||
|
||||
if (overload_template.nsoverload(1, "hello") != 1030)
|
||||
throw new Exception ("nsoverload(int t, const char *)");
|
||||
|
||||
if (overload_template.nsoverload(k) != 1010)
|
||||
throw new Exception ("nsoverload(Klass t)");
|
||||
|
||||
if (overload_template.nsoverload(k, k) != 1020)
|
||||
throw new Exception ("nsoverload(Klass t, const Klass &)");
|
||||
|
||||
if (overload_template.nsoverload(k, "hello") != 1030)
|
||||
throw new Exception ("nsoverload(Klass t, const char *)");
|
||||
|
||||
if (overload_template.nsoverload(10.0, "hi") != 1040)
|
||||
throw new Exception ("nsoverload(double t, const char *)");
|
||||
|
||||
if (overload_template.nsoverload() != 1050)
|
||||
throw new Exception ("nsoverload(const char *)");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue